Example usage for android.widget TextView getContext

List of usage examples for android.widget TextView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

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

@BindingAdapter("prettyDateTime")
public static void toPrettyDateTime(TextView view, Date date) {
    if (date == null) {
        view.setText(null);/*ww  w .j  a  v  a  2 s.  c  o m*/
        return;
    }
    view.setText(getPrettyTime(view.getContext()).format(date));
}

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

@BindingAdapter("committer")
public static void toCommitter(TextView view, GitPersonalInfo info) {
    if (info == null) {
        view.setText(null);/*from  w  w w. j ava 2  s .  co m*/
        return;
    }

    String date = getPrettyTime(view.getContext()).format(info.date);
    String txt = view.getContext().getString(R.string.committer_format, info.name, info.email, date);
    view.setText(txt);
}

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

@BindingAdapter("humanReadableSize")
public static void toHumanReadableSize(TextView v, Long size) {
    if (size == null) {
        v.setText(null);/*from  w ww .  j a  v  a 2 s.  c  om*/
        return;
    }
    v.setText(android.text.format.Formatter.formatFileSize(v.getContext(), size));
}

From source file:com.pranavpandey.smallapp.theme.DynamicTheme.java

/**
 * Highlight the query text within a TextView. Suitable for notifying user about the
 * searched query found in the adapter. TextView should not be empty. Please set your
 * default text first then, highlight the query text by using this function.
 *
 * @param query String to be highlighted.
 * @param textView to set the highlighted text.
 * @param colorId Color id of the highlighted text.
 *
 * @see {@link android.text.Spannable}./*  w w  w . j av a2s  .  c  om*/
 */
public static void highlightQueryTextColorRes(@NonNull String query, @NonNull TextView textView,
        @ColorRes int colorId) {
    final String stringText = textView.getText().toString();
    if (!stringText.isEmpty() && stringText.toLowerCase(Locale.getDefault()).contains(query)) {
        final int startPos = stringText.toLowerCase(Locale.getDefault()).indexOf(query);
        final int endPos = startPos + query.length();

        Spannable spanText = Spannable.Factory.getInstance().newSpannable(stringText);
        spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(textView.getContext(), colorId)),
                startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        textView.setText(spanText, TextView.BufferType.SPANNABLE);
    }
}

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

@BindingAdapter("revisionCommit")
public static void toRevisionCommit(TextView view, RevisionInfo revision) {
    if (revision == null) {
        view.setText(null);/*from w  ww.j a v a  2 s  .c  om*/
        return;
    }
    if (revision.commit == null) {
        view.setText(view.getContext().getString(R.string.options_base));
    } else {
        view.setText(revision.commit.commit.substring(0, 10));
    }
}

From source file:com.silentcircle.common.util.ViewUtil.java

public static Intent createIntentForLinks(TextView view) {

    CharSequence text = view.getText();

    if (text instanceof Spannable) {

        Spannable stext = (Spannable) text;
        URLSpan[] spans = stext.getSpans(0, stext.length(), URLSpan.class);

        if (spans != null && spans.length > 0) {
            ChooserBuilder chooser = new ChooserBuilder(view.getContext());
            chooser.label(R.string.view);
            for (URLSpan span : spans) {
                String url = span.getURL();
                CharSequence label = stext.subSequence(stext.getSpanStart(span), stext.getSpanEnd(span));
                chooser.intent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), label);
            }//from   w  w w  .j  a v  a  2s . c o m
            return chooser.build();

        }
    }
    return null;
}

From source file:de.spiritcroc.modular_remote.Util.java

/**
 * @return/*from  w w  w . ja  va  2 s .c  o m*/
 * Size if valid, else -1
 */
public static double getSizeInput(TextView textView) {
    String input = textView.getText().toString();
    if (input.equals("")) {
        Context context = textView.getContext();
        textView.setError(context.getString(R.string.error_should_not_be_empty));
        return -1;
    }
    try {
        double result = Double.parseDouble(input);
        if (result > 0) {
            return result;
        } else {
            Context context = textView.getContext();
            textView.setError(context.getString(R.string.error_should_be_higher_than_zero));
            return -1;
        }
    } catch (Exception e) {
        Context context = textView.getContext();
        textView.setError(context.getString(R.string.error_invalid));
        return -1;
    }
}

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

@BindingAdapter("projectStatus")
public static void toProjectStatus(TextView v, ProjectStatus status) {
    if (status == null) {
        v.setText(null);//  ww  w . j a v  a 2 s .  co  m
        return;
    }

    String statusText = null;
    if (status.equals(ProjectStatus.ACTIVE)) {
        statusText = v.getContext().getString(R.string.project_details_status_active);
    } else if (status.equals(ProjectStatus.READ_ONLY)) {
        statusText = v.getContext().getString(R.string.project_details_status_read_only);
    } else if (status.equals(ProjectStatus.HIDDEN)) {
        statusText = v.getContext().getString(R.string.project_details_status_hidden);
    }
    v.setText(statusText);
}

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

@BindingAdapter("commentLine")
public static void toCommentLine(TextView v, CommentInfo comment) {
    if (comment == null) {
        v.setText(null);/*from w w  w. j a  v  a2 s . c  om*/
    } else if (comment.line == null) {
        v.setText(R.string.change_details_comment_file);
    } else if (SideType.PARENT.equals(comment.side)) {
        v.setText(v.getContext().getString(R.string.change_details_comment_base_line_number, comment.line));
    } else {
        v.setText(v.getContext().getString(R.string.change_details_comment_line_number, comment.line));
    }
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

public static void setRelativeDepartureTime(TextView timeRel, Date date) {
    long difference = getDifferenceInMinutes(date);
    if (difference > 99 || difference < -99) {
        timeRel.setVisibility(GONE);/*  ww w. ja  v  a 2  s . c o m*/
    } else if (difference == 0) {
        timeRel.setText(timeRel.getContext().getString(R.string.now_small));
        timeRel.setVisibility(VISIBLE);
    } else if (difference > 0) {
        timeRel.setText(timeRel.getContext().getString(R.string.in_x_minutes, difference));
        timeRel.setVisibility(VISIBLE);
    } else {
        timeRel.setText(timeRel.getContext().getString(R.string.x_minutes_ago, difference * -1));
        timeRel.setVisibility(VISIBLE);
    }
}