Search in sources :

Example 26 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by Ramblurr.

the class CardEditor method onCreateDialog.

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    switch(id) {
        case DIALOG_TAGS_SELECT:
            builder.setTitle(R.string.card_details_tags);
            builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (mAddNote) {
                        try {
                            JSONArray ja = new JSONArray();
                            for (String t : selectedTags) {
                                ja.put(t);
                            }
                            mCol.getModels().current().put("tags", ja);
                            mCol.getModels().setChanged();
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        mEditorNote.setTags(selectedTags);
                    }
                    mCurrentTags = selectedTags;
                    updateTags();
                }
            });
            builder.setNegativeButton(res.getString(R.string.cancel), null);
            mNewTagEditText = (EditText) new EditText(this);
            mNewTagEditText.setHint(R.string.add_new_tag);
            InputFilter filter = new InputFilter() {

                public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                    for (int i = start; i < end; i++) {
                        if (source.charAt(i) == ' ' || source.charAt(i) == ',') {
                            return "";
                        }
                    }
                    return null;
                }
            };
            mNewTagEditText.setFilters(new InputFilter[] { filter });
            ImageView mAddTextButton = new ImageView(this);
            mAddTextButton.setImageResource(R.drawable.ic_addtag);
            mAddTextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String tag = mNewTagEditText.getText().toString();
                    if (tag.length() != 0) {
                        if (mEditorNote.hasTag(tag)) {
                            mNewTagEditText.setText("");
                            return;
                        }
                        selectedTags.add(tag);
                        actualizeTagDialog(mTagsDialog);
                        mNewTagEditText.setText("");
                    }
                }
            });
            FrameLayout frame = new FrameLayout(this);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            params.rightMargin = 10;
            mAddTextButton.setLayoutParams(params);
            frame.addView(mNewTagEditText);
            frame.addView(mAddTextButton);
            builder.setView(frame, false, true);
            dialog = builder.create();
            mTagsDialog = dialog;
            break;
        case DIALOG_DECK_SELECT:
            ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>();
            // Use this array to know which ID is associated with each
            // Item(name)
            final ArrayList<Long> dialogDeckIds = new ArrayList<Long>();
            ArrayList<JSONObject> decks = mCol.getDecks().all();
            Collections.sort(decks, new JSONNameComparator());
            builder.setTitle(R.string.deck);
            for (JSONObject d : decks) {
                try {
                    if (d.getInt("dyn") == 0) {
                        dialogDeckItems.add(d.getString("name"));
                        dialogDeckIds.add(d.getLong("id"));
                    }
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }
            // Convert to Array
            String[] items = new String[dialogDeckItems.size()];
            dialogDeckItems.toArray(items);
            builder.setItems(items, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    long newId = dialogDeckIds.get(item);
                    if (mCurrentDid != newId) {
                        if (mAddNote) {
                            try {
                                // TODO: mEditorNote.setDid(newId);
                                mEditorNote.model().put("did", newId);
                                mCol.getModels().setChanged();
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                        }
                        mCurrentDid = newId;
                        updateDeck();
                    }
                }
            });
            dialog = builder.create();
            mDeckSelectDialog = dialog;
            break;
        case DIALOG_MODEL_SELECT:
            ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
            // Use this array to know which ID is associated with each
            // Item(name)
            final ArrayList<Long> dialogIds = new ArrayList<Long>();
            ArrayList<JSONObject> models = mCol.getModels().all();
            Collections.sort(models, new JSONNameComparator());
            builder.setTitle(R.string.note_type);
            for (JSONObject m : models) {
                try {
                    dialogItems.add(m.getString("name"));
                    dialogIds.add(m.getLong("id"));
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }
            // Convert to Array
            String[] items2 = new String[dialogItems.size()];
            dialogItems.toArray(items2);
            builder.setItems(items2, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    long oldModelId;
                    try {
                        oldModelId = mCol.getModels().current().getLong("id");
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                    long newId = dialogIds.get(item);
                    if (oldModelId != newId) {
                        mCol.getModels().setCurrent(mCol.getModels().get(newId));
                        JSONObject cdeck = mCol.getDecks().current();
                        try {
                            cdeck.put("mid", newId);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        mCol.getDecks().save(cdeck);
                        int size = mEditFields.size();
                        String[] oldValues = new String[size];
                        for (int i = 0; i < size; i++) {
                            oldValues[i] = mEditFields.get(i).getText().toString();
                        }
                        setNote();
                        resetEditFields(oldValues);
                        mTimerHandler.removeCallbacks(checkDuplicatesRunnable);
                        duplicateCheck(false);
                    }
                }
            });
            dialog = builder.create();
            break;
        case DIALOG_RESET_CARD:
            builder.setTitle(res.getString(R.string.reset_card_dialog_title));
            builder.setMessage(res.getString(R.string.reset_card_dialog_message));
            builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // for (long cardId :
                // mDeck.getCardsFromFactId(mEditorNote.getId())) {
                // mDeck.cardFromId(cardId).resetCard();
                // }
                // mDeck.reset();
                // setResult(Reviewer.RESULT_EDIT_CARD_RESET);
                // mCardReset = true;
                // Themes.showThemedToast(CardEditor.this,
                // getResources().getString(
                // R.string.reset_card_dialog_confirmation), true);
                }
            });
            builder.setNegativeButton(res.getString(R.string.no), null);
            builder.setCancelable(true);
            dialog = builder.create();
            break;
        case DIALOG_INTENT_INFORMATION:
            dialog = createDialogIntentInformation(builder, res);
    }
    return dialog;
}
Also used : DialogInterface(android.content.DialogInterface) Builder(com.ichi2.themes.StyledDialog.Builder) StyledDialog(com.ichi2.themes.StyledDialog) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Spanned(android.text.Spanned) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OnClickListener(android.content.DialogInterface.OnClickListener) JSONObject(org.json.JSONObject) FrameLayout(android.widget.FrameLayout) Builder(com.ichi2.themes.StyledDialog.Builder) OnClickListener(android.content.DialogInterface.OnClickListener) Resources(android.content.res.Resources)

Example 27 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START 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();
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) TypeToken(com.google.gson.reflect.TypeToken) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Maps(java8.util.Maps) KEY_STOPPED(com.ichi2.anki.StudySettingActivity.KEY_STOPPED) DeckInfoListAdapter(com.ichi2.anki.widgets.DeckInfoListAdapter) Decks(com.ichi2.libanki.Decks) Gson(com.google.gson.Gson) Locale(java.util.Locale) Handler(android.os.Handler) DeckConfig(com.ichi2.libanki.DeckConfig) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) TaskData(com.ichi2.async.TaskData) RecyclerView(androidx.recyclerview.widget.RecyclerView) REQUEST_BROWSE_CARDS(com.ichi2.anki.DeckPicker.REQUEST_BROWSE_CARDS) TabLayout(com.google.android.material.tabs.TabLayout) TYPE_LIFE(com.ichi2.libanki.stats.Stats.AxisType.TYPE_LIFE) SHOW_STUDYOPTIONS(com.ichi2.anki.DeckPicker.SHOW_STUDYOPTIONS) Set(java.util.Set) FragmentTransaction(androidx.fragment.app.FragmentTransaction) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) DeckPickerContextMenu(com.ichi2.anki.dialogs.DeckPickerContextMenu) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) NextCardHandler(com.ichi2.anki.AbstractFlashcardViewer.NextCardHandler) ALL_DECKS_ID(com.ichi2.libanki.stats.Stats.ALL_DECKS_ID) CompatHelper(com.ichi2.compat.CompatHelper) Toolbar(androidx.appcompat.widget.Toolbar) RelativeLayout(android.widget.RelativeLayout) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) Snackbar(com.google.android.material.snackbar.Snackbar) DialogFragment(androidx.fragment.app.DialogFragment) KEY_SHOW_TTS_ICON(com.ichi2.libanki.Consts.KEY_SHOW_TTS_ICON) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) Dialog(android.app.Dialog) Intent(android.content.Intent) StepsPreference.convertToJSON(com.ichi2.preferences.StepsPreference.convertToJSON) HashMap(java.util.HashMap) Collection(com.ichi2.libanki.Collection) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) PixelFormat(android.graphics.PixelFormat) Editable(android.text.Editable) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) ArrayList(java.util.ArrayList) JSONArray(com.ichi2.utils.JSONArray) Menu(android.view.Menu) Utils(com.ichi2.libanki.Utils) AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode) Stats(com.ichi2.libanki.stats.Stats) LayoutInflater(android.view.LayoutInflater) CollectionTask(com.ichi2.async.CollectionTask) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) TreeMap(java.util.TreeMap) KEY_MIND_MODE(com.ichi2.anki.StudySettingActivity.KEY_MIND_MODE) CustomStudyDialog(com.ichi2.anki.dialogs.CustomStudyDialog) DeckPicker.fadeOut(com.ichi2.anki.DeckPicker.fadeOut) Activity(android.app.Activity) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) DeckPicker.fadeIn(com.ichi2.anki.DeckPicker.fadeIn) STUDY_SETTING(com.ichi2.anki.StudySettingActivity.STUDY_SETTING) EditText(android.widget.EditText) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Resources(android.content.res.Resources) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) CustomStudyDialog(com.ichi2.anki.dialogs.CustomStudyDialog) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Editable(android.text.Editable)

Example 28 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project AnkiChinaAndroid by ankichinateam.

the class Reviewer method onCollectionLoaded.

@Override
protected void onCollectionLoaded(Collection col) {
    super.onCollectionLoaded(col);
    // Load the first card and start reviewing. Uses the answer card
    // task to load a card, but since we send null
    // as the card to answer, no card will be answered.
    mPrefWhiteboard = MetaDB.getWhiteboardState(this, getParentDid());
    if (mPrefWhiteboard) {
        // DEFECT: Slight inefficiency here, as we set the database using these methods
        boolean whiteboardVisibility = MetaDB.getWhiteboardVisibility(this, getParentDid());
        setWhiteboardEnabledState(true);
        setWhiteboardVisibility(whiteboardVisibility);
    }
    // Reset schedule in case card was previously loaded
    col.getSched().deferReset();
    getCol().startTimebox();
    CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false), new TaskData(null, 0));
    disableDrawerSwipeOnConflicts();
    // Add a weak reference to current activity so that scheduler can talk to to Activity
    mSched.setContext(new WeakReference<Activity>(this));
    // Set full screen/immersive mode if needed
    if (mPrefFullscreenReview) {
        CompatHelper.getCompat().setFullScreen(this);
    }
}
Also used : Activity(android.app.Activity) TaskData(com.ichi2.async.TaskData)

Example 29 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method showCustomStudyDialog.

private void showCustomStudyDialog(Collection col) {
    // 1、使用Dialog、设置style
    // if (mCloudCustomDialog == null) {
    mCustomStudyDialog = new Dialog(getAnkiActivity());
    // 2、设置布局
    View view = View.inflate(getAnkiActivity(), R.layout.custom_study_dialog, null);
    mCustomStudyDialog.setContentView(view);
    Window window = mCustomStudyDialog.getWindow();
    // mCustomStudyDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
    // 设置弹出位置
    window.setGravity(Gravity.CENTER);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    EditText addNewEditor = mCustomStudyDialog.findViewById(R.id.add_new_card);
    EditText addRevEditor = mCustomStudyDialog.findViewById(R.id.add_rev_card);
    int totalNew = col.getSched().totalNewForCurrentDeck();
    int totalRev = col.getSched().totalRevForCurrentDeck();
    ((TextView) mCustomStudyDialog.findViewById(R.id.content)).setText(String.format(getAnkiActivity().getString(R.string.custom_study_dialog_content), totalNew, totalRev));
    Button start = mCustomStudyDialog.findViewById(R.id.start);
    if (totalNew + totalRev == 0) {
        start.setEnabled(false);
        start.setText("今日已无待学习的卡牌");
    } else {
        start.setOnClickListener(view1 -> {
            int addNew = 0;
            try {
                addNew = Integer.parseInt(addNewEditor.getText().toString());
            } catch (Exception ignored) {
            }
            int addRev = 0;
            try {
                addRev = Integer.parseInt(addRevEditor.getText().toString());
            } catch (Exception ignored) {
            }
            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", addNew).apply();
            Deck deck = col.getDecks().current();
            deck.put("extendNew", addNew);
            col.getDecks().save(deck);
            col.getSched().extendLimits(addNew, 0);
            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", addRev).apply();
            deck.put("extendRev", addRev);
            col.getDecks().save(deck);
            col.getSched().extendLimits(0, addRev);
            refreshInterface();
            getAnkiActivity().startActivityForResultWithoutAnimation(new Intent(getAnkiActivity(), Reviewer.class), AnkiActivity.REQUEST_REVIEW);
            mCustomStudyDialog.dismiss();
        });
    }
    mCustomStudyDialog.setCanceledOnTouchOutside(true);
    mCustomStudyDialog.setCancelable(true);
    mCustomStudyDialog.show();
}
Also used : Window(android.view.Window) EditText(android.widget.EditText) ColorDrawable(android.graphics.drawable.ColorDrawable) Button(android.widget.Button) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) CustomStudyDialog(com.ichi2.anki.dialogs.CustomStudyDialog) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Deck(com.ichi2.libanki.Deck) TextView(android.widget.TextView) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 30 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START 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;
    }
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) KeyEvent(android.view.KeyEvent) TypeToken(com.google.gson.reflect.TypeToken) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) Dialog(android.app.Dialog) HashMap(java.util.HashMap) StepsPreference.convertToJSON(com.ichi2.preferences.StepsPreference.convertToJSON) Collection(com.ichi2.libanki.Collection) Editable(android.text.Editable) TypedArray(android.content.res.TypedArray) JSONArray(com.ichi2.utils.JSONArray) StepsPreference(com.ichi2.preferences.StepsPreference) Gson(com.google.gson.Gson) DeckConfig(com.ichi2.libanki.DeckConfig) Map(java.util.Map) View(android.view.View) TaskData(com.ichi2.async.TaskData) ContextCompat(androidx.core.content.ContextCompat) REORDER(com.ichi2.async.CollectionTask.TASK_TYPE.REORDER) InputType(android.text.InputType) TextUtils(android.text.TextUtils) CollectionTask(com.ichi2.async.CollectionTask) JSONObject(com.ichi2.utils.JSONObject) Timber(timber.log.Timber) StudyOptionsFragment.getDeckIds(com.ichi2.anki.StudyOptionsFragment.getDeckIds) IdRes(androidx.annotation.IdRes) CONF_RESET(com.ichi2.async.CollectionTask.TASK_TYPE.CONF_RESET) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) JSONArray(com.ichi2.utils.JSONArray) Gson(com.google.gson.Gson) TaskData(com.ichi2.async.TaskData) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Dialog(android.app.Dialog) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Editable(android.text.Editable) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Test (org.junit.Test)23 Intent (android.content.Intent)21 JSONObject (com.ichi2.utils.JSONObject)17 Model (com.ichi2.libanki.Model)14 View (android.view.View)13 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)12 Collection (com.ichi2.libanki.Collection)11 Note (com.ichi2.libanki.Note)9 File (java.io.File)9 JSONArray (com.ichi2.utils.JSONArray)8 SharedPreferences (android.content.SharedPreferences)7 TextView (android.widget.TextView)7 EditText (android.widget.EditText)6 Deck (com.ichi2.libanki.Deck)6 Dialog (android.app.Dialog)5 NonNull (androidx.annotation.NonNull)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)5 RobolectricTest (com.ichi2.anki.RobolectricTest)5 TaskData (com.ichi2.async.TaskData)5