From f8bd4f98068327854a61f8a44110b3f5949fc4fb Mon Sep 17 00:00:00 2001 From: lordwelch Date: Sat, 1 Apr 2017 14:00:37 -0600 Subject: [PATCH] working, need to get actual data intents setup how I want them using hashmap not hashtable need to add support for loading a specified file possibly ad some sort of statistics e.g. name, phone number, result --- .idea/inspectionProfiles/Project_Default.xml | 14 +++ .../inspectionProfiles/profiles_settings.xml | 7 ++ .idea/modules.xml | 2 - app/build.gradle | 16 ++- app/src/main/AndroidManifest.xml | 4 +- .../myapplication/ChoiceActivity.java | 105 +++++++++++++++++ .../myapplication/MainActivity.java | 111 +++++++++++++++--- app/src/main/res/layout/activity_choice.xml | 68 ++++++++++- app/src/main/res/layout/activity_main.xml | 38 ++++-- app/src/main/res/raw/script.json | 8 +- app/src/main/res/values/strings.xml | 1 + device-2017-04-01-113118.png | Bin 0 -> 50281 bytes device-2017-04-01-113131.png | Bin 0 -> 55184 bytes 13 files changed, 332 insertions(+), 42 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 device-2017-04-01-113118.png create mode 100644 device-2017-04-01-113131.png diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..956ac03 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 031c785..abc31fc 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,8 +3,6 @@ - - diff --git a/app/build.gradle b/app/build.gradle index de48147..6af97ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,14 @@ apply plugin: 'com.android.application' android { + signingConfigs { + config { + keyAlias 'gemfinder' + keyPassword 'guanfacine' + storeFile file('/home/timmy/Downloads/GemFinder-key.keystore') + storePassword 'guanfacine' + } + } compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { @@ -13,14 +21,18 @@ android { } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.config + } + debug { + signingConfig signingConfigs.config } } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c35c86..81fe44c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,14 +10,14 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + - + \ No newline at end of file diff --git a/app/src/main/java/com/welchsoftwaredevelopers/myapplication/ChoiceActivity.java b/app/src/main/java/com/welchsoftwaredevelopers/myapplication/ChoiceActivity.java index 0315907..a878bfa 100644 --- a/app/src/main/java/com/welchsoftwaredevelopers/myapplication/ChoiceActivity.java +++ b/app/src/main/java/com/welchsoftwaredevelopers/myapplication/ChoiceActivity.java @@ -1,13 +1,118 @@ package com.welchsoftwaredevelopers.myapplication; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; public class ChoiceActivity extends AppCompatActivity { + private ArrayList> script; + private ArrayList ScriptQuestion; + private RadioGroup group; + private SharedPreferences sharedPref; + private Boolean clear = false; + private Integer current; + + public ChoiceActivity() { + script = new ArrayList<>(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choice); + + Intent intent = getIntent(); + group = (RadioGroup) findViewById(R.id.radioGroup1); + ScriptQuestion = intent.getStringArrayListExtra("Questions"); + current = intent.getIntExtra("Next", 0); + clear = intent.getBooleanExtra("Clear", false); + Integer i = 0; + Integer size = intent.getIntExtra("Size", 0); + ((TextView) findViewById(R.id.textView)).setText(ScriptQuestion.get(current)); + while (i < size) { + HashMap tmp1 = new HashMap<>(); + tmp1.putAll((HashMap) intent.getSerializableExtra("Opts" + i.toString())); + script.add(tmp1); + i++; + } + Log.d("D", size.toString()); + Log.d("D", script.toString()); + Log.d("D", current.toString()); + Log.d("D", ScriptQuestion.toString()); + Iterator iter1 = script.get(current).get("Text").iterator(); + RadioButton button; + while (iter1.hasNext()) { + button = new RadioButton(this); + button.setText((String) iter1.next()); + group.addView(button); + } + } + + @Override + protected void onStart() { + super.onStart(); + Integer Total; + sharedPref = this.getPreferences(Context.MODE_PRIVATE); + if (clear) { + Log.d("D", "clear"); + Total = 0; + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt(getString(R.string.Total), 0); + editor.commit(); + } else { + Total = sharedPref.getInt(getString(R.string.Total), 0); + } + ((TextView) findViewById(R.id.textView_choice_total)).setText(Total.toString()); + } + + public void ClickDone(View v) { + Integer totalDone = sharedPref.getInt(getString(R.string.Total), 0) + 1; + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt(getString(R.string.Total), totalDone); + + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(getString(R.string.Total), totalDone); + editor.apply(); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + finish(); + } + + public void ClickChoice(View v) { + if (group.getCheckedRadioButtonId() == -1) { + Toast.makeText(this, "Select an option", Toast.LENGTH_SHORT).show(); + } else { + Intent intent = new Intent(this, ChoiceActivity.class); + intent.putStringArrayListExtra("Questions", ScriptQuestion); + intent.putExtra("Size", script.size()); + Log.d("D", "Sel button: " + ( (Integer) group.indexOfChild(findViewById(group.getCheckedRadioButtonId())) ).toString() ); + + intent.putExtra("Next", (Integer) script.get(current).get("Destination").get(group.indexOfChild(findViewById(group.getCheckedRadioButtonId())))); + + Iterator> iter1 = script.iterator(); + Integer i = 0; + while (iter1.hasNext()) { + String nameOpts = "Opts" + i.toString(); + intent.putExtra(nameOpts, iter1.next()); + i++; + } + startActivity(intent); + } } } diff --git a/app/src/main/java/com/welchsoftwaredevelopers/myapplication/MainActivity.java b/app/src/main/java/com/welchsoftwaredevelopers/myapplication/MainActivity.java index b7e7840..19bdc20 100644 --- a/app/src/main/java/com/welchsoftwaredevelopers/myapplication/MainActivity.java +++ b/app/src/main/java/com/welchsoftwaredevelopers/myapplication/MainActivity.java @@ -1,9 +1,13 @@ package com.welchsoftwaredevelopers.myapplication; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.TextView; import android.widget.Toast; import java.io.BufferedReader; @@ -14,7 +18,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import org.json.JSONArray; @@ -22,7 +28,14 @@ import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends AppCompatActivity { - public List> script = new ArrayList<>(); + private ArrayList> script; + private ArrayList ScriptQuestion; + private Boolean clear = false; + + public MainActivity() { + script = new ArrayList<>(); + ScriptQuestion = new ArrayList<>(); + } @Override protected void onCreate(Bundle savedInstanceState) { @@ -30,26 +43,71 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); try { - JSONArray test = new JSONArray(convertStreamToString(getResources().openRawResource(R.raw.script))); + String str = convertStreamToString(getResources().openRawResource(R.raw.script)); + JSONArray test = new JSONArray(str); readJson(test); + Log.d("D", "test"); + Log.d("D", "script var: " + script.toString()); + Log.d("D", "script question: " + ScriptQuestion.toString()); } catch (JSONException | IOException e) { e.printStackTrace(); } } - public static void readJson(JSONArray ScriptObject) throws JSONException { - Integer length = ScriptObject.length(); - for (i = 0; i > length; i++) { - JSONObject question = ScriptObject.getJSONObject(i); - question + @Override + protected void onStart() { + super.onStart(); + + Intent intent = getIntent(); + Integer count = intent.getIntExtra(getString(R.string.Total), 0); + SharedPreferences sharedPref = MainActivity.this.getPreferences(Context.MODE_PRIVATE); + if (sharedPref.getInt(getString(R.string.Total), 0) < count) { + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt(getString(R.string.Total), count); + editor.commit(); } + + + Integer Total = sharedPref.getInt(getString(R.string.Total), 0); + ((TextView) findViewById(R.id.textView_Total)).setText(Total.toString()); + } + + public void readJson(JSONArray ScriptObject) throws JSONException { + Integer length = ScriptObject.length(); + Log.d("D", "length: " + length.toString()); + for (int i = 0; i < length; i++) { + Log.d("D", "test loop" + length.toString() + ": " + ((Integer) i).toString()); + JSONObject question = ScriptObject.getJSONObject(i); + Log.d("D", "current question object: " + question.toString()); + + JSONArray opts = question.getJSONArray("opts"); + Integer length1 = opts.length(); + + ScriptQuestion.add(question.getString("question")); + Log.d("D", "current question string: " + question.getString("question")); + + List optText = new ArrayList<>(length1); + List optDestination = new ArrayList<>(length1); + for (int x = 0; x < length1; x++) { + Log.d("D", "test inner loop" + length1.toString() + ": " + ((Integer) x).toString()); + JSONObject tempOpt = opts.getJSONObject(x); + Log.d("D", "opts object: " + tempOpt.toString()); + optText.add(tempOpt.getString("Text")); + optDestination.add(tempOpt.getInt("Destination")); + } + HashMap tmp = new HashMap<>(); + tmp.put("Text", optText); + tmp.put("Destination", optDestination); + script.add(tmp); + } + } //http://www.java2s.com/Code/Java/File-Input-Output/ConvertInputStreamtoString.htm public static String convertStreamToString(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); - String line = null; + String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } @@ -57,7 +115,7 @@ public class MainActivity extends AppCompatActivity { return sb.toString(); } - public static String getStringFromFile(String filePath) throws IOException, FileNotFoundException{ + public static String getStringFromFile(String filePath) throws IOException, FileNotFoundException { File fl = new File(filePath); FileInputStream fin = new FileInputStream(fl); String ret = convertStreamToString(fin); @@ -66,18 +124,33 @@ public class MainActivity extends AppCompatActivity { return ret; } + public void ClickClear(View v) { + clear = true; + ((TextView) findViewById(R.id.textView_Total)).setText("0"); + SharedPreferences sharedPref = MainActivity.this.getPreferences(Context.MODE_PRIVATE); + + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt(getString(R.string.Total), 0); + editor.commit(); + } + public void Click(View v) { - if (true) { - Toast.makeText(this, " Please Make A Selection ", Toast.LENGTH_SHORT).show(); - } - else { - Intent intent = new Intent(this, ChoiceActivity.class); - intent.putStringArrayListExtra("Text", (ArrayList) script.get(1).get("Text")); - intent.putIntegerArrayListExtra("Destination", (ArrayList) script.get(1).get("Destination")); - intent.putExtra("Question", (ArrayList) script.get(1).get("Question")); - intent. - startActivity(intent); + Intent intent = new Intent(this, ChoiceActivity.class); + intent.putStringArrayListExtra("Questions", ScriptQuestion); + intent.putExtra("Size", script.size()); + intent.putExtra("Next", 0); + intent.putExtra("Clear", clear); + + Integer length = script.size(); + Integer i; + for (i = 0; i < length; i++) { + String nameOpts = "Opts" + i.toString(); + HashMap tempHash = script.get(i); + Log.d("D", "temp hash: " + tempHash.toString()); + intent.putExtra(nameOpts, tempHash); } + startActivity(intent); + } } diff --git a/app/src/main/res/layout/activity_choice.xml b/app/src/main/res/layout/activity_choice.xml index dcb6c4e..66bdc61 100644 --- a/app/src/main/res/layout/activity_choice.xml +++ b/app/src/main/res/layout/activity_choice.xml @@ -1,9 +1,67 @@ - + android:orientation="vertical" + android:paddingLeft="16dp" + android:paddingRight="16dp"> - + + + + + + + + + + + + + + +