Skip to content

Commit 68233c8

Browse files
committed
lookup text by ProcessText intent
1 parent 36a2acd commit 68233c8

2 files changed

Lines changed: 21 additions & 54 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
<action android:name="android.intent.action.WEB_SEARCH" />
8484
<category android:name="android.intent.category.DEFAULT" />
8585
<category android:name="android.intent.category.BROWSABLE" />
86+
</intent-filter>
87+
<intent-filter >
88+
<action android:name="android.intent.action.PROCESS_TEXT"/>
89+
<category android:name="android.intent.category.DEFAULT" />
90+
<data android:mimeType="text/plain" />
8691
</intent-filter>
8792
</activity>
8893

app/src/main/java/landau/sweb/MainActivity.java

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import android.content.ActivityNotFoundException;
1313
import android.content.BroadcastReceiver;
1414
import android.content.ClipData;
15-
import android.content.ClipboardManager;
1615
import android.content.ContentValues;
1716
import android.content.Context;
1817
import android.content.DialogInterface;
@@ -159,9 +158,9 @@
159158
import net.gnu.util.Mht2Htm;
160159
import net.gnu.util.Util;
161160
import org.apache.commons.compress.PasswordRequiredException;
161+
import org.geometerplus.android.fbreader.DictionaryUtil;
162162
import org.json.JSONArray;
163163
import org.json.JSONException;
164-
import org.geometerplus.android.fbreader.DictionaryUtil;
165164

166165
public class MainActivity extends ParentActivity {
167166
private PowerManager.WakeLock mWakeLock;
@@ -218,16 +217,7 @@ public class MainActivity extends ParentActivity {
218217
// //todo jump to the picture view page
219218
// }
220219
// }
221-
private ClipboardManager mClipboard;
222-
private String clipData = "";
223220

224-
private ClipboardManager.OnPrimaryClipChangedListener mPrimaryChangeListener
225-
= new ClipboardManager.OnPrimaryClipChangedListener() {
226-
public void onPrimaryClipChanged() {
227-
updateClipData(true);
228-
}
229-
};
230-
231221
private static class CrawlerInfo implements Comparable<CrawlerInfo> {
232222

233223
final String url;
@@ -4003,10 +3993,14 @@ public void onSystemUiVisibilityChange(int p1) {
40033993
updateFullScreen();}});
40043994
isFullscreen = false;
40053995
isNightMode = prefs.getBoolean("night_mode", false);
4006-
mClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
4007-
mClipboard.addPrimaryClipChangedListener(mPrimaryChangeListener);
4008-
DictionaryUtil.init(this, null);
40093996

3997+
DictionaryUtil.init(this, null);
3998+
final CharSequence text = getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
3999+
ExceptionLogger.d(TAG, "onCreate text " + text);
4000+
if (text != null) {
4001+
DictionaryUtil.openTextInDictionary(MainActivity.this, text+"", false, 100, 10);
4002+
}
4003+
40104004
webviews = (FrameLayout) findViewById(R.id.webviews);
40114005
currentTabIndex = 0;
40124006
address = (ViewGroup)findViewById(R.id.address);
@@ -4215,16 +4209,6 @@ public void run() {
42154209
dialog.dismiss();
42164210
}
42174211
}));
4218-
actions.add(new MenuAction("Lookup", 0, new Runnable() {
4219-
@Override
4220-
public void run() {
4221-
if (clipData != null && clipData.length() > 0) {
4222-
DictionaryUtil.openTextInDictionary(MainActivity.this, clipData, false, 100, 10);
4223-
} else {
4224-
Toast.makeText(MainActivity.this, "Nothing to translate", Toast.LENGTH_SHORT).show();
4225-
}
4226-
}
4227-
}));
42284212
actions.add(new MenuAction("Save as Pdf", 0, new Runnable() {
42294213
@Override
42304214
public void run() {
@@ -5282,7 +5266,7 @@ public void run() {
52825266
@Override
52835267
protected void onResume() {
52845268
super.onResume();
5285-
if (printJob != null && printBtnPressed) {
5269+
if (printJob != null && printBtnPressed) {
52865270
if (printJob.isCompleted()) {
52875271
AndroidUtils.toast(this, "Printing Completed");
52885272
} else if (printJob.isStarted()) {
@@ -5322,7 +5306,6 @@ protected void onDestroy() {
53225306
if (placesDb != null) {
53235307
placesDb.close();
53245308
}
5325-
mClipboard.removePrimaryClipChangedListener(mPrimaryChangeListener);
53265309
}
53275310

53285311
@Override
@@ -5462,33 +5445,6 @@ public void run() {
54625445
}
54635446
}
54645447

5465-
void updateClipData(boolean updateType) {
5466-
final ClipData clip = mClipboard.getPrimaryClip();
5467-
// String[] mimeTypes = clip != null ? clip.getDescription().filterMimeTypes("*/*") : null;
5468-
// if (mimeTypes != null) {
5469-
// mMimeTypes.setText("");
5470-
// for (int i=0; i<mimeTypes.length; i++) {
5471-
// if (i > 0) {
5472-
// mMimeTypes.append("\n");
5473-
// }
5474-
// mMimeTypes.append(mimeTypes[i]);
5475-
// }
5476-
// } else {
5477-
// mMimeTypes.setText("NULL");
5478-
// }
5479-
5480-
if (clip != null) {
5481-
final ClipData.Item item = clip.getItemAt(0);
5482-
final CharSequence text = item.getText();
5483-
clipData = text == null ? "" : (text + "").trim();
5484-
if (autoLookup) {
5485-
if (clipData != null && clipData.length() > 0) {
5486-
DictionaryUtil.openTextInDictionary(this, clipData, false, 100, 10);
5487-
}
5488-
}
5489-
}
5490-
}
5491-
54925448
//image = null, all=.
54935449
private void log(final String pat, final boolean showImages) {
54945450
final Tab currentTab = getCurrentTab();
@@ -6724,7 +6680,13 @@ private void closeTab(WebView webView, final int tabIndex) {
67246680

67256681
@Override
67266682
protected void onNewIntent(final Intent intent) {
6727-
loadIntent(intent);
6683+
final CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
6684+
ExceptionLogger.d(TAG, "onNewIntent text " + text);
6685+
if (text != null) {
6686+
DictionaryUtil.openTextInDictionary(MainActivity.this, text+"", false, 100, 10);
6687+
} else {
6688+
loadIntent(intent);
6689+
}
67286690
}
67296691

67306692
private void loadIntent(final Intent intent) {

0 commit comments

Comments
 (0)