how to disable Search Button- Android - android-widget

I am displaying a dialog while launching the app, and user has to click on that dialog to move on for next screens, so dialog should not close if user press back/search buttons of the device.
dialog.setCancleble() is working for back button but not for search button.
So, what should I implement to achieve this?

You have to override the Key Event in your Activity. Here is a little snippet which catches few Key Events,
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// PhysicalMenuClicked=true;
}
if(keyCode==KeyEvent.KEYCODE_BACK)
{
// CustomDialog.exitApp_Dialog(context);
}
if(keyCode==KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0)
{
return true; //true means that we are handling the event here.
}
return true;
}

Related

Back Button in webView

When the user clicks on back button, I've implemented the following code that works very well for links inside of my webview:
#Override
public void onBackPressed() {
if (this.webViewFragment != null && this.webViewFragment.canGoBack()) {
this.webViewFragment.goBack();
} else {
super.onBackPressed();
}
}
My problem is that I have native menu in Android, and when the user clicks on the menu Profile for example and then clicks on the menu Dashboard, the back button doesn't work. Nothing happens. As I said before, just works for links clicked inside of the webview.
Anyone knows a solution for that?
or try this
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

JavaFx how to hide popup when mouse is clicked on owner window?

Hi i have javafx app which has only one stage.On tab key press event of text field, a popup showed on primary stage of application. like below
private void tripNoKeyPressEventAction(KeyEvent event){
if(event.getCode() == KeyCode.TAB || event.getCode() == KeyCode.ENTER) {
popup.show(GateIn.primaryStage);
}
}
popup.requestFocus();
popup.focusedProperty().addListener(new ChangeListener<Boolean>
() {
#Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if(t1==false)
{
System.out.println("focus lost");
popup.hide();
}
}
});
I don't click on the popup and don't select anything in popup. I will just click on the stage behind it.I expect popup to be closed but It gives me IllegalArgumentException before executing popup's focusedProperty Listener.
If popup is on a different stage (other than primary stage of aaplication),based on stage focusedProperty() i can hide popup.
How to hide popup in case popup is shown on primary stage?
With FX 8, you can simply do
popup.setAutoHide(true)
You should set a event dispatcher for most top level window then all event will cross it.
In the popup window:
getScene().getWindow().setEventDispatcher((event, tail) -> {
if (event.getEventType() == RedirectedEvent.REDIRECTED) {
// RedirectedEvent is a box that contains original event from other target
RedirectedEvent ev = (RedirectedEvent) event;
if (ev.getOriginalEvent().getEventType() == MouseEvent.MOUSE_PRESSED) {
hide();
}
}else {
// if click in the popup window. handle the event by default
tail.dispatchEvent(event);
}
return null;
});
More information please see javafx.event.EventDispatcher

add View by using WindowManager, but can back key press

I've add a View, by using WindowManager.
It shows properly what I wanted to do,
but I have a problem.
this is the problem.
back key press doesn't affect under android component(like activity)
what I want is my added view can focusable, ( can click the view's inner button )
only when click the view,
and outside of the view can process their work.
( for example, if there is a button, can be clicked, and when back key press, top activity was gone )
but if I add a flag - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
then I can't receive onClick method on my added view's button.
but back button work correctly.
otherwise, if i remove the flag -I can receive onClick callback,
but now back button doesn't work.
I have a dilema. :(
Thank you.
Have your View override
public boolean dispatchKeyEvent(KeyEvent event)
to do something when back is pressed.
Override dispatchKeyEvent of your View
#Override
public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
{
// handle back press
// if (event.getAction() == KeyEvent.ACTION_DOWN)
return true;
}
return super.dispatchKeyEvent(event);
}
You can do like this:
Add a Float window by WindowManager, for example, add a view to screen bottom:
WindowManager windowManager = (WindowManager) getActivity().getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.type= WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
layoutParams.format = PixelFormat.TRANSLUCENT;
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
layoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
FrameLayout view = new FrameLayout(getActivity()) {
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
// do you code
return true;
}
return super.dispatchKeyEvent(event);
}
};
windowManager.addView(view, layoutParams);

Is it possible to expand GWT droplist(ListBox) by keyboard?

I have a flextable full of listboxes set to listBox.setVisibleItemCount(1), so they act as droplists.
When clicked on with the left mouse button they expand and let the user select an item.
Is it possible to mimic the mouse click with a keyboard key?
I've already tried to add keypress handler to the listbox that will fire a mousedown native event, but that did nothing.
Anyone have any idead?
Thanks in advance
I haven't found a solution yet for my problem but I have this workaround that works for now:
listBox.addBlurHandler(new BlurHandler() {
public void onBlur(BlurEvent event) {
ListBox listBox = ((ListBox)event.getSource());
SelectElement.as(listBox.getElement()).setSize(1);
}
});
listBox.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event ) {
if (event.getCharCode() == 32) {
ListBox listBox = ((ListBox)event.getSource());
SelectElement.as(listBox.getElement()).setSize(listBox.getItemCount());
}
}
});

Suppress control-click context menu, gwt 1.6

My gwt 1.6 application intercepts mouse clicks on hyperlinks, so when a user shift-clicks on links to "authors" they get an Edit... dialog box instead of navigating to the author's page. That's working nicely.
I'd now like to allow the user to control-click to select more than one author, but I can't figure out how to suppress the browser's default popup menu. This code handles shift-clicks correctly, but fails in the hosted browser when I control-click and half-fails in Firefox (handleCtrlClick() gets called, but I still get the browser menu):
public void onModuleLoad() {
Event.addNativePreviewHandler(this);
}
//
// Preview events-- look for shift-clicks on paper/author links, and pops up
// edit dialog boxes.
// And looks for control-click to do multiple selection.
//
public void onPreviewNativeEvent(Event.NativePreviewEvent pe) {
NativeEvent e = pe.getNativeEvent();
switch (Event.getTypeInt(e.getType())) {
case Event.ONCLICK:
if (e.getShiftKey()) { handleShiftClick(e); }
if (e.getCtrlKey()) { handleCtrlClick(e); }
break;
case Event.ONCONTEXTMENU:
if (e.getCtrlKey()) { // THIS IS NOT WORKING...
e.preventDefault();
e.stopPropagation();
}
break;
}
}
A breakpoint set inside the ONCONTEXTMENU case is never called.
IIRC ctrl + click is the correct way to select multiple items not ctrl + right click unless you're using a one button mouse (iMac), in that case I can't help you.
Could you provide more details?
Edit:
Why not override the contextmenu (e.g. disable it) then create your own context menu widget (perhaps based on vertical MenuBar + MenuItems) and display it only on Ctrl + RightClick?
In other words you'd create a MouseHandler somewhat like this (pseudo code):
public void onMouseDown(MouseDownEvent event) {
Widget sender = (Widget) event.getSource();
int button = event.getNativeButton();
if (button == NativeEvent.BUTTON_LEFT) {
if(event.is_ctrl_also)
{
// Add to selection
selection = selection + sender;
}
else
{
// Lose selection and start a new one
selection = sender;
}
}
else if(button == NativeEvent.BUTTON_RIGHT) {
if(event.is_ctrl_also)
{
// show context menu
this.contextmenu.show();
}
else
{
// do something else
}
}
return;
}
I've not encountered the bug with Ctrl-Leftclick firing a ContextMenu event, but I'm sure you could also make a workaround for Firefox only using permutations.
I'm getting closer:
public void onModuleLoad() {
Event.addNativePreviewHandler(this); // Catch shift- or control- clicks on links
addContextMenuEventListener(RootPanel.getBodyElement());
}
protected native void addContextMenuEventListener(Element elem) /-{
elem.oncontextmenu = function(e) {
return false; // TODO: only return false if control key down...
};
}-/;
That disables the right-click menu entirely; I'd really like to disable it ONLY if the control key is pressed...