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

Commit d95d371d authored by Joey's avatar Joey
Browse files

Implement new design specifications for apply buttons



Co-authored-by: default avatarAsher Simonds <dayanhammer@gmail.com>
Signed-off-by: default avatarJoey <joey@lineageos.org>
Change-Id: Ica1a684b7eff21b5ccc5757289d3b7ff3d254c94
parent 6c70c71e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -50,4 +50,5 @@ dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
}
+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.appcompat_appcompat \
    androidx.palette_palette \
    androidx.recyclerview_recyclerview \
    androidx.transition_transition
    androidx.transition_transition \
    com.google.android.material_material

LOCAL_PACKAGE_NAME := Backgrounds

+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@
        <activity
            android:name=".ui.ApplyActivity"
            android:excludeFromRecents="true"
            android:resizeableActivity="false" />
            android:resizeableActivity="false"
            android:theme="@style/AppTheme.PrimaryNav" />

        <provider
            android:name="androidx.core.content.FileProvider"
+71 −49
Original line number Diff line number Diff line
@@ -15,14 +15,16 @@
 */
package org.lineageos.backgrounds.ui;

import android.annotation.SuppressLint;
import android.app.WallpaperManager;
import android.content.ContentResolver;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -34,6 +36,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.google.android.material.bottomsheet.BottomSheetBehavior;

import org.lineageos.backgrounds.R;
import org.lineageos.backgrounds.bundle.WallpaperBundle;
import org.lineageos.backgrounds.task.ApplyWallpaperTask;
@@ -51,11 +55,9 @@ public final class ApplyActivity extends AppCompatActivity {
    private static final int LOCK_FLAG = WallpaperManager.FLAG_LOCK;

    private ImageView mPreviewView;
    private LinearLayout mApplyView;
    private TextView mBothView;
    private TextView mHomeView;
    private TextView mLockView;
    private ImageView mCloseView;

    private BottomSheetBehavior mApplySheetBehavior;
    private boolean mIsApplyingWallpaper = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstance) {
@@ -64,21 +66,26 @@ public final class ApplyActivity extends AppCompatActivity {
        setContentView(R.layout.activity_apply);

        mPreviewView = findViewById(R.id.apply_preview);
        mApplyView = findViewById(R.id.apply_button);
        mBothView = findViewById(R.id.apply_both);
        mHomeView = findViewById(R.id.apply_home);
        mLockView = findViewById(R.id.apply_lock);
        mCloseView = findViewById(R.id.apply_close);
        ImageView closeView = findViewById(R.id.apply_close);

        LinearLayout applySheetView = findViewById(R.id.apply_button);
        TextView bothView = findViewById(R.id.apply_both);
        TextView homeView = findViewById(R.id.apply_home);
        TextView lockView = findViewById(R.id.apply_lock);

        mBothView.setOnClickListener(v -> applyWallpaper(BOTH_FLAG));
        mHomeView.setOnClickListener(v -> applyWallpaper(HOME_FLAG));
        mLockView.setOnClickListener(v -> applyWallpaper(LOCK_FLAG));
        mCloseView.setOnClickListener(v -> finish());
        mApplySheetBehavior = BottomSheetBehavior.from(applySheetView);

        closeView.setOnClickListener(v -> quitIfDoingNothing());
        bothView.setOnClickListener(v -> applyWallpaper(BOTH_FLAG));
        homeView.setOnClickListener(v -> applyWallpaper(HOME_FLAG));
        lockView.setOnClickListener(v -> applyWallpaper(LOCK_FLAG));

        setup();
    }

    private void setup() {
        setupBottomSheet();

        final WallpaperBundle wallpaperBundle = getIntent().getParcelableExtra(EXTRA_WALLPAPER);
        if (wallpaperBundle == null) {
            return;
@@ -103,6 +110,34 @@ public final class ApplyActivity extends AppCompatActivity {
        }
    }

    private void setupBottomSheet() {
        mApplySheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @SuppressLint("SwitchIntDef")
            @Override
            public void onStateChanged(@NonNull View view, int i) {
            }

            @Override
            public void onSlide(@NonNull View view, float v) {
                /*  1 - Expanded
                 *  :
                 *  0 - Peek
                 *  :
                 * -1 - Hidden
                 */
                if (v == 1f || v == 0f || v == -1f) {
                    // Let the sliding sheet "lock in" the new position
                    view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK,
                            HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
                    // Quit if the user slides the sheet out
                    if (v == -1f) {
                        quitIfDoingNothing();
                    }
                }
            }
        });
    }

    private void setupBuiltIn(@NonNull final WallpaperBundle bundle) {
        Drawable drawable = ContextCompat.getDrawable(this, bundle.getDescriptor());
        displayPreview(drawable);
@@ -172,8 +207,9 @@ public final class ApplyActivity extends AppCompatActivity {
    }

    private void applyWallpaper(final int flags) {
        hideApplyButton();
        mCloseView.setClickable(false);
        hideApplyLayout();

        mIsApplyingWallpaper = true;

        final Drawable drawable = mPreviewView.getDrawable();

@@ -203,26 +239,18 @@ public final class ApplyActivity extends AppCompatActivity {

        mPreviewView.setImageDrawable(drawable);
        colorUi();
        showApplyButton();
        showApplyLayout();
    }

    private void showApplyButton() {
        mApplyView.setScaleX(0f);
        mApplyView.setScaleY(0f);
        mApplyView.setVisibility(View.VISIBLE);
        mApplyView.animate()
                .setStartDelay(350)
                .scaleX(1f)
                .scaleY(1f)
                .start();
    private void showApplyLayout() {
        mApplySheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

        new Handler().postDelayed(() ->
                mApplySheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED), 350);
    }

    private void hideApplyButton() {
        mApplyView.animate()
                .scaleX(0f)
                .scaleY(0f)
                .setDuration(250)
                .start();
    private void hideApplyLayout() {
        mApplySheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    }

    private void onWallpaperApplied(final boolean success) {
@@ -241,21 +269,15 @@ public final class ApplyActivity extends AppCompatActivity {
        final int color = ColorUtils.extractColor(ColorUtils.extractPalette(previewDrawable));

        // SystemUI
        UiUtils.setSystemUiColors(getWindow(), color);

        // Apply
        final ColorStateList backgroundList = ColorStateList.valueOf(color);
        mApplyView.setBackgroundTintList(backgroundList);

        final int actionsColor = getColor(ColorUtils.isColorLight(color) ?
                android.R.color.black : android.R.color.white);
        final ColorStateList actionsList = ColorStateList.valueOf(actionsColor);

        mBothView.setTextColor(actionsColor);
        mBothView.setCompoundDrawableTintList(actionsList);
        mHomeView.setTextColor(actionsColor);
        mHomeView.setCompoundDrawableTintList(actionsList);
        mLockView.setTextColor(actionsColor);
        mLockView.setCompoundDrawableTintList(actionsList);
        UiUtils.setStatusBarColor(getWindow(), color);

    }

    private void quitIfDoingNothing() {
        if (mIsApplyingWallpaper) {
            return;
        }

        finish();
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import org.lineageos.backgrounds.bundle.WallpaperBundle;
import org.lineageos.backgrounds.bundle.WallpaperType;
import org.lineageos.backgrounds.factory.UserWallpaperFactory;
import org.lineageos.backgrounds.task.FetchDataTask;
import org.lineageos.backgrounds.util.UiUtils;

import java.util.List;

Loading