Is there a way to understand if a user, in the home screen, is clicking an app's icon or simply the desktop?
During the develop of a live wallpaper, i overridden the onTouchEvent
function
@Override
public void onTouchEvent(MotionEvent event) {
int action = event.getAction();
float currentXPosition = event.getX();
float currentYPosition = event.getY();
Log.d(Constants.TAG_DISPLAY, "Action = " + action);
Log.d(Constants.TAG_DISPLAY, "X = " + currentXPosition + "Y = " + currentYPosition);
if (action == MotionEvent.ACTION_UP) {
Log.d(Constants.TAG_DISPLAY, "FIRE Action, drawframe");
pos[0] = Math.round(currentXPosition) + 150;
pos[1] = Math.round(currentYPosition) - 50;
drawFrame(true, true);
}
super.onTouchEvent(event);
}
in order to refresh the wallpaper. But I don't want to refresh it if the user is opening an application. From event or the super action, it's possible to determine the user action?
I found a workaround to understand if a user open an app. Just the open process, not bring to foreground a background app.
public int getTotalRunningApp(){
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
return procInfos.size();
}
@Override
public void onTouchEvent(MotionEvent event) {
int runApp = getTotalRunningApp();
Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);
...
super.onTouchEvent(event);
runApp = getTotalRunningApp();
Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);
...
}
By calling getTotalRunningApp()
before and after the real super.onTouchEvent
we can monitorize the number of running app and understand "a little" if a user is tapping an app or just moving homescreen or doing nothing.
It's not working with background app.