Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.27 KB | None | 0 0
  1. package com.example.test;
  2.  
  3. import java.util.Random;
  4.  
  5. import android.annotation.SuppressLint;
  6. import android.app.Activity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.view.animation.Animation;
  11. import android.view.animation.Animation.AnimationListener;
  12. import android.view.animation.AnimationUtils;
  13. import android.widget.Button;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16.  
  17. @SuppressLint("NewApi")
  18. public class MainActivity extends Activity implements AnimationListener{
  19.    
  20.      TextView text;
  21.      Button start,stop,add;
  22.      Animation anim;
  23.    
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.        
  29.         final Rows r = new Rows();
  30.        
  31.        text = (TextView) findViewById(R.id.text);
  32.        start =  (Button) findViewById(R.id.start);
  33.        stop =  (Button) findViewById(R.id.stop);
  34.        add =  (Button) findViewById(R.id.add);
  35.        
  36.        anim = AnimationUtils.loadAnimation(this, R.anim.myrotate);
  37.        anim.setAnimationListener(this);
  38.        
  39.        
  40.  
  41.      text.setOnClickListener(new View.OnClickListener() {
  42.         public void onClick(View arg0) {
  43.            text.setText("");
  44.            text.clearAnimation();
  45.            text.setVisibility(text.GONE);
  46.          
  47.     }
  48.     });
  49.    
  50.      start.setOnClickListener(new View.OnClickListener() {
  51.          public void onClick(View arg0) {
  52.             // new CheckThread().start();
  53.              runOnUiThread(new Runnable(){
  54.                  public void run(){
  55.                text.setVisibility(text.VISIBLE);
  56.               text.setText("readme и стали виртуальными любовниками");
  57.             text.startAnimation(anim);
  58.                  }
  59.              });
  60.                }
  61.                });
  62.      
  63.      stop.setOnClickListener(new View.OnClickListener() {
  64.          public void onClick(View arg0) {
  65.              new CheckThread().stop();
  66.                }
  67.                });
  68.        
  69.      add.setOnClickListener(new View.OnClickListener() {
  70.          public void onClick(View arg0) {
  71.         String rnd = getRNDText();
  72.         r.addRow(rnd);
  73.         Toast.makeText(MainActivity.this, "Add:"+rnd, Toast.LENGTH_LONG).show();
  74.                }
  75.                });
  76.        
  77.         }
  78.    
  79.     @Override
  80.     public void onAnimationEnd(Animation arg0) {
  81.           text.setText("");
  82.           text.clearAnimation();
  83.           text.setVisibility(text.GONE);
  84.           Toast.makeText(MainActivity.this, "Animation End", Toast.LENGTH_LONG).show();
  85.     }
  86.  
  87.     @Override
  88.     public void onAnimationRepeat(Animation arg0) {
  89.           Toast.makeText(MainActivity.this, "Animation Repeat", Toast.LENGTH_LONG).show();
  90.     }
  91.  
  92.     @Override
  93.     public void onAnimationStart(Animation arg0) {
  94.  
  95.           Toast.makeText(MainActivity.this, "Animation Start", Toast.LENGTH_LONG).show();
  96.     }
  97.    
  98.  
  99.     public class CheckThread implements Runnable {
  100.      Thread th;
  101.      boolean status;
  102.  
  103.      
  104.     @Override
  105.     public void run() {
  106.     main();
  107.     }
  108.        
  109.           public void start(){
  110.             status=true;
  111.             th = new Thread(this);
  112.             th.setPriority(Thread.NORM_PRIORITY);
  113.             Log.e("CheckThread", "start()");
  114.             th.start();
  115.         }
  116.  
  117.         public synchronized void stop() {
  118.             status=false;
  119.             th = null;
  120.             Log.e("CheckThread", "stop()");
  121.             notify();
  122.         }
  123.        
  124.         public void main()  {
  125.             final Rows r = new Rows();
  126.             while(status){
  127.                 if(r.countRows()>=0){
  128.                     Log.e("CheckThread", "check...");
  129.                  runOnUiThread(new Runnable(){
  130.                   public void run(){
  131.                     for(int i=0; i<r.countRows(); i++){
  132.                     text.setText(r.getRow(i));
  133.                     text.startAnimation(anim);
  134.                     }
  135.                       }
  136.                  });
  137.                  
  138.                 }
  139.                        
  140.                 if(!status)break;
  141.             }
  142.              
  143.        }
  144.        
  145.     }  
  146.    
  147.     public static String getRNDText(){
  148.         String s = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnprstuvwxyz ";
  149.         Random r = new Random();
  150.         String v="";
  151.         for(int i=0;i<30;i++){
  152.         v += s.charAt(r.nextInt(s.length()));
  153.         }
  154.         return v;
  155.         }
  156.  
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement