SHARE
TWEET

Untitled

a guest Jun 25th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private Boolean  statusKeyboard = false;
  4. private EditText mTextoEditor1;
  5. private Button mBotonSend;
  6. private TextView mDumpTextView;
  7. private MiTareaAsincrona tarea1;
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11.     super.onCreate( savedInstanceState );
  12.     setContentView( R.layout.activity_main );
  13.     Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar );
  14.     setSupportActionBar( toolbar );
  15.  
  16.     mBotonSend = findViewById(R.id.bt2_SendButton);
  17.     mDumpTextView = (TextView) findViewById(R.id.tv1_ReadValues);
  18.     mTextoEditor1 = (EditText) findViewById(R.id.et1_WriteValues);
  19.  
  20.     mBotonSend.setOnClickListener(new View.OnClickListener() {
  21.         @Override
  22.         public void onClick(View view) {
  23.             String message = mTextoEditor1.getText().toString();
  24.             if (mTextoEditor1.getText().toString().trim().equals("")) {
  25.                 Toast.makeText(MainActivity.this, "Por favar Ingresar al texto...", Toast.LENGTH_SHORT).show();
  26.             } else {                                
  27.                 mDumpTextView.append( message + "rn" );
  28.             }
  29.             mTextoEditor1.setText("");
  30.         }
  31.     });
  32.  
  33.     tarea1 = new MiTareaAsincrona();
  34.     tarea1.execute();
  35. }
  36.  
  37. private class MiTareaAsincrona extends AsyncTask<Void, Integer, Boolean> {
  38.     @Override
  39.     protected Boolean doInBackground(Void... params) {
  40.         setupTimer(20);
  41.         return true;
  42.     }
  43.  
  44.     @Override
  45.     protected void onPostExecute(Boolean result) {
  46.         if(result)
  47.             Toast.makeText(MainActivity.this, "Timer finalizado!", Toast.LENGTH_SHORT).show();
  48.     }
  49.  
  50.     @Override
  51.     protected void onCancelled() { }
  52. }
  53.  
  54. private void setupTimer(Integer milisegundos) {
  55.     new CountDownTimer( milisegundos, 1000 ) {
  56.         public void onTick(long millisUntilFinished) {
  57.             //mDumpTextView.setText( "seconds: " + millisUntilFinished / 1000 );
  58.         }
  59.  
  60.         public void onFinish() {
  61.             mDumpTextView.setText( "done!" );
  62.             start();
  63.         }
  64.     }.start();
  65.   }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top