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

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)
}
}
}