import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class Setting extends Activity {
private static final String SHAREDPREFERENCES="SleepClock";
private static final String ALARMSTATUS="keyAlarmStatus";
private static final String ALARMTIME="keyAlarmTime";
private static final String SILENTMODE="keysilentmode";
private static final String VIBRATEMODE="keyvibraetmode";
// private static final String ACCELEROMETER="keyaccelerometer";
private static final String SNOOZETIMEPOS="keySnoozeTimePos";
private static final String SNOOZETIME="keySnoozeTime";
private static final String FLIGHTMODE="keyFlightmode";
private static final String RINGTONEPOS="keyRingtonePos";
private static final String RINGTONE="keyRingtone";
private static final String MONDAY="keyMONDAY";
private static final String TUESDAY="keyTUESDAY";
private static final String WEDNESDAY="keyWEDNESDAY";
private static final String THURSDAY="keyTHURSDAY";
private static final String FRIDAY="keyFRIDAY";
private static final String SATURDAY="keySATURDAY";
private static final String SUNDAY="keySUNDAY";
private TextView txtsnoozetime=null;
private TextView txtrepeatday=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.xsetting);
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
boolean boolsilentmode = mSPreferences.getBoolean(SILENTMODE,false);
final CheckBox chkplaysilentmode=(CheckBox)findViewById(R.id.chkplaysilentmode);
chkplaysilentmode.setChecked(boolsilentmode);
chkplaysilentmode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(chkplaysilentmode.isChecked()){
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(SILENTMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Play Silent Mode True", Toast.LENGTH_SHORT).show();
}
else
{
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(SILENTMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Play Silent Mode False", Toast.LENGTH_SHORT).show();
}
}
});
LinearLayout llayplaysilentmode=(LinearLayout)findViewById(R.id.llayplaysilentmode);
llayplaysilentmode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!chkplaysilentmode.isChecked()){
chkplaysilentmode.setChecked(true);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(SILENTMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Play Silent Mode True", Toast.LENGTH_SHORT).show();
}
else
{
chkplaysilentmode.setChecked(false);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(SILENTMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Play Silent Mode False", Toast.LENGTH_SHORT).show();
}
}
});
boolean boolvibratemode = mSPreferences.getBoolean(VIBRATEMODE,true);
final CheckBox chkvibratemode=(CheckBox)findViewById(R.id.chkvibratemode);
chkvibratemode.setChecked(boolvibratemode);
chkvibratemode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(chkvibratemode.isChecked()){
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(VIBRATEMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Vibrate Enable True", Toast.LENGTH_SHORT).show();
}
else
{
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(VIBRATEMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Vibrate Enable False", Toast.LENGTH_SHORT).show();
}
}
});
LinearLayout llayvibratemode=(LinearLayout)findViewById(R.id.llayvibratemode);
llayvibratemode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!chkvibratemode.isChecked()){
chkvibratemode.setChecked(true);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(VIBRATEMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Vibrate Enable True", Toast.LENGTH_SHORT).show();
}
else
{
chkvibratemode.setChecked(false);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(VIBRATEMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Vibrate Enable False", Toast.LENGTH_SHORT).show();
}
}
});
LinearLayout llayringtonesset=(LinearLayout)findViewById(R.id.llayringtonesset);
llayringtonesset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Ringtoneset();
}
});
Button btnringtonesset=(Button)findViewById(R.id.btnringtonesset);
btnringtonesset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Ringtoneset();
}
});
LinearLayout llayringvolumeset=(LinearLayout)findViewById(R.id.llayringvolumeset);
llayringvolumeset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Ringvolumeset();
}
});
Button btnringvolumeset=(Button)findViewById(R.id.btnringvolumeset);
btnringvolumeset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Ringvolumeset();
}
});
LinearLayout llaysnoozetimeset=(LinearLayout)findViewById(R.id.llaysnoozetimeset);
llaysnoozetimeset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Snoozeset();
}
});
Button btnsnoozetimeset=(Button)findViewById(R.id.btnsnoozetimeset);
btnsnoozetimeset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Snoozeset();
}
});
CharSequence[] snoozeitems = {"10 Minutes", "15 Minutes", "20 Minutes"};
// CharSequence[] snoozeitems = {"2 Minutes", "3 Minutes", "4 Minutes"};
int pos = mSPreferences.getInt(SNOOZETIMEPOS,0);
txtsnoozetime=(TextView)findViewById(R.id.txtsnoozetime);
txtsnoozetime.setText(snoozeitems[pos].toString());
txtrepeatday=(TextView)findViewById(R.id.txtrepeatday);
boolrepeat[0]=mSPreferences.getBoolean(MONDAY, true);
boolrepeat[1]=mSPreferences.getBoolean(TUESDAY, true);
boolrepeat[2]=mSPreferences.getBoolean(WEDNESDAY, true);
boolrepeat[3]=mSPreferences.getBoolean(THURSDAY, true);
boolrepeat[4]=mSPreferences.getBoolean(FRIDAY, true);
boolrepeat[5]=mSPreferences.getBoolean(SATURDAY, true);
boolrepeat[6]=mSPreferences.getBoolean(SUNDAY, true);
String strrepeatday = "";
for(int i=0;i < boolrepeat.length;i++){
if(boolrepeat[i]){
strrepeatday=strrepeatday+repeatitemssmall[i];
}
}
if(!strrepeatday.equals("")){
txtrepeatday.setText(strrepeatday);
}
else
{
txtrepeatday.setText("");
}
LinearLayout llayrepeatset=(LinearLayout)findViewById(R.id.llayrepeatset);
llayrepeatset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RepeatAlarm();
}
});
Button btnrepeatset=(Button)findViewById(R.id.btnrepeatset);
btnrepeatset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RepeatAlarm();
}
});
boolean boolAirplanemode = mSPreferences.getBoolean(FLIGHTMODE,true);
final CheckBox chkairplanemode=(CheckBox)findViewById(R.id.chkairplanemode);
chkairplanemode.setChecked(boolAirplanemode);
chkairplanemode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(chkairplanemode.isChecked()){
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(FLIGHTMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Airplane Enable True", Toast.LENGTH_SHORT).show();
}
else
{
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(FLIGHTMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Airplane Enable False", Toast.LENGTH_SHORT).show();
}
}
});
LinearLayout llayairplanemode=(LinearLayout)findViewById(R.id.llayairplanemode);
llayairplanemode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!chkairplanemode.isChecked()){
chkairplanemode.setChecked(true);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(FLIGHTMODE, true);
mEditor.commit();
//Toast.makeText(Setting.this,"Airplane Enable True", Toast.LENGTH_SHORT).show();
}
else
{
chkairplanemode.setChecked(false);
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(FLIGHTMODE, false);
mEditor.commit();
//Toast.makeText(Setting.this,"Airplane Enable False", Toast.LENGTH_SHORT).show();
}
}
});
//
// LinearLayout llaysleepcalculator=(LinearLayout)findViewById(R.id.llaysleepcalculator);
// llaysleepcalculator.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent mIntent=new Intent(Setting.this,TimeCalculator.class);
// startActivity(mIntent);
// }
// });
//
// Button btnsleepcalculator=(Button)findViewById(R.id.btnsleepcalculator);
// btnsleepcalculator.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent mIntent=new Intent(Setting.this,TimeCalculator.class);
// startActivity(mIntent);
// }
// });
// boolean boolaccelerometer = mSPreferences.getBoolean(ACCELEROMETER,true);
// final CheckBox chkaccelerometer=(CheckBox)findViewById(R.id.chkaccelerometer);
// chkaccelerometer.setChecked(boolaccelerometer);
// chkaccelerometer.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// if(chkaccelerometer.isChecked()){
// SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
// SharedPreferences.Editor mEditor=mSharedPreferences.edit();
// mEditor.putBoolean(ACCELEROMETER, true);
// mEditor.commit();
// //Toast.makeText(Setting.this,"Accelerometer Enable True", Toast.LENGTH_SHORT).show();
// }
// else
// {
// SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
// SharedPreferences.Editor mEditor=mSharedPreferences.edit();
// mEditor.putBoolean(ACCELEROMETER, false);
// mEditor.commit();
// //Toast.makeText(Setting.this,"Accelerometer Enable False", Toast.LENGTH_SHORT).show();
// }
// }
// });
// LinearLayout llayaccelerometer=(LinearLayout)findViewById(R.id.llayaccelerometer);
// llayaccelerometer.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// if(!chkaccelerometer.isChecked()){
// chkaccelerometer.setChecked(true);
// SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
// SharedPreferences.Editor mEditor=mSharedPreferences.edit();
// mEditor.putBoolean(ACCELEROMETER, true);
// mEditor.commit();
// //Toast.makeText(Setting.this,"Accelerometer Enable True", Toast.LENGTH_SHORT).show();
// }
// else
// {
// chkaccelerometer.setChecked(false);
// SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
// SharedPreferences.Editor mEditor=mSharedPreferences.edit();
// mEditor.putBoolean(ACCELEROMETER, false);
// mEditor.commit();
// //Toast.makeText(Setting.this,"Accelerometer Enable False", Toast.LENGTH_SHORT).show();
// }
// }
// });
}
//This For Snooze Set
private AlertDialog mAlertDialog = null ;
private void Snoozeset()
{
final int[] snoozetime={10,15,20};
final CharSequence[] snoozeitems = {"10 Minutes", "15 Minutes", "20 Minutes"};
// final int[] snoozetime={2,3,4};
// final CharSequence[] snoozeitems = {"2 Minutes", "3 Minutes", "4 Minutes"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
int pos = mSPreferences.getInt(SNOOZETIMEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(Setting.this);
builder.setTitle("Snooze Minutes");
builder.setSingleChoiceItems(snoozeitems, pos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, snoozeitems[item], Toast.LENGTH_SHORT).show();
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(SNOOZETIME, snoozetime[item]);
mEditor.putInt(SNOOZETIMEPOS, item);
mEditor.commit();
txtsnoozetime.setText(snoozeitems[item].toString());
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(true);
mAlertDialog.show();
}
//This Is For Play Music
private void PlayMusic() {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.setLooping(true);
mMediaPlayer.start();
// i.e. react on the end of the music-file:
// mMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
//
// // @Override
// public void onCompletion(MediaPlayer arg0) {
// System.out.println("Songs Finish");
// }
// });
}
//This Is For Stop Music
private void StopMusic()
{
if(mMediaPlayer!=null)
{
if(mMediaPlayer.isPlaying()==true)
{
mMediaPlayer.release();
mMediaPlayer=null;
}
}
}
@Override
protected void onPause() {
super.onPause();
StopMusic();
}
//This methos use for set ringtone
int ringpos=0;
private MediaPlayer mMediaPlayer=null;
private void Ringtoneset()
{
// final int[] ringtoneid={R.raw.arctic,R.raw.clocks,R.raw.earthquake,R.raw.extream,R.raw.goingsolo,R.raw.hours24,R.raw.leaves,R.raw.lightning,R.raw.midnightafternoon,R.raw.nataschafavorite,R.raw.piano,R.raw.sea,R.raw.water,R.raw.wind,R.raw.summerevening,R.raw.cuckooclock,R.raw.duck,R.raw.birds,R.raw.buffalo,R.raw.cat,R.raw.chrrrchrrr,R.raw.cow,R.raw.delfin,R.raw.elephant,R.raw.frogcroak,R.raw.gecko,R.raw.wolf,R.raw.horse,R.raw.koyal,R.raw.lion,R.raw.monkey,R.raw.sheep,R.raw.magic,R.raw.sparrowsinging};
// final CharSequence[] ringtoneitems = {"Arctic","Clocks","Earth Quake","Extream","Going Solo","Hours 24","Leaves","Lightning","Midnight Afternoon","Natascha's Favorite","Piano","Sea","Water","Wind","Summer Evening","Cuckoo Clock","Duck","Birds","Buffalo","Cat","Chrrr Chrrr","Cow","Delfin","Elephant","Frog Croak","Gecko","Wolf","Horse","Koyal","Lion","Monkey","Sheep","Magic","Sparrow Singing"};
// final int[] ringtoneid={R.raw.arctic,R.raw.extream,R.raw.goingsolo,R.raw.hours24,R.raw.midnightafternoon,R.raw.water,R.raw.cuckooclock,R.raw.duck,R.raw.birds,R.raw.buffalo,R.raw.cat,R.raw.chrrrchrrr,R.raw.cow,R.raw.delfin,R.raw.elephant,R.raw.frogcroak,R.raw.gecko,R.raw.wolf,R.raw.horse,R.raw.koyal,R.raw.lion,R.raw.monkey,R.raw.sheep,R.raw.magic,R.raw.sparrowsinging};
final int[] ringtoneid={R.raw.arctic,R.raw.extream,R.raw.goingsolo,R.raw.hours24,R.raw.midnightafternoon,R.raw.water,R.raw.cuckooclock,R.raw.duck,R.raw.birds,R.raw.cat,R.raw.chrrrchrrr,R.raw.cow,R.raw.delfin,R.raw.elephant,R.raw.gecko,R.raw.wolf,R.raw.horse,R.raw.koyal,R.raw.monkey,R.raw.sheep,R.raw.sparrowsinging};
final CharSequence[] ringtoneitems = {"Arctic","Extream","Going Solo","Hours 24","Midnight Afternoon","Water","Cuckoo Clock","Duck","Birds","Cat","Chrrr Chrrr","Cow","Delfin","Elephant","Gecko","Wolf","Horse","Koyal","Monkey","Sheep","Sparrow Singing"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
ringpos = mSPreferences.getInt(RINGTONEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(Setting.this);
builder.setTitle("Ringtones Set");
builder.setSingleChoiceItems(ringtoneitems, ringpos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, ringtoneitems[item], Toast.LENGTH_SHORT).show();
ringpos=item;
StopMusic();
mMediaPlayer = MediaPlayer.create(Setting.this,ringtoneid[item]);
PlayMusic();
}
});
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(RINGTONE, ringtoneid[ringpos]);
mEditor.putInt(RINGTONEPOS, ringpos);
mEditor.commit();
Toast.makeText(Setting.this, ringtoneitems[ringpos], Toast.LENGTH_SHORT).show();
StopMusic();
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
StopMusic();
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(false);
mAlertDialog.show();
}
//This For Ring Volume Set
int volume=0;
private void Ringvolumeset()
{
try
{
final Dialog mDialog;
mDialog = new Dialog(Setting.this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.xringdialog);
mDialog.setCanceledOnTouchOutside(false)
mDialog.show();
final AudioManager mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
SeekBar seekbarringtone=(SeekBar)mDialog.findViewById(R.id.seekbarringtone);
seekbarringtone.setMax(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seekbarringtone.setProgress(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
volume=mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
seekbarringtone.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar bar, int progress,boolean fromUser) {
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,progress,AudioManager.FLAG_PLAY_SOUND);
}
public void onStartTrackingTouch(SeekBar bar) {
}
public void onStopTrackingTouch(SeekBar bar) {
}
});
Button btnset = (Button) mDialog.findViewById(R.id.btnset);
btnset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
}
});
Button btnemailcancel = (Button) mDialog.findViewById(R.id.btncancel);
btnemailcancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,volume,AudioManager.FLAG_PLAY_SOUND);
mDialog.dismiss();
}
});
}
catch(Exception e) {
System.out.println("Error" + e.getMessage().toString());
}
}
//This Method use for Repeat Alarm Day Select
private boolean boolrepeat[]=new boolean[7];
private String repeatitemssmall[]={" Mon", " Tue", " Wed"," Thu"," Fri"," Sat"," Sun"};
private void RepeatAlarm()
{
final CharSequence[] repeatitems = {"MONDAY", "TUESDAY", "WEDNESDAY","THURSDAY","FRIDAY","SATURDAY","SUNDAY"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
boolrepeat[0]=mSPreferences.getBoolean(MONDAY, true);
boolrepeat[1]=mSPreferences.getBoolean(TUESDAY, true);
boolrepeat[2]=mSPreferences.getBoolean(WEDNESDAY, true);
boolrepeat[3]=mSPreferences.getBoolean(THURSDAY, true);
boolrepeat[4]=mSPreferences.getBoolean(FRIDAY, true);
boolrepeat[5]=mSPreferences.getBoolean(SATURDAY, true);
boolrepeat[6]=mSPreferences.getBoolean(SUNDAY, true);
AlertDialog.Builder builder = new AlertDialog.Builder(Setting.this);
builder.setTitle("Repeat");
builder.setMultiChoiceItems(repeatitems, boolrepeat, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
boolrepeat[which]=isChecked;
//Toast.makeText(Setting.this,repeatitems[which], Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putBoolean(MONDAY,boolrepeat[0]);
mEditor.putBoolean(TUESDAY,boolrepeat[1]);
mEditor.putBoolean(WEDNESDAY,boolrepeat[2]);
mEditor.putBoolean(THURSDAY,boolrepeat[3]);
mEditor.putBoolean(FRIDAY,boolrepeat[4]);
mEditor.putBoolean(SATURDAY,boolrepeat[5]);
mEditor.putBoolean(SUNDAY,boolrepeat[6]);
mEditor.commit();
String strrepeatday = "";
for(int i=0;i < boolrepeat.length;i++){
if(boolrepeat[i]){
strrepeatday=strrepeatday + repeatitemssmall[i];
}
}
if(!strrepeatday.equals("")){
txtrepeatday.setText(strrepeatday);
}
else
{
txtrepeatday.setText("");
}
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
boolean boolalarmstatus = mSPreferences.getBoolean(ALARMSTATUS,false);
if(boolalarmstatus){
//SetAlarm.StopAlarm();
stopService(new Intent(Setting.this,SetAlarm.class));
long temptime=System.currentTimeMillis() + DateUtils.MINUTE_IN_MILLIS * 60;
int hour=DateOperation.getHour(temptime);
int minute=DateOperation.getMinute(temptime);
temptime=DateOperation.setCalendar(hour, minute,0);
long lngalarmtime=mSPreferences.getLong(ALARMTIME,temptime);
hour=DateOperation.getHour(lngalarmtime);
minute=DateOperation.getMinute(lngalarmtime);
lngalarmtime=DateOperation.setCalendar(hour, minute,0);
long comparetime=System.currentTimeMillis();
hour=DateOperation.getHour(comparetime);
minute=DateOperation.getMinute(comparetime);
comparetime=DateOperation.setCalendar(hour, minute,0);
int DateResult=DateOperation.LongTimeCompare(lngalarmtime,comparetime);
if(DateResult > 0)
{
//Toast.makeText(this, "1 Greater", Toast.LENGTH_SHORT).show();
long beforetime=lngalarmtime - DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval;
//SetAlarm.InitAlarm(Setting.this,beforetime,DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval);
Intent mIntent=new Intent(Setting.this,SetAlarm.class);
mIntent.setAction("START");
mIntent.putExtra("keyBeforeTime",beforetime);
mIntent.putExtra("keyAfterTime",DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval);
startService(mIntent);
System.out.println("New Alarm Set 4");
}
else if(DateResult < 0 || DateResult == 0)
{
lngalarmtime=lngalarmtime + DateUtils.HOUR_IN_MILLIS * 24;
SharedPreferences mSP2=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mE2=mSP2.edit();
mE2.putLong(ALARMTIME,lngalarmtime);
mE2.commit();
long beforetime=lngalarmtime - DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval;
//SetAlarm.InitAlarm(Setting.this,beforetime,DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval);
Intent mIntent=new Intent(Setting.this,SetAlarm.class);
mIntent.setAction("START");
mIntent.putExtra("keyBeforeTime",beforetime);
mIntent.putExtra("keyAfterTime",DateUtils.MINUTE_IN_MILLIS * SetAlarm.AlarmInterval);
startService(mIntent);
System.out.println("Next Day Set 4");
}
}
// Toast.makeText(Setting.this,"Repeat Day Set", Toast.LENGTH_SHORT).show();
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(true);
mAlertDialog.show();
}
}
No comments:
Post a Comment