Skip to content

Commit 8667ec4

Browse files
committed
completed example module
1 parent 8727935 commit 8667ec4

File tree

7 files changed

+67
-4
lines changed

7 files changed

+67
-4
lines changed

app/src/main/java/com/example/autotextswitcherlibrary/MainActivity.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.example.autotextswitcherlibrary;
22

33
import androidx.appcompat.app.AppCompatActivity;
4+
import androidx.appcompat.widget.AppCompatTextView;
45

6+
import android.graphics.Color;
57
import android.os.Bundle;
8+
import android.view.Gravity;
9+
10+
import com.masoud.autotextswitcher.AutoTextSwitcher;
611

712
public class MainActivity extends AppCompatActivity
813
{
@@ -12,5 +17,17 @@ protected void onCreate(Bundle savedInstanceState)
1217
{
1318
super.onCreate(savedInstanceState);
1419
setContentView(R.layout.activity_main);
20+
21+
AutoTextSwitcher textSwitcher = findViewById(R.id.textSwitcher);
22+
textSwitcher.setFactory(() ->
23+
{
24+
AppCompatTextView textView = new AppCompatTextView(MainActivity.this);
25+
textView.setTextAppearance(MainActivity.this, R.style.InfoTextAppearanceStyle);
26+
textView.setMinLines(2);
27+
textView.setPadding(10, 10, 10, 10);
28+
textView.setShadowLayer(12, 0, -5.5f, Color.parseColor("#65FFFFFF"));
29+
textView.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
30+
return textView;
31+
});
1532
}
1633
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@integer/InfoTextAnimationDuration"
4+
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
5+
<alpha
6+
android:fromAlpha="0"
7+
android:toAlpha="1" />
8+
<translate
9+
android:fromYDelta="100%"
10+
android:toYDelta="0%" />
11+
</set>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@integer/InfoTextAnimationDuration"
4+
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
5+
<alpha
6+
android:fromAlpha="1"
7+
android:toAlpha="0" />
8+
<translate
9+
android:fromYDelta="0%"
10+
android:toYDelta="-50%" />
11+
</set>

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
<TextView
10-
android:layout_width="wrap_content"
9+
<com.masoud.autotextswitcher.AutoTextSwitcher
10+
android:id="@+id/textSwitcher"
11+
android:layout_width="match_parent"
1112
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13+
android:inAnimation="@anim/text_in_animation"
14+
android:outAnimation="@anim/text_out_animation"
15+
app:autoStart="true"
16+
app:changeAnimationTime="3000"
1317
app:layout_constraintBottom_toBottomOf="parent"
1418
app:layout_constraintEnd_toEndOf="parent"
1519
app:layout_constraintStart_toStartOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
20+
app:layout_constraintTop_toTopOf="parent"
21+
app:textArray="@array/info_array" />
1722

1823
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/integers.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<integer name="InfoTextAnimationDuration">520</integer>
4+
</resources>

app/src/main/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
<resources>
22
<string name="app_name">AutoTextSwitcherLibrary</string>
3+
4+
<string name="click_mic">Click mic icon to start recognize</string>
5+
<string name="click_flash">Click flash icon to start Float-Mode</string>
6+
7+
<string-array name="info_array">
8+
<item>@string/click_mic</item>
9+
<item>@string/click_flash</item>
10+
</string-array>
311
</resources>

app/src/main/res/values/styles.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="InfoTextAppearanceStyle" parent="TextAppearance.MaterialComponents.Headline6">
4+
<item name="android:textColor">#FFF</item>
5+
<item name="android:textSize">18sp</item>
6+
</style>
7+
</resources>

0 commit comments

Comments
 (0)