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

Joshelyn's Final Assessment--semi completed #16

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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 18
minSdkVersion 17
targetSdkVersion 22
versionCode 2
versionName "1.0.0-SNAPSHOT"
Expand Down
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
64 changes: 64 additions & 0 deletions src/main/java/nyc/c4q/CustomListAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package nyc.c4q;

/**
*/
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Person> people;


public CustomListAdapter(Activity activity, List<Person> people) {
this.activity = activity;
this.people = people;
}

@Override
public int getCount() {
return people.size();
}

@Override
public Object getItem(int location) {
return people.get(location);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.listitem_member, null);

TextView names = (TextView) convertView.findViewById(R.id.text_name);
TextView houses = (TextView) convertView.findViewById(R.id.text_house);

// getting movie data for the row
Person m = people.get(position);

// Names
names.setText("Name");

// Houses
houses.setText("House");

return convertView;
}
}
4 changes: 3 additions & 1 deletion src/main/java/nyc/c4q/LibraryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.View;
import android.widget.EditText;


public class LibraryActivity extends Activity {

public EditText inputParameter;
Expand Down Expand Up @@ -53,4 +52,7 @@ public void button_getCheckedOut_onClick(View view) {
// earliest due first.
}


//I am not sure where on earth I'm suppose to put the Database.

}
40 changes: 34 additions & 6 deletions src/main/java/nyc/c4q/ListActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package nyc.c4q;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.ToggleButton;

import java.util.ArrayList;
import java.util.List;

public class ListActivity extends Activity {

public ListView list;
public class ListActivity extends android.app.ListActivity {

private ListActivity activity;
private ListView listView;
private CustomListAdapter adapter;
private List<Person> resultList = new ArrayList<Person>();
private ToggleButton buttonName;
private Button buttonColor;

public static final Person[] PEOPLE = {
new Person("Hannah", "Abbott", House.Hufflepuff),
Expand Down Expand Up @@ -42,12 +51,31 @@ public class ListActivity extends Activity {
new Person("Ron", "Weasley", House.Gryffindor)
};


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

list = (ListView) findViewById(R.id.list);
listView = (ListView) findViewById(android.R.id.list);
adapter = new CustomListAdapter(this, resultList);
listView.setAdapter(adapter);

buttonName = (ToggleButton) findViewById(R.id.button_name);
buttonColor = (Button) findViewById(R.id.button_color);

buttonName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
//if the click is on
result.append("First and Last").append();

//if the click is off
result.append("Last and First ").append();
Toast.makeText(ListActivity.this, result.toString(), Toast.LENGTH_SHORT).show();
}
});
}

}
22 changes: 21 additions & 1 deletion src/main/java/nyc/c4q/PaceCalculatorActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
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);

// //To have the fragment be shown in the PaceCalculatorActivity
// android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
// FragmentTransaction transaction = fm.beginTransaction();
// transaction.replace(R.id.fragment_pace_calculator, new PaceCalculatorFragment()).commit();



//
// if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
// .add(R.id.fragment_pace_calculator, new PaceCalculatorFragment())
// .commit();
// }


// //if you added fragment via layout xml
// PaceCalculatorFragment fragment = (PaceCalculatorFragment)fm.findFragmentById(R.id.fragment_pace_calculator);
// fragment.getView();

}

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

import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link PaceCalculatorFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link PaceCalculatorFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class PaceCalculatorFragment extends android.support.v4.app.Fragment {
//created the variables
private Button btn;
private EditText inputDistance;
private EditText inputTimeMin;
private EditText inputTimeSec;
private EditText inputPaceMin;
private EditText inputPaceSec;
private TextView tvResult;
private int count = 0; //0 because it hasn't been clicked yet


// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment BlankFragment.
*/
// TODO: Rename and change types and number of parameters
public static PaceCalculatorFragment newInstance(String param1, String param2) {
PaceCalculatorFragment fragment = new PaceCalculatorFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

public PaceCalculatorFragment() {
// Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

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

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


//to create a button
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//the idea for this part is to calculate the pace which means pace is equal to minutes/miles (time/distance)
//if the fields where all there, then the calculation should work
if(inputDistance == null) {
//the logic is that the number used in the Edit Text should give the integers and provide this operation
//converting editText to Integers
String stringInputTimeMinTextFromET = inputTimeMin.getText().toString();
int numberInputTimeMinIntFromET = new Integer(stringInputTimeMinTextFromET).intValue();

String stringInputPaceMinTextFromET = inputPaceMin.getText().toString();
int numberInputPaceMinIntFromET = new Integer(stringInputPaceMinTextFromET).intValue();

String stringInputDistanceTextFromET = inputDistance.getText().toString();
int numberInputDistanceIntFromET = new Integer(stringInputDistanceTextFromET).intValue();

numberInputDistanceIntFromET = numberInputTimeMinIntFromET / numberInputPaceMinIntFromET;

tvResult.setText(String.valueOf(numberInputDistanceIntFromET));

}
else if (inputTimeMin == null) {
String stringInputTimeMinTextFromET = inputTimeMin.getText().toString();
int numberInputTimeMinIntFromET = new Integer(stringInputTimeMinTextFromET).intValue();

String stringInputPaceMinTextFromET = inputPaceMin.getText().toString();
int numberInputPaceMinIntFromET = new Integer(stringInputPaceMinTextFromET).intValue();

String stringInputDistanceTextFromET = inputDistance.getText().toString();
int numberInputDistanceIntFromET = new Integer(stringInputDistanceTextFromET).intValue();

numberInputTimeMinIntFromET = numberInputPaceMinIntFromET * numberInputDistanceIntFromET;

tvResult.setText(String.valueOf(numberInputTimeMinIntFromET));

}

else if (inputPaceMin == null) {
String stringInputTimeMinTextFromET = inputTimeMin.getText().toString();
int numberInputTimeMinIntFromET = new Integer(stringInputTimeMinTextFromET).intValue();

String stringInputPaceMinTextFromET = inputPaceMin.getText().toString();
int numberInputPaceMinIntFromET = new Integer(stringInputPaceMinTextFromET).intValue();

String stringInputDistanceTextFromET = inputDistance.getText().toString();
int numberInputDistanceIntFromET = new Integer(stringInputDistanceTextFromET).intValue();

numberInputPaceMinIntFromET = numberInputTimeMinIntFromET / numberInputDistanceIntFromET;

tvResult.setText(String.valueOf(numberInputPaceMinIntFromET));
}

else{
//do nothing
return ;
}

//if one of the fields is missing, then the other parts should be calculated in order to find the missing part
//if time is not there, then pace and distance should be multiplied
//if pace is not there, then time should divide by distance
//if distance is not there, then time should divide by p
count++; //incrementing by 1

}
});
return result;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

// @Override
// public void onAttach(Activity activity) {
// super.onAttach(activity);
// try {
// mListener = (OnFragmentInteractionListener) activity;
// } catch (ClassCastException e) {
// throw new ClassCastException(activity.toString()
// + " must implement OnFragmentInteractionListener");
// }
// }
//
// @Override
// public void onDetach() {
// super.onDetach();
// mListener = null;
// }

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}

}
Loading