diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-10-24 01:58:13 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-10-24 01:59:35 +0200 |
commit | 2d0061f6579d43438eb966a7292e58f8bcff5ecc (patch) | |
tree | 7a4f870cda412230604dc37c6b6f4fa15c870e00 /src/com/ruesga/android/wallpapers | |
parent | 7e12ef2e5c314918a5e29534755df6ce09db215b (diff) | |
download | android_packages_wallpapers_PhotoPhase-2d0061f6579d43438eb966a7292e58f8bcff5ecc.tar.gz android_packages_wallpapers_PhotoPhase-2d0061f6579d43438eb966a7292e58f8bcff5ecc.tar.bz2 android_packages_wallpapers_PhotoPhase-2d0061f6579d43438eb966a7292e58f8bcff5ecc.zip |
Fix hardware acceleration problem and improve responsiveness
* Change to software acceleration when no animation is required and
remove
drawing cache (fix opengl error for reach max texture size)
* Improve responsiveness of choose albums activity
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/com/ruesga/android/wallpapers')
4 files changed, 54 insertions, 48 deletions
diff --git a/src/com/ruesga/android/wallpapers/photophase/preferences/ChoosePicturesFragment.java b/src/com/ruesga/android/wallpapers/photophase/preferences/ChoosePicturesFragment.java index 0179e8b..dad1982 100644 --- a/src/com/ruesga/android/wallpapers/photophase/preferences/ChoosePicturesFragment.java +++ b/src/com/ruesga/android/wallpapers/photophase/preferences/ChoosePicturesFragment.java @@ -110,7 +110,6 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS if (isSelectedItem(f.getAbsolutePath())) { album.getSelectedItems().add(f.getAbsolutePath()); } - Thread.yield(); } } } @@ -149,8 +148,11 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS } doEndScroll(steps, true); - // Load in background - loadInBackground(1500L); + // We not need Hardware acceleration anymore (no more animations) + // Disable drawing cache + mScroller.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + mScroller.setDrawingCacheEnabled(false); + mScroller.setSmoothScrollingEnabled(true); } }; @@ -342,7 +344,7 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS AlbumInfo albumInfo = (AlbumInfo)v.findViewById(R.id.album_info); AlbumPictures albumPictures = (AlbumPictures)v.findViewById(R.id.album_pictures); albumInfo.updateView(album); - albumPictures.updateView(album); + albumPictures.updateView(album, true); } // Restore the preference @@ -361,14 +363,19 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS * @param album The album to create * @return View The view create */ - View createAlbumView(Album album) { + View createAlbumView(final Album album) { LayoutInflater li = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View albumView = li.inflate(R.layout.album, mAlbumsPanel, false); final AlbumInfo albumInfo = (AlbumInfo)albumView.findViewById(R.id.album_info); final AlbumPictures albumPictures = (AlbumPictures)albumView.findViewById(R.id.album_pictures); // Load the album info - albumInfo.updateView(album); + albumInfo.post(new Runnable() { + @Override + public void run() { + albumInfo.updateView(album); + } + }); if (album.isSelected()) { albumInfo.setSelected(true); } @@ -379,7 +386,7 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS removeAlbumItems(ref); mSelectedAlbums.add(ref.getPath()); ref.setSelected(true); - albumPictures.updateView(ref); + albumPictures.updateView(ref, true); Preferences.Media.setSelectedMedia(getActivity(), mSelectedAlbums); mSelectionChanged = true; @@ -390,7 +397,7 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS // Remove all pictures of the album removeAlbumItems(ref); ref.setSelected(false); - albumPictures.updateView(ref); + albumPictures.updateView(ref, true); Preferences.Media.setSelectedMedia(getActivity(), mSelectedAlbums); mSelectionChanged = true; @@ -400,7 +407,7 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS }); // Load the album picture data - albumPictures.updateView(album); + albumPictures.updateView(album, false); albumPictures.addCallBackListener(new AlbumPictures.CallbacksListener() { @Override public void onBackButtonClick(View v) { @@ -480,26 +487,10 @@ public class ChoosePicturesFragment extends PreferenceFragment implements OnEndS /*package*/ synchronized void doEndScroll(int amount, boolean animate) { for (int i = 0; i < amount; i++) { //Add to the panel of cards - if (mAlbumViews != null && !mAlbumViews.isEmpty()) { - mAlbumsPanel.addCard(mAlbumViews.remove(0), animate); + if (mAlbumViews == null || mAlbumViews.isEmpty()) { + break; } + mAlbumsPanel.addCard(mAlbumViews.remove(0), animate); } } - - /** - * Method that load albums in background - * - * @param delay The delay time - */ - /*package*/ void loadInBackground(long delay) { - mAlbumsPanel.postDelayed(new Runnable() { - @Override - public void run() { - doEndScroll(AMOUNT_OF_ADDED_STEPS, false); - if (mAlbumViews != null && !mAlbumViews.isEmpty()) { - loadInBackground(300L); - } - } - }, delay); - } } diff --git a/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumInfo.java b/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumInfo.java index f86ea40..e930521 100644 --- a/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumInfo.java +++ b/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumInfo.java @@ -153,15 +153,6 @@ public class AlbumInfo extends RelativeLayout mOverflowButton.setOnClickListener(this); updateView(mAlbum); - - post(new Runnable() { - @Override - public void run() { - // Show as icon, the first picture - mTask = new AsyncPictureLoaderTask(getContext(), mIcon); - mTask.execute(new File(mAlbum.getItems().get(0))); - } - }); } /** @@ -172,7 +163,7 @@ public class AlbumInfo extends RelativeLayout super.onDetachedFromWindow(); // Cancel pending tasks - if (mTask.getStatus().compareTo(Status.PENDING) == 0) { + if (mTask != null && mTask.getStatus().compareTo(Status.PENDING) == 0) { mTask.cancel(true); } } @@ -262,7 +253,7 @@ public class AlbumInfo extends RelativeLayout public void updateView(Album album) { mAlbum = album; - if (mIcon != null) { + if (mAlbum != null && mIcon != null) { Resources res = getContext().getResources(); int selectedItems = mAlbum.getSelectedItems().size(); @@ -277,6 +268,17 @@ public class AlbumInfo extends RelativeLayout mItems.setText(String.format(res.getQuantityText( R.plurals.album_number_of_pictures, items).toString(), items)); setSelected(album.isSelected()); + + if (mTask == null) { + post(new Runnable() { + @Override + public void run() { + // Show as icon, the first picture + mTask = new AsyncPictureLoaderTask(getContext(), mIcon); + mTask.execute(new File(mAlbum.getItems().get(0))); + } + }); + } } } } diff --git a/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumPictures.java b/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumPictures.java index 572ab6e..3a9866c 100644 --- a/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumPictures.java +++ b/src/com/ruesga/android/wallpapers/photophase/widgets/AlbumPictures.java @@ -73,6 +73,8 @@ public class AlbumPictures extends RelativeLayout private View mBackButton; private View mOverflowButton; + private boolean mInitialized; + /*package*/ Album mAlbum; /** @@ -117,6 +119,7 @@ public class AlbumPictures extends RelativeLayout private void init() { mCallbacks = new ArrayList<AlbumPictures.CallbacksListener>(); mHandler = new Handler(); + mInitialized = false; } /** @@ -134,7 +137,7 @@ public class AlbumPictures extends RelativeLayout TextView title = (TextView)findViewById(R.id.album_pictures_title); title.setText(mAlbum.getName()); - updateView(mAlbum); + updateView(mAlbum, false); } /** @@ -159,10 +162,19 @@ public class AlbumPictures extends RelativeLayout * Method that set the data of the view * * @param album The album data + * @param recreate If the view should be recreated */ - public void updateView(Album album) { + public void updateView(Album album, boolean recreate) { mAlbum = album; + recreateView(false); + } + /** + * Method that recreates the the view + * + * @param propagateShow If should propagate the show event + */ + private void recreateView(final boolean propagateShow) { if (mHolder != null) { mHandler.post(new Runnable() { @Override @@ -177,17 +189,18 @@ public class AlbumPictures extends RelativeLayout for (final String picture : mAlbum.getItems()) { View v = createPicture(inflater, picture, isPictureSelected(picture)); mHolder.addView(v); - Thread.yield(); } } else { int i = 0; for (final String picture : mAlbum.getItems()) { View v = mHolder.getChildAt(i); v.setSelected(isPictureSelected(picture)); - Thread.yield(); i++; } } + if (propagateShow) { + mScroller.onShow(); + } } }); } @@ -294,7 +307,10 @@ public class AlbumPictures extends RelativeLayout * Method invoked when the view is displayed */ public void onShow() { - mScroller.onShow(); + if (!mInitialized) { + mInitialized = true; + recreateView(true); + } } /** diff --git a/src/com/ruesga/android/wallpapers/photophase/widgets/VerticalEndlessScroller.java b/src/com/ruesga/android/wallpapers/photophase/widgets/VerticalEndlessScroller.java index 1e812ed..c82cf8c 100644 --- a/src/com/ruesga/android/wallpapers/photophase/widgets/VerticalEndlessScroller.java +++ b/src/com/ruesga/android/wallpapers/photophase/widgets/VerticalEndlessScroller.java @@ -97,7 +97,7 @@ public class VerticalEndlessScroller extends ScrollView { */ @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { - // We take the last son in the scrollview + // We take the last child in the scrollview View view = getChildAt(getChildCount() - 1); int diff = (view.getBottom() - (getHeight() + getScrollY())); if ((!mSwitch && diff <= mEndPadding)) { @@ -109,9 +109,6 @@ public class VerticalEndlessScroller extends ScrollView { } else if (diff > mEndPadding) { mSwitch = false; } - if (!mSwitch) { -// super.onScrollChanged(l, t, oldl, oldt); - } } } |