Example usage for android.view KeyEvent KEYCODE_TAB

List of usage examples for android.view KeyEvent KEYCODE_TAB

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_TAB.

Prototype

int KEYCODE_TAB

To view the source code for android.view KeyEvent KEYCODE_TAB.

Click Source Link

Document

Key code constant: Tab key.

Usage

From source file:net.kervala.comicsreader.PhotoViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_TAB:
    case KeyEvent.KEYCODE_SEARCH:
        showDialog(CommonActivity.DIALOG_PAGES);
        return true;
    case KeyEvent.KEYCODE_BACK:
        if (mAlbum != null) {
            setResult(CommonActivity.RESULT_FILE);
            //            String mimeType = mAlbum.getMimeType();
            //            Intent intent = getIntent();
            //            intent.setDataAndType(mAlbum.getAlbumUri(), mimeType);
            //            setResult(RESULT_FILE, intent);
        }//  w ww .  j  a  v a  2s .c  o  m
        finish();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:Main.java

public static String getKeyNameByCode(int code) {
    switch (code) {
    case KeyEvent.KEYCODE_0:
        return "<0>";
    case KeyEvent.KEYCODE_1:
        return "<1>";
    case KeyEvent.KEYCODE_2:
        return "<2>";
    case KeyEvent.KEYCODE_3:
        return "<3>";
    case KeyEvent.KEYCODE_4:
        return "<4>";
    case KeyEvent.KEYCODE_5:
        return "<5>";
    case KeyEvent.KEYCODE_6:
        return "<6>";
    case KeyEvent.KEYCODE_7:
        return "<7>";
    case KeyEvent.KEYCODE_8:
        return "<8>";
    case KeyEvent.KEYCODE_9:
        return "<9>";
    case KeyEvent.KEYCODE_A:
        return "<A>";
    case KeyEvent.KEYCODE_B:
        return "<B>";
    case KeyEvent.KEYCODE_C:
        return "<C>";
    case KeyEvent.KEYCODE_D:
        return "<D>";
    case KeyEvent.KEYCODE_E:
        return "<E>";
    case KeyEvent.KEYCODE_F:
        return "<F>";
    case KeyEvent.KEYCODE_G:
        return "<G>";
    case KeyEvent.KEYCODE_H:
        return "<H>";
    case KeyEvent.KEYCODE_I:
        return "<I>";
    case KeyEvent.KEYCODE_J:
        return "<J>";
    case KeyEvent.KEYCODE_K:
        return "<K>";
    case KeyEvent.KEYCODE_L:
        return "<L>";
    case KeyEvent.KEYCODE_M:
        return "<M>";
    case KeyEvent.KEYCODE_N:
        return "<N>";
    case KeyEvent.KEYCODE_O:
        return "<O>";
    case KeyEvent.KEYCODE_P:
        return "<P>";
    case KeyEvent.KEYCODE_Q:
        return "<Q>";
    case KeyEvent.KEYCODE_R:
        return "<R>";
    case KeyEvent.KEYCODE_S:
        return "<S>";
    case KeyEvent.KEYCODE_T:
        return "<T>";
    case KeyEvent.KEYCODE_U:
        return "<U>";
    case KeyEvent.KEYCODE_V:
        return "<V>";
    case KeyEvent.KEYCODE_W:
        return "<W>";
    case KeyEvent.KEYCODE_X:
        return "<X>";
    case KeyEvent.KEYCODE_Y:
        return "<Y>";
    case KeyEvent.KEYCODE_Z:
        return "<Z>";
    case KeyEvent.KEYCODE_APOSTROPHE:
        return "<'>";
    case KeyEvent.KEYCODE_AT:
        return "<@>";
    case KeyEvent.KEYCODE_BACK:
        return "<Back>";
    case KeyEvent.KEYCODE_BACKSLASH:
        return "<\\>";
    case KeyEvent.KEYCODE_CALL:
        return "<Call>";
    case KeyEvent.KEYCODE_CAMERA:
        return "<Camera>";
    case KeyEvent.KEYCODE_CLEAR:
        return "<Clear>";
    case KeyEvent.KEYCODE_COMMA:
        return "<,>";
    case KeyEvent.KEYCODE_DEL:
        return "<Del>";
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "<PadCenter>";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "<PadDown>";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "<PadLeft>";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "<PadRight>";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "<PadUp>";
    case KeyEvent.KEYCODE_ENDCALL:
        return "<EndCall>";
    case KeyEvent.KEYCODE_ENTER:
        return "<Enter>";
    case KeyEvent.KEYCODE_ENVELOPE:
        return "<Envelope>";
    case KeyEvent.KEYCODE_EQUALS:
        return "<=>";
    case KeyEvent.KEYCODE_EXPLORER:
        return "<Explorer>";
    case KeyEvent.KEYCODE_FOCUS:
        return "<??? 0>";
    case KeyEvent.KEYCODE_GRAVE:
        return "<??? 1>";
    case KeyEvent.KEYCODE_HEADSETHOOK:
        return "<??? 2>";
    case KeyEvent.KEYCODE_HOME:
        return "<Home>";
    case KeyEvent.KEYCODE_LEFT_BRACKET:
        return "<(>";
    case KeyEvent.KEYCODE_MENU:
        return "<Menu>";
    case KeyEvent.KEYCODE_MINUS:
        return "<->";
    case KeyEvent.KEYCODE_NOTIFICATION:
        return "<??? 3>";
    case KeyEvent.KEYCODE_NUM:
        return "<Num>";
    case KeyEvent.KEYCODE_PERIOD:
        return "<??? 4>";
    case KeyEvent.KEYCODE_PLUS:
        return "<+>";
    case KeyEvent.KEYCODE_POUND:
        return "<??? 5>";
    case KeyEvent.KEYCODE_POWER:
        return "<Power>";
    case KeyEvent.KEYCODE_RIGHT_BRACKET:
        return "<)>";
    case KeyEvent.KEYCODE_SEMICOLON:
        return "<;>";
    case KeyEvent.KEYCODE_SLASH:
        return "</>";
    case KeyEvent.KEYCODE_SOFT_LEFT:
        return "<??? 6>";
    case KeyEvent.KEYCODE_SOFT_RIGHT:
        return "<??? 7>";
    case KeyEvent.KEYCODE_SPACE:
        return "<Space>";
    case KeyEvent.KEYCODE_STAR:
        return "<*>";
    case KeyEvent.KEYCODE_SYM:
        return "<Sym>";
    case KeyEvent.KEYCODE_TAB:
        return "<Tab>";
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return "<VolumeDown>";
    case KeyEvent.KEYCODE_VOLUME_UP:
        return "<VolumeUp>";
    case KeyEvent.KEYCODE_UNKNOWN:
    default:/* w ww  .j  a  va2 s .  co  m*/
        return "<Unknown>";
    }
}

From source file:com.duy.pascal.ui.editor.view.CodeSuggestsEditText.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    boolean consumed = mPopup.onKeyUp(keyCode, event);
    if (consumed) {
        switch (keyCode) {
        // if the list accepts the key events and the key event
        // was a click, the text view gets the selected item
        // from the drop down as its content
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_TAB:
            if (event.hasNoModifiers()) {
                performCompletion();/*from w w w .  j a va  2  s.  c  o  m*/
            }
            return true;
        }
    }

    if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
        performCompletion();
        return true;
    }

    return super.onKeyUp(keyCode, event);
}

From source file:com.duy.pascal.ui.editor.view.CodeSuggestsEditText.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!hasFocus()) {
        requestFocus();// www  .j a v a 2 s  .  c  o  m
    }
    if (mPopup.onKeyDown(keyCode, event)) {
        return true;
    }

    if (!isPopupShowing()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                performValidation();
            }
        }
    }

    if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
        return true;
    }

    mLastKeyCode = keyCode;
    boolean handled = super.onKeyDown(keyCode, event);
    mLastKeyCode = KeyEvent.KEYCODE_UNKNOWN;

    if (handled && isPopupShowing()) {
        clearListSelection();
    }

    return handled;
}

From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java

/**
 * Initializes the on-screen keys for meta keys and arrow keys.
 *//*w  ww  .  j a  v a  2  s. c o m*/
private void initializeOnScreenKeys() {

    layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys);

    keyStow = (ImageButton) findViewById(R.id.keyStow);
    setKeyStowDrawableAndVisibility();
    keyStow.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (layoutKeys.getVisibility() == View.VISIBLE) {
                extraKeysHidden = true;
                setExtraKeysVisibility(View.GONE, false);
            } else {
                extraKeysHidden = false;
                setExtraKeysVisibility(View.VISIBLE, true);
            }
            layoutKeys.offsetTopAndBottom(prevBottomOffset);
            setKeyStowDrawableAndVisibility();
        }
    });

    // Define action of tab key and meta keys.
    keyTab = (ImageButton) findViewById(R.id.keyTab);
    keyTab.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_TAB;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyTab.setImageResource(R.drawable.tabon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyTab.setImageResource(R.drawable.taboff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyEsc = (ImageButton) findViewById(R.id.keyEsc);
    keyEsc.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = 111; /* KEYCODE_ESCAPE */
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyEsc.setImageResource(R.drawable.escon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyEsc.setImageResource(R.drawable.escoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyCtrl = (ImageButton) findViewById(R.id.keyCtrl);
    keyCtrl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = false;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
        }
    });

    keyCtrl.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = true;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
            return true;
        }
    });

    keySuper = (ImageButton) findViewById(R.id.keySuper);
    keySuper.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = false;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
        }
    });

    keySuper.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = true;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
            return true;
        }
    });

    keyAlt = (ImageButton) findViewById(R.id.keyAlt);
    keyAlt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = false;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
        }
    });

    keyAlt.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = true;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
            return true;
        }
    });

    keyShift = (ImageButton) findViewById(R.id.keyShift);
    keyShift.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = false;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
        }
    });

    keyShift.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = true;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
            return true;
        }
    });

    // TODO: Evaluate whether I should instead be using:
    // vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft);

    // Define action of arrow keys.
    keyUp = (ImageButton) findViewById(R.id.keyUpArrow);
    keyUp.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_UP;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyUp.setImageResource(R.drawable.upon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyUp.setImageResource(R.drawable.upoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyDown = (ImageButton) findViewById(R.id.keyDownArrow);
    keyDown.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_DOWN;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyDown.setImageResource(R.drawable.downon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyDown.setImageResource(R.drawable.downoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow);
    keyLeft.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_LEFT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyLeft.setImageResource(R.drawable.lefton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyLeft.setImageResource(R.drawable.leftoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyRight = (ImageButton) findViewById(R.id.keyRightArrow);
    keyRight.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_RIGHT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyRight.setImageResource(R.drawable.righton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyRight.setImageResource(R.drawable.rightoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });
}

From source file:com.irccloud.android.activity.MainActivity.java

@SuppressLint("NewApi")
@SuppressWarnings({ "deprecation", "unchecked" })
@Override/*from   ww w .  j av  a 2s.  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    suggestionsTimer = new Timer("suggestions-timer");
    countdownTimer = new Timer("messsage-countdown-timer");

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenReceiver, filter);

    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        if (cloud != null) {
            setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                    cloud, 0xFFF2F7FC));
            cloud.recycle();
        }
    }
    setContentView(R.layout.activity_message);
    try {
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    } catch (Throwable t) {
    }

    suggestionsAdapter = new SuggestionsAdapter();
    progressBar = (ProgressBar) findViewById(R.id.progress);
    errorMsg = (TextView) findViewById(R.id.errorMsg);
    buffersListView = findViewById(R.id.BuffersList);
    messageContainer = (LinearLayout) findViewById(R.id.messageContainer);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);

    redColor = getResources().getColor(R.color.highlight_red);
    blueColor = getResources().getColor(R.color.dark_blue);

    messageTxt = (ActionEditText) findViewById(R.id.messageTxt);
    messageTxt.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && messageTxt.getText() != null && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            } else if (keyCode == KeyEvent.KEYCODE_TAB) {
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                    nextSuggestion();
                return true;
            }
            return false;
        }
    });
    messageTxt.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (drawerLayout != null && v == messageTxt && hasFocus) {
                drawerLayout.closeDrawers();
                update_suggestions(false);
            } else if (!hasFocus) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        suggestionsContainer.setVisibility(View.INVISIBLE);
                    }
                });
            }
        }
    });
    messageTxt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawerLayout != null) {
                drawerLayout.closeDrawers();
            }
        }
    });
    messageTxt.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null
                    && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            }
            return true;
        }
    });
    textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Object[] spans = s.getSpans(0, s.length(), Object.class);
            for (Object o : spans) {
                if (((s.getSpanFlags(o) & Spanned.SPAN_COMPOSING) != Spanned.SPAN_COMPOSING)
                        && (o.getClass() == StyleSpan.class || o.getClass() == ForegroundColorSpan.class
                                || o.getClass() == BackgroundColorSpan.class
                                || o.getClass() == UnderlineSpan.class || o.getClass() == URLSpan.class)) {
                    s.removeSpan(o);
                }
            }
            if (s.length() > 0
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED) {
                sendBtn.setEnabled(true);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(1);
            } else {
                sendBtn.setEnabled(false);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(0.5f);
            }
            String text = s.toString();
            if (text.endsWith("\t")) { //Workaround for Swype
                text = text.substring(0, text.length() - 1);
                messageTxt.setText(text);
                nextSuggestion();
            } else if (suggestionsContainer != null && suggestionsContainer.getVisibility() == View.VISIBLE) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        update_suggestions(false);
                    }
                });
            } else {
                if (suggestionsTimer != null) {
                    if (suggestionsTimerTask != null)
                        suggestionsTimerTask.cancel();
                    suggestionsTimerTask = new TimerTask() {
                        @Override
                        public void run() {
                            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                            update_suggestions(false);
                        }
                    };
                    suggestionsTimer.schedule(suggestionsTimerTask, 250);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    };
    messageTxt.addTextChangedListener(textWatcher);
    sendBtn = findViewById(R.id.sendBtn);
    sendBtn.setFocusable(false);
    sendBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED)
                new SendTask().execute((Void) null);
        }
    });

    photoBtn = findViewById(R.id.photoBtn);
    if (photoBtn != null) {
        photoBtn.setFocusable(false);
        photoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                insertPhoto();
            }
        });
    }
    userListView = findViewById(R.id.usersListFragment);

    View v = getLayoutInflater().inflate(R.layout.actionbar_messageview, null);
    v.findViewById(R.id.actionTitleArea).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            show_topic_popup();
        }
    });

    if (drawerLayout != null) {
        if (findViewById(R.id.usersListFragment2) == null) {
            upDrawable = new DrawerArrowDrawable(this);
            greyColor = upDrawable.getColor();
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationIcon(upDrawable);
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationContentDescription("Show navigation drawer");
            drawerLayout.setDrawerListener(mDrawerListener);
            if (refreshUpIndicatorTask != null)
                refreshUpIndicatorTask.cancel(true);
            refreshUpIndicatorTask = new RefreshUpIndicatorTask();
            refreshUpIndicatorTask.execute((Void) null);
        }
    }
    messageTxt.setDrawerLayout(drawerLayout);

    title = (TextView) v.findViewById(R.id.title);
    subtitle = (TextView) v.findViewById(R.id.subtitle);
    key = (ImageView) v.findViewById(R.id.key);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        server = ServersDataSource.getInstance().getServer(savedInstanceState.getInt("cid"));
        buffer = BuffersDataSource.getInstance().getBuffer(savedInstanceState.getInt("bid"));
        backStack = (ArrayList<Integer>) savedInstanceState.getSerializable("backStack");
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("imagecaptureuri"))
        imageCaptureURI = Uri.parse(savedInstanceState.getString("imagecaptureuri"));
    else
        imageCaptureURI = null;

    ConfigInstance config = (ConfigInstance) getLastCustomNonConfigurationInstance();
    if (config != null) {
        imgurTask = config.imgurUploadTask;
        fileUploadTask = config.fileUploadTask;
    }

    drawerLayout.setScrimColor(0);
    drawerLayout.closeDrawers();

    getSupportActionBar().setElevation(0);
}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

/**
 * Initializes the on-screen keys for meta keys and arrow keys.
 */// w  w  w .  j a va  2  s .  co  m
private void initializeOnScreenKeys() {

    layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys);

    keyStow = (ImageButton) findViewById(R.id.keyStow);
    setKeyStowDrawableAndVisibility();
    keyStow.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (layoutKeys.getVisibility() == View.VISIBLE) {
                extraKeysHidden = true;
                setExtraKeysVisibility(View.GONE, false);
            } else {
                extraKeysHidden = false;
                setExtraKeysVisibility(View.VISIBLE, true);
            }
            layoutKeys.offsetTopAndBottom(prevBottomOffset);
            setKeyStowDrawableAndVisibility();
        }
    });

    // Define action of tab key and meta keys.
    keyTab = (ImageButton) findViewById(R.id.keyTab);
    keyTab.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_TAB;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyTab.setImageResource(R.drawable.tabon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyTab.setImageResource(R.drawable.taboff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyEsc = (ImageButton) findViewById(R.id.keyEsc);
    keyEsc.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = 111; /* KEYCODE_ESCAPE */
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyEsc.setImageResource(R.drawable.escon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyEsc.setImageResource(R.drawable.escoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyCtrl = (ImageButton) findViewById(R.id.keyCtrl);
    keyCtrl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = false;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
        }
    });

    keyCtrl.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            myVibrator.vibrate(Constants.SHORT_VIBRATION);
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = true;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
            return true;
        }
    });

    keySuper = (ImageButton) findViewById(R.id.keySuper);
    keySuper.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = false;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
        }
    });

    keySuper.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            myVibrator.vibrate(Constants.SHORT_VIBRATION);
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = true;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
            return true;
        }
    });

    keyAlt = (ImageButton) findViewById(R.id.keyAlt);
    keyAlt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = false;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
        }
    });

    keyAlt.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            myVibrator.vibrate(Constants.SHORT_VIBRATION);
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = true;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
            return true;
        }
    });

    keyShift = (ImageButton) findViewById(R.id.keyShift);
    keyShift.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = false;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
        }
    });

    keyShift.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            myVibrator.vibrate(Constants.SHORT_VIBRATION);
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = true;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
            return true;
        }
    });

    // Define action of arrow keys.
    keyUp = (ImageButton) findViewById(R.id.keyUpArrow);
    keyUp.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_UP;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyUp.setImageResource(R.drawable.upon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyUp.setImageResource(R.drawable.upoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyDown = (ImageButton) findViewById(R.id.keyDownArrow);
    keyDown.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_DOWN;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyDown.setImageResource(R.drawable.downon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyDown.setImageResource(R.drawable.downoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow);
    keyLeft.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_LEFT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyLeft.setImageResource(R.drawable.lefton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyLeft.setImageResource(R.drawable.leftoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyRight = (ImageButton) findViewById(R.id.keyRightArrow);
    keyRight.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_RIGHT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                myVibrator.vibrate(Constants.SHORT_VIBRATION);
                keyRight.setImageResource(R.drawable.righton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyRight.setImageResource(R.drawable.rightoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });
}

From source file:com.redinput.datetimepickercompat.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * //from ww w .  j a  v  a2  s.  co  m
 * @param keyCode
 *            the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format(Locale.getDefault(), "%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java

/**
  * Initializes the on-screen keys for meta keys and arrow keys.
  *///from   w ww  .  j av a 2  s .c  o  m
private void initializeOnScreenKeys() {

    layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys);

    keyStow = (ImageButton) findViewById(R.id.keyStow);
    setKeyStowDrawableAndVisibility();
    keyStow.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (layoutKeys.getVisibility() == View.VISIBLE) {
                extraKeysHidden = true;
                setExtraKeysVisibility(View.GONE, false);
            } else {
                extraKeysHidden = false;
                setExtraKeysVisibility(View.VISIBLE, true);
            }
            layoutKeys.offsetTopAndBottom(prevBottomOffset);
            setKeyStowDrawableAndVisibility();
        }
    });

    // Define action of tab key and meta keys.
    keyTab = (ImageButton) findViewById(R.id.keyTab);
    keyTab.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_TAB;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyTab.setImageResource(R.drawable.tabon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyTab.setImageResource(R.drawable.taboff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyEsc = (ImageButton) findViewById(R.id.keyEsc);
    keyEsc.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = 111; /* KEYCODE_ESCAPE */
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyEsc.setImageResource(R.drawable.escon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyEsc.setImageResource(R.drawable.escoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyCtrl = (ImageButton) findViewById(R.id.keyCtrl);
    keyCtrl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = false;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
        }
    });

    keyCtrl.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenCtrlToggle();
            keyCtrlToggled = true;
            if (on)
                keyCtrl.setImageResource(R.drawable.ctrlon);
            else
                keyCtrl.setImageResource(R.drawable.ctrloff);
            return true;
        }
    });

    keySuper = (ImageButton) findViewById(R.id.keySuper);
    keySuper.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = false;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
        }
    });

    keySuper.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenSuperToggle();
            keySuperToggled = true;
            if (on)
                keySuper.setImageResource(R.drawable.superon);
            else
                keySuper.setImageResource(R.drawable.superoff);
            return true;
        }
    });

    keypad = (HangulKeypad) findViewById(R.id.hangul_keypad);
    keypad.setVncKeyboard(canvas);
    keypad.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            btnChatShowToggle.setVisibility(View.VISIBLE);
            keypad.setVisibility(View.GONE);
            keypad.setTag("");
            keyKor.setVisibility(View.VISIBLE);
            if (v.getId() == R.id.key_show_eng) {
                InputMethodManager inputMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMgr.toggleSoftInput(0, 0);
            }
        }
    });

    //TODO
    keyKor = (Button) findViewById(R.id.keyKor);
    keyKor.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String toggle = (String) keypad.getTag();

            if (TextUtils.isEmpty(toggle)) {
                InputMethodManager inputMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMgr.hideSoftInputFromWindow(btnChatShowToggle.getWindowToken(), 0);

                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        canvas.getKeyboard().processLocalKeyEvent(144, new KeyEvent(144, 0));

                        keyKor.setVisibility(View.GONE);
                        keypad.setVisibility(View.VISIBLE);
                        keypad.setTag("1");
                    }
                }, 500);
            } else {
                keyKor.setVisibility(View.VISIBLE);
                btnChatShowToggle.setVisibility(View.VISIBLE);

                keypad.setVisibility(View.GONE);
                keypad.setTag("");
            }
        }
    });

    keyAlt = (ImageButton) findViewById(R.id.keyAlt);
    keyAlt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = false;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
        }
    });

    keyAlt.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenAltToggle();
            keyAltToggled = true;
            if (on)
                keyAlt.setImageResource(R.drawable.alton);
            else
                keyAlt.setImageResource(R.drawable.altoff);
            return true;
        }
    });

    keyShift = (ImageButton) findViewById(R.id.keyShift);
    keyShift.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = false;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
        }
    });

    keyShift.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
            boolean on = canvas.getKeyboard().onScreenShiftToggle();
            keyShiftToggled = true;
            if (on)
                keyShift.setImageResource(R.drawable.shifton);
            else
                keyShift.setImageResource(R.drawable.shiftoff);
            return true;
        }
    });

    // vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft);

    // Define action of arrow keys.
    keyUp = (ImageButton) findViewById(R.id.keyUpArrow);
    keyUp.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_UP;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyUp.setImageResource(R.drawable.upon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyUp.setImageResource(R.drawable.upoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyDown = (ImageButton) findViewById(R.id.keyDownArrow);
    keyDown.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_DOWN;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyDown.setImageResource(R.drawable.downon);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyDown.setImageResource(R.drawable.downoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow);
    keyLeft.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_LEFT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyLeft.setImageResource(R.drawable.lefton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyLeft.setImageResource(R.drawable.leftoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });

    keyRight = (ImageButton) findViewById(R.id.keyRightArrow);
    keyRight.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent e) {
            RemoteKeyboard k = canvas.getKeyboard();
            int key = KeyEvent.KEYCODE_DPAD_RIGHT;
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas);
                keyRight.setImageResource(R.drawable.righton);
                k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key));
                return true;
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
                keyRight.setImageResource(R.drawable.rightoff);
                resetOnScreenKeys(0);
                k.stopRepeatingKeyEvent();
                return true;
            }
            return false;
        }
    });
}

From source file:mirko.android.datetimepicker.time.TimePickerDialogSupport.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//  w  ww  . j av a  2s .c  o  m
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this, mTimePicker.getHours(), mTimePicker.getMinutes());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}