List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:net.sourceforge.fidocadj.FidoMain.java
/** One of the most important functions for the user interface: handle all the menu events!/*from w w w . j a v a 2 s. c om*/ */ @Override public boolean onOptionsItemSelected(MenuItem item) { // status is a variable which will be used as a return value. It must // be put to 'true' if the action is taken into account and handled // properly. boolean status = false; String fileName; /* dialogs */ DialogSaveName dsn; DialogOpenFile dof; DialogLayer dl; DialogAbout da; MapCoordinates mp; if (onContextItemSelected(item)) return true; switch (item.getItemId()) { case R.id.menu_copy_split: // Copy and split nonstandard macros // TODO: this is not yet working. drawingPanel.getCopyPasteActions().copySelected(true, true); status = true; break; case R.id.menu_undo: // Undo action drawingPanel.getUndoActions().undo(); status = true; break; case R.id.menu_redo: // Redo action try { drawingPanel.getUndoActions().redo(); } catch (NoSuchElementException E) { // Does nothing. Actually it is not a big issue. android.util.Log.w("fidocadj", "Can not redo."); } status = true; break; case R.id.new_drawing: // New drawing drawingPanel.getParserActions().parseString(new StringBuffer("")); drawingPanel.getParserActions().openFileName = null; drawingPanel.initLayers(); drawingPanel.invalidate(); status = true; break; case R.id.open_file: // Open an existing file Intent myIntent = new Intent(this, ExplorerActivity.class); myIntent.putExtra(ExplorerActivity.DIRECTORY, false); int requestCode = ExplorerActivity.REQUEST_FILE; startActivityForResult(myIntent, requestCode); break; case R.id.open_file_deprecated: // Open an existing file dof = new DialogOpenFile(); dof.show(fragmentManager, ""); status = true; break; case R.id.save: // Save fileName = drawingPanel.getParserActions().openFileName; if (fileName == null || fileName == tempFileName) { dsn = new DialogSaveName(); dsn.show(fragmentManager, ""); } else { IO.writeFileToSD(drawingPanel.getParserActions().openFileName, drawingPanel.getText()); } status = true; break; case R.id.save_with_name: // Save with name dsn = new DialogSaveName(); dsn.show(fragmentManager, ""); status = true; break; case R.id.delete: // Delete a saved file fileName = drawingPanel.getParserActions().openFileName; if (fileName != null) { deleteFile(drawingPanel.getParserActions().openFileName); drawingPanel.getParserActions().parseString(new StringBuffer("")); drawingPanel.getParserActions().openFileName = null; drawingPanel.invalidate(); } else { Toast toast = Toast.makeText(this, R.string.No_file_opened, 5); toast.show(); } status = true; break; case R.id.layer: // Set the current layer dl = new DialogLayer(); dl.show(fragmentManager, ""); status = true; break; case R.id.showgrid: // Toggle grid visibility drawingPanel.setShowGrid(!drawingPanel.getShowGrid()); drawingPanel.invalidate(); item.setChecked(drawingPanel.getShowGrid()); status = true; break; case R.id.snaptogrid: // Toggle snap to grid while editing mp = drawingPanel.getMapCoordinates(); mp.setSnap(!mp.getSnap()); drawingPanel.invalidate(); item.setChecked(mp.getSnap()); status = true; break; case R.id.use_sensors_rotate_mirror: // Toggle "use sensors..." activateSensors = !activateSensors; item.setChecked(activateSensors); status = true; break; case R.id.zoomtofit: // Zoom to fit drawingPanel.zoomToFit(); break; case R.id.about: // Show the about dialog da = new DialogAbout(); da.show(fragmentManager, ""); status = true; break; default: } if (!status) android.util.Log.e("fidocadj", "menu not found: " + item.getItemId()); else drawingPanel.invalidate(); return status; }
From source file:com.smc.tw.waltz.MainActivity.java
private void resetLayout() { if (DEBUG)//from w w w . j av a2 s .c o m Log.d(TAG, "resetLayout"); MenuItem menuDropbox = mNavigationView.getMenu().findItem(R.id.navigation_dropbox); MenuItem menuDeviceList = mNavigationView.getMenu().findItem(R.id.navigation_device_list); MenuItem menuSignin = mNavigationView.getMenu().findItem(R.id.navigation_signin); MenuItem menuSignout = mNavigationView.getMenu().findItem(R.id.navigation_signout); View headerLayout = mNavigationView.getHeaderView(0); TextView userInfoView = (TextView) headerLayout.findViewById(R.id.navigation_header_user_name); if (MainApplication.isUserSignedIn()) { if (menuSignin != null) { menuSignin.setEnabled(false); menuSignin.setVisible(false); } if (menuSignout != null) { menuSignout.setEnabled(true); menuSignout.setVisible(true); } if (menuDropbox != null) { menuDropbox.setEnabled(true); menuDropbox.setVisible(true); } UserManager userManager = MainApplication.getUserManager(); String name = userManager.getUsername(); userInfoView.setText(name); userInfoView.setVisibility(View.VISIBLE); } else { if (menuSignin != null) { menuSignin.setEnabled(true); menuSignin.setVisible(true); } if (menuSignout != null) { menuSignout.setEnabled(false); menuSignout.setVisible(false); } if (menuDropbox != null) { menuDropbox.setEnabled(false); menuDropbox.setVisible(false); } userInfoView.setVisibility(View.GONE); } if (mShowDropbox) { showDropboxAssociation(); if (menuDropbox != null) menuDropbox.setChecked(true); } else { showDeviceList(); mDeviceListFragment.notifyDataSetChanged(); if (menuDeviceList != null) menuDeviceList.setChecked(true); } }
From source file:net.etuldan.sparss.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;/*from w ww .java2s.c o m*/ if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.ic_star_border); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } } break; } case R.id.menu_full_screen: { setImmersiveFullScreen(true); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } case R.id.menu_open_in_browser: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); startActivity(browserIntent); } } break; } case R.id.menu_switch_full_original: { isChecked = !item.isChecked(); item.setChecked(isChecked); if (mPreferFullText) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mPreferFullText = false; mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true); } }); } else { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos); if (alreadyMobilized) { activity.runOnUiThread(new Runnable() { @Override public void run() { mPreferFullText = true; mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true); } }); } else if (!isRefreshing()) { ConnectivityManager connectivityManager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); // since we have acquired the networkInfo, we use it for basic checks if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) { FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] }); activity.startService(new Intent(activity, FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); activity.runOnUiThread(new Runnable() { @Override public void run() { showSwipeProgress(); } }); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show(); } }); } } } break; } default: break; } } return super.onOptionsItemSelected(item); }
From source file:com.chummy.jezebel.material.dark.activities.Main.java
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case R.id.share: Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); String shareBody = "Check out " + getResources().getString(R.string.theme_name) + " by " + getResources().getString(R.string.nicholas_short) + "!\n\nDownload it here!: " + getResources().getString(R.string.play_store_link); sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title)))); break;/* w w w .jav a2 s . c om*/ case R.id.sendemail: StringBuilder emailBuilder = new StringBuilder(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:" + getResources().getString(R.string.email_id))); if (!isAppInstalled("org.cyanogenmod.theme.chooser")) { if (!isAppInstalled("com.cyngn.theme.chooser")) { if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject)); } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_rro)); } } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cos)); } } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cm)); } emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "(" + Build.VERSION.INCREMENTAL + ")"); emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " (" + Build.VERSION.RELEASE + ") " + "[" + Build.ID + "]"); emailBuilder.append("\nDevice: " + Build.DEVICE); emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER); emailBuilder.append("\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")"); if (!isAppInstalled("org.cyanogenmod.theme.chooser")) { if (!isAppInstalled("com.cyngn.theme.chooser")) { if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) { emailBuilder.append("\nTheme Engine: Not Available"); } else { emailBuilder.append("\nTheme Engine: Layers Manager (RRO)"); } } else { emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine"); } } else { emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine"); } PackageInfo appInfo = null; try { appInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } emailBuilder.append("\nApp Version Name: " + appInfo.versionName); emailBuilder.append("\nApp Version Code: " + appInfo.versionCode); intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()); startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title)))); break; case R.id.changelog: changelog(); break; case R.id.hide_launcher: boolean checked = item.isChecked(); if (!checked) { new MaterialDialog.Builder(this).title(R.string.warning).content(R.string.hide_action) .positiveText(R.string.nice).show(); } item.setChecked(!checked); setLauncherIconEnabled(checked); return true; default: return super.onOptionsItemSelected(item); } return true; }
From source file:org.de.jmg.learn.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. try {//w w w. j av a 2 s.co m int id = item.getItemId(); if (id == R.id.action_settings) { mPager.setCurrentItem(SettingsActivity.fragID); } else if (id == R.id.mnuCredits) { InputStream is = this.getAssets().open("CREDITS"); java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); String strCredits = s.hasNext() ? s.next() : ""; s.close(); is.close(); String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; Spannable spn = lib.getSpanableString(strCredits + "\nV" + versionName); lib.ShowMessage(this, spn, "Credits"); } else if (id == R.id.mnuContact) { Intent intent = new Intent(Intent.ACTION_SEND, Uri.fromParts("mailto", "jhmgbl2@t-online.de", null)); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "jhmgbl2@t-online.de" }); String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; intent.putExtra(Intent.EXTRA_SUBJECT, "learnforandroid " + versionName); intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.ConvertVok)); this.startActivity(Intent.createChooser(intent, getString(R.string.SendMail))); } else if (id == R.id.mnuFileOpen) { mPager.setCurrentItem(fragFileChooser.fragID); //LoadFile(true); } else if (id == R.id.mnuHome) { mPager.setCurrentItem(_MainActivity.fragID); } else if (id == R.id.mnuOpenQuizlet) { //LoginQuizlet(); if (mPager.getCurrentItem() != fragFileChooserQuizlet.fragID) { mPager.setCurrentItem(fragFileChooserQuizlet.fragID); } else { if (fPA != null && fPA.fragQuizlet != null) { searchQuizlet(); } } } else if (id == R.id.mnuUploadToQuizlet) { uploadtoQuizlet(); } else if (id == R.id.mnuAskReverse) { item.setChecked(!item.isChecked()); vok.reverse = item.isChecked(); setMnuReverse(); } else if (id == R.id.mnuOpenUri) { if (saveVok(false)) { String defaultURI = prefs.getString("defaultURI", ""); Uri def; if (libString.IsNullOrEmpty(defaultURI)) { File F = new File(JMGDataDirectory); def = Uri.fromFile(F); } else { def = Uri.parse(defaultURI); } lib.SelectFile(this, def); } } else if (id == R.id.mnuNew) { newVok(); } else if (id == R.id.mnuAddWord) { mPager.setCurrentItem(_MainActivity.fragID); if (fPA.fragMain != null && fPA.fragMain.mainView != null) { if (fPA.fragMain.EndEdit(false)) { vok.AddVokabel(); fPA.fragMain.getVokabel(true, false, true); fPA.fragMain.StartEdit(); } } } else if (id == R.id.mnuFileOpenASCII) { LoadFile(false); } else if (id == R.id.mnuConvMulti) { if (fPA.fragMain != null && fPA.fragMain.mainView != null) { vok.ConvertMulti(); fPA.fragMain.getVokabel(false, false); } } else if (id == R.id.mnuFileSave) { saveVok(false); } else if (id == R.id.mnuSaveAs) { SaveVokAs(true, false); } else if (id == R.id.mnuRestart) { vok.restart(); } else if (id == R.id.mnuDelete) { if (fPA.fragMain != null && fPA.fragMain.mainView != null) { vok.DeleteVokabel(); fPA.fragMain.EndEdit2(); } } else if (id == R.id.mnuReverse) { if (fPA.fragMain != null && fPA.fragMain.mainView != null) { vok.revert(); fPA.fragMain.getVokabel(false, false); } } else if (id == R.id.mnuReset) { if (lib.ShowMessageYesNo(this, this.getString(R.string.ResetVocabulary), "") == yesnoundefined.yes) { vok.reset(); } } else if (id == R.id.mnuStatistics) { if (vok.getGesamtzahl() > 5) { try { /* IDemoChart chart = new org.de.jmg.learn.chart.LearnBarChart(); int UIMode = lib.getUIMode(this); switch (UIMode) { case Configuration.UI_MODE_TYPE_TELEVISION: isTV = true; break; case Configuration.UI_MODE_TYPE_WATCH: isWatch = true; break; } Intent intent = chart.execute(this); this.startActivity(intent); */ mPager.setCurrentItem(fragStatistics.fragID); } catch (Exception ex) { lib.ShowException(this, ex); } } } else if (id == R.id.mnuEdit) { if (fPA.fragMain != null && fPA.fragMain.mainView != null) { fPA.fragMain.edit(); } } else if (id == R.id.mnuLoginQuizlet) { LoginQuizlet(false); } } catch (Throwable ex) { lib.ShowException(this, ex); } return super.onOptionsItemSelected(item); }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View layoutView = inflater.inflate(R.layout.settings_layout, null); Integer rows = mActualLevel.getBoardAtIndex(mActualIndex).getRows(); Integer columns = mActualLevel.getBoardAtIndex(mActualIndex).getCols(); final CheckBox bordersCheckbox = (CheckBox) layoutView.findViewById(R.id.bordersCheckbox); bordersCheckbox.setChecked(mActiveConfig.getShowBorders()); builder.setTitle(getResources().getString(R.string.settings)).setView(layoutView).setPositiveButton( getResources().getString(R.string.apply), new DialogInterface.OnClickListener() { @Override/* ww w . ja v a 2 s. c o m*/ public void onClick(DialogInterface dialog, int which) { if (newCols == 0) newCols++; if (newRows == 0) newRows++; mActualLevel.getBoardAtIndex(mActualIndex).setCols(newCols); mActualLevel.getBoardAtIndex(mActualIndex).setRows(newRows); IOBoardActivity.this.mActiveConfig.setShowBorders(bordersCheckbox.isChecked()); //TODO:createView(); refreshView(); } }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("dialog", "dismiss and discard"); } }); SeekBar sRows = (SeekBar) layoutView.findViewById(R.id.seekRows); SeekBar sCols = (SeekBar) layoutView.findViewById(R.id.seekCols); final TextView rowsLbl = (TextView) layoutView.findViewById(R.id.numRowsLbl); final TextView colsLbl = (TextView) layoutView.findViewById(R.id.numColsLbl); sRows.setProgress(rows); sCols.setProgress(columns); newRows = rows; newCols = columns; rowsLbl.setText("" + rows); colsLbl.setText("" + columns); sRows.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (seekBar.getProgress() == 0) seekBar.setProgress(1); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.d("seeking", "seek rows " + progress); newRows = progress; rowsLbl.setText("" + progress); } }); sCols.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (seekBar.getProgress() == 0) seekBar.setProgress(1); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.d("seeking", "seek cols " + progress); newCols = progress; colsLbl.setText("" + progress); } }); builder.create().show(); break; } case R.id.editMode: { Log.d("options menu", "edit mode selected"); item.setChecked(!item.isChecked()); toggleEditing(); break; } case R.id.scanMode: { Log.d("options menu", "scan mode selected"); item.setChecked(!item.isChecked()); IOGlobalConfiguration.isScanMode = item.isChecked(); if (IOGlobalConfiguration.isScanMode) startScanMode(); else stopScanMode(); break; } case R.id.action_new: { new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.warning)) .setMessage(getString(R.string.new_board_alert)) .setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { FragmentManager fm = getSupportFragmentManager(); while (fm.getBackStackEntryCount() > 0) fm.popBackStackImmediate(); mActiveConfig = new IOConfiguration(); fm.beginTransaction() .replace(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel())) .commit(); if (!IOGlobalConfiguration.isEditing) toggleEditing(); } }) .setNegativeButton(getResources().getString(R.string.cancel), null).setCancelable(false) .create().show(); break; } case R.id.action_save: { if (null == mActualConfigName) IOBoardActivity.this.mActiveConfig.save(); else IOBoardActivity.this.mActiveConfig.saveAs(mActualConfigName); break; } case R.id.action_save_as: { final AlertDialog.Builder alert = new AlertDialog.Builder(this); View contentView = getLayoutInflater().inflate(R.layout.rename_alert_layout, null); final EditText inputText = (EditText) contentView.findViewById(R.id.newNameEditText); alert.setView(contentView); alert.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = inputText.getText().toString().trim(); if (value.indexOf(".xml") != -1) value = value.replace(".xml", ""); File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), IOApplication.APPLICATION_NAME + "/boards"); File file = new File(dirFile.toString(), value + ".xml"); if (file.exists()) { dialog.cancel(); new AlertDialog.Builder(IOBoardActivity.this).setTitle(getString(R.string.warning)) .setMessage(getString(R.string.file_already_exists)) .setPositiveButton(getString(R.string.continue_string), null).create().show(); } else { IOBoardActivity.this.mActiveConfig.saveAs(value); mActualConfigName = value; } } }); alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); break; } case R.id.action_load: { File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), IOApplication.APPLICATION_NAME + "/boards"); if (!dirFile.exists()) dirFile.mkdirs(); final String[] configFiles = dirFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.indexOf(".xml") != -1) return true; return false; } }); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item); adapter.addAll(configFiles); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getResources().getString(R.string.choose)) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("media_debug", "click on item " + which); String fileName = configFiles[which]; Log.d("board_debug", fileName); FragmentManager fm = getSupportFragmentManager(); while (fm.getBackStackEntryCount() > 0) fm.popBackStackImmediate(); mActiveConfig = IOConfiguration.getSavedConfiguration(fileName); fm.beginTransaction() .replace(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel())) .commit(); } }).setNegativeButton(getResources().getString(R.string.cancel), null).create().show(); break; } case R.id.action_about: { Intent aboutIntent = new Intent(getApplicationContext(), IOAboutActivity.class); startActivity(aboutIntent); break; } case R.id.action_exit: { finish(); break; } case R.id.action_lock: { if (IOGlobalConfiguration.isEditing) toggleEditing(); lockUI(); break; } default: break; } return super.onOptionsItemSelected(item); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (DEBUG)/*w ww . j av a 2 s. c o m*/ Logger.LogDebug("OpenExplorer.onOptionsItemSelected(" + item + ")"); if (item.getItemId() == R.id.menu_more && isGTV()) { showMenu(mOptsMenu, findViewById(item.getItemId()), false); return true; } if (item.getSubMenu() != null) { onPrepareOptionsMenu(item.getSubMenu()); if (!USE_PRETTY_MENUS) return false; else { View anchor = findViewById(item.getItemId()); if (anchor == null && !BEFORE_HONEYCOMB && item.getActionView() != null) anchor = item.getActionView(); if (anchor == null && !BEFORE_HONEYCOMB) { anchor = getActionBar().getCustomView(); if (anchor.findViewById(item.getItemId()) != null) anchor = anchor.findViewById(item.getItemId()); } if (anchor == null) anchor = mToolbarButtons; if (anchor == null) anchor = findViewById(android.R.id.home); if (anchor == null && !BEFORE_HONEYCOMB && USE_ACTION_BAR) anchor = getActionBar().getCustomView().findViewById(android.R.id.home); if (anchor == null) anchor = getCurrentFocus().getRootView(); OpenFragment f = getSelectedFragment(); if (f != null) if (f.onClick(item.getItemId(), anchor)) return true; } } if (item.isCheckable()) item.setChecked(item.getGroupId() > 0 ? true : !item.isChecked()); OpenFragment f = getSelectedFragment(); if (f != null && f.onOptionsItemSelected(item)) return true; if (DEBUG) Logger.LogDebug("OpenExplorer.onOptionsItemSelected(0x" + Integer.toHexString(item.getItemId()) + ")"); return onClick(item.getItemId(), item, null); }
From source file:com.esri.squadleader.view.SquadLeaderActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.add_layer: //Present Add Layer from Web dialog if (null == addLayerDialogFragment) { addLayerDialogFragment = new AddLayerDialogFragment(); addLayerDialogFragment.setAddLayerFromFileRequestCode(ADD_LAYER_FROM_FILE); }/* ww w .j ava 2s .com*/ addLayerDialogFragment.show(getFragmentManager(), getString(R.string.add_layer_fragment_tag)); return true; case R.id.add_feature: // Present Add Feature dialog if (null == addFeatureDialogFragment) { addFeatureDialogFragment = new AddFeatureDialogFragment(); } addFeatureDialogFragment.show(getFragmentManager(), getString(R.string.add_feature_fragment_tag)); return true; case R.id.clear_messages: //Present Clear Messages dialog if (null == clearMessagesDialogFragment) { clearMessagesDialogFragment = new ClearMessagesDialogFragment(); } clearMessagesDialogFragment.show(getFragmentManager(), getString(R.string.clear_messages_fragment_tag)); return true; case R.id.go_to_mgrs: //Present Go to MGRS dialog if (null == goToMgrsDialogFragment) { goToMgrsDialogFragment = new GoToMgrsDialogFragment(); } goToMgrsDialogFragment.show(getFragmentManager(), getString(R.string.go_to_mgrs_fragment_tag)); return true; case R.id.set_location_mode: //Present Set Location Mode dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.set_location_mode).setNegativeButton(R.string.cancel, null) .setSingleChoiceItems( new String[] { getString(R.string.option_location_service), getString(R.string.option_simulation_builtin), getString(R.string.option_simulation_file) }, mapController.getLocationController().getMode() == LocationMode.LOCATION_SERVICE ? 0 : null == mapController.getLocationController().getGpxFile() ? 1 : 2, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clearDisplayStrings(); try { if (2 == which) { //Present file chooser Intent getContentIntent = FileUtils.createGetContentIntent(); Intent intent = Intent.createChooser(getContentIntent, "Select a file"); startActivityForResult(intent, REQUEST_CHOOSER); } else { mapController.getLocationController().setGpxFile(null, true); mapController.getLocationController() .setMode(0 == which ? LocationMode.LOCATION_SERVICE : LocationMode.SIMULATOR, true); mapController.getLocationController().start(); } } catch (Exception e) { Log.d(TAG, "Couldn't set location mode", e); } finally { dialog.dismiss(); } } }); AlertDialog dialog = builder.create(); dialog.show(); return true; case R.id.settings: Intent intent = new Intent(this, SettingsActivity.class); startActivityForResult(intent, SETTINGS_ACTIVITY); return true; case R.id.toggle_labels: item.setChecked(!item.isChecked()); item.setIcon(item.isChecked() ? R.drawable.ic_action_labels : R.drawable.ic_action_labels_off); SharedPreferences prefs = getPreferences(MODE_PRIVATE); String key = getString(R.string.pref_labels); prefs.edit().putBoolean(key, item.isChecked()).commit(); if (null != mil2525cController) { mil2525cController.setShowLabels(item.isChecked()); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:de.gebatzens.sia.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(SIAApp.SIA_APP.school.getTheme()); super.onCreate(savedInstanceState); Log.w("ggvp", "CREATE NEW MAINACTIVITY"); //Debug.startMethodTracing("sia3"); SIAApp.SIA_APP.activity = this; savedState = savedInstanceState;//from w ww.j a v a2 s. co m final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments; Intent intent = getIntent(); if (intent != null && intent.getStringExtra("fragment") != null) { FragmentData frag = fragments .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0); SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag)); } if (intent != null && intent.getBooleanExtra("reload", false)) { SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); intent.removeExtra("reload"); } setContentView(R.layout.activity_main); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); mContent = getFragment(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData()); if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) { ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm); summerNavigationPalm.setImageResource(R.drawable.summer_palm); ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image); summerBackgroundImage.setImageResource(R.drawable.summer_background); } mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_refresh: ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true); SIAApp.SIA_APP.refreshAsync(new Runnable() { @Override public void run() { ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)) .setRefreshing(false); } }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); return true; case R.id.action_settings: Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); return true; case R.id.action_addToCalendar: showExamDialog(); return true; case R.id.action_help: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(getApplication().getString(R.string.help)); builder.setMessage(getApplication().getString(R.string.exam_explain)); builder.setPositiveButton(getApplication().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } return false; } }); updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.addDrawerListener(mDrawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationHeader = navigationView.getHeaderView(0); mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text); mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name); mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture); mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage()); mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link); mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewIn) { mDrawerLayout.closeDrawers(); Intent linkIntent = new Intent(Intent.ACTION_VIEW); linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website)); startActivity(linkIntent); } }); final Menu menu = navigationView.getMenu(); menu.clear(); for (int i = 0; i < fragments.size(); i++) { MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name); item.setIcon(fragments.get(i).getIconRes()); } menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings); menu.setGroupCheckable(R.id.fragments, true, true); menu.setGroupCheckable(R.id.settings, false, false); final Menu navMenu = navigationView.getMenu(); selectedItem = SIAApp.SIA_APP.getFragmentIndex(); if (selectedItem != -1) navMenu.getItem(selectedItem).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.settings_item) { mDrawerLayout.closeDrawers(); Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); } else { final int index = menuItem.getOrder(); if (SIAApp.SIA_APP.getFragmentIndex() != index) { SIAApp.SIA_APP.setFragmentIndex(index); menuItem.setChecked(true); updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString()); mContent = getFragment(); Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out); fadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.setVisibility(View.INVISIBLE); if (fragments.get(index).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index)); //removeAllFragments(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); snowView.updateSnow(); } @Override public void onAnimationRepeat(Animation animation) { } }); FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.startAnimation(fadeOut); mDrawerLayout.closeDrawers(); } else { mDrawerLayout.closeDrawers(); } } return true; } }); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < fragments.size(); i++) { Drawable drawable = getDrawable(fragments.get(i).getIconRes()); Bitmap icon; if (drawable instanceof VectorDrawable) { icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes()); } Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(connectedIcon); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#f5f5f5")); canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint); paint.setColorFilter( new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f), paint); Intent newTaskIntent = new Intent(this, MainActivity.class); newTaskIntent.setAction(Intent.ACTION_MAIN); newTaskIntent.putExtra("fragment", fragments.get(i).type.toString()); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name) .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name) .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); } } if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) { if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) { TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3) .show(getSupportFragmentManager(), "upgrade_dialog"); } SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply(); } snowView = (SnowView) findViewById(R.id.snow_view); shareToolbar = (Toolbar) findViewById(R.id.share_toolbar); shareToolbar.getMenu().clear(); shareToolbar.inflateMenu(R.menu.share_toolbar_menu); shareToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleShareToolbar(false); for (Shareable s : MainActivity.this.shared) { s.setMarked(false); } MainActivity.this.shared.clear(); mContent.updateFragment(); } }); shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleShareToolbar(false); HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>(); for (Shareable s : MainActivity.this.shared) { ArrayList<Shareable> list = dates.get(s.getDate()); if (list == null) { list = new ArrayList<Shareable>(); dates.put(s.getDate(), list); } list.add(s); s.setMarked(false); } MainActivity.this.shared.clear(); List<Date> dateList = new ArrayList<Date>(dates.keySet()); Collections.sort(dateList); String content = ""; for (Date key : dateList) { content += SubstListAdapter.translateDay(key) + "\n\n"; Collections.sort(dates.get(key)); for (Shareable s : dates.get(key)) { content += s.getShareContent() + "\n"; } content += "\n"; } content = content.substring(0, content.length() - 1); mContent.updateFragment(); if (item.getItemId() == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.entries), content); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.action_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); } return true; } }); if (shared.size() > 0) { shareToolbar.setVisibility(View.VISIBLE); updateShareToolbarText(); } // if a fragment is opened via a notification or a shortcut reset the shared entries // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment if (intent != null && intent.hasExtra("fragment")) { resetShareToolbar(); intent.removeExtra("fragment"); } }