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">
<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$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>

View File

@ -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'
})

View File

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

View File

@ -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<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
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<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;
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<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
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<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
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<String>) script.get(1).get("Text"));
intent.putIntegerArrayListExtra("Destination", (ArrayList<Integer>) script.get(1).get("Destination"));
intent.putExtra("Question", (ArrayList<String>) 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<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"?>
<android.support.constraint.ConstraintLayout 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"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="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"
android:layout_width="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
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:onClick="Click"
android:text="Start"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.248" />
android:layout_marginTop="100dp"
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>

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB