Monday, December 1, 2014

Android using text binking with color interval

Android  using text blinking  and color change for every 20 mins......using timetcount

source code:

xml file:

<TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />


java file:

package com.example.blinking;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
TextView text;
Animation animBlink;
private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF;

private CountDownTimer countDownTimer;
private final long startTime = 30 * 1000;
private final long interval = 1 * 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

text = (TextView) findViewById(R.id.textview);


countDownTimer = new MyCountDownTimer(startTime, interval);
countDownTimer.start();
Log.d("timecounter", ""+String.valueOf(startTime / 1000));

Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); // You can manage the blinking time with this//
// parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
text.startAnimation(anim);
text.setTextColor(RED);


}

public class MyCountDownTimer extends CountDownTimer {

public MyCountDownTimer(long startTime, long interval) {

super(startTime, interval);

}

@Override
public void onFinish() {

//text.setText("Time's up!");
text.setTextColor(RED);
countDownTimer.cancel();
countDownTimer.start();
}

@Override
public void onTick(long millisUntilFinished) {

//text.setText("" + millisUntilFinished / 1000);

long tir =millisUntilFinished / 1000;
if(tir <=20)
{
text.setTextColor(BLUE);
}
}

}


}







No comments:

Post a Comment