Update Demo support PreferenceFragment

This commit is contained in:
2022-04-18 02:31:40 +08:00
parent 16c0d2723d
commit 18064d7cac
18 changed files with 247 additions and 72 deletions

15
.idea/misc.xml generated
View File

@@ -5,10 +5,25 @@
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.4169230769230769" />
<entry key="app_demo/src/main/res/layout/activity_main.xml" value="0.4375" />
<entry key="demo-app/src/main/res/drawable/ic_launcher_background.xml" value="0.238" />
<entry key="demo-app/src/main/res/layout/activity_main.xml" value="0.4375" />
<entry key="demo-module/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.238" />
<entry key="demo-module/src/main/res/drawable/ic_launcher_background.xml" value="0.238" />
<entry key="demo-module/src/main/res/layout/activity_main.xml" value="0.4375" />
<entry key="demo-module/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.238" />
<entry key="demo-module/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml" value="0.238" />
<entry key="demo-module/src/main/res/xml/settings_preference.xml" value="0.4359375" />
<entry key="demo-module/src/main/res/xml/settings_preferences.xml" value="0.43697916666666664" />
<entry key="demo/src/main/res/layout/activity_main.xml" value="0.4375" />
<entry key="module_demo/src/main/res/layout/activity_main.xml" value="0.4375" />
<entry key="yukihookapi-ui-component/src/main/kotlin/com/highcapable/yukihookapi/ui/view/ModuleActiveBannerView.kt" value="0.44074074074074077" />
<entry key="yukihookapi-ui-component/src/main/res/drawable-night/bg_dark_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/drawable/bg_button_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/drawable/bg_dark_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/drawable/bg_green_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/drawable/bg_orange_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/drawable/bg_yellow_round.xml" value="0.238" />
<entry key="yukihookapi-ui-component/src/main/res/layout/wgt_module_active_banner.xml" value="0.4359375" />
</map>
</option>
</component>

View File

@@ -13,7 +13,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_second_text"
@@ -21,7 +21,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_third_text"
@@ -29,7 +29,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_fourth_text"
@@ -37,7 +37,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_seventh_text"
@@ -45,7 +45,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_eighth_text"
@@ -53,7 +53,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_ninth_text"
@@ -61,7 +61,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_tenth_text"
@@ -69,7 +69,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_sixth_text"
@@ -77,7 +77,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/app_demo_fifth_text"
@@ -85,7 +85,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
android:textSize="18sp" />
<Button
android:id="@+id/app_demo_button"

View File

@@ -1,16 +1,16 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="yuki_theme_color">#FFEBAD70</color>
<color name="yuki_accent_color">#FF777777</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@@ -1,3 +1,3 @@
<resources>
<string name="app_name">YukiHookAppDemo</string>
<string name="app_name">YukiHookDemoApp</string>
</resources>

View File

@@ -1,16 +1,16 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -54,6 +54,7 @@ dependencies {
implementation project(':yukihookapi')
// Implementation Processor
ksp project(':yukihookapi-ksp-xposed')
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'

View File

@@ -40,5 +40,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.PreferenceActivity"
android:exported="false" />
</application>
</manifest>

View File

@@ -93,6 +93,15 @@ class HookEntry : YukiHookXposedInitProxy {
type = StringType
}.get(instance).set("I am hook result")
}
// 在执行方法之后拦截
afterHook {
if (prefs.getBoolean("show_dialog_when_demo_app_opend"))
AlertDialog.Builder(instance())
.setTitle("Hooked")
.setMessage("This App has been hooked!")
.setPositiveButton("OK", null)
.show()
}
}
// 注入要 Hook 的方法
injectMember {
@@ -131,7 +140,7 @@ class HookEntry : YukiHookXposedInitProxy {
replaceUnit {
AlertDialog.Builder(instance())
.setTitle("Hooked")
.setMessage("I am hook your toast showing")
.setMessage("I am hook your toast showing!")
.setPositiveButton("OK", null)
.show()
}

View File

@@ -29,9 +29,11 @@
package com.highcapable.yukihookapi.demo_module.ui
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.demo_module.data.DataConst
import com.highcapable.yukihookapi.demo_module.databinding.ActivityMainBinding
import com.highcapable.yukihookapi.hook.factory.isModuleActive
@@ -44,9 +46,11 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
ActivityMainBinding.inflate(layoutInflater).apply {
setContentView(root)
moduleDemoText.text = "Module is Active -> $isModuleActive\n" +
"Hook Framework -> ${YukiHookModuleStatus.executorName}\n" +
"API Version -> ${YukiHookModuleStatus.executorVersion}"
moduleDemoActiveText.text = "Module is Active$isModuleActive"
moduleDemoFrameworkText.text = "Hook Framework${YukiHookModuleStatus.executorName}"
moduleDemoApiVersionText.text = "API Version${YukiHookModuleStatus.executorVersion}"
moduleDemoYukiHookApiVersionText.text = "YukiHookAPI Version${YukiHookAPI.API_VERSION_NAME}(${YukiHookAPI.API_VERSION_CODE})"
moduleDemoNewXshareText.text = "New XShare Mode${modulePrefs.isRunInNewXShareMode}"
moduleDemoEditText.also {
it.setText(modulePrefs.get(DataConst.TEST_KV_DATA))
moduleDemoButton.setOnClickListener { _ ->
@@ -56,6 +60,7 @@ class MainActivity : AppCompatActivity() {
} else Toast.makeText(applicationContext, "Please enter the text", Toast.LENGTH_SHORT).show()
}
}
moduleDemoFrgButton.setOnClickListener { startActivity(Intent(this@MainActivity, PreferenceActivity::class.java)) }
}
}
}

View File

@@ -0,0 +1,59 @@
/*
* YukiHookAPI - An efficient Kotlin version of the Xposed Hook API.
* Copyright (C) 2019-2022 HighCapable
* https://github.com/fankes/YukiHookAPI
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file is Created by fankes on 2022/4/18.
*/
package com.highcapable.yukihookapi.demo_module.ui
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.highcapable.yukihookapi.demo_module.R
import com.highcapable.yukihookapi.hook.xposed.prefs.ui.ModulePreferenceFragment
class PreferenceActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
title = "PreferenceFragment"
if (savedInstanceState == null)
supportFragmentManager
.beginTransaction()
.replace(android.R.id.content, SettingsFragment())
.commitAllowingStateLoss()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onSupportNavigateUp(): Boolean {
onBackPressed()
return super.onSupportNavigateUp()
}
class SettingsFragment : ModulePreferenceFragment() {
override fun onCreatePreferencesInModuleApp(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settings_preferences, rootKey)
}
}
}

View File

@@ -7,30 +7,103 @@
android:orientation="vertical"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/module_demo_text"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:lineSpacingExtra="6dp"
android:text="sample"
android:textSize="20sp" />
android:gravity="center|start"
android:orientation="vertical">
<EditText
android:id="@+id/module_demo_edit_text"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:hint="Please enter the text"
android:singleLine="true"
android:textSize="20sp"
tools:ignore="Autofill,LabelFor,TextFields" />
<TextView
android:id="@+id/module_demo_active_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="sample"
android:textSize="18sp" />
<TextView
android:id="@+id/module_demo_framework_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="sample"
android:textSize="18sp" />
<TextView
android:id="@+id/module_demo_api_version_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="sample"
android:textSize="18sp" />
<TextView
android:id="@+id/module_demo_yuki_hook_api_version_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="sample"
android:textSize="18sp" />
<TextView
android:id="@+id/module_demo_new_xshare_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="sample"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:gravity="center|start"
android:singleLine="true"
android:text="Leave something in there"
android:textSize="15sp" />
<EditText
android:id="@+id/module_demo_edit_text"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Please enter the text"
android:singleLine="true"
android:textSize="18sp"
tools:ignore="Autofill,LabelFor,TextFields" />
</LinearLayout>
<Button
android:id="@+id/module_demo_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Save Test Data"
android:textAllCaps="false" />
<Button
android:id="@+id/module_demo_frg_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open PreferenceFragment"
android:textAllCaps="false" />
</LinearLayout>

View File

@@ -1,16 +1,16 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="yuki_theme_color">#FFEBAD70</color>
<color name="yuki_accent_color">#FF777777</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@@ -1,3 +1,3 @@
<resources>
<string name="app_name">YukiHookModuleDemo</string>
<string name="app_name">YukiHookDemoModule</string>
</resources>

View File

@@ -1,16 +1,16 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Default" parent="Theme.Material3.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/yuki_theme_color</item>
<item name="colorPrimaryVariant">@color/yuki_theme_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorSecondary">@color/yuki_accent_color</item>
<item name="colorSecondaryVariant">@color/yuki_accent_color</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -0,0 +1,10 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="Normal Preference">
<SwitchPreference
app:defaultValue="false"
app:key="show_dialog_when_demo_app_opend"
app:summary="Open a dialog on start Demo App"
app:title="Show Dialog" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -151,7 +151,12 @@ class YukiHookModulePrefs(private val context: Context? = null) {
* - 前提条件为当前 Xposed 模块已被激活
* @return [Boolean] 仅限在模块中判断 - 在宿主 [XSharedPreferences] 环境中始终返回 false
*/
val isRunInNewXShareMode get() = isUsingNewXSharePrefs
val isRunInNewXShareMode
get() = runCatching {
/** 执行一次装载 */
sPref.edit()
isUsingNewXSharePrefs
}.getOrNull() ?: false
/**
* 自定义 Sp 存储名称