質問編集履歴
12
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,289 +1,73 @@
|
|
1
1
|
```### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
3
|
+
public static final String ALARM_TIME = "alarm_time";
|
4
4
|
|
5
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
6
5
|
|
7
|
-
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
8
6
|
|
9
|
-
|
7
|
+
Button button;
|
10
8
|
|
11
|
-
|
9
|
+
ToggleButton alarmButton;
|
12
10
|
|
13
|
-
|
11
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
14
12
|
|
15
|
-
|
13
|
+
PreferenceUtil pref;
|
16
14
|
|
17
|
-
![イメージ説明](4696bc358ab4200e531cfc056540bcd1.png)
|
18
15
|
|
19
|
-
```
|
20
16
|
|
21
|
-
|
17
|
+
@Override
|
22
18
|
|
23
|
-
|
19
|
+
protected void onCreate(Bundle savedInstanceState) {
|
24
20
|
|
25
|
-
|
21
|
+
super.onCreate(savedInstanceState);
|
26
22
|
|
27
|
-
|
23
|
+
setContentView(R.layout.activity_main);
|
28
24
|
|
29
|
-
|
25
|
+
Button sendButton = findViewById(R.id.nextButton);
|
30
26
|
|
31
|
-
|
27
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
32
28
|
|
33
|
-
|
29
|
+
@Override
|
34
30
|
|
35
|
-
i
|
31
|
+
public void onClick(View v) {
|
36
32
|
|
37
|
-
i
|
33
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
38
34
|
|
39
|
-
|
35
|
+
startActivity(intent);
|
40
36
|
|
41
|
-
|
37
|
+
}
|
42
38
|
|
43
|
-
|
39
|
+
});
|
44
40
|
|
45
|
-
|
41
|
+
pref = new PreferenceUtil(this);
|
46
42
|
|
47
|
-
|
43
|
+
setupViews();
|
48
44
|
|
49
|
-
|
45
|
+
setListeners();
|
50
46
|
|
51
|
-
|
47
|
+
}
|
52
48
|
|
53
|
-
import java.text.DateFormat;
|
54
49
|
|
55
|
-
import java.text.SimpleDateFormat;
|
56
50
|
|
57
|
-
|
51
|
+
private void setupViews() {
|
58
52
|
|
59
|
-
|
53
|
+
button = (Button) findViewById(R.id.button);
|
60
54
|
|
61
|
-
|
55
|
+
alarmButton = (ToggleButton) findViewById(R.id.AlarmButton);
|
62
56
|
|
63
|
-
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
64
57
|
|
65
|
-
public class MainActivity extends AppCompatActivity {
|
66
58
|
|
67
|
-
|
59
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
68
60
|
|
69
|
-
|
61
|
+
if (alarmTime != 0) {
|
70
62
|
|
71
|
-
|
63
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
72
64
|
|
73
|
-
|
65
|
+
Date date = new Date(alarmTime);
|
74
66
|
|
75
|
-
|
67
|
+
button.setText(df.format(date));
|
76
68
|
|
77
|
-
|
69
|
+
alarmButton.setChecked(true);
|
78
70
|
|
79
|
-
|
71
|
+
}
|
80
72
|
|
81
|
-
protected void onCreate(Bundle savedInstanceState) {
|
82
|
-
|
83
|
-
super.onCreate(savedInstanceState);
|
84
|
-
|
85
|
-
setContentView(R.layout.activity_main);
|
86
|
-
|
87
|
-
Button sendButton = findViewById(R.id.nextButton);
|
88
|
-
|
89
|
-
sendButton.setOnClickListener(new View.OnClickListener() {
|
90
|
-
|
91
|
-
@Override
|
92
|
-
|
93
|
-
public void onClick(View v) {
|
94
|
-
|
95
|
-
Intent intent = new Intent(getApplication(), SubActivity.class);
|
96
|
-
|
97
|
-
startActivity(intent);
|
98
|
-
|
99
|
-
|
73
|
+
}
|
100
|
-
|
101
|
-
});
|
102
|
-
|
103
|
-
pref = new PreferenceUtil(this);
|
104
|
-
|
105
|
-
setupViews();
|
106
|
-
|
107
|
-
setListeners();
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
private void setupViews() {
|
112
|
-
|
113
|
-
button = (Button) findViewById(R.id.button);
|
114
|
-
|
115
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
116
|
-
|
117
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
118
|
-
|
119
|
-
if (alarmTime != 0) {
|
120
|
-
|
121
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
122
|
-
|
123
|
-
Date date = new Date(alarmTime);
|
124
|
-
|
125
|
-
button.setText(df.format(date));
|
126
|
-
|
127
|
-
alarmSwitch.setChecked(true);
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
private void setListeners() {
|
134
|
-
|
135
|
-
button.setOnClickListener(new View.OnClickListener() {
|
136
|
-
|
137
|
-
@Override
|
138
|
-
|
139
|
-
public void onClick(View view) {
|
140
|
-
|
141
|
-
final Calendar calendar = Calendar.getInstance();
|
142
|
-
|
143
|
-
final int year = calendar.get(Calendar.YEAR);
|
144
|
-
|
145
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
146
|
-
|
147
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
148
|
-
|
149
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
150
|
-
|
151
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
152
|
-
|
153
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
154
|
-
|
155
|
-
@Override
|
156
|
-
|
157
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
158
|
-
|
159
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
160
|
-
|
161
|
-
@Override
|
162
|
-
|
163
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
164
|
-
|
165
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
166
|
-
|
167
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
168
|
-
|
169
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
170
|
-
|
171
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
172
|
-
|
173
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
174
|
-
|
175
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
176
|
-
|
177
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
178
|
-
|
179
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
180
|
-
|
181
|
-
// 過去だったら明日にする
|
182
|
-
|
183
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
184
|
-
|
185
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
186
|
-
|
187
|
-
}*/
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
}, hour, minute, true);
|
192
|
-
|
193
|
-
timePickerDialog.show();
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
}, year, monthOfYear, dayOfMonth);
|
198
|
-
|
199
|
-
datePickerDialog.show();
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
});
|
204
|
-
|
205
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
206
|
-
|
207
|
-
@Override
|
208
|
-
|
209
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
210
|
-
|
211
|
-
if (isChecked) {
|
212
|
-
|
213
|
-
register(alarmCalendar.getTimeInMillis());
|
214
|
-
|
215
|
-
} else {
|
216
|
-
|
217
|
-
unregister();
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
});
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
// 登録
|
228
|
-
|
229
|
-
private void register(long alarmTimeMillis) {
|
230
|
-
|
231
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
232
|
-
|
233
|
-
PendingIntent pendingIntent = getPendingIntent();
|
234
|
-
|
235
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
236
|
-
|
237
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
238
|
-
|
239
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
240
|
-
|
241
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
242
|
-
|
243
|
-
} else {
|
244
|
-
|
245
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
// 保存
|
250
|
-
|
251
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
// 解除
|
256
|
-
|
257
|
-
private void unregister() {
|
258
|
-
|
259
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
260
|
-
|
261
|
-
alarmManager.cancel(getPendingIntent());
|
262
|
-
|
263
|
-
pref.delete(ALARM_TIME);
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
private PendingIntent getPendingIntent() {
|
268
|
-
|
269
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
270
|
-
|
271
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
272
|
-
|
273
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
274
|
-
|
275
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
276
|
-
|
277
|
-
// あとからのものが上書きされる
|
278
|
-
|
279
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
```
|
286
|
-
|
287
|
-
### 補足情報(FW/ツールのバージョンなど)
|
288
|
-
|
289
|
-
Android Studio ver3.1.3
|
11
意図的な内容抹消の取り消し
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Android アラーム 画面遷移
|
test
CHANGED
@@ -1,23 +1,289 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
```### 前提・実現したいこと
|
2
|
+
|
3
|
+
二度寝防止シンプルなアラームアプリを作成中です。
|
4
|
+
|
5
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
6
|
+
|
7
|
+
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
8
|
+
|
9
|
+
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
![イメージ説明](58398f9f10fd21b22f8e64edbe49f6c7.png)
|
14
|
+
|
15
|
+
![イメージ説明](8cdac80b5d4e98bcdd0ffd848a31a853.png)
|
16
|
+
|
17
|
+
![イメージ説明](4696bc358ab4200e531cfc056540bcd1.png)
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
import android.app.Activity;
|
22
|
+
|
23
|
+
import android.app.AlarmManager;
|
24
|
+
|
25
|
+
import android.app.DatePickerDialog;
|
26
|
+
|
27
|
+
import android.app.PendingIntent;
|
28
|
+
|
29
|
+
import android.app.TimePickerDialog;
|
30
|
+
|
31
|
+
import android.content.Context;
|
32
|
+
|
33
|
+
import android.content.Intent;
|
34
|
+
|
35
|
+
import android.os.Build;
|
36
|
+
|
37
|
+
import android.os.Bundle;
|
38
|
+
|
39
|
+
import android.support.v7.app.AppCompatActivity;
|
40
|
+
|
41
|
+
import android.view.View;
|
42
|
+
|
43
|
+
import android.widget.Button;
|
44
|
+
|
45
|
+
import android.widget.CompoundButton;
|
46
|
+
|
47
|
+
import android.widget.DatePicker;
|
48
|
+
|
49
|
+
import android.widget.Switch;
|
50
|
+
|
51
|
+
import android.widget.TimePicker;
|
52
|
+
|
53
|
+
import java.text.DateFormat;
|
54
|
+
|
55
|
+
import java.text.SimpleDateFormat;
|
56
|
+
|
57
|
+
import java.util.Calendar;
|
58
|
+
|
59
|
+
import java.util.Date;
|
60
|
+
|
61
|
+
import java.util.Set;
|
62
|
+
|
63
|
+
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
64
|
+
|
65
|
+
public class MainActivity extends AppCompatActivity {
|
66
|
+
|
67
|
+
public static final String ALARM_TIME = "alarm_time";
|
68
|
+
|
69
|
+
Button button;
|
70
|
+
|
71
|
+
Button nextButton;
|
72
|
+
|
73
|
+
Switch alarmSwitch;
|
74
|
+
|
75
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
76
|
+
|
77
|
+
PreferenceUtil pref;
|
78
|
+
|
79
|
+
@Override
|
80
|
+
|
81
|
+
protected void onCreate(Bundle savedInstanceState) {
|
82
|
+
|
83
|
+
super.onCreate(savedInstanceState);
|
84
|
+
|
85
|
+
setContentView(R.layout.activity_main);
|
86
|
+
|
87
|
+
Button sendButton = findViewById(R.id.nextButton);
|
88
|
+
|
89
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
90
|
+
|
91
|
+
@Override
|
92
|
+
|
93
|
+
public void onClick(View v) {
|
94
|
+
|
95
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
96
|
+
|
97
|
+
startActivity(intent);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
pref = new PreferenceUtil(this);
|
104
|
+
|
105
|
+
setupViews();
|
106
|
+
|
107
|
+
setListeners();
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
private void setupViews() {
|
112
|
+
|
113
|
+
button = (Button) findViewById(R.id.button);
|
114
|
+
|
115
|
+
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
116
|
+
|
117
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
118
|
+
|
119
|
+
if (alarmTime != 0) {
|
120
|
+
|
121
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
122
|
+
|
123
|
+
Date date = new Date(alarmTime);
|
124
|
+
|
125
|
+
button.setText(df.format(date));
|
126
|
+
|
127
|
+
alarmSwitch.setChecked(true);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
private void setListeners() {
|
134
|
+
|
135
|
+
button.setOnClickListener(new View.OnClickListener() {
|
136
|
+
|
137
|
+
@Override
|
138
|
+
|
139
|
+
public void onClick(View view) {
|
140
|
+
|
141
|
+
final Calendar calendar = Calendar.getInstance();
|
142
|
+
|
143
|
+
final int year = calendar.get(Calendar.YEAR);
|
144
|
+
|
145
|
+
final int monthOfYear = calendar.get(Calendar.MONTH);
|
146
|
+
|
147
|
+
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
148
|
+
|
149
|
+
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
150
|
+
|
151
|
+
final int minute = calendar.get(Calendar.MINUTE);
|
152
|
+
|
153
|
+
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
154
|
+
|
155
|
+
@Override
|
156
|
+
|
157
|
+
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
158
|
+
|
159
|
+
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
160
|
+
|
161
|
+
@Override
|
162
|
+
|
163
|
+
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
164
|
+
|
165
|
+
alarmCalendar.set(Calendar.YEAR, y);
|
166
|
+
|
167
|
+
alarmCalendar.set(Calendar.MONTH, m);
|
168
|
+
|
169
|
+
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
170
|
+
|
171
|
+
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
172
|
+
|
173
|
+
alarmCalendar.set(Calendar.MINUTE, minute);
|
174
|
+
|
175
|
+
alarmCalendar.set(Calendar.SECOND, 0);
|
176
|
+
|
177
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
178
|
+
|
179
|
+
button.setText(df.format(alarmCalendar.getTime()));
|
180
|
+
|
181
|
+
// 過去だったら明日にする
|
182
|
+
|
183
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
184
|
+
|
185
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
186
|
+
|
187
|
+
}*/
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}, hour, minute, true);
|
192
|
+
|
193
|
+
timePickerDialog.show();
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}, year, monthOfYear, dayOfMonth);
|
198
|
+
|
199
|
+
datePickerDialog.show();
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
206
|
+
|
207
|
+
@Override
|
208
|
+
|
209
|
+
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
210
|
+
|
211
|
+
if (isChecked) {
|
212
|
+
|
213
|
+
register(alarmCalendar.getTimeInMillis());
|
214
|
+
|
215
|
+
} else {
|
216
|
+
|
217
|
+
unregister();
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
// 登録
|
228
|
+
|
229
|
+
private void register(long alarmTimeMillis) {
|
230
|
+
|
231
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
232
|
+
|
233
|
+
PendingIntent pendingIntent = getPendingIntent();
|
234
|
+
|
235
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
236
|
+
|
237
|
+
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
238
|
+
|
239
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
240
|
+
|
241
|
+
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
242
|
+
|
243
|
+
} else {
|
244
|
+
|
245
|
+
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
// 保存
|
250
|
+
|
251
|
+
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
// 解除
|
256
|
+
|
257
|
+
private void unregister() {
|
258
|
+
|
259
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
260
|
+
|
261
|
+
alarmManager.cancel(getPendingIntent());
|
262
|
+
|
263
|
+
pref.delete(ALARM_TIME);
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
private PendingIntent getPendingIntent() {
|
268
|
+
|
269
|
+
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
270
|
+
|
271
|
+
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
272
|
+
|
273
|
+
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
274
|
+
|
275
|
+
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
276
|
+
|
277
|
+
// あとからのものが上書きされる
|
278
|
+
|
279
|
+
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
### 補足情報(FW/ツールのバージョンなど)
|
288
|
+
|
289
|
+
Android Studio ver3.1.3
|
10
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
aaawwwwwwwwwww
|
test
CHANGED
@@ -1,333 +1,23 @@
|
|
1
|
-
|
1
|
+
// 低ボタンが押された時
|
2
2
|
|
3
|
+
Button rowButton = findViewById(R.id.row_button);
|
3
4
|
|
4
|
-
|
5
|
-
二度寝防止シンプルなアラームアプリを作成中です。
|
6
|
-
|
7
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
8
|
-
|
9
|
-
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
10
|
-
|
11
|
-
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
![イメージ説明](58398f9f10fd21b22f8e64edbe49f6c7.png)
|
24
|
-
|
25
|
-
![イメージ説明](8cdac80b5d4e98bcdd0ffd848a31a853.png)
|
26
|
-
|
27
|
-
![イメージ説明](4696bc358ab4200e531cfc056540bcd1.png)
|
28
|
-
|
29
|
-
```
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
import android.app.Activity;
|
34
|
-
|
35
|
-
import android.app.AlarmManager;
|
36
|
-
|
37
|
-
import android.app.DatePickerDialog;
|
38
|
-
|
39
|
-
import android.app.PendingIntent;
|
40
|
-
|
41
|
-
import android.app.TimePickerDialog;
|
42
|
-
|
43
|
-
import android.content.Context;
|
44
|
-
|
45
|
-
import android.content.Intent;
|
46
|
-
|
47
|
-
import android.os.Build;
|
48
|
-
|
49
|
-
import android.os.Bundle;
|
50
|
-
|
51
|
-
import android.support.v7.app.AppCompatActivity;
|
52
|
-
|
53
|
-
import android.view.View;
|
54
|
-
|
55
|
-
import android.widget.Button;
|
56
|
-
|
57
|
-
import android.widget.CompoundButton;
|
58
|
-
|
59
|
-
import android.widget.DatePicker;
|
60
|
-
|
61
|
-
import android.widget.Switch;
|
62
|
-
|
63
|
-
import android.widget.TimePicker;
|
64
|
-
|
65
|
-
import java.text.DateFormat;
|
66
|
-
|
67
|
-
import java.text.SimpleDateFormat;
|
68
|
-
|
69
|
-
import java.util.Calendar;
|
70
|
-
|
71
|
-
import java.util.Date;
|
72
|
-
|
73
|
-
import java.util.Set;
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
public class MainActivity extends AppCompatActivity {
|
82
|
-
|
83
|
-
|
5
|
+
rowButton.setOnClickListener(new View.OnClickListener() { // returnButtonになっていた
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Button button;
|
88
|
-
|
89
|
-
Button nextButton;
|
90
|
-
|
91
|
-
Switch alarmSwitch;
|
92
|
-
|
93
|
-
Calendar alarmCalendar = Calendar.getInstance();
|
94
|
-
|
95
|
-
PreferenceUtil pref;
|
96
|
-
|
97
|
-
|
98
6
|
|
99
7
|
@Override
|
100
8
|
|
101
|
-
p
|
9
|
+
public void onClick(View v) {
|
102
10
|
|
103
|
-
|
11
|
+
SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE);
|
104
12
|
|
105
|
-
|
13
|
+
SharedPreferences.Editor editor = data.edit();
|
106
14
|
|
107
|
-
|
15
|
+
editor.putInt("LevelSave", 1); // 1:低、2:中、3:高の3段階があるとする。
|
108
16
|
|
109
|
-
|
17
|
+
editor.apply();
|
110
18
|
|
111
|
-
@Override
|
112
|
-
|
113
|
-
public void onClick(View v) {
|
114
|
-
|
115
|
-
|
19
|
+
Toast.makeText(SubActivity.this, "簡単がクリックされました!", Toast.LENGTH_LONG).show();
|
116
|
-
|
117
|
-
startActivity(intent);
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
});
|
122
|
-
|
123
|
-
pref = new PreferenceUtil(this);
|
124
|
-
|
125
|
-
setupViews();
|
126
|
-
|
127
|
-
setListeners();
|
128
|
-
|
129
|
-
|
130
20
|
|
131
21
|
}
|
132
22
|
|
133
|
-
|
134
|
-
|
135
|
-
private void setupViews() {
|
136
|
-
|
137
|
-
button = (Button) findViewById(R.id.button);
|
138
|
-
|
139
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
144
|
-
|
145
|
-
if (alarmTime != 0) {
|
146
|
-
|
147
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
148
|
-
|
149
|
-
Date date = new Date(alarmTime);
|
150
|
-
|
151
|
-
button.setText(df.format(date));
|
152
|
-
|
153
|
-
alarmSwitch.setChecked(true);
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
private void setListeners() {
|
162
|
-
|
163
|
-
button.setOnClickListener(new View.OnClickListener() {
|
164
|
-
|
165
|
-
@Override
|
166
|
-
|
167
|
-
public void onClick(View view) {
|
168
|
-
|
169
|
-
final Calendar calendar = Calendar.getInstance();
|
170
|
-
|
171
|
-
final int year = calendar.get(Calendar.YEAR);
|
172
|
-
|
173
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
174
|
-
|
175
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
176
|
-
|
177
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
178
|
-
|
179
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
180
|
-
|
181
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
182
|
-
|
183
|
-
@Override
|
184
|
-
|
185
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
186
|
-
|
187
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
188
|
-
|
189
|
-
@Override
|
190
|
-
|
191
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
192
|
-
|
193
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
194
|
-
|
195
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
196
|
-
|
197
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
198
|
-
|
199
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
200
|
-
|
201
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
202
|
-
|
203
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
204
|
-
|
205
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
206
|
-
|
207
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
208
|
-
|
209
|
-
// 過去だったら明日にする
|
210
|
-
|
211
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
212
|
-
|
213
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
214
|
-
|
215
|
-
}*/
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
}, hour, minute, true);
|
220
|
-
|
221
|
-
timePickerDialog.show();
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
}, year, monthOfYear, dayOfMonth);
|
226
|
-
|
227
|
-
datePickerDialog.show();
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
23
|
+
});
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
236
|
-
|
237
|
-
@Override
|
238
|
-
|
239
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
240
|
-
|
241
|
-
if (isChecked) {
|
242
|
-
|
243
|
-
register(alarmCalendar.getTimeInMillis());
|
244
|
-
|
245
|
-
} else {
|
246
|
-
|
247
|
-
unregister();
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
});
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
// 登録
|
262
|
-
|
263
|
-
private void register(long alarmTimeMillis) {
|
264
|
-
|
265
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
266
|
-
|
267
|
-
PendingIntent pendingIntent = getPendingIntent();
|
268
|
-
|
269
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
270
|
-
|
271
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
272
|
-
|
273
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
274
|
-
|
275
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
276
|
-
|
277
|
-
} else {
|
278
|
-
|
279
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
// 保存
|
284
|
-
|
285
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
// 解除
|
292
|
-
|
293
|
-
private void unregister() {
|
294
|
-
|
295
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
296
|
-
|
297
|
-
alarmManager.cancel(getPendingIntent());
|
298
|
-
|
299
|
-
pref.delete(ALARM_TIME);
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
private PendingIntent getPendingIntent() {
|
306
|
-
|
307
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
308
|
-
|
309
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
310
|
-
|
311
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
312
|
-
|
313
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
314
|
-
|
315
|
-
// あとからのものが上書きされる
|
316
|
-
|
317
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
```
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
### 補足情報(FW/ツールのバージョンなど)
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
Android Studio ver3.1.3
|
9
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,8 +10,6 @@
|
|
10
10
|
|
11
11
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
12
|
|
13
|
-
![イメージ説明](a2d99be8e54d2eb03dc7c6ccb9d2ed33.png)![イメージ説明](fc98a37f6773dcfeed4f499955a809ad.png)
|
14
|
-
|
15
13
|
|
16
14
|
|
17
15
|
|
@@ -22,6 +20,12 @@
|
|
22
20
|
|
23
21
|
```
|
24
22
|
|
23
|
+
![イメージ説明](58398f9f10fd21b22f8e64edbe49f6c7.png)
|
24
|
+
|
25
|
+
![イメージ説明](8cdac80b5d4e98bcdd0ffd848a31a853.png)
|
26
|
+
|
27
|
+
![イメージ説明](4696bc358ab4200e531cfc056540bcd1.png)
|
28
|
+
|
25
29
|
```
|
26
30
|
|
27
31
|
|
8
自力で画面遷移ができたので、他の問題を教えてほしいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,11 +10,11 @@
|
|
10
10
|
|
11
11
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
12
|
|
13
|
-
![イメージ説明](e705fb47220188df8fadd70a85385537.png)
|
14
|
-
|
15
|
-
![イメージ説明](e
|
13
|
+
![イメージ説明](a2d99be8e54d2eb03dc7c6ccb9d2ed33.png)![イメージ説明](fc98a37f6773dcfeed4f499955a809ad.png)
|
16
|
-
|
17
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -22,6 +22,8 @@
|
|
22
22
|
|
23
23
|
```
|
24
24
|
|
25
|
+
```
|
26
|
+
|
25
27
|
|
26
28
|
|
27
29
|
import android.app.Activity;
|
7
自力で画面遷移ができたので、他の問題を教えてほしいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,313 @@
|
|
10
10
|
|
11
11
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
12
|
|
13
|
-
![イメージ説明](e705fb47220188df8fadd70a85385537.png)
|
13
|
+
![イメージ説明](e705fb47220188df8fadd70a85385537.png)
|
14
|
+
|
14
|
-
|
15
|
+
![イメージ説明](e6d7bc11613a6bf83e325cf6d1129d45.png)
|
16
|
+
|
17
|
+
![イメージ説明](91e3fd6f1fbf680197cd9c7eace18c46.png)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
import android.app.Activity;
|
28
|
+
|
29
|
+
import android.app.AlarmManager;
|
30
|
+
|
31
|
+
import android.app.DatePickerDialog;
|
32
|
+
|
33
|
+
import android.app.PendingIntent;
|
34
|
+
|
35
|
+
import android.app.TimePickerDialog;
|
36
|
+
|
37
|
+
import android.content.Context;
|
38
|
+
|
39
|
+
import android.content.Intent;
|
40
|
+
|
41
|
+
import android.os.Build;
|
42
|
+
|
43
|
+
import android.os.Bundle;
|
44
|
+
|
45
|
+
import android.support.v7.app.AppCompatActivity;
|
46
|
+
|
47
|
+
import android.view.View;
|
48
|
+
|
49
|
+
import android.widget.Button;
|
50
|
+
|
51
|
+
import android.widget.CompoundButton;
|
52
|
+
|
53
|
+
import android.widget.DatePicker;
|
54
|
+
|
55
|
+
import android.widget.Switch;
|
56
|
+
|
57
|
+
import android.widget.TimePicker;
|
58
|
+
|
59
|
+
import java.text.DateFormat;
|
60
|
+
|
61
|
+
import java.text.SimpleDateFormat;
|
62
|
+
|
63
|
+
import java.util.Calendar;
|
64
|
+
|
65
|
+
import java.util.Date;
|
66
|
+
|
67
|
+
import java.util.Set;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public class MainActivity extends AppCompatActivity {
|
76
|
+
|
77
|
+
public static final String ALARM_TIME = "alarm_time";
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
Button button;
|
82
|
+
|
83
|
+
Button nextButton;
|
84
|
+
|
85
|
+
Switch alarmSwitch;
|
86
|
+
|
87
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
88
|
+
|
89
|
+
PreferenceUtil pref;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
@Override
|
94
|
+
|
95
|
+
protected void onCreate(Bundle savedInstanceState) {
|
96
|
+
|
97
|
+
super.onCreate(savedInstanceState);
|
98
|
+
|
99
|
+
setContentView(R.layout.activity_main);
|
100
|
+
|
101
|
+
Button sendButton = findViewById(R.id.nextButton);
|
102
|
+
|
103
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
104
|
+
|
105
|
+
@Override
|
106
|
+
|
107
|
+
public void onClick(View v) {
|
108
|
+
|
109
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
110
|
+
|
111
|
+
startActivity(intent);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
});
|
116
|
+
|
117
|
+
pref = new PreferenceUtil(this);
|
118
|
+
|
15
|
-
|
119
|
+
setupViews();
|
120
|
+
|
121
|
+
setListeners();
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
private void setupViews() {
|
130
|
+
|
131
|
+
button = (Button) findViewById(R.id.button);
|
132
|
+
|
133
|
+
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
138
|
+
|
139
|
+
if (alarmTime != 0) {
|
140
|
+
|
141
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
142
|
+
|
143
|
+
Date date = new Date(alarmTime);
|
144
|
+
|
145
|
+
button.setText(df.format(date));
|
146
|
+
|
147
|
+
alarmSwitch.setChecked(true);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
private void setListeners() {
|
156
|
+
|
157
|
+
button.setOnClickListener(new View.OnClickListener() {
|
158
|
+
|
159
|
+
@Override
|
160
|
+
|
161
|
+
public void onClick(View view) {
|
162
|
+
|
163
|
+
final Calendar calendar = Calendar.getInstance();
|
164
|
+
|
165
|
+
final int year = calendar.get(Calendar.YEAR);
|
166
|
+
|
167
|
+
final int monthOfYear = calendar.get(Calendar.MONTH);
|
168
|
+
|
169
|
+
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
170
|
+
|
171
|
+
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
172
|
+
|
173
|
+
final int minute = calendar.get(Calendar.MINUTE);
|
174
|
+
|
175
|
+
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
176
|
+
|
177
|
+
@Override
|
178
|
+
|
179
|
+
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
180
|
+
|
181
|
+
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
182
|
+
|
183
|
+
@Override
|
184
|
+
|
185
|
+
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
186
|
+
|
187
|
+
alarmCalendar.set(Calendar.YEAR, y);
|
188
|
+
|
189
|
+
alarmCalendar.set(Calendar.MONTH, m);
|
190
|
+
|
191
|
+
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
192
|
+
|
193
|
+
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
194
|
+
|
195
|
+
alarmCalendar.set(Calendar.MINUTE, minute);
|
196
|
+
|
197
|
+
alarmCalendar.set(Calendar.SECOND, 0);
|
198
|
+
|
199
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
200
|
+
|
201
|
+
button.setText(df.format(alarmCalendar.getTime()));
|
202
|
+
|
203
|
+
// 過去だったら明日にする
|
204
|
+
|
205
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
206
|
+
|
207
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
208
|
+
|
209
|
+
}*/
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}, hour, minute, true);
|
214
|
+
|
215
|
+
timePickerDialog.show();
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
}, year, monthOfYear, dayOfMonth);
|
220
|
+
|
221
|
+
datePickerDialog.show();
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
});
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
230
|
+
|
231
|
+
@Override
|
232
|
+
|
233
|
+
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
234
|
+
|
235
|
+
if (isChecked) {
|
236
|
+
|
237
|
+
register(alarmCalendar.getTimeInMillis());
|
238
|
+
|
239
|
+
} else {
|
240
|
+
|
241
|
+
unregister();
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
});
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
// 登録
|
256
|
+
|
257
|
+
private void register(long alarmTimeMillis) {
|
258
|
+
|
259
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
260
|
+
|
261
|
+
PendingIntent pendingIntent = getPendingIntent();
|
262
|
+
|
263
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
264
|
+
|
265
|
+
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
266
|
+
|
267
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
268
|
+
|
269
|
+
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
270
|
+
|
271
|
+
} else {
|
272
|
+
|
273
|
+
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
// 保存
|
278
|
+
|
279
|
+
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// 解除
|
286
|
+
|
287
|
+
private void unregister() {
|
288
|
+
|
289
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
290
|
+
|
291
|
+
alarmManager.cancel(getPendingIntent());
|
292
|
+
|
293
|
+
pref.delete(ALARM_TIME);
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
private PendingIntent getPendingIntent() {
|
300
|
+
|
301
|
+
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
302
|
+
|
303
|
+
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
304
|
+
|
305
|
+
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
306
|
+
|
307
|
+
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
308
|
+
|
309
|
+
// あとからのものが上書きされる
|
310
|
+
|
311
|
+
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
```
|
16
320
|
|
17
321
|
|
18
322
|
|
6
自力で画面遷移ができたので、他の問題を教えてほしいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,304 +14,6 @@
|
|
14
14
|
|
15
15
|
### 該当のソースコード
|
16
16
|
|
17
|
-
```ここに言語を入力
|
18
|
-
|
19
|
-
import android.app.Activity;
|
20
|
-
|
21
|
-
import android.app.AlarmManager;
|
22
|
-
|
23
|
-
import android.app.DatePickerDialog;
|
24
|
-
|
25
|
-
import android.app.PendingIntent;
|
26
|
-
|
27
|
-
import android.app.TimePickerDialog;
|
28
|
-
|
29
|
-
import android.content.Context;
|
30
|
-
|
31
|
-
import android.content.Intent;
|
32
|
-
|
33
|
-
import android.os.Build;
|
34
|
-
|
35
|
-
import android.os.Bundle;
|
36
|
-
|
37
|
-
import android.support.v7.app.AppCompatActivity;
|
38
|
-
|
39
|
-
import android.view.View;
|
40
|
-
|
41
|
-
import android.widget.Button;
|
42
|
-
|
43
|
-
import android.widget.CompoundButton;
|
44
|
-
|
45
|
-
import android.widget.DatePicker;
|
46
|
-
|
47
|
-
import android.widget.Switch;
|
48
|
-
|
49
|
-
import android.widget.TimePicker;
|
50
|
-
|
51
|
-
import java.text.DateFormat;
|
52
|
-
|
53
|
-
import java.text.SimpleDateFormat;
|
54
|
-
|
55
|
-
import java.util.Calendar;
|
56
|
-
|
57
|
-
import java.util.Date;
|
58
|
-
|
59
|
-
import java.util.Set;
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
public class MainActivity extends AppCompatActivity {
|
68
|
-
|
69
|
-
public static final String ALARM_TIME = "alarm_time";
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
Button button;
|
74
|
-
|
75
|
-
Button nextButton;
|
76
|
-
|
77
|
-
Switch alarmSwitch;
|
78
|
-
|
79
|
-
Calendar alarmCalendar = Calendar.getInstance();
|
80
|
-
|
81
|
-
PreferenceUtil pref;
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@Override
|
86
|
-
|
87
|
-
protected void onCreate(Bundle savedInstanceState) {
|
88
|
-
|
89
|
-
super.onCreate(savedInstanceState);
|
90
|
-
|
91
|
-
setContentView(R.layout.activity_main);
|
92
|
-
|
93
|
-
Button sendButton = findViewById(R.id.nextButton);
|
94
|
-
|
95
|
-
sendButton.setOnClickListener(new View.OnClickListener() {
|
96
|
-
|
97
|
-
@Override
|
98
|
-
|
99
|
-
public void onClick(View v) {
|
100
|
-
|
101
|
-
Intent intent = new Intent(getApplication(), SubActivity.class);
|
102
|
-
|
103
|
-
startActivity(intent);
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
});
|
108
|
-
|
109
|
-
pref = new PreferenceUtil(this);
|
110
|
-
|
111
|
-
setupViews();
|
112
|
-
|
113
|
-
setListeners();
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
private void setupViews() {
|
122
|
-
|
123
|
-
button = (Button) findViewById(R.id.button);
|
124
|
-
|
125
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
130
|
-
|
131
|
-
if (alarmTime != 0) {
|
132
|
-
|
133
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
134
|
-
|
135
|
-
Date date = new Date(alarmTime);
|
136
|
-
|
137
|
-
button.setText(df.format(date));
|
138
|
-
|
139
|
-
alarmSwitch.setChecked(true);
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
private void setListeners() {
|
148
|
-
|
149
|
-
button.setOnClickListener(new View.OnClickListener() {
|
150
|
-
|
151
|
-
@Override
|
152
|
-
|
153
|
-
public void onClick(View view) {
|
154
|
-
|
155
|
-
final Calendar calendar = Calendar.getInstance();
|
156
|
-
|
157
|
-
final int year = calendar.get(Calendar.YEAR);
|
158
|
-
|
159
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
160
|
-
|
161
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
162
|
-
|
163
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
164
|
-
|
165
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
166
|
-
|
167
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
168
|
-
|
169
|
-
@Override
|
170
|
-
|
171
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
172
|
-
|
173
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
174
|
-
|
175
|
-
@Override
|
176
|
-
|
177
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
178
|
-
|
179
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
180
|
-
|
181
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
182
|
-
|
183
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
184
|
-
|
185
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
186
|
-
|
187
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
188
|
-
|
189
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
190
|
-
|
191
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
192
|
-
|
193
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
194
|
-
|
195
|
-
// 過去だったら明日にする
|
196
|
-
|
197
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
198
|
-
|
199
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
200
|
-
|
201
|
-
}*/
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}, hour, minute, true);
|
206
|
-
|
207
|
-
timePickerDialog.show();
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
}, year, monthOfYear, dayOfMonth);
|
212
|
-
|
213
|
-
datePickerDialog.show();
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
});
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
222
|
-
|
223
|
-
@Override
|
224
|
-
|
225
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
226
|
-
|
227
|
-
if (isChecked) {
|
228
|
-
|
229
|
-
register(alarmCalendar.getTimeInMillis());
|
230
|
-
|
231
|
-
} else {
|
232
|
-
|
233
|
-
unregister();
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
});
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
// 登録
|
248
|
-
|
249
|
-
private void register(long alarmTimeMillis) {
|
250
|
-
|
251
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
252
|
-
|
253
|
-
PendingIntent pendingIntent = getPendingIntent();
|
254
|
-
|
255
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
256
|
-
|
257
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
258
|
-
|
259
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
260
|
-
|
261
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
262
|
-
|
263
|
-
} else {
|
264
|
-
|
265
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
// 保存
|
270
|
-
|
271
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
// 解除
|
278
|
-
|
279
|
-
private void unregister() {
|
280
|
-
|
281
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
282
|
-
|
283
|
-
alarmManager.cancel(getPendingIntent());
|
284
|
-
|
285
|
-
pref.delete(ALARM_TIME);
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
private PendingIntent getPendingIntent() {
|
292
|
-
|
293
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
294
|
-
|
295
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
296
|
-
|
297
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
298
|
-
|
299
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
300
|
-
|
301
|
-
// あとからのものが上書きされる
|
302
|
-
|
303
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
```
|
312
|
-
|
313
|
-
|
314
|
-
|
315
17
|
|
316
18
|
|
317
19
|
### 補足情報(FW/ツールのバージョンなど)
|
5
更新
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
4
自力で画面遷移ができたので、他の問題を教えてほしいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
+
```### 前提・実現したいこと
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
二度寝防止シンプルなアラームアプリを作成中です。
|
6
|
+
|
7
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
8
|
+
|
9
|
+
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
10
|
+
|
11
|
+
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
|
+
|
13
|
+
![イメージ説明](e705fb47220188df8fadd70a85385537.png)![イメージ説明](3c6331af43cfa569ef561268a52b07d9.png)![![イメージ説明](3ed6f0dce5993751a9b907c7a8c234de.png)
|
14
|
+
|
15
|
+
### 該当のソースコード
|
16
|
+
|
1
17
|
```ここに言語を入力
|
2
18
|
|
3
|
-
コード
|
4
|
-
|
5
|
-
```### 前提・実現したいこと
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
二度寝防止シンプルなアラームアプリを作成中です。
|
10
|
-
|
11
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
12
|
-
|
13
|
-
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
14
|
-
|
15
|
-
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
16
|
-
|
17
|
-
![イメージ説明](e705fb47220188df8fadd70a85385537.png)![イメージ説明](3c6331af43cfa569ef561268a52b07d9.png)![![イメージ説明](3ed6f0dce5993751a9b907c7a8c234de.png)
|
18
|
-
|
19
|
-
### 該当のソースコード
|
20
|
-
|
21
|
-
```ここに言語を入力
|
22
|
-
|
23
19
|
import android.app.Activity;
|
24
20
|
|
25
21
|
import android.app.AlarmManager;
|
3
わかりにくい指摘
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
1
|
-
### 前提・実現したいこと
|
5
|
+
```### 前提・実現したいこと
|
2
6
|
|
3
7
|
|
4
8
|
|
5
9
|
二度寝防止シンプルなアラームアプリを作成中です。
|
6
10
|
|
7
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
11
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
8
12
|
|
9
13
|
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
10
14
|
|
11
15
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
12
16
|
|
13
|
-
![イメージ説明](e705fb47220188df8fadd70a85385537.png)![イメージ説明](3c6331af43cfa569ef561268a52b07d9.png)
|
17
|
+
![イメージ説明](e705fb47220188df8fadd70a85385537.png)![イメージ説明](3c6331af43cfa569ef561268a52b07d9.png)![![イメージ説明](3ed6f0dce5993751a9b907c7a8c234de.png)
|
14
18
|
|
15
19
|
### 該当のソースコード
|
16
20
|
|
17
|
-
|
21
|
+
```ここに言語を入力
|
18
|
-
|
19
|
-
|
20
22
|
|
21
23
|
import android.app.Activity;
|
22
24
|
|
@@ -310,8 +312,6 @@
|
|
310
312
|
|
311
313
|
|
312
314
|
|
313
|
-
|
314
|
-
|
315
315
|
```
|
316
316
|
|
317
317
|
|
2
自力で画面遷移ができたので、他の問題を教えてほしいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,22 +2,18 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
二度寝防止シンプルなアラームアプリを作成中です。
|
6
|
+
|
5
|
-
|
7
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
6
|
-
|
8
|
+
|
7
|
-
|
9
|
+
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
8
10
|
|
9
11
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
10
12
|
|
11
|
-
![イメージ説明](e705fb47220188df8fadd70a85385537.png)
|
13
|
+
![イメージ説明](e705fb47220188df8fadd70a85385537.png)![イメージ説明](3c6331af43cfa569ef561268a52b07d9.png)
|
12
14
|
|
13
15
|
### 該当のソースコード
|
14
16
|
|
15
|
-
MainActivity.java
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
```ここに言語名を入力
|
20
|
-
|
21
17
|
package ararm3.jackn.opengl.com.myalarm4;
|
22
18
|
|
23
19
|
|
@@ -40,14 +36,8 @@
|
|
40
36
|
|
41
37
|
import android.os.Bundle;
|
42
38
|
|
43
|
-
import android.provider.Settings;
|
44
|
-
|
45
39
|
import android.support.v7.app.AppCompatActivity;
|
46
40
|
|
47
|
-
import android.util.Log;
|
48
|
-
|
49
|
-
import android.util.MonthDisplayHelper;
|
50
|
-
|
51
41
|
import android.view.View;
|
52
42
|
|
53
43
|
import android.widget.Button;
|
@@ -56,50 +46,36 @@
|
|
56
46
|
|
57
47
|
import android.widget.DatePicker;
|
58
48
|
|
59
|
-
import android.widget.EditText;
|
60
|
-
|
61
49
|
import android.widget.Switch;
|
62
50
|
|
63
|
-
import android.widget.TextView;
|
64
|
-
|
65
51
|
import android.widget.TimePicker;
|
66
52
|
|
67
|
-
import android.widget.Toast;
|
68
|
-
|
69
|
-
import android.text.format.Time;
|
70
|
-
|
71
53
|
import java.text.DateFormat;
|
72
54
|
|
73
55
|
import java.text.SimpleDateFormat;
|
74
56
|
|
75
|
-
import java.time.Month;
|
76
|
-
|
77
57
|
import java.util.Calendar;
|
78
58
|
|
79
59
|
import java.util.Date;
|
80
60
|
|
61
|
+
import java.util.Set;
|
62
|
+
|
81
63
|
|
82
64
|
|
83
65
|
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
84
66
|
|
85
|
-
import ararm3.jackn.opengl.com.myalarm4.util.SecondActivity;
|
86
|
-
|
87
|
-
import ararm3.jackn.opengl.com.myalarm4.util.SubActivity;
|
88
|
-
|
89
67
|
|
90
68
|
|
91
69
|
public class MainActivity extends AppCompatActivity {
|
92
70
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
71
|
public static final String ALARM_TIME = "alarm_time";
|
98
72
|
|
99
73
|
|
100
74
|
|
101
75
|
Button button;
|
102
76
|
|
77
|
+
Button nextButton;
|
78
|
+
|
103
79
|
Switch alarmSwitch;
|
104
80
|
|
105
81
|
Calendar alarmCalendar = Calendar.getInstance();
|
@@ -116,15 +92,31 @@
|
|
116
92
|
|
117
93
|
setContentView(R.layout.activity_main);
|
118
94
|
|
95
|
+
Button sendButton = findViewById(R.id.nextButton);
|
96
|
+
|
97
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
98
|
+
|
99
|
+
@Override
|
100
|
+
|
101
|
+
public void onClick(View v) {
|
102
|
+
|
103
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
104
|
+
|
105
|
+
startActivity(intent);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
});
|
110
|
+
|
119
111
|
pref = new PreferenceUtil(this);
|
120
112
|
|
121
113
|
setupViews();
|
122
114
|
|
123
115
|
setListeners();
|
124
116
|
|
117
|
+
|
118
|
+
|
125
|
-
}
|
119
|
+
}
|
126
|
-
|
127
|
-
|
128
120
|
|
129
121
|
|
130
122
|
|
@@ -198,13 +190,17 @@
|
|
198
190
|
|
199
191
|
alarmCalendar.set(Calendar.SECOND, 0);
|
200
192
|
|
201
|
-
|
202
|
-
|
203
193
|
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
204
194
|
|
205
195
|
button.setText(df.format(alarmCalendar.getTime()));
|
206
196
|
|
207
|
-
|
197
|
+
// 過去だったら明日にする
|
198
|
+
|
199
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
200
|
+
|
201
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
202
|
+
|
203
|
+
}*/
|
208
204
|
|
209
205
|
}
|
210
206
|
|
@@ -218,10 +214,6 @@
|
|
218
214
|
|
219
215
|
datePickerDialog.show();
|
220
216
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
217
|
}
|
226
218
|
|
227
219
|
});
|
@@ -314,22 +306,16 @@
|
|
314
306
|
|
315
307
|
}
|
316
308
|
|
317
|
-
|
318
|
-
|
319
309
|
}
|
320
310
|
|
321
311
|
|
322
312
|
|
313
|
+
|
314
|
+
|
323
315
|
```
|
324
316
|
|
325
317
|
|
326
318
|
|
327
|
-
### 試したこと
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
メインのレイアウトにボタン(nextButton)を配置し、クリックしたら画面遷移したいがうまくいかない。
|
332
|
-
|
333
319
|
|
334
320
|
|
335
321
|
### 補足情報(FW/ツールのバージョンなど)
|
1
タイトル更新
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Android アラーム
|
1
|
+
Android アラーム 画面遷移
|
test
CHANGED
File without changes
|