Initial commit

This commit is contained in:
2025-02-10 03:05:25 +08:00
commit 57a0ecc385
93 changed files with 6685 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
plugins {
autowire(libs.plugins.android.application)
autowire(libs.plugins.kotlin.android)
}
android {
namespace = property.project.app.packageName
compileSdk = property.project.android.compileSdk
defaultConfig {
applicationId = property.project.app.packageName
minSdk = property.project.android.minSdk
targetSdk = property.project.android.targetSdk
versionName = property.project.app.versionName
versionCode = property.project.app.versionCode
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = listOf(
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"
)
}
buildFeatures {
buildConfig = true
viewBinding = true
}
}
dependencies {
implementation(projects.pangutextAndroid)
implementation(com.highcapable.betterandroid.ui.component)
implementation(com.highcapable.betterandroid.ui.extension)
implementation(com.highcapable.betterandroid.system.extension)
implementation(androidx.core.core.ktx)
implementation(androidx.appcompat.appcompat)
implementation(com.google.android.material.material)
implementation(androidx.constraintlayout.constraintlayout)
testImplementation(junit.junit)
androidTestImplementation(androidx.test.ext.junit)
androidTestImplementation(androidx.test.espresso.espresso.core)
}

32
demo-android/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,32 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static *** throwUninitializedProperty(...);
public static *** throwUninitializedPropertyAccessException(...);
}
-keep class * extends android.app.Activity
-keep class * implements androidx.viewbinding.ViewBinding {
<init>();
*** inflate(android.view.LayoutInflater);
}

View File

@@ -0,0 +1,24 @@
package com.highcapable.pangutext.demo
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.highcapable.pangutext", appContext.packageName)
}
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.DefaultAppTheme"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.ListActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
</application>
</manifest>

View File

@@ -0,0 +1,50 @@
/*
* PanguText - A typographic solution for the optimal alignment of CJK characters, English words, and half-width digits.
* Copyright (C) 2019 HighCapable
* https://github.com/BetterAndroid/PanguText
*
* Apache License Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is created by fankes on 2025/2/9.
*/
package com.highcapable.pangutext.demo.ui
import android.graphics.Color
import android.os.Bundle
import com.highcapable.betterandroid.ui.component.adapter.factory.bindAdapter
import com.highcapable.betterandroid.ui.extension.view.textColor
import com.highcapable.pangutext.demo.databinding.ActivityListBinding
import com.highcapable.pangutext.demo.databinding.AdapterListBinding
import com.highcapable.pangutext.demo.ui.base.BaseActivity
class ListActivity : BaseActivity<ActivityListBinding>() {
private val listData = List(100) { "这是第${it}条Data演示" }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.recyclerView.bindAdapter<String> {
onBindData { listData }
onBindViews<AdapterListBinding> { binding, text, _ ->
binding.text.text = text
binding.text.textColor = Color.rgb(
(0..255).random(),
(0..255).random(),
(0..255).random()
)
}
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* PanguText - A typographic solution for the optimal alignment of CJK characters, English words, and half-width digits.
* Copyright (C) 2019 HighCapable
* https://github.com/BetterAndroid/PanguText
*
* Apache License Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is created by fankes on 2025/1/12.
*/
package com.highcapable.pangutext.demo.ui
import android.os.Bundle
import android.text.method.LinkMovementMethod
import androidx.core.text.HtmlCompat
import com.highcapable.betterandroid.ui.component.insets.factory.handleOnWindowInsetsChanged
import com.highcapable.betterandroid.ui.component.insets.factory.setInsetsPadding
import com.highcapable.betterandroid.ui.extension.component.startActivity
import com.highcapable.pangutext.demo.databinding.ActivityMainBinding
import com.highcapable.pangutext.demo.ui.base.BaseActivity
class MainActivity : BaseActivity<ActivityMainBinding>() {
private val demoText = HtmlCompat.fromHtml(
"今天下午我去了一家新开的咖啡店店里环境非常舒适感觉很cozy。" +
"我点了一杯latte坐在窗边透过玻璃看着街上的人来人往。店员还<b>特别热情</b>" +
"给我推荐了一款很<font color='#639F70'><b>特别的</b></font>chocolate cake味道真是不错<br/>" +
"我发现现在很多人都<b>喜欢在咖啡店里工作</b>几乎每桌都有laptop。我的旁边有一位女士正在忙着处理emails。" +
"我想,这样的环境真是适合集中精力工作。<br/>" +
"总的来说,今天的体验很不错,下次还想再来尝试其他的<font color='#5C80BC'>drinks</font>和<font color='#9C528B'>desserts</font>。<br/>" +
"<span style='background-color: #E9EDDE'>混<b>合wo</b>rd样式</span>测试。<br/>" +
"You can<a href='https://github.com/BetterAndroid/PanguText'>点击这里访问项目地址</a>。",
HtmlCompat.FROM_HTML_MODE_LEGACY
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.root.handleOnWindowInsetsChanged(animated = true) { linearLayout, insetsWrapper ->
linearLayout.setInsetsPadding(insetsWrapper.safeDrawing)
}
listOf(
binding.textViewPanguText,
binding.textViewPanguTextCjkSpacingRatio,
binding.textViewNoPanguText
).forEach {
it.movementMethod = LinkMovementMethod.getInstance()
it.text = demoText
}
binding.buttonJumpList.setOnClickListener {
startActivity<ListActivity>()
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* PanguText - A typographic solution for the optimal alignment of CJK characters, English words, and half-width digits.
* Copyright (C) 2019 HighCapable
* https://github.com/BetterAndroid/PanguText
*
* Apache License Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is created by fankes on 2025/2/10.
*/
package com.highcapable.pangutext.demo.ui.base
import android.os.Bundle
import android.view.LayoutInflater
import androidx.viewbinding.ViewBinding
import com.highcapable.betterandroid.ui.component.activity.AppBindingActivity
import com.highcapable.pangutext.android.factory.PanguTextFactory2
open class BaseActivity<VB : ViewBinding> : AppBindingActivity<VB>() {
override fun onPrepareContentView(savedInstanceState: Bundle?): LayoutInflater {
val inflater = super.onPrepareContentView(savedInstanceState)
PanguTextFactory2.inject(inflater)
return inflater
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:scaleX="0.4686"
android:scaleY="0.4686"
android:translateX="12.7536"
android:translateY="12.4412">
<path
android:fillColor="@android:color/white"
android:pathData="M43.901,36H4.099C5.102,25.893 13.629,18 24,18C34.371,18 42.898,25.893 43.901,36Z"
android:strokeWidth="4"
android:strokeColor="@android:color/white"
android:strokeLineJoin="round" />
<path
android:pathData="M14,20L10,13"
android:strokeWidth="4"
android:strokeColor="@android:color/white"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:pathData="M33,20L37,13"
android:strokeWidth="4"
android:strokeColor="@android:color/white"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
</vector>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorBackgroundPrimary"
android:orientation="vertical"
tools:context=".ui.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/app_name"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@@ -0,0 +1,168 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorBackgroundPrimary"
android:orientation="vertical"
tools:context=".ui.MainActivity"
tools:ignore="HardcodedText">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/app_name"
android:textSize="20sp" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadingEdgeLength="10dp"
android:fillViewport="true"
android:requiresFadingEdge="vertical"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingBottom="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Xiaoming今年16岁"
android:textSize="15sp"
app:panguText_enabled="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Xiaoming今年16岁"
android:textSize="15sp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第1个Radio Button" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="第2个Radio Button" />
</RadioGroup>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:maxLines="1"
android:text="这是一个Check Box组件" />
<com.google.android.material.materialswitch.MaterialSwitch
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="这是一个Switch组件" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input something"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_jump_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="启动List演示" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="中英混排演示"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Mixed Chinese and English Demo"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="包含 PanguText (With PanguText)"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_pangu_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:lineSpacingExtra="5dp"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="3.5f Spacing Ratio PanguText"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_pangu_text_cjk_spacing_ratio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:lineSpacingExtra="5dp"
android:textSize="15sp"
app:panguText_cjkSpacingRatio="3.5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="不包含 PanguText (Without PanguText)"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_no_pangu_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:lineSpacingExtra="5dp"
android:textSize="15sp"
app:panguText_enabled="false" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp" />
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="Base.Theme.DefaultAppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
<item name="colorPrimary">@color/theme</item>
<item name="colorAccent">@color/theme</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorBackgroundPrimary">@color/background_night</item>
</style>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Pangu Text 演示</string>
</resources>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="theme">#FF639F70</color>
<color name="background_day">#FFF5F5F5</color>
<color name="background_night">#FF2D2D2D</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Pangu Text Demo</string>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Colors">
<attr name="colorBackgroundPrimary" format="color" />
</declare-styleable>
</resources>

View File

@@ -0,0 +1,13 @@
<resources>
<!-- Base application theme. -->
<style name="Base.Theme.DefaultAppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<item name="colorPrimary">@color/theme</item>
<item name="colorAccent">@color/theme</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorBackgroundPrimary">@color/background_day</item>
</style>
<style name="Theme.DefaultAppTheme" parent="Base.Theme.DefaultAppTheme" />
</resources>

View File

@@ -0,0 +1,17 @@
package com.highcapable.pangutext.demo
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}