Skip to content

Commit 33bba4f

Browse files
committed
First commit
0 parents  commit 33bba4f

File tree

14 files changed

+407
-0
lines changed

14 files changed

+407
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.0"
6+
7+
defaultConfig {
8+
minSdkVersion 15
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
compile fileTree(dir: 'libs', include: ['*.jar'])
26+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
exclude group: 'com.android.support', module: 'support-annotations'
28+
})
29+
compile 'com.android.support:appcompat-v7:25.0.1'
30+
testCompile 'junit:junit:4.12'
31+
}

fadingtextview.iml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":fadingtextview" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":fadingtextview" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
13+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
14+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15+
<afterSyncTasks>
16+
<task>generateDebugSources</task>
17+
</afterSyncTasks>
18+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
19+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
20+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
21+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
22+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
23+
<option name="LIBRARY_PROJECT" value="true" />
24+
</configuration>
25+
</facet>
26+
</component>
27+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
28+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
29+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
30+
<exclude-output />
31+
<content url="file://$MODULE_DIR$">
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
44+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
84+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
85+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
91+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.2/jars" />
92+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-idling-resource/2.2.2/jars" />
93+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.5/jars" />
94+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/rules/0.5/jars" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/runner/0.5/jars" />
96+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/25.0.1/jars" />
97+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/25.0.1/jars" />
98+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/25.0.1/jars" />
99+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/25.0.1/jars" />
100+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/25.0.1/jars" />
101+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/25.0.1/jars" />
102+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/25.0.1/jars" />
103+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/25.0.1/jars" />
104+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/25.0.1/jars" />
105+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
106+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
107+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
108+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
109+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
110+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
111+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
112+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
113+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
114+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
115+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/typedefs.txt" />
116+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
117+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
118+
</content>
119+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
120+
<orderEntry type="sourceFolder" forTests="false" />
121+
<orderEntry type="library" exported="" name="support-annotations-25.0.1" level="project" />
122+
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
123+
<orderEntry type="library" exported="" scope="TEST" name="runner-0.5" level="project" />
124+
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
125+
<orderEntry type="library" exported="" scope="TEST" name="espresso-idling-resource-2.2.2" level="project" />
126+
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
127+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
128+
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
129+
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
130+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
131+
<orderEntry type="library" exported="" name="support-compat-25.0.1" level="project" />
132+
<orderEntry type="library" exported="" name="support-fragment-25.0.1" level="project" />
133+
<orderEntry type="library" exported="" name="animated-vector-drawable-25.0.1" level="project" />
134+
<orderEntry type="library" exported="" name="support-v4-25.0.1" level="project" />
135+
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
136+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
137+
<orderEntry type="library" exported="" name="support-core-ui-25.0.1" level="project" />
138+
<orderEntry type="library" exported="" name="support-media-compat-25.0.1" level="project" />
139+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
140+
<orderEntry type="library" exported="" name="support-vector-drawable-25.0.1" level="project" />
141+
<orderEntry type="library" exported="" name="appcompat-v7-25.0.1" level="project" />
142+
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
143+
<orderEntry type="library" exported="" name="support-core-utils-25.0.1" level="project" />
144+
</component>
145+
</module>

proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/tomer/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.tomer.fadingtextview;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.tomer.fadingtextview.test", appContext.getPackageName());
25+
}
26+
}

src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.tomer.fadingtextview">
4+
5+
<application
6+
android:label="@string/app_name"
7+
android:supportsRtl="true">
8+
</application>
9+
10+
</manifest>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.tomer.fadingtextview;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.os.Build;
6+
import android.os.Handler;
7+
import android.support.annotation.ArrayRes;
8+
import android.support.annotation.RequiresApi;
9+
import android.support.v4.content.ContextCompat;
10+
import android.util.AttributeSet;
11+
import android.view.animation.Animation;
12+
import android.view.animation.AnimationUtils;
13+
import android.widget.TextView;
14+
15+
/**
16+
* Created by tomer on 12/8/16.
17+
*/
18+
19+
public class FadingTextView extends TextView {
20+
private Animation fadeInAnimation, fadeOutAnimation;
21+
private Handler handler;
22+
private CharSequence[] texts;
23+
private boolean isShown;
24+
private int position;
25+
private int timeout = 15000;
26+
27+
public FadingTextView(Context context) {
28+
super(context);
29+
init(context);
30+
}
31+
32+
public FadingTextView(Context context, AttributeSet attrs) {
33+
super(context, attrs);
34+
init(context);
35+
handleAttrs(context, attrs);
36+
}
37+
38+
public FadingTextView(Context context, AttributeSet attrs, int defStyleAttr) {
39+
super(context, attrs, defStyleAttr);
40+
init(context);
41+
handleAttrs(context, attrs);
42+
}
43+
44+
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
45+
public FadingTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46+
super(context, attrs, defStyleAttr, defStyleRes);
47+
init(context);
48+
handleAttrs(context, attrs);
49+
}
50+
51+
public void resume() {
52+
isShown = true;
53+
startAnimation();
54+
}
55+
56+
public void pause() {
57+
isShown = false;
58+
handler.removeCallbacksAndMessages(null);
59+
}
60+
61+
private void init(Context context) {
62+
fadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fadein);
63+
fadeOutAnimation = AnimationUtils.loadAnimation(context, R.anim.fadeout);
64+
handler = new Handler();
65+
isShown = true;
66+
setMaxLines(1);
67+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
68+
setTextAppearance(android.R.style.TextAppearance_Material_Button);
69+
setTextColor(ContextCompat.getColor(context, android.R.color.white));
70+
}
71+
}
72+
73+
private void handleAttrs(Context context, AttributeSet attrs) {
74+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.fading_text_view);
75+
this.texts = a.getTextArray(R.styleable.fading_text_view_texts);
76+
this.timeout = Math.abs(a.getInteger(R.styleable.fading_text_view_timeout, 14500)) + getResources().getInteger(android.R.integer.config_longAnimTime);
77+
a.recycle();
78+
startAnimation();
79+
}
80+
81+
public CharSequence[] getTexts() {
82+
return texts;
83+
}
84+
85+
public void setTexts(@ArrayRes int texts) {
86+
this.texts = getResources().getStringArray(texts);
87+
}
88+
89+
protected void startAnimation() {
90+
setText(texts[position]);
91+
startAnimation(fadeInAnimation);
92+
handler.postDelayed(new Runnable() {
93+
@Override
94+
public void run() {
95+
startAnimation(fadeOutAnimation);
96+
getAnimation().setAnimationListener(new Animation.AnimationListener() {
97+
@Override
98+
public void onAnimationStart(Animation animation) {
99+
100+
}
101+
102+
@Override
103+
public void onAnimationEnd(Animation animation) {
104+
if (isShown) {
105+
position = position == texts.length - 1 ? 0 : position + 1;
106+
startAnimation();
107+
}
108+
}
109+
110+
@Override
111+
public void onAnimationRepeat(Animation animation) {
112+
113+
}
114+
});
115+
}
116+
}, timeout);
117+
}
118+
}

src/main/res/anim/fadein.xml

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+
<set xmlns:android="http://schemas.android.com/apk/res/android">
3+
<alpha
4+
android:duration="@android:integer/config_longAnimTime"
5+
android:fromAlpha="0.0"
6+
android:interpolator="@android:anim/linear_interpolator"
7+
android:toAlpha="1.0" />
8+
</set>

src/main/res/anim/fadeout.xml

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+
<set xmlns:android="http://schemas.android.com/apk/res/android">
3+
<alpha
4+
android:duration="@android:integer/config_longAnimTime"
5+
android:fromAlpha="1.0"
6+
android:interpolator="@android:anim/anticipate_interpolator"
7+
android:toAlpha="0.0" />
8+
</set>

0 commit comments

Comments
 (0)