@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); this.setTitle(R.string.setting); sp = PreferenceManager.getDefaultSharedPreferences(this); edit = sp.edit(); Button widgettheme = (Button) findViewById(R.id.widgettheme); Button settime = (Button) findViewById(R.id.settime); Button save = (Button) findViewById(R.id.set_save); nc = (CheckBox) findViewById(R.id.nightcheck); rs = (CheckBox) findViewById(R.id.ringswitch); widgettheme.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View Button) { AlertDialog.Builder ad = new AlertDialog.Builder(Settings.this) .setTitle("选择颜色?") .setItems( color, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface p1, int p2) { edit.putInt("widgetTextColor", colori[p2]); edit.commit(); } }); ad.show(); } }); settime.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View Button) { Intent set = new Intent(Settings.this, Settime.class); startActivity(set); return; } }); save.setOnClickListener( new View.OnClickListener() { public void onClick(View Button) { save(); return; } }); nc.setChecked(sp.getBoolean("nightmode", false)); if (sp.getBoolean("timewrong", false) == true) { rs.setChecked(false); rs.setClickable(false); } }
public void save() { if (rs.isChecked() == true) { edit.putBoolean("silent", true); edit.commit(); } else { edit.putBoolean("silent", false); edit.commit(); } if (nc.isChecked() == true) { edit.putBoolean("nightmode", true); edit.commit(); } else { edit.putBoolean("nightmode", false); edit.commit(); } Toast.makeText(getApplicationContext(), "保存成功!", Toast.LENGTH_SHORT).show(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.create_task_activity); // Setting the UI view with create_task_list taskDataBase = TaskListDataBase.getInstance(getApplicationContext()); dateSeted = (TextView) findViewById(R.id.date_set_view); timeSeted = (TextView) findViewById(R.id.time_set_view); Button createActivityButton = (Button) findViewById(R.id.create_button); // Creating the 'create' button createActivityButton.setOnClickListener( new View.OnClickListener() // Setting click listener for addTask button { public void onClick(View v) { long rowID; TaskListArray array = TaskListArray.getInstance(getApplicationContext()); EditText titleField = (EditText) findViewById(R.id.enter_task_title); // Getting the task title Task newTask = new Task(titleField.getText().toString()); // Creating new task with that title EditText descriptionField = (EditText) findViewById(R.id.enter_task_description); // Getting the task description newTask.setDescription( descriptionField.getText().toString()); // Setting the task description if (checked) { if (!dateAndTimeIsSet()) Toast.makeText( getApplicationContext(), "Please Set Date And Time For The Reminder", Toast.LENGTH_SHORT) .show(); else { Calendar cal = Calendar.getInstance(); cal.set( year, month, day, hour, minute, 0); // Setting a new Calendar instance with the user reminder date rowID = taskDataBase.addTask(newTask); // Adding to DataBase newTask.setId(rowID); array.addTask(newTask); new SetReminder( getApplicationContext(), cal, newTask); // Creating a new reminder to be added to the alarm manager finish(); } } else { rowID = taskDataBase.addTask(newTask); // Adding to DataBase newTask.setId(rowID); array.addTask(newTask); finish(); } } }); // Set Date Button setDate = (Button) findViewById(R.id.set_date); // Creating the 'Set Date' button setDate.setOnClickListener( new View.OnClickListener() // Setting click listener for setDate button { public void onClick(View v) { newDateFragment = new DatePickerFragment(); newDateFragment.show( getSupportFragmentManager(), "datePicker"); // Show the user dialog to pick a date } }); // Set Time button setTime = (Button) findViewById(R.id.set_time); // Creating the 'Set Time' button setTime.setOnClickListener( new View.OnClickListener() // Setting click listener for setTime button { public void onClick(View v) { newTimeFragment = new TimePickerFragment(); newTimeFragment.show( getSupportFragmentManager(), "timePicker"); // Show the user dialog to pick a time } }); final CheckBox checkBox = (CheckBox) findViewById(R.id.set_reminder); // Creating the CheckBox checkBox.setOnClickListener( new View .OnClickListener() // Setting click listener for the check-box for controlling the set's // buttons clickability { public void onClick(View v) { checked = ((CheckBox) v).isChecked(); switch (v.getId()) { case R.id.set_reminder: if (checked) // If the CheckBox is checked allows the user to set a reminder, else // don't { setDate.setVisibility(View.VISIBLE); setTime.setVisibility(View.VISIBLE); dateSeted.setVisibility(View.VISIBLE); timeSeted.setVisibility(View.VISIBLE); } else { setDate.setVisibility(View.INVISIBLE); setTime.setVisibility(View.INVISIBLE); dateSeted.setVisibility(View.INVISIBLE); timeSeted.setVisibility(View.INVISIBLE); } break; } } }); }