Loading src/com/android/customization/model/mode/ModeSection.java +20 −9 Original line number Diff line number Diff line Loading @@ -39,15 +39,21 @@ 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<ModeSectionView>, LifecycleObserver, HubSectionBatterySaverListener { private final Lifecycle mLifecycle; private final BatterySaverStateReceiver mBatterySaverStateReceiver; private static ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); private Context mContext; private Lifecycle mLifecycle; private BatterySaverStateReceiver mBatterySaverStateReceiver; private ModeSectionView mModeSectionView; public ModeSection(Context context, Lifecycle lifecycle) { Loading @@ -60,18 +66,23 @@ public class ModeSection implements HubSectionController<ModeSectionView>, Lifec @OnLifecycleEvent(Lifecycle.Event.ON_START) @MainThread public void onStart() { if (mContext != null) { 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 Loading src/com/android/customization/model/themedicon/ThemedIconSectionController.java +10 −2 Original line number Diff line number Diff line Loading @@ -25,12 +25,17 @@ import com.android.wallpaper.R; import com.android.wallpaper.model.HubSectionController; 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<ThemedIconSectionView> { private final ThemedIconSwitchProvider mThemedIconOptionsProvider; private final WorkspaceViewModel mWorkspaceViewModel; private static ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); public ThemedIconSectionController(ThemedIconSwitchProvider themedIconOptionsProvider, WorkspaceViewModel workspaceViewModel) { mThemedIconOptionsProvider = themedIconOptionsProvider; Loading @@ -48,8 +53,11 @@ public class ThemedIconSectionController implements HubSectionController<ThemedI (ThemedIconSectionView) LayoutInflater.from(context).inflate( R.layout.themed_icon_section_view, /* root= */ null); themedIconColorSectionView.setViewListener(this::onViewActivated); themedIconColorSectionView.getSwitch() .setChecked(mThemedIconOptionsProvider.fetchThemedIconEnabled()); sExecutorService.submit(() -> { boolean themedIconEnabled = mThemedIconOptionsProvider.fetchThemedIconEnabled(); themedIconColorSectionView.post(() -> themedIconColorSectionView.getSwitch().setChecked(themedIconEnabled)); }); return themedIconColorSectionView; } Loading src/com/android/customization/picker/mode/ModeSectionView.java +2 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,8 @@ public final class ModeSectionView extends SectionView { switchView.setOnCheckedChangeListener((buttonView, isChecked) -> switchView.setChecked(mIsDarkModeActivated) ); setOnClickListener(view -> modeToggleClicked()); setOnClickListener( view -> switchView.postDelayed(() -> modeToggleClicked(), /* delayMillis= */ 100)); } private void modeToggleClicked() { Loading Loading
src/com/android/customization/model/mode/ModeSection.java +20 −9 Original line number Diff line number Diff line Loading @@ -39,15 +39,21 @@ 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<ModeSectionView>, LifecycleObserver, HubSectionBatterySaverListener { private final Lifecycle mLifecycle; private final BatterySaverStateReceiver mBatterySaverStateReceiver; private static ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); private Context mContext; private Lifecycle mLifecycle; private BatterySaverStateReceiver mBatterySaverStateReceiver; private ModeSectionView mModeSectionView; public ModeSection(Context context, Lifecycle lifecycle) { Loading @@ -60,18 +66,23 @@ public class ModeSection implements HubSectionController<ModeSectionView>, Lifec @OnLifecycleEvent(Lifecycle.Event.ON_START) @MainThread public void onStart() { if (mContext != null) { 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 Loading
src/com/android/customization/model/themedicon/ThemedIconSectionController.java +10 −2 Original line number Diff line number Diff line Loading @@ -25,12 +25,17 @@ import com.android.wallpaper.R; import com.android.wallpaper.model.HubSectionController; 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<ThemedIconSectionView> { private final ThemedIconSwitchProvider mThemedIconOptionsProvider; private final WorkspaceViewModel mWorkspaceViewModel; private static ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); public ThemedIconSectionController(ThemedIconSwitchProvider themedIconOptionsProvider, WorkspaceViewModel workspaceViewModel) { mThemedIconOptionsProvider = themedIconOptionsProvider; Loading @@ -48,8 +53,11 @@ public class ThemedIconSectionController implements HubSectionController<ThemedI (ThemedIconSectionView) LayoutInflater.from(context).inflate( R.layout.themed_icon_section_view, /* root= */ null); themedIconColorSectionView.setViewListener(this::onViewActivated); themedIconColorSectionView.getSwitch() .setChecked(mThemedIconOptionsProvider.fetchThemedIconEnabled()); sExecutorService.submit(() -> { boolean themedIconEnabled = mThemedIconOptionsProvider.fetchThemedIconEnabled(); themedIconColorSectionView.post(() -> themedIconColorSectionView.getSwitch().setChecked(themedIconEnabled)); }); return themedIconColorSectionView; } Loading
src/com/android/customization/picker/mode/ModeSectionView.java +2 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,8 @@ public final class ModeSectionView extends SectionView { switchView.setOnCheckedChangeListener((buttonView, isChecked) -> switchView.setChecked(mIsDarkModeActivated) ); setOnClickListener(view -> modeToggleClicked()); setOnClickListener( view -> switchView.postDelayed(() -> modeToggleClicked(), /* delayMillis= */ 100)); } private void modeToggleClicked() { Loading