From 8d14e8ac684a234e43db8e98c60a42821904e72b Mon Sep 17 00:00:00 2001 From: Chihhang Chuang Date: Tue, 15 Jun 2021 14:03:18 +0800 Subject: Replace "Hub" naming with "Customization" - Since "Hub" is a meaningless naming. - Also update "Mode" prefix naming to "DarkMode". - Remove unused interface in Injector. Bug: 190354625 Test: Manually Change-Id: I5293f590070e9f4a852ab31e64506639a549a558 --- res/layout/dark_mode_section_view.xml | 44 +++++++ res/layout/mode_section_view.xml | 44 ------- .../customization/model/CustomizationManager.java | 14 --- .../customization/model/CustomizationSection.java | 52 -------- .../model/grid/GridOptionsManager.java | 2 +- .../model/grid/GridSectionController.java | 14 +-- .../model/mode/BatterySaverStateReceiver.java | 47 ------- .../model/mode/DarkModeSectionController.java | 139 +++++++++++++++++++++ .../customization/model/mode/ModeSection.java | 132 ------------------- .../themedicon/ThemedIconSectionController.java | 7 +- .../module/CustomizationInjector.java | 29 ----- .../module/DefaultCustomizationInjector.java | 12 +- .../module/DefaultCustomizationSections.java | 24 ++-- .../customization/picker/grid/GridFragment.java | 2 +- .../picker/grid/GridFullPreviewFragment.java | 2 +- .../picker/mode/DarkModeSectionView.java | 70 +++++++++++ .../customization/picker/mode/ModeSectionView.java | 72 ----------- 17 files changed, 286 insertions(+), 420 deletions(-) create mode 100644 res/layout/dark_mode_section_view.xml delete mode 100644 res/layout/mode_section_view.xml delete mode 100644 src/com/android/customization/model/CustomizationSection.java delete mode 100644 src/com/android/customization/model/mode/BatterySaverStateReceiver.java create mode 100644 src/com/android/customization/model/mode/DarkModeSectionController.java delete mode 100644 src/com/android/customization/model/mode/ModeSection.java create mode 100644 src/com/android/customization/picker/mode/DarkModeSectionView.java delete mode 100644 src/com/android/customization/picker/mode/ModeSectionView.java diff --git a/res/layout/dark_mode_section_view.xml b/res/layout/dark_mode_section_view.xml new file mode 100644 index 00000000..d63f07a4 --- /dev/null +++ b/res/layout/dark_mode_section_view.xml @@ -0,0 +1,44 @@ + + + + + + + + + diff --git a/res/layout/mode_section_view.xml b/res/layout/mode_section_view.xml deleted file mode 100644 index 12e0c040..00000000 --- a/res/layout/mode_section_view.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - diff --git a/src/com/android/customization/model/CustomizationManager.java b/src/com/android/customization/model/CustomizationManager.java index efc4c747..104cc837 100644 --- a/src/com/android/customization/model/CustomizationManager.java +++ b/src/com/android/customization/model/CustomizationManager.java @@ -27,20 +27,6 @@ import java.util.List; */ public interface CustomizationManager { - /** - * Create a new {@link CustomizationSection} corresponding to this Manager - */ - default CustomizationSection createSection() { - return null; - } - - /** - * @return the id in the navigation menu for the section this Manager manages. - */ - default int getNavId() { - return 0; - }; - /** * Callback for applying a customization option. */ diff --git a/src/com/android/customization/model/CustomizationSection.java b/src/com/android/customization/model/CustomizationSection.java deleted file mode 100644 index da1b4f8d..00000000 --- a/src/com/android/customization/model/CustomizationSection.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source 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 com.android.customization.model; - -import android.content.Context; - -import androidx.annotation.IdRes; -import androidx.fragment.app.Fragment; - -/** - * Represents a section of the Picker (eg "ThemeBundle", "Clock", etc). - * There should be a concrete subclass per available section, providing the corresponding - * Fragment to be displayed when switching to each section. - * @param CustomizationOption that this section represents. - */ -public abstract class CustomizationSection { - - /** - * IdRes used to identify this section in the BottomNavigationView menu. - */ - @IdRes - public final int id; - protected final CustomizationManager mCustomizationManager; - - public CustomizationSection(@IdRes int id, CustomizationManager manager) { - this.id = id; - mCustomizationManager = manager; - } - - /** - * @return the Fragment corresponding to this section. - */ - public abstract Fragment getFragment(Context c); - - public CustomizationManager getCustomizationManager() { - return mCustomizationManager; - } - -} diff --git a/src/com/android/customization/model/grid/GridOptionsManager.java b/src/com/android/customization/model/grid/GridOptionsManager.java index c1ec7293..da1139ee 100644 --- a/src/com/android/customization/model/grid/GridOptionsManager.java +++ b/src/com/android/customization/model/grid/GridOptionsManager.java @@ -43,7 +43,7 @@ public class GridOptionsManager implements CustomizationManager { private final ThemesUserEventLogger mEventLogger; /** Returns the {@link GridOptionsManager} instance. */ - public static GridOptionsManager get(Context context) { + public static GridOptionsManager getInstance(Context context) { if (sGridOptionsManager == null) { Context appContext = context.getApplicationContext(); CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector(); diff --git a/src/com/android/customization/model/grid/GridSectionController.java b/src/com/android/customization/model/grid/GridSectionController.java index a570565c..5470d77d 100644 --- a/src/com/android/customization/model/grid/GridSectionController.java +++ b/src/com/android/customization/model/grid/GridSectionController.java @@ -27,22 +27,22 @@ import com.android.customization.model.CustomizationManager.OptionsFetchedListen import com.android.customization.picker.grid.GridFragment; import com.android.customization.picker.grid.GridSectionView; import com.android.wallpaper.R; -import com.android.wallpaper.model.HubSectionController; +import com.android.wallpaper.model.CustomizationSectionController; import java.util.List; -/** A {@link HubSectionController} for app grid. */ -public class GridSectionController implements HubSectionController { +/** A {@link CustomizationSectionController} for app grid. */ +public class GridSectionController implements CustomizationSectionController { private static final String TAG = "GridSectionController"; private final GridOptionsManager mGridOptionsManager; - private final HubSectionNavigationController mHubSectionNavigationController; + private final CustomizationSectionNavigationController mSectionNavigationController; public GridSectionController(GridOptionsManager gridOptionsManager, - HubSectionNavigationController hubSectionNavigationController) { + CustomizationSectionNavigationController sectionNavigationController) { mGridOptionsManager = gridOptionsManager; - mHubSectionNavigationController = hubSectionNavigationController; + mSectionNavigationController = sectionNavigationController; } @Override @@ -74,7 +74,7 @@ public class GridSectionController implements HubSectionController mHubSectionNavigationController.navigateTo( + gridSectionView.setOnClickListener(v -> mSectionNavigationController.navigateTo( GridFragment.newInstance(context.getString(R.string.grid_title)))); return gridSectionView; diff --git a/src/com/android/customization/model/mode/BatterySaverStateReceiver.java b/src/com/android/customization/model/mode/BatterySaverStateReceiver.java deleted file mode 100644 index 803f7222..00000000 --- a/src/com/android/customization/model/mode/BatterySaverStateReceiver.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source 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 com.android.customization.model.mode; - -import static android.os.PowerManager.ACTION_POWER_SAVE_MODE_CHANGED; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.PowerManager; -import android.text.TextUtils; - -import com.android.wallpaper.model.HubSectionController.HubSectionBatterySaverListener; - -/** - * Broadcast receiver for getting battery saver state and callback to - * {@link HubSectionBatterySaverListener} - */ -public class BatterySaverStateReceiver extends BroadcastReceiver { - - private final HubSectionBatterySaverListener mHubSectionBatterySaverListener; - - public BatterySaverStateReceiver(HubSectionBatterySaverListener batterySaverController) { - mHubSectionBatterySaverListener = batterySaverController; - } - - @Override - public void onReceive(Context context, Intent intent) { - if (TextUtils.equals(intent.getAction(), ACTION_POWER_SAVE_MODE_CHANGED)) { - PowerManager pm = context.getSystemService(PowerManager.class); - mHubSectionBatterySaverListener.onBatterySaverStateChanged(pm.isPowerSaveMode()); - } - } -} diff --git a/src/com/android/customization/model/mode/DarkModeSectionController.java b/src/com/android/customization/model/mode/DarkModeSectionController.java new file mode 100644 index 00000000..de639832 --- /dev/null +++ b/src/com/android/customization/model/mode/DarkModeSectionController.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2021 The Android Open Source 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 com.android.customization.model.mode; + + +import static android.Manifest.permission.MODIFY_DAY_NIGHT_MODE; +import static android.content.pm.PackageManager.PERMISSION_GRANTED; +import static android.os.PowerManager.ACTION_POWER_SAVE_MODE_CHANGED; + +import android.app.UiModeManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.PowerManager; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.widget.Switch; +import android.widget.Toast; + +import androidx.annotation.MainThread; +import androidx.core.content.ContextCompat; +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; +import androidx.lifecycle.OnLifecycleEvent; + +import com.android.customization.picker.mode.DarkModeSectionView; +import com.android.wallpaper.R; +import com.android.wallpaper.model.CustomizationSectionController; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** Section for dark theme toggle that controls if this section will be shown visually. */ +public class DarkModeSectionController implements + CustomizationSectionController, LifecycleObserver { + + private static final ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); + + private final Lifecycle mLifecycle; + private final PowerManager mPowerManager; + private final BatterySaverStateReceiver mBatterySaverStateReceiver = + new BatterySaverStateReceiver(); + + private Context mContext; + private DarkModeSectionView mDarkModeSectionView; + + public DarkModeSectionController(Context context, Lifecycle lifecycle) { + mContext = context; + mLifecycle = lifecycle; + mPowerManager = context.getSystemService(PowerManager.class); + mLifecycle.addObserver(this); + } + + @OnLifecycleEvent(Lifecycle.Event.ON_START) + @MainThread + public void onStart() { + sExecutorService.submit(() -> { + if (mContext != null && mLifecycle.getCurrentState().isAtLeast( + Lifecycle.State.STARTED)) { + mContext.registerReceiver(mBatterySaverStateReceiver, + new IntentFilter(ACTION_POWER_SAVE_MODE_CHANGED)); + } + }); + } + + @OnLifecycleEvent(Lifecycle.Event.ON_STOP) + @MainThread + public void onStop() { + sExecutorService.submit(() -> { + if (mContext != null && mBatterySaverStateReceiver != null) { + mContext.unregisterReceiver(mBatterySaverStateReceiver); + } + }); + } + + @Override + public void release() { + mLifecycle.removeObserver(this); + mContext = null; + } + + @Override + public boolean isAvailable(Context context) { + if (context == null) { + return false; + } + return ContextCompat.checkSelfPermission(context, MODIFY_DAY_NIGHT_MODE) + == PERMISSION_GRANTED; + } + + @Override + public DarkModeSectionView createView(Context context) { + mDarkModeSectionView = (DarkModeSectionView) LayoutInflater.from( + context).inflate(R.layout.dark_mode_section_view, /* root= */ null); + mDarkModeSectionView.setViewListener(this::onViewActivated); + PowerManager pm = context.getSystemService(PowerManager.class); + mDarkModeSectionView.setEnabled(!pm.isPowerSaveMode()); + return mDarkModeSectionView; + } + + private void onViewActivated(Context context, boolean viewActivated) { + if (context == null) { + return; + } + Switch switchView = mDarkModeSectionView.findViewById(R.id.dark_mode_toggle); + if (!switchView.isEnabled()) { + Toast disableToast = Toast.makeText(mContext, + mContext.getString(R.string.mode_disabled_msg), Toast.LENGTH_SHORT); + disableToast.show(); + return; + } + UiModeManager uiModeManager = context.getSystemService(UiModeManager.class); + uiModeManager.setNightModeActivated(viewActivated); + } + + private class BatterySaverStateReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (TextUtils.equals(intent.getAction(), ACTION_POWER_SAVE_MODE_CHANGED) + && mDarkModeSectionView != null) { + mDarkModeSectionView.setEnabled(!mPowerManager.isPowerSaveMode()); + } + } + } +} diff --git a/src/com/android/customization/model/mode/ModeSection.java b/src/com/android/customization/model/mode/ModeSection.java deleted file mode 100644 index 9096e07c..00000000 --- a/src/com/android/customization/model/mode/ModeSection.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source 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 com.android.customization.model.mode; - - -import static android.Manifest.permission.MODIFY_DAY_NIGHT_MODE; -import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static android.os.PowerManager.ACTION_POWER_SAVE_MODE_CHANGED; - -import android.app.UiModeManager; -import android.content.Context; -import android.content.IntentFilter; -import android.os.PowerManager; -import android.view.LayoutInflater; -import android.widget.Switch; -import android.widget.Toast; - -import androidx.annotation.MainThread; -import androidx.core.content.ContextCompat; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleObserver; -import androidx.lifecycle.OnLifecycleEvent; - -import com.android.customization.picker.mode.ModeSectionView; -import com.android.wallpaper.R; -import com.android.wallpaper.model.HubSectionController; -import com.android.wallpaper.model.HubSectionController.HubSectionBatterySaverListener; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * Section for dark theme toggle that controls if this section will be shown visually - */ -public class ModeSection implements HubSectionController, LifecycleObserver, - HubSectionBatterySaverListener { - - private final Lifecycle mLifecycle; - private final BatterySaverStateReceiver mBatterySaverStateReceiver; - - private static ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); - - private Context mContext; - private ModeSectionView mModeSectionView; - - public ModeSection(Context context, Lifecycle lifecycle) { - mContext = context; - mLifecycle = lifecycle; - mBatterySaverStateReceiver = new BatterySaverStateReceiver(this); - mLifecycle.addObserver(this); - } - - @OnLifecycleEvent(Lifecycle.Event.ON_START) - @MainThread - public void onStart() { - sExecutorService.submit(() -> { - if (mContext != null && mLifecycle.getCurrentState().isAtLeast( - Lifecycle.State.STARTED)) { - mContext.registerReceiver(mBatterySaverStateReceiver, - new IntentFilter(ACTION_POWER_SAVE_MODE_CHANGED)); - } - }); - } - - @OnLifecycleEvent(Lifecycle.Event.ON_STOP) - @MainThread - public void onStop() { - sExecutorService.submit(() -> { - if (mContext != null && mBatterySaverStateReceiver != null) { - mContext.unregisterReceiver(mBatterySaverStateReceiver); - } - }); - } - - @Override - public void release() { - mLifecycle.removeObserver(this); - mContext = null; - } - - @Override - public boolean isAvailable(Context context) { - if (context == null) { - return false; - } - return ContextCompat.checkSelfPermission(context, MODIFY_DAY_NIGHT_MODE) - == PERMISSION_GRANTED; - } - - @Override - public ModeSectionView createView(Context context) { - mModeSectionView = (ModeSectionView) LayoutInflater.from( - context).inflate(R.layout.mode_section_view, /* root= */ null); - mModeSectionView.setViewListener(this::onViewActivated); - PowerManager pm = context.getSystemService(PowerManager.class); - mModeSectionView.setEnabled(!pm.isPowerSaveMode()); - return mModeSectionView; - } - - private void onViewActivated(Context context, boolean viewActivated) { - if (context == null) { - return; - } - Switch switchView = mModeSectionView.findViewById(R.id.dark_mode_toggle); - if (!switchView.isEnabled()) { - Toast disableToast = Toast.makeText(mContext, - mContext.getString(R.string.mode_disabled_msg), Toast.LENGTH_SHORT); - disableToast.show(); - return; - } - UiModeManager uiModeManager = context.getSystemService(UiModeManager.class); - uiModeManager.setNightModeActivated(viewActivated); - } - - @Override - public void onBatterySaverStateChanged(boolean isEnabled) { - mModeSectionView.setEnabled(!isEnabled); - } -} diff --git a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java index 32fbfa87..9ec5c2cb 100644 --- a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java +++ b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java @@ -22,14 +22,15 @@ import androidx.annotation.Nullable; import com.android.customization.picker.themedicon.ThemedIconSectionView; import com.android.wallpaper.R; -import com.android.wallpaper.model.HubSectionController; +import com.android.wallpaper.model.CustomizationSectionController; import com.android.wallpaper.model.WorkspaceViewModel; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -/** The {@link HubSectionController} for themed icon section. */ -public class ThemedIconSectionController implements HubSectionController { +/** The {@link CustomizationSectionController} for themed icon section. */ +public class ThemedIconSectionController implements + CustomizationSectionController { private final ThemedIconSwitchProvider mThemedIconOptionsProvider; private final WorkspaceViewModel mWorkspaceViewModel; diff --git a/src/com/android/customization/module/CustomizationInjector.java b/src/com/android/customization/module/CustomizationInjector.java index 722ebb3c..85853deb 100644 --- a/src/com/android/customization/module/CustomizationInjector.java +++ b/src/com/android/customization/module/CustomizationInjector.java @@ -16,11 +16,9 @@ package com.android.customization.module; import android.content.Context; -import android.content.Intent; import androidx.fragment.app.FragmentActivity; -import com.android.customization.model.CustomizationManager; import com.android.customization.model.theme.OverlayManagerCompat; import com.android.customization.model.theme.ThemeBundleProvider; import com.android.customization.model.theme.ThemeManager; @@ -32,31 +30,4 @@ public interface CustomizationInjector extends Injector { ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger); - - /** - * Obtain an extra CustomizationManager to add to the bottom nav - */ - default CustomizationManager getExtraManager(FragmentActivity activity, - OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger eventLogger) { - return null; - } - - /** - * Obtain an extra Customization intent to start Activity if any. - * - * @param context The {@link Context} of the application - * @return intent The {@link Intent} to start Activity - */ - default Intent getCustomizeExtIntent(Context context) { - return null; - } - - /** - * Check if the system supporting customization extension. - * - * @return {@code true} if the system supports customization extension, {@code false} otherwise. - */ - default boolean supportsCustomizationExtended(Context context) { - return false; - } } diff --git a/src/com/android/customization/module/DefaultCustomizationInjector.java b/src/com/android/customization/module/DefaultCustomizationInjector.java index 5b5c11ef..24dfb588 100644 --- a/src/com/android/customization/module/DefaultCustomizationInjector.java +++ b/src/com/android/customization/module/DefaultCustomizationInjector.java @@ -31,8 +31,8 @@ import com.android.customization.model.theme.ThemeManager; import com.android.wallpaper.model.CategoryProvider; import com.android.wallpaper.model.WallpaperInfo; import com.android.wallpaper.module.BaseWallpaperInjector; +import com.android.wallpaper.module.CustomizationSections; import com.android.wallpaper.module.DefaultCategoryProvider; -import com.android.wallpaper.module.HubSections; import com.android.wallpaper.module.LoggingOptInStatusProvider; import com.android.wallpaper.module.WallpaperPreferences; import com.android.wallpaper.module.WallpaperRotationRefresher; @@ -47,7 +47,7 @@ public class DefaultCustomizationInjector extends BaseWallpaperInjector private WallpaperRotationRefresher mWallpaperRotationRefresher; private PerformanceMonitor mPerformanceMonitor; private WallpaperPreferences mPrefs; - private HubSections mHubSections; + private CustomizationSections mCustomizationSections; @Override public synchronized WallpaperPreferences getPreferences(Context context) { @@ -142,10 +142,10 @@ public class DefaultCustomizationInjector extends BaseWallpaperInjector } @Override - public HubSections getHubSections() { - if (mHubSections == null) { - mHubSections = new DefaultCustomizationSections(); + public CustomizationSections getCustomizationSections() { + if (mCustomizationSections == null) { + mCustomizationSections = new DefaultCustomizationSections(); } - return mHubSections; + return mCustomizationSections; } } diff --git a/src/com/android/customization/module/DefaultCustomizationSections.java b/src/com/android/customization/module/DefaultCustomizationSections.java index d35d1982..db9218fa 100644 --- a/src/com/android/customization/module/DefaultCustomizationSections.java +++ b/src/com/android/customization/module/DefaultCustomizationSections.java @@ -8,42 +8,44 @@ import androidx.lifecycle.LifecycleOwner; import com.android.customization.model.grid.GridOptionsManager; import com.android.customization.model.grid.GridSectionController; -import com.android.customization.model.mode.ModeSection; +import com.android.customization.model.mode.DarkModeSectionController; import com.android.customization.model.themedicon.ThemedIconSectionController; import com.android.customization.model.themedicon.ThemedIconSwitchProvider; import com.android.customization.model.themedicon.ThemedIconUtils; import com.android.wallpaper.R; -import com.android.wallpaper.model.HubSectionController; +import com.android.wallpaper.model.CustomizationSectionController; +import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController; import com.android.wallpaper.model.PermissionRequester; import com.android.wallpaper.model.WallpaperColorsViewModel; import com.android.wallpaper.model.WallpaperPreviewNavigator; import com.android.wallpaper.model.WallpaperSectionController; import com.android.wallpaper.model.WorkspaceViewModel; -import com.android.wallpaper.module.HubSections; +import com.android.wallpaper.module.CustomizationSections; import java.util.ArrayList; import java.util.List; -/** {@link HubSections} for the customization picker. */ -public final class DefaultCustomizationSections implements HubSections { +/** {@link CustomizationSections} for the customization picker. */ +public final class DefaultCustomizationSections implements CustomizationSections { @Override - public List> getAllSectionControllers(Activity activity, + public List> getAllSectionControllers(Activity activity, LifecycleOwner lifecycleOwner, WallpaperColorsViewModel wallpaperColorsViewModel, WorkspaceViewModel workspaceViewModel, PermissionRequester permissionRequester, WallpaperPreviewNavigator wallpaperPreviewNavigator, - HubSectionController.HubSectionNavigationController hubSectionNavigationController, + CustomizationSectionNavigationController sectionNavigationController, @Nullable Bundle savedInstanceState) { - List> sectionControllers = new ArrayList<>(); + List> sectionControllers = new ArrayList<>(); // Wallpaper section. sectionControllers.add(new WallpaperSectionController( activity, lifecycleOwner, permissionRequester, wallpaperColorsViewModel, - workspaceViewModel, hubSectionNavigationController, wallpaperPreviewNavigator, + workspaceViewModel, sectionNavigationController, wallpaperPreviewNavigator, savedInstanceState)); // Dark/Light theme section. - sectionControllers.add(new ModeSection(activity, lifecycleOwner.getLifecycle())); + sectionControllers.add(new DarkModeSectionController(activity, + lifecycleOwner.getLifecycle())); // Themed app icon section. sectionControllers.add(new ThemedIconSectionController( @@ -53,7 +55,7 @@ public final class DefaultCustomizationSections implements HubSections { // App grid section. sectionControllers.add(new GridSectionController( - GridOptionsManager.get(activity), hubSectionNavigationController)); + GridOptionsManager.getInstance(activity), sectionNavigationController)); return sectionControllers; } diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java index 18fb5a75..45cc18d8 100644 --- a/src/com/android/customization/picker/grid/GridFragment.java +++ b/src/com/android/customization/picker/grid/GridFragment.java @@ -134,7 +134,7 @@ public class GridFragment extends AppbarFragment { // Clear memory cache whenever grid fragment view is being loaded. Glide.get(getContext()).clearMemory(); - mGridManager = GridOptionsManager.get(getContext()); + mGridManager = GridOptionsManager.getInstance(getContext()); mEventLogger = (ThemesUserEventLogger) InjectorProvider.getInjector() .getUserEventLogger(getContext()); setUpOptions(savedInstanceState); diff --git a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java index fc724dbc..f4b0219a 100644 --- a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java +++ b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java @@ -89,7 +89,7 @@ public class GridFullPreviewFragment extends AppbarFragment { SurfaceView wallpaperSurface = view.findViewById(R.id.wallpaper_preview_surface); mWallpaperPreviewer = new WallpaperPreviewer( getLifecycle(), getActivity(), wallpaperPreviewImage, wallpaperSurface); - mGridOptionPreviewer = new GridOptionPreviewer(GridOptionsManager.get(getContext()), + mGridOptionPreviewer = new GridOptionPreviewer(GridOptionsManager.getInstance(getContext()), view.findViewById(R.id.grid_preview_container)); return view; } diff --git a/src/com/android/customization/picker/mode/DarkModeSectionView.java b/src/com/android/customization/picker/mode/DarkModeSectionView.java new file mode 100644 index 00000000..64b46222 --- /dev/null +++ b/src/com/android/customization/picker/mode/DarkModeSectionView.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 The Android Open Source 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 com.android.customization.picker.mode; + +import android.content.Context; +import android.content.res.Configuration; +import android.util.AttributeSet; +import android.widget.Switch; + +import androidx.annotation.Nullable; + +import com.android.wallpaper.R; +import com.android.wallpaper.picker.SectionView; + +/** The view of section in the customization picker fragment. */ +public final class DarkModeSectionView extends SectionView { + + private boolean mIsDarkModeActivated; + + public DarkModeSectionView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + setTitle(context.getString(R.string.mode_title)); + mIsDarkModeActivated = (context.getResources().getConfiguration().uiMode + & Configuration.UI_MODE_NIGHT_YES) != 0; + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + Switch switchView = findViewById(R.id.dark_mode_toggle); + switchView.setChecked(mIsDarkModeActivated); + switchView.setOnCheckedChangeListener((buttonView, isChecked) -> + switchView.setChecked(mIsDarkModeActivated) + ); + setOnClickListener( + view -> switchView.postDelayed(() -> modeToggleClicked(), /* delayMillis= */ 100)); + } + + private void modeToggleClicked() { + mIsDarkModeActivated = !mIsDarkModeActivated; + viewActivated(mIsDarkModeActivated); + } + + private void viewActivated(boolean isChecked) { + if (mSectionViewListener != null) { + mSectionViewListener.onViewActivated(getContext(), isChecked); + } + } + + @Override + public void setEnabled(boolean enabled) { + final int numOfChildViews = getChildCount(); + for (int i = 0; i < numOfChildViews; i++) { + getChildAt(i).setEnabled(enabled); + } + } +} diff --git a/src/com/android/customization/picker/mode/ModeSectionView.java b/src/com/android/customization/picker/mode/ModeSectionView.java deleted file mode 100644 index 37e90a5d..00000000 --- a/src/com/android/customization/picker/mode/ModeSectionView.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source 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 com.android.customization.picker.mode; - -import android.content.Context; -import android.content.res.Configuration; -import android.util.AttributeSet; -import android.widget.Switch; - -import androidx.annotation.Nullable; - -import com.android.wallpaper.R; -import com.android.wallpaper.picker.SectionView; - -/** - * The view of section in the Customization Hub fragment. - */ -public final class ModeSectionView extends SectionView { - - private boolean mIsDarkModeActivated; - - public ModeSectionView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - setTitle(context.getString(R.string.mode_title)); - mIsDarkModeActivated = (context.getResources().getConfiguration().uiMode - & Configuration.UI_MODE_NIGHT_YES) != 0; - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - Switch switchView = findViewById(R.id.dark_mode_toggle); - switchView.setChecked(mIsDarkModeActivated); - switchView.setOnCheckedChangeListener((buttonView, isChecked) -> - switchView.setChecked(mIsDarkModeActivated) - ); - setOnClickListener( - view -> switchView.postDelayed(() -> modeToggleClicked(), /* delayMillis= */ 100)); - } - - private void modeToggleClicked() { - mIsDarkModeActivated = !mIsDarkModeActivated; - viewActivated(mIsDarkModeActivated); - } - - private void viewActivated(boolean isChecked) { - if (mSectionViewListener != null) { - mSectionViewListener.onViewActivated(getContext(), isChecked); - } - } - - @Override - public void setEnabled(boolean enabled) { - final int numOfChildViews = getChildCount(); - for (int i = 0; i < numOfChildViews; i++) { - getChildAt(i).setEnabled(enabled); - } - } -} -- cgit v1.2.3 From 5b4b42f74076e903a810b84129e0647493ca08b2 Mon Sep 17 00:00:00 2001 From: Chuck Liao Date: Wed, 16 Jun 2021 10:38:43 +0800 Subject: Rename the title of the first gird option Rename it from "Default" to "5x5" to avoid misleading when Launcher's default grid configuration is not 5x5. Screenshots: Before: https://screenshot.googleplex.com/4aTmiqZ3RUFbj3t.png After: https://screenshot.googleplex.com/6ecXhDa9mDUi9aC.png Bug: 191118996 Test: manual Change-Id: Ic2f0cfaf7d783b489123af7426d26742afd915c8 --- .../customization/model/grid/LauncherGridOptionsProvider.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java index aeb6e713..fd403631 100644 --- a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java +++ b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java @@ -48,9 +48,6 @@ public class LauncherGridOptionsProvider { private static final String COL_PREVIEW_COUNT = "preview_count"; private static final String COL_IS_DEFAULT = "is_default"; - // Normal gird size name - private static final String GRID_NAME_NORMAL = "normal"; - private static final String METADATA_KEY_PREVIEW_VERSION = "preview_version"; private final Context mContext; @@ -91,9 +88,7 @@ public class LauncherGridOptionsProvider { int cols = c.getInt(c.getColumnIndex(COL_COLS)); int previewCount = c.getInt(c.getColumnIndex(COL_PREVIEW_COUNT)); boolean isSet = Boolean.parseBoolean(c.getString(c.getColumnIndex(COL_IS_DEFAULT))); - String title = GRID_NAME_NORMAL.equals(name) - ? mContext.getString(R.string.default_theme_title) - : mContext.getString(R.string.grid_title_pattern, cols, rows); + String title = mContext.getString(R.string.grid_title_pattern, cols, rows); mOptions.add(new GridOption(title, name, isSet, rows, cols, mPreviewUtils.getUri(PREVIEW), previewCount, iconPath)); } -- cgit v1.2.3