Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
CPTR405
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kaelan Willauer
CPTR405
Commits
c60b7ee8
Commit
c60b7ee8
authored
Apr 09, 2021
by
Kaelan Willauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
homework 2
parent
d9d74709
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
42 deletions
+95
-42
.idea/gradle.xml
.idea/gradle.xml
+1
-0
app/src/main/java/com/zybooks/pizzaparty/MainActivity.java
app/src/main/java/com/zybooks/pizzaparty/MainActivity.java
+49
-7
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_main.xml
+32
-35
app/src/main/res/values/colors.xml
app/src/main/res/values/colors.xml
+1
-0
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
+5
-0
app/src/main/res/values/styles.xml
app/src/main/res/values/styles.xml
+7
-0
No files found.
.idea/gradle.xml
View file @
c60b7ee8
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"GradleMigrationSettings"
migrationVersion=
"1"
/>
<component
name=
"GradleSettings"
>
<option
name=
"linkedExternalProjectsSettings"
>
<GradleProjectSettings>
...
...
app/src/main/java/com/zybooks/pizzaparty/MainActivity.java
View file @
c60b7ee8
...
...
@@ -3,12 +3,18 @@
package
com.zybooks.pizzaparty
;
import
android.os.Bundle
;
import
android.text.Editable
;
import
android.text.TextWatcher
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.ArrayAdapter
;
import
android.widget.EditText
;
import
android.widget.RadioGroup
;
import
android.widget.TextView
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.util.Log
;
import
android.widget.Spinner
;
import
android.widget.Toast
;
public
class
MainActivity
extends
AppCompatActivity
{
...
...
@@ -16,7 +22,7 @@ public class MainActivity extends AppCompatActivity {
private
EditText
mNumAttendEditText
;
private
TextView
mNumPizzasTextView
;
private
RadioGroup
mHowHungryRadioGroup
;
private
Spinner
mHowHungrySpinner
;
private
final
static
String
TAG
=
"MainActivity"
;
...
...
@@ -30,7 +36,44 @@ public class MainActivity extends AppCompatActivity {
// Assign the widgets to fields
mNumAttendEditText
=
findViewById
(
R
.
id
.
attendEditText
);
mNumPizzasTextView
=
findViewById
(
R
.
id
.
answerTextView
);
mHowHungryRadioGroup
=
findViewById
(
R
.
id
.
hungryRadioGroup
);
mHowHungrySpinner
=
findViewById
(
R
.
id
.
hunger_spinner
);
// Watch for changes to number attending
mNumAttendEditText
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
}
@Override
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
}
@Override
public
void
afterTextChanged
(
Editable
s
)
{
mNumPizzasTextView
.
setText
(
""
);
}
});
// set up the hunger spinner
ArrayAdapter
<
CharSequence
>
adapter
=
ArrayAdapter
.
createFromResource
(
this
,
R
.
array
.
hunger_array
,
android
.
R
.
layout
.
simple_spinner_item
);
adapter
.
setDropDownViewResource
(
android
.
R
.
layout
.
simple_spinner_dropdown_item
);
mHowHungrySpinner
.
setAdapter
(
adapter
);
mHowHungrySpinner
.
setSelection
(
0
,
false
);
mHowHungrySpinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
String
item
=
(
String
)
parent
.
getItemAtPosition
(
position
);
Toast
.
makeText
(
MainActivity
.
this
,
item
,
Toast
.
LENGTH_SHORT
).
show
();
mNumPizzasTextView
.
setText
(
""
);
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
parent
)
{
}
});
}
public
void
calculateClick
(
View
view
)
{
...
...
@@ -40,18 +83,17 @@ public class MainActivity extends AppCompatActivity {
try
{
String
numAttendStr
=
mNumAttendEditText
.
getText
().
toString
();
numAttend
=
Integer
.
parseInt
(
numAttendStr
);
}
catch
(
NumberFormatException
ex
)
{
}
catch
(
NumberFormatException
ex
)
{
numAttend
=
0
;
}
// Get hunger level selection
int
checkedId
=
mHowHungry
RadioGroup
.
getCheckedRadioButtonId
();
int
checkedId
=
mHowHungry
Spinner
.
getId
();
// I didn't know what to do after updating to mHowHungrySpinner
PizzaCalculator
.
HungerLevel
hungerLevel
=
PizzaCalculator
.
HungerLevel
.
RAVENOUS
;
if
(
checkedId
==
R
.
id
.
lightRadioButton
)
{
if
(
checkedId
==
R
.
id
.
hunger_spinner
)
{
hungerLevel
=
PizzaCalculator
.
HungerLevel
.
LIGHT
;
}
else
if
(
checkedId
==
R
.
id
.
mediumRadioButton
)
{
else
if
(
checkedId
==
R
.
id
.
hunger_spinner
)
{
hungerLevel
=
PizzaCalculator
.
HungerLevel
.
MEDIUM
;
}
...
...
app/src/main/res/layout/activity_main.xml
View file @
c60b7ee8
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.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:id=
"@+id/activity_main"
android:background=
"@drawable/pizza_background"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:paddingBottom=
"16dp"
android:paddingLeft=
"16dp"
android:paddingRight=
"16dp"
android:paddingTop=
"16dp"
tools:context=
"com.zybooks.pizzaparty.MainActivity"
>
<TextView
android:id=
"@+id/numberLabel"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:labelFor=
"@id/attendEditText"
android:text=
"@string/number_of_people"
android:textSize=
"@dimen/label_text_size"
android:labelFor=
"@id/attendEditText"
/>
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<EditText
android:id=
"@+id/attendEditText"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:inputType=
"number"
android:layout_marginLeft=
"5dp"
android:ems=
"5"
android:importantForAutofill=
"no"
android:hint=
"@string/_10"
/>
android:hint=
"@string/_10"
app:layout_constraintLeft_toRightOf=
"@id/numberLabel"
app:layout_constraintBaseline_toBaselineOf=
"@id/numberLabel"
/>
<TextView
android:id=
"@+id/hungryLabel"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2
0
dp"
android:layout_marginTop=
"2
5
dp"
android:text=
"@string/how_hungry"
android:textSize=
"24sp"
android:labelFor=
"@id/hungryRadioGroup"
/>
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/numberLabel"
android:labelFor=
"@id/hunger_spinner"
/>
<
RadioGroup
android:id=
"@+id/hung
ryRadioGroup
"
android:layout_width=
"
fill_par
ent"
<
Spinner
android:id=
"@+id/hung
er_spinner
"
android:layout_width=
"
wrap_cont
ent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<RadioButton
android:id=
"@+id/lightRadioButton"
android:text=
"@string/light"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<RadioButton
android:id=
"@+id/mediumRadioButton"
android:text=
"@string/medium"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"true"
/>
<RadioButton
android:id=
"@+id/ravenousRadioButton"
android:text=
"@string/ravenous"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</RadioGroup>
app:layout_constraintLeft_toRightOf=
"@id/hungryLabel"
app:layout_constraintBaseline_toBaselineOf=
"@id/hungryLabel"
/>
<TextView
android:id=
"@+id/answerTextView"
...
...
@@ -65,7 +56,10 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
app:layout_constraintLeft_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/hunger_spinner"
android:layout_marginLeft=
"5dp"
/>
<Button
android:id=
"@+id/calcButton"
...
...
@@ -73,5 +67,8 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:onClick=
"calculateClick"
/>
</LinearLayout>
\ No newline at end of file
android:onClick=
"calculateClick"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/answerTextView"
style=
"@style/CalcButton"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
c60b7ee8
...
...
@@ -8,4 +8,5 @@
<color
name=
"black"
>
#FF000000
</color>
<color
name=
"white"
>
#FFFFFFFF
</color>
<color
name=
"my_green"
>
#11BB11
</color>
<color
name=
"gray"
>
#AAA
</color>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
c60b7ee8
...
...
@@ -8,4 +8,9 @@
<string
name=
"ravenous"
>
Ravenous
</string>
<string
name=
"total_pizzas"
>
Total pizzas: %d
</string>
<string
name=
"calculate"
>
Calculate
</string>
<string-array
name=
"hunger_array"
>
<item>
Light
</item>
<item>
Medium
</item>
<item>
Ravenous
</item>
</string-array>
</resources>
\ No newline at end of file
app/src/main/res/values/styles.xml
0 → 100644
View file @
c60b7ee8
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name=
"CalcButton"
>
<item
name=
"android:textSize"
>
24sp
</item>
<item
name=
"android:textColor"
>
@color/gray
</item>
</style>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment