Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ThemedTextView and set the text color based on background color luma #2681

Open
EmmanuelMess opened this issue Jul 15, 2021 · 0 comments
Labels
Area-UIUX Related to user interface/experience (e.g. dialogs, notifications). Issue-Bug Related unexpected behavior or something worth investigating. Issue-Easy (good first issue) Beginners welcome! Issues with relative low difficulty.

Comments

@EmmanuelMess
Copy link
Member

  /**
   * Correctly sets text color based on a given background color so that the
   * user can see the text correctly
   */
  @JvmStatic
  fun setIntelligentTextColor(context: Context, textView: TextView, backgroundColor: Int) {
    val red = Color.red(backgroundColor) * 0.299f
    val green = Color.green(backgroundColor) * 0.587f
    val blue = Color.blue(backgroundColor) * 0.114f

    val luma = (red + green + blue) / 255.0f

    val color = if(luma > 0.5) android.R.color.black else android.R.color.white

    textView.setTextColor(Utils.getColor(context, color))
  }
@EmmanuelMess EmmanuelMess added Area-UIUX Related to user interface/experience (e.g. dialogs, notifications). Issue-Easy (good first issue) Beginners welcome! Issues with relative low difficulty. Issue-Bug Related unexpected behavior or something worth investigating. labels Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-UIUX Related to user interface/experience (e.g. dialogs, notifications). Issue-Bug Related unexpected behavior or something worth investigating. Issue-Easy (good first issue) Beginners welcome! Issues with relative low difficulty.
Projects
None yet
Development

No branches or pull requests

1 participant