Loading src/com/android/customization/model/CustomizationManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.customization.model; import android.util.Log; import android.widget.Toast; import androidx.annotation.Nullable; Loading @@ -28,6 +27,20 @@ import java.util.List; */ public interface CustomizationManager<T extends CustomizationOption> { /** * Create a new {@link CustomizationSection} corresponding to this Manager */ default CustomizationSection<T> 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. */ Loading src/com/android/customization/model/CustomizationSection.java 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * 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 <T> CustomizationOption that this section represents. */ public abstract class CustomizationSection<T extends CustomizationOption> { /** * IdRes used to identify this section in the BottomNavigationView menu. */ @IdRes public final int id; protected final CustomizationManager<T> mCustomizationManager; public CustomizationSection(@IdRes int id, CustomizationManager<T> manager) { this.id = id; mCustomizationManager = manager; } /** * @return the Fragment corresponding to this section. */ public abstract Fragment getFragment(Context c); public CustomizationManager<T> getCustomizationManager() { return mCustomizationManager; } } src/com/android/customization/module/CustomizationInjector.java +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.Context; 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; Loading @@ -30,4 +31,12 @@ 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; } } src/com/android/customization/picker/CustomizationFragmentHost.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * 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; import com.android.customization.model.CustomizationManager; /** * Interface to be implemented by an Activity hosting any Customization Fragment */ public interface CustomizationFragmentHost { /** * Gets the CustomizationManager manager for the given section * @return the {@link CustomizationManager} */ CustomizationManager<?> getCustomizationManager(int sectionId); } src/com/android/customization/picker/CustomizationPickerActivity.java +25 −39 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.customization.picker; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; Loading @@ -37,7 +38,7 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import com.android.customization.model.CustomizationManager; import com.android.customization.model.CustomizationOption; import com.android.customization.model.CustomizationSection; import com.android.customization.model.clock.ClockManager; import com.android.customization.model.clock.Clockface; import com.android.customization.model.clock.ContentProviderClockProvider; Loading Loading @@ -90,8 +91,9 @@ import java.util.Map; * Fragments providing customization options. */ public class CustomizationPickerActivity extends FragmentActivity implements WallpapersUiContainer, CategoryFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost, BottomActionBarHost, FragmentTransactionChecker { CategoryFragmentHost, CustomizationFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost, BottomActionBarHost, FragmentTransactionChecker { public static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR"; Loading Loading @@ -180,7 +182,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal // Keep CategoryFragment's design to load category within its fragment if (section instanceof WallpaperSection) { switchFragment(section); section.onVisible(); } } Loading Loading @@ -232,6 +233,11 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector(); ThemesUserEventLogger eventLogger = (ThemesUserEventLogger) injector.getUserEventLogger( this); CustomizationManager<?> extraManager = injector.getExtraManager( this, new OverlayManagerCompat(this), eventLogger); if (extraManager != null && extraManager.isAvailable()) { mSections.put(extraManager.getNavId(), extraManager.createSection()); } ThemeManager themeManager = injector.getThemeManager( new DefaultThemeProvider(this, injector.getCustomizationPreferences(this)), this, new OverlayManagerCompat(this), eventLogger); Loading Loading @@ -280,7 +286,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal int id = item.getItemId(); CustomizationSection section = mSections.get(id); switchFragment(section); section.onVisible(); String name = getResources().getResourceName(id); if (!prefs.getTabVisited(name)) { prefs.setTabVisited(name); Loading Loading @@ -357,7 +362,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal private void switchFragment(CustomizationSection section) { final FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = section.getFragment(); Fragment fragment = section.getFragment(this); final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); Loading Loading @@ -427,22 +432,29 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal return mDelegate; } @Override public CustomizationManager<?> getCustomizationManager(int id) { CustomizationSection<?> section = mSections.get(id); return section == null ? null : section.getCustomizationManager(); } @Override public ClockManager getClockManager() { CustomizationSection section = mSections.get(R.id.nav_clock); return section == null ? null : (ClockManager) section.customizationManager; return section == null ? null : (ClockManager) section.getCustomizationManager(); } @Override public GridOptionsManager getGridOptionsManager() { CustomizationSection section = mSections.get(R.id.nav_grid); return section == null ? null : (GridOptionsManager) section.customizationManager; return section == null ? null : (GridOptionsManager) section.getCustomizationManager(); } @Override public ThemeManager getThemeManager() { CustomizationSection section = mSections.get(R.id.nav_theme); return section == null ? null : (ThemeManager) section.customizationManager; return section == null ? null : (ThemeManager) section.getCustomizationManager(); } @Override Loading Loading @@ -475,32 +487,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal return mIsSafeToCommitFragmentTransaction; } /** * 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. */ static abstract class CustomizationSection<T extends CustomizationOption> { /** * IdRes used to identify this section in the BottomNavigationView menu. */ @IdRes final int id; protected final CustomizationManager<T> customizationManager; private CustomizationSection(@IdRes int id, CustomizationManager<T> manager) { this.id = id; this.customizationManager = manager; } /** * @return the Fragment corresponding to this section. */ abstract Fragment getFragment(); void onVisible() {} } /** * {@link CustomizationSection} corresponding to the "Wallpaper" section of the Picker. */ Loading @@ -511,7 +497,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mWallpaperCategoryFragment == null) { mWallpaperCategoryFragment = CategoryFragment.newInstance( getString(R.string.wallpaper_title)); Loading @@ -529,7 +515,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = ThemeFragment.newInstance(getString(R.string.theme_title)); } Loading @@ -546,7 +532,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = GridFragment.newInstance(getString(R.string.grid_title)); } Loading @@ -563,7 +549,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = ClockFragment.newInstance(getString(R.string.clock_title)); } Loading Loading
src/com/android/customization/model/CustomizationManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.customization.model; import android.util.Log; import android.widget.Toast; import androidx.annotation.Nullable; Loading @@ -28,6 +27,20 @@ import java.util.List; */ public interface CustomizationManager<T extends CustomizationOption> { /** * Create a new {@link CustomizationSection} corresponding to this Manager */ default CustomizationSection<T> 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. */ Loading
src/com/android/customization/model/CustomizationSection.java 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * 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 <T> CustomizationOption that this section represents. */ public abstract class CustomizationSection<T extends CustomizationOption> { /** * IdRes used to identify this section in the BottomNavigationView menu. */ @IdRes public final int id; protected final CustomizationManager<T> mCustomizationManager; public CustomizationSection(@IdRes int id, CustomizationManager<T> manager) { this.id = id; mCustomizationManager = manager; } /** * @return the Fragment corresponding to this section. */ public abstract Fragment getFragment(Context c); public CustomizationManager<T> getCustomizationManager() { return mCustomizationManager; } }
src/com/android/customization/module/CustomizationInjector.java +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.Context; 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; Loading @@ -30,4 +31,12 @@ 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; } }
src/com/android/customization/picker/CustomizationFragmentHost.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * 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; import com.android.customization.model.CustomizationManager; /** * Interface to be implemented by an Activity hosting any Customization Fragment */ public interface CustomizationFragmentHost { /** * Gets the CustomizationManager manager for the given section * @return the {@link CustomizationManager} */ CustomizationManager<?> getCustomizationManager(int sectionId); }
src/com/android/customization/picker/CustomizationPickerActivity.java +25 −39 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.customization.picker; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; Loading @@ -37,7 +38,7 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import com.android.customization.model.CustomizationManager; import com.android.customization.model.CustomizationOption; import com.android.customization.model.CustomizationSection; import com.android.customization.model.clock.ClockManager; import com.android.customization.model.clock.Clockface; import com.android.customization.model.clock.ContentProviderClockProvider; Loading Loading @@ -90,8 +91,9 @@ import java.util.Map; * Fragments providing customization options. */ public class CustomizationPickerActivity extends FragmentActivity implements WallpapersUiContainer, CategoryFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost, BottomActionBarHost, FragmentTransactionChecker { CategoryFragmentHost, CustomizationFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost, BottomActionBarHost, FragmentTransactionChecker { public static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR"; Loading Loading @@ -180,7 +182,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal // Keep CategoryFragment's design to load category within its fragment if (section instanceof WallpaperSection) { switchFragment(section); section.onVisible(); } } Loading Loading @@ -232,6 +233,11 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector(); ThemesUserEventLogger eventLogger = (ThemesUserEventLogger) injector.getUserEventLogger( this); CustomizationManager<?> extraManager = injector.getExtraManager( this, new OverlayManagerCompat(this), eventLogger); if (extraManager != null && extraManager.isAvailable()) { mSections.put(extraManager.getNavId(), extraManager.createSection()); } ThemeManager themeManager = injector.getThemeManager( new DefaultThemeProvider(this, injector.getCustomizationPreferences(this)), this, new OverlayManagerCompat(this), eventLogger); Loading Loading @@ -280,7 +286,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal int id = item.getItemId(); CustomizationSection section = mSections.get(id); switchFragment(section); section.onVisible(); String name = getResources().getResourceName(id); if (!prefs.getTabVisited(name)) { prefs.setTabVisited(name); Loading Loading @@ -357,7 +362,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal private void switchFragment(CustomizationSection section) { final FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = section.getFragment(); Fragment fragment = section.getFragment(this); final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); Loading Loading @@ -427,22 +432,29 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal return mDelegate; } @Override public CustomizationManager<?> getCustomizationManager(int id) { CustomizationSection<?> section = mSections.get(id); return section == null ? null : section.getCustomizationManager(); } @Override public ClockManager getClockManager() { CustomizationSection section = mSections.get(R.id.nav_clock); return section == null ? null : (ClockManager) section.customizationManager; return section == null ? null : (ClockManager) section.getCustomizationManager(); } @Override public GridOptionsManager getGridOptionsManager() { CustomizationSection section = mSections.get(R.id.nav_grid); return section == null ? null : (GridOptionsManager) section.customizationManager; return section == null ? null : (GridOptionsManager) section.getCustomizationManager(); } @Override public ThemeManager getThemeManager() { CustomizationSection section = mSections.get(R.id.nav_theme); return section == null ? null : (ThemeManager) section.customizationManager; return section == null ? null : (ThemeManager) section.getCustomizationManager(); } @Override Loading Loading @@ -475,32 +487,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal return mIsSafeToCommitFragmentTransaction; } /** * 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. */ static abstract class CustomizationSection<T extends CustomizationOption> { /** * IdRes used to identify this section in the BottomNavigationView menu. */ @IdRes final int id; protected final CustomizationManager<T> customizationManager; private CustomizationSection(@IdRes int id, CustomizationManager<T> manager) { this.id = id; this.customizationManager = manager; } /** * @return the Fragment corresponding to this section. */ abstract Fragment getFragment(); void onVisible() {} } /** * {@link CustomizationSection} corresponding to the "Wallpaper" section of the Picker. */ Loading @@ -511,7 +497,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mWallpaperCategoryFragment == null) { mWallpaperCategoryFragment = CategoryFragment.newInstance( getString(R.string.wallpaper_title)); Loading @@ -529,7 +515,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = ThemeFragment.newInstance(getString(R.string.theme_title)); } Loading @@ -546,7 +532,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = GridFragment.newInstance(getString(R.string.grid_title)); } Loading @@ -563,7 +549,7 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override Fragment getFragment() { public Fragment getFragment(Context c) { if (mFragment == null) { mFragment = ClockFragment.newInstance(getString(R.string.clock_title)); } Loading