add appBar and menu

This commit is contained in:
lordwelch 2017-04-04 15:25:35 -06:00
parent a02c1aa23c
commit 92303438ed
13 changed files with 302 additions and 127 deletions

2
.idea/misc.xml generated
View File

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" 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" />
</component>
<component name="ProjectType">

View File

@ -40,5 +40,6 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}

View File

@ -8,14 +8,19 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:label="@string/title"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChoiceActivity" />
<activity
android:name=".ChoiceActivity"
android:theme="@style/AppTheme.NoActionBar" />
</application>
</manifest>

View File

@ -5,7 +5,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@ -24,11 +28,13 @@ public class ChoiceActivity extends AppCompatActivity {
private ArrayList<String> ScriptQuestion;
private RadioGroup group;
private SharedPreferences sharedPref;
private Boolean clear = false;
private Boolean clear;
private Boolean fail;
private Integer current;
public ChoiceActivity() {
script = new ArrayList<>();
fail = false;
}
@ -36,29 +42,33 @@ public class ChoiceActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
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));
((TextView) findViewById(R.id.question)).setText(ScriptQuestion.get(current));
while (i < size) {
HashMap<String, List> tmp1 = new HashMap<>();
tmp1.putAll((HashMap<String,List>) intent.getSerializableExtra("Opts" + i.toString()));
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());
Log.d("D", "script size: " + size.toString());
Log.d("D", "script: " + script.toString());
Log.d("D", "current: " + current.toString());
Log.d("D", "questions: " + ScriptQuestion.toString());
Iterator iter1 = script.get(current).get("Text").iterator();
RadioButton button;
while (iter1.hasNext()) {
button = new RadioButton(this);
Log.d("D", "Radiobutton");
button.setText((String) iter1.next());
group.addView(button);
}
@ -74,22 +84,57 @@ public class ChoiceActivity extends AppCompatActivity {
Total = 0;
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.Total), 0);
if (clear) {
Clear();
}
editor.commit();
} else {
Total = sharedPref.getInt(getString(R.string.Total), 0);
}
((TextView) findViewById(R.id.textView_choice_total)).setText(Total.toString());
((TextView) findViewById(R.id.choice_textView_total)).setText(Total.toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
inflater.inflate(R.menu.choice, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.clearMenu:
Clear();
return true;
case R.id.FailMenu:
fail = true;
default:
return super.onOptionsItemSelected(item);
}
}
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);
Integer totalDone;
totalDone = sharedPref.getInt(getString(R.string.Total), 0);
Log.d("D", fail.toString());
if (!fail) {
totalDone = sharedPref.getInt(getString(R.string.Total), 0) + 1;
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.Total), totalDone);
editor.apply();
}
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("Clear", clear);
intent.putExtra(getString(R.string.Total), totalDone);
editor.apply();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
clear = false;
fail = false;
startActivity(intent);
finish();
}
@ -101,7 +146,10 @@ public class ChoiceActivity extends AppCompatActivity {
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("Clear", clear);
clear = false;
fail = false;
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()))));
@ -115,4 +163,13 @@ public class ChoiceActivity extends AppCompatActivity {
startActivity(intent);
}
}
public void Clear() {
clear = true;
((TextView) findViewById(R.id.choice_textView_total)).setText("0");
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.Total), 0);
editor.commit();
}
}

View File

@ -5,7 +5,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
@ -41,6 +45,8 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
try {
String str = convertStreamToString(getResources().openRawResource(R.raw.script));
@ -66,10 +72,33 @@ public class MainActivity extends AppCompatActivity {
editor.putInt(getString(R.string.Total), count);
editor.commit();
}
if (intent.getBooleanExtra("Clear", false)) {
Clear();
}
clear = false;
Integer Total = sharedPref.getInt(getString(R.string.Total), 0);
((TextView) findViewById(R.id.textView_Total)).setText(Total.toString());
((TextView) findViewById(R.id.main_textView_Total)).setText(Total.toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.clearMenu:
Clear();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void readJson(JSONArray ScriptObject) throws JSONException {
@ -125,8 +154,12 @@ public class MainActivity extends AppCompatActivity {
}
public void ClickClear(View v) {
Clear();
}
public void Clear() {
clear = true;
((TextView) findViewById(R.id.textView_Total)).setText("0");
((TextView) findViewById(R.id.main_textView_Total)).setText("0");
SharedPreferences sharedPref = MainActivity.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
@ -141,13 +174,12 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("Next", 0);
intent.putExtra("Clear", clear);
Integer length = script.size();
Integer i;
for (i = 0; i < length; i++) {
Iterator<HashMap<String, List>> iter1 = script.iterator();
Integer i = 0;
while (iter1.hasNext()) {
String nameOpts = "Opts" + i.toString();
HashMap<String, List> tempHash = script.get(i);
Log.d("D", "temp hash: " + tempHash.toString());
intent.putExtra(nameOpts, tempHash);
intent.putExtra(nameOpts, iter1.next());
i++;
}
startActivity(intent);

View File

@ -1,67 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout 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_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
tools:context="com.welchsoftwaredevelopers.myapplication.ChoiceActivity">
<TextView
android:id="@+id/textView_choice_total"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="viewEnd" />
android:theme="@style/AppTheme.AppBarOverlay">
<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.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp">
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</RadioGroup>
</ScrollView>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<include layout="@layout/content_choice" />
<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>
</android.support.design.widget.CoordinatorLayout>

View File

@ -1,55 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout 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_height="match_parent"
tools:context="com.welchsoftwaredevelopers.myapplication.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
tools:context="com.welchsoftwaredevelopers.myapplication.MainActivity">
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="100dp"
android:onClick="Click"
android:text="Start"
android:textSize="30sp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="100dp"
app:layout_constraintTop_toBottomOf="@+id/textView_Total"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/textView_Total"
android:layout_width="368dp"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:textAlignment="viewEnd"
android:textColor="@android:color/black"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" />
android:theme="@style/AppTheme.AppBarOverlay">
<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:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/choice_textView_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:textAlignment="viewEnd" />
<TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="nothing"
android:textColor="@android:color/black" />
<ScrollView
android:id="@+id/scrollView"
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
style="?android:buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_Done"
style="?android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="ClickDone"
android:text="@string/DoneButton" />
<Button
android:id="@+id/button_Continue"
style="?android:buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="ClickChoice"
android:text="@string/ContinueButton" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,54 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.welchsoftwaredevelopers.myapplication.MainActivity"
tools:showIn="@layout/activity_main">
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="100dp"
android:onClick="Click"
android:text="@string/StartButton"
android:textSize="30sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_textView_Total" />
<TextView
android:id="@+id/main_textView_Total"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="64dp"
android:textAlignment="viewEnd"
android:textColor="@android:color/black"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="301dp"
android:onClick="ClickClear"
android:text="@string/ClearButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_textView_Total" />
</android.support.constraint.ConstraintLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/FailMenu"
android:title="@string/FailMenu" />
</menu>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/clearMenu"
android:title="@string/ClearButton" />
</menu>

View File

@ -1,4 +1,10 @@
<resources>
<string name="app_name">My Application</string>
<string name="Total">Total</string>
<string name="title">Phonathon</string>
<string name="StartButton">Start</string>
<string name="ClearButton">Clear</string>
<string name="DoneButton">Done</string>
<string name="ContinueButton">Continue</string>
<string name="FailMenu">Fail</string>
</resources>

View File

@ -8,4 +8,13 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>