From 694ba6b36416f4701ba27757929b0435b8dd7582 Mon Sep 17 00:00:00 2001 From: rayacevdo45 Date: Sun, 30 Aug 2015 17:19:14 -0400 Subject: [PATCH 1/2] first commit --- build.gradle | 2 + src/main/java/nyc/c4q/ListActivity.java | 151 ++++++++++++++---- .../java/nyc/c4q/PaceCalculatorActivity.java | 35 +++- src/main/res/layout/activity_list.xml | 7 +- .../res/layout/fragment_pace_calculator.xml | 30 +--- 5 files changed, 164 insertions(+), 61 deletions(-) diff --git a/build.gradle b/build.gradle index 7c6b66b..4d6600f 100644 --- a/build.gradle +++ b/build.gradle @@ -53,6 +53,8 @@ dependencies { compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.google.code.gson:gson:2.3.1' + compile 'com.j256.ormlite:ormlite-android:4.48' + // TODO: requires special build of robolectric right now. working on this... testCompile('org.robolectric:robolectric:2.4') { exclude module: 'classworlds' diff --git a/src/main/java/nyc/c4q/ListActivity.java b/src/main/java/nyc/c4q/ListActivity.java index 08894ac..f1d6796 100644 --- a/src/main/java/nyc/c4q/ListActivity.java +++ b/src/main/java/nyc/c4q/ListActivity.java @@ -1,46 +1,24 @@ package nyc.c4q; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ListView; +import java.util.ArrayList; + public class ListActivity extends Activity { + private Button flip; + private ListView list; + private ArrayAdapter adapter; + + ArrayList names; + ArrayList names2; - public ListView list; - - public static final Person[] PEOPLE = { - new Person("Hannah", "Abbott", House.Hufflepuff), - new Person("Katie", "Bell", House.Gryffindor), - new Person("Susan", "Bones", House.Hufflepuff), - new Person("Terry", "Boot", House.Ravenclaw), - new Person("Lavender", "Brown", House.Gryffindor), - new Person("Cho", "Chang", House.Ravenclaw), - new Person("Michael", "Corner", House.Ravenclaw), - new Person("Colin", "Creevey", House.Gryffindor), - new Person("Marietta", "Edgecombe", House.Ravenclaw), - new Person("Justin", "Finch-Fletchley", House.Hufflepuff), - new Person("Seamus", "Finnigan", House.Gryffindor), - new Person("Anthony", "Goldstein", House.Ravenclaw), - new Person("Hermione", "Granger", House.Gryffindor), - new Person("Angelina", "Johnson", House.Gryffindor), - new Person("Lee", "Jordan", House.Gryffindor), - new Person("Neville", "Longbottom", House.Gryffindor), - new Person("Luna", "Lovegood", House.Ravenclaw), - new Person("Ernie", "Macmillan", House.Hufflepuff), - new Person("Parvati", "Patil", House.Gryffindor), - new Person("Padma", "Patil", House.Ravenclaw), - new Person("Harry", "Potter", House.Gryffindor), - new Person("Zacharias", "Smith", House.Hufflepuff), - new Person("Alicia", "Spinnet", House.Gryffindor), - new Person("Dean", "Thomas", House.Gryffindor), - new Person("Fred", "Weasley", House.Gryffindor), - new Person("George", "Weasley", House.Gryffindor), - new Person("Ginny", "Weasley", House.Gryffindor), - new Person("Ron", "Weasley", House.Gryffindor) - }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -48,6 +26,111 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_list); list = (ListView) findViewById(R.id.list); + flip = (Button) findViewById(R.id.flipID); + + SharedPreferences settings; + settings = ListActivity.this.getSharedPreferences("PREFS_NAME", 0); + String name = settings.getString("flipText",""); + //button.setVisibility(View.VISIBLE); + if (! name.equals("")){ + flip.setText(name); + } + + names = new ArrayList(); + names.add("Hannah Abbott"); + names.add("Katie Bell"); + names.add("Susan Bones"); + names.add("Terry Boot"); + names.add("Lavender Brown"); + names.add("Cho Chang"); + names.add("Michael Corner"); + names.add("Colin Creevey"); + names.add("Marietta Edgecombe"); + names.add("Justin Finch-Fletchley"); + names.add("Seamus Finnigan"); + names.add("Anthony Goldstein"); + names.add("Hermione Granger"); + names.add("Angelina Johnson"); + names.add("Lee Jordan"); + names.add("Neville Longbottom"); + names.add("Luna Lovegood"); + names.add("Ernin Macmillan"); + names.add("Parvati Patil"); + names.add("Padma Patil"); + names.add("Harry Potter"); + names.add("Zacharias Smith"); + names.add("Alicia Spinnet"); + names.add("Dean Thomas"); + names.add("Fred Weasley"); + names.add("George Weasley"); + names.add("Ginny Weasley"); + names.add("Ron Weasley"); + + names2 = new ArrayList(); + names2.add("Abbott, Hannah"); + names2.add("Bell, Katie"); + names2.add("Bones, Susan"); + names2.add("Boot, Terry"); + names2.add("Brown, Lavender"); + names2.add("Chang, Cho"); + names2.add("Corner, Michael"); + names2.add("Creevey, Colin"); + names2.add("Edgecombe, Marietta"); + names2.add("Finch-Fletchley, Justin"); + names2.add("Finnigan, Seamus"); + names2.add("Goldstein, Anthony"); + names2.add("Granger, Hermione"); + names2.add("Johnson, Angelina "); + names2.add("Jordan, Lee"); + names2.add("Longbottom, Neville"); + names2.add("Lovegood, Luna"); + names2.add("Macmillan, Ernin"); + names2.add("Patil, Parvati"); + names2.add("Patil, Padma"); + names2.add("Potter, Harry"); + names2.add("Smith, Zacharias"); + names2.add("Spinnet, Alicia"); + names2.add("Thomas, Dean"); + names2.add("Weasley, Fred"); + names2.add("Weasley, George"); + names2.add("Weasley, Ginny"); + names2.add("Weasley, Ron"); + + if (flip.getText().toString().equals("Last, First")){ + adapter = new ArrayAdapter<>(ListActivity.this, android.R.layout.simple_list_item_1, names); + list.setAdapter(adapter); + } + else { + adapter = new ArrayAdapter<>(ListActivity.this, android.R.layout.simple_list_item_1, names2); + list.setAdapter(adapter); + } + + + } + public void flipM (View v){ + if (flip.getText().toString().equals("Last, First")){ + flip.setText("First Last"); + adapter = new ArrayAdapter<>(ListActivity.this, android.R.layout.simple_list_item_1, names2); + list.setAdapter(adapter); + } + else { + flip.setText("Last, First"); + adapter = new ArrayAdapter<>(ListActivity.this, android.R.layout.simple_list_item_1, names); + list.setAdapter(adapter); + } } + @Override + protected void onStop() { + super.onStop(); + + String flipText = flip.getText().toString(); + SharedPreferences settings; + settings = ListActivity.this.getSharedPreferences("PREFS_NAME", 0); + SharedPreferences.Editor editor = settings.edit(); + + editor.putString("flipText", flipText); + editor.commit(); + + } } diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java index 5c0616e..b3c5bbe 100644 --- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java +++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java @@ -1,14 +1,47 @@ package nyc.c4q; -import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.ArrayList; public class PaceCalculatorActivity extends FragmentActivity { + EditText distance, time; + TextView pace; + ArrayList numbers; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pace_calculator); + + distance = (EditText) findViewById(R.id.input_distance); + time = (EditText) findViewById(R.id.input_time); + pace = (TextView) findViewById(R.id.paceID); + + numbers = new ArrayList(); + for (int i = 1; i < 10000; i++){ + String n = Integer.toString(i); + numbers.add(n); + } } + public void calculate (View v){ + String dString = distance.getText().toString(); + String tString = time.getText().toString(); + + if (numbers.contains(dString) && numbers.contains(tString)) { + double d = Integer.parseInt(dString); + double t = Integer.parseInt(tString); + double p = d / t; + pace.setText(p + " Miles Per Minute"); + } + else { Toast.makeText(getApplicationContext(), "Please Enter a valid numbers between 0 - 10000", + Toast.LENGTH_LONG).show(); + } + } } diff --git a/src/main/res/layout/activity_list.xml b/src/main/res/layout/activity_list.xml index 3e82945..81a8dd3 100644 --- a/src/main/res/layout/activity_list.xml +++ b/src/main/res/layout/activity_list.xml @@ -11,12 +11,13 @@ >