Add a settings screen, with a preference to disable tracking

This commit is contained in:
YuviPanda 2013-04-07 18:10:42 +05:30
parent 3ba54daf4f
commit 1b89d96943
7 changed files with 42 additions and 6 deletions

View file

@ -100,9 +100,8 @@ public class CommonsApplication extends Application {
throw new RuntimeException(e);
}
// Enable / disable tracking based on user preference. Defaults to true
SharedPreferences settings = getSharedPreferences(Prefs.GLOBAL_PREFS, MODE_PRIVATE);
EventLog.enabled = settings.getBoolean(Prefs.TRACKING_ENABLED, EventLog.enabled);
// Initialize EventLogging
EventLog.setApp(this);
}
public MWApi getApi() {

View file

@ -1,6 +1,9 @@
package org.wikimedia.commons;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.*;
import android.preference.PreferenceManager;
import android.util.*;
import in.yuvi.http.fluent.Http;
import org.apache.http.HttpResponse;
@ -10,8 +13,7 @@ import java.net.*;
public class EventLog {
// Set to false in CommonsApplication if the user has disabled tracking
public static boolean enabled = true;
private static CommonsApplication app;
private static class LogTask extends AsyncTask<LogBuilder, Void, Boolean> {
@ -52,6 +54,10 @@ public class EventLog {
}
}
public static void setApp(CommonsApplication app) {
EventLog.app = app;
}
public static class LogBuilder {
private JSONObject data;
private long rev;
@ -91,7 +97,8 @@ public class EventLog {
}
public void log() {
if(!enabled) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(app);
if(!settings.getBoolean(Prefs.TRACKING_ENABLED, true)) {
return; // User has disabled tracking
}
LogTask logTask = new LogTask();

View file

@ -0,0 +1,13 @@
package org.wikimedia.commons;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
public class SettingsActivity extends SherlockPreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}

View file

@ -217,6 +217,10 @@ public class ContributionsListFragment extends SherlockFragment {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureURI);
startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA);
return true;
case R.id.menu_settings:
Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingsIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}