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

The following examples show how to use android.widget.TextView#getCurrentTextColor() .
Example 1
Project: VCL-Android   File: PlaybackSpeedDialog.java    License: 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 2
Project: prayer-times-android   File: OngoingNotificationsReceiver.java    License: 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 3
Project: PaymentKit-Droid   File: AnimUtils.java    License: 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 4
Project: animation-samples   File: TextResize.java    License: 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 5
Project: Last-Launcher   File: LauncherActivity.java    License: 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 6
Project: debugdrawer   File: WatcherElement.java    License: 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 7
Project: restcomm-android-sdk   File: BasicUITests.java    License: 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 8
Project: atlas   File: TextResize.java    License: 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 9
Project: android-instant-apps   File: TextResize.java    License: 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
Project: android-login   File: TextSizeTransition.java    License: 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 11
Project: friendspell   File: CustomMatchers.java    License: 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 12
Project: Scoops   File: TestUtils.java    License: 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 13
Project: android-sliderview   File: SlidingTabLayout.java    License: 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 14
Project: Accessibility-Test-Framework-for-Android   File: ViewHierarchyElementAndroid.java    License: 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 15
Project: HeadsUp   File: NotificationWidget.java    License: 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 16
Project: VCL-Android   File: PickTimeFragment.java    License: 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 17
Project: 600SeriesAndroidUploader   File: UserLogAdapter.java    License: 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 18
Project: react-native-navigation   File: TextViewUtils.java    License: 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 19
Project: material-components-android   File: TestUtilsMatchers.java    License: 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 20
Project: Scoops   File: TextViewColorAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int getColor(TextView view) {
    return view.getCurrentTextColor();
}