Skip to content

Commit

Permalink
Refined some UI elements, but the result is still not good. (Android …
Browse files Browse the repository at this point in the history
…development is so difficult!)
  • Loading branch information
PBBB committed Feb 3, 2024
1 parent b9fe4cd commit 1348cbe
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Note that haptic feedbacks and vibration effects behave dramatically differently
There are official Android documents talking about haptics in detail: [Haptics](https://source.android.com/devices/input/haptics). You should read them first to know the basics about haptics and what you can do with those APIs, before using this app to get hands on the actual feeling of the haptics.

There are three ways to orchestrate haptic patterns:
- **Haptic Feedback**: suitable for input events (like long press, or swipe), or UI elements (like keyboard).
- **OneShot & Waveform**: suitable for more refined vibration patterns that last over time.
- **Composition**: According to the documents, compositions enable stringing together sequences of more nuanced haptics or vibrations. However, none of the devices I tested supports this feature including Pixel 5, so in this app you can only try the primitive haptics instead of composing them.
- **Haptic Feedback**: suitable for input events (like long press, or swipe), or UI elements (like keyboard). However, the support from different phone vendors vary a lot.
- **OneShot & Waveform**: best compatible, the effects are not optimal. Some phone vendors might have some optimizations over shorter vibrations.
- **Composition**: According to the documents, compositions enable stringing together sequences of more nuanced haptics or vibrations.

## Haptics
- Uses [View#performHapticFeedback](https://developer.android.com/reference/android/view/View#performHapticFeedback(int)).
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'com.google.android.material:material:1.11.0'
// implementation('androidx.activity:activity:1.8.2')
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:exported="false" />
<activity
android:name=".VibratorActivity"
android:parentActivityName=".MainActivity"></activity>
android:parentActivityName=".MainActivity" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import android.os.VibrationEffect
import android.os.Vibrator
import android.view.View
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import com.pbb.study.hapticfeedback.databinding.ActivityCompositionBinding
//import kotlinx.android.synthetic.main.activity_composition.*

class CompositionActivity : AppCompatActivity() {

private lateinit var binding:ActivityCompositionBinding
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
binding = ActivityCompositionBinding.inflate(layoutInflater)
val view = binding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.*
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.pbb.study.hapticfeedback.databinding.ActivityMainBinding
Expand All @@ -14,6 +15,7 @@ class MainActivity : AppCompatActivity() {

private lateinit var binding:ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.VibrationEffect
import android.os.Vibrator
import android.view.View
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.pbb.study.hapticfeedback.databinding.ActivityVibratorBinding
Expand All @@ -17,6 +18,7 @@ class VibratorActivity : AppCompatActivity() {
private lateinit var binding: ActivityVibratorBinding

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
binding = ActivityVibratorBinding.inflate(layoutInflater)
val view = binding.root
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_composition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingTop="?android:attr/actionBarSize"
tools:layout_editor_absoluteX="8dp">

<LinearLayout
Expand Down Expand Up @@ -168,6 +169,10 @@
android:text="This very short low frequency effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback."
android:textAlignment="viewStart" />

<Space
android:layout_width="match_parent"
android:layout_height="48dp" />

</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="8dp">

Expand Down Expand Up @@ -178,6 +179,11 @@
android:text="Play Haptics" />

</LinearLayout>

<Space
android:layout_width="match_parent"
android:layout_height="48dp" />

</LinearLayout>
</ScrollView>

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/layout/activity_vibrator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingTop="?android:attr/actionBarSize"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">

Expand Down Expand Up @@ -214,7 +216,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="performOneShotOrWaveformVibration"
android:paddingEnd="4dp"
android:text="Vibrate" />

<Button
Expand All @@ -223,7 +224,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="stopVibrate"
android:paddingStart="4dp"
android:text="Stop" />
</LinearLayout>

Expand All @@ -249,6 +249,10 @@
android:text="Time(ms): The number of milliseconds to vibrate. This must be a positive number. \n\nAmplitude: The strength of the vibration. This must be a value between 1 and 255, or DEFAULT_AMPLITUDE(-1). \n\nRepeat: No use"
android:textAlignment="viewStart" />

<Space
android:layout_width="match_parent"
android:layout_height="48dp" />

</LinearLayout>
</ScrollView>

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/menu/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/composition"
android:title="Composition" />
<item
android:id="@+id/vibrator"
android:title="OneShot &amp; Waveform"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/composition"
android:title="Composition" />
</menu>
4 changes: 2 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorPrimary">#0078EF</color>
<color name="colorPrimaryDark">#016FDC</color>
<color name="colorAccent">#03DAC5</color>
</resources>
5 changes: 2 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.Material3.Light">
<style name="AppTheme" parent="Theme.Material3.DynamicColors.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccent">@color/colorPrimary</item>
</style>

</resources>

0 comments on commit 1348cbe

Please sign in to comment.