Copyright (c) 2014 Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are me...
If you think the Android project diagnostic-tool listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.openxc.openxcdiagnostic.dump;
//www.java2s.comimport android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.openxc.openxcdiagnostic.R;
publicclass SettingsManager {
privatestatic String TAG = "Dump Settings Manager";
private SharedPreferences mPreferences;
private DumpActivity mContext;
private EditText mMessagesInput;
public SettingsManager(DumpActivity context) {
mContext = context;
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
}
/**
* Display the settings alert.
*/publicvoid showAlert() {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
LinearLayout settingsLayout = (LinearLayout) mContext
.getLayoutInflater().inflate(R.layout.dumpsettingsalert, null);
builder.setView(settingsLayout);
builder.setTitle(mContext.getResources().getString(
R.string.dump_settings_alert_label));
builder.setPositiveButton("Done", new OnClickListener() {
@Override
publicvoid onClick(DialogInterface dialog, int which) {
try {
int maxMessageCount = Integer.valueOf(mMessagesInput
.getText().toString());
save(maxMessageCount);
mContext.limitMessageCount(maxMessageCount);
} catch (NumberFormatException e) {
Log.w(TAG, "Invalid number entered");
}
}
});
builder.create().show();
mMessagesInput = (EditText) settingsLayout
.findViewById(R.id.numMessagesInput);
mMessagesInput.setText(String.valueOf(getNumMessages()));
}
/**
*
* @return The number of messages to keep in the queue specified by the
* user. Defaults to 999.
*/publicint getNumMessages() {
return mPreferences.getInt(getNumMessagesKey(), 999);
}
privatevoid save(int value) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(getNumMessagesKey(), value);
editor.commit();
}
privatestatic String getNumMessagesKey() {
return"num_messages_key";
}
}