Skip to content

Commit

Permalink
Merge pull request #173 from Ryosuke839/#164-process-text-optional
Browse files Browse the repository at this point in the history
Make intent-filter android.intent.action.PROCESS_TEXT optional
  • Loading branch information
Ryosuke839 authored Apr 7, 2024
2 parents 6036141 + d2ccf8a commit b949fec
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
22 changes: 12 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.PROCESS_TEXT" />
</intent>
</queries>

Expand Down Expand Up @@ -65,20 +65,22 @@

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<activity-alias
android:name="UnicodeActivityAlias"
android:targetActivity="UnicodeActivity"
android:enabled="true"
android:exported="true">

<intent-filter android:icon="@mipmap/ic_launcher">
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
</activity-alias>

<activity android:name="SettingActivity"
android:parentActivityName=".UnicodeActivity" />
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/jp/ddo/hotmist/unicodepad/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package jp.ddo.hotmist.unicodepad

import android.app.AlertDialog
import android.content.ComponentName
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -33,7 +35,6 @@ import androidx.preference.*
import org.json.JSONException
import org.json.JSONObject
import java.io.IOException
import java.util.*

class SettingActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -111,6 +112,7 @@ class SettingActivity : BaseActivity() {
setText(findPreference("checker")!!)
setText(findPreference("recentsize")!!)
setEntry(findPreference("scroll")!!)
findPreference<Preference>("process_text")!!.onPreferenceChangeListener = this
findPreference<Preference>("legal_app")!!.also {
it.setOnPreferenceClickListener {
openPage("https://github.com/Ryosuke839/UnicodePad")
Expand Down Expand Up @@ -164,6 +166,16 @@ class SettingActivity : BaseActivity() {
Toast.makeText(activity, R.string.theme_title, Toast.LENGTH_SHORT).show()
activity.setResult(RESULT_FIRST_USER)
}
if (key == "process_text") {
val packageName = activity.packageName
val newState =
if (newValue as Boolean) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED
activity.packageManager.setComponentEnabledSetting(
ComponentName(packageName, "$packageName.UnicodeActivityAlias"),
newState, PackageManager.DONT_KILL_APP
)
return true
}
}
preference.summary = if (preference is ListPreference) preference.entries[preference.findIndexOfValue(newValue.toString())] else newValue.toString()
return true
Expand Down Expand Up @@ -243,6 +255,7 @@ class SettingActivity : BaseActivity() {
it.put("ime", if (pref.contains("ime")) pref.getBoolean("ime", true) else null)
it.put("clear", if (pref.contains("clear")) pref.getBoolean("clear", true) else null)
it.put("buttons", if (pref.contains("buttons")) pref.getBoolean("buttons", true) else null)
it.put("process_text", if (pref.contains("process_text")) pref.getBoolean("process_text", true) else null)
it.put("scroll", pref.getString("scroll", null))
it.put("recentsize", pref.getString("recentsize", null))
})
Expand Down Expand Up @@ -366,6 +379,7 @@ class SettingActivity : BaseActivity() {
(it.opt("ime") as? Boolean)?.let { bool -> edit.putBoolean("ime", bool) }
(it.opt("clear") as? Boolean)?.let { bool -> edit.putBoolean("clear", bool) }
(it.opt("buttons") as? Boolean)?.let { bool -> edit.putBoolean("buttons", bool) }
(it.opt("process_text") as? Boolean)?.let { bool -> edit.putBoolean("process_text", bool) }
(it.opt("scroll") as? String)?.let { str -> edit.putString("scroll", str) }
(it.opt("recentsize") as? String)?.let { str -> edit.putString("recentsize", str) }
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@
<string name="ime_desc">IMEを無効化</string>
<string name="clear_desc">全削除ボタンを表示</string>
<string name="buttons_desc">ボタン行を表示</string>
<string name="process_text_desc">テキスト選択メニューから起動する</string>
<string name="malformed">ZIP内のファイル名が破損</string>
<string name="legal">法的表記</string>
<string name="legal_uni2">本アプリケーションはUnicode Data Fileの改変された版を含んでいます。
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
<string name="ime_desc">Disable IME</string>
<string name="clear_desc">Show clear button</string>
<string name="buttons_desc">Show button row</string>
<string name="process_text_desc">Launch from text selection context menu</string>
<string name="clear" translatable="false">⌧</string>
<string name="erase" translatable="false">⌫</string>
<string name="notacharacter" translatable="false">&lt;not a character&gt;</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
android:inputType="number"
android:summary=""
android:title="@string/recent_desc" />
<CheckBoxPreference
android:defaultValue="true"
android:key="process_text"
android:title="@string/process_text_desc" />
</PreferenceCategory>
<PreferenceCategory
android:key="legal"
Expand Down

0 comments on commit b949fec

Please sign in to comment.