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

Commit 2c79f468 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix blur ui issues -

1. Consider navigation bar while doing blur.
2. Properly set offset for the wallpaper to prevent shifted blurred background.
parent 628dc472
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
    <uses-permission android:name="lineageos.permission.READ_WEATHER" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
    <application
        android:name=".BlissLauncher"
        android:icon="@mipmap/ic_launcher"
+37 −6
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

@@ -28,6 +27,7 @@ public class DeviceProfile {

    public static Path path;
    private final float widthCm;
    private int statusBarHeight;
    public int cellHeightWithoutPaddingPx;
    public int hotseatCellHeightWithoutPaddingPx;
    public int fillResIconDpi;
@@ -158,13 +158,18 @@ public class DeviceProfile {
        widthPx = realSize.x;
        double x = widthPx / dm.xdpi;
        widthCm = (float) (x * 2.540001f);
        Log.i(TAG, "DeviceProfile: " + availableWidthPx);
        Log.i(TAG, "DeviceProfile: " + widthPx);
        heightPx = realSize.y;

        context = getContext(context, Configuration.ORIENTATION_PORTRAIT);
        Resources res = context.getResources();

        // status bar height
        statusBarHeight = 0;
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = res.getDimensionPixelSize(resourceId);
        }

        ComponentName cn = new ComponentName(context.getPackageName(),
                this.getClass().getName());

@@ -248,8 +253,6 @@ public class DeviceProfile {
        dateTextBottomPadding = (dateTextviewHeight - (int) (0.86 * Utilities.calculateTextHeight(
                (float) dateTextSize / 2))) / 2;

        Log.i(TAG, "datepadding: " + dateTextTopPadding + "*" + dateTextBottomPadding);

        cellHeightWithoutPaddingPx = iconSizePx + Utilities.pxFromDp(4, dm)
                + Utilities.calculateTextHeight(iconTextSizePx);

@@ -351,6 +354,34 @@ public class DeviceProfile {
        return resizedPath;
    }

    public boolean hasSoftNavigationBar(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);

        Point smallestSize = new Point();
        Point largestSize = new Point();
        display.getCurrentSizeRange(smallestSize, largestSize);

        int availableHeight = largestSize.y;

        Point realSize = new Point();
        display.getRealSize(realSize);
        int realHeight = realSize.y;
        context = getContext(context, Configuration.ORIENTATION_PORTRAIT);
        Resources res = context.getResources();

        // status bar height
        statusBarHeight = 0;
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = res.getDimensionPixelSize(resourceId);
        }

        return (realHeight - availableHeight - statusBarHeight) > 0;
    }

    private int getLauncherIconDensity(int requiredSize) {
        // Densities typically defined by an app.
        int[] densityBuckets = new int[]{
+17 −16
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ import android.graphics.Canvas;
import android.graphics.Matrix;
import android.support.v4.app.ActivityCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

@@ -20,12 +19,11 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.Utilities;

public class BlurWallpaperProvider {

    private static final String TAG = "BlurWallpaperProvider";

    private final Context context;
    private final WallpaperManager wallpaperManager;

@@ -49,7 +47,7 @@ public class BlurWallpaperProvider {
        this.wallpaperManager = WallpaperManager.getInstance(context);
        blurProcessor = HokoBlur.with(context).sampleFactor(SAMPLE_FACTOR)
                .scheme(HokoBlur.SCHEME_OPENGL)
                .mode(HokoBlur.MODE_GAUSSIAN)
                .mode(HokoBlur.MODE_STACK)
                .forceCopy(false)
                .needUpscale(true)
                .processor();
@@ -109,8 +107,11 @@ public class BlurWallpaperProvider {
        int overlayWidth = launcherView.getWidth();
        int overlayHeight = launcherView.getHeight();

        Log.i(BlurWallpaperProvider.class.getName(), "mergeLauncherView: " + wallpaperWidth + "*" + wallpaperHeight);
        Log.i(BlurWallpaperProvider.class.getName(), "mergeLauncherView: " + overlayWidth + "*" + overlayHeight);
        // Hack for removing soft navigation bar
        if(overlayHeight > wallpaperHeight) {
            overlayHeight = wallpaperHeight;
            launcherView = Bitmap.createBitmap(launcherView, 0, 0, overlayWidth, overlayHeight);
        }

        float marginLeft = (float) (wallpaperWidth * 0.5 - overlayWidth * 0.5);
        float marginTop = (float) (wallpaperHeight * 0.5 - overlayHeight * 0.5);
@@ -123,13 +124,11 @@ public class BlurWallpaperProvider {
    }

    public void blurWithLauncherView(Bitmap view, int radius) {
        Log.d(TAG, "blurWithLauncherView() called with: view = [" + view + "], radius = [" + radius + "]");
        cancelPreTask(false);
        mFuture = mDispatcher.submit(new BlurTask(view, blurProcessor, radius) {
            @Override
            void onBlurSuccess(Bitmap bitmap) {
                if (bitmap != null && listener != null) {
                    Log.d(TAG, "blurBackgroundLayer() called with: bitmap = [" + bitmap + "]");
                    listener.blurFrontLayer(bitmap);
                }
            }
@@ -143,7 +142,6 @@ public class BlurWallpaperProvider {

    public void cancelPreTask(boolean interrupt) {
        if (mFuture != null && !mFuture.isCancelled() && !mFuture.isDone()) {
            Log.d(TAG, "cancelPreTask() called with: interrupt = [" + interrupt + "]");
            mFuture.cancel(interrupt);
            mFuture = null;
        }
@@ -166,22 +164,26 @@ public class BlurWallpaperProvider {
            return wallpaper;
        }

        Log.i(TAG, "Screen dimension: " + width + "*" + height);
        Log.i(TAG, "wallpaper dimension: " + wallpaper.getWidth() + "*" + wallpaper.getHeight());

        int scaledWidth = (int) Math.max(width, (wallpaper.getWidth() * upscaleFactor));
        int scaledHeight = (int) Math.max(height, (wallpaper.getHeight() * upscaleFactor));
        Log.i(TAG, "Scaled dimension: " + scaledWidth + "*" + scaledHeight);

        wallpaper = Bitmap.createScaledBitmap(wallpaper, scaledWidth, scaledHeight, false);

        int navigationBarHeight = 0;
        if (BlissLauncher.getApplication(context).getDeviceProfile().hasSoftNavigationBar(context)) {

            int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                navigationBarHeight = context.getResources().getDimensionPixelSize(resourceId);
            }
        }

        int y;
        if (wallpaper.getHeight() > height) {
            y = (wallpaper.getHeight() - height) / 2;
        } else y = 0;

        return Bitmap.createBitmap(wallpaper, 0, y, width, height);
        return Bitmap.createBitmap(wallpaper, 0, y, width, height - navigationBarHeight);
    }

    public interface Listener {
@@ -193,7 +195,6 @@ public class BlurWallpaperProvider {
    }

    public void clear() {
        Log.d(TAG, "clear() called");
        listener = null;
        cancelPreTask(true);
        sInstance = null;
@@ -216,7 +217,7 @@ public class BlurWallpaperProvider {
                blurProcessor.radius(radius);
                onBlurSuccess(blurProcessor.blur(bitmap));
            } else {
                onBlurFailed((float) radius / 25);
                onBlurFailed((float) radius / 15);
            }
        }

+2 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class WallpaperChangeReceiver extends BroadcastReceiver {

    private void updateOffset() {
        WallpaperManager wm = (WallpaperManager) mContext.getSystemService(WALLPAPER_SERVICE);
        wm.setWallpaperOffsets(mWorkspace.getWindowToken(), 0f, 0.5f);
        wm.setWallpaperOffsets(mWindowToken, 0f, 0.5f);
        wm.setWallpaperOffsetSteps(0.0f, 0.0f);
    }
}
+16 −34
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.WallpaperManager;
import android.app.usage.UsageStats;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -266,6 +267,9 @@ public class LauncherActivity extends AppCompatActivity implements
        setContentView(mLauncherView);
        setupViews();

        WallpaperManager wm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
        wm.suggestDesiredDimensions(mDeviceProfile.widthPx, mDeviceProfile.heightPx);

        mProgressBar.setVisibility(View.VISIBLE);

        if (Preferences.shouldAskForNotificationAccess(this)) {
@@ -345,7 +349,7 @@ public class LauncherActivity extends AppCompatActivity implements
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        workspace.setOnClickListener(v -> {
            if (swipeSearchContainer.getVisibility() == VISIBLE) {
                hideSwipeSearchContainer(25);
                hideSwipeSearchContainer(18);
            }
        });
    }
@@ -1106,7 +1110,7 @@ public class LauncherActivity extends AppCompatActivity implements
                if (scrollX >= 0 && scrollX < mDeviceProfile.availableWidthPx) {
                    float fraction = (float) (mDeviceProfile.availableWidthPx - scrollX)
                            / mDeviceProfile.availableWidthPx;
                    int radius = (int) (fraction * 25);
                    int radius = (int) (fraction * 18);
                    BlurWallpaperProvider.getInstance(LauncherActivity.this).blur(radius);
                }
                if (isViewScrolling) {
@@ -1116,7 +1120,6 @@ public class LauncherActivity extends AppCompatActivity implements

            @Override
            public void onViewScrollFinished(int page) {
                Log.d(TAG, "onViewScrollFinished() called with: page = [" + page + "]");
                isViewScrolling = false;
                if (page != 0) {
                    BlurWallpaperProvider.getInstance(LauncherActivity.this).clear();
@@ -1161,28 +1164,23 @@ public class LauncherActivity extends AppCompatActivity implements

    @Override
    public void blurBackgroundLayer(Bitmap bitmap) {
        Log.d(TAG, "blurBackgroundLayer() called with: bitmap = [" + bitmap + "]");
        BitmapDrawable drawable = new BitmapDrawable(bitmap);
        new Handler(Looper.getMainLooper())
                .post(() -> {
                    Log.d(TAG, "removeBlur() called");
                    backgroundLayer.setBackground(drawable);
                });    }

    @Override
    public void blurFrontLayer(Bitmap bitmap) {
        Log.d(TAG, "blurFrontLayer() called with: bitmap = [" + bitmap + "]");
        BitmapDrawable drawable = new BitmapDrawable(bitmap);
        new Handler(Looper.getMainLooper())
                .post(() -> {
                    Log.d(TAG, "removeBlur() called");
                    frontLayer.setBackground(drawable);
                });
    }

    @Override
    public void fallbackToDimBackground(float dimAlpha) {
        Log.d(TAG, "fallbackToDimBackground() called with: dimAlpha = [" + dimAlpha + "]");
        int color = 0x44000000;
        int alpha = Math.round(Color.alpha(color) * dimAlpha);
        int red = Color.red(color);
@@ -1193,10 +1191,7 @@ public class LauncherActivity extends AppCompatActivity implements

    private void removeBlur(View view) {
        new Handler(Looper.getMainLooper())
                .post(() -> {
                    Log.d(TAG, "removeBlur() called");
                    view.setBackground(null);
                });
                .post(() -> view.setBackground(null));
    }

    public void refreshSuggestedApps(ViewGroup viewGroup, boolean forceRefresh) {
@@ -2801,12 +2796,10 @@ public class LauncherActivity extends AppCompatActivity implements
            startBounds.bottom += deltaHeight;
        }

        Log.d("ShowFolder", "displayFolder() called with: app = [" + app + "], v = [" + v + "]");

        // Construct and run the parallel animation of the four translation and
        // scale properties (X, Y, SCALE_X, and SCALE_Y).
        AnimatorSet set = new AnimatorSet();
        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 25);
        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 18);
        mergedView = BlurWallpaperProvider.getInstance(this).mergeLauncherView(getLauncherView());
        valueAnimator.addUpdateListener(animation ->
                BlurWallpaperProvider.getInstance(this).blurWithLauncherView(mergedView, (Integer) animation.getAnimatedValue()));
@@ -2822,13 +2815,12 @@ public class LauncherActivity extends AppCompatActivity implements
                .with(ObjectAnimator.ofFloat(mHorizontalPager, View.ALPHA, 1f, 0f))
                .with(ObjectAnimator.ofFloat(mIndicator, View.ALPHA, 1f, 0f))
                .with(ObjectAnimator.ofFloat(mDock, View.ALPHA, 1f, 0f));
        set.setDuration(400);
        set.setDuration(360);
        set.setInterpolator(new LinearInterpolator());
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                Log.d("ShowFolder", "onAnimationStart() called with: animation = [" + animation + "]");
                mFolderWindowContainer.setVisibility(View.VISIBLE);

                // Set the pivot point for SCALE_X and SCALE_Y transformations
@@ -2841,13 +2833,12 @@ public class LauncherActivity extends AppCompatActivity implements

            @Override
            public void onAnimationEnd(Animator animation) {
                Log.d("ShowFolder", "onAnimationEnd() called with: animation = [" + animation + "]");
                currentAnimator = null;
                mergedView = null;
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                Log.d("ShowFolder", "onAnimationCancel() called with: animation = [" + animation + "]");
                currentAnimator = null;
                mergedView = null;
                BlurWallpaperProvider.getInstance(LauncherActivity.this).clear();
@@ -2881,7 +2872,6 @@ public class LauncherActivity extends AppCompatActivity implements
        view.buildDrawingCache(true);
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(false);

        return bitmap;
    }

@@ -2896,12 +2886,10 @@ public class LauncherActivity extends AppCompatActivity implements
            currentAnimator.cancel();
        }

        Log.d("HideFolder", "hideFolderWindowContainer() called");

        // Animate the four positioning/sizing properties in parallel,
        // back to their original values.
        AnimatorSet set = new AnimatorSet();
        ValueAnimator valueAnimator = ValueAnimator.ofInt(25, 0);
        ValueAnimator valueAnimator = ValueAnimator.ofInt(18, 0);
        valueAnimator.addUpdateListener(animation ->
                BlurWallpaperProvider.getInstance(this).blurWithLauncherView(mergedView, (Integer) animation.getAnimatedValue()));
        set.play(ObjectAnimator
@@ -2919,12 +2907,11 @@ public class LauncherActivity extends AppCompatActivity implements
                .with(ObjectAnimator.ofFloat(mIndicator, View.ALPHA, 0f, 1f))
                .with(ObjectAnimator.ofFloat(mDock, View.ALPHA, 0f, 1f))
                .with(valueAnimator);
        set.setDuration(400);
        set.setDuration(360);
        set.setInterpolator(new LinearInterpolator());
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                Log.d("HideFolder", "onAnimationEnd() called with: animation = [" + animation + "]");
                mFolderWindowContainer.setVisibility(View.GONE);
                currentAnimator = null;
                mergedView = null;
@@ -2934,7 +2921,6 @@ public class LauncherActivity extends AppCompatActivity implements

            @Override
            public void onAnimationCancel(Animator animation) {
                Log.d("HideFolder", "onAnimationCancel() called with: animation = [" + animation + "]");
                mFolderWindowContainer.setVisibility(View.GONE);
                currentAnimator = null;
                mergedView = null;
@@ -2979,7 +2965,7 @@ public class LauncherActivity extends AppCompatActivity implements
        }

        if (swipeSearchContainer.getVisibility() == VISIBLE) {
            hideSwipeSearchContainer(25);
            hideSwipeSearchContainer(18);
        }

        if (isWobbling) {
@@ -2990,12 +2976,11 @@ public class LauncherActivity extends AppCompatActivity implements
    }

    private void showSwipeSearchContainer() {
        Log.d(TAG, "showSwipeSearchContainer() called " + blurRadius + " " + (mergedView == null));
        if (currentAnimator != null) {
            currentAnimator.cancel();
        }
        AnimatorSet set = new AnimatorSet();
        ValueAnimator blurAnimator = ValueAnimator.ofInt(blurRadius, 25);
        ValueAnimator blurAnimator = ValueAnimator.ofInt(blurRadius, 18);
        blurAnimator.addUpdateListener(animation ->
                BlurWallpaperProvider.getInstance(this).blurWithLauncherView(mergedView, (Integer) animation.getAnimatedValue()));
        set.play(ObjectAnimator.ofFloat(swipeSearchContainer, View.TRANSLATION_Y, 0))
@@ -3009,7 +2994,6 @@ public class LauncherActivity extends AppCompatActivity implements
                            @Override
                            public void onAnimationCancel(Animator animation) {
                                super.onAnimationCancel(animation);
                                Log.d(TAG, "onAnimationCancel() called with: animation = [" + animation + "]");
                                currentAnimator = null;
                                BlurWallpaperProvider.getInstance(LauncherActivity.this).clear();
                                removeBlur(frontLayer);
@@ -3022,7 +3006,6 @@ public class LauncherActivity extends AppCompatActivity implements
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                Log.d(TAG, "onAnimationEnd() called with: animation = [" + animation + "]");
                                currentAnimator = null;
                                mergedView = null;
                                mHorizontalPager.setVisibility(GONE);
@@ -3128,7 +3111,7 @@ public class LauncherActivity extends AppCompatActivity implements
                            @Override
                            public void onAnimationStart(Animator animation) {
                                super.onAnimationStart(animation);
                                BlurWallpaperProvider.getInstance(LauncherActivity.this).clear();
                                //BlurWallpaperProvider.getInstance(LauncherActivity.this).clear();
                                mHorizontalPager.setVisibility(VISIBLE);
                                mIndicator.setVisibility(VISIBLE);
                                mDock.setVisibility(VISIBLE);
@@ -3186,8 +3169,7 @@ public class LauncherActivity extends AppCompatActivity implements
            mHorizontalPager.setAlpha(deltaAlpha);
            mIndicator.setAlpha(deltaAlpha);
            mDock.setAlpha(deltaAlpha);
            blurRadius = (int) ((1 - deltaAlpha) * 25);
            Log.d(TAG, "onSwipe() called with: position = [" + position + "]");
            blurRadius = (int) ((1 - deltaAlpha) * 18);
            BlurWallpaperProvider.getInstance(this).blurWithLauncherView(mergedView, blurRadius);
        }