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

Commit 9ee76b8d authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Blur background behind popped-up folder apps and swipe-down to search...

Blur background behind popped-up folder apps and swipe-down to search container with a fallback case
parent 677f9ea3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:hardwareAccelerated="true"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
        <activity
            android:name=".features.launcher.LauncherActivity"
+83 −27
Original line number Diff line number Diff line
@@ -5,37 +5,30 @@ import android.app.WallpaperManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
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;

import com.hoko.blur.HokoBlur;
import com.hoko.blur.processor.BlurProcessor;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import foundation.e.blisslauncher.core.Utilities;

public class BlurWallpaperProvider {

    private static final String TAG = "BlurWallpaperProvider";

    private final Context context;
    private final WallpaperManager wallpaperManager;

    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
    private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
    private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
    private static final int KEEP_ALIVE = 1;

    public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
            CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
            TimeUnit.SECONDS, new LinkedBlockingQueue<>());
    private final BlurProcessor blurProcessor;

    private ExecutorService mDispatcher = Executors.newSingleThreadExecutor();
@@ -44,7 +37,7 @@ public class BlurWallpaperProvider {

    private DisplayMetrics displayMetrics = new DisplayMetrics();

    private static final float SAMPLE_FACTOR = 4.0f;
    private static final float SAMPLE_FACTOR = 8.0f;

    private static BlurWallpaperProvider sInstance;
    private Bitmap wallpaper;
@@ -72,26 +65,24 @@ public class BlurWallpaperProvider {
    }

    private void init() {
        updateAsync();
        updateWallpaper();
    }

    private void updateAsync() {
        THREAD_POOL_EXECUTOR.execute(updateRunnable);
        mDispatcher.submit(updateRunnable);
    }

    private void updateWallpaper() {
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        wallpaper = Utilities.drawableToBitmap(wallpaperManager.getFastDrawable(), true);
        //wallpaper = scaleToScreenSize(wallpaper);

        if (wallpaperManager.getWallpaperInfo() != null) {
            // Wallpaper is live wallpaper so can't support blur effect.
            return;
        }
        wallpaper = Utilities.drawableToBitmap(wallpaperManager.getDrawable(), true);
        wallpaper = scaleAndCropToScreenSize(wallpaper);
    }


@@ -105,6 +96,52 @@ public class BlurWallpaperProvider {
                    //bitmap.recycle();
                }
            }

            @Override
            void onBlurFailed(float factor) {
                listener.fallbackToDimBackground(factor);
            }
        });
    }

    public Bitmap mergeLauncherView(Bitmap launcherView) {
        updateWallpaper();
        if (wallpaper == null) {  // possibly we don't have access to read the wallpaper or the wallpaper is live wallpaper.
            return null;
        }
        int wallpaperWidth = wallpaper.getWidth();
        int wallpaperHeight = wallpaper.getHeight();
        int overlayWidth = launcherView.getWidth();
        int overlayHeight = launcherView.getHeight();

        Log.i(BlurWallpaperProvider.class.getName(), "mergeLauncherView: " + wallpaperWidth + "*" + wallpaperHeight);
        Log.i(BlurWallpaperProvider.class.getName(), "mergeLauncherView: " + overlayWidth + "*" + overlayHeight);

        float marginLeft = (float) (wallpaperWidth * 0.5 - overlayWidth * 0.5);
        float marginTop = (float) (wallpaperHeight * 0.5 - overlayHeight * 0.5);

        Bitmap finalBitmap = Bitmap.createBitmap(wallpaperWidth, wallpaperHeight, wallpaper.getConfig());
        Canvas canvas = new Canvas(finalBitmap);
        canvas.drawBitmap(wallpaper, new Matrix(), null);
        canvas.drawBitmap(launcherView, marginLeft, marginTop, null);
        return finalBitmap;
    }

    public void blurWithLauncherView(Bitmap view, int radius) {
        cancelPreTask(false);
        mFuture = mDispatcher.submit(new BlurTask(view, blurProcessor, radius) {
            @Override
            void onBlurSuccess(Bitmap bitmap) {
                if (bitmap != null && listener != null) {
                    listener.onBlurSuccess(bitmap);
                    //bitmap.recycle();
                }
            }

            @Override
            void onBlurFailed(float factor) {
                listener.fallbackToDimBackground(factor);
            }
        });
    }

@@ -115,7 +152,7 @@ public class BlurWallpaperProvider {
        }
    }

    private Bitmap scaleToScreenSize(Bitmap wallpaper) {
    private Bitmap scaleAndCropToScreenSize(Bitmap wallpaper) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        display.getRealMetrics(displayMetrics);
@@ -132,14 +169,29 @@ 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);

        return Bitmap.createScaledBitmap(wallpaper, scaledWidth, scaledHeight, false);
        int x = 0;
        int y = (wallpaper.getHeight() - height) / 2;
        if (y < 0 || y + height > wallpaper.getHeight()) {
            y = 0;
        }

        Log.i(TAG, "X and Y: " + x + "*" + y);
        return Bitmap.createBitmap(wallpaper, x, 0, width, height);
    }

    public interface Listener {
        void onBlurSuccess(Bitmap bitmap);

        void fallbackToDimBackground(float dimAlpha);
    }

    public void clear() {
@@ -164,9 +216,13 @@ public class BlurWallpaperProvider {
            if (bitmap != null && !bitmap.isRecycled() && blurProcessor != null) {
                blurProcessor.radius(radius);
                onBlurSuccess(blurProcessor.blur(bitmap));
            } else {
                onBlurFailed((float) radius / 25);
            }
        }

        abstract void onBlurSuccess(Bitmap bitmap);

        abstract void onBlurFailed(float factor);
    }
}
+26 −0
Original line number Diff line number Diff line
package foundation.e.blisslauncher.core.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import foundation.e.blisslauncher.core.blur.BlurWallpaperProvider;

public class WallpaperChangeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        BlurWallpaperProvider.getInstance(context).clear();
    }

    public static WallpaperChangeReceiver register(Context context) {
        IntentFilter timeIntentFilter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
        WallpaperChangeReceiver receiver = new WallpaperChangeReceiver();
        context.registerReceiver(receiver, timeIntentFilter);
        return receiver;
    }

    public static void unregister(Context context, WallpaperChangeReceiver receiver) {
        context.unregisterReceiver(receiver);
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ public class BlissInput extends android.support.v7.widget.AppCompatEditText {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onDragEvent(DragEvent event) {
        // Without this drag/drop apps won't work on API <24.
+108 −38

File changed.

Preview size limit exceeded, changes collapsed.