mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Style cleanup
This commit is contained in:
@@ -89,7 +89,8 @@ public class MyTracksSettings extends PreferenceActivity {
|
||||
// Hook up switching of displayed list entries between metric and imperial
|
||||
// units
|
||||
CheckBoxPreference metricUnitsPreference =
|
||||
(CheckBoxPreference) findPreference(getString(R.string.metric_units_key));
|
||||
(CheckBoxPreference) findPreference(
|
||||
getString(R.string.metric_units_key));
|
||||
metricUnitsPreference.setOnPreferenceChangeListener(
|
||||
new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
@@ -118,11 +119,15 @@ public class MyTracksSettings extends PreferenceActivity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Preference backupNowPreference = findPreference(getString(R.string.backup_to_sd_key));
|
||||
Preference restoreNowPreference = findPreference(getString(R.string.restore_from_sd_key));
|
||||
Preference backupNowPreference =
|
||||
findPreference(getString(R.string.backup_to_sd_key));
|
||||
Preference restoreNowPreference =
|
||||
findPreference(getString(R.string.restore_from_sd_key));
|
||||
|
||||
// If recording, disable backup/restore (we don't want to get to inconsistent states)
|
||||
boolean recording = preferences.getLong(getString(R.string.recording_track_key), -1) != -1;
|
||||
// If recording, disable backup/restore
|
||||
// (we don't want to get to inconsistent states)
|
||||
boolean recording =
|
||||
preferences.getLong(getString(R.string.recording_track_key), -1) != -1;
|
||||
backupNowPreference.setEnabled(!recording);
|
||||
restoreNowPreference.setEnabled(!recording);
|
||||
backupNowPreference.setSummary(
|
||||
@@ -133,24 +138,28 @@ public class MyTracksSettings extends PreferenceActivity {
|
||||
: R.string.settings_restore_from_sd_summary);
|
||||
|
||||
// Add actions to the backup preferences
|
||||
backupNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(MyTracksSettings.this, BackupActivity.class);
|
||||
intent.setAction(BackupActivity.BACKUP_ACTION);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
restoreNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(MyTracksSettings.this, BackupActivity.class);
|
||||
intent.setAction(BackupActivity.RESTORE_ACTION);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
backupNowPreference.setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent =
|
||||
new Intent(MyTracksSettings.this, BackupActivity.class);
|
||||
intent.setAction(BackupActivity.BACKUP_ACTION);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
restoreNowPreference.setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent =
|
||||
new Intent(MyTracksSettings.this, BackupActivity.class);
|
||||
intent.setAction(BackupActivity.RESTORE_ACTION);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,7 +62,8 @@ public class BackupActivity extends Activity {
|
||||
public static final String RESTORE_ACTION = "restore";
|
||||
|
||||
private final FileUtils fileUtils = new FileUtils();
|
||||
private final ExternalFileBackup backup = new ExternalFileBackup(this, fileUtils);
|
||||
private final ExternalFileBackup backup =
|
||||
new ExternalFileBackup(this, fileUtils);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -155,18 +156,20 @@ public class BackupActivity extends Activity {
|
||||
Builder confirmationDialogBuilder = new AlertDialog.Builder(this);
|
||||
confirmationDialogBuilder.setMessage(R.string.restore_overwrites_warning);
|
||||
confirmationDialogBuilder.setCancelable(false);
|
||||
confirmationDialogBuilder.setNegativeButton(android.R.string.no, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
BackupActivity.this.finish();
|
||||
}
|
||||
});
|
||||
confirmationDialogBuilder.setPositiveButton(android.R.string.yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
pickBackupForRestore(backupDates);
|
||||
}
|
||||
});
|
||||
confirmationDialogBuilder.setNegativeButton(android.R.string.no,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
BackupActivity.this.finish();
|
||||
}
|
||||
});
|
||||
confirmationDialogBuilder.setPositiveButton(android.R.string.yes,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
pickBackupForRestore(backupDates);
|
||||
}
|
||||
});
|
||||
confirmationDialogBuilder.create().show();
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -30,12 +30,14 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public abstract class BackupPreferencesListener implements OnSharedPreferenceChangeListener {
|
||||
public abstract class BackupPreferencesListener
|
||||
implements OnSharedPreferenceChangeListener {
|
||||
|
||||
/**
|
||||
* Real implementation of the listener, which calls the {@link BackupManager}.
|
||||
*/
|
||||
private static class BackupPreferencesListenerImpl extends BackupPreferencesListener {
|
||||
private static class BackupPreferencesListenerImpl
|
||||
extends BackupPreferencesListener {
|
||||
private final BackupManager backupManager;
|
||||
|
||||
public BackupPreferencesListenerImpl(Context context) {
|
||||
@@ -43,7 +45,8 @@ public abstract class BackupPreferencesListener implements OnSharedPreferenceCha
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
public void onSharedPreferenceChanged(
|
||||
SharedPreferences sharedPreferences, String key) {
|
||||
backupManager.dataChanged();
|
||||
}
|
||||
}
|
||||
@@ -51,9 +54,11 @@ public abstract class BackupPreferencesListener implements OnSharedPreferenceCha
|
||||
/**
|
||||
* Dummy implementation of the listener which does nothing.
|
||||
*/
|
||||
private static class DummyBackupPreferencesListener extends BackupPreferencesListener {
|
||||
private static class DummyBackupPreferencesListener
|
||||
extends BackupPreferencesListener {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
public void onSharedPreferenceChanged(
|
||||
SharedPreferences sharedPreferences, String key) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ class DatabaseDumper {
|
||||
* This assumes the cursor will have the same column and column indices on
|
||||
* every row (and thus may not work with a {@link MergeCursor}).
|
||||
*/
|
||||
public void writeAllRows(Cursor cursor, DataOutputStream writer) throws IOException {
|
||||
public void writeAllRows(Cursor cursor, DataOutputStream writer)
|
||||
throws IOException {
|
||||
writeHeaders(cursor, cursor.getCount(), writer);
|
||||
|
||||
if (!cursor.moveToFirst()) {
|
||||
@@ -81,7 +82,8 @@ class DatabaseDumper {
|
||||
* @param numRows the number of rows that will be later written
|
||||
* @throws IOException if there are errors while writing
|
||||
*/
|
||||
public void writeHeaders(Cursor cursor, int numRows, DataOutputStream writer) throws IOException {
|
||||
public void writeHeaders(Cursor cursor, int numRows, DataOutputStream writer)
|
||||
throws IOException {
|
||||
initializeCachedValues(cursor);
|
||||
writeQueryMetadata(cursor, numRows, writer);
|
||||
}
|
||||
@@ -93,7 +95,8 @@ class DatabaseDumper {
|
||||
* @param cursor the cursor to write data from
|
||||
* @throws IOException if there are any errors while writing
|
||||
*/
|
||||
public void writeOneRow(Cursor cursor, DataOutputStream writer) throws IOException {
|
||||
public void writeOneRow(Cursor cursor, DataOutputStream writer)
|
||||
throws IOException {
|
||||
if (columnIndices == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot write rows before writing the header");
|
||||
@@ -147,7 +150,8 @@ class DatabaseDumper {
|
||||
* @param numRows the number of rows that will be dumped
|
||||
* @throws IOException if there are any errors while writing
|
||||
*/
|
||||
private void writeQueryMetadata(Cursor cursor, int numRows, DataOutputStream writer) throws IOException {
|
||||
private void writeQueryMetadata(
|
||||
Cursor cursor, int numRows, DataOutputStream writer) throws IOException {
|
||||
// Write column data
|
||||
writer.writeInt(columnNames.length);
|
||||
for (int i = 0; i < columnNames.length; i++) {
|
||||
@@ -169,7 +173,9 @@ class DatabaseDumper {
|
||||
* @param cursor the cursor to read from
|
||||
* @throws IOException if there are any errors while writing
|
||||
*/
|
||||
private void writeCell(int columnIdx, byte columnTypeId, Cursor cursor, DataOutputStream writer) throws IOException {
|
||||
private void writeCell(
|
||||
int columnIdx, byte columnTypeId, Cursor cursor, DataOutputStream writer)
|
||||
throws IOException {
|
||||
switch (columnTypeId) {
|
||||
case ContentTypeIds.LONG_TYPE_ID:
|
||||
writer.writeLong(cursor.getLong(columnIdx));
|
||||
@@ -190,7 +196,8 @@ class DatabaseDumper {
|
||||
writer.writeUTF(cursor.getString(columnIdx));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Type " + columnTypeId + " not supported");
|
||||
throw new IllegalArgumentException(
|
||||
"Type " + columnTypeId + " not supported");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +207,8 @@ class DatabaseDumper {
|
||||
* @param columnType the type of the value to write
|
||||
* @throws IOException if there are any errors while writing
|
||||
*/
|
||||
private void writeDummyCell(byte columnTypeId, DataOutputStream writer) throws IOException {
|
||||
private void writeDummyCell(byte columnTypeId, DataOutputStream writer)
|
||||
throws IOException {
|
||||
switch (columnTypeId) {
|
||||
case ContentTypeIds.LONG_TYPE_ID:
|
||||
writer.writeLong(0L);
|
||||
@@ -221,7 +229,8 @@ class DatabaseDumper {
|
||||
writer.writeUTF("");
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Type " + columnTypeId + " not supported");
|
||||
throw new IllegalArgumentException(
|
||||
"Type " + columnTypeId + " not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,8 @@ public class DatabaseImporter {
|
||||
for (int c = 0; c < numColumns; c++) {
|
||||
if ((fields & 1) == 1) {
|
||||
// Field is present, read into values
|
||||
readOneCell(columnNames[c], columnTypes[c], valueBulk[numValues], reader);
|
||||
readOneCell(columnNames[c], columnTypes[c], valueBulk[numValues],
|
||||
reader);
|
||||
} else if (readNullFields) {
|
||||
// Field not present but still written, read and discard
|
||||
readOneCell(columnNames[c], columnTypes[c], null, reader);
|
||||
@@ -139,7 +140,8 @@ public class DatabaseImporter {
|
||||
* in - if null, the value is just discarded
|
||||
* @throws IOException if there are any problems while reading
|
||||
*/
|
||||
private void readOneCell(String name, byte typeId, ContentValues values, DataInputStream reader) throws IOException {
|
||||
private void readOneCell(String name, byte typeId, ContentValues values,
|
||||
DataInputStream reader) throws IOException {
|
||||
switch (typeId) {
|
||||
case ContentTypeIds.BOOLEAN_TYPE_ID: {
|
||||
boolean value = reader.readBoolean();
|
||||
|
||||
@@ -141,7 +141,8 @@ class ExternalFileBackup {
|
||||
* Synchronously writes a backup to the given file.
|
||||
*/
|
||||
private void writeToFile(File outputFile) throws IOException {
|
||||
Log.d(MyTracksConstants.TAG, "Writing backup to file " + outputFile.getAbsolutePath());
|
||||
Log.d(MyTracksConstants.TAG,
|
||||
"Writing backup to file " + outputFile.getAbsolutePath());
|
||||
|
||||
// Create all the auxiliary classes that will do the writing
|
||||
PreferenceBackupHelper preferencesHelper = new PreferenceBackupHelper();
|
||||
@@ -212,13 +213,17 @@ class ExternalFileBackup {
|
||||
* Synchronously restores the backup from the given file.
|
||||
*/
|
||||
private void restoreFromFile(File inputFile) throws IOException {
|
||||
Log.d(MyTracksConstants.TAG, "Restoring from file " + inputFile.getAbsolutePath());
|
||||
Log.d(MyTracksConstants.TAG,
|
||||
"Restoring from file " + inputFile.getAbsolutePath());
|
||||
|
||||
PreferenceBackupHelper preferencesHelper = new PreferenceBackupHelper();
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
DatabaseImporter trackImporter = new DatabaseImporter(TracksColumns.CONTENT_URI, resolver, false);
|
||||
DatabaseImporter waypointImporter = new DatabaseImporter(WaypointsColumns.CONTENT_URI, resolver, false);
|
||||
DatabaseImporter pointImporter = new DatabaseImporter(TrackPointsColumns.CONTENT_URI, resolver, false);
|
||||
DatabaseImporter trackImporter =
|
||||
new DatabaseImporter(TracksColumns.CONTENT_URI, resolver, false);
|
||||
DatabaseImporter waypointImporter =
|
||||
new DatabaseImporter(WaypointsColumns.CONTENT_URI, resolver, false);
|
||||
DatabaseImporter pointImporter =
|
||||
new DatabaseImporter(TrackPointsColumns.CONTENT_URI, resolver, false);
|
||||
|
||||
FileInputStream inputStream = new FileInputStream(inputFile);
|
||||
DataInputStream reader = new DataInputStream(inputStream);
|
||||
|
||||
@@ -80,7 +80,8 @@ class PreferenceBackupHelper {
|
||||
* @return whether the preference change was successful
|
||||
* @throws IOException if there are any errors while reading
|
||||
*/
|
||||
public boolean importPreferences(byte[] data, SharedPreferences preferences) throws IOException {
|
||||
public boolean importPreferences(byte[] data, SharedPreferences preferences)
|
||||
throws IOException {
|
||||
ByteArrayInputStream bufStream = new ByteArrayInputStream(data);
|
||||
DataInputStream reader = new DataInputStream(bufStream);
|
||||
|
||||
@@ -148,7 +149,8 @@ class PreferenceBackupHelper {
|
||||
* @param writer the writer to write to
|
||||
* @throws IOException if there are errors while writing
|
||||
*/
|
||||
private void writePreference(String name, Object value, DataOutputStream writer) throws IOException {
|
||||
private void writePreference(String name, Object value, DataOutputStream writer)
|
||||
throws IOException {
|
||||
writer.writeUTF(name);
|
||||
|
||||
if (value instanceof Boolean) {
|
||||
@@ -167,7 +169,8 @@ class PreferenceBackupHelper {
|
||||
writer.writeByte(ContentTypeIds.STRING_TYPE_ID);
|
||||
writer.writeUTF((String) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Type " + value.getClass().getName() + " not supported");
|
||||
throw new IllegalArgumentException(
|
||||
"Type " + value.getClass().getName() + " not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user