Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.test;
- import java.util.Random;
- import android.annotation.SuppressLint;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- import android.widget.TextView;
- import android.widget.Toast;
- @SuppressLint("NewApi")
- public class MainActivity extends Activity implements AnimationListener{
- TextView text;
- Button start,stop,add;
- Animation anim;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Rows r = new Rows();
- text = (TextView) findViewById(R.id.text);
- start = (Button) findViewById(R.id.start);
- stop = (Button) findViewById(R.id.stop);
- add = (Button) findViewById(R.id.add);
- anim = AnimationUtils.loadAnimation(this, R.anim.myrotate);
- anim.setAnimationListener(this);
- text.setOnClickListener(new View.OnClickListener() {
- public void onClick(View arg0) {
- text.setText("");
- text.clearAnimation();
- text.setVisibility(text.GONE);
- }
- });
- start.setOnClickListener(new View.OnClickListener() {
- public void onClick(View arg0) {
- // new CheckThread().start();
- runOnUiThread(new Runnable(){
- public void run(){
- text.setVisibility(text.VISIBLE);
- text.setText("readme и стали виртуальными любовниками");
- text.startAnimation(anim);
- }
- });
- }
- });
- stop.setOnClickListener(new View.OnClickListener() {
- public void onClick(View arg0) {
- new CheckThread().stop();
- }
- });
- add.setOnClickListener(new View.OnClickListener() {
- public void onClick(View arg0) {
- String rnd = getRNDText();
- r.addRow(rnd);
- Toast.makeText(MainActivity.this, "Add:"+rnd, Toast.LENGTH_LONG).show();
- }
- });
- }
- @Override
- public void onAnimationEnd(Animation arg0) {
- text.setText("");
- text.clearAnimation();
- text.setVisibility(text.GONE);
- Toast.makeText(MainActivity.this, "Animation End", Toast.LENGTH_LONG).show();
- }
- @Override
- public void onAnimationRepeat(Animation arg0) {
- Toast.makeText(MainActivity.this, "Animation Repeat", Toast.LENGTH_LONG).show();
- }
- @Override
- public void onAnimationStart(Animation arg0) {
- Toast.makeText(MainActivity.this, "Animation Start", Toast.LENGTH_LONG).show();
- }
- public class CheckThread implements Runnable {
- Thread th;
- boolean status;
- @Override
- public void run() {
- main();
- }
- public void start(){
- status=true;
- th = new Thread(this);
- th.setPriority(Thread.NORM_PRIORITY);
- Log.e("CheckThread", "start()");
- th.start();
- }
- public synchronized void stop() {
- status=false;
- th = null;
- Log.e("CheckThread", "stop()");
- notify();
- }
- public void main() {
- final Rows r = new Rows();
- while(status){
- if(r.countRows()>=0){
- Log.e("CheckThread", "check...");
- runOnUiThread(new Runnable(){
- public void run(){
- for(int i=0; i<r.countRows(); i++){
- text.setText(r.getRow(i));
- text.startAnimation(anim);
- }
- }
- });
- }
- if(!status)break;
- }
- }
- }
- public static String getRNDText(){
- String s = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnprstuvwxyz ";
- Random r = new Random();
- String v="";
- for(int i=0;i<30;i++){
- v += s.charAt(r.nextInt(s.length()));
- }
- return v;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement