import android.annotation.TargetApi;
import android.icu.util.Calendar;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
@TargetApi(Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread myThread = null;
Runnable runnable = new CountDownRunner();
myThread= new Thread(runnable);
myThread.start();
}
public void doWork() {
runOnUiThread(new Runnable() {
@TargetApi(Build.VERSION_CODES.N)
public void run() {
try{
Button botonJAVA = (Button)findViewById(R.id.botonXML);
Button boton2JAVA = (Button)findViewById(R.id.boton2XML);
TextView txtCurrentTime= (TextView)findViewById(R.id.hola);
TextView hora= (TextView)findViewById(R.id.hola2);
Calendar c = Calendar .getInstance();
int second = c.get(Calendar.SECOND);
int minute = c.get(Calendar.MINUTE);
int hour = c.get(Calendar.HOUR);
String time = hour+":"+minute+":"+second;
txtCurrentTime.setText("La hora es : " + time);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":" + minutes + ":" + seconds;
hora.setText(curTime);
if ((hours==10)&&(minutes==00))
{
botonJAVA.setEnabled(true);
}
else
{
botonJAVA.setEnabled(false);
}
if ((hour==12)&&(minutes==00))
{
botonJAVA.setEnabled(false);
}
if ((hour==4)&&(minutes==00))
{
boton2JAVA.setEnabled(true);
}
else
{
boton2JAVA.setEnabled(false);
}
if ((hour==7)&&(minutes==00))
{
boton2JAVA.setEnabled(false);
}
}catch (Exception e) {}
}
});
}
class CountDownRunner implements Runnable{
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()){
try {
doWork();
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch(Exception e){
}
}
}
}
}