"figuring out how to pass script between activities."

This commit is contained in:
lordwelch 2017-03-31 17:07:03 -06:00
parent 9b75e375e0
commit eecf46161e
6 changed files with 47 additions and 26 deletions

2
.idea/misc.xml generated
View File

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

4
.idea/modules.xml generated
View File

@ -2,7 +2,9 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/MyApplication.iml" filepath="$PROJECT_DIR$/MyApplication.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

@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".ChoiceActivity"> <activity android:name=".ChoiceActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -19,6 +19,7 @@ import java.util.List;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
public List<Hashtable<String, List>> script = new ArrayList<>(); public List<Hashtable<String, List>> script = new ArrayList<>();
@ -30,13 +31,21 @@ public class MainActivity extends AppCompatActivity {
try { try {
JSONArray test = new JSONArray(convertStreamToString(getResources().openRawResource(R.raw.script))); JSONArray test = new JSONArray(convertStreamToString(getResources().openRawResource(R.raw.script)));
readJson(test);
} catch (JSONException | IOException e) { } catch (JSONException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
//http://www.java2s.com/Code/Java/File-Input-Output/ConvertInputStreamtoString.htm
public static void readJson(JSONArray ScriptObject) throws JSONException {
Integer length = ScriptObject.length();
for (i = 0; i > length; i++) {
JSONObject question = ScriptObject.getJSONObject(i);
question
}
}
//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();
@ -60,10 +69,13 @@ public class MainActivity extends AppCompatActivity {
public void Click(View v) { public void Click(View v) {
if (true) { if (true) {
Toast.makeText(this, " Please Make A Selection ", Toast.LENGTH_SHORT).show(); Toast.makeText(this, " Please Make A Selection ", Toast.LENGTH_SHORT).show();
} else { }
else {
Intent intent = new Intent(this, ChoiceActivity.class); Intent intent = new Intent(this, ChoiceActivity.class);
intent.putStringArrayListExtra("Text", (ArrayList<String>) script.get(1).get("Text")); intent.putStringArrayListExtra("Text", (ArrayList<String>) script.get(1).get("Text"));
intent.putIntegerArrayListExtra("Destination", (ArrayList<Integer>) script.get(1).get("Destination")); intent.putIntegerArrayListExtra("Destination", (ArrayList<Integer>) script.get(1).get("Destination"));
intent.putExtra("Question", (ArrayList<String>) script.get(1).get("Question"));
intent.
startActivity(intent); startActivity(intent);
} }
} }

View File

@ -1,5 +1,7 @@
[ [
[ {
"question": "question 1:",
"opts": [
{ {
"Text": "opt1", "Text": "opt1",
"DESTINATION": 1 "DESTINATION": 1
@ -8,8 +10,11 @@
"Text": "opt2", "Text": "opt2",
"DESTINATION": 2 "DESTINATION": 2
} }
], ]
[ },
{
"question": "question 2:",
"opts": [
{ {
"Text": "opt1", "Text": "opt1",
"DESTINATION": 3 "DESTINATION": 3
@ -19,4 +24,5 @@
"DESTINATION": 0 "DESTINATION": 0
} }
] ]
}
] ]

View File

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files