List of usage examples for android.support.v4.app DialogFragment show
public int show(FragmentTransaction transaction, String tag)
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*w ww .ja va 2 s. co m*/ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = (TextView) getActivity().findViewById(R.id.textView); markdownView = (MarkdownView) getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); final String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"; final String js = "var styleNode = document.createElement('style');\n" + "styleNode.type = \"text/css\";\n" + "var styleText = document.createTextNode('" + css + "');\n" + "styleNode.appendChild(styleText);\n" + "document.getElementsByTagName('head')[0].appendChild(styleNode);\n"; markdownView.getSettings().setJavaScriptEnabled(true); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @TargetApi(Build.VERSION_CODES.N) @Override public void onLoadResource(WebView view, String url) { view.stopLoading(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } @Override public void onPageFinished(WebView view, String url) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) view.evaluateJavascript(js, null); else view.loadUrl("javascript:" + js); } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); if (markdownView != null) markdownView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); }
From source file:com.waz.zclient.pages.main.profile.ZetaPreferencesActivity.java
@Override public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) {/*from w w w . j a va 2s . c o m*/ final String key = preference.getKey(); final DialogFragment f; if (preference.getKey().equals(getString(R.string.pref_options_ringtones_ping_key)) || preference.getKey().equals(getString(R.string.pref_options_ringtones_text_key)) || preference.getKey().equals(getString(R.string.pref_options_ringtones_ringtone_key))) { final int defaultId = preference.getExtras().getInt(WireRingtonePreferenceDialogFragment.EXTRA_DEFAULT); f = WireRingtonePreferenceDialogFragment.newInstance(key, defaultId); } else { return false; } f.setTargetFragment(preferenceFragmentCompat, 0); f.show(getSupportFragmentManager(), key); return true; }
From source file:com.quarterfull.newsAndroid.NewsReaderListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (drawerToggle != null && drawerToggle.onOptionsItemSelected(item)) return true; switch (item.getItemId()) { case android.R.id.home: if (handlePodcastBackPressed()) return true; break;// w w w. j a va 2s. co m case R.id.action_settings: Intent intent = new Intent(this, SettingsActivity.class); startActivityForResult(intent, RESULT_SETTINGS); return true; case R.id.menu_update: startSync(); break; case R.id.action_login: StartLoginFragment(NewsReaderListActivity.this); break; case R.id.action_add_new_feed: Intent newFeedIntent = new Intent(this, NewFeedActivity.class); startActivityForResult(newFeedIntent, RESULT_ADD_NEW_FEED); break; case R.id.menu_StartImageCaching: DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this); long highestItemId = dbConn.getLowestRssItemIdUnread(); Intent service = new Intent(this, DownloadImagesService.class); service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemId); service.putExtra(DownloadImagesService.DOWNLOAD_MODE_STRING, DownloadImagesService.DownloadMode.PICTURES_ONLY); startService(service); break; case R.id.menu_CreateDatabaseDump: DatabaseUtils.CopyDatabaseToSdCard(this); new AlertDialog.Builder(this).setMessage("Created dump at: " + DatabaseUtils.GetPath(this)) .setNeutralButton(getString(android.R.string.ok), null).show(); break; case R.id.menu_About_Changelog: DialogFragment dialog = new VersionInfoDialogFragment(); dialog.show(getSupportFragmentManager(), "VersionChangelogDialogFragment"); return true; case R.id.menu_markAllAsRead: NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); if (ndf != null) { DatabaseConnectionOrm dbConn2 = new DatabaseConnectionOrm(this); dbConn2.markAllItemsAsReadForCurrentView(); reloadCountNumbersOfSlidingPaneAdapter(); ndf.RefreshCurrentRssView(); } return true; case R.id.menu_downloadMoreItems: DownloadMoreItems(); return true; } return super.onOptionsItemSelected(item); }
From source file:ivl.android.moneybalance.ExpenseEditorActivity.java
private void pickDate() { final DatePickerDialog.OnDateSetListener onDateSet = new DatePickerDialog.OnDateSetListener() { @Override/*from w w w . ja v a 2 s. c om*/ public void onDateSet(DatePicker view, int year, int month, int day) { Calendar date = Calendar.getInstance(); date.clear(); date.set(year, month, day); expense.setDate(date); updateDate(); } }; DialogFragment fragment = new DialogFragment() { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Calendar date = expense.getDate(); int year = date.get(Calendar.YEAR); int month = date.get(Calendar.MONTH); int day = date.get(Calendar.DAY_OF_MONTH); return new DatePickerDialog(getActivity(), onDateSet, year, month, day); } }; fragment.show(getSupportFragmentManager(), "datePicker"); }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Set action bar elevation getSupportActionBar().setElevation(getResources().getDimensionPixelSize(R.dimen.action_bar_elevation)); }/*from w w w . ja va2 s . c o m*/ // Show dialog if this is the user's first time running Notepad SharedPreferences prefMain = getPreferences(Context.MODE_PRIVATE); if (prefMain.getInt("first-run", 0) == 0) { // Show welcome dialog if (getSupportFragmentManager().findFragmentByTag("firstrunfragment") == null) { DialogFragment firstRun = new FirstRunDialogFragment(); firstRun.show(getSupportFragmentManager(), "firstrunfragment"); } } else { // The following code is only present to support existing users of Notepad on Google Play // and can be removed if using this source code for a different app // Convert old preferences to new ones SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE); if (prefMain.getInt("sort-by", -1) == 0) { SharedPreferences.Editor editor = pref.edit(); SharedPreferences.Editor editorMain = prefMain.edit(); editor.putString("sort_by", "date"); editorMain.putInt("sort-by", -1); editor.apply(); editorMain.apply(); } else if (prefMain.getInt("sort-by", -1) == 1) { SharedPreferences.Editor editor = pref.edit(); SharedPreferences.Editor editorMain = prefMain.edit(); editor.putString("sort_by", "name"); editorMain.putInt("sort-by", -1); editor.apply(); editorMain.apply(); } if (pref.getString("font_size", "null").equals("null")) { SharedPreferences.Editor editor = pref.edit(); editor.putString("font_size", "large"); editor.apply(); } // Rename any saved drafts from 1.3.x File oldDraft = new File(getFilesDir() + File.separator + "draft"); File newDraft = new File(getFilesDir() + File.separator + String.valueOf(System.currentTimeMillis())); if (oldDraft.exists()) oldDraft.renameTo(newDraft); } // Begin a new FragmentTransaction FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // This fragment shows NoteListFragment as a sidebar (only seen in tablet mode landscape) if (!(getSupportFragmentManager().findFragmentById(R.id.noteList) instanceof NoteListFragment)) transaction.replace(R.id.noteList, new NoteListFragment(), "NoteListFragment"); // This fragment shows NoteListFragment in the main screen area (only seen on phones and tablet mode portrait), // but only if it doesn't already contain NoteViewFragment or NoteEditFragment. // If NoteListFragment is already showing in the sidebar, use WelcomeFragment instead if (!((getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) || (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment))) { if ((getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) == null && findViewById(R.id.layoutMain).getTag().equals("main-layout-large")) || ((getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) && findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))) transaction.replace(R.id.noteViewEdit, new WelcomeFragment(), "NoteListFragment"); else if (findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) transaction.replace(R.id.noteViewEdit, new NoteListFragment(), "NoteListFragment"); } // Commit fragment transaction transaction.commit(); if (savedInstanceState != null) { ArrayList<String> filesToExportList = savedInstanceState.getStringArrayList("files_to_export"); if (filesToExportList != null) filesToExport = filesToExportList.toArray(); ArrayList<String> filesToDeleteList = savedInstanceState.getStringArrayList("files_to_delete"); if (filesToDeleteList != null) filesToDelete = filesToDeleteList.toArray(); ArrayList<String> savedCab = savedInstanceState.getStringArrayList("cab"); if (savedCab != null) { inCabMode = true; cab = savedCab; } } }
From source file:com.csipsimple.ui.SipHome.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case ACCOUNTS_MENU: startActivity(new Intent(this, AccountsEditList.class)); return true; case PARAMS_MENU: startActivityForResult(new Intent(SipManager.ACTION_UI_PREFS_GLOBAL), CHANGE_PREFS); return true; case CLOSE_MENU: Log.d(THIS_FILE, "CLOSE"); boolean currentlyActiveForIncoming = prefProviderWrapper.isValidConnectionForIncoming(); boolean futureActiveForIncoming = (prefProviderWrapper.getAllIncomingNetworks().size() > 0); if (currentlyActiveForIncoming || futureActiveForIncoming) { // Alert user that we will disable for all incoming calls as // he want to quit new AlertDialog.Builder(this).setTitle(R.string.warning) .setMessage(/*from www .j a v a 2 s .co m*/ getString(currentlyActiveForIncoming ? R.string.disconnect_and_incoming_explaination : R.string.disconnect_and_future_incoming_explaination)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { prefProviderWrapper.setPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, true); disconnect(true); } }).setNegativeButton(R.string.cancel, null).show(); } else { disconnect(true); } return true; case HELP_MENU: // Create the fragment and show it as a dialog. DialogFragment newFragment = Help.newInstance(); newFragment.show(getSupportFragmentManager(), "dialog"); return true; case DISTRIB_ACCOUNT_MENU: WizardInfo distribWizard = CustomDistribution.getCustomDistributionWizard(); Cursor c = getContentResolver().query(SipProfile.ACCOUNT_URI, new String[] { SipProfile.FIELD_ID }, SipProfile.FIELD_WIZARD + "=?", new String[] { distribWizard.id }, null); Intent it = new Intent(this, BasePrefsWizard.class); it.putExtra(SipProfile.FIELD_WIZARD, distribWizard.id); Long accountId = null; if (c != null && c.getCount() > 0) { try { c.moveToFirst(); accountId = c.getLong(c.getColumnIndex(SipProfile.FIELD_ID)); } catch (Exception e) { Log.e(THIS_FILE, "Error while getting wizard", e); } finally { c.close(); } } if (accountId != null) { it.putExtra(SipProfile.FIELD_ID, accountId); } startActivityForResult(it, REQUEST_EDIT_DISTRIBUTION_ACCOUNT); return true; default: break; } return super.onOptionsItemSelected(item); }
From source file:eu.trentorise.smartcampus.jp.MonitorJourneyFragment.java
@Override protected void setUpTimingControls() { fromTime = (EditText) getView().findViewById(R.id.recur_time_from); toTime = (EditText) getView().findViewById(R.id.recur_time_to); fromDate = (EditText) getView().findViewById(R.id.recur_date_from); toDate = (EditText) getView().findViewById(R.id.recur_date_to); alwaysCheckbox = (CheckBox) getView().findViewById(R.id.always_checkbox); Date newDate = new Date(); if (params.getData().getParameters().getTime() != null) { try {//w w w. ja v a 2 s .co m Date d = Config.FORMAT_TIME_SMARTPLANNER.parse(params.getData().getParameters().getTime()); fromTime.setText(Config.FORMAT_TIME_UI.format(d)); d.setTime(d.getTime() + params.getData().getParameters().getInterval()); toTime.setText(Config.FORMAT_TIME_UI.format(d)); } catch (ParseException e) { } } else { fromTime.setTag(newDate); fromTime.setText(Config.FORMAT_TIME_UI.format(newDate)); // toTime is set to now + intervalhour Calendar cal = Calendar.getInstance(); cal.setTime(newDate); cal.add(Calendar.HOUR_OF_DAY, INTERVALHOUR); Date interval = cal.getTime(); toTime.setTag(interval); toTime.setText(Config.FORMAT_TIME_UI.format(interval)); } Date d = params.getData().getParameters().getFromDate() > 0 ? new Date(params.getData().getParameters().getFromDate()) : newDate; Date today = new Date(); if (d.before(today)) d = today; fromDate.setText(Config.FORMAT_DATE_UI.format(d)); Calendar cal = Calendar.getInstance(); cal.setTime(today); cal.add(Calendar.DATE, INTERVALDAY); newDate = cal.getTime(); d = params.getData().getParameters().getToDate() > 0 ? new Date(params.getData().getParameters().getToDate()) : newDate; if (params.getData().getParameters().getToDate() != Config.ALWAYS_DATE) toDate.setText(Config.FORMAT_DATE_UI.format(d)); else { // mettilo a domani e always mettilo a true alwaysCheckbox.setChecked(true); d = newDate; toDate.setEnabled(false); } fromTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = TimePickerDialogFragment.newInstance((EditText) v); newFragment.setArguments(TimePickerDialogFragment.prepareData(fromTime.getText().toString())); newFragment.show(getSherlockActivity().getSupportFragmentManager(), "timePicker"); } }); toTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = TimePickerDialogFragment.newInstance((EditText) v); newFragment.setArguments(TimePickerDialogFragment.prepareData(toTime.getText().toString())); newFragment.show(getSherlockActivity().getSupportFragmentManager(), "timePicker"); } }); fromDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = DatePickerDialogFragment.newInstance((EditText) v); newFragment.setArguments(DatePickerDialogFragment.prepareData(fromDate.toString())); newFragment.show(getSherlockActivity().getSupportFragmentManager(), "datePicker"); } }); toDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = DatePickerDialogFragment.newInstance((EditText) v); newFragment.setArguments(DatePickerDialogFragment.prepareData(toDate.toString())); newFragment.show(getSherlockActivity().getSupportFragmentManager(), "datePicker"); } }); /* set the toggle buttons */ days.clear(); ToggleButton tmpToggle = (ToggleButton) getView().findViewById(R.id.monday_toggle); days.put(2, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.tuesday_toggle); days.put(3, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.wednesday_toggle); days.put(4, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.thursday_toggle); days.put(5, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.friday_toggle); days.put(6, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.saturday_toggle); days.put(7, tmpToggle); tmpToggle = (ToggleButton) getView().findViewById(R.id.sunday_toggle); days.put(1, tmpToggle); setToggleDays(params.getData().getParameters().getRecurrence()); }
From source file:com.apps.mohb.wifiauthority.AboutActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); DialogFragment dialog; Intent intent;//from w w w .j av a 2 s . co m Bundle bundle; switch (id) { // Feedback case R.id.action_feedback: intent = new Intent(this, FeedbackActivity.class); bundle = new Bundle(); bundle.putString("url", getString(R.string.url_contact)); intent.putExtras(bundle); startActivity(intent); break; // Bug report case R.id.action_bug_report: intent = new Intent(this, FeedbackActivity.class); bundle = new Bundle(); bundle.putString("url", getString(R.string.url_bug_report)); intent.putExtras(bundle); startActivity(intent); break; // Terms of use case R.id.action_terms_of_use: dialog = new TermsOfUseDialogFragment(); dialog.show(getSupportFragmentManager(), "TermsOfUseDialogFragment"); break; // Privacy policy case R.id.action_privacy_policy: dialog = new PrivacyPolicyDialogFragment(); dialog.show(getSupportFragmentManager(), "PrivacyPolicyDialogFragment"); break; // Legal notices case R.id.action_legal_notices: new GetLegalNotices().execute(); break; // Icons attribution case R.id.action_material_icons: dialog = new MaterialIconsDialogFragment(); dialog.show(getSupportFragmentManager(), "MaterialIconsDialogFragment"); break; } return super.onOptionsItemSelected(item); }
From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mSettings = Settings.getInstance(this); setTheme(mSettings.getTheme());//w ww . j a v a 2s . com super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setStayAwake(mSettings.shouldStayAwake()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences.registerOnSharedPreferenceChangeListener(this); mDatabase = new PlumbleSQLiteDatabase(this); // TODO add support for cloud storage mDatabase.open(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList.setOnItemClickListener(this); mDrawerAdapter = new DrawerAdapter(this, this); mDrawerList.setAdapter(mDrawerAdapter); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { supportInvalidateOptionsMenu(); } @Override public void onDrawerStateChanged(int newState) { super.onDrawerStateChanged(newState); // Prevent push to talk from getting stuck on when the drawer is opened. if (getService() != null && getService().isSynchronized() && getService().isTalking() && !mSettings.isPushToTalkToggle()) { getService().setTalkingState(false); } } @Override public void onDrawerOpened(View drawerView) { supportInvalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // Tint logo to theme int iconColor = getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }) .getColor(0, -1); Drawable logo = getResources().getDrawable(R.drawable.ic_home); logo.setColorFilter(iconColor, PorterDuff.Mode.MULTIPLY); getSupportActionBar().setLogo(logo); AlertDialog.Builder dadb = new AlertDialog.Builder(this); dadb.setMessage(R.string.disconnectSure); dadb.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mService != null && mService.isConnectionEstablished()) mService.disconnect(); loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES); } }); dadb.setNegativeButton(android.R.string.cancel, null); mDisconnectPromptBuilder = dadb; if (savedInstanceState == null) { if (getIntent() != null && getIntent().hasExtra(EXTRA_DRAWER_FRAGMENT)) { loadDrawerFragment(getIntent().getIntExtra(EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_FAVOURITES)); } else { loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES); } } // If we're given a Mumble URL to show, open up a server edit fragment. if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) { String url = getIntent().getDataString(); try { Server server = MumbleURLParser.parseURL(url); // Open a dialog prompting the user to connect to the Mumble server. DialogFragment fragment = (DialogFragment) ServerEditFragment.createServerEditDialog( PlumbleActivity.this, server, ServerEditFragment.Action.CONNECT_ACTION, true); fragment.show(getSupportFragmentManager(), "url_edit"); } catch (MalformedURLException e) { Toast.makeText(this, getString(R.string.mumble_url_parse_failed), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } setVolumeControlStream( mSettings.isHandsetMode() ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC); if (mSettings.isFirstRun()) showSetupWizard(); }
From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java
/** * Controls internet connection, whether external storage is writalbe and ParserService isn't running. * If everything is alright, launches new ParserService. *//* w w w .j ava 2 s. c om*/ public void downloadDictionary() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected()) { mWaitingForConnection = true; this.registerReceiver(mInternetReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); SharedPreferences settings = getSharedPreferences(ParserService.DICTIONARY_PREFERENCES, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("waitingForConnection", true); editor.commit(); DialogFragment newFragment = DictionaryFragmentAlertDialog.newInstance( R.string.internet_connection_failed_title, R.string.internet_connection_failed_message, true); newFragment.show(getSupportFragmentManager(), "dialog"); } else if (!canWriteExternalStorage()) { DialogFragment newFragment = DictionaryFragmentAlertDialog.newInstance( R.string.external_storrage_failed_title, R.string.external_storrage_failed_message, true); newFragment.show(getSupportFragmentManager(), "dialog"); } else if (!isMyServiceRunning(getApplicationContext())) { if (mWaitingForConnection) { this.unregisterReceiver(mInternetReceiver); mWaitingForConnection = false; } Intent intent = new Intent(this, ParserService.class); startService(intent); } }