-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
94 lines (63 loc) · 2.64 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.example.alarmpart;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
TimePicker timePicker;
TextView textView;
int mHour,mMin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timePicker = (TimePicker)findViewById(R.id.timePicker);
textView = (TextView)findViewById(R.id.timetext);
Button mute = (Button) findViewById(R.id.mute);
mute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),ttt_part.class);
startActivity(intent);
}
});
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
mHour= hourOfDay;
mMin= minute;
textView.setText(textView.getText().toString());
}
});
}
public void setTimer(View v){
AlarmManager alarmManager= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Date date = new Date();
Calendar cal_alarm = Calendar.getInstance();
Calendar cal_now = Calendar.getInstance();
cal_now.setTime(date);
cal_alarm.setTime(date);
cal_alarm.set(Calendar.HOUR_OF_DAY,mHour);
cal_alarm.set(Calendar.MINUTE,mMin);
cal_alarm.set(Calendar.SECOND,0);
if(cal_alarm.before(cal_now)){
cal_alarm.add(Calendar.DATE,1);
}
Intent i = new Intent(MainActivity.this,MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,24444,i,0);
alarmManager.set(AlarmManager.RTC_WAKEUP,cal_alarm.getTimeInMillis(),pendingIntent);
}
public void muter(){
final AudioManager audioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}