List of usage examples for android.content.res Resources getString
@NonNull public String getString(@StringRes int id) throws NotFoundException
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
@Override protected void onPrepareDialog(int id, Dialog dialog) { Resources res = getResources(); StyledDialog ad = (StyledDialog) dialog; switch (id) { case DIALOG_DELETE_DECK: if (!AnkiDroidApp.colIsOpen() || mDeckList == null || mDeckList.size() == 0) { return; }// w w w .java 2 s.c o m boolean isDyn = AnkiDroidApp.getCol().getDecks().isDyn(mCurrentDid); if (isDyn) { ad.setMessage(String.format(res.getString(R.string.delete_cram_deck_message), "\'" + AnkiDroidApp.getCol().getDecks().name(mCurrentDid) + "\'")); } else { ad.setMessage(String.format(res.getString(R.string.delete_deck_message), "\'" + AnkiDroidApp.getCol().getDecks().name(mCurrentDid) + "\'")); } break; case DIALOG_CONTEXT_MENU: if (!AnkiDroidApp.colIsOpen() || mDeckList == null || mDeckList.size() == 0) { return; } mCurrentDid = Long.parseLong(mDeckList.get(mContextMenuPosition).get("did")); // try { // ad.changeListItem(CONTEXT_MENU_COLLAPSE_DECK, getResources().getString(AnkiDroidApp.getCol().getDecks().get(mCurrentDid).getBoolean("collapsed") ? R.string.contextmenu_deckpicker_inflate_deck : R.string.contextmenu_deckpicker_collapse_deck)); // } catch (NotFoundException e) { // // do nothing // } catch (JSONException e) { // // do nothing // } ad.setTitle(AnkiDroidApp.getCol().getDecks().name(mCurrentDid)); break; case DIALOG_IMPORT_LOG: case DIALOG_SYNC_LOG: case DIALOG_SYNC_SANITY_ERROR: // If both have text, separate them by a new line. if (!TextUtils.isEmpty(mDialogMessage) && !TextUtils.isEmpty(mSyncMessage)) { ad.setMessage(mDialogMessage + "\n\n" + mSyncMessage); } else if (!TextUtils.isEmpty(mDialogMessage)) { ad.setMessage(mDialogMessage); } else { ad.setMessage(mSyncMessage); } break; case DIALOG_DB_ERROR: mLoadFailed = false; ad.getButton(Dialog.BUTTON3).setEnabled(hasErrorFiles()); break; case DIALOG_LOAD_FAILED: mLoadFailed = true; if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) { mOpenCollectionDialog.setMessage(res.getString(R.string.col_load_failed)); } break; case DIALOG_ERROR_HANDLING: ArrayList<String> options = new ArrayList<String>(); ArrayList<Integer> values = new ArrayList<Integer>(); if (AnkiDroidApp.getCol() == null) { // retry options.add(res.getString(R.string.backup_retry_opening)); values.add(0); } else { // fix integrity options.add(res.getString(R.string.check_db)); values.add(1); } // repair db with sqlite options.add(res.getString(R.string.backup_error_menu_repair)); values.add(2); // // restore from backup options.add(res.getString(R.string.backup_restore)); values.add(3); // delete old collection and build new one options.add(res.getString(R.string.backup_full_sync_from_server)); values.add(4); // delete old collection and build new one options.add(res.getString(R.string.backup_del_collection)); values.add(5); String[] titles = new String[options.size()]; mRepairValues = new int[options.size()]; for (int i = 0; i < options.size(); i++) { titles[i] = options.get(i); mRepairValues[i] = values.get(i); } ad.setItems(titles, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (mRepairValues[which]) { case 0: loadCollection(); return; case 1: integrityCheck(); return; case 2: showDialog(DIALOG_REPAIR_COLLECTION); return; case 3: showDialog(DIALOG_RESTORE_BACKUP); return; case 4: showDialog(DIALOG_FULL_SYNC_FROM_SERVER); return; case 5: showDialog(DIALOG_NEW_COLLECTION); return; } } }); break; case DIALOG_IMPORT_SELECT: List<File> fileList = Utils.getImportableDecks(); if (fileList.size() == 0) { Themes.showThemedToast(DeckPicker.this, getResources().getString(R.string.upgrade_import_no_file_found), false); } ad.setEnabled(fileList.size() != 0); String[] tts = new String[fileList.size()]; mImportValues = new String[fileList.size()]; for (int i = 0; i < tts.length; i++) { tts[i] = fileList.get(i).getName().replace(".apkg", ""); mImportValues[i] = fileList.get(i).getAbsolutePath(); } ad.setItems(tts, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mImportPath = mImportValues[which]; switch (mImportMethod) { case IMPORT_METHOD_ADD: DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener, new TaskData(AnkiDroidApp.getCol(), mImportPath, false)); mImportPath = null; break; case IMPORT_METHOD_REPLACE: DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mImportReplaceListener, new TaskData(AnkiDroidApp.getCol(), mImportPath)); mImportPath = null; break; case IMPORT_METHOD_ASK: default: showDialog(DIALOG_IMPORT); } mImportMethod = IMPORT_METHOD_ASK; } }); break; } }
From source file:com.ichi2.anki.Reviewer.java
@SuppressLint("NewApi") @Override//from w ww . ja va 2 s. com public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.reviewer, menu); Resources res = getResources(); if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) { menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_unmark_note) .setIcon(R.drawable.ic_star_white_24dp); } else { menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_mark_note) .setIcon(R.drawable.ic_star_outline_white_24dp); } if (colIsOpen() && getCol().undoAvailable()) { menu.findItem(R.id.action_undo).setEnabled(true).getIcon().setAlpha(Themes.ALPHA_ICON_ENABLED_LIGHT); } else { menu.findItem(R.id.action_undo).setEnabled(false).getIcon().setAlpha(Themes.ALPHA_ICON_DISABLED_LIGHT); } if (mPrefWhiteboard) { // Don't force showing mark icon when whiteboard enabled // TODO: allow user to customize which icons are force-shown MenuItemCompat.setShowAsAction(menu.findItem(R.id.action_mark_card), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); // Check if we can forceably squeeze in 3 items into the action bar, if not hide "show whiteboard" if (CompatHelper.getSdkVersion() >= 14 && !ViewConfiguration.get(this).hasPermanentMenuKey()) { // Android 4.x device with overflow menu in the action bar and small screen can't // support forcing 2 extra items into the action bar Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = getResources().getDisplayMetrics().density; float dpWidth = outMetrics.widthPixels / density; if (dpWidth < 360) { menu.findItem(R.id.action_hide_whiteboard).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } } // Configure the whiteboard related items in the action bar menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.disable_whiteboard); menu.findItem(R.id.action_hide_whiteboard).setVisible(true); menu.findItem(R.id.action_clear_whiteboard).setVisible(true); Drawable whiteboardIcon = getResources().getDrawable(R.drawable.ic_gesture_white_24dp); if (mShowWhiteboard) { whiteboardIcon.setAlpha(255); menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon); menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.hide_whiteboard); } else { whiteboardIcon.setAlpha(77); menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon); menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.show_whiteboard); } } else { menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.enable_whiteboard); } if (!CompatHelper.isHoneycomb() && !mDisableClipboard) { menu.findItem(R.id.action_search_dictionary).setVisible(true) .setEnabled(!(mPrefWhiteboard && mShowWhiteboard)) .setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select)); } if (getCol().getDecks().isDyn(getParentDid())) { menu.findItem(R.id.action_open_deck_options).setVisible(false); } return super.onCreateOptionsMenu(menu); }
From source file:com.example.aitor2.myapplication.DrawerArrowSample.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.home_view);//ww w. j ava2s.c o m final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator); final Resources resources = getResources(); drawer_adapter adapter = new drawer_adapter(this, icons, titles); ListView lv = (ListView) findViewById(R.id.drawer_listview); lv.setAdapter(adapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawer.closeDrawer(START); if (position == 0) { Intent intent = new Intent(DrawerArrowSample.this, DrawerArrowSample.class); startActivity(intent); finish(); } else if (position == 1) { Intent intent = new Intent(DrawerArrowSample.this, misReservas.class); startActivity(intent); finish(); } } }); findViewById(R.id.pink_icon).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(DrawerArrowSample.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT) .show(); } }); actionB = (FloatingActionButton) findViewById(R.id.pink_icon); actionB.setStrokeVisible(true); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(onRefreshListener); swipeRefreshLayout.setColorSchemeColors(Color.BLACK, Color.GREEN, Color.BLACK, Color.GREEN); drawerArrowDrawable = new DrawerArrowDrawable(resources); drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray)); imageView.setImageDrawable(drawerArrowDrawable); drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { offset = slideOffset; // Sometimes slideOffset ends up so close to but not quite 1 or 0. if (slideOffset >= .995) { flipped = true; drawerArrowDrawable.setFlip(flipped); } else if (slideOffset <= .005) { flipped = false; drawerArrowDrawable.setFlip(flipped); } drawerArrowDrawable.setParameter(offset); } }); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (drawer.isDrawerVisible(START)) { drawer.closeDrawer(START); } else { drawer.openDrawer(START); } } }); final TextView styleButton = (TextView) findViewById(R.id.indicator_style); styleButton.setOnClickListener(new View.OnClickListener() { boolean rounded = false; @Override public void onClick(View v) { styleButton.setText(rounded // ? resources.getString(R.string.rounded) // : resources.getString(R.string.squared)); rounded = !rounded; drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded); drawerArrowDrawable.setParameter(offset); drawerArrowDrawable.setFlip(flipped); drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray)); imageView.setImageDrawable(drawerArrowDrawable); } }); /////////////////////create expandable listview new expandable().execute(); ////////////////////calendario // Pop up Date picker on pressing the editText }
From source file:com.androzic.track.TrackDetails.java
private void updateTrackDetails() { AppCompatActivity activity = (AppCompatActivity) getActivity(); Resources resources = getResources(); activity.getSupportActionBar().setTitle(track.name); View view = getView();// w w w . ja v a2s .c o m int pointCount = track.getPointCount(); ((TextView) view.findViewById(R.id.point_count)) .setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount)); String distance = StringFormatter.distanceH(track.distance); ((TextView) view.findViewById(R.id.distance)).setText(distance); Track.TrackPoint ftp = track.getPoint(0); Track.TrackPoint ltp = track.getLastPoint(); String start_coords = StringFormatter.coordinates(" ", ftp.latitude, ftp.longitude); ((TextView) view.findViewById(R.id.start_coordinates)).setText(start_coords); String finish_coords = StringFormatter.coordinates(" ", ltp.latitude, ltp.longitude); ((TextView) view.findViewById(R.id.finish_coordinates)).setText(finish_coords); Date start_date = new Date(ftp.time); ((TextView) view.findViewById(R.id.start_date)) .setText(DateFormat.getDateFormat(activity).format(start_date) + " " + DateFormat.getTimeFormat(activity).format(start_date)); Date finish_date = new Date(ltp.time); ((TextView) view.findViewById(R.id.finish_date)) .setText(DateFormat.getDateFormat(activity).format(finish_date) + " " + DateFormat.getTimeFormat(activity).format(finish_date)); long elapsed = (ltp.time - ftp.time) / 1000; String timeSpan; if (elapsed < 24 * 60 * 60 * 3) { timeSpan = DateUtils.formatElapsedTime(elapsed); } else { timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH); } ((TextView) view.findViewById(R.id.time_span)).setText(timeSpan); // Gather statistics int segmentCount = 0; double minElevation = Double.MAX_VALUE; double maxElevation = Double.MIN_VALUE; double maxSpeed = 0; MeanValue mv = new MeanValue(); for (Track.TrackSegment segment : track.getSegments()) { Track.TrackPoint ptp = null; if (segment.independent) segmentCount++; for (Track.TrackPoint tp : segment.getPoints()) { if (ptp != null) { double d = Geo.distance(tp.latitude, tp.longitude, ptp.latitude, ptp.longitude); double speed = d / ((tp.time - ptp.time) / 1000); if (speed == Double.POSITIVE_INFINITY) continue; mv.addValue(speed); if (speed > maxSpeed) maxSpeed = speed; } ptp = tp; if (tp.elevation < minElevation && tp.elevation != 0) minElevation = tp.elevation; if (tp.elevation > maxElevation) maxElevation = tp.elevation; } } double averageSpeed = mv.getMeanValue(); ((TextView) view.findViewById(R.id.segment_count)) .setText(resources.getQuantityString(R.plurals.numberOfSegments, segmentCount, segmentCount)); ((TextView) view.findViewById(R.id.max_elevation)).setText(StringFormatter.elevationH(maxElevation)); ((TextView) view.findViewById(R.id.min_elevation)).setText(StringFormatter.elevationH(minElevation)); ((TextView) view.findViewById(R.id.max_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.max_speed), StringFormatter.speedH(maxSpeed))); ((TextView) view.findViewById(R.id.average_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.average_speed), StringFormatter.speedH(averageSpeed))); }
From source file:com.ichi2.anki2.Reviewer.java
private void showEaseButtons() { Resources res = getResources(); // hide flipcard button switchVisibility(mFlipCardLayout, View.GONE); int buttonCount; try {/*from ww w. ja va 2s. c om*/ buttonCount = mSched.answerButtons(mCurrentCard); } catch (RuntimeException e) { AnkiDroidApp.saveExceptionReportFile(e, "Reviewer-showEaseButtons"); closeReviewer(DeckPicker.RESULT_DB_ERROR, true); return; } // Set correct label for each button switch (buttonCount) { case 2: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease3_successive)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); mEase2Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextRecomColor); mEase2.setTextColor(mNextTimeTextRecomColor); mNext3.setTextColor(mNextTimeTextColor); mEase3.setTextColor(mNextTimeTextColor); break; case 3: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease3_successive)); mEase3.setText(res.getString(R.string.ease3_learning)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); switchVisibility(mEase3Layout, View.VISIBLE); mEase2Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextRecomColor); mEase2.setTextColor(mNextTimeTextRecomColor); mNext3.setTextColor(mNextTimeTextColor); mEase3.setTextColor(mNextTimeTextColor); break; default: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease2_successive)); mEase3.setText(res.getString(R.string.ease3_successive)); mEase4.setText(res.getString(R.string.ease3_learning)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); switchVisibility(mEase3Layout, View.VISIBLE); switchVisibility(mEase4Layout, View.VISIBLE); mEase3Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextColor); mEase2.setTextColor(mNextTimeTextColor); mNext3.setTextColor(mNextTimeTextRecomColor); mEase3.setTextColor(mNextTimeTextRecomColor); } // Show next review time if (mshowNextReviewTime) { mNext1.setText(mSched.nextIvlStr(mCurrentCard, 1)); mNext2.setText(mSched.nextIvlStr(mCurrentCard, 2)); if (buttonCount > 2) { mNext3.setText(mSched.nextIvlStr(mCurrentCard, 3)); } if (buttonCount > 3) { mNext4.setText(mSched.nextIvlStr(mCurrentCard, 4)); } } }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
private void showEaseButtons() { Resources res = getResources(); // hide flipcard button switchVisibility(mFlipCardLayout, View.GONE); int buttonCount; try {/* w w w .j a v a2s . co m*/ buttonCount = mSched.answerButtons(mCurrentCard); } catch (RuntimeException e) { AnkiDroidApp.saveExceptionReportFile(e, "Reviewer-showEaseButtons"); closeReviewer(DeckPicker.RESULT_DB_ERROR, true); return; } // Set correct label for each button switch (buttonCount) { case 2: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease3_successive)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); mEase2Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextRecomColor); mEase2.setTextColor(mNextTimeTextRecomColor); mNext3.setTextColor(mNextTimeTextColor); mEase3.setTextColor(mNextTimeTextColor); break; case 3: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease3_successive)); mEase3.setText(res.getString(R.string.ease3_learning)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); switchVisibility(mEase3Layout, View.VISIBLE); mEase2Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextRecomColor); mEase2.setTextColor(mNextTimeTextRecomColor); mNext3.setTextColor(mNextTimeTextColor); mEase3.setTextColor(mNextTimeTextColor); break; default: mEase1.setText(res.getString(R.string.ease1_successive)); mEase2.setText(res.getString(R.string.ease2_successive)); mEase3.setText(res.getString(R.string.ease3_successive)); mEase4.setText(res.getString(R.string.ease3_learning)); switchVisibility(mEase1Layout, View.VISIBLE); switchVisibility(mEase2Layout, View.VISIBLE); switchVisibility(mEase3Layout, View.VISIBLE); switchVisibility(mEase4Layout, View.VISIBLE); mEase3Layout.requestFocus(); mNext2.setTextColor(mNextTimeTextColor); mEase2.setTextColor(mNextTimeTextColor); mNext3.setTextColor(mNextTimeTextRecomColor); mEase3.setTextColor(mNextTimeTextRecomColor); } // Show next review time if (mShowNextReviewTime) { mNext1.setText(mSched.nextIvlStr(mCurrentCard, 1)); mNext2.setText(mSched.nextIvlStr(mCurrentCard, 2)); if (buttonCount > 2) { mNext3.setText(mSched.nextIvlStr(mCurrentCard, 3)); } if (buttonCount > 3) { mNext4.setText(mSched.nextIvlStr(mCurrentCard, 4)); } } }
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
/** Handles item selections */ @Override//from w w w .j ava 2s . co m public boolean onOptionsItemSelected(MenuItem item) { Resources res = getResources(); switch (item.getItemId()) { case MENU_HELP: showDialog(DIALOG_SELECT_HELP); return true; case MENU_SYNC: sync(); return true; case MENU_ADD_NOTE: addNote(); return true; case MENU_STATISTICS: showDialog(DIALOG_SELECT_STATISTICS_TYPE); return true; case MENU_CARDBROWSER: openCardBrowser(); return true; case MENU_CREATE_DECK: StyledDialog.Builder builder2 = new StyledDialog.Builder(DeckPicker.this); builder2.setTitle(res.getString(R.string.new_deck)); mDialogEditText = (EditText) new EditText(DeckPicker.this); // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter }); builder2.setView(mDialogEditText, false, false); builder2.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String deckName = mDialogEditText.getText().toString().replaceAll("[\'\"\\n\\r\\[\\]\\(\\)]", ""); // Log.i(AnkiDroidApp.TAG, "Creating deck: " + deckName); AnkiDroidApp.getCol().getDecks().id(deckName, true); loadCounts(); } }); builder2.setNegativeButton(res.getString(R.string.cancel), null); builder2.create().show(); return true; case MENU_CREATE_DYNAMIC_DECK: StyledDialog.Builder builder3 = new StyledDialog.Builder(DeckPicker.this); builder3.setTitle(res.getString(R.string.new_deck)); mDialogEditText = (EditText) new EditText(DeckPicker.this); ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames(); int n = 1; String cramDeckName = "Cram 1"; while (names.contains(cramDeckName)) { n++; cramDeckName = "Cram " + n; } mDialogEditText.setText(cramDeckName); // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter }); builder3.setView(mDialogEditText, false, false); builder3.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { long id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString()); openStudyOptions(id, new Bundle()); } }); builder3.setNegativeButton(res.getString(R.string.cancel), null); builder3.create().show(); return true; case MENU_ABOUT: startActivity(new Intent(DeckPicker.this, Info.class)); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.RIGHT); } return true; case MENU_ADD_SHARED_DECK: if (AnkiDroidApp.getCol() != null) { SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); String hkey = preferences.getString("hkey", ""); if (hkey.length() == 0) { showDialog(DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK); } else { addSharedDeck(); } } return true; case MENU_IMPORT: showDialog(DIALOG_IMPORT_HINT); return true; case MENU_PREFERENCES: startActivityForResult(new Intent(DeckPicker.this, Preferences.class), PREFERENCES_UPDATE); return true; case MENU_FEEDBACK: Intent i = new Intent(DeckPicker.this, Feedback.class); i.putExtra("request", REPORT_FEEDBACK); startActivityForResult(i, REPORT_FEEDBACK); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT); } return true; case CHECK_DATABASE: integrityCheck(); return true; case StudyOptionsActivity.MENU_ROTATE: if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } return true; case StudyOptionsActivity.MENU_NIGHT: SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this); if (preferences.getBoolean("invertedColors", false)) { preferences.edit().putBoolean("invertedColors", false).commit(); item.setIcon(R.drawable.ic_menu_night); } else { preferences.edit().putBoolean("invertedColors", true).commit(); item.setIcon(R.drawable.ic_menu_night_checked); } return true; case MENU_REUPGRADE: restartUpgradeProcess(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java
public Thread videoUploadToFTPserver(final Activity activity, final Handler handler, final String latestVideoFile_filename, final String latestVideoFile_absolutepath, final String emailAddress, final long sdrecord_id) { Log.d(TAG, "doVideoFTP starting"); // Make the progress bar view visible. ((VidiomActivity) activity).startedUploading(PublishingUtils.TYPE_FTP); final Resources res = activity.getResources(); Thread t = new Thread(new Runnable() { public void run() { // Do background task. // FTP; connect preferences here! ///*from ww w .j av a2s . co m*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext()); String ftpHostName = prefs.getString("defaultFTPhostPreference", null); String ftpUsername = prefs.getString("defaultFTPusernamePreference", null); String ftpPassword = prefs.getString("defaultFTPpasswordPreference", null); // use name of local file. String ftpRemoteFtpFilename = latestVideoFile_filename; // FTP FTPClient ftpClient = new FTPClient(); InetAddress uploadhost = null; try { uploadhost = InetAddress.getByName(ftpHostName); } catch (UnknownHostException e1) { // If DNS resolution fails then abort immediately - show // dialog to // inform user first. e1.printStackTrace(); Log.e(TAG, " got exception resolving " + ftpHostName + " - video uploading failed."); uploadhost = null; } if (uploadhost == null) { // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_find_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } boolean connected = false; try { ftpClient.connect(uploadhost); connected = true; } catch (SocketException e) { e.printStackTrace(); connected = false; } catch (UnknownHostException e) { // e.printStackTrace(); connected = false; } catch (IOException e) { // e.printStackTrace(); connected = false; } if (!connected) { // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_login_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } boolean reply = false; try { reply = ftpClient.login(ftpUsername, ftpPassword); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp.login - video uploading failed."); } // check the reply code here // If we cant login, abort after showing user a dialog. if (!reply) { try { ftpClient.disconnect(); } catch (IOException e) { // e.printStackTrace(); } // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_login_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } // Set File type to binary try { ftpClient.setFileType(FTP.BINARY_FILE_TYPE); } catch (IOException e) { // e.printStackTrace(); // keep going?! } // BEYOND HERE DONT USE DIALOGS! // Construct the input stream to send to Ftp server, from the // local // video file on the sd card BufferedInputStream buffIn = null; File file = new File(latestVideoFile_absolutepath); try { buffIn = new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { // e.printStackTrace(); Log.e(TAG, " got exception on local video file - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); // This is a bad error, lets abort. // user dialog ?! shouldnt happen, but still... return; } ftpClient.enterLocalPassiveMode(); try { // UPLOAD THE LOCAL VIDEO FILE. ftpClient.storeFile(ftpRemoteFtpFilename, buffIn); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on storeFile - video uploading failed."); // This is a bad error, lets abort. // user dialog ?! shouldnt happen, but still... // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { buffIn.close(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on buff.close - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { ftpClient.logout(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp logout - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { ftpClient.disconnect(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp disconnect - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } if (emailAddress != null && ftpHostName != null) { // EmailSender through IR controlled gmail system. SSLEmailSender sender = new SSLEmailSender( activity.getString(R.string.automatic_email_username), activity.getString(R.string.automatic_email_password)); // consider // this // public // knowledge. try { sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(), activity.getString(R.string.url_of_hosted_video_is_) + " " + ftpHostName, // body.getText().toString(), activity.getString(R.string.automatic_email_from), // from.getText().toString(), emailAddress // to.getText().toString() ); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } // Log record of this URL in POSTs table dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id, ftpHostName, ftpHostName, ""); mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. handler.postDelayed(new Runnable() { public void run() { // Update UI // Indicate back to calling activity the result! // update uploadInProgress state also. ((VidiomActivity) activity).finishedUploading(true); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_succeeded_)); } }, 0); } }); t.start(); return t; }
From source file:com.ichi2.anki2.DeckPicker.java
@Override protected Dialog onCreateDialog(int id) { StyledDialog dialog;// w w w . j av a 2s . c om Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(this); switch (id) { case DIALOG_OK: builder.setPositiveButton(R.string.ok, null); dialog = builder.create(); break; case DIALOG_NO_SDCARD: builder.setMessage("The SD card could not be read. Please, turn off USB storage."); builder.setPositiveButton(R.string.ok, null); dialog = builder.create(); break; case DIALOG_SELECT_HELP: builder.setTitle(res.getString(R.string.help_title)); builder.setItems(new String[] { res.getString(R.string.help_tutorial), res.getString(R.string.help_online), res.getString(R.string.help_faq) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { if (arg1 == 0) { createTutorialDeck(); } else { if (Utils.isIntentAvailable(DeckPicker.this, "android.intent.action.VIEW")) { Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(getResources().getString( arg1 == 0 ? R.string.link_help : R.string.link_faq))); startActivity(intent); } else { startActivity(new Intent(DeckPicker.this, Info.class)); } } } }); dialog = builder.create(); break; case DIALOG_CONNECTION_ERROR: builder.setTitle(res.getString(R.string.connection_error_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(res.getString(R.string.connection_error_message)); builder.setPositiveButton(res.getString(R.string.retry), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sync(); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); dialog = builder.create(); break; case DIALOG_SYNC_CONFLICT_RESOLUTION: builder.setTitle(res.getString(R.string.sync_conflict_title)); builder.setIcon(android.R.drawable.ic_input_get); builder.setMessage(res.getString(R.string.sync_conflict_message)); builder.setPositiveButton(res.getString(R.string.sync_conflict_local), mSyncConflictResolutionListener); builder.setNeutralButton(res.getString(R.string.sync_conflict_remote), mSyncConflictResolutionListener); builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel), mSyncConflictResolutionListener); builder.setCancelable(true); dialog = builder.create(); break; case DIALOG_LOAD_FAILED: builder.setMessage(res.getString(R.string.open_collection_failed_message, BackupManager.BROKEN_DECKS_SUFFIX, res.getString(R.string.repair_deck))); builder.setTitle(R.string.open_collection_failed_title); builder.setIcon(R.drawable.ic_dialog_alert); builder.setPositiveButton(res.getString(R.string.error_handling_options), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finishWithAnimation(); } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finishWithAnimation(); } }); dialog = builder.create(); break; case DIALOG_DB_ERROR: builder.setMessage(R.string.answering_error_message); builder.setTitle(R.string.answering_error_title); builder.setIcon(R.drawable.ic_dialog_alert); builder.setPositiveButton(res.getString(R.string.error_handling_options), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setNeutralButton(res.getString(R.string.answering_error_report), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(DeckPicker.this, Feedback.class); i.putExtra("request", RESULT_DB_ERROR); dialog.dismiss(); startActivityForResult(i, REPORT_ERROR); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.RIGHT); } } }); builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!AnkiDroidApp.colIsOpen()) { finishWithAnimation(); } } }); builder.setCancelable(true); dialog = builder.create(); break; case DIALOG_ERROR_HANDLING: builder.setTitle(res.getString(R.string.error_handling_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setSingleChoiceItems(new String[] { "1" }, 0, null); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (mLoadFailed) { // dialog has been called because collection could not be opened showDialog(DIALOG_LOAD_FAILED); } else { // dialog has been called because a db error happened showDialog(DIALOG_DB_ERROR); } } }); builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mLoadFailed) { // dialog has been called because collection could not be opened showDialog(DIALOG_LOAD_FAILED); } else { // dialog has been called because a db error happened showDialog(DIALOG_DB_ERROR); } } }); dialog = builder.create(); break; case DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK: builder.setTitle(res.getString(R.string.connection_error_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(res.getString(R.string.no_user_password_error_message)); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent myAccount = new Intent(DeckPicker.this, MyAccount.class); myAccount.putExtra("notLoggedIn", true); startActivityForResult(myAccount, LOG_IN_FOR_SHARED_DECK); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE); } } }); dialog = builder.create(); break; case DIALOG_USER_NOT_LOGGED_IN_SYNC: builder.setTitle(res.getString(R.string.connection_error_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(res.getString(R.string.no_user_password_error_message)); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent myAccount = new Intent(DeckPicker.this, MyAccount.class); myAccount.putExtra("notLoggedIn", true); startActivityForResult(myAccount, LOG_IN_FOR_SYNC); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE); } } }); dialog = builder.create(); break; // case DIALOG_USER_NOT_LOGGED_IN_DOWNLOAD: // if (id == DIALOG_USER_NOT_LOGGED_IN_SYNC) { // } else { // builder.setPositiveButton(res.getString(R.string.log_in), // new DialogInterface.OnClickListener() { // // @Override // public void onClick(DialogInterface dialog, int which) { // Intent myAccount = new Intent(DeckPicker.this, // MyAccount.class); // myAccount.putExtra("notLoggedIn", true); // startActivityForResult(myAccount, LOG_IN_FOR_DOWNLOAD); // if (UIUtils.getApiLevel() > 4) { // ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.LEFT); // } // } // }); // } // builder.setNegativeButton(res.getString(R.string.cancel), null); // dialog = builder.create(); // break; case DIALOG_NO_CONNECTION: builder.setTitle(res.getString(R.string.connection_error_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(res.getString(R.string.connection_needed)); builder.setPositiveButton(res.getString(R.string.ok), null); dialog = builder.create(); break; case DIALOG_DELETE_DECK: if (!AnkiDroidApp.colIsOpen() || mDeckList == null) { return null; } // Message is set in onPrepareDialog builder.setTitle(res.getString(R.string.delete_deck_title)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (AnkiDroidApp.getCol().getDecks().selected() == mCurrentDid) { Fragment frag = (Fragment) getSupportFragmentManager() .findFragmentById(R.id.studyoptions_fragment); if (frag != null && frag instanceof StudyOptionsFragment) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.remove(frag); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } } DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DELETE_DECK, new DeckTask.TaskListener() { @Override public void onPreExecute() { mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "", getResources().getString(R.string.delete_deck), true); } @Override public void onPostExecute(TaskData result) { if (result == null) { return; } Object[] res = result.getObjArray(); updateDecksList((TreeSet<Object[]>) res[0], (Integer) res[1], (Integer) res[2]); if (mProgressDialog.isShowing()) { try { mProgressDialog.dismiss(); } catch (Exception e) { Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage()); } } } @Override public void onProgressUpdate(TaskData... values) { } }, new TaskData(AnkiDroidApp.getCol(), mCurrentDid)); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); dialog = builder.create(); break; case DIALOG_SELECT_STATISTICS_TYPE: dialog = ChartBuilder.getStatisticsDialog(this, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean muh = mFragmented ? AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean( "statsRange", true) : true; DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_STATISTICS, mLoadStatisticsHandler, new DeckTask.TaskData(AnkiDroidApp.getCol(), which, mFragmented ? AnkiDroidApp .getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()) .getBoolean("statsRange", true) : true)); } }, mFragmented); break; case DIALOG_CONTEXT_MENU: String[] entries = new String[3]; // entries[CONTEXT_MENU_DECK_SUMMARY] = // "XXXsum";//res.getStringArray(R.array.statistics_type_labels)[0]; // entries[CONTEXT_MENU_CUSTOM_DICTIONARY] = // res.getString(R.string.contextmenu_deckpicker_set_custom_dictionary); // entries[CONTEXT_MENU_RESET_LANGUAGE] = // res.getString(R.string.contextmenu_deckpicker_reset_language_assignments); entries[CONTEXT_MENU_COLLAPSE_DECK] = res.getString(R.string.contextmenu_deckpicker_collapse_deck); entries[CONTEXT_MENU_RENAME_DECK] = res.getString(R.string.contextmenu_deckpicker_rename_deck); entries[CONTEXT_MENU_DELETE_DECK] = res.getString(R.string.contextmenu_deckpicker_delete_deck); builder.setTitle("Context Menu"); builder.setIcon(R.drawable.ic_menu_manage); builder.setItems(entries, mContextMenuListener); dialog = builder.create(); break; case DIALOG_REPAIR_COLLECTION: builder.setTitle(res.getString(R.string.backup_repair_deck)); builder.setMessage(res.getString(R.string.repair_deck_dialog, BackupManager.BROKEN_DECKS_SUFFIX)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REPAIR_DECK, mRepairDeckHandler, new DeckTask.TaskData(AnkiDroidApp.getCol(), AnkiDroidApp.getCollectionPath())); } }); builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { showDialog(DIALOG_ERROR_HANDLING); } }); dialog = builder.create(); break; case DIALOG_SYNC_SANITY_ERROR: builder.setPositiveButton(getString(R.string.sync_sanity_local), mSyncSanityFailListener); builder.setNeutralButton(getString(R.string.sync_sanity_remote), mSyncSanityFailListener); builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel), mSyncSanityFailListener); builder.setTitle(res.getString(R.string.sync_log_title)); dialog = builder.create(); break; case DIALOG_SYNC_UPGRADE_REQUIRED: builder.setMessage(res.getString(R.string.upgrade_required, res.getString(R.string.link_anki))); builder.setPositiveButton(res.getString(R.string.retry), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sync("download", mSyncMediaUsn); } }); builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mLoadFailed) { // dialog has been called because collection could not be opened showDialog(DIALOG_LOAD_FAILED); } else { // dialog has been called because a db error happened showDialog(DIALOG_DB_ERROR); } } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { if (mLoadFailed) { // dialog has been called because collection could not be opened showDialog(DIALOG_LOAD_FAILED); } else { // dialog has been called because a db error happened showDialog(DIALOG_DB_ERROR); } } }); builder.setTitle(res.getString(R.string.sync_log_title)); dialog = builder.create(); break; case DIALOG_SYNC_LOG: builder.setTitle(res.getString(R.string.sync_log_title)); builder.setPositiveButton(res.getString(R.string.ok), null); dialog = builder.create(); break; case DIALOG_BACKUP_NO_SPACE_LEFT: builder.setTitle(res.getString(R.string.attention)); builder.setMessage(res.getString(R.string.backup_deck_no_space_left)); builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { loadCollection(); } }); // builder.setNegativeButton(res.getString(R.string.dont_show_again), new // DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface arg0, int arg1) { // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit(); // } // }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { loadCollection(); } }); dialog = builder.create(); break; case DIALOG_SD_CARD_NOT_MOUNTED: if (mNotMountedDialog == null || !mNotMountedDialog.isShowing()) { mNotMountedDialog = StyledOpenCollectionDialog.show(DeckPicker.this, getResources().getString(R.string.sd_card_not_mounted), new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { finishWithAnimation(); } }, new View.OnClickListener() { @Override public void onClick(View v) { startActivityForResult(new Intent(DeckPicker.this, Preferences.class), PREFERENCES_UPDATE); } }); } dialog = null; break; case DIALOG_IMPORT: builder.setTitle(res.getString(R.string.import_title)); builder.setMessage(res.getString(R.string.import_message, mImportPath)); builder.setPositiveButton(res.getString(R.string.import_message_add), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener, new TaskData(AnkiDroidApp.getCol(), mImportPath, false)); mImportPath = null; } }); builder.setNeutralButton(res.getString(R.string.import_message_replace), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(DeckPicker.this); builder.setTitle(res.getString(R.string.import_title)); builder.setMessage(res.getString(R.string.import_message_replace_confirm, mImportPath)); builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mImportReplaceListener, new TaskData(AnkiDroidApp.getCol(), mImportPath)); mImportPath = null; } }); builder.setNegativeButton(res.getString(R.string.no), null); builder.show(); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.setCancelable(true); dialog = builder.create(); break; case DIALOG_IMPORT_SELECT: builder.setTitle(res.getString(R.string.import_title)); dialog = builder.create(); break; case DIALOG_IMPORT_HINT: builder.setTitle(res.getString(R.string.import_title)); builder.setMessage(res.getString(R.string.import_hint, AnkiDroidApp.getCurrentAnkiDroidDirectory())); builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDialog(DIALOG_IMPORT_SELECT); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); dialog = builder.create(); break; case DIALOG_IMPORT_LOG: builder.setIcon(R.drawable.ic_dialog_alert); builder.setTitle(res.getString(R.string.import_title)); builder.setPositiveButton(res.getString(R.string.ok), null); dialog = builder.create(); break; case DIALOG_NO_SPACE_LEFT: builder.setTitle(res.getString(R.string.attention)); builder.setMessage(res.getString(R.string.sd_space_warning, BackupManager.MIN_FREE_SPACE)); builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finishWithAnimation(); } }); // builder.setNegativeButton(res.getString(R.string.dont_show_again), new // DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface arg0, int arg1) { // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit(); // } // }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { finishWithAnimation(); } }); dialog = builder.create(); break; case DIALOG_RESTORE_BACKUP: File[] files = BackupManager.getBackups(new File(AnkiDroidApp.getCollectionPath())); mBackups = new File[files.length]; for (int i = 0; i < files.length; i++) { mBackups[i] = files[files.length - 1 - i]; } if (mBackups.length == 0) { builder.setTitle(getResources().getString(R.string.backup_restore)); builder.setMessage(res.getString(R.string.backup_restore_no_backups)); builder.setPositiveButton(res.getString(R.string.ok), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { showDialog(DIALOG_ERROR_HANDLING); } }); } else { String[] dates = new String[mBackups.length]; for (int i = 0; i < mBackups.length; i++) { dates[i] = mBackups[i].getName().replaceAll(".*-(\\d{4}-\\d{2}-\\d{2})-(\\d{2})-(\\d{2}).anki2", "$1 ($2:$3 h)"); } builder.setTitle(res.getString(R.string.backup_restore_select_title)); builder.setIcon(android.R.drawable.ic_input_get); builder.setSingleChoiceItems(dates, dates.length, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_RESTORE_DECK, mRestoreDeckHandler, new DeckTask.TaskData(new Object[] { AnkiDroidApp.getCol(), AnkiDroidApp.getCollectionPath(), mBackups[which].getPath() })); } }); builder.setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { showDialog(DIALOG_ERROR_HANDLING); } }); } dialog = builder.create(); break; case DIALOG_NEW_COLLECTION: builder.setTitle(res.getString(R.string.backup_new_collection)); builder.setMessage(res.getString(R.string.backup_del_collection_question)); builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AnkiDroidApp.closeCollection(false); String path = AnkiDroidApp.getCollectionPath(); AnkiDatabaseManager.closeDatabase(path); if (BackupManager.moveDatabaseToBrokenFolder(path, false)) { loadCollection(); } else { showDialog(DIALOG_ERROR_HANDLING); } } }); builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { showDialog(DIALOG_ERROR_HANDLING); } }); dialog = builder.create(); break; case DIALOG_FULL_SYNC_FROM_SERVER: builder.setTitle(res.getString(R.string.backup_full_sync_from_server)); builder.setMessage(res.getString(R.string.backup_full_sync_from_server_question)); builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sync("download", mSyncMediaUsn); } }); builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { showDialog(DIALOG_ERROR_HANDLING); } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { showDialog(DIALOG_ERROR_HANDLING); } }); dialog = builder.create(); break; default: dialog = null; } if (dialog != null) { dialog.setOwnerActivity(this); } return dialog; }