Example usage for android.view KeyEvent KEYCODE_ENTER

List of usage examples for android.view KeyEvent KEYCODE_ENTER

Introduction

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

Prototype

int KEYCODE_ENTER

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

Click Source Link

Document

Key code constant: Enter key.

Usage

From source file:org.zirco.ui.activities.MainActivity.java

/**
 * Create main UI./*from ww w.  j  a  v a 2s .co m*/
 */
private void buildComponents() {

    mToolsActionGrid = new QuickActionGrid(this);
    mToolsActionGrid.addQuickAction(new QuickAction(this, R.drawable.ic_btn_home, R.string.QuickAction_Home));
    mToolsActionGrid.addQuickAction(new QuickAction(this, R.drawable.ic_btn_share, R.string.QuickAction_Share));
    mToolsActionGrid
            .addQuickAction(new QuickAction(this, R.drawable.ic_btn_select, R.string.QuickAction_SelectText));
    mToolsActionGrid.addQuickAction(
            new QuickAction(this, R.drawable.ic_btn_mobile_view, R.string.QuickAction_MobileView));

    mToolsActionGrid.setOnQuickActionClickListener(new OnQuickActionClickListener() {
        @Override
        public void onQuickActionClicked(QuickActionWidget widget, int position) {
            switch (position) {
            case 0:
                navigateToHome();
                break;
            case 1:
                ApplicationUtils.sharePage(MainActivity.this, mCurrentWebView.getTitle(),
                        mCurrentWebView.getUrl());
                break;
            case 2:
                swithToSelectAndCopyTextMode();
                break;
            case 3:
                String currentUrl = mUrlEditText.getText().toString();

                // Do not reload mobile view if already on it.
                if (!currentUrl.startsWith(Constants.URL_GOOGLE_MOBILE_VIEW_NO_FORMAT)) {
                    String url = String.format(Constants.URL_GOOGLE_MOBILE_VIEW,
                            mUrlEditText.getText().toString());
                    navigateToUrl(url);
                }
                break;
            }
        }
    });

    mToolsActionGrid.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            mToolsActionGridVisible = false;
            startToolbarsHideRunnable();
        }
    });

    mGestureDetector = new GestureDetector(this, new GestureListener());

    mUrlBarVisible = true;

    mWebViews = new ArrayList<CustomWebView>();
    Controller.getInstance().setWebViewList(mWebViews);

    mBubbleRightView = (ImageView) findViewById(R.id.BubbleRightView);
    mBubbleRightView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setToolbarsVisibility(true);
        }
    });
    mBubbleRightView.setVisibility(View.GONE);

    mBubbleLeftView = (ImageView) findViewById(R.id.BubbleLeftView);
    mBubbleLeftView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setToolbarsVisibility(true);
        }
    });
    mBubbleLeftView.setVisibility(View.GONE);

    mViewPager = (CustomViewPager) findViewById(R.id.ViewPager);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {
            Log.d("onPageSelected", Integer.toString(arg0));
            CustomWebView oldWebView = mPagerAdapter.getWebViewAtIndex(mCurrentDisplayedViewIndex);
            mCurrentDisplayedViewIndex = arg0;
            mCurrentWebView = mPagerAdapter.getWebViewAtIndex(mCurrentDisplayedViewIndex);

            oldWebView.doOnPause();
            mCurrentWebView.doOnResume();

            startToolbarsHideRunnable();

            showToastOnTabSwitch();

            updatePreviousNextTabViewsVisibility();
            updateUI();
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });

    mPagerAdapter = new CustomPagerAdapter(this, mViewPager);
    mViewPager.setAdapter(mPagerAdapter);

    mTopBar = (LinearLayout) findViewById(R.id.BarLayout);
    mTopBar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Dummy event to steel it from the WebView, in case of clicking between the buttons.            
        }
    });

    mBottomBar = (LinearLayout) findViewById(R.id.BottomBarLayout);
    mBottomBar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Dummy event to steel it from the WebView, in case of clicking between the buttons.            
        }
    });

    mPreviousTabView = (ImageView) findViewById(R.id.PreviousTabView);
    mPreviousTabView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPreviousTab(true);
        }
    });
    mPreviousTabView.setVisibility(View.GONE);

    mNextTabView = (ImageView) findViewById(R.id.NextTabView);
    mNextTabView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showNextTab(true);
        }
    });
    mNextTabView.setVisibility(View.GONE);

    String[] from = new String[] { UrlSuggestionCursorAdapter.URL_SUGGESTION_TITLE,
            UrlSuggestionCursorAdapter.URL_SUGGESTION_URL };
    int[] to = new int[] { R.id.AutocompleteTitle, R.id.AutocompleteUrl };

    UrlSuggestionCursorAdapter adapter = new UrlSuggestionCursorAdapter(this, R.layout.url_autocomplete_line,
            null, from, to);

    adapter.setCursorToStringConverter(new CursorToStringConverter() {
        @Override
        public CharSequence convertToString(Cursor cursor) {
            String aColumnString = cursor
                    .getString(cursor.getColumnIndex(UrlSuggestionCursorAdapter.URL_SUGGESTION_URL));
            return aColumnString;
        }
    });

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {
            if ((constraint != null) && (constraint.length() > 0)) {
                return BookmarksProviderWrapper.getUrlSuggestions(getContentResolver(), constraint.toString(),
                        PreferenceManager.getDefaultSharedPreferences(MainActivity.this)
                                .getBoolean(Constants.PREFERENCE_USE_WEAVE, false));
            } else {
                return BookmarksProviderWrapper.getUrlSuggestions(getContentResolver(), null,
                        PreferenceManager.getDefaultSharedPreferences(MainActivity.this)
                                .getBoolean(Constants.PREFERENCE_USE_WEAVE, false));
            }
        }
    });

    mUrlEditText = (AutoCompleteTextView) findViewById(R.id.UrlText);
    mUrlEditText.setThreshold(1);
    mUrlEditText.setAdapter(adapter);

    mUrlEditText.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                navigateToUrl();
                return true;
            }

            return false;
        }

    });

    mUrlTextWatcher = new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void afterTextChanged(Editable arg0) {
            updateGoButton();
        }
    };

    mUrlEditText.addTextChangedListener(mUrlTextWatcher);

    mUrlEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Select all when focus gained.
            if (hasFocus) {
                mUrlEditText.setSelection(0, mUrlEditText.getText().length());
            }
        }
    });

    mUrlEditText.setCompoundDrawablePadding(5);

    mGoButton = (ImageButton) findViewById(R.id.GoBtn);
    mGoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            if (mCurrentWebView.isLoading()) {
                mCurrentWebView.stopLoading();
            } else if (!mCurrentWebView.isSameUrl(mUrlEditText.getText().toString())) {
                navigateToUrl();
            } else {
                mCurrentWebView.reload();
            }
        }
    });

    mToolsButton = (ImageButton) findViewById(R.id.ToolsBtn);
    mToolsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mToolsActionGridVisible = true;
            mToolsActionGrid.show(v);
        }
    });

    mProgressBar = (ProgressBar) findViewById(R.id.WebViewProgress);
    mProgressBar.setMax(100);

    mPreviousButton = (ImageButton) findViewById(R.id.PreviousBtn);
    mNextButton = (ImageButton) findViewById(R.id.NextBtn);

    mPreviousButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            navigatePrevious();
        }
    });

    mNextButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            navigateNext();
        }
    });

    mNewTabButton = (ImageButton) findViewById(R.id.NewTabBtn);
    mNewTabButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            addTab(true, mCurrentDisplayedViewIndex + 1);
        }
    });

    mRemoveTabButton = (ImageButton) findViewById(R.id.RemoveTabBtn);
    mRemoveTabButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            removeCurrentTab();
        }
    });

    mQuickButton = (ImageButton) findViewById(R.id.QuickBtn);
    mQuickButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onQuickButton();
        }
    });

}

From source file:cn.fulldroid.lib.datetimepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./*from   w  w w .j a v a  2  s .  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(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("%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.hirecraft.controls.mylib.datetimepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//w  w w .j  av a2  s . c  om
 * @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("%d", getValFromKeyCode(deleted));
                }
                DateTimeUtils.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.googlecode.eyesfree.brailleback.IMENavigationModeTest.java

/**
 * Tests that text and navigation mode is not triggered when the input view
 * is not shown, even if input is started. This distinction is needed to
 * handle Chrome correctly./*from  w  ww  . j  a va  2  s. c o  m*/
 */
public void testTextAndNavigationModeRequiresStartInputView() {
    EditorInfo ei = new EditorInfo();

    // Mock out the AccessibilityNodeInfo.
    // The class actually uses the compat variant, but on recent API
    // releases (including the test environment) they should call through.
    AccessibilityNodeInfo rawNode = mock(AccessibilityNodeInfo.class);
    when(mAccessibilityService.getRootInActiveWindow()).thenReturn(rawNode);
    when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)).thenReturn(rawNode);
    when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)).thenReturn(rawNode);
    when(rawNode.getClassName()).thenReturn("com.example.ExampleWebView");
    when(mSelfBrailleManager.hasContentForNode(compatWrapperForNode(rawNode))).thenReturn(true);

    mIMENavMode.onActivate();
    mIMENavMode.onCreateIME();
    verify(mNext).onActivate();
    mIMENavMode.onBindInput();
    mIMENavMode.onStartInput(ei, false /* restarting */);

    assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator());
    assertNull(mIMENavMode.getDisplayManager());
    assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager());
    verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false);

    AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent);
        verify(mNext).onObserveAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onAccessibilityEvent(accessibilityEvent);
        verify(mNext).onAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();
    try {
        mIMENavMode.onInvalidateAccessibilityNode(node);
        verify(mNext).onInvalidateAccessibilityNode(node);
    } finally {
        node.recycle();
    }

    DisplayManager.Content content = new DisplayManager.Content("");
    mIMENavMode.onPanLeftOverflow(content);
    verify(mNext).onPanLeftOverflow(content);
    mIMENavMode.onPanRightOverflow(content);
    verify(mNext).onPanRightOverflow(content);

    BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).handleBrailleKey(0x1b);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).moveCursor(anyInt(), anyInt());

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).sendDefaultAction();

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).route(anyInt(), any(DisplayManager.Content.class));

    mIMENavMode.onFinishInput();
    mIMENavMode.onUnbindInput();
    mIMENavMode.onDestroyIME();

    verify(mSelfBrailleManager, never()).setImeOpen(true);

    // Deactivate, but make sure it didn't happen too early.
    verify(mNext, never()).onDeactivate();
    mIMENavMode.onDeactivate();
    verify(mNext).onDeactivate();
}

From source file:com.azuyo.happybeing.fourmob.timepicker.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//w  ww. j a  v a  2  s  .co  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(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("%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:org.connectbot.ConsoleActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        StrictModeSetup.run();//from w w w  .  j av a2s .  c o  m
    }

    hardKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;

    clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    titleBarHide = prefs.getBoolean(PreferenceConstants.TITLEBARHIDE, false);
    if (titleBarHide && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // This is a separate method because Gradle does not uniformly respect the conditional
        // Build check. See: https://code.google.com/p/android/issues/detail?id=137195
        requestActionBar();
    }

    this.setContentView(R.layout.act_console);

    // hide status bar if requested by user
    if (prefs.getBoolean(PreferenceConstants.FULLSCREEN, false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    // TODO find proper way to disable volume key beep if it exists.
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // handle requested console from incoming intent
    if (icicle == null) {
        requested = getIntent().getData();
    } else {
        String uri = icicle.getString(STATE_SELECTED_URI);
        if (uri != null) {
            requested = Uri.parse(uri);
        }
    }

    inflater = LayoutInflater.from(this);

    toolbar = (Toolbar) findViewById(R.id.toolbar);

    pager = (TerminalViewPager) findViewById(R.id.console_flip);
    pager.addOnPageChangeListener(new TerminalViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            setTitle(adapter.getPageTitle(position));
            onTerminalChanged();
        }
    });
    adapter = new TerminalPagerAdapter();
    pager.setAdapter(adapter);

    empty = (TextView) findViewById(android.R.id.empty);

    stringPromptGroup = (RelativeLayout) findViewById(R.id.console_password_group);
    stringPromptInstructions = (TextView) findViewById(R.id.console_password_instructions);
    stringPrompt = (EditText) findViewById(R.id.console_password);
    stringPrompt.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            // pass collected password down to current terminal
            String value = stringPrompt.getText().toString();

            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return false;
            helper.setResponse(value);

            // finally clear password for next user
            stringPrompt.setText("");
            updatePromptVisible();

            return true;
        }
    });

    booleanPromptGroup = (RelativeLayout) findViewById(R.id.console_boolean_group);
    booleanPrompt = (TextView) findViewById(R.id.console_prompt);

    booleanYes = (Button) findViewById(R.id.console_prompt_yes);
    booleanYes.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.TRUE);
            updatePromptVisible();
        }
    });

    Button booleanNo = (Button) findViewById(R.id.console_prompt_no);
    booleanNo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.FALSE);
            updatePromptVisible();
        }
    });

    fade_out_delayed = AnimationUtils.loadAnimation(this, R.anim.fade_out_delayed);

    // Preload animation for keyboard button
    keyboard_fade_in = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_in);
    keyboard_fade_out = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_out);

    keyboardGroup = (LinearLayout) findViewById(R.id.keyboard_group);

    keyboardAlwaysVisible = prefs.getBoolean(PreferenceConstants.KEY_ALWAYS_VISIVLE, false);
    if (keyboardAlwaysVisible) {
        // equivalent to android:layout_above=keyboard_group
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.ABOVE, R.id.keyboard_group);
        pager.setLayoutParams(layoutParams);

        // Show virtual keyboard
        keyboardGroup.setVisibility(View.VISIBLE);
    }

    mKeyboardButton = (ImageView) findViewById(R.id.button_keyboard);
    mKeyboardButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View terminal = adapter.getCurrentTerminalView();
            if (terminal == null)
                return;
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInputFromWindow(terminal.getApplicationWindowToken(),
                    InputMethodManager.SHOW_FORCED, 0);
            terminal.requestFocus();
            hideEmulatedKeys();
        }
    });

    findViewById(R.id.button_ctrl).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_esc).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_tab).setOnClickListener(emulatedKeysListener);

    addKeyRepeater(findViewById(R.id.button_up));
    addKeyRepeater(findViewById(R.id.button_up));
    addKeyRepeater(findViewById(R.id.button_down));
    addKeyRepeater(findViewById(R.id.button_left));
    addKeyRepeater(findViewById(R.id.button_right));

    findViewById(R.id.button_home).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_end).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_pgup).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_pgdn).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f1).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f2).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f3).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f4).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f5).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f6).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f7).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f8).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f9).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f10).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f11).setOnClickListener(emulatedKeysListener);
    findViewById(R.id.button_f12).setOnClickListener(emulatedKeysListener);

    actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        if (titleBarHide) {
            actionBar.hide();
        }
        actionBar.addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
            public void onMenuVisibilityChanged(boolean isVisible) {
                inActionBarMenu = isVisible;
                if (!isVisible) {
                    hideEmulatedKeys();
                }
            }
        });
    }

    final HorizontalScrollView keyboardScroll = (HorizontalScrollView) findViewById(R.id.keyboard_hscroll);
    if (!hardKeyboard) {
        // Show virtual keyboard and scroll back and forth
        showEmulatedKeys(false);
        keyboardScroll.postDelayed(new Runnable() {
            @Override
            public void run() {
                final int xscroll = findViewById(R.id.button_f12).getRight();
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "smoothScrollBy(toEnd[" + xscroll + "])");
                }
                keyboardScroll.smoothScrollBy(xscroll, 0);
                keyboardScroll.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (BuildConfig.DEBUG) {
                            Log.d(TAG, "smoothScrollBy(toStart[" + (-xscroll) + "])");
                        }
                        keyboardScroll.smoothScrollBy(-xscroll, 0);
                    }
                }, 500);
            }
        }, 500);
    }

    // Reset keyboard auto-hide timer when scrolling
    keyboardScroll.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                autoHideEmulatedKeys();
                break;
            case MotionEvent.ACTION_UP:
                v.performClick();
                return (true);
            }
            return (false);
        }
    });

    tabs = (TabLayout) findViewById(R.id.tabs);
    if (tabs != null)
        setupTabLayoutWithViewPager();

    pager.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showEmulatedKeys(true);
        }
    });

    // Change keyboard button image according to soft keyboard visibility
    // How to detect keyboard visibility: http://stackoverflow.com/q/4745988
    contentView = findViewById(android.R.id.content);
    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            contentView.getWindowVisibleDisplayFrame(r);
            int screenHeight = contentView.getRootView().getHeight();
            int keypadHeight = screenHeight - r.bottom;

            if (keypadHeight > screenHeight * 0.15) {
                // keyboard is opened
                mKeyboardButton.setImageResource(R.drawable.ic_keyboard_hide);
                mKeyboardButton.setContentDescription(
                        getResources().getText(R.string.image_description_hide_keyboard));
            } else {
                // keyboard is closed
                mKeyboardButton.setImageResource(R.drawable.ic_keyboard);
                mKeyboardButton.setContentDescription(
                        getResources().getText(R.string.image_description_show_keyboard));
            }
        }
    });
}

From source file:com.bitflake.counter.HorizontalPicker.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (!isEnabled()) {
        return super.onKeyDown(keyCode, event);
    }//from ww w  .j  ava  2  s  .  com

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        selectItem();
        return true;
    case KeyEvent.KEYCODE_DPAD_LEFT:
        smoothScrollBy(-1);
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        smoothScrollBy(1);
        return true;
    default:
        return super.onKeyDown(keyCode, event);
    }

}

From source file:info.bartowski.easteregg.LLand.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent ev) {
    if (DEBUG)/*  w  w w.j  a  v a2  s.c o m*/
        L("keyDown: %d", keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_SPACE:
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_BUTTON_A:
        poke();
        return true;
    }
    return false;
}

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

/**
 * Sends over the unix username and password if this is VNC over SSH connectio and automatic sending of 
 * UNIX credentials is enabled for AutoX (for x11vnc's "-unixpw" option).
 *///from  w w  w. j  a  va2  s  . c  om
void sendUnixAuth() {
    // If the type of connection is ssh-tunneled and we are told to send the unix credentials, then do so.
    if (connection.getConnectionType() == Constants.CONN_TYPE_SSH && connection.getAutoXUnixAuth()) {
        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_UNKNOWN,
                new KeyEvent(SystemClock.uptimeMillis(), connection.getSshUser(), 0, 0));
        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_ENTER,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_ENTER,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));

        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_UNKNOWN,
                new KeyEvent(SystemClock.uptimeMillis(), connection.getSshPassword(), 0, 0));
        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_ENTER,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        keyboard.processLocalKeyEvent(KeyEvent.KEYCODE_ENTER,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
    }
}

From source file:info.bartowski.easteregg.LLand.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent ev) {
    if (DEBUG)/* w ww.j a  v a  2 s.  c o  m*/
        L("keyDown: %d", keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_SPACE:
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_BUTTON_A:
        unpoke();
        return true;
    }
    return false;
}