Example usage for android.content.res Resources getStringArray

List of usage examples for android.content.res Resources getStringArray

Introduction

In this page you can find the example usage for android.content.res Resources getStringArray.

Prototype

@NonNull
public String[] getStringArray(@ArrayRes int id) throws NotFoundException 

Source Link

Document

Return the string array associated with a particular resource ID.

Usage

From source file:com.google.android.apps.santatracker.launch.StartupActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu
    getMenuInflater().inflate(R.menu.menu_startup, menu);

    // Add cast button
    if (mCastManager != null) {
        mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item);
    }/*from   ww  w. j  a v a2 s.  co m*/

    mMenuItemLegal = menu.findItem(R.id.legal);
    mMenuItemLegal.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Resources resources = getResources();
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(StartupActivity.this);
            dialogBuilder.setItems(resources.getStringArray(R.array.legal_privacy),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            String url;
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(StartupActivity.this);
                            switch (which) {
                            case 1:
                                // Privacy
                                url = resources.getString(R.string.url_privacy);
                                break;
                            case 2:
                                // TOS
                                url = resources.getString(R.string.url_tos);
                                break;
                            case 3:
                                // TOS
                                url = resources.getString(R.string.url_seismic);
                                break;
                            case 4:
                                // Show play services license text
                                dialog.dismiss();
                                dialogBuilder
                                        .setMessage(GooglePlayServicesUtil
                                                .getOpenSourceSoftwareLicenseInfo(getApplicationContext()))
                                        .create().show();
                                dialogBuilder.setPositiveButton(android.R.string.ok,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.dismiss();
                                            }
                                        });
                                return;
                            case 0:
                            default:
                                url = resources.getString(R.string.url_legal);
                                break;
                            }
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        }
                    });
            dialogBuilder.create().show();
            return true;
        }
    });

    menu.findItem(R.id.menu_app_invite).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            mInvitesFragment.sendGenericInvite();
            return true;
        }
    });

    menu.findItem(R.id.open_help).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_help))));
            return true;
        }
    });

    menu.findItem(R.id.github_santa).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_github_santa))));
            return true;
        }
    });

    menu.findItem(R.id.github_pienoon).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_github_pienoon))));
            return true;
        }
    });

    menu.findItem(R.id.sign_out).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Games.signOut(mGamesFragment.getGamesApiClient());
            updateSignInState(false);
            return true;
        }
    });

    // TODO Temp menu items for testing notifications
    menu.findItem(R.id.notification_nearby).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            SantaNotificationBuilder.CreateSantaNotification(StartupActivity.this,
                    R.string.notification_nearby);
            /*
            Intent wearIntent = new Intent(StartupActivity.this,
                    PhoneNotificationService.class);
            wearIntent.setAction(NotificationConstants.ACTION_SEND);
            wearIntent.putExtra(NotificationConstants.KEY_CONTENT,
                    StartupActivity.this.getResources()
                            .getString(R.string.notification_nearby));
            StartupActivity.this.startService(wearIntent);
            */
            return true;
        }
    });
    menu.findItem(R.id.notification_takeoff).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            SantaNotificationBuilder.CreateSantaNotification(StartupActivity.this,
                    R.string.notification_takeoff);
            /*
            Intent wearIntent = new Intent(StartupActivity.this,
                    PhoneNotificationService.class);
            wearIntent.setAction(NotificationConstants.ACTION_SEND);
            wearIntent.putExtra(NotificationConstants.KEY_CONTENT,
                    StartupActivity.this.getResources()
                            .getString(R.string.notification_takeoff));
            StartupActivity.this.startService(wearIntent);
            */
            return true;
        }
    });
    menu.findItem(R.id.notification_location)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    /*
                    SantaNotificationBuilder
                            .CreateTriviaNotification(StartupActivity.this, "location",
                                    "photoUrl", "mapUrl", "fact");
                    */
                    SantaNotificationBuilder.CreateInfoNotification(StartupActivity.this, "Title", "text",
                            "https://www.google.com/images/srpr/logo11w.png");
                    return true;
                }
            });

    menu.findItem(R.id.launch_mode).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            enableTrackerMode(true);
            return true;
        }
    });

    menu.findItem(R.id.countdown_mode).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            startCountdown(OFFLINE_SANTA_DEPARTURE);
            return true;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:com.ichi2.anki2.StudyOptionsFragment.java

private void onPrepareDialog(int id, StyledDialog styledDialog) {
    Resources res = getResources();
    switch (id) {
    case DIALOG_CUSTOM_STUDY_DETAILS:
        styledDialog.setTitle(res.getStringArray(R.array.custom_study_options_labels)[mCustomDialogChoice]);
        switch (mCustomDialogChoice + 1) {
        case CUSTOM_STUDY_NEW:
            if (AnkiDroidApp.colIsOpen()) {
                Collection col = AnkiDroidApp.getCol();
                mCustomStudyTextView1.setText(res.getString(R.string.custom_study_new_total_new,
                        col.getSched().totalNewForCurrentDeck()));
            }//w  ww.java  2 s .  c  o  m
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_new_extend));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendNew", 10)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n)
                                            .commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendNew", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(n, 0);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_REV:
            if (AnkiDroidApp.colIsOpen()) {
                Collection col = AnkiDroidApp.getCol();
                mCustomStudyTextView1.setText(res.getString(R.string.custom_study_rev_total_rev,
                        col.getSched().totalRevForCurrentDeck()));
            }
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_rev_extend));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendRev", 10)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n)
                                            .commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendRev", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(0, n);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_FORGOT:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_forgotten));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("forgottenDays", 2)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            int forgottenDays = Integer
                                    .parseInt(((EditText) mCustomStudyEditText).getText().toString());
                            JSONArray ar = new JSONArray();
                            try {
                                ar.put(0, 1);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            createFilteredDeck(ar,
                                    new Object[] { String.format(Locale.US, "rated:%d:1", forgottenDays), 9999,
                                            Sched.DYN_RANDOM },
                                    false);
                        }
                    });
            break;

        case CUSTOM_STUDY_AHEAD:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_ahead));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("aheadDays", 1)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            int days = Integer.parseInt(((EditText) mCustomStudyEditText).getText().toString());
                            createFilteredDeck(new JSONArray(), new Object[] {
                                    String.format(Locale.US, "prop:due<=%d", days), 9999, Sched.DYN_DUE },
                                    true);
                        }
                    });
            break;

        case CUSTOM_STUDY_RANDOM:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_random));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("randomCards", 100)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            int randomCards = Integer
                                    .parseInt(((EditText) mCustomStudyEditText).getText().toString());
                            createFilteredDeck(new JSONArray(),
                                    new Object[] { "", randomCards, Sched.DYN_RANDOM }, true);
                        }
                    });
            break;

        case CUSTOM_STUDY_PREVIEW:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_preview));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("previewDays", 1)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String previewDays = ((EditText) mCustomStudyEditText).getText().toString();
                            createFilteredDeck(new JSONArray(),
                                    new Object[] { "is:new added:" + previewDays, 9999, Sched.DYN_OLDEST },
                                    false);
                        }
                    });
            break;

        case CUSTOM_STUDY_TAGS:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_tags));
            mCustomStudyEditText
                    .setText(AnkiDroidApp.getSharedPrefs(getActivity()).getString("customTags", ""));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String tags = ((EditText) mCustomStudyEditText).getText().toString();
                            createFilteredDeck(new JSONArray(),
                                    new Object[] { "(is:new or is:due) " + tags, 9999, Sched.DYN_RANDOM },
                                    true);
                        }
                    });
            break;
        }
    }
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java

private void onPrepareDialog(int id, StyledDialog styledDialog) {
    Resources res = getResources();
    switch (id) {
    case DIALOG_CUSTOM_STUDY_DETAILS:
        styledDialog.setTitle(res.getStringArray(R.array.custom_study_options_labels)[mCustomDialogChoice]);
        switch (mCustomDialogChoice + 1) {
        case CUSTOM_STUDY_NEW:
            if (AnkiDroidApp.colIsOpen()) {
                Collection col = AnkiDroidApp.getCol();
                mCustomStudyTextView1.setText(res.getString(R.string.custom_study_new_total_new,
                        col.getSched().totalNewForCurrentDeck()));
            }/*  www  .j  a  v  a  2 s.  c om*/
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_new_extend));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendNew", 10)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n)
                                            .commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendNew", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(n, 0);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                    Themes.showThemedToast(getActivity().getBaseContext(),
                                            getResources().getString(R.string.custom_study_invalid_number),
                                            false);
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_REV:
            if (AnkiDroidApp.colIsOpen()) {
                Collection col = AnkiDroidApp.getCol();
                mCustomStudyTextView1.setText(res.getString(R.string.custom_study_rev_total_rev,
                        col.getSched().totalRevForCurrentDeck()));
            }
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_rev_extend));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendRev", 10)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n)
                                            .commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendRev", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(0, n);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                    Themes.showThemedToast(getActivity().getBaseContext(),
                                            getResources().getString(R.string.custom_study_invalid_number),
                                            false);
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_FORGOT:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_forgotten));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("forgottenDays", 2)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JSONArray ar = new JSONArray();
                            try {
                                int forgottenDays = Integer
                                        .parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                ar.put(0, 1);
                                createFilteredDeck(ar,
                                        new Object[] { String.format(Locale.US, "rated:%d:1", forgottenDays),
                                                9999, Sched.DYN_RANDOM },
                                        false);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(),
                                        getResources().getString(R.string.custom_study_invalid_number), false);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_AHEAD:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_ahead));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("aheadDays", 1)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                int days = Integer
                                        .parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                createFilteredDeck(new JSONArray(), new Object[] {
                                        String.format(Locale.US, "prop:due<=%d", days), 9999, Sched.DYN_DUE },
                                        true);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(),
                                        getResources().getString(R.string.custom_study_invalid_number), false);
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_RANDOM:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_random));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("randomCards", 100)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                int randomCards = Integer
                                        .parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                createFilteredDeck(new JSONArray(),
                                        new Object[] { "", randomCards, Sched.DYN_RANDOM }, true);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(),
                                        getResources().getString(R.string.custom_study_invalid_number), false);
                            }
                        }
                    });
            break;

        case CUSTOM_STUDY_PREVIEW:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_preview));
            mCustomStudyEditText.setText(
                    Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("previewDays", 1)));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String previewDays = ((EditText) mCustomStudyEditText).getText().toString();
                            createFilteredDeck(new JSONArray(),
                                    new Object[] { "is:new added:" + previewDays, 9999, Sched.DYN_OLDEST },
                                    false);
                        }
                    });
            break;

        case CUSTOM_STUDY_TAGS:
            mCustomStudyTextView1.setText("");
            mCustomStudyTextView2.setText(res.getString(R.string.custom_study_tags));
            mCustomStudyEditText
                    .setText(AnkiDroidApp.getSharedPrefs(getActivity()).getString("customTags", ""));
            styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String tags = ((EditText) mCustomStudyEditText).getText().toString();
                            createFilteredDeck(new JSONArray(),
                                    new Object[] { "(is:new or is:due) " + tags, 9999, Sched.DYN_RANDOM },
                                    true);
                        }
                    });
            break;
        }
    }
}

From source file:com.ichi2.anki2.CardBrowser.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;/*from w w  w. j  av a 2 s  .  c o m*/
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
    case DIALOG_ORDER:
        builder.setTitle(res.getString(R.string.card_browser_change_display_order_title));
        builder.setMessage(res.getString(R.string.card_browser_change_display_order_reverse));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
        builder.setSingleChoiceItems(res.getStringArray(R.array.card_browser_order_labels), mOrder,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int which) {
                        if (which != mOrder) {
                            mOrder = which;
                            mOrderAsc = false;
                            try {
                                if (mOrder == 0) {
                                    mCol.getConf().put("sortType", fSortTypes[1]);
                                    AnkiDroidApp.getSharedPrefs(getBaseContext()).edit()
                                            .putBoolean("cardBrowserNoSorting", true).commit();
                                } else {
                                    mCol.getConf().put("sortType", fSortTypes[mOrder]);
                                    AnkiDroidApp.getSharedPrefs(getBaseContext()).edit()
                                            .putBoolean("cardBrowserNoSorting", false).commit();
                                }
                                // default to descending for non-text fields
                                if (fSortTypes[mOrder].equals("noteFld")) {
                                    mOrderAsc = true;
                                }
                                mCol.getConf().put("sortBackwards", mOrderAsc);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            searchCards();
                        } else if (which != CARD_ORDER_NONE) {
                            mOrderAsc = !mOrderAsc;
                            try {
                                mCol.getConf().put("sortBackwards", mOrderAsc);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            Collections.reverse(mCards);
                            updateList();
                        }
                    }
                });
        dialog = builder.create();
        break;

    case DIALOG_CONTEXT_MENU:
        // FIXME:
        String[] entries = new String[4];
        @SuppressWarnings("unused")
        MenuItem item;
        entries[CONTEXT_MENU_MARK] = res.getString(R.string.card_browser_mark_card);
        entries[CONTEXT_MENU_SUSPEND] = res.getString(R.string.card_browser_suspend_card);
        entries[CONTEXT_MENU_DELETE] = res.getString(R.string.card_browser_delete_card);
        entries[CONTEXT_MENU_DETAILS] = res.getString(R.string.card_browser_card_details);
        builder.setTitle("contextmenu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

    case DIALOG_TAGS:
        allTags = mCol.getTags().all();
        builder.setTitle(R.string.studyoptions_limit_select_tags);
        builder.setMultiChoiceItems(allTags, new boolean[allTags.length],
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String tag = allTags[which];
                        if (mSelectedTags.contains(tag)) {
                            Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
                            mSelectedTags.remove(tag);
                        } else {
                            Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
                            mSelectedTags.add(tag);
                        }
                    }
                });
        builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSearchEditText.setText("");
                String tags = mSelectedTags.toString();
                mSearchEditText.setHint(getResources().getString(R.string.card_browser_tags_shown,
                        tags.substring(1, tags.length() - 1)));
                StringBuilder sb = new StringBuilder();
                for (String tag : mSelectedTags) {
                    sb.append("tag:").append(tag).append(" ");
                }
                mSearchTerms = sb.toString();
                searchCards();
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                mSelectedTags.clear();
            }
        });
        dialog = builder.create();
        break;
    // TODO(flerda@gmail.com): Fix card browser fields. See above.
    // https://code.google.com/p/ankidroid/issues/detail?id=1310
    /*
    case DIALOG_FIELD:
        builder.setTitle(res
                .getString(R.string.card_browser_field_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
            
        HashMap<String, String> card = mAllCards.get(0);
            
        String[][] items = mCol.getCard(Long.parseLong( card.get("id") )).note().items();
            
        mFields = new String[items.length+1];
        mFields[0]="SFLD";
            
        for (int i = 0; i < items.length; i++) {
            mFields[i+1] = items[i][0];
        }
            
        builder.setSingleChoiceItems(mFields, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int which) {
                if (which != mField) {
                    mField = which;
                    AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit()
                        .putInt("cardBrowserField", mField).commit();
                    getCards();
                }
            }
        });
        dialog = builder.create();
        break;
    */
    }
    return dialog;
}

From source file:com.hichinaschool.flashcards.anki.CardBrowser.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;//w ww .j  ava  2 s  .  c o m
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
    case DIALOG_ORDER:
        builder.setTitle(res.getString(R.string.card_browser_change_display_order_title));
        builder.setMessage(res.getString(R.string.card_browser_change_display_order_reverse));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
        builder.setSingleChoiceItems(res.getStringArray(R.array.card_browser_order_labels), mOrder,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int which) {
                        if (which != mOrder) {
                            mOrder = which;
                            mOrderAsc = false;
                            try {
                                if (mOrder == 0) {
                                    mCol.getConf().put("sortType", fSortTypes[1]);
                                    AnkiDroidApp.getSharedPrefs(getBaseContext()).edit()
                                            .putBoolean("cardBrowserNoSorting", true).commit();
                                } else {
                                    mCol.getConf().put("sortType", fSortTypes[mOrder]);
                                    AnkiDroidApp.getSharedPrefs(getBaseContext()).edit()
                                            .putBoolean("cardBrowserNoSorting", false).commit();
                                }
                                // default to descending for non-text fields
                                if (fSortTypes[mOrder].equals("noteFld")) {
                                    mOrderAsc = true;
                                }
                                mCol.getConf().put("sortBackwards", mOrderAsc);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            searchCards();
                        } else if (which != CARD_ORDER_NONE) {
                            mOrderAsc = !mOrderAsc;
                            try {
                                mCol.getConf().put("sortBackwards", mOrderAsc);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            Collections.reverse(mCards);
                            updateList();
                        }
                    }
                });
        dialog = builder.create();
        break;

    case DIALOG_CONTEXT_MENU:
        // FIXME:
        String[] entries = new String[4];
        @SuppressWarnings("unused")
        MenuItem item;
        entries[CONTEXT_MENU_MARK] = res.getString(R.string.card_browser_mark_card);
        entries[CONTEXT_MENU_SUSPEND] = res.getString(R.string.card_browser_suspend_card);
        entries[CONTEXT_MENU_DELETE] = res.getString(R.string.card_browser_delete_card);
        entries[CONTEXT_MENU_DETAILS] = res.getString(R.string.card_browser_card_details);
        builder.setTitle("contextmenu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

    case DIALOG_TAGS:
        allTags = mCol.getTags().all();
        builder.setTitle(R.string.studyoptions_limit_select_tags);
        builder.setMultiChoiceItems(allTags, new boolean[allTags.length],
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String tag = allTags[which];
                        if (mSelectedTags.contains(tag)) {
                            // Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
                            mSelectedTags.remove(tag);
                        } else {
                            // Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
                            mSelectedTags.add(tag);
                        }
                    }
                });
        builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSearchEditText.setText("");
                String tags = mSelectedTags.toString();
                mSearchEditText.setHint(getResources().getString(R.string.card_browser_tags_shown,
                        tags.substring(1, tags.length() - 1)));
                StringBuilder sb = new StringBuilder();
                for (String tag : mSelectedTags) {
                    sb.append("tag:").append(tag).append(" ");
                }
                mSearchTerms = sb.toString();
                searchCards();
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                mSelectedTags.clear();
            }
        });
        dialog = builder.create();
        break;
    // TODO(flerda@gmail.com): Fix card browser fields. See above.
    // https://code.google.com/p/ankidroid/issues/detail?id=1310
    /*
    case DIALOG_FIELD:
        builder.setTitle(res
                .getString(R.string.card_browser_field_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
            
        HashMap<String, String> card = mAllCards.get(0);
            
        String[][] items = mCol.getCard(Long.parseLong( card.get("id") )).note().items();
            
        mFields = new String[items.length+1];
        mFields[0]="SFLD";
            
        for (int i = 0; i < items.length; i++) {
            mFields[i+1] = items[i][0];
        }
            
        builder.setSingleChoiceItems(mFields, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int which) {
                if (which != mField) {
                    mField = which;
                    AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit()
                        .putInt("cardBrowserField", mField).commit();
                    getCards();
                }
            }
        });
        dialog = builder.create();
        break;
    */
    }
    return dialog;
}

From source file:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    //  Debug.startMethodTracing("calc");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*w ww  . j a  v  a 2 s  . com*/

    DPRatio = getResources().getDisplayMetrics().density;

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    Log.i(TAG, " max mem = " + maxMemory + "k");

    // set and get preferences in PreferenceActivity
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Set variable according to the preferences
    updatePreferenceSaved();

    textRMSChar = new char[getString(R.string.textview_RMS_text).length()];
    textCurChar = new char[getString(R.string.textview_cur_text).length()];
    textRecChar = new char[getString(R.string.textview_rec_text).length()];
    textPeakChar = new char[getString(R.string.textview_peak_text).length()];

    graphView = (AnalyzeView) findViewById(R.id.plot);

    // travel Views, and attach ClickListener to the views that contain android:tag="select"  
    visit((ViewGroup) graphView.getRootView(), new Visit() {
        @Override
        public void exec(View view) {
            view.setOnLongClickListener(AnalyzeActivity.this);
            view.setOnClickListener(AnalyzeActivity.this);
            ((TextView) view).setFreezesText(true);
        }
    }, "select");

    Resources res = getResources();
    getAudioSourceNameFromIdPrepare(res);

    listItemTextSize = res.getDimension(R.dimen.button_text_fontsize);
    listItemTitleTextSize = res.getDimension(R.dimen.button_text_small_fontsize);

    /// initialize pop up window items list
    // http://www.codeofaninja.com/2013/04/show-listview-as-drop-down-android.html
    popupMenuSampleRate = popupMenuCreate(validateAudioRates(res.getStringArray(R.array.sample_rates)),
            R.id.button_sample_rate);
    popupMenuFFTLen = popupMenuCreate(res.getStringArray(R.array.fft_len), R.id.button_fftlen);
    popupMenuAverage = popupMenuCreate(res.getStringArray(R.array.fft_ave_num), R.id.button_average);

    mDetector = new GestureDetectorCompat(this, new AnalyzerGestureListener());

    setTextViewFontSize();
}

From source file:nl.hnogames.domoticz.Adapters.DashboardAdapter.java

/**
 * Gets the status text/* w  w w .  ja v  a 2s.  co  m*/
 *
 * @param statusArrayRes      Status array to use
 * @param statusNamesArrayRes Status array of names to use
 * @param text                Text to find
 * @return Returns the status text
 */
private String getStatus(int statusArrayRes, int statusNamesArrayRes, String text) {
    Resources res = context.getResources();
    String[] states = res.getStringArray(statusArrayRes);
    String[] stateNames = res.getStringArray(statusNamesArrayRes);

    int length = states.length;
    for (int i = 0; i < length; i++) {
        if (states[i].equals(text))
            return stateNames[i];
    }
    return text;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    //  Debug.startMethodTracing("calc");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from ww w.  j ava 2  s.co  m*/

    DPRatio = getResources().getDisplayMetrics().density;

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    Log.i(TAG, " max mem = " + maxMemory + "k");

    // set and get preferences in PreferenceActivity
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Set variable according to the preferences
    updatePreferenceSaved();

    textRMSChar = new char[getString(R.string.textview_RMS_text).length()];
    textCurChar = new char[getString(R.string.textview_cur_text).length()];
    textRecChar = new char[getString(R.string.textview_rec_text).length()];
    textPeakChar = new char[getString(R.string.textview_peak_text).length()];

    graphView = (AnalyzeView) findViewById(R.id.plot);

    // travel Views, and attach ClickListener to the views that contain android:tag="select"
    visit((ViewGroup) graphView.getRootView(), new Visit() {
        @Override
        public void exec(View view) {
            view.setOnLongClickListener(AnalyzeActivity.this);
            view.setOnClickListener(AnalyzeActivity.this);
            ((TextView) view).setFreezesText(true);
        }
    }, "select");

    Resources res = getResources();
    getAudioSourceNameFromIdPrepare(res);

    listItemTextSize = res.getDimension(R.dimen.button_text_fontsize);
    listItemTitleTextSize = res.getDimension(R.dimen.button_text_small_fontsize);

    /// initialize pop up window items list
    // http://www.codeofaninja.com/2013/04/show-listview-as-drop-down-android.html
    popupMenuSampleRate = popupMenuCreate(validateAudioRates(res.getStringArray(R.array.sample_rates)),
            R.id.button_sample_rate);
    popupMenuFFTLen = popupMenuCreate(res.getStringArray(R.array.fft_len), R.id.button_fftlen);
    popupMenuAverage = popupMenuCreate(res.getStringArray(R.array.fft_ave_num), R.id.button_average);

    mDetector = new GestureDetectorCompat(this, new AnalyzerGestureListener());

    setTextViewFontSize();
}

From source file:jackpal.androidterm.Term.java

private String formatMessage(int keyId, int disabledKeyId, Resources r, int arrayId, int enabledId,
        int disabledId, String regex) {
    if (keyId == disabledKeyId) {
        return r.getString(disabledId);
    }/*from   w w  w  . j a v  a 2  s.co m*/
    String[] keyNames = r.getStringArray(arrayId);
    String keyName = keyNames[keyId];
    String template = r.getString(enabledId);
    String result = template.replaceAll(regex, keyName);
    return result;
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java

protected StyledDialog onCreateDialog(int id) {
    StyledDialog dialog = null;//from w  w  w  .j ava2s.c  o  m
    Resources res = getResources();
    StyledDialog.Builder builder1 = new StyledDialog.Builder(this.getActivity());

    switch (id) {
    case DIALOG_STATISTIC_TYPE:
        dialog = ChartBuilder.getStatisticsDialog(getActivity(), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_STATISTICS, mLoadStatisticsHandler,
                        new DeckTask.TaskData(AnkiDroidApp.getCol(), which, false));
            }
        }, mFragmented);
        break;

    case DIALOG_CUSTOM_STUDY:
        builder1.setTitle(res.getString(R.string.custom_study));
        builder1.setIcon(android.R.drawable.ic_menu_sort_by_size);
        builder1.setItems(res.getStringArray(R.array.custom_study_options_labels),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mCustomDialogChoice = which;
                        showDialog(DIALOG_CUSTOM_STUDY_DETAILS);
                    }
                });
        builder1.setCancelable(true);
        dialog = builder1.create();
        break;

    case DIALOG_CUSTOM_STUDY_DETAILS:
        builder1.setContentView(mCustomStudyDetailsView);
        builder1.setCancelable(true);
        builder1.setNegativeButton(R.string.cancel, null);
        builder1.setPositiveButton(R.string.ok, null);
        dialog = builder1.create();
        break;

    default:
        dialog = null;
    }

    dialog.setOwnerActivity(getActivity());
    return dialog;
}