Search in sources :

Example 61 with KeyEvent

use of android.view.KeyEvent in project mobile-android by photo.

the class TagsFragment method init.

public void init(View v) {
    final EditText search = (EditText) v.findViewById(R.id.edit_search);
    search.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                switch(event.getKeyCode()) {
                    case KeyEvent.KEYCODE_ENTER:
                        CommonUtils.debug(TAG, "Key code enter");
                        if (KeyEvent.ACTION_DOWN == event.getAction()) {
                            CommonUtils.debug(TAG, "Opening gallery");
                            search.post(new Runnable() {

                                @Override
                                public void run() {
                                    galleryOpenControl.openGallery(search.getText().toString().trim(), null);
                                }
                            });
                            return true;
                        }
                        break;
                }
            }
            return false;
        }
    });
    Button filterBtn = (Button) v.findViewById(R.id.filterBtn);
    filterBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TrackerUtils.trackButtonClickEvent("filterBtn", TagsFragment.this);
            galleryOpenControl.openGallery(mAdapter.getSelectedTags(), null);
        }
    });
    refresh(v);
}
Also used : EditText(android.widget.EditText) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView)

Example 62 with KeyEvent

use of android.view.KeyEvent in project PlayerHater by chrisrhoden.

the class TouchableNotificationPlugin method getMediaButtonPendingIntent.

private PendingIntent getMediaButtonPendingIntent(int keycode) {
    Intent intent = new Intent(getContext(), BroadcastReceiver.class);
    intent.setAction(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, keycode));
    return PendingIntent.getBroadcast(getContext(), keycode, intent, 0);
}
Also used : KeyEvent(android.view.KeyEvent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 63 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 64 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)

Example 65 with KeyEvent

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

the class ItemActivityTest method testBackPressed.

@Test
public void testBackPressed() {
    Intent intent = new Intent();
    WebItem webItem = new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public String getId() {
            return "1";
        }
    };
    intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
    controller.withIntent(intent).create().start().resume().visible();
    activity.onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
    verify(keyDelegate).setBackInterceptor(any());
    verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
}
Also used : KeyEvent(android.view.KeyEvent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

KeyEvent (android.view.KeyEvent)513 View (android.view.View)145 TextView (android.widget.TextView)109 Intent (android.content.Intent)53 ImageView (android.widget.ImageView)38 DialogInterface (android.content.DialogInterface)36 EditText (android.widget.EditText)36 KeyCharacterMap (android.view.KeyCharacterMap)35 Editable (android.text.Editable)34 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Instrumentation (android.app.Instrumentation)30 OnClickListener (android.view.View.OnClickListener)30 Paint (android.graphics.Paint)27 Button (android.widget.Button)27 TextWatcher (android.text.TextWatcher)24 InputMethodManager (android.view.inputmethod.InputMethodManager)22 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 LayoutInflater (android.view.LayoutInflater)21 Test (org.junit.Test)20