List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.oakesville.mythling.MediaPagerActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) { if ((getCurrentFocus().getParent() instanceof View && ((View) getCurrentFocus().getParent()).getId() == R.id.button_bar) || getCurrentFocus().getId() == R.id.title_text) { findViewById(R.id.pager_position).requestFocus(); return true; }//from w w w . jav a 2s . c o m } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { if (getCurrentFocus().getId() == R.id.pager_position) { if (pager.getCurrentItem() < getListables().size() - 1) { pager.setCurrentItem(pager.getCurrentItem() + 1); positionBar.setProgress(pager.getCurrentItem()); return true; } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) { if (getCurrentFocus().getId() == R.id.pager_position) { if (pager.getCurrentItem() > 0) { pager.setCurrentItem(pager.getCurrentItem() - 1); positionBar.setProgress(pager.getCurrentItem()); return true; } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { pager.setCurrentItem(getListables().size() - 1); positionBar.setProgress(getListables().size() - 1); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_REWIND) { pager.setCurrentItem(0); positionBar.setProgress(0); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) { Listable listable = getListables().get(pager.getCurrentItem()); if (listable instanceof Item) { playItem((Item) listable); return true; } } } return super.dispatchKeyEvent(event); }
From source file:android.car.cluster.sample.MainClusterActivity.java
@Override public void onKeyEvent(KeyEvent event) { Log.i(TAG, "onKeyEvent, event: " + event); dispatchKeyEvent(event); // TODO: dispatch event doesn't work for some reason. if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { int nextItem = (mPager.getCurrentItem() + 1) % mButtonToFacet.size(); mOrderToFacet.get(nextItem).button.requestFocus(); } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) { int nextItem = (mPager.getCurrentItem() - 1); if (nextItem < 0) nextItem = mButtonToFacet.size() - 1; mOrderToFacet.get(nextItem).button.requestFocus(); }// www . j av a 2s . c o m } }
From source file:com.mobirix.battlefieldcommander.activity.BillingNativeActivity.java
public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event); return super.dispatchKeyEvent(event); }
From source file:org.mdc.chess.SeekBarPreference.java
@Override protected View onCreateView(ViewGroup parent) { TextView name = new TextView(getContext()); name.setText(getTitle());//from w ww . jav a 2s . c o m //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large); TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large); name.setGravity(Gravity.START); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.START; lp.weight = 1.0f; name.setLayoutParams(lp); currValBox = new TextView(getContext()); currValBox.setTextSize(12); currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC); currValBox.setPadding(2, 5, 0, 0); currValBox.setText(valToString()); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER; currValBox.setLayoutParams(lp); LinearLayout row1 = new LinearLayout(getContext()); row1.setOrientation(LinearLayout.HORIZONTAL); row1.addView(name); row1.addView(currValBox); final SeekBar bar = new SeekBar(getContext()); bar.setMax(maxValue); bar.setProgress(currVal); bar.setOnSeekBarChangeListener(this); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.END; bar.setLayoutParams(lp); CharSequence summaryCharSeq = getSummary(); boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0); TextView summary = null; if (haveSummary) { summary = new TextView(getContext()); summary.setText(getSummary()); // summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large); summary.setGravity(Gravity.START); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.START; lp.weight = 1.0f; summary.setLayoutParams(lp); } LinearLayout layout = new LinearLayout(getContext()); layout.setPadding(25, 5, 25, 5); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(row1); layout.addView(bar); if (summary != null) { layout.addView(summary); } layout.setId(android.R.id.widget_frame); currValBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null); final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext()); builder.setView(content); String title = ""; String key = getKey(); if (key.equals("strength")) { title = getContext().getString(R.string.edit_strength); } else if (key.equals("bookRandom")) { title = getContext().getString(R.string.edit_randomization); } builder.setTitle(title); final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number); valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", ".")); final Runnable selectValue = new Runnable() { public void run() { try { String txt = valueView.getText().toString(); int value = (int) (Double.parseDouble(txt) * 10 + 0.5); if (value < 0) value = 0; if (value > maxValue) value = maxValue; onProgressChanged(bar, value, false); } catch (NumberFormatException ignored) { } } }; valueView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { selectValue.run(); return true; } return false; } }); builder.setPositiveButton("Ok", new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { selectValue.run(); } }); builder.setNegativeButton("Cancel", null); builder.create().show(); } }); return layout; }
From source file:com.doctoror.fuckoffmusicplayer.presentation.playback.PlaybackAndroidService.java
private void onActionMediaButton(@NonNull final Intent intent) { final KeyEvent keyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { switch (keyEvent.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY: onActionPlayPause();//from w w w . ja v a 2 s . c om break; case KeyEvent.KEYCODE_MEDIA_PAUSE: onActionPause(); break; case KeyEvent.KEYCODE_MEDIA_NEXT: onActionNext(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: onActionPrev(); break; case KeyEvent.KEYCODE_MEDIA_STOP: onActionStop(); break; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: onActionPlayPause(); break; } } }
From source file:com.darshancomputing.BatteryIndicatorPro.AlarmsFragment.java
private void bindView(View view) { final TextView summary_tv = (TextView) view.findViewById(R.id.alarm_summary); final View summary_box = view.findViewById(R.id.alarm_summary_box); final CompoundButton toggle = (CompoundButton) view.findViewById(R.id.toggle); final int id = mCursor.getInt(AlarmDatabase.INDEX_ID); String type = mCursor.getString(AlarmDatabase.INDEX_TYPE); String threshold = mCursor.getString(AlarmDatabase.INDEX_THRESHOLD); Boolean enabled = (mCursor.getInt(AlarmDatabase.INDEX_ENABLED) == 1); String s = pfrag.str.alarm_types_display[pfrag.str.indexOf(pfrag.str.alarm_type_values, type)]; if (type.equals("temp_rises")) { s += " " + pfrag.str.formatTemp(Integer.valueOf(threshold), convertF, false); } else if (type.equals("charge_drops") || type.equals("charge_rises")) { s += " " + threshold + "%"; }//w w w . j a va 2 s . co m final String summary = s; summary_tv.setText(summary); toggle.setChecked(enabled); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { alarms.setEnabled(id, isChecked); } }); summary_box.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { curId = id; curIndex = mAlarmsList.indexOfChild((View) v.getParent().getParent()); getActivity().getMenuInflater().inflate(R.menu.alarm_item_context, menu); menu.setHeaderTitle(summary); } }); summary_box.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, android.view.KeyEvent event) { if (keyCode == event.KEYCODE_DPAD_CENTER && event.getAction() == event.ACTION_DOWN) v.setPressed(true); return false; } }); summary_box.setOnClickListener(new OnClickListener() { public void onClick(View v) { ComponentName comp = new ComponentName(getActivity().getPackageName(), AlarmEditActivity.class.getName()); startActivity(new Intent().setComponent(comp).putExtra(AlarmEditActivity.EXTRA_ALARM_ID, id)); } }); }
From source file:com.bellman.bible.android.view.activity.search.Search.java
/** * Called when the activity is first created. */// w ww . j av a2s.c o m @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, true); Log.i(TAG, "Displaying Search view"); setContentView(R.layout.search); if (!searchControl.validateIndex(getDocumentToSearch())) { Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() { @Override public void okay() { finish(); } }); } mSearchTextInput = (EditText) findViewById(R.id.searchText); mSearchTextInput.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press onSearch(null); return true; } return false; } }); // pre-load search string if passed in Bundle extras = getIntent().getExtras(); if (extras != null) { String searchText = extras.getString(SEARCH_TEXT_SAVE); if (StringUtils.isNotEmpty(searchText)) { mSearchTextInput.setText(searchText); } } RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup); wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { wordsRadioSelection = checkedId; } }); if (extras != null) { int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1); if (wordsSelection != -1) { wordsRadioGroup.check(wordsSelection); } } RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup); sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { sectionRadioSelection = checkedId; } }); if (extras != null) { int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1); if (sectionSelection != -1) { sectionRadioGroup.check(sectionSelection); } } // set text for current bible book on appropriate radio button RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook); // set current book to default and allow override if saved - implies returning via Back button currentBookName = searchControl.getCurrentBookName(); if (extras != null) { String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE); if (currentBibleBookSaved != null) { currentBookName = currentBibleBookSaved; } } currentBookRadioButton.setText(currentBookName); Log.d(TAG, "Finished displaying Search view"); }
From source file:ayushi.view.fragment.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag_settings, container, false); getActivity().setTitle("About App"); mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); }//from ww w .j a va 2 s . c o m if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); mToolbar.setTitleTextColor(Color.WHITE); submitLog = (TextView) rootView.findViewById(R.id.submit_log_txt); if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { submitLog.setText("Disable"); } else { submitLog.setText("Enable"); } rootView.findViewById(R.id.submit_log).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, false); submitLog.setText("Disable"); } else { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true); submitLog.setText("Enable"); } } }); rootView.setFocusableInTouchMode(true); rootView.requestFocus(); rootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT, ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP); } return true; } }); rootView.findViewById(R.id.picasso).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/square/picasso")); startActivity(browserIntent); } }); rootView.findViewById(R.id.acra).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ACRA/acra")); startActivity(browserIntent); } }); rootView.findViewById(R.id.pull_zoom_view).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/Frank-Zhu/PullZoomView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_buddies).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/jpardogo/ListBuddies")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_jazzy).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/twotoasters/JazzyListView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.email_dev).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "serveroverloadofficial@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here"); emailIntent.setType("message/rfc822"); try { startActivity(Intent.createChooser(emailIntent, "Send email using...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show(); } } }); return rootView; }
From source file:com.trupti_prajapati.retailapp.view.fragment.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag_aboutus, container, false); getActivity().setTitle("About App"); mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); }/*from w ww.j av a 2s. c o m*/ if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); mToolbar.setTitleTextColor(Color.WHITE); submitLog = (TextView) rootView.findViewById(R.id.submit_log_txt); if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { submitLog.setText("Disable"); } else { submitLog.setText("Enable"); } rootView.findViewById(R.id.submit_log).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, false); submitLog.setText("Disable"); } else { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true); submitLog.setText("Enable"); } } }); rootView.setFocusableInTouchMode(true); rootView.requestFocus(); rootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT, ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP); } return true; } }); rootView.findViewById(R.id.picasso).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/square/picasso")); startActivity(browserIntent); } }); rootView.findViewById(R.id.acra).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ACRA/acra")); startActivity(browserIntent); } }); rootView.findViewById(R.id.pull_zoom_view).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/Frank-Zhu/PullZoomView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_buddies).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/jpardogo/ListBuddies")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_jazzy).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/twotoasters/JazzyListView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.email_dev).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "serveroverloadofficial@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here"); emailIntent.setType("message/rfc822"); try { startActivity(Intent.createChooser(emailIntent, "Send email using...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show(); } } }); return rootView; }
From source file:au.com.wallaceit.reddinator.ViewAllSubredditsActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); global = ((GlobalObjects) getApplicationContext()); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); }/* w w w. jav a 2s.c om*/ setContentView(R.layout.viewallsubreddit); // setup list view listview = getListView(); listview.setTextFilterEnabled(true); listview.setEmptyView(findViewById(R.id.subredditload)); listview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(); // update subreddit without adding to list intent.putExtra("subreddit", sreddits.get(position)); setResult(RESULT_SET_SUBREDDIT, intent); finish(); } }); // get empty view text for easy access later emptyview = (TextView) findViewById(R.id.poploadtxt); // setup search buttons searchbox = (EditText) this.findViewById(R.id.searchbox); searchbox.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { search(v.getText().toString()); } return true; } }); ImageView searchbtn = (ImageView) this.findViewById(R.id.searchbutton); searchbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String query = searchbox.getText().toString(); if (!query.equals("")) { search(query); } else { new AlertDialog.Builder(ViewAllSubredditsActivity.this).setTitle("No Query") .setMessage("Please enter something to search for").show(); } } }); }