mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-29 06:44:08 +00:00
android: fix cursor and handle color
On android, the handle is the same as the cursor color and the cursor color is usually the "accent" color. We can't know the accent color from the native code, but we know the selection color which is the accent color with a lesser opacity.
This commit is contained in:
parent
b988d6d198
commit
9f6b837f7d
4 changed files with 68 additions and 12 deletions
|
@ -7,6 +7,8 @@ import android.view.inputmethod.EditorInfo;
|
|||
import android.view.inputmethod.InputConnection;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.BlendMode;
|
||||
import android.graphics.BlendModeColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Editable;
|
||||
|
@ -85,6 +87,14 @@ class InputHandle extends ImageView {
|
|||
public void hide() {
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
|
||||
public void setHandleColor(int color) {
|
||||
Drawable drawable = getDrawable();
|
||||
if (drawable != null) {
|
||||
drawable.setColorFilter(new BlendModeColorFilter(color, BlendMode.SRC_IN));
|
||||
setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SlintInputView extends View {
|
||||
|
@ -213,6 +223,12 @@ class SlintInputView extends View {
|
|||
mHandle.hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void setHandleColor(int color) {
|
||||
if (mHandle != null) {
|
||||
mHandle.setHandleColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SlintAndroidJavaHelper {
|
||||
|
@ -270,6 +286,16 @@ public class SlintAndroidJavaHelper {
|
|||
int selEnd = Math.max(cursor_position, anchor_position);
|
||||
mInputView.setText(text, selStart, selEnd, preedit_start, preedit_end, input_type);
|
||||
mInputView.setCursorPos(rect_x, rect_y, rect_w, rect_h, show_cursor_handles);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void set_handle_color(int color) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mInputView.setHandleColor(color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue