Browse Source

Code comments and Javadoc.

seavenois 9 years ago
parent
commit
f89897cce9

+ 61 - 9
app/src/main/java/com/ivalentin/margolariak/SettingsActivity.java

@@ -1,28 +1,44 @@
 package com.ivalentin.margolariak;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.net.Uri;
 import android.os.Bundle;
-import android.preference.Preference;
-import android.util.Log;
 import android.view.View;
 import android.view.Window;
 import android.widget.CheckBox;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+/**
+ * Activity that allows the user to change the app settings.
+ *
+ * @author Iñigo Valentin
+ * @see Activity
+ */
 public class SettingsActivity extends Activity {
 
 	//Assign menu items
-	private LinearLayout llSync, llNotifications, llVersion, llSource, llFeedback;
+	private LinearLayout llSync;
+	private LinearLayout llNotifications;
 	private CheckBox cbSync, cbNotifications;
-	private TextView tvSync, tvNotifications, tvVersion;
+	private TextView tvSync;
+	private TextView tvNotifications;
 	private SharedPreferences preferences;
 	private SharedPreferences.Editor editor;
 
+	/**
+	 * Run when the app is created. Assigns views, configures their initial
+	 * states, and sets listeners
+	 *
+	 * @param savedInstanceState Activity state.
+	 *
+	 * @see Activity#onCreate(Bundle)
+	 */
+	@SuppressLint("CommitPrefEdits") // apply() is called in other methods
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
@@ -38,12 +54,12 @@ public class SettingsActivity extends Activity {
 		//Assign views
 		llSync = (LinearLayout) findViewById(R.id.ll_settings_sync);
 		llNotifications = (LinearLayout) findViewById(R.id.ll_settings_notifications);
-		llVersion = (LinearLayout) findViewById(R.id.ll_settings_version);
-		llSource = (LinearLayout) findViewById(R.id.ll_settings_source);
-		llFeedback = (LinearLayout) findViewById(R.id.ll_settings_feedback);
+		LinearLayout llVersion = (LinearLayout) findViewById(R.id.ll_settings_version);
+		LinearLayout llSource = (LinearLayout) findViewById(R.id.ll_settings_source);
+		LinearLayout llFeedback = (LinearLayout) findViewById(R.id.ll_settings_feedback);
 		tvSync = (TextView) findViewById(R.id.tv_settings_sync);
 		tvNotifications = (TextView) findViewById(R.id.tv_settings_notifications);
-		tvVersion = (TextView) findViewById(R.id.tv_settings_version);
+		TextView tvVersion = (TextView) findViewById(R.id.tv_settings_version);
 		cbSync = (CheckBox) findViewById(R.id.cb_settings_sync);
 		cbNotifications = (CheckBox) findViewById(R.id.cb_settings_notifications);
 
@@ -94,6 +110,12 @@ public class SettingsActivity extends Activity {
 		});
 	}
 
+	/**
+	 * UI feedback for touched settings.
+	 * Just makes them blink.
+	 *
+	 * @param v The view to be made to blink
+	 */
 	private void blink(View v){
 		final View view = v;
 
@@ -117,7 +139,6 @@ public class SettingsActivity extends Activity {
 										  @Override
 										  public void run() {
 											  view.setBackgroundColor(Color.argb(passAlpha, r, g, b));
-											  Log.e("PASS", "Alpha: " + passAlpha);
 										  }
 									  });
 
@@ -133,6 +154,14 @@ public class SettingsActivity extends Activity {
 
 	}
 
+	/**
+	 * Not called from code, but referenced from activity_settings.xml.
+	 * Toggles the value of the sync preferences, changing the actual
+	 * preference, the ui, and, if set to disabled, it also disables the
+	 * notification setting.
+	 *
+	 * @param v Ignored
+	 */
 	public void toggleSync(View v){
 		blink(llSync);
 		editor.putBoolean(GM.PREFERENCES.KEY.SYNC, !preferences.getBoolean(GM.PREFERENCES.KEY.SYNC, GM.PREFERENCES.DEFAULT.SYNC));
@@ -149,6 +178,13 @@ public class SettingsActivity extends Activity {
 		}
 	}
 
+	/**
+	 * Not called from code, but referenced from activity_settings.xml.
+	 * Toggles the value of the notification preferences, changing the
+	 * actual preference and the ui.
+	 *
+	 * @param v Ignored
+	 */
 	public void toggleNotifications(View v){
 		if (preferences.getBoolean(GM.PREFERENCES.KEY.SYNC, GM.PREFERENCES.DEFAULT.SYNC)) {
 			blink(llNotifications);
@@ -167,6 +203,10 @@ public class SettingsActivity extends Activity {
 		}
 	}
 
+	/**
+	 * Enables the notification setting toggler. Must be called when
+	 * the sync preference changes to true.
+	 */
 	private void enableNotifications(){
 		llNotifications.setAlpha(1);
 		if (preferences.getBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, GM.PREFERENCES.DEFAULT.NOTIFICATIONS)){
@@ -180,12 +220,24 @@ public class SettingsActivity extends Activity {
 
 	}
 
+	/**
+	 * Enables the notification setting toggler. Must be called when
+	 * the sync preference changes to false.
+	 */
 	private void disableNotifications(){
 		llNotifications.setAlpha(0.4f);
 		tvNotifications.setText(R.string.preferences_sync_notifications_disabled);
 		cbNotifications.setChecked(false);
 	}
 
+	/**
+	 * Not called from code, but referenced from activity_settings.xml.
+	 * Finishes the activity.
+	 *
+	 * @param v Ignored
+	 *
+	 * @see Activity#finish()
+	 */
 	public void finish(View v){
 		finish();
 	}

+ 12 - 15
app/src/main/res/layout/activity_settings.xml

@@ -39,6 +39,7 @@
                 android:layout_height="wrap_content"
                 android:gravity="center"
                 android:text="@string/app_name"
+                android:contentDescription="@string/app_name"
                 android:textSize="18sp"
                 android:textStyle="bold"
                 android:textColor="@color/menu_entry"/>
@@ -57,21 +58,13 @@
             android:layout_width="40dp"
             android:layout_height="match_parent"
             android:src="@android:drawable/ic_menu_revert"
-            android:onClick="finish();"
+            android:onClick="finish"
+            android:contentDescription="@string/accept"
             android:layout_weight=".2"
-            android:id="@+id/bt_menu"
+            android:id="@+id/bt_back"
             app:srcCompat="@android:drawable/ic_menu_revert"
             android:background="#00000000"/>
 
-        <ProgressBar
-            android:id="@+id/pb_sync"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:layout_weight=".2"
-            android:visibility="gone"
-            android:maxHeight="40dp"
-            android:maxWidth="40dp"/>
-
     </LinearLayout>
 
     <ScrollView
@@ -106,7 +99,8 @@
                 android:layout_height="match_parent"
                 android:id="@+id/ll_settings_sync"
                 android:padding="10dp"
-                android:layout_marginBottom="5dp">
+                android:layout_marginBottom="5dp"
+                android:onClick="toggleSync">
 
                 <LinearLayout
                     android:orientation="vertical"
@@ -144,7 +138,8 @@
                     android:layout_weight=".85"
                     android:gravity="center_vertical|center_horizontal"
                     android:layout_gravity="center_vertical|center_horizontal"
-                    android:textAlignment="center"/>
+                    android:textAlignment="center"
+                    android:onClick="toggleSync"/>
 
             </LinearLayout>
 
@@ -163,7 +158,8 @@
                 android:layout_height="match_parent"
                 android:id="@+id/ll_settings_notifications"
                 android:padding="10dp"
-                android:layout_marginBottom="5dp">
+                android:layout_marginBottom="5dp"
+                android:onClick="toggleNotifications">
 
                 <LinearLayout
                     android:orientation="vertical"
@@ -201,7 +197,8 @@
                     android:layout_weight=".85"
                     android:gravity="center_vertical|center_horizontal"
                     android:layout_gravity="center_vertical|center_horizontal"
-                    android:textAlignment="center"/>
+                    android:textAlignment="center"
+                    android:onClick="toggleNotifications"/>
 
             </LinearLayout>