-
Notifications
You must be signed in to change notification settings - Fork 624
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
Fixed text input on Android, fixed for older Android versions #7204
Open
wuwbobo2021
wants to merge
4
commits into
slint-ui:master
Choose a base branch
from
wuwbobo2021:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−53
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright © SixtyFPS GmbH <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.FutureTask; | ||
import android.view.ActionMode; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
@@ -16,6 +18,7 @@ | |
import android.content.res.TypedArray; | ||
import android.graphics.BlendMode; | ||
import android.graphics.BlendModeColorFilter; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
import android.text.Editable; | ||
|
@@ -102,7 +105,11 @@ public void hide() { | |
public void setHandleColor(int color) { | ||
Drawable drawable = getDrawable(); | ||
if (drawable != null) { | ||
drawable.setColorFilter(new BlendModeColorFilter(color, BlendMode.SRC_IN)); | ||
if (android.os.Build.VERSION.SDK_INT >= 29) { | ||
drawable.setColorFilter(new BlendModeColorFilter(color, BlendMode.SRC_IN)); | ||
} else { | ||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); | ||
} | ||
setImageDrawable(drawable); | ||
} | ||
} | ||
|
@@ -295,8 +302,9 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) { | |
mode.setTitle(null); | ||
mode.setSubtitle(null); | ||
mode.setTitleOptionalHint(true); | ||
|
||
menu.setGroupDividerEnabled(true); | ||
if (android.os.Build.VERSION.SDK_INT >= 28) { | ||
menu.setGroupDividerEnabled(true); | ||
} | ||
|
||
final TypedArray a = getContext().obtainStyledAttributes(new int[] { | ||
android.R.attr.actionModeCutDrawable, | ||
|
@@ -340,6 +348,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { | |
public void onDestroyActionMode(ActionMode action) { | ||
} | ||
|
||
// Introduced in API level 23 | ||
@Override | ||
public void onGetContentRect(ActionMode mode, View view, Rect outRect) { | ||
outRect.set(selectionRect); | ||
|
@@ -467,6 +476,7 @@ public int color_scheme() { | |
public Rect get_view_rect() { | ||
Rect rect = new Rect(); | ||
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); | ||
// Note: `View.getRootWindowInsets` requires API level 23 or above | ||
WindowInsets insets = mActivity.getWindow().getDecorView().getRootView().getRootWindowInsets(); | ||
if (insets != null) { | ||
int dx = rect.left - insets.getSystemWindowInsetLeft(); | ||
|
@@ -490,17 +500,35 @@ public void run() { | |
} | ||
|
||
public String get_clipboard() { | ||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); | ||
if (clipboard.hasPrimaryClip()) { | ||
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); | ||
return item.getText().toString(); | ||
FutureTask<String> future = new FutureTask<>(new Callable<String>() { | ||
@Override | ||
public String call() throws Exception { | ||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); | ||
if (clipboard.hasPrimaryClip()) { | ||
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); | ||
return item.getText().toString(); | ||
} | ||
return ""; | ||
} | ||
}); | ||
|
||
mActivity.runOnUiThread(future); | ||
try { | ||
return future.get(); // Wait for the result and return it | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return ""; | ||
} | ||
return ""; | ||
} | ||
|
||
public void set_clipboard(String text) { | ||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clip = ClipData.newPlainText(null, text); | ||
clipboard.setPrimaryClip(clip); | ||
mActivity.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clip = ClipData.newPlainText(null, text); | ||
clipboard.setPrimaryClip(clip); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this also work on windows without the .exe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have tested it, it works on Windows 10 indeed.