aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-10-15 13:21:23 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-10-15 13:21:23 +0000
commit4c2f1f3f70df6408aeeb80b778bcc33ff75df957 (patch)
tree4d763588102af8f60262ecdfb9c5e94e1ca1ca3c /app/src
parent3b0ba561b2c8d66c6785618ffa876313166a2e31 (diff)
downloadinfinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar.gz
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar.bz2
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar.lz
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar.xz
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.tar.zst
infinity-for-reddit-4c2f1f3f70df6408aeeb80b778bcc33ff75df957.zip
Set EditText cursor color in CustomizePostFilterActivity.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java57
-rw-r--r--app/src/main/res/drawable/edit_text_cursor.xml4
2 files changed, 61 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
index c02d0687..862a5603 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
@@ -4,12 +4,15 @@ import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
+import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -29,6 +32,7 @@ import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.r0adkll.slidr.Slidr;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
@@ -371,6 +375,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor();
+ Drawable cursorDrawable = Utils.getTintedDrawable(this, R.drawable.edit_text_cursor, primaryTextColor);
nameTextInputLayout.setBoxStrokeColor(primaryTextColor);
nameTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
nameTextInputEditText.setTextColor(primaryTextColor);
@@ -423,6 +428,58 @@ public class CustomizePostFilterActivity extends BaseActivity {
maxAwardsTextInputLayout.setBoxStrokeColor(primaryTextColor);
maxAwardsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
maxAwardsTextInputEditText.setTextColor(primaryTextColor);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ nameTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ titleExcludesStringsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ titleExcludesRegexTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ excludesSubredditsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ excludesUsersTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ excludesFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ containsFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ excludesDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ minVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ maxVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ minCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ maxCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ minAwardsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ maxAwardsTextInputEditText.setTextCursorDrawable(cursorDrawable);
+ } else {
+ setCursorDrawableColor(nameTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(titleExcludesStringsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(titleExcludesRegexTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(excludesSubredditsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(excludesUsersTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(excludesFlairsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(containsFlairsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(excludesDomainsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(minVoteTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(maxVoteTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(minCommentsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(maxCommentsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(minAwardsTextInputEditText, primaryTextColor);
+ setCursorDrawableColor(maxAwardsTextInputEditText, primaryTextColor);
+ }
+ }
+
+ public static void setCursorDrawableColor(EditText editText, int color) {
+ try {
+ Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
+ fCursorDrawableRes.setAccessible(true);
+ int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
+ Field fEditor = TextView.class.getDeclaredField("mEditor");
+ fEditor.setAccessible(true);
+ Object editor = fEditor.get(editText);
+ Class<?> clazz = editor.getClass();
+ Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
+ fCursorDrawable.setAccessible(true);
+ Drawable[] drawables = new Drawable[2];
+ drawables[0] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
+ drawables[1] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
+ drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ drawables[1].setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ fCursorDrawable.set(editor, drawables);
+ } catch (Throwable ignored) { }
}
@Override
diff --git a/app/src/main/res/drawable/edit_text_cursor.xml b/app/src/main/res/drawable/edit_text_cursor.xml
new file mode 100644
index 00000000..10700fe8
--- /dev/null
+++ b/app/src/main/res/drawable/edit_text_cursor.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <size android:width="2dp" />
+</shape> \ No newline at end of file