Last active
August 29, 2015 14:08
-
-
Save crossproduct/305c5a1fe3a9b790ba21 to your computer and use it in GitHub Desktop.
Kiosk App Snippets : Android : 4.4.4 API 19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** Custom ViewGroup class which will be used to EAT all the touch events. nom nom nom. ** | |
public class customViewGroup extends ViewGroup { | |
public customViewGroup(Context context) { | |
super(context); | |
} | |
@Override | |
protected void onLayout(boolean changed, int l, int t, int r, int b) { | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent ev) { | |
Log.v("customViewGroup", "**********Intercepted"); | |
return false; | |
} | |
} | |
** REQUIRES THIS PERMISSION ** | |
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> | |
** USING IT ** | |
// get a window manager | |
WindowManager manager = ((WindowManager) getApplicationContext() | |
.getSystemService(Context.WINDOW_SERVICE)); | |
// create some layout parameters | |
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); | |
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; | |
localLayoutParams.gravity = Gravity.TOP; | |
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| | |
// this is to enable the notification to receive touch events | |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | | |
// Draws over status bar | |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; | |
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; | |
localLayoutParams.height = (int) (25 * getResources().getDisplayMetrics().scaledDensity); // 25 seems to be the safest minimum | |
localLayoutParams.format = PixelFormat.TRANSPARENT; | |
customViewGroup view = new customViewGroup(this); | |
manager.addView(view, localLayoutParams); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment