增加剪切板提示开关,在安卓13可用。

This commit is contained in:
Cold-Mint 2023-06-26 20:27:32 +08:00
parent fbfa342507
commit 01715baa99
10 changed files with 109 additions and 55 deletions

View File

@ -101,10 +101,8 @@ dependencies {
implementation 'com.github.promeg:tinypinyin:2.0.3'
implementation 'io.github.youth5201314:banner:2.2.2'
implementation 'androidx.core:core-ktx:1.8.0'
// implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.github.yalantis:ucrop:2.2.8-native'
// implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9'
implementation 'io.github.Rosemoe.sora-editor:editor:0.16.5'
implementation project(path: ':assistantCoreLibrary')
implementation project(path: ':dialog')

View File

@ -62,6 +62,12 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
true
}
val clipboardCue = manager.findPreference<SwitchPreference>(requireContext().getString(R.string.setting_clipboard_cue))
// Only show a toast for Android 12 and lower.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2){
//如果是安卓12或更低
clipboardCue?.isEnabled = false
}
val dynamicColor =
manager.findPreference<SwitchPreference>(requireContext().getString(R.string.setting_dynamic_color))
if (!DynamicColors.isDynamicColorAvailable()) {

View File

@ -11,6 +11,7 @@ import android.view.View
import android.widget.Toast
import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog
import com.coldmint.dialog.CoreDialog
import com.coldmint.rust.core.database.code.CodeDataBase
import com.coldmint.rust.core.database.code.CodeInfo
import com.coldmint.rust.core.database.code.SectionInfo
@ -20,6 +21,7 @@ import com.coldmint.rust.pro.databinding.CodeTableItemBinding
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.GlobalMethod
import com.google.android.material.chip.Chip
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.util.concurrent.Executors
class CodeTableAdapter(
@ -144,8 +146,16 @@ class CodeTableAdapter(
}
val demo = codeInfo.demo
resultView.demoView.isVisible = demo.isNotBlank()
resultView.demoView.text = demo
resultView.imageView.isVisible = demo.isNotBlank()
resultView.imageView.setOnClickListener {
val dialog = MaterialAlertDialogBuilder(context);
dialog.setTitle(R.string.code_demo)
dialog.setMessage(demo)
dialog.setPositiveButton(R.string.dialog_ok){
v,a->
}
dialog.show()
}
resultView.subTitleView.text = codeInfo.code
resultView.subTitleView.setOnClickListener {

View File

@ -38,7 +38,7 @@ object AppSettings {
}
enum class Setting {
DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath, SimpleDisplayOfAutoCompleteMenu, SourceFileType
DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath, SimpleDisplayOfAutoCompleteMenu, SourceFileType, ClipboardCue
}
@ -135,6 +135,7 @@ object AppSettings {
mApplication.getString(R.string.setting_simple_display_of_auto_complete_menu)
//setting_source_file_type
map[Setting.SourceFileType] = mApplication.getString(R.string.setting_source_file_type)
map[Setting.ClipboardCue] = mApplication.getString(R.string.setting_clipboard_cue)
//仅保存不可显示
map[Setting.SetGameStorage] = "SetGameStorage"
map[Setting.AppID] = "AppId"
@ -235,18 +236,23 @@ object AppSettings {
is String -> {
editor.putString(name, value as String)
}
is Boolean -> {
editor.putBoolean(name, value as Boolean)
}
is Int -> {
editor.putInt(name, value as Int)
}
is Float -> {
editor.putFloat(name, value as Float)
}
is Long -> {
editor.putLong(name, value as Long)
}
else -> {
return false
}
@ -271,18 +277,23 @@ object AppSettings {
is String -> {
editor.putString(name, value as String)
}
is Boolean -> {
editor.putBoolean(name, value as Boolean)
}
is Int -> {
editor.putInt(name, value as Int)
}
is Float -> {
editor.putFloat(name, value as Float)
}
is Long -> {
editor.putLong(name, value as Long)
}
else -> {
return false
}

View File

@ -4,6 +4,7 @@ import android.Manifest
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Context.CLIPBOARD_SERVICE
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.Bitmap
@ -20,6 +21,7 @@ import android.view.View
import android.widget.PopupMenu
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat.getSystemService
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.FragmentActivity
import com.bumptech.glide.load.MultiTransformation
@ -49,7 +51,6 @@ object GlobalMethod {
const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda"
/**
* 转dp
* @param i Int
@ -300,7 +301,8 @@ object GlobalMethod {
scope.showRequestReasonDialog(
deniedList,
activity.getString(R.string.dialog_title),
activity.getString(R.string.dialog_confirm),activity.getString(R.string.dialog_cancel)
activity.getString(R.string.dialog_confirm),
activity.getString(R.string.dialog_cancel)
)
}
.request { allGranted, grantedList, deniedList ->
@ -335,11 +337,15 @@ object GlobalMethod {
* @param showView 展示的视图设置为null则不展示提示
*/
fun copyText(context: Context, text: String, showView: View? = null) {
val clipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(text, text)
clipboardManager.setPrimaryClip(clipData)
val clipboardManager = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
// When setting the clip board text.
clipboardManager.setPrimaryClip(ClipData.newPlainText("", text))
if (showView != null) {
if (AppSettings.getValue(
AppSettings.Setting.ClipboardCue,
Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2
)
) {
Snackbar.make(
showView,
String.format(context.getText(R.string.copy_complete).toString(), text),
@ -347,6 +353,7 @@ object GlobalMethod {
).show()
}
}
}
//图像着色
fun tintDrawable(drawable: Drawable?, colors: ColorStateList?): Drawable {

View File

@ -258,6 +258,8 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio
AppSettings.Setting.DynamicColor,
DynamicColors.isDynamicColorAvailable()
)
//如果是安卓12或更低那么默认启用。安卓13默认关闭
AppSettings.initSetting(AppSettings.Setting.ClipboardCue,Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2)
AppSettings.initSetting(AppSettings.Setting.KeywordColor, "#2196f3")
AppSettings.initSetting(AppSettings.Setting.SectionColor, "#e91e63")
AppSettings.initSetting(AppSettings.Setting.TextColor, "#212121")

View File

@ -1,5 +1,11 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z" />
</vector>

View File

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp">
<TextView
android:id="@+id/titleView"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/imageView"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -25,54 +27,56 @@
<TextView
android:id="@+id/descriptionView"
android:layout_width="match_parent"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/subTitleView"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="8dp"
android:text="描述" />
<View
android:id="@+id/LineView"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="5dp"
android:background="?android:colorPrimary"
android:layout_below="@id/descriptionView"/>
<ImageView
android:layout_marginLeft="8dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:id="@+id/imageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/baseline_help_outline_24" />
<!-- <TextView-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:id="@+id/DemoTitleView"-->
<!-- style="@style/TextAppearance.Material3.BodySmall"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_below="@id/descriptionView"-->
<!-- android:text="示例代码:"-->
<!-- android:textColor="?attr/colorSecondary" />-->
<!-- <TextView-->
<!-- android:id="@+id/demoView"-->
<!-- style="@style/TextAppearance.Material3.BodySmall"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_below="@id/descriptionView"-->
<!-- android:layout_marginTop="5dp"-->
<!-- android:text="demo"-->
<!-- android:visibility="gone" />-->
<TextView
android:id="@+id/DemoTitleView"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/LineView"
android:text="示例代码:"
android:textColor="?attr/colorSecondary" />
<TextView
android:id="@+id/demoView"
android:visibility="gone"
android:layout_width="wrap_content"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_height="wrap_content"
android:layout_below="@id/DemoTitleView"
android:layout_marginTop="5dp"
android:text="demo" />
<TextView
style="@style/TextAppearance.Material3.BodySmall"
android:id="@+id/valueTypeView"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/demoView"
android:layout_below="@id/descriptionView"
android:layout_marginTop="5dp"
android:text="值类型" />
<TextView
android:id="@+id/versionView"
android:layout_width="wrap_content"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/valueTypeView"
android:layout_marginLeft="8dp"
@ -83,9 +87,9 @@
android:id="@+id/chipGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleLine="false"
android:layout_below="@id/valueTypeView"
android:layout_marginTop="8dp">
android:layout_marginTop="8dp"
app:singleLine="false">
</com.google.android.material.chip.ChipGroup>

View File

@ -880,6 +880,7 @@
<string name="display_source_code">显示源代码</string>
<string name="dynamic_color">动态颜色</string>
<string name="setting_dynamic_color" translatable="false">DynamicColor</string>
<string name="setting_clipboard_cue" translatable="false">ClipboardCue</string>
<string name="dynamic_color_tip">跟随设备壁纸更换主题色。</string>
<string name="dynamic_color_disabled">此设备不支持动态颜色。</string>
<string name="an_unsupported_file_type">不支持的文件格式%1$s。</string>
@ -967,4 +968,7 @@
<string name="github">GitHub</string>
<string name="dataset_not_exist">DataBaseManifest.json不存在无法加载信息。</string>
<string name="dataset_minversion_low">此数据集仅适用于旧版本助手。</string>
<string name="code_demo">示例代码</string>
<string name="clipboard_cue">剪切板提示</string>
<string name="clipboard_cue_tip">在安卓13及以上系统应用将内容复制到剪贴板时弹出提示。</string>
</resources>

View File

@ -12,6 +12,12 @@
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:defaultValue="true"
android:summary="@string/clipboard_cue_tip"
android:title="@string/clipboard_cue"
app:key="@string/setting_clipboard_cue"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>