List of usage examples for android.view MenuItem getItemId
public int getItemId();
From source file:com.aqnote.app.wifianalyzer.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); NavigationMenu.find(menuItem.getItemId()).activateNavigationMenu(this, menuItem); return true;/*from ww w. j a v a 2s. c om*/ }
From source file:com.google.bazel.example.android.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_ping) { new AsyncTask<String, Void, String>() { public static final int READ_TIMEOUT_MS = 5000; public static final int CONNECTION_TIMEOUT_MS = 2000; private String inputStreamToString(InputStream stream) throws IOException { StringBuilder result = new StringBuilder(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); String line;/*from w w w. j a v a 2 s . c om*/ while ((line = reader.readLine()) != null) { result.append(line); } } finally { stream.close(); } return result.toString(); } private HttpURLConnection getConnection(String url) throws IOException { URLConnection urlConnection = new URL(url).openConnection(); urlConnection.setConnectTimeout(CONNECTION_TIMEOUT_MS); urlConnection.setReadTimeout(READ_TIMEOUT_MS); return (HttpURLConnection) urlConnection; } @Override protected String doInBackground(String... params) { String url = params[0]; HttpURLConnection connection = null; try { connection = getConnection(url); return new JSONObject(inputStreamToString(connection.getInputStream())) .getString("requested"); } catch (IOException e) { Log.e("background", "IOException", e); return null; } catch (JSONException e) { Log.e("background", "JSONException", e); return null; } finally { if (connection != null) { connection.disconnect(); } } } @Override protected void onPostExecute(String result) { TextView textView = (TextView) findViewById(R.id.text_view); if (result == null) { Toast.makeText(MainActivity.this, getString(R.string.error_sending_request), Toast.LENGTH_LONG).show(); textView.setText("???"); return; } textView.setText(result); } }.execute("http://10.0.2.2:8080/boop"); return true; } return super.onOptionsItemSelected(item); }
From source file:com.perm.DoomPlay.VkAlbumsActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.itemNewAlbum) { AddListDialog dialog = new AddListDialog() { @Override/* w w w .j a va 2 s.c o m*/ boolean isPlaylistExist(String playlist) { for (AudioAlbum album : albums) { if (album.title.equals(playlist)) return true; } return false; } @Override void createPlatlist(String playlist) { new AsyncTask<String, Void, Void>() { @Override protected Void doInBackground(String... params) { try { handler.sendEmptyMessage(1); albums.add(0, new AudioAlbum(MainScreenActivity.api.addAudioAlbum(params[0]), params[0])); handler.sendEmptyMessage(2); } catch (IOException e) { showException(e); handler.sendEmptyMessage(2); cancel(true); } catch (JSONException e) { showException(e); handler.sendEmptyMessage(2); cancel(true); } catch (KException e) { handleKException(e); handler.sendEmptyMessage(2); cancel(true); } return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); adapter.notifyDataSetChanged(); } }.execute(playlist); } }; dialog.show(getSupportFragmentManager(), "tag"); return true; } return super.onOptionsItemSelected(item); }
From source file:com.scigames.registration.Registration4PhotoActivity.java
/** * Called when a menu item is selected.// ww w . jav a 2 s .c o m */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case BACK_ID: finish(); return true; case CLEAR_ID: //firstName.setText(""); //password.setText(""); return true; } return super.onOptionsItemSelected(item); }
From source file:com.royclarkson.springagram.PhotoListFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.action_add_to_gallery: addToGallery(info.position);/*w ww . j a v a 2s . c o m*/ return true; case R.id.action_delete: deletePhoto(info.position); return true; default: return super.onContextItemSelected(item); } }
From source file:com.starwood.anglerslong.LicenseActivity.java
/********************************************************* * Gives functionality to the action bar *********************************************************/ public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(); switch (item.getItemId()) { case R.id.add: if (numItems <= 5) { intent.setClass(getApplicationContext(), LicenseAddActivity.class); intent.putExtra("title", "License"); intent.putExtra("isPopulated", isLicensePopulated); intent.putExtra("isArrayEmpty", isArrayEmpty); intent.putExtra("isLicense", true); startActivity(intent);//from w w w . j a va 2 s .com } else { Toast.makeText(getApplicationContext(), "You cannot have more than 5 licenses", Toast.LENGTH_SHORT) .show(); } return true; case R.id.delete: if (isLicensePopulated && !isArrayEmpty) { isDeletable = true; Toast.makeText(getApplicationContext(), "Please click the item you would like to delete", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "There's nothing to delete. Please Add an item first.", Toast.LENGTH_SHORT).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:de.awisus.refugeeaidleipzig.MainActivity.java
/** * Control of item selection in the nav drawer * changes fragment container to profile fragment, if profile is chosen * if user is logged off, the login mask shows up * changes fragment container to map fragment, if map is chosen * pops up About dialogue, if About is chosen * closes drawer/*from w ww .j a v a2 s.c o m*/ * @param item pressed nav menu item * @return true for success */ @Override public boolean onNavigationItemSelected(MenuItem item) { int id = (item.getItemId()); // Show user profile if logged on if (id == R.id.nav_profil) { if (model.angemeldet()) { wechsleFragment(FragmentProfil.newInstance(model)); } else { // get saved login data String datei = null; try { datei = Datei.getInstance().lesen(this, "login.json"); } catch (IOException e) { Log.e("Laden", "Fehler beim Lesen der Logindatei"); } if (datei != null) { LoginData login = new Gson().fromJson(datei, LoginData.class); new NutzerGet(this, R.string.meldung_anmelden).execute(login); } else { // Else, show login dialogue FragmentAnmelden fragAnmelden; fragAnmelden = FragmentAnmelden.newInstance(model); fragAnmelden.show(getSupportFragmentManager(), "Anmelden"); } } } // Switch to Google Map if (id == R.id.nav_karte) { wechsleFragment(FragmentKarte.newInstance(this, model)); } // Show About Dialogue if (id == R.id.nav_ueber) { String titel; titel = getResources().getString(R.string.titel_ueber); titel += " "; titel += getResources().getString(R.string.app_name); titel += " v" + BuildConfig.VERSION_NAME; FragmentInfo fragUeber = FragmentInfo.newInstance(titel, R.string.info); fragUeber.show(getSupportFragmentManager(), titel); } // Close drawer drawer.closeDrawer(GravityCompat.START); return true; }
From source file:de.nico.asura.Main.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_prefs: startActivity(new Intent(this, Preferences.class)); return true; case R.id.action_WebView1: if (!(Utils.isNetworkAvailable(this))) Utils.makeLongToast(this, offline); else/* www. ja v a2s . c o m*/ startActivity(new Intent(this, WebView1.class)); return true; case R.id.action_Link1: if (!(Utils.isNetworkAvailable(this))) Utils.makeLongToast(this, offline); else startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.menu_Link_1_url)))); return true; case R.id.action_AuthWebView1: if (!(Utils.isNetworkAvailable(this))) Utils.makeLongToast(this, offline); else startActivity(new Intent(this, AuthWebView1.class)); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.bishoph.oxdemo.OXDemo.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_settings) { Intent settingsActivity = new Intent(getBaseContext(), PreferencesActivity.class); startActivity(settingsActivity); return true; }//from w ww .j av a 2s . c o m return super.onOptionsItemSelected(item); }
From source file:pl.bcichecki.rms.client.android.fragments.DevicesListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.fragment_devices_list_menu_new) { performActionNew(item);// w w w. j ava 2 s . c o m return true; } if (item.getItemId() == R.id.fragment_devices_list_menu_refresh) { downloadData(); return true; } return super.onOptionsItemSelected(item); }