Skip to content

Commit

Permalink
Merge pull request #98 from Susko3/paste_shortcut
Browse files Browse the repository at this point in the history
Add `Paste` shortcut
  • Loading branch information
Ryosuke839 committed Sep 17, 2022
2 parents cfa4eea + 9ce7c38 commit dee9f34
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<activity android:name="SettingActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.provider.FontRequest
import androidx.core.view.MenuItemCompat
import androidx.core.view.doOnLayout
import androidx.emoji2.text.EmojiCompat
import androidx.emoji2.text.EmojiCompat.InitCallback
import androidx.emoji2.text.FontRequestEmojiCompatConfig
Expand Down Expand Up @@ -212,6 +213,12 @@ class UnicodeActivity : AppCompatActivity() {
pager.setCurrentItem(min(pref.getInt("page", 1), adpPage.count - 1), false)
val it = intent
action = it.action
// handle the paste home screen shortcut
if (action == "jp.ddo.hotmist.unicodepad.intent.action.PASTE") {
val view = findViewById<View>(android.R.id.content).rootView
// the ClipboardManager text becomes valid when the view is in focus.
view.doOnLayout { editText.setText(cm.text) }
}
when {
action == ACTION_INTERCEPT -> it.getStringExtra(REPLACE_KEY)
action == Intent.ACTION_SEND -> it.getCharSequenceExtra(Intent.EXTRA_TEXT)?.toString()
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable-v25/ic_shortcut_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#F5F5F5" />
<size
android:width="48dp"
android:height="48dp" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable-v25/ic_shortcut_paste.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_shortcut_background" />
<item
android:drawable="@drawable/ic_paste"
android:gravity="center" />
</layer-list>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_paste.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z" />
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/xml-v25/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="paste"
android:icon="@drawable/ic_shortcut_paste"
android:shortcutShortLabel="@android:string/paste">
<intent
android:action="jp.ddo.hotmist.unicodepad.intent.action.PASTE"
android:targetPackage="jp.ddo.hotmist.unicodepad"
android:targetClass="jp.ddo.hotmist.unicodepad.UnicodeActivity" />
</shortcut>
</shortcuts>
4 changes: 4 additions & 0 deletions app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Shortcuts are not available in older Android versions. -->
</shortcuts>

0 comments on commit dee9f34

Please sign in to comment.