I'm trying to reverse engieering a Dialer from a 4.4.4 android device.
I added a onkeydown listener ,so when the user press the '9' button,the listview in the callLogActivity should scroll to top.
Of course I'm editing the smali files,not the java itself,but I'll attach a java code of everything I tried,which didn't give the desired result
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == 16) {
listview.requestFocus();
listview.setSelection(0);
listview.setSelectionAfterHeaderView();
listview.setItemChecked(0, true);
return true;
return super.dispatchKeyEvent(event);
}
}
As you can see,I tried many similar methods, such as setSelection() and setItemChecked() and more....
Actually,The list indeed scrolls to top,but the focus(selected) still stay on the current ListItem..
It's not just a visual effect problem,the focus really stay on the current item(you can see it when you just hit the "ok" button).
If you were wondering what's the meaning of "pressing the ok or '9' button" ,it's the time to expose that device model, it's the xiaomi qin 1s,a feature phone with android OS on it.
Did i miss something?
Related
how can I show a dialog to stay or leave the current page with Vaadin 23, when a user clicks back button on browser?
Regards
It depends what you wish to achieve.
See this older discussion: Vaadin onbeforeunload event
Generally: use the onBeforeUnload javascript even for this
https://www.w3schools.com/tags/ev_onbeforeunload.asp
This is executed when the user would go away from your vaadin app, but not when using the back button inside your vaadin app.
For these you can use the navigation lifecycle events as documented here
https://vaadin.com/docs/latest/routing/lifecycle
Not sure if it also catches, when a user leaves your app...
Assuming you mean, that is it possible to prevent the navigation happening, you simply can't do that. If disabling back button is important for you, the only way is to enforce your users to use the application via desktop shortcut which starts the app using --app paramater (if using Chrome). This is not a limitation in Vaadin, but a general restriction in browser behavior.
There is already a possibility to handle Browser Back Button Event on Vaadin (https://vaadin.com/docs/v14/flow/routing/tutorial-routing-lifecycle):
public class SignupForm extends Div implements BeforeLeaveObserver {
#Override
public void beforeLeave(BeforeLeaveEvent event) {
if (this.hasChanges()) {
ContinueNavigationAction action = event.postpone();
ConfirmDialog.build("Are you sure you want"+
" to leave this page?")
.ifAccept(action::proceed)
.show();
}
}
private boolean hasChanges() {
// no-op implementation
return true;
}
}
This code works once but when you click on Cancel on Confirm Dialog so that you want to stay on current page and click again on Back Button on Browser, than you don't see any Confirm Dialog again... I can not understand, why...
I have an Android Studio project, generated from a Unity3d Project.
I wanted to run my project on a Google Glass so I followed this tutorial (http://forum.unity3d.com/threads/how-to-build-for-google-glass.219558/).
Everything works fine so far, but I can't close the app via swipe down, even though I added this to the UnityPlayerActivity.java:
#Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){ finish(); }
return true;
}
Again, everything else works just fine.
1st UPDATE:
I tried the application on a tablet - like on the Glass, "Back"-button does not work.
Then I implemented this in Unity:
if(Input.GetKeyDown(KeyCode.Escape)){
Application.Quit();
}
Now it works on the tablet, but the Glass-situation did not change.
2nd UPDATE:
This also didn't work: this.finishAffinity();
3rd UPDATE:
I tried to close my Unity Application using this Coroutine in the Start()-Method:
IEnumerator waitAndExit(int sec)
{
yield return new WaitForSeconds(sec);
Application.Quit();
}
This successfully shuts down my application, so the problem appears to be this:
Unity does not recognize swiping down on Google Glass as a keyEvent in Input and the UnityPlayer object seems to get ALL input from android.
How can I stop that?I wan't to handle touchpad events with java, but my original idea - overriding onKeyDown - did not work.
4th Update:
I tried to recognize a gesture like in this answer and added this to my onCreate():
mUnityPlayer.setFocusable(false);
//mUnityPlayer.requestFocus();
Unfortunately it did not help.
This is not really a solution, but rather a work-around:
Using contextual voice commands works fine, even with the UnityPlayer-object blocking touchpad input.
I now close my app via "OK glass - quit".
If anybody figures out how to solve it properly - I'll test, verify and accept your answer.
I'm Developing Android Application for Parental Controlling, so I want to disable home and back button. Because kids are unpredictable, their can push home button or back button and so on. Than i want to disable sliding notification bar. (Because notification bar can change device configuration and setting)
I'm planning to create Android Application which is similar to the Samsung Kids Mode-Parental Control.
Is possible to create application like Samsung Kids Mode? Can you give some link/article or even example program to me?
I Have tried this :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
but it not handle home button, the Home button still working.
Thanks in advance to everyone for taking time to read this, hoping a positive solution.
I dont know of anyway to override the home button. Im not sure that it can be done. You can override the back button like so.
#Override
public void onBackPressed() {
//do nothing, important dont call super.onBackPressed
}
Another this you can do is set the app to immersive mode to reduce the chance of accidently exiting the app
https://developer.android.com/training/system-ui/immersive.html
Extended from Activity
#Override
public void onBackPressed() {
}
can be used to override back button. Be sure to remove super.onBackPressed().
I want my app to start, after the back button was pressed 3Times.
So I created this class which is executed in the Launcher.
public class KeyManager extends Activity {
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(KeyEvent == "Back key"){
Log.e("KM", "PRESSED!!!!!"+keyCode);
}
//return super.onKeyDown(keyCode, event);
return false;
}
}
This code works, if it s implemented in the launcher class, but it does not work, if the app is in the background. How or which key listener do I need for listening to background keys or more if the app is working only in the background?
This is not possible due security reasons. It's more likely a keylogger. If you really want to do that use an AccessibilityService which let you capture the KeyHooks even on a non-rooted Device. Warning: This is Dangerous and user must explizit enable it, to get it activated.
You may/can also modify the default keyboard, to capture those.
I want my app to start, after the back button was pressed 3Times.
You are welcome to download the Android source code, alter the operating system to contain this feature, compile it into a ROM mod, and install that ROM mod on your device.
Otherwise, what you want is not supported by Android.
I have a requirement to restrict the user from pressing back button or disabling the back button in a screen. How should I get the Task done?
And Also on the same screen if user clicks the Ok button all the Screens from Home should get cleared and Home Screen should be displayed.
I got an answer here but it doesn't work. I am testing the app on Simulator 9550. Don't whether it is OS issue.
Thanks.
In order to modify the behaviour when the user presses ESC / back, you simply override the keyChar() method in your Screen subclass(es):
protected boolean keyChar(char c, int status, int time) {
if (c == Characters.ESCAPE) {
// do nothing if ESC was pressed
return true;
} else {
// accept the default behaviour for other keys
return super.keyChar(c, status, time);
}
}
In order to pop (remove) all screens except the app's home screen see this recent answer ... the one you linked to has a bug in it.