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

Commit d0cc88cb authored by Joey's avatar Joey
Browse files

Support setting different wallpapers for lock and home



Signed-off-by: default avatarJoey <joey@lineageos.org>
parent 1e491e58
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ final class ApplyWallpaperImpl {
        final WallpaperManager manager = mCallback.getWallpaperManager();

        try {
            manager.setBitmap(bm);
            manager.setBitmap(bm, null, true, mCallback.getFlags());
            return true;
        } catch (IOException e) {
            Log.e(TAG, e.getMessage(), e);
@@ -53,5 +53,7 @@ final class ApplyWallpaperImpl {

        @NonNull
        WallpaperManager getWallpaperManager();

        int getFlags();
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -48,10 +48,17 @@ public final class ApplyWallpaperTask extends AsyncTask<Drawable, Void, Boolean>
        return mCallbacks.getWallpaperManager();
    }

    @Override
    public int getFlags() {
        return mCallbacks.getFlags();
    }

    public interface Callback {
        void onCompleted(final boolean result);

        @NonNull
        WallpaperManager getWallpaperManager();

        int getFlags();
    }
}
+40 −13
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

@@ -44,8 +45,15 @@ public final class ApplyActivity extends AppCompatActivity {
    public static final String EXTRA_TRANSITION_NAME = "transition_shared_preview";
    static final String EXTRA_WALLPAPER = "apply_extra_wallpaper_parcel";

    private static final int BOTH_FLAG = WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK;
    private static final int HOME_FLAG = WallpaperManager.FLAG_SYSTEM;
    private static final int LOCK_FLAG = WallpaperManager.FLAG_LOCK;

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

    @Override
    protected void onCreate(@Nullable Bundle savedInstance) {
@@ -54,9 +62,14 @@ public final class ApplyActivity extends AppCompatActivity {
        setContentView(R.layout.activity_apply);

        mPreviewView = findViewById(R.id.apply_preview);
        mButtonView = findViewById(R.id.apply_button);
        mApplyView = findViewById(R.id.apply_button);
        mBothView = findViewById(R.id.apply_both);
        mHomeView = findViewById(R.id.apply_home);
        mLockView = findViewById(R.id.apply_lock);

        mButtonView.setOnClickListener(v -> applyWallpaper());
        mBothView.setOnClickListener(v -> applyWallpaper(BOTH_FLAG));
        mHomeView.setOnClickListener(v -> applyWallpaper(HOME_FLAG));
        mLockView.setOnClickListener(v -> applyWallpaper(LOCK_FLAG));

        setup();
    }
@@ -132,7 +145,7 @@ public final class ApplyActivity extends AppCompatActivity {
        }).execute(wallpaperUri);
    }

    private void applyWallpaper() {
    private void applyWallpaper(final int flags) {
        hideApplyButton();

        final Drawable drawable = mPreviewView.getDrawable();
@@ -148,6 +161,11 @@ public final class ApplyActivity extends AppCompatActivity {
            public WallpaperManager getWallpaperManager() {
                return getSystemService(WallpaperManager.class);
            }

            @Override
            public int getFlags() {
                return flags;
            }
        }).execute(drawable);
    }

@@ -162,10 +180,10 @@ public final class ApplyActivity extends AppCompatActivity {
    }

    private void showApplyButton() {
        mButtonView.setScaleX(0f);
        mButtonView.setScaleY(0f);
        mButtonView.setVisibility(View.VISIBLE);
        mButtonView.animate()
        mApplyView.setScaleX(0f);
        mApplyView.setScaleY(0f);
        mApplyView.setVisibility(View.VISIBLE);
        mApplyView.animate()
                .setStartDelay(350)
                .scaleX(1f)
                .scaleY(1f)
@@ -173,7 +191,7 @@ public final class ApplyActivity extends AppCompatActivity {
    }

    private void hideApplyButton() {
        mButtonView.animate()
        mApplyView.animate()
                .scaleX(0f)
                .scaleY(0f)
                .setDuration(250)
@@ -199,9 +217,18 @@ public final class ApplyActivity extends AppCompatActivity {
        UiUtils.setSystemUiColors(getWindow(), color);

        // Apply
        final ColorStateList colorStateList = ColorStateList.valueOf(color);
        mButtonView.setBackgroundTintList(colorStateList);
        mButtonView.setTextColor(getColor(ColorUtils.isColorLight(color) ?
                android.R.color.black : android.R.color.white));
        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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -16,5 +16,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/black" />
    <corners android:radius="24dp" />
    <corners android:radius="36dp" />
</shape>
+24 −0
Original line number Diff line number Diff line
<!--
  Copyright (C) 2019 The LineageOS 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.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="32dp"
    android:height="32dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="@android:color/white"
        android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19H7V5h10v14z" />
</vector>
Loading