mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Add avatar picker and defaults.
This commit is contained in:
committed by
Greyson Parrelli
parent
0093e1d3eb
commit
ed23c3fe7c
@@ -1,8 +1,16 @@
|
||||
package org.signal.core.util;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.InputFilter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -17,4 +25,41 @@ public final class EditTextUtil {
|
||||
filters.add(new GraphemeClusterLimitFilter(maximumGraphemes));
|
||||
text.setFilters(filters.toArray(new InputFilter[0]));
|
||||
}
|
||||
|
||||
public static void setCursorColor(EditText text, @ColorInt int colorInt) {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
Drawable cursorDrawable = text.getTextCursorDrawable().mutate();
|
||||
|
||||
cursorDrawable.setColorFilter(new PorterDuffColorFilter(colorInt, PorterDuff.Mode.SRC_IN));
|
||||
text.setTextCursorDrawable(cursorDrawable);
|
||||
} else {
|
||||
setCursorColorViaReflection(text, colorInt);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setCursorColorViaReflection(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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user