Skip to content

Commit

Permalink
Support Contextual Half-width Spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
WordlessEcho committed Apr 14, 2021
1 parent 70f793d commit dc34dd5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/moe/echo/variablefonttest/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MainActivity : AppCompatActivity() {

val previewContent = findViewById<EditText>(R.id.previewContent)
val textSize = findViewById<EditText>(R.id.textSize)
val chws = findViewById<SwitchCompat>(R.id.chws)
val wght = findViewById<Slider>(R.id.wght)
val preview = findViewById<TextView>(R.id.preview)

Expand All @@ -30,5 +31,9 @@ class MainActivity : AppCompatActivity() {
wght.addOnChangeListener { _, value, _ ->
preview.fontVariationSettings = "'wght' $value"
}

chws.setOnCheckedChangeListener { buttonView, isChecked ->
preview.fontFeatureSettings = if (isChecked) "'chws' 1" else ""
}
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
android:inputType="number"
android:hint="@string/text_size" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/chws"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enable_chws"
android:checked="true" />

<com.google.android.material.slider.Slider
android:id="@+id/wght"
android:paddingHorizontal="10dp"
Expand All @@ -39,6 +46,7 @@
android:layout_height="wrap_content"
android:text="@string/default_preview"
android:textSize="20sp"
android:fontFeatureSettings="'chws' 1"
android:fontVariationSettings="'wght' 400" />

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<string name="default_preview">这句话后来演变成“饮水思源”这个成语,意为喝水的时候想一想流水的源头,比喻不忘本。</string>
<string name="input_hint_for_preview">输入一些你想看到的文字。</string>
<string name="text_size">字号</string>
<string name="enable_chws">启用标点挤压(chws)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<string name="default_preview">This sentence becomes to the idiom of "when you drink water, think of its source", which means don’t just be thankful for the water: be thankful for all the elements and processes (both past and present) that allowed you to enjoy that humble cup of water.</string>
<string name="input_hint_for_preview">Input some words you want to see.</string>
<string name="text_size">Text size</string>
<string name="enable_chws">Enable Contextual Half-width Spacing</string>
</resources>

0 comments on commit dc34dd5

Please sign in to comment.