logo
down
shadow

How to use the back press to remove the view added by WindowManager?


How to use the back press to remove the view added by WindowManager?

By : Teguh Santosa
Date : November 18 2020, 03:49 PM
this will help guys, I am developing an android AppLock Application, and I use WindowManager to add a gesture lock view. but I have a problem. back key press doesn't remove the view. And I can't rewrite the View to override the dispatchKeyEvent() function, as I use LayoutInflater to inflate my view. Just like that: , Here is a pseudo code that could help.
code :
public class MainActivity extends Activity {
    private MyService mServer;
    ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceDisconnected(ComponentName name) {

        }

        public void onServiceConnected(ComponentName name, IBinder service) {

            LocalBinder mLocalBinder = (LocalBinder) service;
            mServer = mLocalBinder.getServerInstance();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = new Intent(MainActivity.this, MyService.class);
        bindService(intent, mConnection, BIND_AUTO_CREATE);

    }
    @Override
    public void onBackPressed() {
        try{
            mServer.removeWindow();
        }
        catch(IllegalArgumentException e){
            super.onBackPressed();
        }


    }

}

public class MyService extends Service {

    Thread thread;
    WindowManager windowsManager = null;
    WindowManager.LayoutParams params;
    View view;

    IBinder mBinder = new LocalBinder();


    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    public class LocalBinder extends Binder {
        public MyService getServerInstance() {
            return MyService.this;
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                showView();
            }

        }, 5000);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void showView() {
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT, 
                WindowManager.LayoutParams.MATCH_PARENT, 
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN | 
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
                PixelFormat.RGBA_8888);
        params.gravity = (Gravity.CENTER);
        LayoutInflater layoutInflater = 
                (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.view_service, null);
        if(windowsManager == null) {
            windowsManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        }
        if(windowsManager != null && view != null) {
            Message message = addViewHandler.obtainMessage(1);
            addViewHandler.sendMessage(message);
        }

    }

    Handler addViewHandler = new Handler() {

        @Override
        public void handleMessage(Message message) {
            int flag = message.what;
            if(flag == 1) {
                windowsManager.addView(view, params);
            } else if(flag == 0) {
                windowsManager.removeView(view);
            }
        }
    };
    public void removeWindow(){
        windowsManager.removeView(view);
    }

}


Share : facebook icon twitter icon
How to capture keypress in View added by WindowManager

How to capture keypress in View added by WindowManager


By : Josh Green
Date : March 29 2020, 07:55 AM
hop of those help? Views, which added by windows manager not receive onKey event due to android safety politics.
add View by using WindowManager, but can back key press

add View by using WindowManager, but can back key press


By : Очкарик Чмокнутый
Date : March 29 2020, 07:55 AM
Any of those help I've add a View, by using WindowManager. , Have your View override
code :
public boolean dispatchKeyEvent(KeyEvent event) 
In windowManager only the last added View can click or do other operators

In windowManager only the last added View can click or do other operators


By : user3812714
Date : March 29 2020, 07:55 AM
To fix this issue I solve my problem. add flag'WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE' to WindowManager.LayoutParams in every view,and then all view will be worked~
Is possible remove an overlay with WindowManager when press back or home button in android?

Is possible remove an overlay with WindowManager when press back or home button in android?


By : vkate
Date : March 29 2020, 07:55 AM
seems to work fine Simply you need to set the windowmanager type to APPLICATION, this way the windowmanager will attach views while the application is opened only, and no need to overlay home or back buttons, check docs here
code :
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION,
                    0,
                    PixelFormat.TRANSLUCENT);
Animate view added on WindowManager

Animate view added on WindowManager


By : gh426
Date : March 29 2020, 07:55 AM
help you fix your problem You should animate the view LayoutParameters. For example I use a method to update the view layout:
Related Posts Related Posts :
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • ShareActionProvider icon in actionbar
  • How to open a custom attachment using an Android app?
  • Unable to add column dynamically into the sqlite table
  • android persistence activity which never stop
  • The Google Play services resources were not found. Check your project configuration to ensure that the resources are inc
  • How to select files from google drive in android?
  • Run a AsyncTask every 10 seconds until cancelled
  • Blur on touch. Android application
  • NDK Android - Can't build ARMv5 and V7 at the same time
  • Android development with Eclipse clean and build
  • How to set Different Key Background for every Key in Android Custom Keyboard
  • Face recognition using OpenCV in android?
  • Tumblr API - Jumblr for Android [OAuthConnectionException]
  • Small Icon on Notification not working correctly
  • ConstraintLayout match parent height on larger screens but scroll on smaller
  • Kotlin version issue
  • How can i make my android app look the same on RTL and LTR languages?
  • Can not detect Android NDK toolchain
  • Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.
  • Facebook Key Hash for Play Store Release
  • backbutton confirm exit app android + phonegap + jquery
  • How to Make Instagram Listview in android?
  • Up and Down Enemy Movement using translate corona sdk
  • Set selection method is not working in gallery in android
  • How to implement onOptionsItemSelected for Sub-Menu Items?
  • HttpHostConnectException connection refused ConnectException ErrnoException
  • Adding Buttons to expendableListView as last Child
  • Android. Block phone on startup
  • How to programmatically check If string is not to wide to fit onto the screen in Android
  • EditText box cursor appear after touching box?
  • using if statement when video is done playing
  • Add to Aspectpath not found MonkeyTalk
  • GooglePlusUtil cannot be resolved (Android)
  • Trouble understanding Relative Layout
  • How to title/name each fragment separately to appear on PagerTitleStrip?
  • Android webView blinks
  • Available service types in WifiP2pDnsSdServiceInfo.newInstance
  • Hide only bottom action bar Android
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org