Skip to content

Commit 573315f

Browse files
committed
editable text support
for #191
1 parent 44a3808 commit 573315f

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

app/src/main/AndroidManifest.xml

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
<category android:name="android.intent.category.DEFAULT" />
8787
<category android:name="android.intent.category.APP_BROWSER" />
8888
</intent-filter>
89+
<intent-filter>
90+
<action android:name="android.intent.action.PROCESS_TEXT" />
91+
92+
<category android:name="android.intent.category.DEFAULT" />
93+
<data android:mimeType="text/plain" />
94+
</intent-filter>
8995
</activity>
9096
<activity
9197
android:name=".activities.MainActivity"

app/src/main/java/com/trianguloy/urlchecker/activities/AutomationActivity.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
3737
// smaller easter egg
3838
findViewById(R.id.icon).setOnClickListener(icon -> {
3939
var anim = ValueAnimator.ofFloat(0, 360);
40-
anim.addUpdateListener(valueAnimator -> {
41-
icon.setRotation((float) valueAnimator.getAnimatedValue());
42-
});
40+
anim.addUpdateListener(valueAnimator -> icon.setRotation((float) valueAnimator.getAnimatedValue()));
4341
anim.setInterpolator(new AnticipateOvershootInterpolator());
4442
anim.setDuration(1000);
4543
anim.start();

app/src/main/java/com/trianguloy/urlchecker/activities/SettingsActivity.java

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.os.Build;
67
import android.os.Bundle;
78
import android.util.Pair;
89
import android.view.MenuItem;
@@ -34,6 +35,11 @@ public static GenericPref.Int WIDTH_PREF(Context cntx) {
3435
return new GenericPref.Int("width", WindowManager.LayoutParams.WRAP_CONTENT, cntx);
3536
}
3637

38+
/** The sync process-text pref */
39+
public static GenericPref.Bool SYNC_PROCESSTEXT_PREF(Context cntx) {
40+
return new GenericPref.Bool("syncProcessText", true, cntx);
41+
}
42+
3743

3844
@Override
3945
protected void onCreate(Bundle savedInstanceState) {
@@ -49,6 +55,12 @@ protected void onCreate(Bundle savedInstanceState) {
4955
configureLocale();
5056
Animations.ANIMATIONS(this).attachToSwitch(findViewById(R.id.animations));
5157

58+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
59+
SYNC_PROCESSTEXT_PREF(this).attachToSwitch(findViewById(R.id.processText));
60+
} else {
61+
findViewById(R.id.processText).setVisibility(View.GONE);
62+
}
63+
5264
// if this was reloaded, some settings may have change, so reload previous one too
5365
if (AndroidSettings.wasReloaded(this)) AndroidSettings.markForReloading(this);
5466
}

app/src/main/java/com/trianguloy/urlchecker/dialogs/MainDialog.java

+13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.trianguloy.urlchecker.dialogs;
22

3+
import static com.trianguloy.urlchecker.activities.SettingsActivity.SYNC_PROCESSTEXT_PREF;
34
import static com.trianguloy.urlchecker.activities.SettingsActivity.WIDTH_PREF;
45

56
import android.animation.ObjectAnimator;
67
import android.animation.ValueAnimator;
78
import android.app.Activity;
89
import android.app.AlertDialog;
910
import android.content.Intent;
11+
import android.os.Build;
1012
import android.os.Bundle;
1113
import android.util.ArrayMap;
1214
import android.view.View;
@@ -183,6 +185,13 @@ public void onNewUrl(UrlData newUrlData) {
183185
break;
184186
}
185187

188+
// if in text_process mode, update text unless disabled
189+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
190+
&& SYNC_PROCESSTEXT_PREF(this).get()
191+
&& !getIntent().getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true)) {
192+
setResult(RESULT_OK, new Intent().putExtra(Intent.EXTRA_PROCESS_TEXT, urlData.url));
193+
}
194+
186195
// end, reset
187196
updating = 0;
188197
}
@@ -381,6 +390,10 @@ private Set<String> getOpenUrl() {
381390
var links = AndroidUtils.getLinksFromText(sharedText);
382391
if (links.isEmpty()) links.add(sharedText.trim()); // no links? just use the whole text, the user requested the app so...
383392
return links;
393+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Intent.ACTION_PROCESS_TEXT.equals(action)) {
394+
// process text
395+
var text = getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
396+
return text == null ? Collections.emptySet() : Set.of(text.toString());
384397
} else {
385398
// other, check data
386399
var uri = intent.getData();

app/src/main/res/layout/activity_settings.xml

+10-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
android:layout_width="match_parent"
8686
android:layout_height="wrap_content"
8787
android:layout_weight="1"
88-
android:max="100" />
88+
android:max="100"
89+
android:padding="@dimen/smallPadding" />
8990

9091
<FrameLayout
9192
android:layout_width="match_parent"
@@ -127,12 +128,16 @@
127128
android:id="@+id/animations"
128129
android:layout_width="match_parent"
129130
android:layout_height="wrap_content"
130-
android:paddingStart="@dimen/smallPadding"
131-
android:paddingLeft="@dimen/smallPadding"
132-
android:paddingEnd="@dimen/smallPadding"
133-
android:paddingRight="@dimen/smallPadding"
131+
android:padding="@dimen/smallPadding"
134132
android:text="@string/txt_animation" />
135133

134+
<Switch
135+
android:id="@+id/processText"
136+
android:layout_width="match_parent"
137+
android:layout_height="wrap_content"
138+
android:padding="@dimen/smallPadding"
139+
android:text="@string/txt_processText" />
140+
136141
<FrameLayout
137142
android:layout_width="match_parent"
138143
android:layout_height="match_parent"

app/src/main/res/values-es/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Traducciones: %2$s."</string>
5656
<string name="spin_dynamicWidth">Dinámico</string>
5757
<string name="txt_locale">Idioma:</string>
5858
<string name="txt_animation">Activar animaciones</string>
59+
<string name="txt_processText">Sincronizar url con texto editable (cuando la app se abre al mantener pulsado texto en un cuadro de entrada)</string>
5960
<!--
6061
generic
6162
-->

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Translations: %2$s."</string>
5656
<string name="spin_dynamicWidth">Dynamic</string>
5757
<string name="txt_locale">Locale:</string>
5858
<string name="txt_animation">Enable animations</string>
59+
<string name="txt_processText">Sync url with editable text (when the app is opened by long tapping text on an input textbox)</string>
5960
<string name="btn_tutorialSettings">Repeat tutorial</string>
6061
<string name="btn_backupRestore">Backup / Restore</string>
6162
<!--

0 commit comments

Comments
 (0)