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 Original line Diff line number Diff line
@@ -50,4 +50,5 @@ dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -36,7 +36,8 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.appcompat_appcompat \
    androidx.appcompat_appcompat \
    androidx.palette_palette \
    androidx.palette_palette \
    androidx.recyclerview_recyclerview \
    androidx.recyclerview_recyclerview \
    androidx.transition_transition
    androidx.transition_transition \
    com.google.android.material_material


LOCAL_PACKAGE_NAME := Backgrounds
LOCAL_PACKAGE_NAME := Backgrounds


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


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


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


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

import org.lineageos.backgrounds.R;
import org.lineageos.backgrounds.R;
import org.lineageos.backgrounds.bundle.WallpaperBundle;
import org.lineageos.backgrounds.bundle.WallpaperBundle;
import org.lineageos.backgrounds.task.ApplyWallpaperTask;
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 static final int LOCK_FLAG = WallpaperManager.FLAG_LOCK;


    private ImageView mPreviewView;
    private ImageView mPreviewView;
    private LinearLayout mApplyView;

    private TextView mBothView;
    private BottomSheetBehavior mApplySheetBehavior;
    private TextView mHomeView;
    private boolean mIsApplyingWallpaper = false;
    private TextView mLockView;
    private ImageView mCloseView;


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


        mPreviewView = findViewById(R.id.apply_preview);
        mPreviewView = findViewById(R.id.apply_preview);
        mApplyView = findViewById(R.id.apply_button);
        ImageView closeView = findViewById(R.id.apply_close);
        mBothView = findViewById(R.id.apply_both);

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


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

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


        setup();
        setup();
    }
    }


    private void setup() {
    private void setup() {
        setupBottomSheet();

        final WallpaperBundle wallpaperBundle = getIntent().getParcelableExtra(EXTRA_WALLPAPER);
        final WallpaperBundle wallpaperBundle = getIntent().getParcelableExtra(EXTRA_WALLPAPER);
        if (wallpaperBundle == null) {
        if (wallpaperBundle == null) {
            return;
            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) {
    private void setupBuiltIn(@NonNull final WallpaperBundle bundle) {
        Drawable drawable = ContextCompat.getDrawable(this, bundle.getDescriptor());
        Drawable drawable = ContextCompat.getDrawable(this, bundle.getDescriptor());
        displayPreview(drawable);
        displayPreview(drawable);
@@ -172,8 +207,9 @@ public final class ApplyActivity extends AppCompatActivity {
    }
    }


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

        mIsApplyingWallpaper = true;


        final Drawable drawable = mPreviewView.getDrawable();
        final Drawable drawable = mPreviewView.getDrawable();


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


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


    private void showApplyButton() {
    private void showApplyLayout() {
        mApplyView.setScaleX(0f);
        mApplySheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        mApplyView.setScaleY(0f);

        mApplyView.setVisibility(View.VISIBLE);
        new Handler().postDelayed(() ->
        mApplyView.animate()
                mApplySheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED), 350);
                .setStartDelay(350)
                .scaleX(1f)
                .scaleY(1f)
                .start();
    }
    }


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


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


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


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

        mApplyView.setBackgroundTintList(backgroundList);
    private void quitIfDoingNothing() {

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


        finish();
        mBothView.setTextColor(actionsColor);
        mBothView.setCompoundDrawableTintList(actionsList);
        mHomeView.setTextColor(actionsColor);
        mHomeView.setCompoundDrawableTintList(actionsList);
        mLockView.setTextColor(actionsColor);
        mLockView.setCompoundDrawableTintList(actionsList);
    }
    }
}
}
+0 −1
Original line number Original line 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.bundle.WallpaperType;
import org.lineageos.backgrounds.factory.UserWallpaperFactory;
import org.lineageos.backgrounds.factory.UserWallpaperFactory;
import org.lineageos.backgrounds.task.FetchDataTask;
import org.lineageos.backgrounds.task.FetchDataTask;
import org.lineageos.backgrounds.util.UiUtils;


import java.util.List;
import java.util.List;


Loading