添加页面方向指示图标创建功能

This commit is contained in:
ZhanGSKen
2025-07-24 10:12:30 +08:00
parent 9dcbaa0d75
commit a1707e73b5
5 changed files with 113 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Thu Jul 24 00:58:40 GMT 2025
#Thu Jul 24 02:10:57 GMT 2025
stageCount=1
libraryProject=
baseVersion=15.1
publishVersion=15.1.0
buildCount=8
buildCount=21
baseBetaVersion=15.1.1

View File

@@ -8,11 +8,13 @@ import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.LogView;
import cc.winboll.studio.numtable.R;
import com.hjq.toast.ToastUtils;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
@@ -36,8 +38,27 @@ public class MainActivity extends AppCompatActivity {
createDesktopShortcut();
}
});
((RadioButton)findViewById(R.id.rb_right)).setChecked(true);
((RadioButton)findViewById(R.id.rb_left)).setChecked(false);
}
public void onDirectionClick(View view) {
switch (view.getId()) {
case R.id.rb_right:
{
((RadioButton)findViewById(R.id.rb_left)).setChecked(false);
break;
}
case R.id.rb_left:
{
((RadioButton)findViewById(R.id.rb_right)).setChecked(false);
break;
}
}
}
/**
* 创建桌面快捷方式
*/
@@ -51,19 +72,33 @@ public class MainActivity extends AppCompatActivity {
// 2. 创建快捷方式的Intent
Intent shortcutIntent = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 生成随机UUID
UUID uuid = UUID.randomUUID();
// 转换为字符串
String uuidStr = uuid.toString();
// Android 8.0及以上使用ShortcutManager
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
// 创建快捷方式信息
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, "unique_shortcut_id") // 唯一ID
.setShortLabel("应用快捷方式") // 短标签(显示在桌面)
.setLongLabel("我的应用快捷方式") // 标签(长按显示)
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher)) // 图标
.setIntent(targetIntent)
.build();
// 发送创建请求
shortcutManager.requestPinShortcut(shortcutInfo, null);
if (((RadioButton)findViewById(R.id.rb_right)).isChecked()) {
// 创建快捷方式信息
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, uuidStr) // 唯一ID
.setShortLabel(">>") // 标签(显示在桌面
.setLongLabel("在右边 >>") // 长标签(长按显示)
.setIcon(Icon.createWithResource(this, R.drawable.ic_point_right)) // 图标
.setIntent(targetIntent)
.build();
// 发送创建请求
shortcutManager.requestPinShortcut(shortcutInfo, null);
} else {
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, uuidStr) // 唯一ID
.setShortLabel("<<") // 短标签(显示在桌面)
.setLongLabel("在左边 <<") // 长标签(长按显示)
.setIcon(Icon.createWithResource(this, R.drawable.ic_point_left)) // 图标
.setIntent(targetIntent)
.build();
// 发送创建请求
shortcutManager.requestPinShortcut(shortcutInfo, null);
}
ToastUtils.show("已请求创建快捷方式");
} else {
ToastUtils.show("当前设备不支持创建快捷方式");

View File

@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FF3D8A1C"
android:strokeColor="#FFF5DD00"
android:strokeWidth="5.0"
android:strokeLineCap="round"
android:strokeMiterLimit="10"
android:pathData="M401.84 141.95C361.52 236.12 354.86 278.98 399.2 382.12 359.53 383.01 245.24 289.83 245.38 265.73 247.41 236.75 361.69 143.4 401.84 141.95Z"/>
<path
android:fillColor="#FF3D8A1C"
android:strokeColor="#FFF5DD00"
android:strokeWidth="5.0"
android:strokeLineCap="round"
android:strokeMiterLimit="10"
android:pathData="M276.81 141.95C236.49 236.12 229.83 278.98 274.17 382.12 234.5 383.01 120.2 289.83 120.35 265.73 122.37 236.75 236.66 143.4 276.81 141.95Z"/>
</vector>

View File

@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FF3D8A1C"
android:strokeColor="#FFF5DD00"
android:strokeWidth="5.0"
android:strokeLineCap="round"
android:strokeMiterLimit="10"
android:pathData="M103.57 145.68C143.89 239.85 150.55 282.71 106.21 385.85 145.88 386.74 260.17 293.56 260.03 269.46 258 240.48 143.72 147.13 103.57 145.68Z"/>
<path
android:fillColor="#FF3D8A1C"
android:strokeColor="#FFF5DD00"
android:strokeWidth="5.0"
android:strokeLineCap="round"
android:strokeMiterLimit="10"
android:pathData="M228.6 145.68C268.92 239.85 275.58 282.71 231.24 385.85 270.91 386.74 385.21 293.56 385.06 269.46 383.04 240.48 268.75 147.13 228.6 145.68Z"/>
</vector>

View File

@@ -23,21 +23,42 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:gravity="bottom">
android:layout_weight="1.0">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
android:gravity="right|center_vertical"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/ic_point_right"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb_right"
android:onClick="onDirectionClick"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/ic_point_left"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb_left"
android:onClick="onDirectionClick"/>
<Button
android:id="@+id/btn_create_shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="创建桌面快捷方式"
android:layout_marginTop="16dp"/>
android:text="创建桌面快捷方式"/>
</LinearLayout>