Search in sources :

Example 11 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class ChartBuilder method getStatisticsDialog.

public static StyledDialog getStatisticsDialog(Context context, DialogInterface.OnClickListener listener, boolean showWholeDeckSelection) {
    StyledDialog.Builder builder = new StyledDialog.Builder(context);
    builder.setTitle(context.getString(R.string.statistics_type_title));
    builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
    // set items
    String[] items = new String[3];
    items[0] = context.getResources().getString(R.string.stats_forecast);
    items[1] = context.getResources().getString(R.string.stats_review_count);
    items[2] = context.getResources().getString(R.string.stats_review_time);
    builder.setItems(items, listener);
    // period selection
    final RadioButton[] statisticRadioButtons = new RadioButton[3];
    RadioGroup rg = new RadioGroup(context);
    rg.setOrientation(RadioGroup.HORIZONTAL);
    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
    Resources res = context.getResources();
    String[] text = res.getStringArray(R.array.stats_period);
    int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
    for (int i = 0; i < statisticRadioButtons.length; i++) {
        statisticRadioButtons[i] = new RadioButton(context);
        statisticRadioButtons[i].setClickable(true);
        statisticRadioButtons[i].setText("         " + text[i]);
        statisticRadioButtons[i].setHeight(height * 2);
        statisticRadioButtons[i].setSingleLine();
        statisticRadioButtons[i].setBackgroundDrawable(null);
        statisticRadioButtons[i].setGravity(Gravity.CENTER_VERTICAL);
        rg.addView(statisticRadioButtons[i], lp);
    }
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            int checked = arg0.getCheckedRadioButtonId();
            for (int i = 0; i < 3; i++) {
                if (arg0.getChildAt(i).getId() == checked) {
                    AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("statsType", i).commit();
                    break;
                }
            }
        }
    });
    rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
    statisticRadioButtons[Math.min(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), Stats.TYPE_LIFE)].setChecked(true);
    if (showWholeDeckSelection) {
        // collection/current deck
        final RadioButton[] statisticRadioButtons2 = new RadioButton[2];
        RadioGroup rg2 = new RadioGroup(context);
        rg2.setOrientation(RadioGroup.HORIZONTAL);
        String[] text2 = res.getStringArray(R.array.stats_range);
        for (int i = 0; i < statisticRadioButtons2.length; i++) {
            statisticRadioButtons2[i] = new RadioButton(context);
            statisticRadioButtons2[i].setClickable(true);
            statisticRadioButtons2[i].setText("         " + text2[i]);
            statisticRadioButtons2[i].setHeight(height * 2);
            statisticRadioButtons2[i].setSingleLine();
            statisticRadioButtons2[i].setBackgroundDrawable(null);
            statisticRadioButtons2[i].setGravity(Gravity.CENTER_VERTICAL);
            rg2.addView(statisticRadioButtons2[i], lp);
        }
        rg2.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup arg0, int arg1) {
                AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putBoolean("statsRange", arg0.getCheckedRadioButtonId() == arg0.getChildAt(0).getId()).commit();
            }
        });
        rg2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
        statisticRadioButtons2[AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean("statsRange", true) ? 0 : 1].setChecked(true);
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        ll.addView(rg);
        ll.addView(rg2);
        builder.setView(ll, false, true);
    } else {
        builder.setView(rg, false, true);
    }
    return builder.create();
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) StyledDialog(com.ichi2.themes.StyledDialog) RadioButton(android.widget.RadioButton) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 12 with Builder

use of com.ichi2.themes.StyledDialog.Builder 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 13 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class Feedback method initAllAlertDialogs.

/**
     * Create AlertDialogs used on all the activity
     */
private void initAllAlertDialogs() {
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    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), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mPostingFeedback = false;
            refreshInterface();
        }
    });
    mNoConnectionAlert = builder.create();
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Resources(android.content.res.Resources)

Example 14 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class Info method upgradeCancelled.

public void upgradeCancelled() {
    StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
    builder.setTitle(getString(R.string.upgrade_deck_cancelled_title));
    builder.setIcon(R.drawable.ic_dialog_alert);
    builder.setMessage(getString(R.string.upgrade_deck_cancelled_description));
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            Intent result = new Intent();
            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
            setResult(RESULT_OK, result);
            finishWithAnimation();
        }
    });
    builder.show();
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent)

Example 15 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class CardEditor method createDialogIntentInformation.

private StyledDialog createDialogIntentInformation(Builder builder, Resources res) {
    builder.setTitle(res.getString(R.string.intent_add_saved_information));
    ListView listView = new ListView(this);
    mIntentInformationAdapter = new SimpleAdapter(this, mIntentInformation, R.layout.card_item, new String[] { "source", "target", "id" }, new int[] { R.id.card_sfld, R.id.card_tmpl, R.id.card_item });
    listView.setAdapter(mIntentInformationAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(CardEditor.this, CardEditor.class);
            intent.putExtra(EXTRA_CALLER, CALLER_CARDEDITOR_INTENT_ADD);
            HashMap<String, String> map = mIntentInformation.get(position);
            intent.putExtra(EXTRA_CONTENTS, map.get("fields"));
            intent.putExtra(EXTRA_ID, map.get("id"));
            startActivityForResult(intent, REQUEST_INTENT_ADD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardEditor.this, ActivityTransitionAnimation.FADE);
            }
            mIntentInformationDialog.dismiss();
        }
    });
    mCardItemBackground = Themes.getCardBrowserBackground()[0];
    mIntentInformationAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                view.setBackgroundResource(mCardItemBackground);
                return true;
            }
            return false;
        }
    });
    listView.setBackgroundColor(android.R.attr.colorBackground);
    listView.setDrawSelectorOnTop(true);
    listView.setFastScrollEnabled(true);
    Themes.setContentStyle(listView, Themes.CALLER_CARDEDITOR_INTENTDIALOG);
    builder.setView(listView, false, true);
    builder.setCancelable(true);
    builder.setPositiveButton(res.getString(R.string.intent_add_clear_all), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            MetaDB.resetIntentInformation(CardEditor.this);
            mIntentInformation.clear();
            dialog.dismiss();
        }
    });
    StyledDialog dialog = builder.create();
    mIntentInformationDialog = dialog;
    return dialog;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) SimpleAdapter(android.widget.SimpleAdapter) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) OnClickListener(android.content.DialogInterface.OnClickListener) JSONObject(org.json.JSONObject)

Aggregations

StyledDialog (com.ichi2.themes.StyledDialog)18 DialogInterface (android.content.DialogInterface)17 Resources (android.content.res.Resources)12 Intent (android.content.Intent)8 JSONException (org.json.JSONException)7 JSONObject (org.json.JSONObject)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 TextView (android.widget.TextView)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 DeckTask (com.ichi2.async.DeckTask)3 SuppressLint (android.annotation.SuppressLint)2 Dialog (android.app.Dialog)2 OnCancelListener (android.content.DialogInterface.OnCancelListener)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 OnClickListener (android.view.View.OnClickListener)2 EditText (android.widget.EditText)2