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
This commit is contained in:
lordwelch 2017-04-01 14:00:37 -06:00
parent eecf46161e
commit f8bd4f9806
13 changed files with 332 additions and 42 deletions

View File

@ -0,0 +1,14 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>

2
.idea/modules.xml generated
View File

@ -3,8 +3,6 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" /> <module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules> </modules>
</component> </component>

View File

@ -1,6 +1,14 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
signingConfigs {
config {
keyAlias 'gemfinder'
keyPassword 'guanfacine'
storeFile file('/home/timmy/Downloads/GemFinder-key.keystore')
storePassword 'guanfacine'
}
}
compileSdkVersion 25 compileSdkVersion 25
buildToolsVersion "25.0.2" buildToolsVersion "25.0.2"
defaultConfig { defaultConfig {
@ -13,14 +21,18 @@ android {
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
} }
} }
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })

View File

@ -10,14 +10,14 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".ChoiceActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".MainActivity" /> <activity android:name=".ChoiceActivity" />
</application> </application>
</manifest> </manifest>

View File

@ -1,13 +1,118 @@
package com.welchsoftwaredevelopers.myapplication; package com.welchsoftwaredevelopers.myapplication;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; 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 { public class ChoiceActivity extends AppCompatActivity {
private ArrayList<HashMap<String, List>> script;
private ArrayList<String> ScriptQuestion;
private RadioGroup group;
private SharedPreferences sharedPref;
private Boolean clear = false;
private Integer current;
public ChoiceActivity() {
script = new ArrayList<>();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice); 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<String, List> tmp1 = new HashMap<>();
tmp1.putAll((HashMap<String,List>) 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<HashMap<String, List>> iter1 = script.iterator();
Integer i = 0;
while (iter1.hasNext()) {
String nameOpts = "Opts" + i.toString();
intent.putExtra(nameOpts, iter1.next());
i++;
}
startActivity(intent);
}
} }
} }

View File

@ -1,9 +1,13 @@
package com.welchsoftwaredevelopers.myapplication; package com.welchsoftwaredevelopers.myapplication;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -14,7 +18,9 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.json.JSONArray; import org.json.JSONArray;
@ -22,7 +28,14 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
public List<Hashtable<String, List>> script = new ArrayList<>(); private ArrayList<HashMap<String, List>> script;
private ArrayList<String> ScriptQuestion;
private Boolean clear = false;
public MainActivity() {
script = new ArrayList<>();
ScriptQuestion = new ArrayList<>();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -30,26 +43,71 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
try { 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); readJson(test);
Log.d("D", "test");
Log.d("D", "script var: " + script.toString());
Log.d("D", "script question: " + ScriptQuestion.toString());
} catch (JSONException | IOException e) { } catch (JSONException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void readJson(JSONArray ScriptObject) throws JSONException { @Override
Integer length = ScriptObject.length(); protected void onStart() {
for (i = 0; i > length; i++) { super.onStart();
JSONObject question = ScriptObject.getJSONObject(i);
question 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<String> optText = new ArrayList<>(length1);
List<Integer> 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<String, List> 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 //http://www.java2s.com/Code/Java/File-Input-Output/ConvertInputStreamtoString.htm
public static String convertStreamToString(InputStream is) throws IOException { public static String convertStreamToString(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
sb.append(line).append("\n"); sb.append(line).append("\n");
} }
@ -57,7 +115,7 @@ public class MainActivity extends AppCompatActivity {
return sb.toString(); 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); File fl = new File(filePath);
FileInputStream fin = new FileInputStream(fl); FileInputStream fin = new FileInputStream(fl);
String ret = convertStreamToString(fin); String ret = convertStreamToString(fin);
@ -66,18 +124,33 @@ public class MainActivity extends AppCompatActivity {
return ret; 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) { public void Click(View v) {
if (true) { Intent intent = new Intent(this, ChoiceActivity.class);
Toast.makeText(this, " Please Make A Selection ", Toast.LENGTH_SHORT).show(); intent.putStringArrayListExtra("Questions", ScriptQuestion);
} intent.putExtra("Size", script.size());
else { intent.putExtra("Next", 0);
Intent intent = new Intent(this, ChoiceActivity.class); intent.putExtra("Clear", clear);
intent.putStringArrayListExtra("Text", (ArrayList<String>) script.get(1).get("Text"));
intent.putIntegerArrayListExtra("Destination", (ArrayList<Integer>) script.get(1).get("Destination")); Integer length = script.size();
intent.putExtra("Question", (ArrayList<String>) script.get(1).get("Question")); Integer i;
intent. for (i = 0; i < length; i++) {
startActivity(intent); String nameOpts = "Opts" + i.toString();
HashMap<String, List> tempHash = script.get(i);
Log.d("D", "temp hash: " + tempHash.toString());
intent.putExtra(nameOpts, tempHash);
} }
startActivity(intent);
} }
} }

View File

@ -1,9 +1,67 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.welchsoftwaredevelopers.myapplication.ChoiceActivity"> android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
</android.support.constraint.ConstraintLayout> <TextView
android:id="@+id/textView_choice_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="viewEnd" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="hi"
android:textColor="@android:color/black" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1">
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp">
</RadioGroup>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="ClickDone"
android:text="Done" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="ClickChoice"
android:text="Continue" />
</LinearLayout>
</LinearLayout>

View File

@ -4,22 +4,44 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.welchsoftwaredevelopers.myapplication.MainActivity"> tools:context="com.welchsoftwaredevelopers.myapplication.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<Button <Button
android:id="@+id/button" android:id="@+id/button"
android:layout_width="200dp" android:layout_width="200dp"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:onClick="Click" android:onClick="Click"
android:text="Start" android:text="Start"
android:textSize="30sp" android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="100dp"
app:layout_constraintVertical_bias="0.248" /> app:layout_constraintTop_toBottomOf="@+id/textView_Total" />
<TextView
android:id="@+id/textView_Total"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="hello"
android:textAlignment="viewEnd"
android:textColor="@android:color/black"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="ClickClear"
android:text="Button"
android:layout_marginTop="301dp"
app:layout_constraintTop_toBottomOf="@+id/textView_Total"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -4,11 +4,11 @@
"opts": [ "opts": [
{ {
"Text": "opt1", "Text": "opt1",
"DESTINATION": 1 "Destination": 1
}, },
{ {
"Text": "opt2", "Text": "opt2",
"DESTINATION": 2 "Destination": 2
} }
] ]
}, },
@ -17,11 +17,11 @@
"opts": [ "opts": [
{ {
"Text": "opt1", "Text": "opt1",
"DESTINATION": 3 "Destination": 3
}, },
{ {
"Text": "opt2", "Text": "opt2",
"DESTINATION": 0 "Destination": 0
} }
] ]
} }

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">My Application</string> <string name="app_name">My Application</string>
<string name="Total">Total</string>
</resources> </resources>

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB