Search in sources :

Example 31 with KeyEvent

use of android.view.KeyEvent in project Android-Terminal-Emulator by jackpal.

the class FSNavigator method fileView.

////////////////////////////////////////////////////////////
private LinearLayout fileView(boolean entryWindow) {
    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    ll.setOrientation(LinearLayout.HORIZONTAL);
    ll.setGravity(android.view.Gravity.FILL);
    final TextView tv;
    if (entryWindow) {
        tv = new EditText(context);
        tv.setHint(getString(R.string.fsnavigator_optional_enter_path));
        tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 2));
        tv.setOnKeyListener(new EditText.OnKeyListener() {

            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER) {
                    String path = tv.getText().toString();
                    File file = new File(getCanonicalPath(path));
                    chdir(file.getParentFile() == null ? file : file.getParentFile());
                    if (file.isFile()) {
                        setResult(RESULT_OK, getIntent().setData(Uri.fromFile(file)));
                        finish();
                    } else {
                        chdir(file);
                        makeView();
                    }
                    return (true);
                }
                return (false);
            }
        });
        ll.addView(tv);
    } else {
        tv = new TextView(context);
        tv.setClickable(true);
        tv.setLongClickable(true);
        tv.setOnClickListener(fileListener);
        tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1));
        HorizontalScrollView hv = new HorizontalScrollView(context);
        hv.setFillViewport(true);
        hv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, BUTTON_SIZE, 7));
        hv.addView(tv);
        ll.addView(hv);
    }
    tv.setFocusable(true);
    tv.setSingleLine();
    tv.setTextSize(textLg);
    tv.setTypeface(Typeface.SERIF, Typeface.BOLD);
    tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    tv.setPadding(10, 5, 10, 5);
    //1);
    tv.setId(R.id.textview);
    return (ll);
}
Also used : EditText(android.widget.EditText) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View) File(java.io.File) HorizontalScrollView(android.widget.HorizontalScrollView) LinearLayout(android.widget.LinearLayout)

Example 32 with KeyEvent

use of android.view.KeyEvent in project Android-Terminal-Emulator by jackpal.

the class TermKeyListenerTest method keyHelperToggle.

private void keyHelperToggle(int keycode, int metastate, byte[] expectedOutPut, boolean toggle) throws UnsupportedEncodingException, IOException {
    KeyEvent event = new KeyEvent(1, 2, KeyEvent.ACTION_DOWN, keycode, 0, metastate);
    tkl_AltNotEsc.keyDown(event.getKeyCode(), event, true, toggle);
    byte[] res = mckTermSessionB.getCharSequence();
    assertNotNull(res);
    assertTrue(expectedOutPut.length <= res.length);
    for (int i = 0; i < expectedOutPut.length; i++) {
        assertEquals(expectedOutPut[i], res[i]);
    }
}
Also used : KeyEvent(android.view.KeyEvent)

Example 33 with KeyEvent

use of android.view.KeyEvent in project ToolBarLib by jjhesk.

the class MaterialSearchView method initSearchView.

protected void initSearchView() {
    mSearchSrcTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            onSubmitQuery();
            return true;
        }
    });
    mSearchSrcTextView.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mUserQuery = s;
            startFilter(s);
            MaterialSearchView.this.onTextChanged(s);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showKeyboard(mSearchSrcTextView);
                showSuggestions();
            }
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 34 with KeyEvent

use of android.view.KeyEvent in project Android-CollapsibleSearchMenu by johnkil.

the class CollapsibleMenuUtils method addSearchMenuItem.

/**
     * Adding collapsible search menu item to the menu.
     *
     * @param menu
     * @param isLightTheme - true if use light them for ActionBar, else false
     * @return menu item
     */
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
    final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
    menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = menuItem.getActionView();
    final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
    final TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            onQueryChangeListener.onQueryTextChange(charSequence.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    };
    final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
                return true;
            }
            return false;
        }
    };
    menuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            editText.addTextChangedListener(textWatcher);
            editText.setOnEditorActionListener(onEditorActionListener);
            editText.requestFocus();
            showKeyboard(editText);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            editText.setText(null);
            editText.removeTextChangedListener(textWatcher);
            // editText.clearFocus();
            hideKeyboard(editText);
            return true;
        }
    });
    final View searchPlate = searchView.findViewById(R.id.search_plate);
    editText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, final boolean hasFocus) {
            searchView.post(new Runnable() {

                public void run() {
                    searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
                    searchView.invalidate();
                }
            });
        }
    });
    final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
    closeBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(editText.getText())) {
                editText.setText(null);
            } else {
                menuItem.collapseActionView();
            }
        }
    });
    return menuItem;
}
Also used : OnFocusChangeListener(android.view.View.OnFocusChangeListener) MenuItem(com.actionbarsherlock.view.MenuItem) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnActionExpandListener(com.actionbarsherlock.view.MenuItem.OnActionExpandListener) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 35 with KeyEvent

use of android.view.KeyEvent in project materialistic by hidroh.

the class KeyDelegateTest method testOnKeyUp.

@Test
public void testOnKeyUp() {
    KeyEvent keyEvent = mock(KeyEvent.class);
    when(keyEvent.getFlags()).thenReturn(KeyEvent.FLAG_CANCELED_LONG_PRESS);
    assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_BACK, keyEvent));
    assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEvent));
    assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEvent));
    KeyEvent keyEventVolUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP), keyEventVolDown = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN);
    assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp));
    verify(scrollable).scrollToPrevious();
    verify(appBar).setExpanded(eq(true), anyBoolean());
    reset(scrollable, appBar);
    when(scrollable.scrollToPrevious()).thenReturn(true);
    assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp));
    verify(scrollable).scrollToPrevious();
    verify(appBar, never()).setExpanded(eq(true), anyBoolean());
    reset(scrollable, appBar);
    when(appBar.getHeight()).thenReturn(10);
    when(appBar.getBottom()).thenReturn(10);
    assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown));
    verify(scrollable, never()).scrollToNext();
    verify(appBar).setExpanded(eq(false), anyBoolean());
    reset(scrollable, appBar);
    when(appBar.getHeight()).thenReturn(10);
    when(appBar.getBottom()).thenReturn(0);
    assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown));
    verify(scrollable).scrollToNext();
    verify(appBar, never()).setExpanded(eq(false), anyBoolean());
}
Also used : KeyEvent(android.view.KeyEvent) Test(org.junit.Test)

Aggregations

KeyEvent (android.view.KeyEvent)499 View (android.view.View)135 TextView (android.widget.TextView)100 Intent (android.content.Intent)49 DialogInterface (android.content.DialogInterface)36 KeyCharacterMap (android.view.KeyCharacterMap)35 EditText (android.widget.EditText)35 ImageView (android.widget.ImageView)33 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Editable (android.text.Editable)31 Instrumentation (android.app.Instrumentation)30 Paint (android.graphics.Paint)27 OnClickListener (android.view.View.OnClickListener)27 Button (android.widget.Button)26 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 TextWatcher (android.text.TextWatcher)21 LayoutInflater (android.view.LayoutInflater)21 InputMethodManager (android.view.inputmethod.InputMethodManager)20 Test (org.junit.Test)20