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);
}
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);
}
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;
}
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());
}
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));
}
Aggregations