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

@ -73,6 +73,10 @@
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
/>
<service android:name="UploadService" >
</service>
<service

View file

@ -11,4 +11,10 @@
android:showAsAction="always|withText"
android:icon="@android:drawable/ic_menu_gallery"
/>
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:showAsAction="never"
android:icon="@android:drawable/ic_menu_preferences"
/>
</menu>

View file

@ -72,4 +72,7 @@
<string name="categories_not_found">No categories matching %1$s found</string>
<string name="categories_skip_explanation">Add categories to make your images more discoverable on Wikimedia Commons.\n\nStart typing to add categories.\nTap this message (or hit back) to skip this step.</string>
<string name="categories_activity_title">Categories</string>
<string name="preference_tracking">Usage reports</string>
<string name="preference_tracking_summary">Send usage reports to Wikimedia to help us improve the app</string>
<string name="title_activity_settings">Settings</string>
</resources>

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);
}