Example usage for android.widget TextView getResources

List of usage examples for android.widget TextView getResources

Introduction

In this page you can find the example usage for android.widget TextView getResources.

Prototype

public Resources getResources() 

Source Link

Document

Returns the resources associated with this view.

Usage

From source file:com.ruesga.rview.misc.Formatter.java

@BindingAdapter("addedVsDeleted")
public static void toAddedVsRemoved(TextView view, FileInfo info) {
    if (info == null) {
        view.setText(null);//w  w w .  java 2s  .  c o  m
        return;
    }

    final Resources res = view.getResources();
    String added = null;
    if (info.linesInserted != null && info.linesInserted > 0) {
        added = res.getQuantityString(R.plurals.files_added, info.linesInserted, info.linesInserted);
    }
    String deleted = null;
    if (info.linesDeleted != null && info.linesDeleted > 0) {
        deleted = res.getQuantityString(R.plurals.files_deleted, info.linesDeleted, info.linesDeleted);
    }
    if (added == null && deleted == null) {
        added = res.getQuantityString(R.plurals.files_added, 0, 0);
        deleted = res.getQuantityString(R.plurals.files_deleted, 0, 0);
    }

    String txt;
    if (added != null && deleted != null) {
        txt = res.getString(R.string.added_vs_deleted, added, deleted);
    } else if (added != null) {
        txt = added;
    } else {
        txt = deleted;
    }
    view.setText(txt);
}

From source file:com.github.pockethub.android.ui.WelcomePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View v = LayoutInflater.from(container.getContext()).inflate(view, container, false);

    TextView titleText = ((TextView) v.findViewById(R.id.tv_title));
    TextView infoText = ((TextView) v.findViewById(R.id.tv_info));
    titleText.setText(titles[position]);
    infoText.setText(info[position]);//from w w w.j ava 2  s . c om
    if (position == 0) {
        @ColorInt
        int primaryColor = titleText.getResources().getColor(R.color.primary);
        titleText.setTextColor(primaryColor);
        infoText.setTextColor(primaryColor);
    }
    ((ImageView) v.findViewById(R.id.iv_art)).setImageResource(images[position]);

    container.addView(v);
    return v;
}

From source file:com.wayhua.framework.adapter.WelcomePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View v = LayoutInflater.from(container.getContext()).inflate(view, container, false);

    TextView titleText = ((TextView) v.findViewById(R.id.tv_title));
    TextView infoText = ((TextView) v.findViewById(R.id.tv_info));
    titleText.setText(titles[position]);
    infoText.setText(info[position]);/*w  w  w  .  ja  va 2 s .  c  o m*/
    if (position == 0) {
        @ColorInt
        int primaryColor = titleText.getResources().getColor(R.color.colorPrimary);
        titleText.setTextColor(primaryColor);
        infoText.setTextColor(primaryColor);
    }
    ImageView imageView = (ImageView) v.findViewById(R.id.iv_art);
    //.setImageResource(images[position]);
    Glide.with(context).load(images[position]).into(imageView);
    container.addView(v);
    return v;
}

From source file:com.concavenp.artistrymuse.BaseAppCompatActivity.java

/**
 * Helper method that protects against bad data when populating TextView(s).  This overloaded
 * method provides safe conversion protection by wrapping the Double object.
 *
 * @param doubleObject - The Double object to be converted to text and set in the view
 * @param textView - The view to set with the text parameter
 *//*from  w w w . j a va 2 s.c  o m*/
protected void populateTextView(Double doubleObject, TextView textView) {

    // For safety, check as well (I've seen it) ...
    if (textView != null) {

        if (doubleObject != null) {

            String result = "";

            try {

                result = String.format(textView.getResources().getString(R.string.number_format), doubleObject);

            } catch (Exception ex) {

                Log.e(TAG,
                        "The double object threw an exception during string translation, defaulting to an empty string");

            }

            // With a string in hand, populate the TextView
            populateTextView(result, textView);

        } else {

            Log.e(TAG, "The double object was null, defaulting to an empty string");

            // The object was null, default to an empty string
            populateTextView("", textView);

        }

    } else {

        Log.e(TAG, "The TextView object was null, unable to populate");

    }

}

From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java

/**
 * Gets called after user has selected a gallery image to attach.
 *///www  .j  a v a 2 s  .c o m
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PICK_FROM_GALLERY && resultCode == RESULT_OK) {
        // get path to pressed picture.
        Uri selectedImage = data.getData();
        AppVariablesSingleton apv = AppVariablesSingleton.getInstance();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        file_path = cursor.getString(columnIndex);
        // Ignore press if file has already been attached previously.
        if (!attachments.contains(file_path)) {
            Log.d("Attachment Path:", file_path);
            attachments.add(file_path);

            File file = new File(file_path);
            // calculating the file size
            float bytes = file.length();
            kilobytes = bytes / 1024;
            total = sizePref.getFloat("Total", (float) 0.0);
            total += kilobytes;
            sizeEdit.putFloat("Total", total);
            sizeEdit.putFloat(file_path, kilobytes);
            sizeEdit.commit();
            TextView result;
            if (apv.getIsReply()) {
                result = (TextView) findViewById(R.id.totalsizeReply);
            } else {
                result = (TextView) findViewById(R.id.totalsize);
            }
            String total_size = result.getResources().getString(R.string.total_size);
            result.setText(total_size + " " + total + " KB");
            // Attachments list is updated to contain the pressed
            // attachment.
            listView.setAdapter(new AttachmentsAdapter(getApplicationContext(), R.layout.attachments_item,
                    R.id.attachments_text, attachments, result));
        }
        cursor.close();
    }
}

From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java

private void updateSearchView(final String query) {
    View view = getView();//from w  w  w .j  a  v  a2 s .c  o  m
    if (view == null) {
        logger.error("No view created yet!!! query: " + query);
        return;
    }

    RelativeLayout callSearchLayout = (RelativeLayout) view.findViewById(R.id.callSearchLayout);

    if (StringUtils.isNullOrEmpty(query)) {
        if (callSearchLayout != null) {
            callSearchLayout.setVisibility(View.INVISIBLE);
            callSearchLayout.getLayoutParams().height = 0;
        }
    } else {
        if (callSearchLayout != null) {
            TextView searchContactView = (TextView) callSearchLayout.findViewById(R.id.callSearchContact);

            searchContactView.setText(query);
            callSearchLayout.getLayoutParams().height = searchContactView.getResources()
                    .getDimensionPixelSize(R.dimen.account_list_row_height);

            callSearchLayout.setVisibility(View.VISIBLE);

            final ImageButton callButton = (ImageButton) callSearchLayout.findViewById(R.id.contactCallButton);
            callButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AndroidCallUtil.createAndroidCall(getActivity(), callButton, query);
                }
            });
        }
    }
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {
    mWordViews = wordViews;/*from www . jav  a  2  s  .co m*/
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;

    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}

From source file:com.udmurtlyk.extrainputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {
    mWordViews = wordViews;//  w  ww.  j a  v  a 2s.c  om
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;

    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mColorShortcut = a.getColor(R.styleable.SuggestionStripView_colorShortcut, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}

From source file:com.mobiletin.inputmethod.indic.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {

    mWordViews = wordViews;/*from  w ww. j  a v  a2s . co  m*/
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;
    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}