frontend runs
authorEugene Crosser <crosser@average.org>
Wed, 1 May 2013 17:46:53 +0000 (21:46 +0400)
committerEugene Crosser <crosser@average.org>
Wed, 1 May 2013 17:46:53 +0000 (21:46 +0400)
res/layout/main.xml
src/org/average/nfcauthcr/NFCAuthCREnroll.java

index 38060ddb5e4bcea16cbe3d38b560cf79beb08140..611341f7ca121cb1805048953daab23eb55a10d6 100644 (file)
@@ -6,9 +6,11 @@
     tools:context=".NFCAuthCREnroll"
     >
     <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="fill_parent"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
+                android:layout_centerHorizontal="true"
+                android:layout_alignParentTop="true"
     >
         <RadioButton android:id="@+id/slot_1"
                      android:layout_width="wrap_content"
         android:text="@string/enroll"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="20dp"
-        android:layout_marginTop="140dp"
+        android:layout_centerInParent="true"
         android:onClick="onEnrollClicked"
     />
 </RelativeLayout>
index 11010e3e011a83c46414af08ede95588245d83f0..098011a558537164450c2846b6ea751a7ed567bb 100644 (file)
@@ -1,24 +1,74 @@
 package org.average.nfcauthcr;
 
-import android.app.Activity;
 import android.os.Bundle;
+import android.app.Activity;
+import android.preference.PreferenceManager;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.util.Log;
+import android.view.View;
+import android.widget.RadioButton;
 
 public class NFCAuthCREnroll extends Activity
 {
-    private static final String TAG = getClass().getName();
-
-    private static boolean waitingForResult = false;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState)
-    {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.main);
-    }
-
-    @Override
-    protected void onStop() {
-        super.onStop();
-        if (!waitingForResult) { finish(); }
-    }
+       private final String TAG = getClass().getName();
+
+       private static boolean waitingForResult = false;
+       private static SharedPreferences prefs;
+       private static int slot;
+
+       @Override
+       protected void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+               Log.v(TAG, "Starting");
+               prefs = PreferenceManager.getDefaultSharedPreferences(this);
+       }
+
+       @Override
+       protected void onResume() {
+               super.onResume();
+               setContentView(R.layout.main);
+               slot = prefs.getInt("slot_number", -1);
+               Log.v(TAG, "found saved slot value " + slot);
+               RadioButton btn = null;
+               switch (slot) {
+               case 1: btn = (RadioButton)findViewById(R.id.slot_1);
+                       break;
+               case 2: btn = (RadioButton)findViewById(R.id.slot_2);
+                       break;
+               }
+               if (btn != null) btn.setChecked(true);
+       }
+
+       @Override
+       protected void onPause() {
+               super.onPause();
+               Log.v(TAG, "Going inactive, try to stop");
+               if (!waitingForResult) { finish(); }
+       }
+
+       @Override
+       protected void onStop() {
+               super.onStop();
+               Log.v(TAG, "Stop requested");
+       }
+
+       public void onSlotSelectionClicked(View view) {
+               Log.v(TAG, "Radio Button selected");
+               if (! ((RadioButton) view).isChecked()) return;
+               switch(view.getId()) {
+               case R.id.slot_1: slot=1; break;
+               case R.id.slot_2: slot=2; break;
+               }
+               Editor editor = prefs.edit();
+               editor.putInt("slot_number", slot);
+               editor.commit();
+               Log.v(TAG, "stored slot number " + slot);
+       }
+
+       public void onEnrollClicked(View view) {
+               Log.v(TAG, "Enroll clicked");
+               if (!waitingForResult) { finish(); }
+       }
 }