Skip to content

Commit 76d5730

Browse files
committed
完善库功能
1 parent d9c5f82 commit 76d5730

File tree

17 files changed

+272
-46
lines changed

17 files changed

+272
-46
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ dependencies {
286286

287287
```kotlin
288288
// activity
289-
@Route("user/UserActivity")
289+
@Route("/user/UserActivity")
290290
class UserActivity : AppCompatActivity() {
291291

292292
@delegate:RouteParams("params1")
@@ -307,7 +307,7 @@ class UserActivity : AppCompatActivity() {
307307
}
308308

309309
//fragment
310-
@Route("user/UserFragment")
310+
@Route("/user/UserFragment")
311311
class UserFragment : Fragment() {
312312
@delegate:RouteParams("params1")
313313
val params1 :String ? by lazy(LazyThreadSafetyMode.NONE) {

app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
4-
4+
<uses-permission android:name="android.permission.INTERNET"/>
55
<application
66
android:name=".MyApp"
77
android:allowBackup="true"
@@ -24,6 +24,25 @@
2424
<category android:name="android.intent.category.LAUNCHER" />
2525
</intent-filter>
2626
</activity>
27+
<activity
28+
android:name=".WebActivity"
29+
android:label="@string/app_name"
30+
android:theme="@style/Theme.ModuleCommunication">
31+
</activity>
32+
<activity android:name=".SchemeFilterActivity"
33+
android:exported="true">
34+
<!-- Scheme -->
35+
<intent-filter>
36+
<data
37+
android:host="test.flyjingfish.com"
38+
android:scheme="lightrouter"/>
39+
40+
<action android:name="android.intent.action.VIEW"/>
41+
42+
<category android:name="android.intent.category.DEFAULT"/>
43+
<category android:name="android.intent.category.BROWSABLE"/>
44+
</intent-filter>
45+
</activity>
2746
</application>
2847

2948
</manifest>

app/src/main/java/com/flyjingfish/modulecommunication/MainActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class MainActivity : ComponentActivity() {
2424
startActivity(Intent(this,UserActivity::class.java))
2525
}
2626

27+
binding.btnGoUri.setOnClickListener {
28+
// startActivity(Intent(this,SchemeFilterActivity::class.java))
29+
startActivity(Intent(this,WebActivity::class.java))
30+
}
31+
2732
Log.e("MainActivity","------${Int::class.qualifiedName}")
2833
}
2934
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.flyjingfish.modulecommunication
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
import androidx.activity.ComponentActivity
6+
import androidx.core.net.toUri
7+
import com.flyjingfish.module_communication_annotation.ImplementClassUtils
8+
import com.flyjingfish.module_communication_route.ModuleRoute
9+
import com.flyjingfish.user.UserHelper
10+
import com.google.gson.Gson
11+
12+
13+
class SchemeFilterActivity : ComponentActivity() {
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
val userHelper = ImplementClassUtils.getSingleInstance<UserHelper>(UserHelper::class)
17+
val user = userHelper?.getUser()
18+
val gson = Gson()
19+
// val uriTest = "lightrouter://test.flyjingfish.com/user/DetailActivity?age=10&name=hahahaha&aChar=a&user=${gson.toJson(user)}"
20+
// Log.e("SchemeFilterActivity",uriTest)
21+
// val uri = uriTest.toUri()
22+
val uri = intent.data
23+
uri?.let {
24+
ModuleRoute.builder(it)?.go()
25+
finish()
26+
}
27+
}
28+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.flyjingfish.modulecommunication
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.webkit.WebChromeClient
6+
import android.webkit.WebSettings
7+
import android.webkit.WebView
8+
import android.webkit.WebViewClient
9+
import androidx.activity.ComponentActivity
10+
import com.flyjingfish.modulecommunication.databinding.ActivityWebBinding
11+
12+
class WebActivity : ComponentActivity() {
13+
private lateinit var binding : ActivityWebBinding
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
binding = ActivityWebBinding.inflate(layoutInflater)
17+
setContentView(binding.root)
18+
initView()
19+
}
20+
21+
override fun onDestroy() {
22+
super.onDestroy()
23+
binding.web.destroy()
24+
}
25+
26+
override fun onResume() {
27+
super.onResume()
28+
binding.web.onResume()
29+
}
30+
31+
override fun onPause() {
32+
super.onPause()
33+
binding.web.onPause()
34+
}
35+
36+
fun initView() {
37+
setWebHtmlView()
38+
binding.web.webViewClient = CharmWebViewClient()
39+
binding.web.webChromeClient = CharmWebChromeClient()
40+
// binding.mlStatus.showLoading();
41+
binding.web.loadUrl("https://flyjingfish.github.io/demoweb/indexUri.html")
42+
}
43+
private fun setWebHtmlView() {
44+
val s: WebSettings = binding.web.settings
45+
s.allowFileAccess = false
46+
s.allowFileAccessFromFileURLs = false
47+
s.saveFormData = false
48+
s.savePassword = false
49+
s.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
50+
s.javaScriptEnabled = true
51+
s.cacheMode = WebSettings.LOAD_DEFAULT
52+
s.domStorageEnabled = true
53+
s.javaScriptCanOpenWindowsAutomatically = true
54+
s.setSupportZoom(false)
55+
s.builtInZoomControls = false
56+
s.displayZoomControls = false
57+
s.useWideViewPort = true
58+
s.loadWithOverviewMode = true
59+
// binding.web.addJavascriptInterface(this, "nativeApi")
60+
s.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
61+
}
62+
63+
private inner class CharmWebViewClient : WebViewClient() {
64+
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
65+
return if (url.startsWith("http") || url.startsWith("https")) {
66+
view.loadUrl(url)
67+
true
68+
} else {
69+
try {
70+
startActivity(Intent.parseUri(url, 0))
71+
true
72+
} catch (e: Exception) {
73+
true
74+
}
75+
}
76+
}
77+
}
78+
79+
private inner class CharmWebChromeClient : WebChromeClient() {
80+
override fun onReceivedTitle(view: WebView, title: String) {
81+
super.onReceivedTitle(view, title)
82+
}
83+
}
84+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
android:layout_width="wrap_content"
1414
android:layout_height="wrap_content"
1515
android:text="Go User"/>
16+
<Button
17+
android:id="@+id/btn_go_uri"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:text="Go Uri"/>
1621
</LinearLayout>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/web"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
</WebView>

base-lib/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
androidTestImplementation(libs.espresso.core)
3333
api(libs.androidAop.annotation)
3434
api(libs.androidAop.core)
35+
api(libs.gson)
3536
api(project(":module-communication-annotation"))
3637
api(project(":module-communication-intercept"))
3738
api(project(":module-communication-route"))

lib-user/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33
<application>
44
<activity android:name=".UserActivity" android:theme="@style/AppTheme"/>
5+
<activity android:name=".DetailActivity" android:theme="@style/AppTheme"/>
56
</application>
67
</manifest>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.flyjingfish.user;
2+
3+
import android.os.Bundle;
4+
import android.util.Log;
5+
6+
import androidx.annotation.Nullable;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
9+
import com.flyjingfish.module_communication_annotation.Route;
10+
import com.flyjingfish.module_communication_annotation.RouteParams;
11+
import com.flyjingfish.user.databinding.ActivityDetailBinding;
12+
13+
@Route(path = "/user/DetailActivity")
14+
public class DetailActivity extends AppCompatActivity {
15+
@RouteParams(name = "age")
16+
private int age;
17+
@RouteParams(name = "name")
18+
private String name;
19+
@RouteParams(name = "aChar")
20+
private char aChar = 's';
21+
@RouteParams(name = "user")
22+
private User user;
23+
@Override
24+
protected void onCreate(@Nullable Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
ActivityDetailBinding binding = ActivityDetailBinding.inflate(getLayoutInflater());
27+
setContentView(binding.getRoot());
28+
age = getIntent().getIntExtra("age",0);
29+
name = getIntent().getStringExtra("name");
30+
aChar = getIntent().getCharExtra("aChar",'s');
31+
user = (User) getIntent().getSerializableExtra("user");
32+
33+
String logText = "age="+age+",name="+name+",aChar="+aChar+",user="+user;
34+
binding.tvText.setText(logText);
35+
Log.e("DetailActivity",logText);
36+
37+
}
38+
}

0 commit comments

Comments
 (0)