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

assessment #6

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
7 changes: 1 addition & 6 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
<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" />

<activity
android:name=".PaceCalculatorActivity"
android:label="@string/title_activity_pace_calculator"
Expand Down
89 changes: 86 additions & 3 deletions src/main/java/nyc/c4q/ListActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package nyc.c4q;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
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 android.widget.SimpleCursorAdapter;
import android.widget.Toast;

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


public class ListActivity extends Activity {
Expand Down Expand Up @@ -42,12 +51,86 @@ public class ListActivity extends Activity {
new Person("Ron", "Weasley", House.Gryffindor)
};

public static final ArrayList<String> people1 = new ArrayList<>();

int MODE = 1;
SQLiteDatabase.CursorFactory cursorFactory;
SimpleCursorAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

Button buttonName = (Button)findViewById(R.id.button_name);

buttonName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});



SQLiteDatabase db = getBaseContext().openOrCreateDatabase("members", MODE, cursorFactory);

db.execSQL("DROP TABLE members");

db.execSQL("CREATE TABLE members (firstName TEXT, lastName TEXT, house TEXT)");

for (Person person: PEOPLE) {
db.execSQL("INSERT INTO members VALUES ( '" + person.getFirstName() + "' , '" + person.getLastName()
+ "' , '" + person.getHouse() + "')");
people1.add(person.getLastName() +", "+ person.getFirstName() + ": " + person.getHouse().toString() );

}
Collections.sort(people1);

//get entire db back
Cursor query = db.rawQuery("SELECT * from members", null);

if (query.moveToFirst()){
do {
String firstName = query.getString(0);
String lastName = query.getString(1);
String house = query.getString(2);
} while (query.moveToNext());
}
else {
Toast.makeText(getBaseContext(), "Error retriveing data", Toast.LENGTH_SHORT).show();
}

db.close();


ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, people1);
list = (ListView) findViewById(R.id.list);

list.setAdapter(adapter);
}

}
public static Comparator<String> alphatetizer = new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
String name1 = lhs;
String name2 = rhs;

return name1.compareTo(name2);
}

public Comparator<String> dealphatetizer = new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
String name1 = lhs;
String name2 = rhs;

return name2.compareTo(name1);
}
};


//Now, populate listview with db items.

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

import android.content.Context;
import android.widget.ArrayAdapter;

import java.util.ArrayList;

/**
* Created by charlynbuchanan on 8/30/15.
*/
public class ListAdapter extends ArrayAdapter<Person> {

Context context;
ArrayList<String> people1;
int resource;

public ListAdapter(Context context, int resource, ArrayList<Person> PEOPLE) {
super(context, resource, PEOPLE);
this.context = context;
this.people1 = people1;
this.resource = resource;
}

//
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
// View rowView = convertView;
//
// Person p = PEOPLE.get(position);
//
// if (rowView == null) {
// LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// rowView = inflater.inflate(R.layout.activity_list, null);
// }
// }






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

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import java.sql.SQLException;

/**
* Created by charlynbuchanan on 8/30/15.
*/
public class MembersDataSource {
// Database fields
private SQLiteDatabase database;
private MySQLiteHelper dbHelper;
private String[] allColumns = { MySQLiteHelper.COLUMN_ID,
MySQLiteHelper.COLUMN_FIRST_NAME, MySQLiteHelper.COLUMN_LAST_NAME, MySQLiteHelper.COLUMN_HOUSE };

public MembersDataSource(Context context) {
dbHelper = new MySQLiteHelper(context);
}

public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}

//Maintains closure of connection
public void close() {
dbHelper.close();
}

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

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by charlynbuchanan on 8/30/15.
*/
public class MySQLiteHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "members.db";
private static final int DATABASE_VERSION = 1;

//Set up columns
public static final String TABLE_MEMBERS = "members";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_FIRST_NAME = "first";
public static final String COLUMN_LAST_NAME = "last";
public static final String COLUMN_HOUSE = "house";

//Database creation sql statement
public static final String DATABASE_CREATE = "create table "
+ TABLE_MEMBERS + "(" + COLUMN_FIRST_NAME + "integer primary key autoincrement, "
+ "text not null);" + COLUMN_LAST_NAME + COLUMN_HOUSE;

public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {
//make table with previously made create string.
getReadableDatabase().execSQL(DATABASE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEMBERS);

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

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class PaceCalculatorActivity extends FragmentActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pace_calculator);
}

android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.Fragment paceCalculator = new PaceCalculatorFragment();
android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.activity_pace_calculator, paceCalculator);
transaction.addToBackStack(null);
transaction.commit();

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

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

/**
* Created by charlynbuchanan on 8/30/15.
*/
public class PaceCalculatorFragment extends Fragment {

EditText inputDistance;
EditText inputTimeMin;
EditText inputTimeSec;
EditText inputPaceMin;
EditText inputPaceSec;
Button calculate;
int timeMin;
int timeSec;
double distance;
double paceMin;
double paceSec;



@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pace_calculator, container, false);

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





inputTimeMin.getText();



calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("distance", String.valueOf(inputDistance.getText()));
Log.i("timeMin", String.valueOf(inputTimeMin.getText()));
Log.i("timeSec", String.valueOf(inputTimeSec.getText()));
Log.i("paceMin", String.valueOf(inputPaceMin.getText()));
Log.i("paceSec", String.valueOf(inputPaceSec.getText()));

Log.i("timesec new", String.valueOf(timeSec));
// Log.i("possible for method", String.valueOf(Integer.parseInt(inputDistance.getText().toString())));

// timeSec = Integer.valueOf(String.valueOf(inputTimeSec.getText()));
// timeMin = Integer.valueOf(String.valueOf(inputTimeMin.getText()));
// distance = Double.valueOf(String.valueOf(inputDistance.getText()));
// paceMin = Double.valueOf(String.valueOf(inputPaceMin.getText()));
// paceSec = Double.valueOf(String.valueOf(inputPaceSec.getText()));


if (inputDistance == null) {
timeSec = Integer.parseInt(inputTimeSec.getText().toString());
timeMin = Integer.parseInt(inputTimeMin.getText().toString());
paceMin = Integer.parseInt(inputPaceMin.getText().toString());
paceSec = Integer.parseInt(inputPaceSec.getText().toString());
int totalTime = ((timeMin + timeSec)/60);
double totalPace = ((paceMin + paceSec)/60);
double distance = totalTime/totalPace;

inputDistance.setText(String.valueOf(distance));

} else if ((inputTimeMin == null) && (inputTimeSec == null)){
distance = Integer.parseInt(inputDistance.getText().toString());
paceMin = Integer.parseInt(inputPaceMin.getText().toString());
paceSec = Integer.parseInt(inputPaceSec.getText().toString());
double totalPace = ((paceMin + paceSec)/60);

double time = totalPace*distance;
inputTimeMin.setText(String.valueOf(time));




} else if ((inputPaceMin == null) && (inputPaceSec == null)) {
timeSec = Integer.parseInt(inputTimeSec.getText().toString());
timeMin = Integer.parseInt(inputTimeMin.getText().toString());
distance = Integer.parseInt(inputDistance.getText().toString());

int totalTime = ((timeMin + timeSec)/60);
Log.d("totalTime", String.valueOf(totalTime));
double pace = totalTime/distance;
inputPaceMin.setText((String.valueOf(pace) + "minute/mile"));
}
}
});

return view;
}


// public double getDistance() {
// //d=min/distance
//
// }
//
// public double getTime() {
// //t=pace*distance
// }
}
Loading