Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Anthony M. Final pull #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ListViewActivity"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".NetworkActivity" />
<activity android:name=".JSONActivity" />
<activity android:name=".NotificationActivity" />
Expand Down
80 changes: 52 additions & 28 deletions src/main/java/nyc/c4q/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,52 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;


public class ListActivity extends Activity {

public ListView list;
public Button buttonNme;
public Button buttonColor;
boolean isFirst;


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)
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
Expand All @@ -48,6 +58,20 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_list);

list = (ListView) findViewById(R.id.list);
buttonNme = (Button) findViewById(R.id.button_name);
buttonColor = (Button) findViewById(R.id.button_color);


if (isFirst) {
Arrays.sort(PEOPLE, new Comparator<Person>() {
@Override
public int compare(Person person, Person personTwo) {
return person.lastName.compareTo(personTwo.lastName);
}
});


}
}

}
94 changes: 94 additions & 0 deletions src/main/java/nyc/c4q/PaceCalculatorActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,108 @@
package nyc.c4q;

import android.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class PaceCalculatorActivity extends FragmentActivity {

private EditText inputDistance;
private EditText inputTimeMin;
private EditText inputTimeSec;
private EditText inputPaceMin;
private EditText inputPaceSec;
private Button buttonCalculate;
float time;
float pace;
float distance;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pace_calculator);
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
PaceCalculatorFragment paceFragment = (PaceCalculatorFragment) getSupportFragmentManager().findFragmentById(R.id.paceFragment);



inputDistance = (EditText) findViewById(R.id.input_distance);
inputTimeMin = (EditText) findViewById(R.id.input_time_min);
inputTimeSec = (EditText) findViewById(R.id.input_time_sec);
inputPaceMin = (EditText) findViewById(R.id.input_pace_min);
inputPaceSec = (EditText) findViewById(R.id.input_pace_sec);
buttonCalculate = (Button) findViewById(R.id.button_calculate);


try {

String distanceString = inputDistance.getText().toString();
String timeMin = inputTimeMin.getText().toString();
String timeSec = inputTimeSec.getText().toString();
String paceMin = inputPaceMin.getText().toString();
String paceSec = inputPaceSec.getText().toString();

if (timeMin.matches("((-|\\\\+)?[0-9]+(\\\\.[0-9]+)?)+") && timeSec.matches("((-|\\\\+)?[0-9]+(\\\\.[0-9]+)?)+")
&& paceMin.matches("((-|\\\\+)?[0-9]+(\\\\.[0-9]+)?)+") && paceSec.matches("((-|\\\\+)?[0-9]+(\\\\.[0-9]+)?)+")) {
buttonCalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calculateDistance();
}
});
}
} catch (NullPointerException ex) {
Log.d("invalid", "Invalid input");
}

}

public void calculateDistance() {

String timeMin = inputTimeMin.getText().toString();
String timeSec = inputTimeSec.getText().toString();
String paceMin = inputPaceMin.getText().toString();
String paceSec = inputPaceSec.getText().toString();

time = Float.parseFloat(timeMin + "." + timeSec);
Log.d("what", Float.toString(time));
pace = Float.parseFloat(paceMin + "." + paceSec);
Log.d("what2", Float.toString(pace));
distance = time / pace;
Log.d("what3", Float.toString(distance));

inputDistance.setText(String.valueOf("%1f" + distance));

}

public void calculatePace() {

String distanceString = inputDistance.getText().toString();
String timeMin = inputTimeMin.getText().toString();
String timeSec = inputTimeSec.getText().toString();
String paceMin = inputPaceMin.getText().toString();
String paceSec = inputPaceSec.getText().toString();

time = Float.parseFloat(timeMin + "." + timeSec);
distance = Float.parseFloat(distanceString);
pace = time / distance;
}

public void calculateTime() {

String distanceString = inputDistance.getText().toString();
String timeMin = inputTimeMin.getText().toString();
String timeSec = inputTimeSec.getText().toString();
String paceMin = inputPaceMin.getText().toString();
String paceSec = inputPaceSec.getText().toString();

pace = Float.parseFloat(paceMin + "." + paceSec);
distance = Float.parseFloat(distanceString);
time = pace * distance;

}

}
21 changes: 21 additions & 0 deletions src/main/java/nyc/c4q/PaceCalculatorFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package nyc.c4q;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by c4q-anthony-mcbride on 8/30/15.
*/
public class PaceCalculatorFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_pace_calculator, container, false);
return view;
}
}
10 changes: 9 additions & 1 deletion src/main/java/nyc/c4q/Person.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nyc.c4q;

public class Person {
import java.util.Comparator;

public class Person implements Comparator<Person> {
public String firstName;
public String lastName;
public House house;
Expand All @@ -10,4 +12,10 @@ public Person(String firstName, String lastName, House house) {
this.lastName = lastName;
this.house = house;
}


@Override
public int compare(Person person, Person t1) {
return 0;
}
}
24 changes: 22 additions & 2 deletions src/main/res/layout/activity_pace_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,25 @@
android:id="@+id/activity_pace_calculator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nyc.c4q.PaceCalculatorActivity"
/>
tools:context="nyc.c4q.PaceCalculatorActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">



<fragment
android:name="nyc.c4q.PaceCalculatorFragment"
android:id="@+id/paceFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>






</FrameLayout>
4 changes: 1 addition & 3 deletions src/main/res/layout/fragment_pace_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/activity_vertical_margin"
android:text="@string/calculate"
android:onClick="button_calculate_onClick"
/>
android:text="@string/calculate" />

</LinearLayout>
2 changes: 1 addition & 1 deletion src/main/res/raw/books.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@
"isbn": "0439554934",
"isbn13": "9780439554930",
"publisher": "Scholastic",
"publishyear": 2003.
"publishyear": 2003,
"checkedout": true,
"checkedoutby": 38,
"checkoutdateyear": 2015,
Expand Down
1 change: 1 addition & 0 deletions src/test/java/nyc/c4q/Part1PaceCalculatorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void test02CheckDistanceCalculation() {
buttonCalculate.callOnClick();

Assertions.assertThat(inputDistance).containsText("4.8");

}

@Test
Expand Down