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

Commit 8e191fd9 authored by Fengjiang Li's avatar Fengjiang Li Committed by Android (Google) Code Review
Browse files

Merge "[4/n] Add Apply Button to grid preview page" into udc-qpr-dev

parents 8d49225c b93ff3d9
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -88,6 +88,24 @@

        </FrameLayout>

        <Button
            android:id="@+id/apply_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:visibility="gone"
            android:enabled="false"
            style="@style/ActionPrimaryButton"
            android:text="@string/apply_btn" />

        <TextView
            android:id="@+id/apply_button_note"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:textSize="@dimen/grid_apply_button_note_text_size"
            android:visibility="gone"
            android:text="@string/apply_grid_btn_note" />
    </LinearLayout>

</LinearLayout>
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@
    <!-- Dimensions for the grid options -->
    <dimen name="grid_options_container_bottom_margin">@dimen/bottom_actions_height</dimen>
    <dimen name="grid_options_container_horizontal_margin">24dp</dimen>
    <dimen name="grid_apply_button_note_text_size">11sp</dimen>

    <dimen name="card_title_text_size">16sp</dimen>
    <dimen name="card_header_icon_size">32dp</dimen>
+9 −0
Original line number Diff line number Diff line
@@ -178,6 +178,15 @@
    <!--Title for a grid option, describing the number of columns and rows, eg: 4x4 [CHAR LIMIT=10] -->
    <string name="grid_title_pattern"><xliff:g name="num_cols" example="1">%1$d</xliff:g>x<xliff:g name="num_rows" example="1">%2$d</xliff:g></string>

    <!-- Label of what will happen when user tap on apply button to change grid. [CHAR LIMIT=50] -->
    <string name="apply_grid_btn_note">Changing grid size will reload workspace and may take a few seconds.</string>

    <!-- Toast of reloading workspace with new grid. -->
    <string name="toast_of_changing_grid">Reloading workspace with %1$s grid</string>

    <!-- Toast of failure to reload workspace with new grid. -->
    <string name="toast_of_failure_to_change_grid">Failed to reload workspace with %1$s grid</string>

    <!-- Message shown when a theme has been applied successfully in the system [CHAR LIMIT=NONE] -->
    <string name="applied_theme_msg">Style set successfully</string>

+6 −6
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
        }
    };

    private final String mTitle;
    private final String mIconShapePath;
    private final GridTileDrawable mTileDrawable;
    public final String title;
    public final String name;
    public final int rows;
    public final int cols;
@@ -60,7 +60,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {

    public GridOption(String title, String name, boolean isCurrent, int rows, int cols,
            Uri previewImageUri, int previewPagesCount, String iconShapePath) {
        mTitle = title;
        this.title = title;
        mIsCurrent = isCurrent;
        mIconShapePath = iconShapePath;
        mTileDrawable = new GridTileDrawable(rows, cols, mIconShapePath);
@@ -76,7 +76,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
    }

    protected GridOption(Parcel in) {
        mTitle = in.readString();
        title = in.readString();
        mIsCurrent = in.readByte() != 0;
        mIconShapePath = in.readString();
        name = in.readString();
@@ -89,7 +89,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {

    @Override
    public String getTitle() {
        return mTitle;
        return title;
    }

    @Override
@@ -143,7 +143,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(mTitle);
        parcel.writeString(title);
        parcel.writeByte((byte) (mIsCurrent ? 1 : 0));
        parcel.writeString(mIconShapePath);
        parcel.writeString(name);
@@ -158,7 +158,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
        return String.format(
                "GridOption{mTitle='%s', mIsCurrent=%s, mTileDrawable=%s, name='%s', rows=%d, "
                        + "cols=%d, previewImageUri=%s, previewPagesCount=%d}\n",
                mTitle, mIsCurrent, mTileDrawable, name, rows, cols, previewImageUri,
                title, mIsCurrent, mTileDrawable, name, rows, cols, previewImageUri,
                previewPagesCount);
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.lifecycle.MutableLiveData;

import com.android.customization.model.ResourceConstants;
import com.android.wallpaper.R;
import com.android.wallpaper.config.BaseFlags;
import com.android.wallpaper.util.PreviewUtils;

import java.util.ArrayList;
@@ -57,12 +58,14 @@ public class LauncherGridOptionsProvider {

    private final Context mContext;
    private final PreviewUtils mPreviewUtils;
    private final boolean mIsGridApplyButtonEnabled;
    private List<GridOption> mOptions;
    private OptionChangeLiveData mLiveData;

    public LauncherGridOptionsProvider(Context context, String authorityMetadataKey) {
        mPreviewUtils = new PreviewUtils(context, authorityMetadataKey);
        mContext = context;
        mIsGridApplyButtonEnabled = BaseFlags.get().isGridApplyButtonEnabled(context);
    }

    boolean areGridsAvailable() {
@@ -124,6 +127,7 @@ public class LauncherGridOptionsProvider {
    int applyGrid(String name) {
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("enable_apply_button", mIsGridApplyButtonEnabled);
        return mContext.getContentResolver().update(mPreviewUtils.getUri(DEFAULT_GRID), values,
                null, null);
    }
@@ -157,6 +161,14 @@ public class LauncherGridOptionsProvider {
            mContentObserver = new ContentObserver(handler) {
                @Override
                public void onChange(boolean selfChange) {
                    // If grid apply button is enabled, user has previewed the grid before applying
                    // the grid change. Thus there is no need to preview again (which will cause a
                    // blank preview as launcher's is loader thread is busy reloading workspace)
                    // after applying grid change. Thus we should ignore ContentObserver#onChange
                    // from launcher
                    if (BaseFlags.get().isGridApplyButtonEnabled(context.getApplicationContext())) {
                        return;
                    }
                    postValue(new Object());
                }
            };
Loading