package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends Activity {
private static WindowManager mWindowMgr = null;
private mWindowMgrParams = null;
private static FloatsWindowView mFloatsWindowView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView(.activity_main);
}
@Override
protected void onStop() {
();
deleteIconToStatusbar();
}
/*
* Remove the suspension layer when displaying the main application interface
* Modify the icon on the status bar
*/
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
if(mFloatsWindowView != null){
(mFloatsWindowView);
mFloatsWindowView = null;
}
addIconToStatusbar(.a0);
}else{
getWindowLayout();
addIconToStatusbar(.ic_launcher);
}
}
private void initParams(){
DisplayMetrics dm = getResources().getDisplayMetrics();
= - 136;
= 300;
= 136;
= 136;
}
private void getWindowLayout(){
if(mFloatsWindowView == null){
mWindowMgr = (WindowManager)getBaseContext().getSystemService(Context.WINDOW_SERVICE);
mWindowMgrParams = new ();
/*
* 2003 On fingers suspended over all interfaces
* (In 4.0+ system, below the drop-down menu, and in 2.3, above the pull-up menu)
*/
= 2003;
= 1;
/*
* The code is actually |= FLAG_NOT_FOCUSABLE;
* The origin of 40 is the default attribute of wmParams (32) + FLAG_NOT_FOCUSABLE (8)
*/
= 40;
= | ;
initParams();
mFloatsWindowView = new FloatsWindowView(this);
(mFloatsWindowView, mWindowMgrParams);
}
}
private final static int NOTIFICATION_ID_ICON = 0x10000;
/*
* If ICON is not removed from the status bar and continue to call addIconToStatusbar,
* No changes will be made. Apart from:
* If you set the resId in notification to a different icon, different will be displayed.
* icon
*/
private void addIconToStatusbar(int resId){
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification(
resId, "Floats Start!", ());
// Put this notification in the "Ongoing" in the notification bar, that is, the "Running" group
|= Notification.FLAG_ONGOING_EVENT;
// It indicates that after clicking "Clear Notification" in the notification bar, this notification will not be cleared.
// Used frequently with FLAG_ONGOING_EVENT
|= Notification.FLAG_NO_CLEAR;
PendingIntent pi = (this, 0, getIntent(), 0);
= pi;
(this, "FloatsWindow", "start!", pi);
(NOTIFICATION_ID_ICON, n);
}
private void deleteIconToStatusbar(){
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
(NOTIFICATION_ID_ICON);
}
}