diff options
Diffstat (limited to 'src/com/android/wallpaper/picker/individual')
-rwxr-xr-x | src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java | 36 | ||||
-rwxr-xr-x | src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java | 119 |
2 files changed, 52 insertions, 103 deletions
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java index 367181a..de5ba84 100755 --- a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java +++ b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java @@ -16,8 +16,6 @@ package com.android.wallpaper.picker.individual; import android.app.Activity; -import android.app.WallpaperManager; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.res.Resources.NotFoundException; @@ -44,12 +42,9 @@ import com.android.wallpaper.model.PickerIntentFactory; import com.android.wallpaper.model.WallpaperInfo; import com.android.wallpaper.module.Injector; import com.android.wallpaper.module.InjectorProvider; -import com.android.wallpaper.module.LiveWallpaperStatusChecker; -import com.android.wallpaper.module.NoBackupImageWallpaper; import com.android.wallpaper.module.WallpaperPersister; import com.android.wallpaper.picker.BaseActivity; import com.android.wallpaper.picker.PreviewActivity.PreviewActivityIntentFactory; -import com.android.wallpaper.util.ActivityUtils; import com.android.wallpaper.util.DiskBasedLogger; /** @@ -61,13 +56,11 @@ public class IndividualPickerActivity extends BaseActivity { private static final String EXTRA_CATEGORY_COLLECTION_ID = "com.android.wallpaper.category_collection_id"; private static final int PREVIEW_WALLPAPER_REQUEST_CODE = 0; - private static final int NO_BACKUP_IMAGE_WALLPAPER_REQUEST_CODE = 1; private static final int PREVIEW_LIVEWALLPAPER_REQUEST_CODE = 2; private static final String KEY_CATEGORY_COLLECTION_ID = "key_category_collection_id"; private InlinePreviewIntentFactory mPreviewIntentFactory; private WallpaperPersister mWallpaperPersister; - private LiveWallpaperStatusChecker mLiveWallpaperStatusChecker; private Category mCategory; private String mCategoryCollectionId; @@ -83,7 +76,6 @@ public class IndividualPickerActivity extends BaseActivity { mPreviewIntentFactory = new PreviewActivityIntentFactory(); Injector injector = InjectorProvider.getInjector(); mWallpaperPersister = injector.getWallpaperPersister(this); - mLiveWallpaperStatusChecker = injector.getLiveWallpaperStatusChecker(this); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); @@ -160,8 +152,8 @@ public class IndividualPickerActivity extends BaseActivity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - // Handle Up as a Global back since the only entry point to IndividualPickerActivity is from - // TopLevelPickerActivity. + // Handle Up as a Global back since the only entry point to IndividualPickerActivity is + // from TopLevelPickerActivity. onBackPressed(); return true; } @@ -184,18 +176,6 @@ public class IndividualPickerActivity extends BaseActivity { finishWithResultOk(shouldShowMessage); } break; - - case NO_BACKUP_IMAGE_WALLPAPER_REQUEST_CODE: - // User clicked "Set wallpaper" in live wallpaper preview UI. - // NOTE: Don't check for the result code prior to KitKat MR2 because a bug on those versions - // caused the result code to be discarded from LivePicker so we can't rely on it. - if ((!BuildCompat.isAtLeastL() || resultCode == Activity.RESULT_OK) - && mLiveWallpaperStatusChecker.isNoBackupImageWallpaperSet() - && mCategory.getWallpaperRotationInitializer().startRotation(getApplicationContext())) { - finishWithResultOk(true); - } - break; - default: Log.e(TAG, "Invalid request code: " + requestCode); } @@ -211,18 +191,6 @@ public class IndividualPickerActivity extends BaseActivity { : PREVIEW_WALLPAPER_REQUEST_CODE); } - /** - * Shows the system live wallpaper preview for the {@link NoBackupImageWallpaper} which is used to - * draw rotating wallpapers on pre-N Android builds. - */ - public void showNoBackupImageWallpaperPreview() { - Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); - ComponentName componentName = new ComponentName(this, NoBackupImageWallpaper.class); - intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName); - ActivityUtils.startActivityForResultSafely( - this, intent, NO_BACKUP_IMAGE_WALLPAPER_REQUEST_CODE); - } - private void finishWithResultOk(boolean shouldShowMessage) { if (shouldShowMessage) { try { diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java index db21da3..c0c4ce5 100755 --- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java +++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java @@ -58,13 +58,11 @@ import com.android.wallpaper.model.WallpaperRotationInitializer; import com.android.wallpaper.model.WallpaperRotationInitializer.Listener; import com.android.wallpaper.model.WallpaperRotationInitializer.NetworkPreference; import com.android.wallpaper.model.WallpaperRotationInitializer.RotationInitializationState; -import com.android.wallpaper.model.WallpaperRotationInitializer.RotationStateListener; import com.android.wallpaper.module.FormFactorChecker; import com.android.wallpaper.module.FormFactorChecker.FormFactor; import com.android.wallpaper.module.Injector; import com.android.wallpaper.module.InjectorProvider; import com.android.wallpaper.module.PackageStatusNotifier; -import com.android.wallpaper.module.RotatingWallpaperComponentChecker; import com.android.wallpaper.module.WallpaperChangedNotifier; import com.android.wallpaper.module.WallpaperPersister; import com.android.wallpaper.module.WallpaperPersister.Destination; @@ -116,7 +114,6 @@ public class IndividualPickerFragment extends Fragment WallpaperPreferences mWallpaperPreferences; WallpaperChangedNotifier mWallpaperChangedNotifier; - RotatingWallpaperComponentChecker mRotatingWallpaperComponentChecker; RecyclerView mImageGrid; IndividualAdapter mAdapter; WallpaperCategory mCategory; @@ -250,8 +247,6 @@ public class IndividualPickerFragment extends Fragment mWallpaperChangedNotifier = WallpaperChangedNotifier.getInstance(); mWallpaperChangedNotifier.registerListener(mWallpaperChangedListener); - mRotatingWallpaperComponentChecker = injector.getRotatingWallpaperComponentChecker(); - mFormFactor = injector.getFormFactorChecker(appContext).getFormFactor(); mPackageStatusNotifier = injector.getPackageStatusNotifier(appContext); @@ -445,7 +440,8 @@ public class IndividualPickerFragment extends Fragment public void onResume() { super.onResume(); - WallpaperPreferences preferences = InjectorProvider.getInjector().getPreferences(getActivity()); + WallpaperPreferences preferences = InjectorProvider.getInjector() + .getPreferences(getActivity()); preferences.setLastAppActiveTimestamp(new Date().getTime()); // Reset Glide memory settings to a "normal" level of usage since it may have been lowered in @@ -541,31 +537,23 @@ public class IndividualPickerFragment extends Fragment * state of the user's device and binds the state of the current category's rotation to the "start * rotation" tile. */ - private void refreshRotationHolder(final RotationHolder rotationHolder) { + private void refreshRotationHolder(RotationHolder rotationHolder) { mWallpaperRotationInitializer.fetchRotationInitializationState(getContext(), - new RotationStateListener() { - @Override - public void onRotationStateReceived( - @RotationInitializationState final int rotationInitializationState) { - - // Update the UI state of the "start rotation" tile displayed on screen. Do this in a - // Handler so it is scheduled at the end of the message queue. This is necessary to - // ensure we do not remove or add data from the adapter while the layout is still being - // computed. RecyclerView documentation therefore recommends performing such changes in - // a Handler. - new android.os.Handler().post(new Runnable() { - @Override - public void run() { - // A config change may have destroyed the activity since the refresh started, so - // check for that to avoid an NPE. - if (getActivity() == null) { - return; - } + rotationState -> { + // Update the UI state of the "start rotation" tile displayed on screen. + // Do this in a Handler so it is scheduled at the end of the message queue. + // This is necessary to ensure we do not remove or add data from the adapter + // while the layout is still being computed. RecyclerView documentation + // therefore recommends performing such changes in a Handler. + new Handler().post(() -> { + // A config change may have destroyed the activity since the refresh + // started, so check for that to avoid an NPE. + if (getActivity() == null) { + return; + } - rotationHolder.bindRotationInitializationState(rotationInitializationState); - } - }); - } + rotationHolder.bindRotationInitializationState(rotationState); + }); }); } @@ -614,34 +602,33 @@ public class IndividualPickerFragment extends Fragment // app before the first wallpaper image in rotation finishes downloading. Activity activity = getActivity(); - if (activity != null - && mWallpaperRotationInitializer - .isNoBackupImageWallpaperPreviewNeeded(appContext)) { - ((IndividualPickerActivity) activity).showNoBackupImageWallpaperPreview(); - } else { - if (mWallpaperRotationInitializer.startRotation(appContext)) { - if (activity != null && mFormFactor == FormFactorChecker.FORM_FACTOR_MOBILE) { - try { - Toast.makeText(getActivity(), R.string.wallpaper_set_successfully_message, - Toast.LENGTH_SHORT).show(); - } catch (NotFoundException e) { - Log.e(TAG, "Could not show toast " + e); - } - activity.setResult(Activity.RESULT_OK); - activity.finish(); - } else if (mFormFactor == FormFactorChecker.FORM_FACTOR_DESKTOP) { - mAdapter.updateSelectedTile(SPECIAL_FIXED_TILE_ADAPTER_POSITION); - } - } else { // Failed to start rotation. - showStartRotationErrorDialog(networkPreference); - - if (mFormFactor == FormFactorChecker.FORM_FACTOR_DESKTOP) { - DesktopRotationHolder rotationViewHolder = - (DesktopRotationHolder) mImageGrid.findViewHolderForAdapterPosition( - SPECIAL_FIXED_TILE_ADAPTER_POSITION); - rotationViewHolder.setSelectionState(SelectableHolder.SELECTION_STATE_DESELECTED); + if (mWallpaperRotationInitializer.startRotation(appContext)) { + if (activity != null + && mFormFactor == FormFactorChecker.FORM_FACTOR_MOBILE) { + try { + Toast.makeText(getActivity(), + R.string.wallpaper_set_successfully_message, + Toast.LENGTH_SHORT).show(); + } catch (NotFoundException e) { + Log.e(TAG, "Could not show toast " + e); } + + activity.setResult(Activity.RESULT_OK); + activity.finish(); + } else if (mFormFactor == FormFactorChecker.FORM_FACTOR_DESKTOP) { + mAdapter.updateSelectedTile(SPECIAL_FIXED_TILE_ADAPTER_POSITION); + } + } else { // Failed to start rotation. + showStartRotationErrorDialog(networkPreference); + + if (mFormFactor == FormFactorChecker.FORM_FACTOR_DESKTOP) { + DesktopRotationHolder rotationViewHolder = + (DesktopRotationHolder) + mImageGrid.findViewHolderForAdapterPosition( + SPECIAL_FIXED_TILE_ADAPTER_POSITION); + rotationViewHolder.setSelectionState( + SelectableHolder.SELECTION_STATE_DESELECTED); } } } @@ -690,11 +677,7 @@ public class IndividualPickerFragment extends Fragment * Returns whether rotation is enabled for this category. */ boolean isRotationEnabled() { - boolean isRotationSupported = - mRotatingWallpaperComponentChecker.getRotatingWallpaperSupport(getContext()) - == RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_SUPPORT_SUPPORTED; - - return isRotationSupported && mWallpaperRotationInitializer != null; + return mWallpaperRotationInitializer != null; } @Override @@ -732,10 +715,10 @@ public class IndividualPickerFragment extends Fragment super(itemView); itemView.setOnClickListener(this); - mTileLayout = (FrameLayout) itemView.findViewById(R.id.daily_refresh); - mRotationMessage = (TextView) itemView.findViewById(R.id.rotation_tile_message); - mRotationTitle = (TextView) itemView.findViewById(R.id.rotation_tile_title); - mRefreshIcon = (ImageView) itemView.findViewById(R.id.rotation_tile_refresh_icon); + mTileLayout = itemView.findViewById(R.id.daily_refresh); + mRotationMessage = itemView.findViewById(R.id.rotation_tile_message); + mRotationTitle = itemView.findViewById(R.id.rotation_tile_title); + mRefreshIcon = itemView.findViewById(R.id.rotation_tile_refresh_icon); mTileLayout.getLayoutParams().height = mTileSizePx.y; // If the feature flag for "dynamic start rotation tile" is not enabled, fall back to the @@ -749,7 +732,8 @@ public class IndividualPickerFragment extends Fragment mRotationMessage.setTextColor( getResources().getColor(R.color.rotation_tile_enabled_subtitle_text_color)); mRefreshIcon.setColorFilter( - getResources().getColor(R.color.rotation_tile_enabled_refresh_icon_color), Mode.SRC_IN); + getResources().getColor(R.color.rotation_tile_enabled_refresh_icon_color), + Mode.SRC_IN); return; } @@ -765,10 +749,7 @@ public class IndividualPickerFragment extends Fragment @Override public void onClick(View v) { - boolean isLiveWallpaperNeeded = mWallpaperRotationInitializer - .isNoBackupImageWallpaperPreviewNeeded(getActivity().getApplicationContext()); - DialogFragment startRotationDialogFragment = StartRotationDialogFragment - .newInstance(isLiveWallpaperNeeded); + DialogFragment startRotationDialogFragment = new StartRotationDialogFragment(); startRotationDialogFragment.setTargetFragment( IndividualPickerFragment.this, UNUSED_REQUEST_CODE); startRotationDialogFragment.show(getFragmentManager(), TAG_START_ROTATION_DIALOG); |