I have three animation working on my App.
1. TextView Marque (Scrolling continues)
2. Blinking Textview (When my Music app in pause mode)
3. SeekBar Progress thread (Shows the Progress of played song)
While i use above all effect for my app, then UI for my my app becomes little hang. I guess all are working on the UI thread. I want to handle it as like each work independently without blocking each other.
Code is like below:
XML layout for the app:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@android:color/black"
android:orientation="vertical">
<TextView
android:id="@+id/songCurrentDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="00:00"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/songTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:ellipsize="marquee"
android:fadingEdgeLength="10dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:singleLine="true"
android:textColor="@android:color/white"
android:gravity="center_horizontal"
android:textSize="30sp"
android:text="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"/>
<SeekBar
android:id="@+id/songProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-15dp"
android:layout_marginRight="-15dp"
android:layout_marginTop="15dp"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/scrubber_progress_horizontal_holo_light"
android:thumb="@drawable/scrubber_control_selector_holo"
android:indeterminate="false" />
</LinearLayout>
My Class code is like below:
public class MainActivity extends Activity {
private Animation blinking_anim;
private SeekBar songProgressBar;
private TextView songCurrentDurationLabel;
private int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
blinking_anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blinking_animation);
songProgressBar = (SeekBar)findViewById(R.id.songProgressBar);
songCurrentDurationLabel = (TextView)findViewById(R.id.songCurrentDurationLabel);
songCurrentDurationLabel.startAnimation(blinking_anim);
mHandler.post(mUpdateTimeTask);
songProgressBar.setMax(10000);
}
private final Handler mHandler = new Handler();
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
try {
Thread.sleep(100);
count = count +10;
songCurrentDurationLabel.setText(""+ count);
songProgressBar.setProgress((int)count);
System.out.println("Runnnnn.........MAIN....");
if(count>=10000){
mHandler.removeCallbacks(mUpdateTimeTask);
}else
mHandler.post(mUpdateTimeTask);
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
Blinking Animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" android:repeatCount="infinite">
<alpha android:fromAlpha="4.0" android:toAlpha="0.0" android:duration="1000" android:repeatCount="infinite">
</alpha></alpha>
</set>
Need help for implementing all this to work independently without hanging each other.