aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2014-06-14 00:43:40 +0200
committerJorge Ruesga <jorge@ruesga.com>2014-06-14 00:43:40 +0200
commit2e3030415e28f9b47e42c299348d20852707f97f (patch)
tree1799a8050093540561175cf50469580f313a83d2
parentcd42499be72a9af6091a5b6eb514f0a23da72b14 (diff)
downloadandroid_packages_wallpapers_PhotoPhase-2e3030415e28f9b47e42c299348d20852707f97f.tar.gz
android_packages_wallpapers_PhotoPhase-2e3030415e28f9b47e42c299348d20852707f97f.tar.bz2
android_packages_wallpapers_PhotoPhase-2e3030415e28f9b47e42c299348d20852707f97f.zip
Fix NPE from getActivity() call
Use onAttach and onDetach to execute mTask, to be sure that the activity was created Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
index 0caf6da..513ea33 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
@@ -19,6 +19,7 @@ package org.cyanogenmod.wallpapers.photophase.preferences;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -282,6 +283,7 @@ public class ChoosePicturesFragment extends PreferenceFragment
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
mHandler = new Handler(mCallback);
mShowingAlbums = true;
@@ -298,7 +300,7 @@ public class ChoosePicturesFragment extends PreferenceFragment
mSelectedAlbums = new HashSet<String>(mOriginalSelectedAlbums);
mSelectionChanged = false;
- Resources res = getActivity().getResources();
+ final Resources res = getResources();
mPicturesAnimDurationIn = res.getInteger(R.integer.pictures_anim_in);
mPicturesAnimDurationOut = res.getInteger(R.integer.pictures_anim_out);
@@ -310,10 +312,6 @@ public class ChoosePicturesFragment extends PreferenceFragment
*/
@Override
public void onDestroy() {
- super.onDestroy();
- if (mTask.getStatus().compareTo(Status.PENDING) == 0) {
- mTask.cancel(true);
- }
unbindDrawables(mAlbumsPanel);
unregister();
@@ -332,6 +330,8 @@ public class ChoosePicturesFragment extends PreferenceFragment
intent.putExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, Boolean.TRUE);
}
getActivity().sendBroadcast(intent);
+
+ super.onDestroy();
}
private void unregister() {
@@ -385,11 +385,33 @@ public class ChoosePicturesFragment extends PreferenceFragment
// Load the albums
unregister();
- mTask.execute();
return root;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ mTask.execute();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onDetach() {
+ if (mTask.getStatus().compareTo(Status.PENDING) == 0) {
+ mTask.cancel(true);
+ }
+ super.onDetach();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public void onClick(View v) {
// Hide the albums picture with animation
@@ -747,7 +769,7 @@ public class ChoosePicturesFragment extends PreferenceFragment
* @param album The album data
*/
void updateAlbumInfo(View v, Album album) {
- Resources res = getActivity().getResources();
+ final Resources res = getResources();
AlbumInfoView info = (AlbumInfoView)v.findViewById(R.id.album_info);
info.setAlbum(album);
@@ -783,7 +805,7 @@ public class ChoosePicturesFragment extends PreferenceFragment
List<Picture> items = album.getItems();
// Calculate the grid dimensions
- Resources res = getActivity().getResources();
+ final Resources res = getResources();
int pictureWidth = (int)res.getDimension(R.dimen.picture_size);
int gridWidth = mPicturesPanel.getWidth();
int columns = gridWidth / pictureWidth;