List of usage examples for android.view View FOCUS_DOWN
int FOCUS_DOWN
To view the source code for android.view View FOCUS_DOWN.
Click Source Link
From source file:com.codename1.impl.android.AndroidImplementation.java
public PeerComponent createBrowserComponent(final Object parent) { if (getActivity() == null) { return null; }//from w w w . j a v a 2 s. c o m final AndroidImplementation.AndroidBrowserComponent[] bc = new AndroidImplementation.AndroidBrowserComponent[1]; final Throwable[] error = new Throwable[1]; final Object lock = new Object(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { synchronized (lock) { try { WebView wv = new WebView(getActivity()) { public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_BACK); return true; case KeyEvent.KEYCODE_MENU: //if the native commands are used don't handle the keycode if (Display.getInstance() .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) { Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU); return true; } } return super.onKeyDown(keyCode, event); } public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Display.getInstance().keyReleased(AndroidImplementation.DROID_IMPL_KEY_BACK); return true; case KeyEvent.KEYCODE_MENU: //if the native commands are used don't handle the keycode if (Display.getInstance() .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) { Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU); return true; } } return super.onKeyUp(keyCode, event); } }; wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); wv.getSettings().setDomStorageEnabled(true); wv.requestFocus(View.FOCUS_DOWN); wv.setFocusableInTouchMode(true); bc[0] = new AndroidImplementation.AndroidBrowserComponent(wv, getActivity(), parent); lock.notify(); } catch (Throwable t) { error[0] = t; lock.notify(); } } } }); while (bc[0] == null && error[0] == null) { Display.getInstance().invokeAndBlock(new Runnable() { public void run() { synchronized (lock) { if (bc[0] == null && error[0] == null) { try { lock.wait(20); } catch (InterruptedException ex) { ex.printStackTrace(); } } } } }); } if (error[0] != null) { throw new RuntimeException(error[0]); } return bc[0]; }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * What is the distance between the source and destination rectangles given the direction of * focus navigation between them? The direction basically helps figure out more quickly what is * self evident by the relationship between the rects... * * @param source the source rectangle/*from www .jav a 2s . co m*/ * @param dest the destination rectangle * @param direction the direction * @return the distance between the rectangles */ static int getDistance(Rect source, Rect dest, int direction) { int sX, sY; // source x, y int dX, dY; // dest x, y switch (direction) { case View.FOCUS_RIGHT: sX = source.right; sY = source.top + source.height() / 2; dX = dest.left; dY = dest.top + dest.height() / 2; break; case View.FOCUS_DOWN: sX = source.left + source.width() / 2; sY = source.bottom; dX = dest.left + dest.width() / 2; dY = dest.top; break; case View.FOCUS_LEFT: sX = source.left; sY = source.top + source.height() / 2; dX = dest.right; dY = dest.top + dest.height() / 2; break; case View.FOCUS_UP: sX = source.left + source.width() / 2; sY = source.top; dX = dest.left + dest.width() / 2; dY = dest.bottom; break; case View.FOCUS_FORWARD: case View.FOCUS_BACKWARD: sX = source.right + source.width() / 2; sY = source.top + source.height() / 2; dX = dest.left + dest.width() / 2; dY = dest.top + dest.height() / 2; break; default: throw new IllegalArgumentException("direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}."); } int deltaX = dX - sX; int deltaY = dY - sY; return deltaY * deltaY + deltaX * deltaX; }