Java Code Examples for android.widget.TextView#getCurrentTextColor()

The following examples show how to use android.widget.TextView#getCurrentTextColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimUtils.java    From PaymentKit-Droid with Apache License 2.0 6 votes vote down vote up
/**
 * @param shouldResetTextColor if true make sure you end the previous animation before starting this one.
 */
public static ObjectAnimator getShakeAnimation(final TextView textView, final boolean shouldResetTextColor) {
    final int textColor = textView.getCurrentTextColor();
    textView.setTextColor(Color.RED);

    ObjectAnimator shakeAnim = ObjectAnimator.ofFloat(textView, "translationX", -16);
    shakeAnim.setDuration(SHAKE_DURATION);
    shakeAnim.setInterpolator(new CycleInterpolator(2.0f));
    shakeAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator anim) {
            if (shouldResetTextColor) {
                textView.setTextColor(textColor);
            }
        }
    });
    return shakeAnim;
}
 
Example 2
Source File: PlaybackSpeedDialog.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dialog_playback_speed, container);
    mSpeedValue = (TextView) view.findViewById(R.id.playback_speed_value);
    mSeekSpeed = (SeekBar) view.findViewById(R.id.playback_speed_seek);
    mPlaybackSpeedIcon = (ImageView) view.findViewById(R.id.playback_speed_icon);

    mSeekSpeed.setOnSeekBarChangeListener(mSeekBarListener);
    mPlaybackSpeedIcon.setOnClickListener(mResetListener);
    mSpeedValue.setOnClickListener(mResetListener);

    mTextColor = mSpeedValue.getCurrentTextColor();


    getDialog().setCancelable(true);
    getDialog().setCanceledOnTouchOutside(true);
    Window window = getDialog().getWindow();
    window.setBackgroundDrawableResource(Util.getResourceFromAttribute(getActivity(), R.attr.rounded_bg));
    window.setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    return view;
}
 
Example 3
Source File: OngoingNotificationsReceiver.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private boolean recurseGroup(@NonNull ViewGroup gp) {
    int count = gp.getChildCount();
    for (int i = 0; i < count; ++i) {
        View v = gp.getChildAt(i);
        if (v instanceof TextView) {
            TextView text = (TextView) v;
            String szText = text.getText().toString();
            if ("COLOR_SEARCH_1ST".equals(szText)) {
                mDefaultTextColor = text.getCurrentTextColor();
            }
        } else if (gp.getChildAt(i) instanceof ViewGroup) {
            if (recurseGroup((ViewGroup) v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: LauncherActivity.java    From Last-Launcher with GNU General Public License v3.0 5 votes vote down vote up
private void changeColorSize(String activityName, TextView view) {
    int color = DbUtils.getAppColor(activityName);
    if (color == DbUtils.NULL_TEXT_COLOR) {
        color = view.getCurrentTextColor();
    }

    int size = DbUtils.getAppSize(activityName);
    if (size == DbUtils.NULL_TEXT_SIZE) {
        for (Apps apps : mAppsList) {
            if (apps.getActivityName().equals(activityName)) {
                size = apps.getSize();
                break;
            }
        }
    }
    dialogs = new ColorSizeDialog(this, activityName, color, view, size);

    Window window = dialogs.getWindow();
    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    }


    dialogs.show();
}
 
Example 5
Source File: SlidingTabLayout.java    From android-sliderview with MIT License 5 votes vote down vote up
private View getCustomTabView(CharSequence title) {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View tabView = inflater.inflate(customTabViewId, strip, false);
    TextView text = (TextView) tabView.findViewById(customTabViewTextViewId);
    if (text != null) {
        text.setText(title);
        if (textColor == -1) textColor = text.getCurrentTextColor();
    }

    return tabView;
}
 
Example 6
Source File: TestUtils.java    From Scoops with Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withTextColor(final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public boolean matchesSafely(TextView warning) {
            return color == warning.getCurrentTextColor();
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
        }
    };
}
 
Example 7
Source File: CustomMatchers.java    From friendspell with Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withTextColor(final int color) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    @Override public boolean matchesSafely(TextView textView) {
      return (textView.getCurrentTextColor() == color);
    }
    @Override public void describeTo(Description description) {
      description.appendText("has colors: " + getHexColor(color));
    }
  };
}
 
Example 8
Source File: TextSizeTransition.java    From android-login with MIT License 5 votes vote down vote up
public TextResizeData(TextView textView) {
  this.paddingLeft = textView.getPaddingLeft();
  this.paddingTop = textView.getPaddingTop();
  this.paddingRight = textView.getPaddingRight();
  this.paddingBottom = textView.getPaddingBottom();
  this.width = textView.getWidth();
  this.height = textView.getHeight();
  this.gravity = textView.getGravity();
  this.textColor = textView.getCurrentTextColor();
}
 
Example 9
Source File: TextResize.java    From android-instant-apps with Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 10
Source File: TextResize.java    From atlas with Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 11
Source File: BasicUITests.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Matcher<View> withTextColor(final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public boolean matchesSafely(TextView textView) {
            return color == textView.getCurrentTextColor();
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("Expected Color: " + color);
        }
    };
}
 
Example 12
Source File: WatcherElement.java    From debugdrawer with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	TextView view = parent.titleView;
	int currentColor = view.getCurrentTextColor();
	if (currentColor == originalColor) {
		view.setTextColor(flashColor);
	} else {
		view.setTextColor(originalColor);
	}

	handler.postDelayed(this, 1000);
}
 
Example 13
Source File: TextResize.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 14
Source File: NotificationWidget.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return {@code true} if given {@link android.widget.TextView} have dark
 * color of text (average of RGB is lower than 127), {@code false} otherwise.
 */
protected boolean hasDarkTextColor(TextView textView) {
    int color = textView.getCurrentTextColor();
    return getAverageRgb(color) < 127;
}
 
Example 15
Source File: PickTimeFragment.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dialog_time_picker, container);
    mTVTimeToJump = (TextView) view.findViewById(R.id.tim_pic_timetojump);
    ((TextView)view.findViewById(R.id.tim_pic_title)).setText(getTitle());
    ((ImageView) view.findViewById(R.id.tim_pic_icon)).setImageResource(Util.getResourceFromAttribute(getActivity(), getIcon()));

    view.findViewById(R.id.tim_pic_1).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_1).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_2).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_2).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_3).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_3).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_4).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_4).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_5).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_5).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_6).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_6).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_7).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_7).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_8).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_8).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_9).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_9).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_0).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_0).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_00).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_00).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_30).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_30).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_cancel).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_cancel).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_delete).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_delete).setOnFocusChangeListener(this);
    view.findViewById(R.id.tim_pic_ok).setOnClickListener(this);
    view.findViewById(R.id.tim_pic_ok).setOnFocusChangeListener(this);

    mTextColor = mTVTimeToJump.getCurrentTextColor();

    getDialog().setCancelable(true);
    getDialog().setCanceledOnTouchOutside(true);
    if (getDialog() != null) {
        int dialogWidth = getResources().getDimensionPixelSize(R.dimen.dialog_time_picker_width);
        int dialogHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
        getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
        getDialog().getWindow().setBackgroundDrawableResource(Util.getResourceFromAttribute(getActivity(), R.attr.rounded_bg));
    }
    return view;
}
 
Example 16
Source File: UserLogAdapter.java    From 600SeriesAndroidUploader with MIT License 4 votes vote down vote up
private void initDrawables(TextView tv) {

        largeText = mContext.getResources().getConfiguration().fontScale > 1;

        int c = tv.getCurrentTextColor();
        float s = tv.getTextSize();

        float[] hsv = new float[3];
        Color.colorToHSV(c, hsv);

        int normal = c >> 24 & 0xFF;
        if (normal == 0xFF) normal = Color.HSVToColor(new float[] {0.f, 0.f, hsv[2]}) & 0xFF;
        int high = (int) (HIGHLIGHT *normal);
        int low = (int) (LOWLIGHT * normal);
        if (high > 0xFF) high = 0xFF;
        if (low > 0xFF) low = 0xFF;

        cNormal = Color.HSVToColor(normal, new float[] {hsv[0], hsv[1], 1.f});
        cHigh = Color.HSVToColor(high, new float[] {hsv[0], hsv[1], 1.f});
        cLow = Color.HSVToColor(low, new float[] {hsv[0], hsv[1], 1.f});

        Log.d(TAG, String.format("textColor: %08x textSize: %s normal: %08x high: %08x low: %08x", c, s, cNormal, cHigh, cLow));

        cEestimate = Color.HSVToColor(high, ESTIMATE_HSV);
        cIsig = Color.HSVToColor(normal, ISIG_HSV);
        cHistory = Color.HSVToColor(normal, HISTORY_HSV);
        cPushover = Color.HSVToColor(normal, PUSHOVER_HSV);

        iBounds = (int) (s * 1.2);
        iOffsetXDp = 0;
        iOffsetYDp = 3;

        iWARN = icon("ion_alert_circled", Color.HSVToColor(high, WARN_HSV));
        iINFO = icon("ion_information_circled", cHigh);
        iNOTE = icon("ion_document", Color.HSVToColor(high, NOTE_HSV));
        iHELP = icon("ion_ios_lightbulb", cHigh);
        iCGM = icon("ion_ios_pulse_strong", Color.HSVToColor(high, CGM_HSV));
        iHEART = icon("ion_heart", Color.HSVToColor(high, HEART_HSV));
        iSHARE = icon("ion_android_share_alt", Color.HSVToColor(normal, SHARE_HSV));
        iREFRESH = icon("ion_refresh", cNormal);
        iSETTING = icon("ion_android_settings", cHigh);

        init = true;
    }
 
Example 17
Source File: TextViewUtils.java    From react-native-navigation with MIT License 4 votes vote down vote up
@ColorInt
public static int getTextColor(TextView view) {
    SpannedString text = new SpannedString(view.getText());
    ForegroundColorSpan[] spans = text.getSpans(0, text.length(), ForegroundColorSpan.class);
    return spans.length == 0 ? view.getCurrentTextColor() : spans[0].getForegroundColor();
}
 
Example 18
Source File: TestUtilsMatchers.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
/** Returns a matcher that matches TextViews with the specified text color. */
public static Matcher<View> withTextColor(final @ColorInt int textColor) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    private String failedCheckDescription;

    @Override
    public void describeTo(final Description description) {
      description.appendText(failedCheckDescription);
    }

    @Override
    public boolean matchesSafely(final TextView view) {
      final @ColorInt int ourTextColor = view.getCurrentTextColor();
      if (ourTextColor != textColor) {
        int ourAlpha = Color.alpha(ourTextColor);
        int ourRed = Color.red(ourTextColor);
        int ourGreen = Color.green(ourTextColor);
        int ourBlue = Color.blue(ourTextColor);

        int expectedAlpha = Color.alpha(textColor);
        int expectedRed = Color.red(textColor);
        int expectedGreen = Color.green(textColor);
        int expectedBlue = Color.blue(textColor);

        failedCheckDescription =
            "expected color to be ["
                + expectedAlpha
                + ","
                + expectedRed
                + ","
                + expectedGreen
                + ","
                + expectedBlue
                + "] but found ["
                + ourAlpha
                + ","
                + ourRed
                + ","
                + ourGreen
                + ","
                + ourBlue
                + "]";
        return false;
      }
      return true;
    }
  };
}
 
Example 19
Source File: ViewHierarchyElementAndroid.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
Builder(int id, @Nullable ViewHierarchyElementAndroid parent, View fromView) {
  // Bookkeeping
  this.id = id;
  this.parentId = (parent != null) ? parent.getId() : null;

  this.drawingOrder = null;

  // API 16+ properties
  this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

  // API 11+ properties
  this.backgroundDrawableColor =
      (AT_11 && (fromView != null) && (fromView.getBackground() instanceof ColorDrawable))
          ? ((ColorDrawable) fromView.getBackground()).getColor()
          : null;

  // Base properties
  this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
  this.className = fromView.getClass().getName();
  this.accessibilityClassName = null;
  this.packageName = fromView.getContext().getPackageName();
  this.resourceName =
      (fromView.getId() != View.NO_ID)
          ? ViewAccessibilityUtils.getResourceNameForView(fromView)
          : null;
  this.contentDescription = SpannableStringAndroid.valueOf(fromView.getContentDescription());
  this.enabled = fromView.isEnabled();
  if (fromView instanceof TextView) {
    TextView textView = (TextView) fromView;
    // Hint text takes precedence if no text is present.
    CharSequence text = textView.getText();
    if (TextUtils.isEmpty(text)) {
      text = textView.getHint();
    }
    this.text = SpannableStringAndroid.valueOf(text);
    this.textSize = textView.getTextSize();

    this.textColor = textView.getCurrentTextColor();
    this.typefaceStyle =
        (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
  } else {
    this.text = null;
    this.textSize = null;
    this.textColor = null;
    this.typefaceStyle = null;
  }

  this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
  this.clickable = fromView.isClickable();
  this.longClickable = fromView.isLongClickable();
  this.focusable = fromView.isFocusable();
  this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
  this.canScrollForward =
      (ViewCompat.canScrollVertically(fromView, 1)
          || ViewCompat.canScrollHorizontally(fromView, 1));
  this.canScrollBackward =
      (ViewCompat.canScrollVertically(fromView, -1)
          || ViewCompat.canScrollHorizontally(fromView, -1));
  this.checkable = (fromView instanceof Checkable);
  this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
  this.hasTouchDelegate = (fromView.getTouchDelegate() != null);
  this.touchDelegateBounds = ImmutableList.of(); // Unavailable from the View API
  this.boundsInScreen = getBoundsInScreen(fromView);
  this.nonclippedHeight = fromView.getHeight();
  this.nonclippedWidth = fromView.getWidth();
  this.actionList = ImmutableList.of(); // Unavailable from the View API
}
 
Example 20
Source File: TextViewColorAdapter.java    From Scoops with Apache License 2.0 4 votes vote down vote up
@Override
public int getColor(TextView view) {
    return view.getCurrentTextColor();
}