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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | package bme.sleep; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.SeekBar; import android.widget.TextView; import android.widget.TimePicker; public class WeakUpSetup extends Activity { private Button StartBT; private TimePicker TimeP; private SeekBar VolumeB; private TextView VolumeTV; public static final String PREF = "WeakUp_PREF"; public static final String PREF_BEFORE = "Is_Pref_Before"; public static final String PREF_HOUR = "WeakUp_HOUR"; public static final String PREF_MINUTE = "WeakUp_MINUTE"; public static final String PREF_VOLUME = "WeakUp_VOLUME"; private int WeakUpHour; private int WeakUpMinute; private int WeakVolume; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.weakup_setup); findViews(); // 宣告介面元件 restorePrefs(); // 載入偏好設定 // 防止手機因手持方向不同 而觸發螢幕方向旋轉 setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); VolumeB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) { /* WeakVolume = seekBar.getProgress(); TextView VolumeTV = (TextView) findViewById(R.id.SubTitle_volume); VolumeTV.setText("響鈴音量" + WeakVolume + "/7"); */ } public void onStartTrackingTouch(SeekBar seekBar) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { WeakVolume = seekBar.getProgress(); TextView VolumeTV = (TextView) findViewById(R.id.SubTitle_volume); VolumeTV.setText("響鈴音量" + WeakVolume + "/7"); } }); StartBT.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { WeakUpHour = TimeP.getCurrentHour(); WeakUpMinute = TimeP.getCurrentMinute(); WeakVolume = VolumeB.getProgress(); Intent intent = new Intent(); intent.setClass(WeakUpSetup.this, Capturing.class); Bundle bundle = new Bundle(); bundle.putInt("KEY_HOUR", TimeP.getCurrentHour()); bundle.putInt("KEY_MINUTE", TimeP.getCurrentMinute()); bundle.putInt("KEY_VOLUME", VolumeB.getProgress()); intent.putExtras(bundle); startActivity(intent); WeakUpSetup.this.finish(); } }); } protected void onPause(){ super.onPause(); SharedPreferences settings = getSharedPreferences(PREF, 0); settings.edit() .putBoolean(PREF_BEFORE, true) .putInt(PREF_HOUR, TimeP.getCurrentHour()) .putInt(PREF_MINUTE, TimeP.getCurrentMinute()) .putInt(PREF_VOLUME, VolumeB.getProgress()) .commit(); } private void restorePrefs() { //取得偏好設定 SharedPreferences settings = getSharedPreferences(PREF, 0); boolean isPrefBefore = settings.getBoolean(PREF_BEFORE, false); WeakUpHour = settings.getInt(PREF_HOUR, 6); WeakUpMinute = settings.getInt(PREF_MINUTE, 0); WeakVolume = settings.getInt(PREF_VOLUME, 5); //設定各元件參數 TimeP.setCurrentHour(WeakUpHour); TimeP.setCurrentMinute(WeakUpMinute); VolumeB.setProgress(WeakVolume); VolumeTV.setText("響鈴音量" + WeakVolume + "%"); TimeP.setIs24HourView(true); if(isPrefBefore){ StartBT.requestFocus(); } } private void findViews() { //宣告介面元件 StartBT = (Button) findViewById(R.id.StartButton); TimeP = (TimePicker) findViewById(R.id.TimePicker01); VolumeB = (SeekBar) findViewById(R.id.VolumeBar); VolumeTV = (TextView) findViewById(R.id.SubTitle_volume); } } |
Direct link: https://paste.plurk.com/show/ACfUuB2AHHxAPNlltgyr