Android based desktop floating clean memory app overview

  • 2020-12-07 04:26:37
  • OfStack

Today, be free and at leisure wrote a small thing to clear the memory, similar to 360, hovering on the desktop, click to clear the background useless programs, the background program is cleared by calling ActivityManger.killBackgroundProcesses way, this way has a bad place, is the importance level set high application can not kill. The key code is shown below


ActivityManager mActivityManager = MyManager.getActivityManager(mContext);
     List<ActivityManager.RunningAppProcessInfo> process = mActivityManager.getRunningAppProcesses();
     for(int i=;i<process.size();i++){
      ActivityManager.RunningAppProcessInfo ar = process.get(i);
      String packageName = ar.processName;
      packageName = packageName.split(":")[];
      // Background whose importance level is greater than and is not trusted will be killed 
      if(ar.importance> && !MyManager.isTrust(packageName)){
       MyManager.getActivityManager(mContext).killBackgroundProcesses(packageName);
      }
     } 

There is also a partial feature, desktop levitation, which is added to the desktop via WindowManger objects, and the key code is shown below


 WindowManager windowManager = getWindowManager(context); 
   int screenWidth = windowManager.getDefaultDisplay().getWidth();
   int screenHeight = windowManager.getDefaultDisplay().getHeight();
   if(mSmallFloatWin==null){
    mSmallFloatWin = new SmallFloatWin(context);
    if (smallWindowParams == null) { 
     smallWindowParams = new LayoutParams(); 
     smallWindowParams.type = LayoutParams.TYPE_PHONE; 
     smallWindowParams.format = PixelFormat.RGBA_; 
     smallWindowParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL 
       | LayoutParams.FLAG_NOT_FOCUSABLE; 
     smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP; 
     smallWindowParams.width = SmallFloatWin.viewWidth; 
     smallWindowParams.height = SmallFloatWin.viewHeight; 
     smallWindowParams.x = screenWidth; 
     smallWindowParams.y = screenHeight / ; 
    } 
    mSmallFloatWin.setParams(smallWindowParams);
    windowManager.addView(mSmallFloatWin, smallWindowParams); 
   } 

mSmallFloatWin is the view object you want to float out of.

Postscript: this little thing kill background program effect is not good, there is another way of thinking through root's permission to execute adb command to carry out background program.

The class ES20en.LayoutParams is used to provide the parameters required for the suspension window. There are several variables that are frequently used:

The type value is used to determine the type of suspension window, generally set to 2002, above all applications but below the status bar.

The flags value is used to determine the behavior of the hover window, such as non-focusable, modeless dialogs, etc. There are a lot of properties that you can look at in the documentation.

The gravity value is used to determine the alignment of the levitating window. Generally, 1 is set to the upper left corner alignment so that coordinates can be calculated when dragging the levitating window.

The x value is used to determine the position of the suspension window, which needs to be changed if the suspension window is to be moved laterally.

The y value is used to determine the position of the suspension window, which needs to be changed if the suspension window is to be moved vertically.

The width value is used to specify the width of the suspension window.

The height value is used to specify the height of the floating window.


Related articles: