WIP: Search in Card Browser for highlighted text from Review mode#4708
WIP: Search in Card Browser for highlighted text from Review mode#4708timrae merged 5 commits intoankidroid:masterfrom
Conversation
|
Thanks for having a go at this. It took me a while to find the article, but this is the way that I was imagining it should be implemented in my comment on #4496. By default, that would add an item to the floating action bar whenever text is selected inside any app, which may not be what users want. But according to the comments section of that article, an issue was added and subsequently fixed that would allow you to limit the visibility of the intents to your own app if you set |
|
FYI, this may also be helpful, though I'm not sure how up-to-date it is. |
b9778fe to
bd2842c
Compare
|
Okay, I rewrote it to a very simple implementation based on It’s still visible from other apps because the hiding functionality is not in Android yet. I also don’t know if I have implemented it in a backwards-compatible manner, since I only have a new device to test it on. |
timrae
left a comment
There was a problem hiding this comment.
ACTION_PROCESS_TEXT is only available from API 23, so you'll need to move any code that uses it to our Compat classes.
|
Normally we just test with the simulator during development |
|
|
8ad8c02 to
ac8eb01
Compare
|
Okay, I moved the |
|
Almost, but that's not quite going to work; you need to instantiate the correct Compat class for the correct API using CompatHelper: |
ac8eb01 to
8b7f2f5
Compare
|
Right. Added v23 to the dispatcher and switched to the singleton method. |
|
@timrae Any further remarks? |
|
Thanks for reminding me. Have you tested it properly with the simulator
running Android 4.0? I'm also still unsure about this `exported` issue...
When was support for this added into the Android framework? One of us will
need to check the framework code.
I need to make a thread on the forum about the change in minimum API, and
we should probably make a maintenance release soon before dropping support
for 2.3.
…On 4/10/2017 01:47, "Profpatsch" ***@***.***> wrote:
@timrae <https://github.com/timrae> Any further remarks?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4708 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACsA4ubBc3sRoiwFvucpcWC4WwZha4Pzks5somU6gaJpZM4PdL3B>
.
|
|
I've made the announcement that Android 4.0 will be the new minimum going forward. We can bump the minimum again to 4.1 whenever the need arises. |
I’m actually not sure if it wouldn’t be better to export it. That way, if you find e.g. a word in your browser, you can highlight it and directly see if you already have it in your vocab list, which is awesome. Update: Right now the browser crashes once I click “Card Browser” though, probably a |
This sounds like it could be useful if we could streamline the process of note addition from the browser a bit better, so that when you choose "Add note" from the browser while there is something in the search box, it automatically populates that text into the first field of the note editor. |
There's no way to customize it without changing the Activity name?
What's the stacktrace? |
At least that’s what the article says: I can’t find any documentation other than https://developer.android.com/reference/android/content/Intent.html#ACTION_PROCESS_TEXT and that medium article; apparently Medium is the way the Android team distributes their docs?
|
|
Hmmm, this stack trace was generated with
|
|
I'm a bit confused, as I would have thought that on older versions of Android the |
I understand now, I should have changed the |
Calling an `ACTION_PROCESS_TEXT` intent from other applications was still possible, but they would crash with a `SecurityException` because the Activity was not exported.
|
Instead of that wrapper function inside the Compat classes, I think it might be more simple to just port over the missing constants from the framework. public class CompatV10 implements Compat {
public static final String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT";
public static final String EXTRA_PROCESS_TEXT = "android.intent.extra.PROCESS_TEXT";
// ....
}
public class CompatV23 implements Compat {
public static final String ACTION_PROCESS_TEXT = Intent.ACTION_PROCESS_TEXT;
public static final String EXTRA_PROCESS_TEXT = Intent.EXTRA_PROCESS_TEXT;
// ...
}Then you can write the code more naturally inside the reviewer using |
Ah right, yes, the activity itself... |
So no need to copy the strings, right? |
Sorry I'm not following your question... Did you see the code sample I posted above? |
Yeah, but I’m not quite sure what this would simplify and how. Do you mean I should remove this function alltogether? |
|
Yes, the only part of the function that is not available on all APIs is the two constants, right? |
|
Ah! Now I get it. Should have gone to bed earlier yesterday. :) |
|
I implemented it; the final strings have to be in the interface, otherwise they cannot be used with Tested with KitKat Emulator and on API 23 device. |
| Compat compat = CompatHelper.getCompat(); | ||
| if (intent.getAction() == compat.ACTION_PROCESS_TEXT) { | ||
| CharSequence search = intent.getCharSequenceExtra(compat.EXTRA_PROCESS_TEXT); | ||
| assert search != null; |
There was a problem hiding this comment.
Thanks, this is much clearer! I think we don't really want to crash if an app developer accidentally doesn't add EXTRA_PROCESS_TEXT... Can you get rid of the assert and just write the following?
if (search != null && search.length() != 0) {
Last nitpick I promise :)
There was a problem hiding this comment.
I think we don't really want to crash if an app developer accidentally doesn't add EXTRA_PROCESS_TEXT
That’s something that should never happen, which is why I use an assert.
From the ACTION_PROCESS_TEXT documentation:
Activity Action: Process a piece of text.
Input: EXTRA_PROCESS_TEXT contains the text to be processed. EXTRA_PROCESS_TEXT_READONLY states if the resulting text will be read-only.
Output: EXTRA_PROCESS_TEXT contains the processed text.
There was a problem hiding this comment.
From the ACTION_PROCESS_TEXT documentation
It doesn't actually say anywhere there that it won't be null, or that it's guaranteed to be present. In fact it will only be there if the developer sending the intent calls putExtra(). You can see this from the getCharSequenceExtra() documentation, which says:
(returns) the value of an item that previously added with putExtra() or null if no CharSequence value was found.
There was a problem hiding this comment.
FYI: In general, we try to only use assert() to pick up programming errors by us, whereas this would be picking up programming errors by others (i.e. other apps, android framework).
| import com.ichi2.async.DeckTask.TaskData; | ||
| import com.ichi2.compat.Compat; | ||
| import com.ichi2.compat.CompatHelper; | ||
| import com.ichi2.compat.CompatV23; |
There was a problem hiding this comment.
Oh I guess this import isn't needed anymore btw
| import android.annotation.TargetApi; | ||
| import android.content.Intent; | ||
|
|
||
| import timber.log.Timber; |
There was a problem hiding this comment.
The compiler doesn’t show these as warnings … :(
There was a problem hiding this comment.
Yeah, most compilers don't unfortunately, even in other programming languages...You can run "optimize imports" with Android Studio which will take care of this for you automatically.
8bff82d to
18c5e08
Compare
|
Unneeded imports & Want to say that I’m impressed by the amount attention and help you have given for this rather minor feature, @timrae. |
| if (intent.getAction() == compat.ACTION_PROCESS_TEXT) { | ||
| CharSequence search = intent.getCharSequenceExtra(compat.EXTRA_PROCESS_TEXT); | ||
| if (search != null && search.length() != 0) { | ||
| Timber.d("CardBrowser :: Called with search intent", search); |
There was a problem hiding this comment.
I guess you forgot to add the %s formatting string here so that the content of search gets printed out...?
There was a problem hiding this comment.
Oh, it’s a format string. Wasn’t clear from the documentation, thought it would display them automatically in a smart way.
It is enough to mock the Intent string constants for older API versions, this way the logic stays at the correct place.
18c5e08 to
971a53e
Compare
|
Thank you! :) |
|
Are you interested in implementing the idea I posted above to allow adding a new note from the content of the browser search bar? |
At the moment I’m short on time, but I’ll put it on my side-project list. (The tab with this question has been open in my browser for nearly a month now. :)) |

I tried my hands at #4496, but that’s as far as I can get. See commit message for the problem.
Basically I can’t find a way to add the callbacks to the action mode. Also, I have no idea what action mode I’m looking at.
I thought about tracking for long presses, but then the question becomes how to still get the text selection functionality.
@timrae: Maybe you have an idea how to implement this functionality?