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:org.billthefarmer.shorty.LookupActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lookup);/* ww w.  ja v  a  2 s .  c  om*/

    // Get text views
    nameView = (TextView) findViewById(R.id.lu_name);
    urlView = (TextView) findViewById(R.id.lu_url);

    // Get buttons, set listener
    Button add = (Button) findViewById(R.id.add);
    if (add != null)
        add.setOnClickListener(this);

    Button remove = (Button) findViewById(R.id.remove);
    if (remove != null)
        remove.setOnClickListener(this);

    Button select = (Button) findViewById(R.id.select);
    if (select != null)
        select.setOnClickListener(this);

    // get list view
    listView = (ListView) findViewById(R.id.list);

    if (listView != null)
        listView.setOnItemClickListener(this);

    // Enable back navigation on action bar
    ActionBar actionBar = getActionBar();
    if (actionBar != null)
        actionBar.setDisplayHomeAsUpEnabled(true);

    // Get preferences
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    String name = preferences.getString(MainActivity.PREF_NAME, null);
    String url = preferences.getString(MainActivity.PREF_URL, null);

    // Set fields from preferences
    if (name != null)
        nameView.setText(name);
    if (url != null)
        urlView.setText(url);

    String entryJSON = preferences.getString(PREF_ENTRIES, null);
    String valueJSON = preferences.getString(PREF_VALUES, null);

    // Get resources
    Resources resources = getResources();

    // Add entries
    if (entryJSON != null) {
        try {
            JSONArray entryArray = new JSONArray(entryJSON);
            entryList = new ArrayList<String>();
            for (int i = 0; !entryArray.isNull(i); i++)
                entryList.add(entryArray.getString(i));
        }

        catch (Exception e) {
            String entries[] = resources.getStringArray(R.array.entries);
            entryList = new ArrayList<String>(Arrays.asList(entries));
        }
    }

    else {
        String entries[] = resources.getStringArray(R.array.entries);
        entryList = new ArrayList<String>(Arrays.asList(entries));
    }

    if (valueJSON != null) {
        try {
            JSONArray valueArray = new JSONArray(valueJSON);
            valueList = new ArrayList<String>();
            for (int i = 0; !valueArray.isNull(i); i++)
                valueList.add(valueArray.getString(i));
        }

        catch (Exception e) {
            String values[] = resources.getStringArray(R.array.values);
            valueList = new ArrayList<String>(Arrays.asList(values));
        }
    }

    else {
        String values[] = resources.getStringArray(R.array.values);
        valueList = new ArrayList<String>(Arrays.asList(values));
    }

    // Set array adapter
    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, entryList);

    listView.setAdapter(arrayAdapter);
}

From source file:planets.position.PlanetListDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int list = getArguments().getInt("list");
    final int which = getArguments().getInt("which");
    int title = getArguments().getInt("title");
    int filter = getArguments().getInt("filter");
    final Resources res = getResources();

    if (which == 3) {
        // filter planets in What's Up activity
        return new AlertDialog.Builder(getActivity()).setTitle(title)
                .setSingleChoiceItems(list, filter, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        ((ViewWhatsUp) getActivity()).loadFilter(item);
                    }// w  w  w  .  jav  a2  s  .  c  o  m
                }).create();
    } else {
        return new AlertDialog.Builder(getActivity()).setTitle(title)
                .setItems(list, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        // switch for LivePosition, Position, NewLoc
                        // activities
                        switch (which) {
                        case 0:
                            // gps offset
                            String[] gpsArray = res.getStringArray(R.array.gps_array);
                            ((NewLoc) getActivity()).loadOffset(gpsArray[item]);
                            break;
                        case 1:
                            // sky position in Planets
                            String[] planetArray1 = res.getStringArray(R.array.planets_array);
                            ((Planets) getActivity()).loadPlanets(planetArray1[item], item, 1);
                            break;
                        case 4:
                            // sky position in Position
                            String[] planetArray2 = res.getStringArray(R.array.planets_array);
                            ((Position) getActivity()).loadPlanet(planetArray2[item], item);
                            break;
                        case 2:
                            // real time position
                            String[] planetLiveArray = res.getStringArray(R.array.planets_array);
                            ((Planets) getActivity()).loadPlanets(planetLiveArray[item], item, 2);
                            break;
                        }
                    }
                }).create();
    }
}

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING:/*from  www.  j av a 2 s.  c  o m*/
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.meiste.greg.ptw.tab.QuestionsAnswers.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    Util.log("QuestionsAnswers: onCreateView");

    final String qjson = getArguments().getString(RACE_QUESTIONS);
    if (qjson == null) {
        return null;
    }/*from   w w  w.  j ava  2s. co  m*/
    final String ajson = getArguments().getString(RACE_ANSWERS);
    if (ajson == null) {
        return null;
    }
    final RaceQuestions rq = RaceQuestions.fromJson(qjson);
    final RaceAnswers ra = RaceAnswers.fromJson(ajson);
    final Resources res = getActivity().getResources();

    final View v = inflater.inflate(R.layout.questions_answered, container, false);

    final TextView q2 = (TextView) v.findViewById(R.id.question2);
    q2.setText(getActivity().getString(R.string.questions_2, rq.q2));

    final TextView q3 = (TextView) v.findViewById(R.id.question3);
    q3.setText(getActivity().getString(R.string.questions_3, rq.q3));

    final TextView a1 = (TextView) v.findViewById(R.id.answer1);
    a1.setText(Driver.find(rq.drivers, res, ra.a1).getName());

    final TextView a2 = (TextView) v.findViewById(R.id.answer2);
    a2.setText(rq.a2[ra.a2]);

    final TextView a3 = (TextView) v.findViewById(R.id.answer3);
    a3.setText(rq.a3[ra.a3]);

    final TextView a4 = (TextView) v.findViewById(R.id.answer4);
    a4.setText(Driver.find(rq.drivers, res, ra.a4).getName());

    final TextView a5 = (TextView) v.findViewById(R.id.answer5);
    a5.setText(res.getStringArray(R.array.num_leaders)[ra.a5]);

    final String cajson = getArguments().getString(RACE_CORRECT_ANSWERS);
    if (cajson != null) {
        Util.log("QuestionsAnswers: Correct answers available");
        final RaceAnswers rca = RaceAnswers.fromJson(cajson);

        // Have to check for null in case there is no correct answer
        if ((rca.a1 != null) && (rca.a1 >= 0)) {
            if (rca.a1 == ra.a1) {
                a1.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a1.setPaintFlags(a1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a1.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c1 = (TextView) v.findViewById(R.id.correct1);
                c1.setText(Driver.find(rq.drivers, res, rca.a1).getName());
                c1.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a2 != null) && (rca.a2 >= 0)) {
            if (rca.a2 == ra.a2) {
                a2.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a2.setPaintFlags(a2.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a2.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c2 = (TextView) v.findViewById(R.id.correct2);
                c2.setText(rq.a2[rca.a2]);
                c2.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a3 != null) && (rca.a3 >= 0)) {
            if (rca.a3 == ra.a3) {
                a3.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a3.setPaintFlags(a3.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a3.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c3 = (TextView) v.findViewById(R.id.correct3);
                c3.setText(rq.a3[rca.a3]);
                c3.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a4 != null) && (rca.a4 >= 0)) {
            if (rca.a4 == ra.a4) {
                a4.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a4.setPaintFlags(a4.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a4.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c4 = (TextView) v.findViewById(R.id.correct4);
                c4.setText(Driver.find(rq.drivers, res, rca.a4).getName());
                c4.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a5 != null) && (rca.a5 >= 0)) {
            if (rca.a5 == ra.a5) {
                a5.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a5.setPaintFlags(a5.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a5.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c5 = (TextView) v.findViewById(R.id.correct5);
                c5.setText(res.getStringArray(R.array.num_leaders)[rca.a5]);
                c5.setVisibility(View.VISIBLE);
            }
        }
    }

    return v;
}

From source file:website.openeng.anki.StudyOptionsFragment.java

/**
 * Special method to show the context menu for the custom study options
 * TODO: Turn this into a DialogFragment
 */// w w w .j a  va  2s .c  om
private void showCustomStudyContextMenu() {
    Resources res = getResources();
    Drawable icon = res.getDrawable(R.drawable.ic_sort_black_36dp);
    icon.setAlpha(Themes.ALPHA_ICON_ENABLED_DARK);
    MaterialDialog dialog = new MaterialDialog.Builder(this.getActivity())
            .title(res.getString(R.string.custom_study)).icon(icon).cancelable(true)
            .items(res.getStringArray(R.array.custom_study_options_labels))
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int which,
                        CharSequence charSequence) {
                    DialogFragment dialogFragment;
                    if (which == CustomStudyDialog.CUSTOM_STUDY_TAGS) {
                        /*
                         * This is a special Dialog for CUSTOM STUDY, where instead of only collecting a
                         * number, it is necessary to collect a list of tags. This case handles the creation
                         * of that Dialog.
                         */
                        dialogFragment = website.openeng.anki.dialogs.TagsDialog.newInstance(
                                TagsDialog.TYPE_CUSTOM_STUDY_TAGS, new ArrayList<String>(),
                                new ArrayList<String>(getCol().getTags().all()));

                        ((TagsDialog) dialogFragment).setTagsDialogListener(new TagsDialogListener() {
                            @Override
                            public void onPositive(List<String> selectedTags, int option) {
                                /*
                                 * Here's the method that gathers the final selection of tags, type of cards and generates the search
                                 * screen for the custom study deck.
                                 */
                                StringBuilder sb = new StringBuilder();
                                switch (option) {
                                case 1:
                                    sb.append("is:new ");
                                    break;
                                case 2:
                                    sb.append("is:due ");
                                    break;
                                default:
                                    // Logging here might be appropriate : )
                                    break;
                                }
                                List<String> arr = new ArrayList<>();
                                if (selectedTags.size() > 0) {
                                    for (String tag : selectedTags) {
                                        arr.add(String.format("tag:'%s'", tag));
                                    }
                                    sb.append("(" + TextUtils.join(" or ", arr) + ")");
                                }
                                mSearchTerms = sb.toString();
                                createFilteredDeck(new JSONArray(),
                                        new Object[] { mSearchTerms, Consts.DYN_MAX_SIZE, Consts.DYN_RANDOM },
                                        false);
                            }
                        });
                    } else {
                        // Show CustomStudyDialog for all options other than the tags dialog
                        dialogFragment = CustomStudyDialog.newInstance(which);
                        // If we increase limits, refresh the interface to reflect the new counts
                        ((CustomStudyDialog) dialogFragment).setCustomStudyDialogListener(
                                new CustomStudyDialog.CustomStudyDialogListener() {
                                    @Override
                                    public void onPositive(int option) {
                                        if (option == CustomStudyDialog.CUSTOM_STUDY_NEW
                                                || option == CustomStudyDialog.CUSTOM_STUDY_REV) {
                                            refreshInterfaceAndDecklist(true);
                                        }
                                    }
                                });
                    }
                    // Show the DialogFragment via Activity
                    ((AnkiActivity) getActivity()).showDialogFragment(dialogFragment);
                }
            }).build();
    dialog.setOwnerActivity(getActivity());
    dialog.show();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//  w  w  w. j a v a  2  s . c  om
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);// ww  w .  j a  v a  2  s  . com
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:com.todoroo.astrid.core.CustomFilterActivity.java

/**
 * Populate criteria list with built in and plugin criteria. The request is sent to every application
 * registered to listen for this broadcast. Each plugin can then add criteria to this activity.
 *///from  w  ww. j  a  v  a 2  s .c om
@SuppressWarnings("nls")
private void populateCriteria() {
    Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_REQUEST_CUSTOM_FILTER_CRITERIA);
    sendOrderedBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);

    Resources r = getResources();

    // built in criteria: due date
    {
        String[] entryValues = new String[] { "0", PermaSql.VALUE_EOD_YESTERDAY, PermaSql.VALUE_EOD,
                PermaSql.VALUE_EOD_TOMORROW, PermaSql.VALUE_EOD_DAY_AFTER, PermaSql.VALUE_EOD_NEXT_WEEK,
                PermaSql.VALUE_EOD_NEXT_MONTH, };
        ContentValues values = new ContentValues();
        values.put(Task.DUE_DATE.name, "?");
        CustomFilterCriterion criterion = new MultipleSelectCriterion(IDENTIFIER_DUEDATE,
                getString(R.string.CFC_dueBefore_text),
                Query.select(Task.ID).from(Task.TABLE).where(Criterion.and(TaskCriteria.activeVisibleMine(),
                        Criterion.or(Field.field("?").eq(0), Task.DUE_DATE.gt(0)), Task.DUE_DATE.lte("?")))
                        .toString(),
                values, r.getStringArray(R.array.CFC_dueBefore_entries), entryValues,
                ((BitmapDrawable) r.getDrawable(R.drawable.tango_calendar)).getBitmap(),
                getString(R.string.CFC_dueBefore_name));
        criteria.put(IDENTIFIER_DUEDATE, criterion);
    }

    // built in criteria: importance
    {
        String[] entryValues = new String[] { Integer.toString(Task.IMPORTANCE_DO_OR_DIE),
                Integer.toString(Task.IMPORTANCE_MUST_DO), Integer.toString(Task.IMPORTANCE_SHOULD_DO),
                Integer.toString(Task.IMPORTANCE_NONE), };
        String[] entries = new String[] { "!!!", "!!", "!", "o" };
        ContentValues values = new ContentValues();
        values.put(Task.IMPORTANCE.name, "?");
        CustomFilterCriterion criterion = new MultipleSelectCriterion(IDENTIFIER_IMPORTANCE,
                getString(R.string.CFC_importance_text),
                Query.select(Task.ID).from(Task.TABLE)
                        .where(Criterion.and(TaskCriteria.activeVisibleMine(), Task.IMPORTANCE.lte("?")))
                        .toString(),
                values, entries, entryValues,
                ((BitmapDrawable) r.getDrawable(R.drawable.tango_warning)).getBitmap(),
                getString(R.string.CFC_importance_name));
        criteria.put(IDENTIFIER_IMPORTANCE, criterion);
    }

    // built in criteria: title containing X
    {
        ContentValues values = new ContentValues();
        values.put(Task.TITLE.name, "?");
        CustomFilterCriterion criterion = new TextInputCriterion(IDENTIFIER_TITLE,
                getString(R.string.CFC_title_contains_text),
                Query.select(Task.ID).from(Task.TABLE)
                        .where(Criterion.and(TaskCriteria.activeVisibleMine(), Task.TITLE.like("%?%")))
                        .toString(),
                null, getString(R.string.CFC_title_contains_name), "",
                ((BitmapDrawable) r.getDrawable(R.drawable.tango_alpha)).getBitmap(),
                getString(R.string.CFC_title_contains_name));
        criteria.put(IDENTIFIER_TITLE, criterion);
    }
}

From source file:com.nit.vicky.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//w  w  w. jav a2  s. co m
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "word", "sfld", "deck", "flags" },
            new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize,
            sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    //mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview);
    mCardsGridView.setAdapter(mGridAdapter);
    mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
        @Override
        public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
            String imgURL = getImgURL(sCardBrowserCard);
            Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show();
        }
    });
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

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

private void getAudioSourceNameFromIdPrepare(Resources res) {
    audioSourceNames = res.getStringArray(R.array.audio_source);
    String[] sasid = res.getStringArray(R.array.audio_source_id);
    audioSourceIDs = new int[audioSourceNames.length];
    for (int i = 0; i < audioSourceNames.length; i++) {
        audioSourceIDs[i] = Integer.parseInt(sasid[i]);
    }/*from   w w w .jav a 2  s  . c  o m*/
}