Example usage for android.content.res Resources getString

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

Introduction

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

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources res = getResources();

    if (key.equals(res.getString(R.string.settings_key_swipe_distance_threshold))
            || key.equals(res.getString(R.string.settings_key_swipe_velocity_threshold))) {
        reloadSwipeThresholdsSettings(res);
    } else if (key.equals(res.getString(R.string.settings_key_long_press_timeout))
            || key.equals(res.getString(R.string.settings_key_multitap_timeout))) {
        closing();/*ww  w.j  a  va2 s  . c o m*/
        mPointerTrackers.clear();
    }

    mAnimationLevel = AnyApplication.getConfig().getAnimationsLevel();
    mPreviewPopup
            .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.KeyPreviewAnimation);
    mMiniKeyboardPopup
            .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.MiniKeyboardAnimation);

}

From source file:com.android.calendar.EventInfoFragment.java

private void updateTitle() {
    Resources res = getActivity().getResources();
    if (mCanModifyCalendar && !mIsOrganizer) {
        getActivity().setTitle(res.getString(R.string.event_info_title_invite));
    } else {/*from   w  w  w.  j  a va2s  .  c o  m*/
        getActivity().setTitle(res.getString(R.string.event_info_title));
    }
}

From source file:com.android.mms.ui.MessageUtils.java

private static String formatDetails(StringBuilder details, Context context, MultimediaMessagePdu msg, int size,
        Resources res) {
    details.append('\n');
    details.append(res.getString(R.string.priority_label));
    details.append(getPriorityDescription(context, msg.getPriority()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append((size - 1) / 1024 + 1);
    details.append(res.getString(R.string.kilobyte));

    return details.toString();
}

From source file:com.android.messaging.ui.conversationlist.ConversationListItemView.java

/**
 * Fills in the data associated with this view.
 *
 * @param cursor The cursor from a ConversationList that this view is in, pointing to its
 * entry.//  ww w  .  j a  v  a  2s. c o m
 */
public void bind(final Cursor cursor, final HostInterface hostInterface) {
    // Update our UI model
    mHostInterface = hostInterface;
    mData.bind(cursor);

    resetAnimatingState();

    mSwipeableContainer.setOnClickListener(this);
    mSwipeableContainer.setOnLongClickListener(this);

    final Resources resources = getContext().getResources();

    int color;
    final int maxLines;
    final Typeface typeface;
    final int typefaceStyle = mData.getShowDraft() ? Typeface.ITALIC : Typeface.NORMAL;
    final String snippetText = getSnippetText();

    if (mData.getIsRead() || mData.getShowDraft()) {
        maxLines = TextUtils.isEmpty(snippetText) ? 0 : NO_UNREAD_SNIPPET_LINE_COUNT;
        color = mListItemReadColor;
        typeface = mListItemReadTypeface;
    } else {
        maxLines = TextUtils.isEmpty(snippetText) ? 0 : UNREAD_SNIPPET_LINE_COUNT;
        color = mListItemUnreadColor;
        typeface = mListItemUnreadTypeface;
    }

    mSnippetTextView.setMaxLines(maxLines);
    mSnippetTextView.setTextColor(color);
    mSnippetTextView.setTypeface(typeface, typefaceStyle);
    mSubjectTextView.setTextColor(color);
    mSubjectTextView.setTypeface(typeface, typefaceStyle);

    setSnippet();
    setConversationName();
    setSubject();
    setContentDescription(buildContentDescription(resources, mData, mConversationNameView.getPaint()));

    final boolean isDefaultSmsApp = PhoneUtils.getDefault().isDefaultSmsApp();
    // don't show the error state unless we're the default sms app
    if (mData.getIsFailedStatus() && isDefaultSmsApp) {
        mTimestampTextView.setTextColor(resources.getColor(R.color.conversation_list_error));
        mTimestampTextView.setTypeface(mListItemReadTypeface, typefaceStyle);
        int failureMessageId = R.string.message_status_download_failed;
        if (mData.getIsMessageTypeOutgoing()) {
            failureMessageId = MmsUtils.mapRawStatusToErrorResourceId(mData.getMessageStatus(),
                    mData.getMessageRawTelephonyStatus());
        }
        mTimestampTextView.setText(resources.getString(failureMessageId));
    } else if (mData.getShowDraft() || mData.getMessageStatus() == MessageData.BUGLE_STATUS_OUTGOING_DRAFT
    // also check for unknown status which we get because sometimes the conversation
    // row is left with a latest_message_id of a no longer existing message and
    // therefore the join values come back as null (or in this case zero).
            || mData.getMessageStatus() == MessageData.BUGLE_STATUS_UNKNOWN) {
        mTimestampTextView.setTextColor(mListItemReadColor);
        mTimestampTextView.setTypeface(mListItemReadTypeface, typefaceStyle);
        mTimestampTextView.setText(resources.getString(R.string.conversation_list_item_view_draft_message));
    } else {
        mTimestampTextView.setTextColor(mListItemReadColor);
        mTimestampTextView.setTypeface(mListItemReadTypeface, typefaceStyle);
        final String formattedTimestamp = mData.getFormattedTimestamp();
        if (mData.getIsSendRequested()) {
            mTimestampTextView.setText(R.string.message_status_sending);
        } else {
            mTimestampTextView.setText(formattedTimestamp);
        }
    }

    final boolean isSelected = mHostInterface.isConversationSelected(mData.getConversationId());
    setSelected(isSelected);
    Uri iconUri = null;
    int contactIconVisibility = GONE;
    int checkmarkVisiblity = GONE;
    int failStatusVisiblity = GONE;
    if (isSelected) {
        checkmarkVisiblity = VISIBLE;
    } else {
        contactIconVisibility = VISIBLE;
        // Only show the fail icon if it is not a group conversation.
        // And also require that we be the default sms app.
        if (mData.getIsFailedStatus() && !mData.getIsGroup() && isDefaultSmsApp) {
            failStatusVisiblity = VISIBLE;
        }
    }
    if (mData.getIcon() != null) {
        iconUri = Uri.parse(mData.getIcon());
    }
    mContactIconView.setImageResourceUri(iconUri, mData.getParticipantContactId(),
            mData.getParticipantLookupKey(), mData.getOtherParticipantNormalizedDestination());
    mContactIconView.setVisibility(contactIconVisibility);
    mContactIconView.setOnLongClickListener(this);
    mContactIconView.setClickable(!mHostInterface.isSelectionMode());
    mContactIconView.setLongClickable(!mHostInterface.isSelectionMode());

    mContactCheckmarkView.setVisibility(checkmarkVisiblity);
    mFailedStatusIconView.setVisibility(failStatusVisiblity);

    final Uri previewUri = mData.getShowDraft() ? mData.getDraftPreviewUri() : mData.getPreviewUri();
    final String previewContentType = mData.getShowDraft() ? mData.getDraftPreviewContentType()
            : mData.getPreviewContentType();
    OnClickListener previewClickListener = null;
    Uri previewImageUri = null;
    int previewImageVisibility = GONE;
    int audioPreviewVisiblity = GONE;
    if (previewUri != null && !TextUtils.isEmpty(previewContentType)) {
        if (ContentType.isAudioType(previewContentType)) {
            boolean incoming = !(mData.getShowDraft() || mData.getIsMessageTypeOutgoing());
            mAudioAttachmentView.bind(previewUri, incoming, false);
            audioPreviewVisiblity = VISIBLE;
        } else if (ContentType.isVideoType(previewContentType)) {
            previewImageUri = UriUtil.getUriForResourceId(getContext(), R.drawable.ic_preview_play);
            previewClickListener = fullScreenPreviewClickListener;
            previewImageVisibility = VISIBLE;
        } else if (ContentType.isImageType(previewContentType)) {
            previewImageUri = previewUri;
            previewClickListener = fullScreenPreviewClickListener;
            previewImageVisibility = VISIBLE;
        }
    }

    final int imageSize = resources.getDimensionPixelSize(R.dimen.conversation_list_image_preview_size);
    mImagePreviewView.setImageResourceId(new UriImageRequestDescriptor(previewImageUri, imageSize, imageSize,
            true /* allowCompression */, false /* isStatic */, false /*cropToCircle*/,
            ImageUtils.DEFAULT_CIRCLE_BACKGROUND_COLOR /* circleBackgroundColor */,
            ImageUtils.DEFAULT_CIRCLE_STROKE_COLOR /* circleStrokeColor */));
    mImagePreviewView.setOnLongClickListener(this);
    mImagePreviewView.setVisibility(previewImageVisibility);
    mImagePreviewView.setOnClickListener(previewClickListener);
    mAudioAttachmentView.setOnLongClickListener(this);
    mAudioAttachmentView.setVisibility(audioPreviewVisiblity);

    final int notificationBellVisiblity = mData.getNotificationEnabled() ? GONE : VISIBLE;
    mNotificationBellView.setVisibility(notificationBellVisiblity);
}

From source file:com.android.mms.ui.MessageUtils.java

private static void initializeMsgDetails(Context context, StringBuilder details, Resources res,
        MultimediaMessagePdu msg) {//w ww  . j av a2  s.c  om
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_message));

    if (msg instanceof RetrieveConf) {
        // From: ***
        String from = extractEncStr(context, ((RetrieveConf) msg).getFrom());
        details.append('\n');
        details.append(res.getString(R.string.from_label));
        details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));
    }

    // To: ***
    details.append('\n');
    details.append(res.getString(R.string.to_address_label));
    EncodedStringValue[] to = msg.getTo();
    if (to != null) {
        details.append(EncodedStringValue.concat(to));
    } else {
        Log.w(TAG, "recipient list is empty!");
    }

    // Bcc: ***
    if (msg instanceof SendReq) {
        EncodedStringValue[] values = ((SendReq) msg).getBcc();
        if ((values != null) && (values.length > 0)) {
            details.append('\n');
            details.append(res.getString(R.string.bcc_label));
            details.append(EncodedStringValue.concat(values));
        }
    }
}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getShowsDialog()) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }/* w ww  .j a v  a 2  s. c  om*/

    View view = inflater.inflate(R.layout.radial_time_picker_dialog, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId,
            R.styleable.BetterPickersDialogs);

    // Prepare some colors to use.
    int headerBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpBlue));
    int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor,
            ContextCompat.getColor(getActivity(), R.color.bpBlue));
    mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor,
            ContextCompat.getColor(getActivity(), R.color.radial_gray_light));

    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mHapticFeedbackController, mInitialHourOfDay, mInitialMinute,
            mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mTitleTextView = (TextView) view.findViewById(R.id.time_picker_header);
    if (mTitleText != null) {
        mTitleTextView.setVisibility(View.VISIBLE);
        mTitleTextView.setText(mTitleText);
    } else {
        mTitleTextView.setVisibility(View.GONE);
    }

    mError = (NumberPickerErrorTextView) view.findViewById(R.id.error);

    if (hasTimeLimits()) {
        mError.setVisibility(View.INVISIBLE);
    } else {
        mError.setVisibility(View.GONE);
    }

    mDoneButton = (Button) view.findViewById(R.id.done_button);
    if (mDoneText != null) {
        mDoneButton.setText(mDoneText);
    }
    mDoneButton.setTextColor(buttonTextColor);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            doneClickValidateAndCallback();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
    if (mCancelText != null) {
        cancelButton.setText(mCancelText);
    }
    cancelButton.setTextColor(buttonTextColor);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            dismiss();
        }
    });

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mTimePicker.setTheme(themeColors);

    // Set the colors for each view based on the theme.
    view.findViewById(R.id.time_display_background).setBackgroundColor(headerBgColor);
    view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor);
    view.findViewById(R.id.time_display).setBackgroundColor(headerBgColor);
    view.findViewById(R.id.time_picker_error_holder).setBackgroundColor(headerBgColor);
    ((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor);
    ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor);
    mTimePicker.setBackgroundColor(bodyBgColor);
    return view;
}

From source file:com.android.mms.ui.MessageUtils.java

static private String getPriorityDescription(Context context, int PriorityValue) {
    Resources res = context.getResources();
    switch (PriorityValue) {
    case PduHeaders.PRIORITY_HIGH:
        return res.getString(R.string.priority_high);
    case PduHeaders.PRIORITY_LOW:
        return res.getString(R.string.priority_low);
    case PduHeaders.PRIORITY_NORMAL:
    default:/*from www .j  a  va 2 s  .  c o m*/
        return res.getString(R.string.priority_normal);
    }
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

protected void showDeleteNoteDialog() {
    Resources res = getResources();
    new MaterialDialog.Builder(this).title(res.getString(R.string.delete_card_title))
            .iconAttr(R.attr.dialogErrorIcon)
            .content(String.format(res.getString(R.string.delete_note_message),
                    Utils.stripHTML(mCurrentCard.q(true))))
            .positiveText(res.getString(R.string.dialog_positive_delete))
            .negativeText(res.getString(R.string.dialog_cancel)).callback(new MaterialDialog.ButtonCallback() {
                @Override/*from   ww w  .j  a v a  2 s .  c  o m*/
                public void onPositive(MaterialDialog dialog) {
                    Timber.i("AbstractFlashcardViewer:: OK button pressed to delete note %d",
                            mCurrentCard.getNid());
                    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                            new DeckTask.TaskData(mCurrentCard, 3));
                }
            }).build().show();
}

From source file:com.android.mms.ui.MessageUtils.java

private static String getTextMessageDetails(Context context, MessageItem msgItem) {
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    String type = IpMessageUtils.getIpMessagePlugin(context).getIpUtils()
            .getIpTextMessageType(msgItem.mIpMessageItem);
    /// M: modify for ipmessage
    if (type != null) {
        details.append(type);//from  ww w .java 2s. c o  m
    } else {
        details.append(res.getString(R.string.text_message));
    }

    // Address: ***
    details.append('\n');
    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    int smsType = msgItem.mBoxId;
    /// @}
    if (Sms.isOutgoingFolder(smsType)) {
        details.append(res.getString(R.string.to_address_label));
    } else {
        details.append(res.getString(R.string.from_label));
    }
    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{

    details.append(msgItem.mAddress);

    /// @}

    // / @}

    // SentDate: ***
    if (msgItem.mSmsSentDate > 0 && smsType == Sms.MESSAGE_TYPE_INBOX) {
        details.append('\n');
        details.append(res.getString(R.string.sent_label));
        String dateStr = formatDateAndTimeStampString(context, 0, msgItem.mSmsSentDate, true);
        details.append(dateStr);
    }

    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    if (msgItem.mSmsDate > 0L) {
        details.append('\n');
        if (smsType == Sms.MESSAGE_TYPE_DRAFT) {
            details.append(res.getString(R.string.saved_label));
        } else if (smsType == Sms.MESSAGE_TYPE_INBOX) {
            details.append(res.getString(R.string.received_label));
        } else {
            details.append(res.getString(R.string.sent_label));
        }
        String dateStr = formatDateAndTimeStampString(context, 0, msgItem.mSmsDate, true);
        details.append(dateStr);
    }
    /// @}

    /// M: Code analyze 028, new feature, add service center in Sms details. @{
    if (smsType == Sms.MESSAGE_TYPE_INBOX) {
        details.append('\n');
        details.append(res.getString(R.string.service_center_label));
        details.append(msgItem.mServiceCenter == null ? "" : msgItem.mServiceCenter);
    }
    /// @}

    // Delivered: ***
    if (smsType == Sms.MESSAGE_TYPE_SENT) {
        // For sent messages with delivery reports, we stick the delivery time in the
        // date_sent column (see MessageStatusReceiver).
        /// M: long dateDelivered = cursor.getLong(MessageListAdapter.COLUMN_SMS_DATE_SENT);
        // / M: Code analyze 027, new feature, to improve the performance of
        // Mms. @{
        long dateDelivered = -1L;
        if (dateDelivered > 0) {
            details.append('\n');
            details.append(res.getString(R.string.delivered_label));
            details.append(MessageUtils.formatTimeStampString(context, dateDelivered, true));
        }
    }

    // Error code: ***
    int errorCode = msgItem.mErrorCode;
    /// @}
    if (errorCode != 0) {
        details.append('\n').append(res.getString(R.string.error_code_label)).append(errorCode);
    }

    return details.toString();
}