So I'm trying to make a Settings screen and it seemed to work until I realized that the preferences won't react to clicks. I tried using onPreferenceStartFragment, but there's a strange error I'm encountering with the line
boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref)
Here's the onPreferenceStartFragment:
public interface OnPreferenceStartFragment {
boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref);
//Syntax error on token ";", { expected after this token
if(pref == password) {
LayoutInflater inflater = LayoutInflater.from(context);
final View text = inflater.inflate(R.layout.changepassword, null);
final EditText currentPassword = (EditText)text.findViewById(R.id.currentPassword);
final EditText newPassword = (EditText)text.findViewById(R.id.newPassword);
final AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Change Your Password");
alert.setView(text);
alert.setPositiveButton("Change", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String stringData = currentPassword.getText().toString().trim();
String stringNew = newPassword.getText().toString().trim();
dataReturned = myFolder.getString("passwordKey", "");
if(dataReturned.equals(stringData)) {
String newData = newPassword.getText().toString().trim();
SharedPreferences.Editor editor = myFolder.edit();
editor.putString("passwordKey", newData);
editor.commit();
dataReturned = myFolder.getString("passwordKey", "couldn't load data");
Toast.makeText(context, "Password changed", Toast.LENGTH_SHORT).show();
currentPassword.setText("");
newPassword.setText("");
}
else {
Toast.makeText(context, "Incorrect Password", Toast.LENGTH_LONG).show();
currentPassword.setText("");
newPassword.setText("");
}
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
alert.show();
;
}
if(pref == notification) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.device_access_secure)
.setOngoing(true)
.setContentTitle("Obstruct")
.setContentText("Start Stealth Mode");
Intent resultIntent = new Intent();
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
return true;
}
Everything seems to be right, but it's flummoxing me that it's not. Any Ideas?