unclear backdrop of movement, with the hidden activity shrouded in mystery

Every time I unlock my phone, there is an activity that appears suddenly.

I want the background of this activity to appear blurry, so that any subsequent activity opened will have a blurry background. The problem is, I don't know which app's activity will be behind mine,

as it could be from any application.

Therefore, I am unable to use the method that blurs the last activity I accessed within my own app.

I found a guide on how to blur/glass/frost the current activity in Android

I have implemented a blur builder as specified here

to create a blurry transparent background effect

like this

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.view.View;
public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.4f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(View v) {
        return blur(v.getContext(), getScreenshot(v));
    }

    public static Bitmap blur(Context ctx, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(ctx);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }

    private static Bitmap getScreenshot(View v) {
        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.draw(c);
        return b;
    }
}

However, I am unsure about how to integrate this into the onCreate method of my activity.

Any insights would be greatly appreciated!

Answer №1

Here is a code snippet you can use within your onCreate() method:

For Fragments:

final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
    if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(activity.getResources(), image));
}

For Activities:

final View content = findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(getResources(), image));
}

UPDATE:

To implement the blur effect in onCreate(), include the following additional code:

new CountDownTimer(1, 1) {
public void onTick(long millisUntilFinished) {
        }

public void onFinish() {
            final View content = findViewById(android.R.id.content).getRootView();
            if (content.getWidth() > 0) {
                Bitmap image = BlurBuilder.blur(content);
                content.setBackground(new BitmapDrawable(getResources(), image));
            }

        }
}.start();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method for retrieving data from a node in Firebase Realtime Database using TypeScript cloud functions, without relying on the onCreate trigger?

Being a beginner with Firebase and TypeScript, I have been struggling to retrieve values from a reference other than the triggered value. Despite finding answers in JavaScript, I am working on writing functions using TypeScript for real-time database for A ...

How to insert a variable into a strings.xml entry in an Android Kotlin project

Is it possible to insert local variables into strings in different ways? val amount = "10" findViewById<TextView>(R.id.textView).text = "There are $amount things." When attempting the same approach in the strings.xml file: <resources> <stri ...

Issue with menu display after clicking icon

On my website, I am trying to set up an icon that will display a menu bar for mobile users. I have written some JavaScript code for this functionality, but it's not working as expected. My approach involved creating an element called "Menu" and assign ...

Is it advisable to utilize both bootstrap.css and normalize.css simultaneously?

Is it redundant to use both bootstrap.css and normalize.css since bootstrap already includes a version of the code from normalize.css? In order to ensure thorough cross-browser compatibility, should I use both bootstrap and normalize.css, or is using just ...

Bring fontawesome into the Laravel environment with MDBVue integration

I attempted to integrate fontawesome into my laravel mdbvue setup. Upon installing mdbvue using the command: npm install mdbvue fontawesome was automatically added to my package-lock.json and can be found in the node_modules folder under @fortawesome. ...

Is there a method to deactivate or modify the multitasking button on the Galaxy Tab 4?

In our line of manufacturing products, we have developed an industrial control application that comes pre-loaded on Samsung Galaxy Tablets. Previously, we used Tab 10 tablets running on Honeycomb, but as we are facing difficulty in sourcing them from the ...

How can I incorporate premium skins into my Android application?

I am looking to create custom "skins" for my Android application, with the intention of selling them on the Android marketplace. Once the user purchases the skin, I want it to be accessible within my app, possibly in the settings section. I am unsure of ...

Searching for data in a bootstrap table that is not case-sensitive

Searching for and highlighting text within a bootstrap table has proven to be a challenge. Check out the Fiddle for an example: https://jsfiddle.net/99x50s2s/74/ HTML <table class='table table-bordered'> <thead> <tr& ...

Tips on making Glide compatible with Android Studio 3.0

After updating to Android Studio 3.0, I've encountered issues with recognizing 'AppGlideModule'. Android Studio is not able to recognize the import import com.bumptech.glide.module.AppGlideModule; link here I have attempted changing &apos ...

Troubleshooting problems with Z-Index div hover overlay on [windows] and Webkit browsers (Safari, Opera, etc)

Note: This issue is specific to Windows Webkit and does not affect Macs I am attempting to create a grid with fixed-size cells containing background images. When hovered over, the background image changes and the cell's height increases, overlaying t ...

Error message in Android studio console for Angular JS: Unexpected token error, even though the code runs smoothly in browser

I'm encountering a strange issue with my Cordova Android project (AngularJS + Ionic). When I run the project in Android Studio, I receive an error on my JS file that says: Uncaught SyntaxError: Unexpected token {, http://192.168.43.211:8100/templates ...

Consistent dimensions for columns in a table, automatically adjusting based on content

Can we ensure that all rows and columns maintain equal height, whether or not they contain an image? If you need a visual representation of this concept, refer to this example: [] [] [] ...

The alignment of the third column div is off and not displaying properly

I am having some trouble with aligning the divs on my page in a column layout. Despite setting the first two divs to float left, the third one does not align properly. I want the third div to be floated right and aligned with the first two. You can see an ...

Show an error notification if the mobile device does not meet the requirements for jquery mobile version

Currently, I am in the process of creating a website using HTML5, CSS3, and jquerymobile. My goal is to have an error message appear saying "Your mobile browser does not support this application" if the page is not rendering correctly or if the jquery mobi ...

Calculating the width of div elements within a horizontal gallery that includes a scrollbar

My website, vladimirvojtela.com, features a gallery with a horizontal scrollbar that leaves whitespace at the end due to the width parameter in the code. Can anyone suggest a script that can automatically adjust the DIV width after all images have been ren ...

CSS problem with rotating image carousel

I'm currently working on incorporating the moving box feature displayed at the bottom of this page. Despite following the CSS code provided, I am facing an issue where the left navigation arrow is not appearing. Can anyone provide any insights or sugg ...

The ul media queries have malfunctioned

In the .gallery section, there are 12 li elements that contain images. Originally, I used media queries to adjust the number of columns in the grid to 6, 4, 3, and 2 based on the browser width. However, when I tried to create a size ratio of 2:1 for all ...

Issues with Bootstrap's center-block functionality

I'm having trouble centering the navigation in my WordPress template that uses Bootstrap. I've tried using the center-block class on different elements, but the menu items are still aligning to the left. I even created a custom class in my custom ...

CSS-Styled Vertical Timeline

I have been working on creating a vertical timeline with icons embedded within it. I initially used this as a reference point. I was able to achieve the desired layout by adding extra spans inside the div. However, the end result appears somewhat cluttere ...

Compilation of Android resources was unsuccessful

I encountered a Compilation Error with the following message: Android resource compilation failed Output: D:\RukhiVivah5\app\src\main\res\mipmap- xxxhdpi\ic_launcher_round.png: error: failed to read PNG signature: file ...