Skip to content

Commit 23859f4

Browse files
committed
🎨 Supports append text by shortcuts to the dailynote doc on Android siyuan-note/siyuan#14414
1 parent 2ae90d0 commit 23859f4

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed

app/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,21 @@ android {
4848

4949
minifyEnabled true
5050
shrinkResources true
51+
5152
// 此处优先级太高,渠道处配置 resValue 不会生效,故放到了 productFlavors 多渠道打包处处理
5253
// resValue "string", "app_name", "SiYuan"
5354
resValue "string", "app_package_name", "org.b3log.siyuan"
55+
5456
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
5557
}
5658
debug {
5759
applicationIdSuffix ".debug"
60+
5861
minifyEnabled false
62+
5963
resValue "string", "app_name", "SiYuan-Debug"
6064
resValue "string", "app_package_name", "org.b3log.siyuan.debug"
65+
6166
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
6267
}
6368
}

app/src/main/AndroidManifest.xml

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
<data android:mimeType="text/plain" />
8888
</intent-filter>
8989

90+
<meta-data
91+
android:name="android.app.shortcuts"
92+
android:resource="@xml/shortcuts" />
93+
9094
</activity>
9195

9296
<activity
@@ -106,6 +110,10 @@
106110
-->
107111
</activity>
108112

113+
<activity
114+
android:name=".ShortcutActivity"
115+
android:theme="@style/Theme.AppCompat.DayNight" />
116+
109117
<service
110118
android:name=".KeepLiveService"
111119
android:foregroundServiceType="specialUse">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SiYuan - 源于思考,饮水思源
3+
* Copyright (c) 2020-present, b3log.org
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.b3log.siyuan;
19+
20+
import android.content.Intent;
21+
import android.os.Bundle;
22+
import android.util.Log;
23+
import android.widget.Button;
24+
import android.widget.EditText;
25+
26+
import androidx.annotation.Nullable;
27+
import androidx.appcompat.app.AppCompatActivity;
28+
29+
import com.blankj.utilcode.util.StringUtils;
30+
31+
/**
32+
* 追加到日记的快捷方式.
33+
*
34+
* @author <a href="https://88250.b3log.org">Liang Ding</a>
35+
* @version 1.0.0.0, Mar 21, 2025
36+
* @since 3.1.26
37+
*/
38+
public class ShortcutActivity extends AppCompatActivity {
39+
40+
@Override
41+
protected void onCreate(@Nullable Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
setContentView(R.layout.activity_shortcut);
44+
handleIntent(getIntent());
45+
}
46+
47+
@Override
48+
public void onNewIntent(final Intent intent) {
49+
super.onNewIntent(intent);
50+
handleIntent(intent);
51+
}
52+
53+
private void handleIntent(final Intent intent) {
54+
final String data = intent.getDataString();
55+
if (StringUtils.equals(data, "appendDailynote")) {
56+
Log.i("shortcut", "Append to daily note");
57+
setupFullScreenInput();
58+
return;
59+
}
60+
61+
Log.i("shortcut", "Unknown data [" + data + "]");
62+
}
63+
64+
private void setupFullScreenInput() {
65+
final EditText input = findViewById(R.id.full_screen_input);
66+
input.requestFocus();
67+
68+
69+
final Button submitButton = findViewById(R.id.submit_button);
70+
submitButton.setOnClickListener(v -> {
71+
String userInput = input.getText().toString();
72+
Log.i("shortcut", "User input: " + userInput);
73+
// Handle the user input here
74+
75+
finish();
76+
});
77+
}
78+
}
10.5 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:padding="16dp">
7+
8+
<EditText
9+
android:id="@+id/full_screen_input"
10+
android:layout_width="match_parent"
11+
android:layout_height="0dp"
12+
android:layout_weight="1"
13+
android:hint="@string/enter_your_text"
14+
android:inputType="textMultiLine"
15+
android:gravity="top"/>
16+
17+
<Button
18+
android:id="@+id/submit_button"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:text="@string/submit" />
22+
</LinearLayout>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="shortcut_append_dailynote">追加到日记</string>
4+
<string name="enter_your_text">请输入文本</string>
5+
<string name="submit">提交</string>
6+
</resources>

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

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="shortcut_append_dailynote">Append to Dailynote</string>
4+
<string name="enter_your_text">Enter your text</string>
5+
<string name="submit">Submit</string>
6+
</resources>

app/src/main/res/xml/shortcuts.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
3+
<shortcut
4+
android:enabled="true"
5+
android:icon="@drawable/dailynote_icon"
6+
android:shortcutId="appendDailynote"
7+
android:shortcutLongLabel="@string/shortcut_append_dailynote"
8+
android:shortcutShortLabel="@string/shortcut_append_dailynote">
9+
<intent
10+
android:action="android.intent.action.VIEW"
11+
android:data="appendDailynote"
12+
android:targetClass="org.b3log.siyuan.ShortcutActivity"
13+
android:targetPackage="org.b3log.siyuan" />
14+
</shortcut>
15+
</shortcuts>

0 commit comments

Comments
 (0)