Skip to content

Instantly share code, notes, and snippets.

@rishabhmhjn
Created September 18, 2014 04:07
Show Gist options
  • Save rishabhmhjn/68f8657e0bbb119d7467 to your computer and use it in GitHub Desktop.
Save rishabhmhjn/68f8657e0bbb119d7467 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ThreeDotsLoadingBar">
<attr name="textSize" format="dimension"/>
</declare-styleable>
</resources>
package in.jasonleon.vanityviews.widget;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import in.jasonleon.vanityviews.R;
/**
* Copyright 2014
* <p/>
* Created by rishabhmhjn on 8/3/14.
*/
public class ThreeDotsLoadingBar extends LinearLayout {
private TextView mLoadingTv1;
private TextView mLoadingTv2;
private TextView mLoadingTv3;
public ThreeDotsLoadingBar(Context context) {
super(context);
init(null);
}
public ThreeDotsLoadingBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
private void init(AttributeSet attrs) {
setOrientation(HORIZONTAL);
View l = LayoutInflater.from(getContext()).inflate(R.layout.vv_3dots_loading_progress_bar,
this);
mLoadingTv1 = (TextView) l.findViewById(R.id.vv_3dots_loading_bar_dot1);
mLoadingTv2 = (TextView) l.findViewById(R.id.vv_3dots_loading_bar_dot2);
mLoadingTv3 = (TextView) l.findViewById(R.id.vv_3dots_loading_bar_dot3);
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.ThreeDotsLoadingBar);
float textSize = a.getDimension(R.styleable.ThreeDotsLoadingBar_textSize, 36);
mLoadingTv1.setTextSize(textSize);
mLoadingTv2.setTextSize(textSize);
mLoadingTv3.setTextSize(textSize);
a.recycle();
}
waveAnimation();
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void waveAnimation() {
PropertyValuesHolder tvOne_Y = PropertyValuesHolder.ofFloat(mLoadingTv1.TRANSLATION_Y, -40.0f);
PropertyValuesHolder tvOne_X = PropertyValuesHolder.ofFloat(mLoadingTv1.TRANSLATION_X, 0);
ObjectAnimator waveOneAnimator = ObjectAnimator.ofPropertyValuesHolder(mLoadingTv1, tvOne_X, tvOne_Y);
waveOneAnimator.setRepeatCount(-1);
waveOneAnimator.setRepeatMode(ValueAnimator.REVERSE);
waveOneAnimator.setDuration(300);
waveOneAnimator.start();
PropertyValuesHolder tvTwo_Y = PropertyValuesHolder.ofFloat(mLoadingTv2.TRANSLATION_Y, -40.0f);
PropertyValuesHolder tvTwo_X = PropertyValuesHolder.ofFloat(mLoadingTv2.TRANSLATION_X, 0);
ObjectAnimator waveTwoAnimator = ObjectAnimator.ofPropertyValuesHolder(mLoadingTv2, tvTwo_X, tvTwo_Y);
waveTwoAnimator.setRepeatCount(-1);
waveTwoAnimator.setRepeatMode(ValueAnimator.REVERSE);
waveTwoAnimator.setDuration(300);
waveTwoAnimator.setStartDelay(100);
waveTwoAnimator.start();
PropertyValuesHolder tvThree_Y = PropertyValuesHolder.ofFloat(mLoadingTv3.TRANSLATION_Y,
-40.0f);
PropertyValuesHolder tvThree_X = PropertyValuesHolder.ofFloat(mLoadingTv3.TRANSLATION_X, 0);
ObjectAnimator waveThreeAnimator = ObjectAnimator.ofPropertyValuesHolder(mLoadingTv3, tvThree_X, tvThree_Y);
waveThreeAnimator.setRepeatCount(-1);
waveThreeAnimator.setRepeatMode(ValueAnimator.REVERSE);
waveThreeAnimator.setDuration(300);
waveThreeAnimator.setStartDelay(200);
waveThreeAnimator.start();
}
}
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/vv_3dots_loading_bar_dot1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:textSize="30sp"/>
<TextView
android:id="@+id/vv_3dots_loading_bar_dot2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:textSize="30sp"/>
<TextView
android:id="@+id/vv_3dots_loading_bar_dot3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:textSize="30sp"/>
</merge>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment