Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e91f9aa authored by chihhangchuang's avatar chihhangchuang
Browse files

[2/3] Create BottomActionBarFragment for BottomActionBar

- BottomActionBar will be avaible for extending fragments.
- Extending fragemnts won't handle reset BottomActionBar anymore.
- All the back key event for BottomActionBar will be handled by BottomActionBarFragment, won't distribute in fragments.

Idea graph: https://screenshot.googleplex.com/aNQVz6Di7B7.png

Test: Manually
Bug: 151287328
Change-Id: Ie990855a619bbee4683f75bf4913cf8717d193ac
parent 586de947
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import com.android.wallpaper.module.FormFactorChecker;
import com.android.wallpaper.module.Injector;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.module.UserEventLogger;
import com.android.wallpaper.picker.BottomActionBarFragment;
import com.android.wallpaper.picker.CategoryFragment;
import com.android.wallpaper.picker.CategoryFragment.CategoryFragmentHost;
import com.android.wallpaper.picker.MyPhotosStarter;
@@ -73,6 +74,7 @@ import com.android.wallpaper.picker.TopLevelPickerActivity;
import com.android.wallpaper.picker.WallpaperPickerDelegate;
import com.android.wallpaper.picker.WallpapersUiContainer;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.BottomActionBar.BottomActionBarHost;

import com.google.android.material.bottomnavigation.BottomNavigationView;

@@ -84,7 +86,8 @@ import java.util.Map;
 *  Fragments providing customization options.
 */
public class CustomizationPickerActivity extends FragmentActivity implements WallpapersUiContainer,
        CategoryFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost {
        CategoryFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost,
        BottomActionBarHost {

    private static final String TAG = "CustomizationPickerActivity";
    @VisibleForTesting static final String WALLPAPER_FLAVOR_EXTRA =
@@ -293,10 +296,9 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal
            return;
        }

        // For other tabs without child fragment. Hide the BottomActionBar if back key is pressed.
        BottomActionBar bottomActionBar = findViewById(R.id.bottom_actionbar);
        if (bottomActionBar != null && bottomActionBar.isVisible()) {
            bottomActionBar.hide();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
        if (fragment instanceof BottomActionBarFragment
                && ((BottomActionBarFragment) fragment).onBackPressed()) {
            return;
        }

@@ -409,6 +411,11 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal
        finish();
    }

    @Override
    public BottomActionBar getBottomActionBar() {
        return findViewById(R.id.bottom_actionbar);
    }

    /**
     * Represents a section of the Picker (eg "ThemeBundle", "Clock", etc).
     * There should be a concrete subclass per available section, providing the corresponding
+3 −3
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import com.android.customization.widget.OptionSelectorController;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.PreviewPager;

import java.util.List;
@@ -51,7 +51,7 @@ import java.util.List;
/**
 * Fragment that contains the main UI for selecting and applying a Clockface.
 */
public class ClockFragment extends ToolbarFragment {
public class ClockFragment extends AppbarFragment {

    private static final String TAG = "ClockFragment";

@@ -64,7 +64,7 @@ public class ClockFragment extends ToolbarFragment {

    public static ClockFragment newInstance(CharSequence title) {
        ClockFragment fragment = new ClockFragment();
        fragment.setArguments(ToolbarFragment.createArguments(title));
        fragment.setArguments(AppbarFragment.createArguments(title));
        return fragment;
    }

+8 −5
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ import com.android.wallpaper.asset.ContentUriAsset;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.util.SurfaceViewUtils;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.PreviewPager;
@@ -72,7 +72,7 @@ import java.util.List;
/**
 * Fragment that contains the UI for selecting and applying a GridOption.
 */
public class GridFragment extends ToolbarFragment {
public class GridFragment extends AppbarFragment {

    private static final int PREVIEW_FADE_DURATION_MS = 100;

@@ -87,7 +87,7 @@ public class GridFragment extends ToolbarFragment {

    public static GridFragment newInstance(CharSequence title) {
        GridFragment fragment = new GridFragment();
        fragment.setArguments(ToolbarFragment.createArguments(title));
        fragment.setArguments(AppbarFragment.createArguments(title));
        return fragment;
    }

@@ -167,8 +167,12 @@ public class GridFragment extends ToolbarFragment {
                loadWallpaperBackground();
            }
        });
        return view;
    }

        mBottomActionBar = getActivity().findViewById(R.id.bottom_actionbar);
    @Override
    protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
        mBottomActionBar = bottomActionBar;
        mBottomActionBar.showActionsOnly(EnumSet.of(CANCEL, APPLY));
        mBottomActionBar.setActionClickListener(CANCEL, unused -> getActivity().onBackPressed());
        mBottomActionBar.setActionClickListener(APPLY, unused -> {
@@ -185,7 +189,6 @@ public class GridFragment extends ToolbarFragment {
                }
            });
        });
        return view;
    }

    private void loadWallpaperBackground() {
+2 −9
Original line number Diff line number Diff line
@@ -15,27 +15,20 @@
 */
package com.android.customization.picker.theme;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.recyclerview.widget.RecyclerView;

import com.android.customization.model.theme.custom.CustomThemeManager;
import com.android.customization.model.theme.custom.ThemeComponentOption;
import com.android.customization.model.theme.custom.ThemeComponentOptionProvider;
import com.android.customization.widget.OptionSelectorController;
import com.android.wallpaper.R;
import com.android.wallpaper.picker.ToolbarFragment;
import com.android.wallpaper.picker.AppbarFragment;

public class CustomThemeComponentFragment extends CustomThemeStepFragment {
    private static final String ARG_USE_GRID_LAYOUT = "CustomThemeComponentFragment.use_grid";;
@@ -48,7 +41,7 @@ public class CustomThemeComponentFragment extends CustomThemeStepFragment {
    public static CustomThemeComponentFragment newInstance(CharSequence toolbarTitle, int position,
            int titleResId, boolean allowGridLayout) {
        CustomThemeComponentFragment fragment = new CustomThemeComponentFragment();
        Bundle arguments = ToolbarFragment.createArguments(toolbarTitle);
        Bundle arguments = AppbarFragment.createArguments(toolbarTitle);
        arguments.putInt(ARG_KEY_POSITION, position);
        arguments.putInt(ARG_KEY_TITLE_RES_ID, titleResId);
        arguments.putBoolean(ARG_USE_GRID_LAYOUT, allowGridLayout);
+2 −3
Original line number Diff line number Diff line
@@ -42,14 +42,14 @@ import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.BitmapCachingAsset;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
import com.android.wallpaper.picker.AppbarFragment;

public class CustomThemeNameFragment extends CustomThemeStepFragment {

    public static CustomThemeNameFragment newInstance(CharSequence toolbarTitle, int position,
            int titleResId) {
        CustomThemeNameFragment fragment = new CustomThemeNameFragment();
        Bundle arguments = ToolbarFragment.createArguments(toolbarTitle);
        Bundle arguments = AppbarFragment.createArguments(toolbarTitle);
        arguments.putInt(ARG_KEY_POSITION, position);
        arguments.putInt(ARG_KEY_TITLE_RES_ID, titleResId);
        fragment.setArguments(arguments);
@@ -104,7 +104,6 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
        mNameEditor = view.findViewById(R.id.custom_theme_name);
        mNameEditor.setText(mCustomThemeManager.getOriginalTheme().getTitle());
        bindCover(view.findViewById(R.id.component_preview_content));

        return view;
    }

Loading