use of com.ichi2.libanki.utils.Time in project Anki-Android by Ramblurr.
the class Feedback method postFeedback.
/**
* Posting feedback or error info to the server. This is called from the AsyncTask.
*
* @param url The url to post the feedback to.
* @param type The type of the info, eg Feedback.TYPE_CRASH_STACKTRACE.
* @param feedback For feedback types this is the message. For error/crash types this is the path to the error file.
* @param groupId A single time generated ID, so that errors/feedback send together can be grouped together.
* @param index The index of the error in the list
* @return A Payload file showing success, response code and response message.
*/
public static Payload postFeedback(String url, String type, String feedback, String groupId, int index, Application app) {
Payload result = new Payload(null);
List<NameValuePair> pairs = null;
if (!isErrorType(type)) {
pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("type", type));
pairs.add(new BasicNameValuePair("groupid", groupId));
pairs.add(new BasicNameValuePair("index", "0"));
pairs.add(new BasicNameValuePair("message", feedback));
addTimestamp(pairs);
} else {
pairs = Feedback.extractPairsFromError(type, feedback, groupId, index, app);
if (pairs == null) {
result.success = false;
result.result = null;
}
}
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("User-Agent", "AnkiDroid");
try {
httpPost.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = httpClient.execute(httpPost);
Log.e(AnkiDroidApp.TAG, String.format("Bug report posted to %s", url));
int respCode = response.getStatusLine().getStatusCode();
switch(respCode) {
case 200:
result.success = true;
result.returnType = respCode;
result.result = Utils.convertStreamToString(response.getEntity().getContent());
// Log.i(AnkiDroidApp.TAG, String.format("postFeedback OK: %s", result.result));
break;
default:
Log.e(AnkiDroidApp.TAG, String.format("postFeedback failure: %d - %s", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
result.success = false;
result.returnType = respCode;
result.result = response.getStatusLine().getReasonPhrase();
break;
}
} catch (ClientProtocolException ex) {
Log.e(AnkiDroidApp.TAG, "ClientProtocolException: " + ex.toString());
result.success = false;
result.result = ex.toString();
} catch (IOException ex) {
Log.e(AnkiDroidApp.TAG, "IOException: " + ex.toString());
result.success = false;
result.result = ex.toString();
}
return result;
}
use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method configMaxDayLearnAndRev.
private void configMaxDayLearnAndRev() {
CustomStyleDialog customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("设置每天学习量").setCustomLayout(R.layout.dialog_common_custom_next).setMultiEditorModeCallback(new CustomStyleDialog.Builder.MultiEditorModeCallback() {
@Override
public String[] getEditorText() {
// return new String[] {mOptions.getJSONObject("new").getString("perDay"), mOptions.getJSONObject("rev").getString("perDay"),};
return new String[] { "30", "200" };
}
@Override
public String[] getEditorHint() {
return new String[] { "每天新卡上限", "每天复习上限" };
}
@Override
public String[] getItemHint() {
return new String[] { "学习一段时间后,未来每天新卡+复习卡约180张,大约需30分钟", "建议设置为最大9999,有多少复习多少" };
}
}).addSingleTextChangedListener(new CustomStyleDialog.Builder.MyTextWatcher() {
@Override
public void beforeTextChanged(Dialog dialog, CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(Dialog dialog, CharSequence s, int start, int before, int count) {
if (s.toString().isEmpty()) {
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText("未来每天学习量=新卡数x6");
} else {
int num = 0;
try {
num = Integer.parseInt(s.toString()) * 6;
} catch (Exception ignored) {
}
int time = num * 10 / 60;
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText(String.format("学习一段时间后,未来每天新卡+复习卡约%s张,大约需%s分钟", num, time));
}
}
@Override
public void afterTextChanged(Dialog dialog, Editable s) {
}
}).setPositiveButton("进入学习", (dialog, which) -> {
String text1 = ((CustomStyleDialog) dialog).getMultiEditor().get(0).getText().toString();
String text2 = ((CustomStyleDialog) dialog).getMultiEditor().get(1).getText().toString();
int maxNewCard = 0;
int maxRevCard = 0;
try {
maxNewCard = Integer.parseInt(text1);
} catch (Exception ignored) {
}
try {
maxRevCard = Integer.parseInt(text2);
} catch (Exception ignored) {
}
if (maxNewCard >= 0 && maxNewCard <= 9999 && maxRevCard >= 0 && maxRevCard <= 9999) {
mOptions.getJSONObject("new").put("perDay", maxNewCard);
mOptions.getJSONObject("rev").put("perDay", maxRevCard);
Timber.i("edit new and rev max:" + maxNewCard + "," + maxRevCard);
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
dialog.dismiss();
openReviewerInternal();
} else {
UIUtils.showThemedToast(getAnkiActivity(), "请填写0至9999之间的数值", false);
}
}).setNegativeButton("跳过", (dialog, which) -> {
dialog.dismiss();
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
openReviewerInternal();
}).create();
customDialog.show();
}
use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.
the class ReadText method initializeTts.
public static String initializeTts(Context context, boolean vipSpeak, boolean showToast, ReadTextListener listener) {
// Store weak reference to Activity to prevent memory leak
mReviewer = new WeakReference<>(context);
// Create new TTS object and setup its onInit Listener
mTts = new TextToSpeech(context, status -> {
if (status == TextToSpeech.SUCCESS) {
// build list of available languages
buildAvailableLanguages(TextToSpeech.LANG_AVAILABLE);
if (availableTtsLocales.size() > 0) {
// notify the reviewer that TTS has been initialized
Timber.d("TTS initialized and available languages found");
if (listener != null) {
listener.ttsInitialized();
}
// ((AbstractFlashcardViewer) mReviewer.get()).ttsInitialized();
} else {
if (showToast) {
Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show();
}
Timber.w("TTS initialized but no available languages found");
}
mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String arg0) {
if (ReadText.sTextQueue.size() > 0) {
String[] text = ReadText.sTextQueue.remove(0);
ReadText.speak(text[0], text[1], TextToSpeech.QUEUE_FLUSH);
}
if (listener != null) {
listener.onDone();
}
}
@Override
@Deprecated
public void onError(String utteranceId) {
Timber.v("Andoid TTS failed. Check logcat for error. Indicates a problem with Android TTS engine.");
final Uri helpUrl = Uri.parse(mReviewer.get().getString(R.string.link_faq_tts));
final AnkiActivity ankiActivity = (AnkiActivity) mReviewer.get();
ankiActivity.mayOpenUrl(helpUrl);
if (showToast) {
UIUtils.showSnackbar(ankiActivity, R.string.no_tts_available_message, false, R.string.help, v -> openTtsHelpUrl(helpUrl), ankiActivity.findViewById(R.id.root_layout), new Snackbar.Callback());
}
}
@Override
public void onStart(String arg0) {
// no nothing
}
});
} else {
if (showToast) {
Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show();
}
Timber.w("TTS not successfully initialized");
}
});
// Show toast that it's getting initialized, as it can take a while before the sound plays the first time
if (showToast) {
Toast.makeText(context, context.getString(R.string.initializing_tts), Toast.LENGTH_LONG).show();
}
return mTts.getDefaultEngine();
}
use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.
the class StudySettingActivity method onClick.
@Override
public void onClick(View v) {
int id = v.getId();
CustomStyleDialog customDialog = null;
switch(id) {
case R.id.rl_max_learn_card:
customDialog = new CustomStyleDialog.Builder(this).setTitle("每日新卡上限").setEditorText(tx_max_learn_card.getText().toString(), "学习一段时间后,未来每天新卡+复习卡约180张,大约需30分钟").addSingleTextChangedListener(new CustomStyleDialog.Builder.MyTextWatcher() {
@Override
public void beforeTextChanged(Dialog dialog, CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(Dialog dialog, CharSequence s, int start, int before, int count) {
if (s.toString().isEmpty()) {
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText("未来每天学习量=新卡数x6");
} else {
try {
int num = Integer.parseInt(s.toString()) * 6;
int time = num * 10 / 60;
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText(String.format("学习一段时间后,未来每天新卡+复习卡约%s张,大约需%s分钟", num, time));
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(StudySettingActivity.this, "请填写0至9999之间的数值", false);
}
}
}
@Override
public void afterTextChanged(Dialog dialog, Editable s) {
}
}).setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 0 && num <= 9999) {
mOptions.getJSONObject("new").put("perDay", num);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写0至9999之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写0至9999之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_max_review_card:
customDialog = new CustomStyleDialog.Builder(this).setTitle("每日复习数上限").setEditorText(tx_max_review_card.getText().toString(), "建议设置为最大9999,有多少复习多少").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 0 && num <= 9999) {
mOptions.getJSONObject("rev").put("perDay", num);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写0至9999之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写0至9999之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_deck_conf_max_ivl:
customDialog = new CustomStyleDialog.Builder(this).setTitle("最大时间间隔").setEditorText(tx_max_review_card.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 0 && num <= 99999) {
mOptions.getJSONObject("rev").put("maxIvl", num);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写0至99999之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写0至99999之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_interval_step:
customDialog = new CustomStyleDialog.Builder(this).setTitle("间隔的步伐(以分钟计)").setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT).setEditorText(tx_interval_step.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
String num = ((CustomStyleDialog) dialog).getEditorText();
String validated = getValidatedStepsInput(num);
if (validated == null) {
UIUtils.showThemedToast(this, getResources().getString(R.string.steps_error), false);
} else if (TextUtils.isEmpty(validated)) {
UIUtils.showThemedToast(this, getResources().getString(R.string.steps_min_error), false);
} else {
mOptions.getJSONObject("new").put("delays", convertToJSON(num));
saveAndUpdateValues();
Timber.i("edit num:%s", num);
dialog.dismiss();
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_interval_graduate:
customDialog = new CustomStyleDialog.Builder(this).setTitle("毕业时间间隔(以天计)").setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT).setEditorText(tx_interval_graduate.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 1 && num <= 99) {
// [graduating, easy]
JSONArray newInts = new JSONArray();
newInts.put(num);
newInts.put(mOptions.getJSONObject("new").getJSONArray("ints").getInt(1));
mOptions.getJSONObject("new").put("ints", newInts);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_interval_simple:
customDialog = new CustomStyleDialog.Builder(this).setTitle("简单按钮对应的时间间隔").setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT).setEditorText(tx_interval_simple.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 1 && num <= 99) {
JSONArray newInts = new JSONArray();
//
newInts.put(mOptions.getJSONObject("new").getJSONArray("ints").getInt(0));
newInts.put(num);
mOptions.getJSONObject("new").put("ints", newInts);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_init_level:
customDialog = new CustomStyleDialog.Builder(this).setTitle("初始难度").setEditorText(tx_init_level.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 100 && num <= 999) {
mOptions.getJSONObject("new").put("initialFactor", num * 10);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写100至999之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_new_card_sequence:
final int[] selectPosition = { mCurrentNewOrderValue };
customDialog = new CustomStyleDialog.Builder(this).setTitle("新卡顺序").setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {
@Override
public String[] getItemContent() {
return mNewOrderLabels;
}
@Override
public String[] getItemHint() {
return new String[0];
}
@Override
public int getDefaultSelectedPosition() {
return selectPosition[0];
}
@Override
public void onItemSelect(int position) {
selectPosition[0] = position;
}
}).setPositiveButton("确认", (dialog, which) -> {
int oldValue = mOptions.getJSONObject("new").getInt("order");
if (oldValue != selectPosition[0]) {
mOptions.getJSONObject("new").put("order", selectPosition[0]);
CollectionTask.launchCollectionTask(REORDER, new ConfChangeHandler(StudySettingActivity.this), new TaskData(new Object[] { mOptions }));
}
dialog.dismiss();
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
customDialog.show();
break;
case R.id.rl_learn_sequence:
final int[] selectPosition3 = { mCurrentStudyPreferenceValue };
customDialog = new CustomStyleDialog.Builder(this).setTitle("学习顺序").setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {
@Override
public String[] getItemContent() {
return mStudyPreferenceLabels;
}
@Override
public String[] getItemHint() {
return new String[0];
}
@Override
public int getDefaultSelectedPosition() {
return selectPosition3[0];
}
@Override
public void onItemSelect(int position) {
selectPosition3[0] = position;
}
}).setPositiveButton("确认", (dialog, which) -> {
int oldValue = mCol.getConf().getInt("newSpread");
if (oldValue != selectPosition3[0]) {
mCol.getConf().put("newSpread", selectPosition3[0]);
mCol.setMod();
CollectionTask.launchCollectionTask(REORDER, new ConfChangeHandler(StudySettingActivity.this), new TaskData(new Object[] { mOptions }));
}
dialog.dismiss();
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
customDialog.show();
break;
case R.id.rl_medal_simple:
customDialog = new CustomStyleDialog.Builder(this).setTitle("回答简单的时间间隔增加比例").setEditorText(tx_medal_simple.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 100 && num <= 1000) {
mOptions.getJSONObject("rev").put("ease4", (Integer) num / 100.0f);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写100至1000之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写100至1000之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_interval_decoration:
customDialog = new CustomStyleDialog.Builder(this).setTitle("时间间隔因子").setEditorText(tx_interval_decoration.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num: " + num / 100.0f);
if (num >= 0 && num <= 999) {
mOptions.getJSONObject("rev").put("ivlFct", num / 100.0f);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写0至999之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写0至999之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_error_interval_step:
customDialog = new CustomStyleDialog.Builder(this).setTitle("间隔的步伐(以分钟计)").setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT).setEditorText(tx_error_interval_step.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
String num = ((CustomStyleDialog) dialog).getEditorText();
String validated = getValidatedStepsInput(num);
if (validated == null) {
UIUtils.showThemedToast(this, getResources().getString(R.string.steps_error), false);
} else {
mOptions.getJSONObject("lapse").put("delays", StepsPreference.convertToJSON(num));
saveAndUpdateValues();
Timber.i("edit num:%s", num);
dialog.dismiss();
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_error_new_interval:
customDialog = new CustomStyleDialog.Builder(this).setTitle("新的时间间隔").setEditorText(tx_error_new_interval.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 0 && num <= 100) {
mOptions.getJSONObject("lapse").put("mult", num / 100.0f);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写0至100之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写0至100之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.rl_error_min_interval:
customDialog = new CustomStyleDialog.Builder(this).setTitle("最小时间间隔(天)").setEditorText(tx_error_min_interval.getText().toString(), "").setPositiveButton("确认", (dialog, which) -> {
try {
int num = Integer.parseInt(((CustomStyleDialog) dialog).getEditorText());
Timber.i("edit num:%s", num);
if (num >= 1 && num <= 99) {
mOptions.getJSONObject("lapse").put("minInt", num);
saveAndUpdateValues();
dialog.dismiss();
} else {
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
} catch (Exception e) {
e.printStackTrace();
UIUtils.showThemedToast(this, "请填写1至99之间的数值", false);
}
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
Timber.i("build a dialog!");
customDialog.show();
break;
case R.id.ll_algorithm:
final int[] selectPosition4 = { mCurrentMindModeValue };
customDialog = new CustomStyleDialog.Builder(this).setTitle("选择记忆模式").setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {
@Override
public String[] getItemContent() {
return mMindModeLabels;
}
@Override
public String[] getItemHint() {
return mMindModeHints;
}
@Override
public int getDefaultSelectedPosition() {
return selectPosition4[0];
}
@Override
public void onItemSelect(int position) {
selectPosition4[0] = position;
}
}).setPositiveButton("确认", (dialog, which) -> {
SharedPreferences sharedPreferences = getSharedPreferences(STUDY_SETTING, 0);
String oldValue = sharedPreferences.getString(KEY_MIND_MODE, "");
// Timber.i("看看保存成什么样子了 %s ", oldValue);
Map<String, Integer> oldMap = null;
Gson gson = new Gson();
try {
oldMap = gson.fromJson(oldValue, Map.class);
} catch (Exception e) {
e.printStackTrace();
}
if (oldMap == null) {
oldMap = new HashMap<>();
}
for (long did : getDeckIds(mDeckId, getCol())) {
// Timber.i("看看都是什么id %s,%s", did, selectPosition4[0]);
oldMap.put(String.valueOf(did), selectPosition4[0]);
}
String newValue = gson.toJson(oldMap);
sharedPreferences.edit().putString(KEY_MIND_MODE, newValue).apply();
mSavedMaxNewCardNum = mOptions.getJSONObject("new").getInt("perDay");
mSavedMaxRevCardNum = mOptions.getJSONObject("rev").getInt("perDay");
CollectionTask.launchCollectionTask(CONF_RESET, new ConfChangeHandler(StudySettingActivity.this, selectPosition4[0]), // 先恢复默认,即长记模式
new TaskData(new Object[] { mOptions }));
dialog.dismiss();
}).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
customDialog.show();
break;
}
}
use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.
the class ModelFieldEditor method renameFieldDialog.
/*
* Creates a dialog to rename the currently selected field
* Processing time is constant
*/
private void renameFieldDialog() {
mFieldNameInput = new EditText(this);
mFieldNameInput.setSingleLine(true);
mFieldNameInput.setText(mFieldLabels.get(mCurrentPos));
mFieldNameInput.setSelection(mFieldNameInput.getText().length());
new MaterialDialog.Builder(this).title(R.string.rename_model).positiveText(R.string.rename).customView(mFieldNameInput, true).onPositive((dialog, which) -> {
String fieldLabel = mFieldNameInput.getText().toString().replaceAll("[\\n\\r]", "");
if (fieldLabel.length() == 0) {
UIUtils.showThemedToast(this, getResources().getString(R.string.toast_empty_name), true);
} else if (containsField(fieldLabel)) {
UIUtils.showThemedToast(this, getResources().getString(R.string.toast_duplicate_field), true);
} else {
// Field is valid, now rename
try {
renameField();
} catch (ConfirmModSchemaException e) {
// Handler mod schema confirmation
ConfirmationDialog c = new ConfirmationDialog();
c.setArgs(getResources().getString(R.string.full_sync_confirmation));
Runnable confirm = () -> {
mCol.modSchemaNoCheck();
try {
renameField();
} catch (ConfirmModSchemaException e1) {
// This should never be thrown
}
dismissContextMenu();
};
c.setConfirm(confirm);
c.setCancel(mConfirmDialogCancel);
ModelFieldEditor.this.showDialogFragment(c);
}
}
}).negativeText(R.string.dialog_cancel).show();
}
Aggregations