I am beginner in Android, and I am trying to create a touch blocker app so,
Can we disable the touch sensitivity of the screen by using certain gesture in android using java ,and the sensitivity of the screen should be back to normal with certain gestures in android application using java.
If possible can anyone give bird view of code snippet?
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
ConstraintLayout parentLayout = (ConstraintLayout) findViewById(R.id.main_layout);
parentLayout.setClipChildren(true);
myLayout.setEnabled(false);
Related
Hi guys i'm a beginner on android studio,
I noticed that when I run my app on my phone, the status bar and also the on-screen buttons are visible but on my friend's device there is no status bar or on-screen buttons so it uses the full resolution, how can i force the app to have both on all devices? The resolution for my phone and his phone is the same (1080x2340) but on his phone it's like it just zooms out.
Is there a way to set the app to work the same on both devices? I mean, the resolution is the SAME but the app looks different because of status bar/on-screen buttons.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
I'm adding a view to windows manager using these layout parameters:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
The expected result is an overlay window that covers the entire screen except the system ui (navigation bar and status bar) and doesn't cover the soft keyboard.
The above parameters do that but the problem is that the navigation bar buttons are not visible while the soft keyboard is open.
Current result:
Expected result:
I've tried a couple of flags like:
WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR
and a combination of:
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
But none of them worked.
I've also gone through the documentation for system ui but most option there that involve WindowManager.LayoutParams flags are for hiding the decoration and the rest of them require a reference to the window which I don't think I can get from an accessibility service.
The problem seems to be the:
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
flag, if I remove it, the navigation buttons are visible but the overlay will cover the keyboard, it will do that even if I use something like this:
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
My question:
Is there any way to have an overlay that doesn't cover the keyboard and doesn't hide the navigation bar buttons ?
Did you try switching from PixelFormat.TRANSLUCENT to PixelFormat.TRANSPARENT? Also:
.apply {
gravity = Gravity.BOTTOM //CENTER or whatever
x = 0
y = 0
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
So I have a custom ListPreference that I want to hide the System UI Elements once the dialog box is presented on the screen.
I have found a post about how to hide element inside the dialog box itself (like the cancel button and title), however, I am not quite sure on how to access those particular pieces.
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
//hide System UI elements here
}
This looks like a good place to make the changes to me, however, I am not 100% on it.
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
This is how the activities accomplish what I am trying to achieve.
getView() is also what I assume to be an approach to this, however, I am not quite sure if the dialog box is a Fragment or not.
Ok so I am able to hide the UI elements but it seem like there is still some sort of transparent bars left over.
Does anyone know of a way to get rid of these remnant bars?
#Override
protected void showDialog(Bundle state) {
super.showDialog(state);
getDialog().getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
This is how I am getting rid of the System UI Elements.
Just updated to the new Android SDK Rev 22.3 with Android 4.4 support. After that I see AdView doesn't have a setGravity method anymore.
I need this as i'm making a Unity3D plugin and can't use XML markup.
EDIT: I'm trying to align the AdView to either the BottomLeft, BottomCenter, TopLeft, ect, ect... So any other way to do it would be helpful as Java on Android isn't my typical environment I use.
I found the solution for that. I previously relied on the setGravity method. To get the same thing I do it in this way:
/// Create a AdView
AdView myAdView = new AdView(MY_ACTIVITY);
myAdView.setAdUnitId(<ADMOB ID>);
myAdView.setAdSize(AdSize.SMART_BANNER);
/// Set the initial frame
FrameLayout.LayoutParams initialFrm = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.TOP);
MY_ACTIVITY.addContentView(myAdView, initialFrm);
/// ....
/// Now whenever I want to position it on the bottom I do this:
myAdView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
/// To put it back on the top, do this:
myAdView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.TOP));
As seen in this app, I want to create an app which dims the screen by creating a shaded overlay.
The window is created, and it's partially transparent, however, I cannot get the applications below it to launch. I can click them, and see the button presses, but other apps cannot launch while mine is running.
Suggestions?
I enclosed my code below, and an example of an app which is already doing this.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup mTopView = (ViewGroup) inflater.inflate(R.layout.activity_black, null);
getWindow().setAttributes(params);
wm.addView(mTopView, params);
https://play.google.com/store/apps/details?id=com.haxor
This is an easy way:
Dialog dialog = new Dialog(this,android.R.style.Theme_DeviceDefault_Dialog_NoActionBar_MinWidth);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
dialog.getWindow().setFormat(PixelFormat.TRANSLUCENT);
dialog.getWindow().setDimAmount(0);
dialog.setContentView(new EditText(this));
dialog.show();
Modified the Activity to be settings, and moved the blacking component to a service, which worked fine.