質問編集履歴
12
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,145 +1,37 @@
|
|
1
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
|
-
Calendar alarmCalendar = Calendar.getInstance();
|
39
|
-
PreferenceUtil pref;
|
40
|
-
@Override
|
41
|
-
protected void onCreate(Bundle savedInstanceState) {
|
42
|
-
super.onCreate(savedInstanceState);
|
43
|
-
setContentView(R.layout.activity_main);
|
44
|
-
Button sendButton = findViewById(R.id.nextButton);
|
45
|
-
sendButton.setOnClickListener(new View.OnClickListener() {
|
46
|
-
@Override
|
47
|
-
public void onClick(View v) {
|
48
|
-
Intent intent = new Intent(getApplication(), SubActivity.class);
|
49
|
-
startActivity(intent);
|
50
|
-
}
|
51
|
-
});
|
52
|
-
pref = new PreferenceUtil(this);
|
53
|
-
setupViews();
|
54
|
-
setListeners();
|
55
|
-
}
|
56
|
-
private void setupViews() {
|
57
|
-
button = (Button) findViewById(R.id.button);
|
58
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
59
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
60
|
-
if (alarmTime != 0) {
|
61
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
62
|
-
Date date = new Date(alarmTime);
|
63
|
-
button.setText(df.format(date));
|
64
|
-
alarmSwitch.setChecked(true);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
private void setListeners() {
|
68
|
-
button.setOnClickListener(new View.OnClickListener() {
|
69
|
-
@Override
|
70
|
-
public void onClick(View view) {
|
71
|
-
final Calendar calendar = Calendar.getInstance();
|
72
|
-
final int year = calendar.get(Calendar.YEAR);
|
73
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
74
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
75
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
76
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
77
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
78
|
-
@Override
|
79
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
80
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
81
|
-
@Override
|
82
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
83
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
84
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
85
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
86
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
87
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
88
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
89
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
90
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
91
|
-
// 過去だったら明日にする
|
92
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
93
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
94
|
-
}*/
|
95
|
-
}
|
96
|
-
}, hour, minute, true);
|
97
|
-
timePickerDialog.show();
|
98
|
-
}
|
99
|
-
}, year, monthOfYear, dayOfMonth);
|
100
|
-
datePickerDialog.show();
|
101
|
-
}
|
102
|
-
});
|
103
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
104
|
-
@Override
|
105
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
106
|
-
if (isChecked) {
|
107
|
-
register(alarmCalendar.getTimeInMillis());
|
108
|
-
} else {
|
109
|
-
unregister();
|
110
|
-
}
|
111
|
-
}
|
112
|
-
});
|
113
|
-
}
|
114
|
-
// 登録
|
115
|
-
private void register(long alarmTimeMillis) {
|
116
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
117
|
-
PendingIntent pendingIntent = getPendingIntent();
|
118
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
119
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
120
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
121
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
122
|
-
} else {
|
123
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
124
|
-
}
|
125
|
-
// 保存
|
126
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
127
|
-
}
|
128
|
-
// 解除
|
129
|
-
private void unregister() {
|
130
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
131
|
-
alarmManager.cancel(getPendingIntent());
|
132
|
-
pref.delete(ALARM_TIME);
|
133
|
-
}
|
134
|
-
private PendingIntent getPendingIntent() {
|
135
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
136
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
137
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
138
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
139
|
-
// あとからのものが上書きされる
|
140
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
141
|
-
}
|
142
|
-
}
|
143
|
-
```
|
144
|
-
### 補足情報(FW/ツールのバージョンなど)
|
145
|
-
Android Studio ver3.1.3
|
2
|
+
public static final String ALARM_TIME = "alarm_time";
|
3
|
+
|
4
|
+
Button button;
|
5
|
+
ToggleButton alarmButton;
|
6
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
7
|
+
PreferenceUtil pref;
|
8
|
+
|
9
|
+
@Override
|
10
|
+
protected void onCreate(Bundle savedInstanceState) {
|
11
|
+
super.onCreate(savedInstanceState);
|
12
|
+
setContentView(R.layout.activity_main);
|
13
|
+
Button sendButton = findViewById(R.id.nextButton);
|
14
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
15
|
+
@Override
|
16
|
+
public void onClick(View v) {
|
17
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
18
|
+
startActivity(intent);
|
19
|
+
}
|
20
|
+
});
|
21
|
+
pref = new PreferenceUtil(this);
|
22
|
+
setupViews();
|
23
|
+
setListeners();
|
24
|
+
}
|
25
|
+
|
26
|
+
private void setupViews() {
|
27
|
+
button = (Button) findViewById(R.id.button);
|
28
|
+
alarmButton = (ToggleButton) findViewById(R.id.AlarmButton);
|
29
|
+
|
30
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
31
|
+
if (alarmTime != 0) {
|
32
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
33
|
+
Date date = new Date(alarmTime);
|
34
|
+
button.setText(df.format(date));
|
35
|
+
alarmButton.setChecked(true);
|
36
|
+
}
|
37
|
+
}
|
11
意図的な内容抹消の取り消し
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Android アラーム 画面遷移
|
body
CHANGED
@@ -1,12 +1,145 @@
|
|
1
|
+
```### 前提・実現したいこと
|
1
|
-
|
2
|
+
二度寝防止シンプルなアラームアプリを作成中です。
|
3
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
4
|
+
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
5
|
+
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
6
|
+
```
|
7
|
+

|
8
|
+

|
9
|
+

|
10
|
+
```
|
11
|
+
import android.app.Activity;
|
12
|
+
import android.app.AlarmManager;
|
13
|
+
import android.app.DatePickerDialog;
|
14
|
+
import android.app.PendingIntent;
|
15
|
+
import android.app.TimePickerDialog;
|
16
|
+
import android.content.Context;
|
17
|
+
import android.content.Intent;
|
18
|
+
import android.os.Build;
|
19
|
+
import android.os.Bundle;
|
20
|
+
import android.support.v7.app.AppCompatActivity;
|
21
|
+
import android.view.View;
|
22
|
+
import android.widget.Button;
|
2
|
-
|
23
|
+
import android.widget.CompoundButton;
|
24
|
+
import android.widget.DatePicker;
|
25
|
+
import android.widget.Switch;
|
26
|
+
import android.widget.TimePicker;
|
27
|
+
import java.text.DateFormat;
|
28
|
+
import java.text.SimpleDateFormat;
|
29
|
+
import java.util.Calendar;
|
30
|
+
import java.util.Date;
|
31
|
+
import java.util.Set;
|
32
|
+
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
33
|
+
public class MainActivity extends AppCompatActivity {
|
3
|
-
|
34
|
+
public static final String ALARM_TIME = "alarm_time";
|
35
|
+
Button button;
|
36
|
+
Button nextButton;
|
37
|
+
Switch alarmSwitch;
|
38
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
39
|
+
PreferenceUtil pref;
|
4
|
-
|
40
|
+
@Override
|
41
|
+
protected void onCreate(Bundle savedInstanceState) {
|
42
|
+
super.onCreate(savedInstanceState);
|
43
|
+
setContentView(R.layout.activity_main);
|
44
|
+
Button sendButton = findViewById(R.id.nextButton);
|
45
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
46
|
+
@Override
|
5
|
-
|
47
|
+
public void onClick(View v) {
|
6
|
-
|
48
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
7
|
-
SharedPreferences.Editor editor = data.edit();
|
8
|
-
editor.putInt("LevelSave", 1); // 1:低、2:中、3:高の3段階があるとする。
|
9
|
-
|
49
|
+
startActivity(intent);
|
10
|
-
Toast.makeText(SubActivity.this, "簡単がクリックされました!", Toast.LENGTH_LONG).show();
|
11
|
-
|
50
|
+
}
|
12
|
-
});
|
51
|
+
});
|
52
|
+
pref = new PreferenceUtil(this);
|
53
|
+
setupViews();
|
54
|
+
setListeners();
|
55
|
+
}
|
56
|
+
private void setupViews() {
|
57
|
+
button = (Button) findViewById(R.id.button);
|
58
|
+
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
59
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
60
|
+
if (alarmTime != 0) {
|
61
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
62
|
+
Date date = new Date(alarmTime);
|
63
|
+
button.setText(df.format(date));
|
64
|
+
alarmSwitch.setChecked(true);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
private void setListeners() {
|
68
|
+
button.setOnClickListener(new View.OnClickListener() {
|
69
|
+
@Override
|
70
|
+
public void onClick(View view) {
|
71
|
+
final Calendar calendar = Calendar.getInstance();
|
72
|
+
final int year = calendar.get(Calendar.YEAR);
|
73
|
+
final int monthOfYear = calendar.get(Calendar.MONTH);
|
74
|
+
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
75
|
+
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
76
|
+
final int minute = calendar.get(Calendar.MINUTE);
|
77
|
+
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
78
|
+
@Override
|
79
|
+
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
80
|
+
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
81
|
+
@Override
|
82
|
+
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
83
|
+
alarmCalendar.set(Calendar.YEAR, y);
|
84
|
+
alarmCalendar.set(Calendar.MONTH, m);
|
85
|
+
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
86
|
+
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
87
|
+
alarmCalendar.set(Calendar.MINUTE, minute);
|
88
|
+
alarmCalendar.set(Calendar.SECOND, 0);
|
89
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
90
|
+
button.setText(df.format(alarmCalendar.getTime()));
|
91
|
+
// 過去だったら明日にする
|
92
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
93
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
94
|
+
}*/
|
95
|
+
}
|
96
|
+
}, hour, minute, true);
|
97
|
+
timePickerDialog.show();
|
98
|
+
}
|
99
|
+
}, year, monthOfYear, dayOfMonth);
|
100
|
+
datePickerDialog.show();
|
101
|
+
}
|
102
|
+
});
|
103
|
+
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
104
|
+
@Override
|
105
|
+
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
106
|
+
if (isChecked) {
|
107
|
+
register(alarmCalendar.getTimeInMillis());
|
108
|
+
} else {
|
109
|
+
unregister();
|
110
|
+
}
|
111
|
+
}
|
112
|
+
});
|
113
|
+
}
|
114
|
+
// 登録
|
115
|
+
private void register(long alarmTimeMillis) {
|
116
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
117
|
+
PendingIntent pendingIntent = getPendingIntent();
|
118
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
119
|
+
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
120
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
121
|
+
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
122
|
+
} else {
|
123
|
+
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
124
|
+
}
|
125
|
+
// 保存
|
126
|
+
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
127
|
+
}
|
128
|
+
// 解除
|
129
|
+
private void unregister() {
|
130
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
131
|
+
alarmManager.cancel(getPendingIntent());
|
132
|
+
pref.delete(ALARM_TIME);
|
133
|
+
}
|
134
|
+
private PendingIntent getPendingIntent() {
|
135
|
+
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
136
|
+
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
137
|
+
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
138
|
+
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
139
|
+
// あとからのものが上書きされる
|
140
|
+
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
```
|
144
|
+
### 補足情報(FW/ツールのバージョンなど)
|
145
|
+
Android Studio ver3.1.3
|
10
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
aaawwwwwwwwwww
|
body
CHANGED
@@ -1,167 +1,12 @@
|
|
1
|
-
```### 前提・実現したいこと
|
2
|
-
|
3
|
-
|
1
|
+
// 低ボタンが押された時
|
4
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
5
|
-
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
6
|
-
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
```
|
12
|
-

|
13
|
-

|
14
|
-

|
15
|
-
```
|
16
|
-
|
17
|
-
import android.app.Activity;
|
18
|
-
import android.app.AlarmManager;
|
19
|
-
import android.app.DatePickerDialog;
|
20
|
-
import android.app.PendingIntent;
|
21
|
-
import android.app.TimePickerDialog;
|
22
|
-
import android.content.Context;
|
23
|
-
import android.content.Intent;
|
24
|
-
import android.os.Build;
|
25
|
-
import android.os.Bundle;
|
26
|
-
import android.support.v7.app.AppCompatActivity;
|
27
|
-
import android.view.View;
|
28
|
-
import android.widget.Button;
|
29
|
-
|
2
|
+
Button rowButton = findViewById(R.id.row_button);
|
30
|
-
import android.widget.DatePicker;
|
31
|
-
import android.widget.Switch;
|
32
|
-
import android.widget.TimePicker;
|
33
|
-
import java.text.DateFormat;
|
34
|
-
import java.text.SimpleDateFormat;
|
35
|
-
import java.util.Calendar;
|
36
|
-
import java.util.Date;
|
37
|
-
import java.util.Set;
|
38
|
-
|
39
|
-
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
40
|
-
|
41
|
-
public class MainActivity extends AppCompatActivity {
|
42
|
-
|
3
|
+
rowButton.setOnClickListener(new View.OnClickListener() { // returnButtonになっていた
|
43
|
-
|
44
|
-
Button button;
|
45
|
-
Button nextButton;
|
46
|
-
Switch alarmSwitch;
|
47
|
-
Calendar alarmCalendar = Calendar.getInstance();
|
48
|
-
PreferenceUtil pref;
|
49
|
-
|
50
4
|
@Override
|
51
|
-
protected void onCreate(Bundle savedInstanceState) {
|
52
|
-
super.onCreate(savedInstanceState);
|
53
|
-
setContentView(R.layout.activity_main);
|
54
|
-
Button sendButton = findViewById(R.id.nextButton);
|
55
|
-
sendButton.setOnClickListener(new View.OnClickListener() {
|
56
|
-
@Override
|
57
|
-
|
5
|
+
public void onClick(View v) {
|
58
|
-
|
6
|
+
SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE);
|
59
|
-
startActivity(intent);
|
60
|
-
}
|
61
|
-
});
|
62
|
-
|
7
|
+
SharedPreferences.Editor editor = data.edit();
|
8
|
+
editor.putInt("LevelSave", 1); // 1:低、2:中、3:高の3段階があるとする。
|
63
|
-
|
9
|
+
editor.apply();
|
64
|
-
|
10
|
+
Toast.makeText(SubActivity.this, "簡単がクリックされました!", Toast.LENGTH_LONG).show();
|
65
|
-
|
66
11
|
}
|
67
|
-
|
68
|
-
private void setupViews() {
|
69
|
-
button = (Button) findViewById(R.id.button);
|
70
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
71
|
-
|
72
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
73
|
-
if (alarmTime != 0) {
|
74
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
75
|
-
Date date = new Date(alarmTime);
|
76
|
-
button.setText(df.format(date));
|
77
|
-
alarmSwitch.setChecked(true);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
private void setListeners() {
|
82
|
-
button.setOnClickListener(new View.OnClickListener() {
|
83
|
-
@Override
|
84
|
-
public void onClick(View view) {
|
85
|
-
final Calendar calendar = Calendar.getInstance();
|
86
|
-
final int year = calendar.get(Calendar.YEAR);
|
87
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
88
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
89
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
90
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
91
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
92
|
-
@Override
|
93
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
94
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
95
|
-
@Override
|
96
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
97
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
98
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
99
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
100
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
101
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
102
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
103
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
104
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
105
|
-
// 過去だったら明日にする
|
106
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
107
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
108
|
-
}*/
|
109
|
-
}
|
110
|
-
}, hour, minute, true);
|
111
|
-
timePickerDialog.show();
|
112
|
-
}
|
113
|
-
}, year, monthOfYear, dayOfMonth);
|
114
|
-
datePickerDialog.show();
|
115
|
-
}
|
116
|
-
|
12
|
+
});
|
117
|
-
|
118
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
119
|
-
@Override
|
120
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
121
|
-
if (isChecked) {
|
122
|
-
register(alarmCalendar.getTimeInMillis());
|
123
|
-
} else {
|
124
|
-
unregister();
|
125
|
-
}
|
126
|
-
}
|
127
|
-
});
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
// 登録
|
132
|
-
private void register(long alarmTimeMillis) {
|
133
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
134
|
-
PendingIntent pendingIntent = getPendingIntent();
|
135
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
136
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
137
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
138
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
139
|
-
} else {
|
140
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
141
|
-
}
|
142
|
-
// 保存
|
143
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
144
|
-
}
|
145
|
-
|
146
|
-
// 解除
|
147
|
-
private void unregister() {
|
148
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
149
|
-
alarmManager.cancel(getPendingIntent());
|
150
|
-
pref.delete(ALARM_TIME);
|
151
|
-
}
|
152
|
-
|
153
|
-
private PendingIntent getPendingIntent() {
|
154
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
155
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
156
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
157
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
158
|
-
// あとからのものが上書きされる
|
159
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
```
|
164
|
-
|
165
|
-
### 補足情報(FW/ツールのバージョンなど)
|
166
|
-
|
167
|
-
Android Studio ver3.1.3
|
9
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,12 +4,14 @@
|
|
4
4
|
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
5
5
|
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
6
6
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
|
-

|
8
7
|
|
9
8
|
|
10
9
|
|
11
10
|
|
12
11
|
```
|
12
|
+

|
13
|
+

|
14
|
+

|
13
15
|
```
|
14
16
|
|
15
17
|
import android.app.Activity;
|
8
自力で画面遷移ができたので、他の問題を教えてほしいです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
5
5
|
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
6
6
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
|
-

|
8
|
-

|
9
|
-

|
10
8
|
|
11
9
|
|
10
|
+
|
11
|
+
|
12
12
|
```
|
13
|
+
```
|
13
14
|
|
14
15
|
import android.app.Activity;
|
15
16
|
import android.app.AlarmManager;
|
7
自力で画面遷移ができたので、他の問題を教えてほしいです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,9 +4,161 @@
|
|
4
4
|
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
5
5
|
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
6
6
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
|
-

|
7
|
+

|
8
|
-
|
8
|
+

|
9
|
+

|
9
10
|
|
11
|
+
|
12
|
+
```
|
13
|
+
|
14
|
+
import android.app.Activity;
|
15
|
+
import android.app.AlarmManager;
|
16
|
+
import android.app.DatePickerDialog;
|
17
|
+
import android.app.PendingIntent;
|
18
|
+
import android.app.TimePickerDialog;
|
19
|
+
import android.content.Context;
|
20
|
+
import android.content.Intent;
|
21
|
+
import android.os.Build;
|
22
|
+
import android.os.Bundle;
|
23
|
+
import android.support.v7.app.AppCompatActivity;
|
24
|
+
import android.view.View;
|
25
|
+
import android.widget.Button;
|
26
|
+
import android.widget.CompoundButton;
|
27
|
+
import android.widget.DatePicker;
|
28
|
+
import android.widget.Switch;
|
29
|
+
import android.widget.TimePicker;
|
30
|
+
import java.text.DateFormat;
|
31
|
+
import java.text.SimpleDateFormat;
|
32
|
+
import java.util.Calendar;
|
33
|
+
import java.util.Date;
|
34
|
+
import java.util.Set;
|
35
|
+
|
36
|
+
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
37
|
+
|
38
|
+
public class MainActivity extends AppCompatActivity {
|
39
|
+
public static final String ALARM_TIME = "alarm_time";
|
40
|
+
|
41
|
+
Button button;
|
42
|
+
Button nextButton;
|
43
|
+
Switch alarmSwitch;
|
44
|
+
Calendar alarmCalendar = Calendar.getInstance();
|
45
|
+
PreferenceUtil pref;
|
46
|
+
|
47
|
+
@Override
|
48
|
+
protected void onCreate(Bundle savedInstanceState) {
|
49
|
+
super.onCreate(savedInstanceState);
|
50
|
+
setContentView(R.layout.activity_main);
|
51
|
+
Button sendButton = findViewById(R.id.nextButton);
|
52
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
53
|
+
@Override
|
54
|
+
public void onClick(View v) {
|
55
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
56
|
+
startActivity(intent);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
pref = new PreferenceUtil(this);
|
60
|
+
setupViews();
|
61
|
+
setListeners();
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
private void setupViews() {
|
66
|
+
button = (Button) findViewById(R.id.button);
|
67
|
+
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
68
|
+
|
69
|
+
long alarmTime = pref.getLong(ALARM_TIME);
|
70
|
+
if (alarmTime != 0) {
|
71
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
72
|
+
Date date = new Date(alarmTime);
|
73
|
+
button.setText(df.format(date));
|
74
|
+
alarmSwitch.setChecked(true);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
private void setListeners() {
|
79
|
+
button.setOnClickListener(new View.OnClickListener() {
|
80
|
+
@Override
|
81
|
+
public void onClick(View view) {
|
82
|
+
final Calendar calendar = Calendar.getInstance();
|
83
|
+
final int year = calendar.get(Calendar.YEAR);
|
84
|
+
final int monthOfYear = calendar.get(Calendar.MONTH);
|
85
|
+
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
86
|
+
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
87
|
+
final int minute = calendar.get(Calendar.MINUTE);
|
88
|
+
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
89
|
+
@Override
|
90
|
+
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
91
|
+
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
92
|
+
@Override
|
93
|
+
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
94
|
+
alarmCalendar.set(Calendar.YEAR, y);
|
95
|
+
alarmCalendar.set(Calendar.MONTH, m);
|
96
|
+
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
97
|
+
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
98
|
+
alarmCalendar.set(Calendar.MINUTE, minute);
|
99
|
+
alarmCalendar.set(Calendar.SECOND, 0);
|
100
|
+
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
101
|
+
button.setText(df.format(alarmCalendar.getTime()));
|
102
|
+
// 過去だったら明日にする
|
103
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
104
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
105
|
+
}*/
|
106
|
+
}
|
107
|
+
}, hour, minute, true);
|
108
|
+
timePickerDialog.show();
|
109
|
+
}
|
110
|
+
}, year, monthOfYear, dayOfMonth);
|
111
|
+
datePickerDialog.show();
|
112
|
+
}
|
113
|
+
});
|
114
|
+
|
115
|
+
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
116
|
+
@Override
|
117
|
+
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
118
|
+
if (isChecked) {
|
119
|
+
register(alarmCalendar.getTimeInMillis());
|
120
|
+
} else {
|
121
|
+
unregister();
|
122
|
+
}
|
123
|
+
}
|
124
|
+
});
|
125
|
+
|
126
|
+
}
|
127
|
+
|
128
|
+
// 登録
|
129
|
+
private void register(long alarmTimeMillis) {
|
130
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
131
|
+
PendingIntent pendingIntent = getPendingIntent();
|
132
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
133
|
+
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
134
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
135
|
+
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
136
|
+
} else {
|
137
|
+
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
138
|
+
}
|
139
|
+
// 保存
|
140
|
+
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
141
|
+
}
|
142
|
+
|
143
|
+
// 解除
|
144
|
+
private void unregister() {
|
145
|
+
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
146
|
+
alarmManager.cancel(getPendingIntent());
|
147
|
+
pref.delete(ALARM_TIME);
|
148
|
+
}
|
149
|
+
|
150
|
+
private PendingIntent getPendingIntent() {
|
151
|
+
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
152
|
+
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
153
|
+
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
154
|
+
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
155
|
+
// あとからのものが上書きされる
|
156
|
+
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
```
|
161
|
+
|
10
162
|
### 補足情報(FW/ツールのバージョンなど)
|
11
163
|
|
12
164
|
Android Studio ver3.1.3
|
6
自力で画面遷移ができたので、他の問題を教えてほしいです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,156 +6,7 @@
|
|
6
6
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
7
|

|
8
8
|
### 該当のソースコード
|
9
|
-
```ここに言語を入力
|
10
|
-
import android.app.Activity;
|
11
|
-
import android.app.AlarmManager;
|
12
|
-
import android.app.DatePickerDialog;
|
13
|
-
import android.app.PendingIntent;
|
14
|
-
import android.app.TimePickerDialog;
|
15
|
-
import android.content.Context;
|
16
|
-
import android.content.Intent;
|
17
|
-
import android.os.Build;
|
18
|
-
import android.os.Bundle;
|
19
|
-
import android.support.v7.app.AppCompatActivity;
|
20
|
-
import android.view.View;
|
21
|
-
import android.widget.Button;
|
22
|
-
import android.widget.CompoundButton;
|
23
|
-
import android.widget.DatePicker;
|
24
|
-
import android.widget.Switch;
|
25
|
-
import android.widget.TimePicker;
|
26
|
-
import java.text.DateFormat;
|
27
|
-
import java.text.SimpleDateFormat;
|
28
|
-
import java.util.Calendar;
|
29
|
-
import java.util.Date;
|
30
|
-
import java.util.Set;
|
31
9
|
|
32
|
-
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
33
|
-
|
34
|
-
public class MainActivity extends AppCompatActivity {
|
35
|
-
public static final String ALARM_TIME = "alarm_time";
|
36
|
-
|
37
|
-
Button button;
|
38
|
-
Button nextButton;
|
39
|
-
Switch alarmSwitch;
|
40
|
-
Calendar alarmCalendar = Calendar.getInstance();
|
41
|
-
PreferenceUtil pref;
|
42
|
-
|
43
|
-
@Override
|
44
|
-
protected void onCreate(Bundle savedInstanceState) {
|
45
|
-
super.onCreate(savedInstanceState);
|
46
|
-
setContentView(R.layout.activity_main);
|
47
|
-
Button sendButton = findViewById(R.id.nextButton);
|
48
|
-
sendButton.setOnClickListener(new View.OnClickListener() {
|
49
|
-
@Override
|
50
|
-
public void onClick(View v) {
|
51
|
-
Intent intent = new Intent(getApplication(), SubActivity.class);
|
52
|
-
startActivity(intent);
|
53
|
-
}
|
54
|
-
});
|
55
|
-
pref = new PreferenceUtil(this);
|
56
|
-
setupViews();
|
57
|
-
setListeners();
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
private void setupViews() {
|
62
|
-
button = (Button) findViewById(R.id.button);
|
63
|
-
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
64
|
-
|
65
|
-
long alarmTime = pref.getLong(ALARM_TIME);
|
66
|
-
if (alarmTime != 0) {
|
67
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
68
|
-
Date date = new Date(alarmTime);
|
69
|
-
button.setText(df.format(date));
|
70
|
-
alarmSwitch.setChecked(true);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
private void setListeners() {
|
75
|
-
button.setOnClickListener(new View.OnClickListener() {
|
76
|
-
@Override
|
77
|
-
public void onClick(View view) {
|
78
|
-
final Calendar calendar = Calendar.getInstance();
|
79
|
-
final int year = calendar.get(Calendar.YEAR);
|
80
|
-
final int monthOfYear = calendar.get(Calendar.MONTH);
|
81
|
-
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
82
|
-
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
83
|
-
final int minute = calendar.get(Calendar.MINUTE);
|
84
|
-
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
|
85
|
-
@Override
|
86
|
-
public void onDateSet(DatePicker datePicker, final int y, final int m, final int d) {
|
87
|
-
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
|
88
|
-
@Override
|
89
|
-
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
90
|
-
alarmCalendar.set(Calendar.YEAR, y);
|
91
|
-
alarmCalendar.set(Calendar.MONTH, m);
|
92
|
-
alarmCalendar.set(Calendar.DAY_OF_MONTH, d);
|
93
|
-
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
94
|
-
alarmCalendar.set(Calendar.MINUTE, minute);
|
95
|
-
alarmCalendar.set(Calendar.SECOND, 0);
|
96
|
-
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
97
|
-
button.setText(df.format(alarmCalendar.getTime()));
|
98
|
-
// 過去だったら明日にする
|
99
|
-
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
100
|
-
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
101
|
-
}*/
|
102
|
-
}
|
103
|
-
}, hour, minute, true);
|
104
|
-
timePickerDialog.show();
|
105
|
-
}
|
106
|
-
}, year, monthOfYear, dayOfMonth);
|
107
|
-
datePickerDialog.show();
|
108
|
-
}
|
109
|
-
});
|
110
|
-
|
111
|
-
alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
112
|
-
@Override
|
113
|
-
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
114
|
-
if (isChecked) {
|
115
|
-
register(alarmCalendar.getTimeInMillis());
|
116
|
-
} else {
|
117
|
-
unregister();
|
118
|
-
}
|
119
|
-
}
|
120
|
-
});
|
121
|
-
|
122
|
-
}
|
123
|
-
|
124
|
-
// 登録
|
125
|
-
private void register(long alarmTimeMillis) {
|
126
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
127
|
-
PendingIntent pendingIntent = getPendingIntent();
|
128
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
129
|
-
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmTimeMillis, null), pendingIntent);
|
130
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
131
|
-
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
132
|
-
} else {
|
133
|
-
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTimeMillis, pendingIntent);
|
134
|
-
}
|
135
|
-
// 保存
|
136
|
-
pref.setLong(ALARM_TIME, alarmTimeMillis);
|
137
|
-
}
|
138
|
-
|
139
|
-
// 解除
|
140
|
-
private void unregister() {
|
141
|
-
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
142
|
-
alarmManager.cancel(getPendingIntent());
|
143
|
-
pref.delete(ALARM_TIME);
|
144
|
-
}
|
145
|
-
|
146
|
-
private PendingIntent getPendingIntent() {
|
147
|
-
Intent intent = new Intent(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
148
|
-
intent.setClass(this, ararm3.jackn.opengl.com.myalarm4.AlarmCheckActivity.class);
|
149
|
-
// 複数のアラームを登録する場合はPendingIntent.getBroadcastの第二引数を変更する
|
150
|
-
// 第二引数が同じで第四引数にFLAG_CANCEL_CURRENTがセットされている場合、2回以上呼び出されたときは
|
151
|
-
// あとからのものが上書きされる
|
152
|
-
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
```
|
157
|
-
|
158
|
-
|
159
10
|
### 補足情報(FW/ツールのバージョンなど)
|
160
11
|
|
161
12
|
Android Studio ver3.1.3
|
5
更新
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
4
自力で画面遷移ができたので、他の問題を教えてほしいです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
```ここに言語を入力
|
2
|
-
コード
|
3
1
|
```### 前提・実現したいこと
|
4
2
|
|
5
3
|
二度寝防止シンプルなアラームアプリを作成中です。
|
3
わかりにくい指摘
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
コード
|
1
|
-
### 前提・実現したいこと
|
3
|
+
```### 前提・実現したいこと
|
2
4
|
|
3
5
|
二度寝防止シンプルなアラームアプリを作成中です。
|
4
|
-
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
6
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり(3枚目の画像のイメージ)、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
5
7
|
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
6
8
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
7
|
-

|
9
|
+

|
8
10
|
### 該当のソースコード
|
9
|
-
|
11
|
+
```ここに言語を入力
|
10
|
-
|
11
12
|
import android.app.Activity;
|
12
13
|
import android.app.AlarmManager;
|
13
14
|
import android.app.DatePickerDialog;
|
@@ -154,7 +155,6 @@
|
|
154
155
|
}
|
155
156
|
}
|
156
157
|
|
157
|
-
|
158
158
|
```
|
159
159
|
|
160
160
|
|
2
自力で画面遷移ができたので、他の問題を教えてほしいです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
+
二度寝防止シンプルなアラームアプリを作成中です。
|
3
|
-
|
4
|
+
設定ボタン(nextButton)をクリックすると画面遷移するようになりますが、設定画面(SubActivity)でアラーム解除の計算式の難易度を変更できたり、スヌーズ間隔を設定したいんですが、どんなコードを書けばいいのですか?
|
4
|
-
|
5
|
+
一生懸命、参考集やネットでしらべてもピンとくるものがありませんので、ここで質問します。
|
5
6
|
初心者なので、ネットや参考集で書いたものばっかですが、温かい目でお願いします。
|
6
|
-

|
7
|
+

|
7
8
|
### 該当のソースコード
|
8
|
-
MainActivity.java
|
9
|
-
|
10
|
-
```ここに言語名を入力
|
11
9
|
package ararm3.jackn.opengl.com.myalarm4;
|
12
10
|
|
13
11
|
import android.app.Activity;
|
@@ -19,36 +17,26 @@
|
|
19
17
|
import android.content.Intent;
|
20
18
|
import android.os.Build;
|
21
19
|
import android.os.Bundle;
|
22
|
-
import android.provider.Settings;
|
23
20
|
import android.support.v7.app.AppCompatActivity;
|
24
|
-
import android.util.Log;
|
25
|
-
import android.util.MonthDisplayHelper;
|
26
21
|
import android.view.View;
|
27
22
|
import android.widget.Button;
|
28
23
|
import android.widget.CompoundButton;
|
29
24
|
import android.widget.DatePicker;
|
30
|
-
import android.widget.EditText;
|
31
25
|
import android.widget.Switch;
|
32
|
-
import android.widget.TextView;
|
33
26
|
import android.widget.TimePicker;
|
34
|
-
import android.widget.Toast;
|
35
|
-
import android.text.format.Time;
|
36
27
|
import java.text.DateFormat;
|
37
28
|
import java.text.SimpleDateFormat;
|
38
|
-
import java.time.Month;
|
39
29
|
import java.util.Calendar;
|
40
30
|
import java.util.Date;
|
31
|
+
import java.util.Set;
|
41
32
|
|
42
33
|
import ararm3.jackn.opengl.com.myalarm4.util.PreferenceUtil;
|
43
|
-
import ararm3.jackn.opengl.com.myalarm4.util.SecondActivity;
|
44
|
-
import ararm3.jackn.opengl.com.myalarm4.util.SubActivity;
|
45
34
|
|
46
35
|
public class MainActivity extends AppCompatActivity {
|
47
|
-
|
48
|
-
|
49
36
|
public static final String ALARM_TIME = "alarm_time";
|
50
37
|
|
51
38
|
Button button;
|
39
|
+
Button nextButton;
|
52
40
|
Switch alarmSwitch;
|
53
41
|
Calendar alarmCalendar = Calendar.getInstance();
|
54
42
|
PreferenceUtil pref;
|
@@ -57,12 +45,20 @@
|
|
57
45
|
protected void onCreate(Bundle savedInstanceState) {
|
58
46
|
super.onCreate(savedInstanceState);
|
59
47
|
setContentView(R.layout.activity_main);
|
48
|
+
Button sendButton = findViewById(R.id.nextButton);
|
49
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
50
|
+
@Override
|
51
|
+
public void onClick(View v) {
|
52
|
+
Intent intent = new Intent(getApplication(), SubActivity.class);
|
53
|
+
startActivity(intent);
|
54
|
+
}
|
55
|
+
});
|
60
56
|
pref = new PreferenceUtil(this);
|
61
57
|
setupViews();
|
62
58
|
setListeners();
|
59
|
+
|
63
60
|
}
|
64
61
|
|
65
|
-
|
66
62
|
private void setupViews() {
|
67
63
|
button = (Button) findViewById(R.id.button);
|
68
64
|
alarmSwitch = (Switch) findViewById(R.id.alarm_switch);
|
@@ -98,18 +94,18 @@
|
|
98
94
|
alarmCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
99
95
|
alarmCalendar.set(Calendar.MINUTE, minute);
|
100
96
|
alarmCalendar.set(Calendar.SECOND, 0);
|
101
|
-
|
102
97
|
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
103
98
|
button.setText(df.format(alarmCalendar.getTime()));
|
104
|
-
|
99
|
+
// 過去だったら明日にする
|
100
|
+
/* if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
101
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
102
|
+
}*/
|
105
103
|
}
|
106
104
|
}, hour, minute, true);
|
107
105
|
timePickerDialog.show();
|
108
106
|
}
|
109
107
|
}, year, monthOfYear, dayOfMonth);
|
110
108
|
datePickerDialog.show();
|
111
|
-
|
112
|
-
|
113
109
|
}
|
114
110
|
});
|
115
111
|
|
@@ -156,15 +152,12 @@
|
|
156
152
|
// あとからのものが上書きされる
|
157
153
|
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
158
154
|
}
|
159
|
-
|
160
155
|
}
|
161
156
|
|
157
|
+
|
162
158
|
```
|
163
159
|
|
164
|
-
### 試したこと
|
165
160
|
|
166
|
-
メインのレイアウトにボタン(nextButton)を配置し、クリックしたら画面遷移したいがうまくいかない。
|
167
|
-
|
168
161
|
### 補足情報(FW/ツールのバージョンなど)
|
169
162
|
|
170
163
|
Android Studio ver3.1.3
|
1
タイトル更新
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Android アラーム
|
1
|
+
Android アラーム 画面遷移
|
body
CHANGED
File without changes
|