Sfoglia il codice sorgente

Advances in settings activity.

seavenois 10 anni fa
parent
commit
d66eba9c0f

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -54,7 +54,7 @@
         </activity>
 
         <activity
-            android:name="com.ivalentin.margolariak.SettingsFragment"
+            android:name=".SettingsActivity"
             android:theme="@style/Theme.NoTitle"
             android:windowSoftInputMode="stateHidden|adjustResize"
             android:configChanges="orientation"

+ 9 - 0
app/src/main/java/com/ivalentin/margolariak/AboutActivity.java

@@ -0,0 +1,9 @@
+package com.ivalentin.margolariak;
+
+import android.app.Activity;
+
+/**
+ * Created by seavenois on 26/09/16.
+ */
+public class AboutActivity extends Activity{
+}

+ 54 - 22
app/src/main/java/com/ivalentin/margolariak/GM.java

@@ -25,16 +25,6 @@ final class GM {
 	 * Code for the location permission request
 	 */
 	static final int PERMISSION_LOCATION = 1;
-
-	/**
-	 * Duration of the menu sliding animation.
-	 */
-	static final int MENU_SLIDING_DURATION = 500;
-	
-	/**
-	 * Interval between menu sliding queries. 
-	 */
-	static final int MENU_QUERY_INTERVAL = 16;
 	
 	/**
 	 * Period of time (in seconds) at the end of witch the app will perform a sync.
@@ -141,11 +131,6 @@ final class GM {
 	 */
 	static final byte SECTION_GALLERY = 5;
 
-	/**
-	 * Constant for section "Settings".
-	 */
-	static final byte SECTION_SETTINGS = 6;
-
 	/**
 	 * Name of the preference group for the app.
 	 */
@@ -165,22 +150,17 @@ final class GM {
 	 * Name of the preference that indicates if we are on festivals.
 	 */
 	static final String PREF_DB_FESTIVALS = "prefDbFestivals";
-	
+
 	/**
 	 * Name of the preference indicating if the user wants to to receive notifications intended for the general public.
 	 */
 	static final String PREF_NOTIFICATION = "prefNotification";
 
-	/**
-	 * Name of the preference indicating if the tutorial has been seen.
-	 */
-	static final String PREF_TUTORIAL = "prefTutorial";
-	
 	/**
 	 * Default value of the preference indicating if the user wants to to receive notifications intended for the general public.
 	 */
 	static final int DEFAULT_PREF_NOTIFICATION = 1;
-	
+
 	/**
 	 * Header of a preference to indicate received notifications.
 	 */
@@ -211,6 +191,58 @@ final class GM {
 	 */
 	static final String DEFAULT_PREF_GM_LOCATION = "19700101000000";
 
+	/**
+	 * Name of the preference indicating if the user wants to perform background syncs.
+	 */
+	static final String PREFERENCE_SYNC_SYNC = "pref_sync_sync";
+
+	/**
+	 * Default value for PREFERENCE_SYNC_SYNC.
+	 */
+	static final boolean DEFAULT_PREFERENCE_SYNC_SYNC = true;
+
+	/**
+	 * Name of the preference indicating if the user wants to to receive notifications intended for the general public.
+	 */
+	static final String PREFERENCE_SYNC_NOTIFICATIONS = "pref_sync_notifications";
+
+	/**
+	 * Default value for PREFERENCE_SYNC_NOTIFICATIONS.
+	 */
+	static final boolean DEFAULT_PREFERENCE_SYNC_NOTIFICATIONS = true;
+
+	/**
+	 * Name of the SharedPreference that stores how many kb have been sent in the foreground.
+	 */
+	static final String STORAGE_TRAFFIC_FG_SENT = "storage_traffic_fg_sent";
+
+	/**
+	 * Name of the SharedPreference that stores how many kb have been received in the foreground.
+	 */
+	static final String STORAGE_TRAFFIC_FG_RECEIVED = "storage_traffic_fg_received";
+
+	/**
+	 * Name of the SharedPreference that stores how many kb have been sent in the background.
+	 */
+	static final String STORAGE_TRAFFIC_BG_SENT = "storage_traffic_bg_received";
+
+	/**
+	 * Name of the SharedPreference that stores how many kb have been received in the background.
+	 */
+	static final String STORAGE_TRAFFIC_BG_RECEIVED = "storage_traffic_bg_received";
+
+	static final String KEY_PREFERENCE_SYNC = "preference_key_sync";
+
+	static final String KEY_PREFERENCE_NOTIFICATION = "preference_key_notification";
+
+	static final String KEY_PREFERENCE_DATA = "preference_key_data";
+
+	static final String KEY_PREFERENCE_VERSION = "preference_key_version";
+
+	static final String KEY_PREFERENCE_SOURCE = "preference_key_source";
+
+	static final String KEY_PREFERENCE_FEEDBACK = "preference_key_feedback";
+
 	/**
 	 * Name of the database
 	 */

+ 19 - 53
app/src/main/java/com/ivalentin/margolariak/MainActivity.java

@@ -16,12 +16,9 @@ import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.support.v4.view.MenuItemCompat;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.KeyEvent;
-import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
@@ -34,7 +31,6 @@ import android.widget.ImageView;
 import android.widget.PopupMenu;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
-import android.widget.ScrollView;
 import android.widget.TextView;
 
 /**
@@ -59,12 +55,29 @@ public class MainActivity extends Activity{
 		MenuInflater inflater = popup.getMenuInflater();
 		inflater.inflate(R.menu.menu, popup.getMenu());
 
-		popup.getMenu().getItem(2).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
+		popup.getMenu().getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
 			@Override
 			public boolean onMenuItemClick(MenuItem item) {
-				Intent intent = new Intent(MainActivity.this, SettingsFragment.class);
+				Intent intent = new Intent(MainActivity.this, AboutActivity.class);
 				startActivity(intent);
+				return true;
+			}
+		});
 
+		popup.getMenu().getItem(1).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
+			@Override
+			public boolean onMenuItemClick(MenuItem item) {
+				Intent intent = new Intent(MainActivity.this, SponsorActivity.class);
+				startActivity(intent);
+				return true;
+			}
+		});
+
+		popup.getMenu().getItem(2).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
+			@Override
+			public boolean onMenuItemClick(MenuItem item) {
+				Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
+				startActivity(intent);
 				return true;
 			}
 		});
@@ -72,54 +85,7 @@ public class MainActivity extends Activity{
 		popup.show();
 	}
 
-//	@Override
-//	public boolean onCreateOptionsMenu(Menu menu) {
-//		Log.e("MENU", "CREATED");
-//		getMenuInflater().inflate(R.menu.menu, menu);
-//		Log.e("SETT", String.valueOf(R.id.pop_menu_settings));
-//		for (int i = 0; i< menu.size() ;i++) {
-//			MenuItem menuItem = menu.getItem(i);
-//			Log.e("MENU", String.valueOf(menuItem.getItemId()));
-//
-//			if (menuItem.getItemId() == R.id.pop_menu_settings) {
-//				View view = MenuItemCompat.getActionView(menuItem);
-//				if (view != null) {
-//					view.setOnClickListener(new OnClickListener() {
-//
-//						@Override
-//						public void onClick(View v) {
-//							Intent intent = new Intent(MainActivity.this, SettingsFragment.class);
-//							startActivity(intent);
-//						}
-//					});
-//				}
-//			}
-//		}
-//		return true;
-//	}
 
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		Log.e("MENU","SELECTED");
-		// Handle item selection
-		switch (item.getItemId()) {
-			case R.id.pop_menu_about:
-				//TODO
-				return true;
-			case R.id.pop_menu_sponsors:
-				//TODO
-				return true;
-			case R.id.pop_menu_settings:
-				Log.e("MENU","SETTINGS");
-				Intent intent = new Intent( this, SettingsFragment.class );
-				//intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, Fragment1.class.getName() );
-				//intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );
-				startActivity(intent);
-				return true;
-			default:
-				return super.onOptionsItemSelected(item);
-		}
-	}
 
 	/**
 	 * Loads a section in the main screen.

+ 104 - 0
app/src/main/java/com/ivalentin/margolariak/SettingsActivity.java

@@ -0,0 +1,104 @@
+package com.ivalentin.margolariak;
+
+import android.app.Notification;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.util.Log;
+import android.widget.Toast;
+
+public class SettingsActivity extends PreferenceActivity {
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+
+		// Load the preferences from an XML resource
+		addPreferencesFromResource(R.xml.preferences);
+
+		SharedPreferences sp = getPreferenceScreen().getSharedPreferences();
+
+		//Set up Sync preference
+		CheckBoxPreference prefSync = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_SYNC);
+		if (prefSync.isChecked()){
+			prefSync.setSummary(getString(R.string.preferences_sync_sync_on));
+		}
+		else{
+			prefSync.setSummary(getString(R.string.preferences_sync_sync_off));
+		}
+		prefSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+
+			public boolean onPreferenceChange(Preference preference, Object newValue) {
+				CheckBoxPreference prefNotification = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_NOTIFICATION);
+				if (newValue.toString().equals("true")) {
+					preference.setSummary(getString(R.string.preferences_sync_sync_on));
+					if (prefNotification.isChecked()){
+						prefNotification.setSummary(getString(R.string.preferences_sync_notifications_on));
+					}
+					else{
+						prefNotification.setSummary(getString(R.string.preferences_sync_notifications_off));
+					}
+					prefNotification.setEnabled(true);
+				} else {
+					prefNotification.setEnabled(false);
+					prefNotification.setSummary(getString(R.string.preferences_sync_notifications_disabled));
+					preference.setSummary(getString(R.string.preferences_sync_sync_off));
+				}
+				return true;
+			}
+		});
+
+		//Set up Notification preference
+		CheckBoxPreference prefNotification = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_NOTIFICATION);
+		if (prefSync.isChecked() == false){
+			prefNotification.setEnabled(false);
+		}
+		else {
+			prefNotification.setEnabled(true);
+			if(prefSync.isChecked() == false){
+
+			}
+			if (prefNotification.isChecked()) {
+				prefNotification.setSummary(getString(R.string.preferences_sync_notifications_on));
+			} else {
+				prefNotification.setSummary(getString(R.string.preferences_sync_notifications_off));
+			}
+		}
+
+		prefNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+
+			public boolean onPreferenceChange(Preference preference, Object newValue) {
+				if (newValue.toString().equals("true")) {
+					preference.setSummary(getString(R.string.preferences_sync_notifications_on));
+				} else {
+					preference.setSummary(getString(R.string.preferences_sync_notifications_off));
+				}
+				return true;
+			}
+		});
+
+
+		//Set up data preference
+		//TODO
+
+
+		//Set up version preference
+		Preference prefVersion = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
+		prefVersion.setSummary(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
+		prefNotification.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+			@Override
+			public boolean onPreferenceClick(Preference preference) {
+				//TODO
+				return false;
+			}
+		});
+
+		//Set up source preference
+		//TODO
+
+		//Set up feedback preference
+		//TODO
+
+	}
+}

+ 0 - 17
app/src/main/java/com/ivalentin/margolariak/SettingsFragment.java

@@ -1,17 +0,0 @@
-package com.ivalentin.margolariak;
-
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceFragment;
-import android.util.Log;
-
-public class SettingsFragment extends PreferenceActivity {
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-
-		// Load the preferences from an XML resource
-		addPreferencesFromResource(R.xml.preferences);
-		Log.e("PREFERENCES", "STARED");
-	}
-}

+ 9 - 0
app/src/main/java/com/ivalentin/margolariak/SponsorActivity.java

@@ -0,0 +1,9 @@
+package com.ivalentin.margolariak;
+
+import android.app.Activity;
+
+/**
+ * Created by seavenois on 26/09/16.
+ */
+public class SponsorActivity extends Activity {
+}

+ 6 - 6
app/src/main/res/xml/preferences.xml

@@ -3,17 +3,17 @@
         android:title="@string/preferences_sync">
 
         <CheckBoxPreference
-            android:key="pref_sync_sync"
+            android:key="preference_key_sync"
             android:title="@string/preferences_sync_sync"
             android:summary="@string/preferences_sync_sync_on"
             android:defaultValue="true" />
         <CheckBoxPreference
-            android:key="pref_sync_notifications"
+            android:key="preference_key_notification"
             android:title="@string/preferences_sync_notifications"
             android:summary="@string/preferences_sync_notifications_on"
             android:defaultValue="true" />
         <Preference
-            android:key="pref_sync_usage"
+            android:key="preference_key_data"
             android:title="@string/preferences_sync_usage"
             android:summary="0 kb" />
 
@@ -23,17 +23,17 @@
         android:title="@string/preferences_info">
 
         <Preference
-            android:key="pref_sync_usage"
+            android:key="preference_key_version"
             android:title="@string/preferences_info_version"
             android:summary="_" />
 
         <Preference
-            android:key="pref_sync_source"
+            android:key="preference_key_source"
             android:title="@string/preferences_info_source"
             android:summary="@string/preferences_info_source_summary" />
 
         <Preference
-            android:key="pref_sync_feedback"
+            android:key="preference_key_feedback"
             android:title="@string/preferences_info_feedback"
             android:summary="@string/preferences_info_feedback_summary" />