CountDownTimer Absolute / Horas / Minutos / Segundos / Milisegundos / Plural String



📋
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/toast_layout_root"    android:layout_width="match_parent"    android:layout_height="fill_parent">
  
<EditText      
android:id="@+id/getminutes"   
android:layout_width="match_parent"  
android:layout_height="wrap_content"  
android:layout_above="@+id/start"      
android:layout_centerHorizontal="true"  
android:ems="10"       
android:hint="Minutes"      
android:inputType="number" />
  


<Button       
android:id="@+id/start" 
android:layout_width="wrap_content"  
android:layout_height="wrap_content"  
android:layout_centerHorizontal="true"    
android:layout_centerVertical="true"      
android:text="Start" />
  


<RelativeLayout    
android:id="@+id/timerLayout"   
android:layout_width="match_parent" 
android:layout_height="wrap_content"  
android:layout_above="@+id/getminutes" 
android:layout_alignParentLeft="true"   
android:layout_alignParentStart="true"   
android:background="@drawable/buttonshape"  
android:visibility="gone">
  




<TextView       
android:id="@+id/milli"    
android:layout_width="100dp" 
android:layout_height="wrap_content"    
android:layout_alignBaseline="@+id/seconds" 
android:layout_alignBottom="@+id/seconds" 
android:layout_alignParentEnd="true"       
android:layout_alignParentRight="true"     
android:layout_marginEnd="11dp"       
android:layout_marginRight="11dp"     
android:background="@drawable/buttonshape"  
android:padding="10dp"       
android:text="milliseconds"   
android:textAlignment="center"  
android:textColor="@color/common_google_signin_btn_text_dark_default" />

  

<TextView       
android:id="@+id/seconds"       
android:layout_width="120dp"    
android:layout_height="wrap_content"  
android:layout_alignParentTop="true"   
android:layout_marginLeft="19dp"        
android:layout_marginStart="19dp"       
android:layout_toEndOf="@+id/minutes"   
android:layout_toRightOf="@+id/minutes"     
android:background="@drawable/buttonshape"   
android:padding="10dp"        
android:text="seconds"       
android:textAlignment="center"  
android:textColor="@color/common_google_signin_btn_text_dark_default" />



  

<TextView      
android:id="@+id/minutes"  
android:layout_width="100dp" 
android:layout_height="wrap_content"     
android:layout_alignParentTop="true"     
android:layout_toEndOf="@+id/hours"     
android:layout_toRightOf="@+id/hours"   
android:background="@drawable/buttonshape"   
android:padding="10dp"       
android:text="minutes"       
android:textAlignment="center" 
android:textColor="@color/common_google_signin_btn_text_dark_default" />



  

<TextView       
android:id="@+id/hours"  
android:layout_width="100dp"      
android:layout_height="wrap_content"  
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:background="@drawable/buttonshape"
android:padding="10dp"
android:text="hours"
android:textAlignment="center"
android:textColor="@color/common_google_signin_btn_text_dark_default" />



  

</RelativeLayout>

  


    <Button  
android:id="@+id/Finish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/start"
android:layout_alignStart="@+id/start"
android:layout_below="@+id/start"
android:text="Button" />
  




</RelativeLayout>





📋
 package My_package_name;

import android.content.res.Resources;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.text.InputFilter;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.concurrent.TimeUnit;

/** * Created by AllanRibas on 01/12/2017. */
public class AbsoluteTimer extends AppCompatActivity {
    TextView hours;
    TextView seconds;
    TextView minutes;
    TextView milli;
    EditText getminutes;
    Button Finish;
    Button start;
    RelativeLayout timerLayout;
    CountDownTimer aCountDownTimer;
    String hora;
    String minuto;
    String segundo;
    Resources res;
    int TEMPO;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.absolute_timer);
        timerLayout = (RelativeLayout) findViewById(R.id.timerLayout);
        start = (Button) findViewById(R.id.start);
        Finish = (Button) findViewById(R.id.Finish);
        getminutes = (EditText) findViewById(R.id.getminutes);
        getminutes.setFilters(new InputFilter[]{new InputFilter.LengthFilter(3)});
        hours = (TextView) findViewById(R.id.hours);
        minutes = (TextView) findViewById(R.id.minutes);
        seconds = (TextView) findViewById(R.id.seconds);
        milli = (TextView) findViewById(R.id.milli);
        res = getResources();
        
        Finish.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                System.exit(0);
            }
        });
        
        start.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                String GetTime = getminutes.getText().toString();
                if(GetTime.length()>0){
                    timerLayout.setVisibility(View.VISIBLE);
                    TEMPO = Integer.parseInt(getminutes.getText().toString())*20000*3;//60000                    
     aCountDownTimer = new CountDownTimer(TEMPO, 5) {
                        public void onTick(long Tempos) {
                            String HORA = String.valueOf(TimeUnit.MILLISECONDS.toHours(Tempos));
                            String MINUTO = String.valueOf(TimeUnit.MILLISECONDS.toMinutes(Tempos) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(Tempos)));
                            String SEGUNDO = String.valueOf(TimeUnit.MILLISECONDS.toSeconds(Tempos) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(Tempos)));
                            String MILLI = String.valueOf(TimeUnit.MILLISECONDS.toMillis(Tempos) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(Tempos)));
                            hora = res.getQuantityString(R.plurals.hora, Integer.parseInt(HORA), "", Integer.parseInt(HORA));
                            minuto = res.getQuantityString(R.plurals.minuto, Integer.parseInt(MINUTO), "", Integer.parseInt(MINUTO));
                            segundo = res.getQuantityString(R.plurals.segundo, Integer.parseInt(SEGUNDO), "", Integer.parseInt(SEGUNDO));
                            hours.setText(""+HORA+" :"+hora);
                            minutes.setText(""+MINUTO+" :"+minuto);
                            seconds.setText(""+SEGUNDO+" :"+segundo);
                            milli.setText(MILLI);
                        }
                        public void onFinish() {

                        }
                    }.start();
                }else{
                    getminutes.setHint("Type a value in minutes, to continue...");
                }
            }
        });
    }
}


 



📋
 
 <!DOCTYPE resources [
    <!ENTITY hora "hora">
    <!ENTITY minuto "minuto">
    <!ENTITY segundo "segundo">

    <!ENTITY horas "horas">
    <!ENTITY minutos "minutos">
    <!ENTITY segundos "segundos">
    ]><resources>
    <string name="app_name">AKSR</string>
    <string name="action_settings">Settings</string>

    <plurals name="hora">
        <item quantity="one">&hora;</item>
        <item quantity="other">&horas;</item>
    </plurals>
    <plurals name="minuto">
        <item quantity="one">&minuto;</item>
        <item quantity="other">&minutos;</item>
    </plurals>
    <plurals name="segundo">
        <item quantity="one">&segundo;</item>
        <item quantity="other">&segundos;</item>
    </plurals>
</resources>

 
  



Nenhum comentário:

Postar um comentário

Obrigado por comentar, volte sempre!

Seguidores

Pages




Ajude continuar nossos projetos.    

Copie este código: [[address]]

Donation of [[value]] BTC Received. Thank You.
[[error]]






Copiado