diff options
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase')
8 files changed, 315 insertions, 20 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java index dff9887..ccb5c2b 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java @@ -83,6 +83,22 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { boolean emptyTextureQueue = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_EMPTY_TEXTURE_QUEUE, false); boolean mediaReload = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, false); boolean mediaIntervalChanged = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_INTERVAL_CHANGED, false); + if (emptyTextureQueue) { + if (mTextureManager != null) { + mTextureManager.emptyTextureQueue(true); + } + } + if (mediaReload) { + synchronized (mMediaSync) { + if (mTextureManager != null) { + mTextureManager.reloadMedia(); + scheduleOrCancelMediaScan(); + } + } + } + if (mediaIntervalChanged) { + scheduleOrCancelMediaScan(); + } if (recreateWorld) { // Recreate the wallpaper world try { @@ -94,18 +110,6 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { if (redraw) { mDispatcher.requestRender(); } - if (emptyTextureQueue) { - mTextureManager.emptyTextureQueue(true); - } - if (mediaReload) { - synchronized (mMediaSync) { - mTextureManager.reloadMedia(); - scheduleOrCancelMediaScan(); - } - } - if (mediaIntervalChanged) { - scheduleOrCancelMediaScan(); - } } }; @@ -320,10 +324,13 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { // the best fixed size will be set. The disposition size is simple for a better // performance of the internal arrays final Configuration conf = mContext.getResources().getConfiguration(); + int orientation = mContext.getResources().getConfiguration().orientation; int w = (int) AndroidHelper.convertDpToPixel(mContext, conf.screenWidthDp); int h = (int) AndroidHelper.convertDpToPixel(mContext, conf.screenWidthDp); Rect dimensions = new Rect(0, 0, w / 2, h / 2); - int cc = PreferencesProvider.Preferences.Layout.getDisposition().size(); + int cc = (orientation == Configuration.ORIENTATION_PORTRAIT) + ? PreferencesProvider.Preferences.Layout.getPortraitDisposition().size() + : PreferencesProvider.Preferences.Layout.getLandscapeDisposition().size(); recycle(); mTextureManager = new TextureManager(mContext, mDispatcher, cc, dimensions); diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java index b9f2d77..9b13c4b 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java @@ -242,7 +242,9 @@ public class PhotoPhaseWallpaperWorld { int rows = portrait ? Preferences.Layout.getRows() : Preferences.Layout.getCols(); float cellw = 2.0f / cols; float cellh = 2.0f / rows; - List<Disposition> dispositions = Preferences.Layout.getDisposition(); + List<Disposition> dispositions = portrait + ? Preferences.Layout.getPortraitDisposition() + : Preferences.Layout.getLandscapeDisposition(); if (DEBUG) Log.d(TAG, "Dispositions: " + dispositions.size() + " | " + String.valueOf(dispositions)); mPhotoFrames = new ArrayList<PhotoFrame>(dispositions.size()); @@ -325,6 +327,28 @@ public class PhotoPhaseWallpaperWorld { 1.0f - (y * cellh), 0.0f }; +// return new float[] +// { +// // top left +// -1.0f, +// -1.0f, +// 0.0f, +// +// // bottom left +// -1.0f, +// 1.0f, +// 0.0f, +// +// // bottom right +// 1.0f, +// 1.0f, +// 0.0f, +// +// // top right +// 1.0f, +// -1.0f, +// 0.0f +// }; } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java index bd42af9..1d39ac7 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java +++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java @@ -209,6 +209,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { */ public void emptyTextureQueue(boolean reload) { synchronized (mSync) { + // Recycle the textures try { List<GLESTextureInfo> all = mQueue.removeAll(); for (GLESTextureInfo info : all) { @@ -223,10 +224,16 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { } catch (EmptyQueueException eqex) { // Ignore } + // Recycle the bitmaps + for (Bitmap bitmap : sRecycledBitmaps) { + bitmap.recycle(); + } + sRecycledBitmaps.clear(); // Reload the queue if (reload) { synchronized (mBackgroundTask.mLoadSync) { + mBackgroundTask.resetAvailableImages(); mBackgroundTask.mLoadSync.notify(); } } @@ -317,12 +324,23 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { */ public void setAvailableImages(File[] images) { synchronized (mLoadSync) { + mNewImages.clear(); mNewImages.addAll(Arrays.asList(images)); mUsedImages.clear(); } } /** + * Method that reset the current available images queue. + */ + public void resetAvailableImages() { + synchronized (mLoadSync) { + mNewImages.addAll(mUsedImages); + mUsedImages.clear(); + } + } + + /** * {@inheritDoc} */ @Override diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java index 34611c9..e56fd65 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java @@ -176,6 +176,8 @@ public class ChoosePicturesFragment extends PreferenceFragment { // Notify that the settings was changed Intent intent = new Intent(PreferencesProvider.ACTION_SETTINGS_CHANGED); if (mSelectionChanged) { + intent.putExtra(PreferencesProvider.EXTRA_FLAG_REDRAW, Boolean.TRUE); + intent.putExtra(PreferencesProvider.EXTRA_FLAG_EMPTY_TEXTURE_QUEUE, Boolean.TRUE); intent.putExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, Boolean.TRUE); } getActivity().sendBroadcast(intent); diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/DispositionFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/DispositionFragment.java new file mode 100644 index 0000000..99d2153 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/DispositionFragment.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase.preferences; + +import android.content.Context; +import android.graphics.Rect; +import android.os.Bundle; +import android.preference.PreferenceFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RelativeLayout; + +import org.cyanogenmod.wallpapers.photophase.R; +import org.cyanogenmod.wallpapers.photophase.model.Disposition; + +import java.util.List; + +/** + * An abstract fragment class that allow to choose the layout disposition of the wallpaper + */ +public abstract class DispositionFragment extends PreferenceFragment { + + /** + * Available modes for the {@link DispositionFragment} class. + */ + public static enum DispositionModes { + /** + * Portrait screen + */ + PORTRAIT, + /** + * Landscape screen + */ + LANDSCAPE; + } + + private final DispositionModes mMode; + + private List<Disposition> mOldDispositions; + + /** + * Constructor of <code>DispositionFragment</code> + * + * @param mode The mode of the disposition layout + */ + public DispositionFragment(DispositionModes mode) { + super(); + mMode = mode; + } + + /** + * Method that returns the current user preference for the disposition + * + * @return List<Disposition> The current user preference dispositions + */ + public abstract List<Disposition> getUserDispositions(); + + /** + * {@inheritDoc} + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Change the preference manager + getPreferenceManager().setSharedPreferencesName(PreferencesProvider.PREFERENCES_FILE); + getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE); + } + + /** + * {@inheritDoc} + */ + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Inflate the layout for this fragment + ViewGroup v = (ViewGroup)inflater.inflate(R.layout.choose_disposition_fragment, container, false); +// v.addView(createFrame()); + return v; + } + + /** + * Method that recreate + * @param r + * @return + */ + private View createFrame(Rect r) { + // Create a view with all the + View v = new View(getActivity()); + v.setBackgroundColor(getResources().getColor(R.color.wallpaper_background_color)); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(r.width(), r.height()); + params.leftMargin = r.top; + params.topMargin = r.left; + v.setLayoutParams(params); + v.setFocusable(true); + v.setFocusableInTouchMode(true); + return v; + } +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/LandscapeDispositionFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/LandscapeDispositionFragment.java new file mode 100644 index 0000000..72b32c5 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/LandscapeDispositionFragment.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase.preferences; + +import android.content.pm.ActivityInfo; +import android.os.Bundle; + +import org.cyanogenmod.wallpapers.photophase.model.Disposition; + +import java.util.List; + +/** + * A fragment class that allow to choose the layout disposition of the wallpaper for landscape + * screen. + */ +public class LandscapeDispositionFragment extends DispositionFragment { + + /** + * Constructor of <code>LandscapeDispositionFragment</code> + */ + public LandscapeDispositionFragment() { + super(DispositionModes.LANDSCAPE); + } + + /** + * {@inheritDoc} + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + + /** + * {@inheritDoc} + */ + @Override + public List<Disposition> getUserDispositions() { + return PreferencesProvider.Preferences.Layout.getLandscapeDisposition(); + } +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PortraitDispositionFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PortraitDispositionFragment.java new file mode 100644 index 0000000..5209a5b --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PortraitDispositionFragment.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase.preferences; + +import android.content.pm.ActivityInfo; +import android.os.Bundle; + +import org.cyanogenmod.wallpapers.photophase.model.Disposition; + +import java.util.List; + +/** + * A fragment class that allow to choose the layout disposition of the wallpaper for portrait + * screen. + */ +public class PortraitDispositionFragment extends DispositionFragment { + + /** + * Constructor of <code>PortraitDispositionFragment</code> + */ + public PortraitDispositionFragment() { + super(DispositionModes.PORTRAIT); + } + + /** + * {@inheritDoc} + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + + /** + * {@inheritDoc} + */ + @Override + public List<Disposition> getUserDispositions() { + return PreferencesProvider.Preferences.Layout.getPortraitDisposition(); + } +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java index deaac53..0ad3ace 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java @@ -293,7 +293,8 @@ public final class PreferencesProvider { private static final int DEFAULT_COLS = 8; private static final int DEFAULT_ROWS = 14; - private static final String DEFAULT_DISPOSITION = "0x0:5x4|5x0:3x2|5x2:3x2|0x4:4x4|4x4:4x4|0x8:8x6"; + private static final String DEFAULT_PORTRAIT_DISPOSITION = "0x0:5x4|5x0:3x2|5x2:3x2|0x4:4x4|4x4:4x4|0x8:8x6"; + private static final String DEFAULT_LANDSCAPE_DISPOSITION = "0x0:5x4|5x0:3x2|5x2:3x2|0x4:4x4|4x4:4x4|0x8:8x6"; /** * Method that returns the rows of the wallpaper. @@ -314,15 +315,35 @@ public final class PreferencesProvider { } /** - * Returns the disposition of the photo frames in the wallpaper. The setting is - * stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means (position x=0, y=0, + * Returns the disposition of the photo frames in the wallpaper on portrait screen. The + * setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means (position x=0, y=0, * 1 cells width, 2 cells height, ...). * * @return List<Disposition> The photo frames dispositions */ - public static List<Disposition> getDisposition() { - String setting = getString("ui_layout_disposition", DEFAULT_DISPOSITION); - String[] v = setting.split("\\|"); + public static List<Disposition> getPortraitDisposition() { + return toDispositions(getString("ui_layout_portrait_disposition", DEFAULT_PORTRAIT_DISPOSITION)); + } + + /** + * Returns the disposition of the photo frames in the wallpaper on landscape screen. The + * setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means (position x=0, y=0, + * 1 cells width, 2 cells height, ...). + * + * @return List<Disposition> The photo frames dispositions + */ + public static List<Disposition> getLandscapeDisposition() { + return toDispositions(getString("ui_layout_landscape_disposition", DEFAULT_LANDSCAPE_DISPOSITION)); + } + + /** + * Method that converts to dispositions reference + * + * @param value The value to convert + * @return List<Disposition> The dispositions reference + */ + private static List<Disposition> toDispositions(String value) { + String[] v = value.split("\\|"); List<Disposition> dispositions = new ArrayList<Disposition>(v.length); for (String s : v) { String[] s1 = s.split(":"); |