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.zphinx.sortattributes.SortDialogManager.java

/**
 * Initializes and displays the alert dialog hosting the list of
 * StateTextView objects/*from w ww.  j ava 2  s. co m*/
 *
 * @param activity
 *            - The activity which uses this dialog
 */
public void showAlertDialog(final Activity activity) {
    String title = null;
    Log.d(TAG, "The alertDialog is: " + alertDialog);
    if (alertDialog == null) {
        Resources res = activity.getResources();
        String[] sortStrings = res.getStringArray(R.array.searchSortValues);
        title = "Sort Search Results";

        AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle);
        ListAdapter adapter = new SortAdapter(activity, R.layout.spinner_sort_list, sortStrings);

        builder.setSingleChoiceItems(adapter, -1, createItemListener(activity, adapter));

        alertDialog = builder.create();
        // Setting Dialog Title
        alertDialog.setTitle(title);

        // Setting alert dialog icon

        alertDialog.setCancelable(true);
        alertDialog.setCanceledOnTouchOutside(true);

        // Setting OK Button
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", sortListener(adapter, activity));

    }
    alertDialog.setOwnerActivity(activity);

    // Showing Alert Message
    alertDialog.show();
}

From source file:com.wholegroup.rally.ScoreActivity.java

/** */
@Override//from  www . j a v a  2s .  c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //  ?  ? ??
    m_sbNumber = new StringBuffer();

    // ?
    Resources m_res = getResources();

    String[] arrDefaultNames = m_res.getStringArray(R.array.names);
    int[] arrDefaultScores = m_res.getIntArray(R.array.scores);

    m_arrRecords = new ScoreRecord[RECORDCOUNT];

    for (int i = 0; i < RECORDCOUNT; i++) {
        if ((i < arrDefaultNames.length) && (i < arrDefaultScores.length)) {
            m_arrRecords[i] = new ScoreRecord(arrDefaultNames[i], arrDefaultScores[i], Rally.GAME_A);
        } else {
            m_arrRecords[i] = new ScoreRecord(getString(R.string.score_default_name), 0, Rally.GAME_A);
        }
    }

    m_strGameA = getString(R.string.rally_text_short_game_a);
    m_strGameB = getString(R.string.rally_text_short_game_b);

    //   
    Intent intent = getIntent();

    m_iScore = intent.getIntExtra(getString(R.string.score_parameter_score), 0);
    m_iType = intent.getIntExtra(getString(R.string.score_parameter_type), Rally.GAME_A);
    m_sName = getString(R.string.score_default_name);

    //   
    LoadScore();

    // ? ??
    Arrays.sort(m_arrRecords);

    // ?  ??
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.score);

    // ?  
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    ((TextView) findViewById(R.id.custom_title_left_text)).setText(R.string.score_activity_title);
    ((TextView) findViewById(R.id.custom_title_right_text)).setText(R.string.application_upper);

    // ?  ? ? ??
    setListAdapter(new ScoreAdapter());

    //     ?  
    if ((0 < m_iScore) && (m_iScore > m_arrRecords[RECORDCOUNT - 1].m_iScore)) {
        showDialog(0);
    }
}

From source file:com.microsoft.mimickeralarm.mimics.MimicColorCaptureFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    Resources resources = getResources();

    String subscriptionKey = KeyUtilities.getToken(getActivity(), "vision");
    mVisionServiceRestClient = new VisionServiceRestClient(subscriptionKey);

    String[] questions = resources.getStringArray(R.array.vision_color_questions);
    TextView instruction = (TextView) view.findViewById(R.id.instruction_text);
    mQuestionColorName = questions[new Random().nextInt(questions.length)];
    instruction.setText(String.format(resources.getString(R.string.mimic_vision_prompt), mQuestionColorName));

    TypedArray colorCodeLower = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_lower", "array", getActivity().getPackageName()));
    mQuestionColorRangeLower = new float[] { colorCodeLower.getFloat(0, 0f), colorCodeLower.getFloat(1, 0f),
            colorCodeLower.getFloat(2, 0f) };
    colorCodeLower.recycle();// ww w . j a  v a  2 s  .c  o  m
    TypedArray colorCodeUpper = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_upper", "array", getActivity().getPackageName()));
    mQuestionColorRangeUpper = new float[] { colorCodeUpper.getFloat(0, 0f), colorCodeUpper.getFloat(1, 0f),
            colorCodeUpper.getFloat(2, 0f) };
    colorCodeUpper.recycle();

    Logger.init(getActivity());
    Loggable playGameEvent = new Loggable.UserAction(Loggable.Key.ACTION_GAME_COLOR);
    Logger.track(playGameEvent);

    return view;
}

From source file:com.online.fullsail.SaveWebMedia.java

@Override
protected void onPostExecute(File download) {
    String fileString = download.toString();
    mNM.cancel(timestamp);//from w ww.  ja v a2 s  .  co  m
    System.gc();
    String fileName = fileString.substring(fileString.lastIndexOf('/') + 1, fileString.length());
    String fileExt = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
    File downFile = new File(externalData, fileName);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(downFile), "application/" + fileExt);
    List<ResolveInfo> intents = this.context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (intents == null || intents.size() == 0) {
        intent.setDataAndType(Uri.fromFile(downFile), "video/" + fileExt);
        intents = this.context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (intents == null || intents.size() == 0) {
            intent.setDataAndType(Uri.fromFile(downFile), "image/" + fileExt);
            intents = this.context.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (intents == null || intents.size() == 0) {
                intent = new Intent(Intent.ACTION_SEARCH);
                if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.ECLAIR) {
                    intent.setPackage("com.android.vending");
                }
                intent.putExtra("query", fileExt);

            }
        }
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(this.context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Notification notification = null;
    Resources resources = this.context.getResources();
    String[] mediaTypes = resources.getStringArray(R.array.media);
    boolean acceptedType = false;
    for (int i = 0; i < mediaTypes.length; i++) {
        if (fileExt.toLowerCase().equals(mediaTypes[i])) {
            acceptedType = true;
        }
    }
    if (acceptedType) {
        Bitmap preview = null;
        String[] videoTypes = resources.getStringArray(R.array.movFiles);
        for (int i = 0; i < videoTypes.length; i++) {
            if (fileExt.toLowerCase().equals(videoTypes[i])) {
                preview = getVideoFrame(fileString);
            }
        }
        String[] imageTypes = resources.getStringArray(R.array.movFiles);
        for (int i = 0; i < imageTypes.length; i++) {
            if (fileExt.toLowerCase().equals(imageTypes[i])) {
                preview = decodeBitmapFile(fileString);
            }
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
        builder.setTicker(this.context.getString(R.string.notify_download_complete))
                .setWhen(System.currentTimeMillis())
                .setContentTitle(this.context.getString(R.string.Document_complete))
                .setContentText(this.context.getString(R.string.Pdf_completed, fileName))
                .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH)
                .setContentIntent(contentIntent);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            notification = new NotificationCompat.BigPictureStyle(builder).bigPicture(preview).build();
        } else {
            notification = builder.build();
        }
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
        builder.setContentTitle(this.context.getString(R.string.Document_complete))
                .setContentText(this.context.getString(R.string.Pdf_completed, fileName))
                .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH)
                .setContentIntent(contentIntent);
        notification = builder.build();
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNM.notify(timestamp, notification);
}

From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private void generateQuestion(View view) {
    Resources resources = getResources();
    String[] questions = resources.getStringArray(R.array.tongue_twisters);
    mQuestion = questions[new Random().nextInt(questions.length)];

    final TextView instructionTextView = (TextView) view.findViewById(R.id.instruction_text);
    instructionTextView.setText(mQuestion);
}

From source file:org.svij.taskwarriorapp.activities.TaskAddActivity.java

public String getPriority(String priority) {
    Resources res = getResources();
    String[] priorities = res.getStringArray(R.array.priority_list);
    if (priority.equals(priorities[0])) {
        return "";
    } else if (priority.equals(priorities[1])) {
        return "H";
    } else if (priority.equals(priorities[2])) {
        return "M";
    } else if (priority.equals(priorities[3])) {
        return "L";
    } else {/*from  w ww.j a v a 2 s .com*/
        return "";
    }
}

From source file:Main.java

public static Object getResource(Context context, Field field, int value) {
    Resources resources = context.getResources();
    Class type = field.getType();

    if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class))
        return resources.getBoolean(value);
    else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) {
        return resources.getInteger(value);
    } else if (type.isAssignableFrom(ColorStateList.class))
        return resources.getColorStateList(value);
    else if (type.isAssignableFrom(XmlResourceParser.class))
        return resources.getXml(value);
    else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class))
        return resources.getDimension(value);
    else if (type.isAssignableFrom(Drawable.class))
        return resources.getDrawable(value);
    else if (type.isAssignableFrom(Animation.class))
        return AnimationUtils.loadAnimation(context, value);
    else if (type.isAssignableFrom(Movie.class))
        return resources.getMovie(value);
    else if (type.isAssignableFrom(String.class))
        return resources.getString(value);
    else if (type.isArray()) {
        if (type.getName().equals("[I")) {
            return resources.getIntArray(value);
        } else if (type.isAssignableFrom(String[].class)) {
            return resources.getStringArray(value);
        }//from  ww w  . j  a v a2  s .  com
    }

    return null;
}

From source file:com.lox.xtendedwallz.Wallpaper.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener() {
        public void onPageSelected(int position) {
            mCurrentFragment = position;
        }//from  ww w .j ava  2 s.  c  o m
    });

    sWallpapers.clear();

    final Resources resources = getResources();
    final String packageName = getApplication().getPackageName();

    fetchWallpapers(resources, packageName, R.array.wallpapers);
    mSectionsPagerAdapter.notifyDataSetChanged();
    mWallpaperInfo = resources.getStringArray(R.array.info);
}

From source file:org.catrobat.catroid.ui.fragment.UserBrickDataEditorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    fragmentView = inflater.inflate(R.layout.fragment_brick_data_editor, container, false);
    fragmentView.setFocusableInTouchMode(true);
    fragmentView.requestFocus();/*from w  w w .j a  v a 2 s  .c  o  m*/

    context = getActivity();
    brickView = View.inflate(context, R.layout.brick_user_editable, null);

    updateBrickView();

    editorBrickSpace = (LinearLayout) fragmentView.findViewById(R.id.brick_data_editor_brick_space);

    editorBrickSpace.addView(brickView);

    ListView buttonList = (ListView) fragmentView.findViewById(R.id.button_list);

    buttonList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Resources resources = getResources();

            String[] actions = resources.getStringArray(R.array.data_editor_buttons);

            String action = actions[position];

            if (action.equals(resources.getString(R.string.add_text))) {
                addTextDialog();
            }
            if (action.equals(resources.getString(R.string.add_variable))) {
                addVariableDialog();
            }
            if (action.equals(resources.getString(R.string.add_line_break))) {
                addLineBreak();
            }
            if (action.equals(resources.getString(R.string.close))) {
                onUserDismiss();
            }
        }
    });

    return fragmentView;
}

From source file:com.nikhilnayak.games.octoshootar.ui.fragments.GameModeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Resources res = getResources();

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

    if (getArguments().containsKey(EXTRA_GAME_MODE)) {
        mGameMode = getArguments().getParcelable(EXTRA_GAME_MODE);
    }/*  w w  w.  j  av  a2s.  c o  m*/

    String[] ranks = res.getStringArray(R.array.ranks_array_full);
    String[] grades = res.getStringArray(R.array.ranks_array_letter);

    final TextView rankTitle = (TextView) v.findViewById(R.id.details_rank);
    final TextView rankLetter = (TextView) v.findViewById(R.id.details_rank_letter);
    final ProgressBar progression = (ProgressBar) v.findViewById(R.id.details_progess_bar);
    final TextView progressText = (TextView) v.findViewById(R.id.details_progression);
    final TextView title = (TextView) v.findViewById(R.id.details_title);
    final int rank = mPlayerProfile.getRankByGameMode(mGameMode);
    final int progress = 100 - (int) ((((float) (ranks.length - 1) - rank) / (float) (ranks.length - 1)) * 100);
    final TextView admiral = (TextView) v.findViewById(R.id.admiral_description);
    final TextView sergeant = (TextView) v.findViewById(R.id.sergeant_description);
    final TextView corporal = (TextView) v.findViewById(R.id.corporal_description);
    final TextView soldier = (TextView) v.findViewById(R.id.soldier_description);
    final TextView deserter = (TextView) v.findViewById(R.id.deserter_description);
    final TextView longDescription = (TextView) v.findViewById(R.id.details_description);
    final int descriptionId = mGameMode.getLongDescription();

    rankTitle.setText(ranks[rank]);
    rankLetter.setText(grades[rank]);
    progression.setProgress(progress);
    progressText.setText(String.valueOf(progress) + " %");
    title.setText(mGameMode.getTitle());
    admiral.setText(mGameMode.getAdmiralRankRule(res));
    sergeant.setText(mGameMode.getSergeantRankRule(res));
    corporal.setText(mGameMode.getCorporalRankRule(res));
    soldier.setText(mGameMode.getSoldierRankRule(res));
    deserter.setText(mGameMode.getDeserterRankRule(res));
    if (descriptionId != -1)
        longDescription.setText(descriptionId);

    if (mListener != null) {
        //show button play
        final View start = v.findViewById(R.id.details_play);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onPlayRequest(mGameMode);
            }
        });

        start.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                start.getViewTreeObserver().removeOnPreDrawListener(this);
                int offset = v.getHeight() - start.getTop();
                start.setTranslationY(offset);
                start.setVisibility(View.VISIBLE);
                start.animate().translationY(0)
                        .setDuration(getResources().getInteger(R.integer.animation_duration_short))
                        .setInterpolator(new DecelerateInterpolator(2)).start();
                return false;
            }
        });

        v.findViewById(R.id.fragment_detail_important_title).setVisibility(View.VISIBLE);
        v.findViewById(R.id.fragment_detail_important_content).setVisibility(View.VISIBLE);
    }

    return v;
}