Skip to content
Snippets Groups Projects
Commit 8a2a5768 authored by unknown's avatar unknown
Browse files

Jogging kemungkinan besar dah bisa

parent 1f8250aa
Branches
No related merge requests found
Showing
with 452 additions and 63 deletions
package com.example.leo.fitnessdiy.Adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.leo.fitnessdiy.R;
import com.example.leo.fitnessdiy.model.Jogging;
import java.util.List;
/**
* Created by Leo on 22/02/2018.
*/
public class JogginHistoryAdapter extends RecyclerView.Adapter<JogginHistoryAdapter.JoggingHistoryViewHolder> {
private List<Jogging> joggings;
public JogginHistoryAdapter(List<Jogging> j) {
this.joggings = j;
}
@Override
public JoggingHistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.jogging_card, parent, false);
return new JoggingHistoryViewHolder(v);
}
@Override
public void onBindViewHolder(JogginHistoryAdapter.JoggingHistoryViewHolder holder, int position) {
holder.Date.setText(joggings.get(position).getDate());
holder.Time.setText(
String.format("%s - %s", joggings.get(position).getStart(),
joggings.get(position).getEnd())
);
holder.Distance.setText(String.format("Your Jogging Distance : %s m",
joggings.get(position).getDistance()));
holder.Track.setText(
String.format("You have been running from %s to %s",
joggings.get(position).getStartingPoint(),
joggings.get(position).getEndPoint())
);
}
@Override
public int getItemCount() {
return joggings.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public static class JoggingHistoryViewHolder extends RecyclerView.ViewHolder{
TextView Date;
TextView Time;
TextView Distance;
TextView Track;
public JoggingHistoryViewHolder(View itemView) {
super(itemView);
Date = (TextView) itemView.findViewById(R.id.jogging_date);
Time = (TextView) itemView.findViewById(R.id.jogging_time);
Distance = (TextView) itemView.findViewById(R.id.jogging_distance);
Track = (TextView) itemView.findViewById(R.id.jogging_track);
}
}
}
package com.example.leo.fitnessdiy.Adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.leo.fitnessdiy.R;
import com.example.leo.fitnessdiy.model.Jogging;
import com.example.leo.fitnessdiy.model.Plank;
import java.util.List;
/**
* Created by Leo on 22/02/2018.
*/
public class PlankHistoryAdapter extends RecyclerView.Adapter<PlankHistoryAdapter.PlankHistoryViewHolder>{
private List<Plank> planks;
public PlankHistoryAdapter(List<Plank> p) {
this.planks = p;
}
@Override
public PlankHistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.plank_card, parent, false);
return new PlankHistoryViewHolder(v);
}
@Override
public void onBindViewHolder(PlankHistoryViewHolder holder, int position) {
holder.Date.setText(planks.get(position).getDate());
holder.Time.setText(
String.format("%s - %s", planks.get(position).getStart(),
planks.get(position).getEnd())
);
holder.Duration.setText(String.format("You last for : %s detik",
planks.get(position).getDuration()));
}
@Override
public int getItemCount() {
return planks.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public static class PlankHistoryViewHolder extends RecyclerView.ViewHolder{
TextView Date;
TextView Time;
TextView Duration;
public PlankHistoryViewHolder(View itemView) {
super(itemView);
Date = (TextView) itemView.findViewById(R.id.plank_date);
Time = (TextView) itemView.findViewById(R.id.plank_time);
Duration = (TextView) itemView.findViewById(R.id.plank_duration);
}
}
}
package com.example.leo.fitnessdiy;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.example.leo.fitnessdiy.Adapter.JogginHistoryAdapter;
import com.example.leo.fitnessdiy.Adapter.PlankHistoryAdapter;
import com.example.leo.fitnessdiy.Utilities.NetworkUtils;
import com.example.leo.fitnessdiy.model.History;
import com.example.leo.fitnessdiy.model.Jogging;
import com.example.leo.fitnessdiy.model.Plank;
import com.example.leo.fitnessdiy.model.PushUp;
import com.example.leo.fitnessdiy.model.SitUp;
import com.example.leo.fitnessdiy.routes.api;
......@@ -30,25 +40,76 @@ import java.util.List;
public class HIstoryActivity extends AppCompatActivity {
public static final String TAG = HIstoryActivity.class.getSimpleName();
private RecyclerView mRecyclerView;
private List<Jogging> joggingHistory;
private RecyclerView plankRecyclerView;
private List<Jogging> joggingHistory = new ArrayList<>();
private CardView jogging;
private CardView plank;
private List<PushUp> pushupHistory;
private List<Plank> plankHistory = new ArrayList<>();
private List<SitUp> situpHistory;
public static final String TAG = HIstoryActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
// mRecyclerView = (RecyclerView) findViewById(R.id.rv_history);
//
// LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//
// mRecyclerView.setLayoutManager(layoutManager);
// mRecyclerView.setHasFixedSize(true);
// RecyclerViewAdapter rv = new RecyclerViewAdapter(histories);
// mRecyclerView.setAdapter(rv);
mRecyclerView = (RecyclerView) findViewById(R.id.jogging_history);
mRecyclerView.setVisibility(View.GONE);
plankRecyclerView = (RecyclerView) findViewById(R.id.plank_history);
plankRecyclerView.setVisibility(View.GONE);
getJoggingData();
getPlankData();
jogging = (CardView) findViewById(R.id.jogging);
jogging.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Jogging Title Clicked");
if (mRecyclerView.getVisibility() == View.GONE) {
Log.d(TAG, "Jogging View Gone");
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
// Set Jogging Adapter
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
JogginHistoryAdapter adapter = new JogginHistoryAdapter(joggingHistory);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setVisibility(View.VISIBLE);
} else {
Log.d(TAG, "Jogging View Visible");
mRecyclerView.setVisibility(View.GONE);
mRecyclerView.removeAllViewsInLayout();
}
}
});
plank = (CardView) findViewById(R.id.plank);
plank.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Plank Title Clicked");
if (plankRecyclerView.getVisibility() == View.GONE) {
LinearLayoutManager layoutManager2 = new LinearLayoutManager(getApplicationContext());
//Set Plank Adapter
plankRecyclerView.setLayoutManager(layoutManager2);
plankRecyclerView.setHasFixedSize(true);
PlankHistoryAdapter pa = new PlankHistoryAdapter(plankHistory);
plankRecyclerView.setAdapter(pa);
plankRecyclerView.setVisibility(View.VISIBLE);
Log.d(TAG, "Plank View Now Visible");
} else {
plankRecyclerView.setVisibility(View.GONE);
plankRecyclerView.removeAllViewsInLayout();
Log.d(TAG, "Plank View Now Gone");
}
}
});
}
public void getJoggingData() {
......@@ -56,6 +117,7 @@ public class HIstoryActivity extends AppCompatActivity {
String response = NetworkUtils.getResponseFromHttpUrl(
new URL(api.JOGGING_HISTORY_URL + "1")
);
Log.d(TAG, response);
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
......@@ -67,6 +129,32 @@ public class HIstoryActivity extends AppCompatActivity {
jsonObject.getString("starting_point"),
jsonObject.getString("end_point")
));
Log.d(TAG, i + jsonObject.getString("jogging_date"));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getPlankData() {
try {
String response = NetworkUtils.getResponseFromHttpUrl(
new URL(api.PLANK_HISTORY_URL + "1")
);
Log.d(TAG, response);
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
plankHistory.add(new Plank(
jsonObject.getString("plank_date"),
jsonObject.getString("plank_time_start"),
jsonObject.getString("plank_time_end"),
jsonObject.getInt("plank_duration")
));
}
} catch (MalformedURLException e) {
e.printStackTrace();
......
......@@ -6,6 +6,10 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
......@@ -15,6 +19,7 @@ import android.os.Build;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
......@@ -29,6 +34,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.example.leo.fitnessdiy.Utilities.NetworkUtils;
import com.example.leo.fitnessdiy.Utilities.PositionUtils;
import com.example.leo.fitnessdiy.model.Jogging;
import com.example.leo.fitnessdiy.routes.api;
import com.google.android.gms.common.ConnectionResult;
......@@ -68,6 +74,7 @@ import java.util.Calendar;
import java.util.List;
import java.util.Locale;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public class JoggingActivity extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
......@@ -108,6 +115,9 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
private TextView infoJoggingEnd;
private Button mButton;
private String startTime;
SensorManager sensorManager;
Sensor stepSensor;
private double distance = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -251,6 +261,10 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
public void onLocationChanged(Location location) {
mMap.clear();
distance += PositionUtils.distance(mLastKnownLocation.getLatitude(),
mLastKnownLocation.getLongitude(),
location.getLatitude(),
location.getLongitude());
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
......@@ -260,6 +274,7 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16
));
mLastKnownLocation = location;
}
@Override
......@@ -449,6 +464,7 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
mButton.setBackgroundColor(Color.parseColor("#FF0000"));
startTime = new SimpleDateFormat("HH:mm:ss")
.format(Calendar.getInstance().getTime());
distance = 0;
}
public void stopJogging(View view) {
......@@ -463,13 +479,12 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
mButton.setBackgroundColor(Color.parseColor("#4CFF00"));
// TODO : Distance itung berapa langkah
float distance = 1000;
Calendar c = Calendar.getInstance();
Jogging jogging = new Jogging(
new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()),
startTime,
new SimpleDateFormat("HH:mm:ss").format(c.getTime()),
distance,
(float) distance,
infoJoggingStart.getText().toString(),
infoJoggingEnd.getText().toString()
);
......@@ -483,7 +498,7 @@ public class JoggingActivity extends FragmentActivity implements OnMapReadyCallb
jogging.getDistance(),
jogging.getStartingPoint(),
jogging.getEndPoint()
);
).replaceAll(" ", "%20");
Log.d(TAG, url);
try {
String response = NetworkUtils.getResponseFromHttpUrl(
......
package com.example.leo.fitnessdiy.Utilities;
/**
* Created by Leo on 22/02/2018.
*/
public class PositionUtils {
public static double distance(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1))
* Math.sin(deg2rad(lat2))
+ Math.cos(deg2rad(lat1))
* Math.cos(deg2rad(lat2))
* Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
return (dist);
}
public static double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}
public static double rad2deg(double rad) {
return (rad * 180.0 / Math.PI);
}
}
......@@ -23,6 +23,8 @@ public class api {
public static final String JOGGING_HISTORY_URL = BASE_URL + "jogging_history.php?user=";
public static final String PLANK_HISTORY_URL = BASE_URL + "plank_history.php?user=";
public static final String PUSHUP_HISTORY_URL = BASE_URL + "pushup_history.php?user=";
public static final String SITUP_HISTORY_URL = BASE_URL + "situp_history.php?user=";
......
app/src/main/res/drawable/down_button.png

957 B

app/src/main/res/drawable/jogging_icon.png

2.98 KiB

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/tools"
tools:context="com.example.leo.fitnessdiy.HIstoryActivity"
android:orientation="vertical"
android:padding="16dp"
android:orientation="vertical">
tools:context="com.example.leo.fitnessdiy.HIstoryActivity">
<android.support.v7.widget.CardView
android:id="@+id/jogging"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/layout_jogging"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<ImageView
android:id="@+id/jogging_icon"
android:layout_width="48dp"
android:layout_height="40dp"
android:layout_marginRight="8dp"
android:contentDescription="TODO"
android:src="@drawable/jogging_icon"/>
<TextView
android:id="@+id/jogging_title"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/jogging_icon"
android:text="@string/jogging_history" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:src="@drawable/down_button"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="@+id/jogging_history"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.CardView
android:id="@+id/plank"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/layout_plank"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<ImageView
android:id="@+id/plank_icon"
android:layout_width="48dp"
android:layout_height="40dp"
android:layout_marginRight="8dp"
android:contentDescription="TODO"
android:src="@drawable/jogging_icon"/>
<TextView
android:id="@+id/plank_title"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_toEndOf="@id/plank_icon"
android:layout_toRightOf="@id/plank_icon"
android:text="@string/plank_history" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:src="@drawable/down_button"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv_history"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="@+id/plank_history"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
......@@ -39,14 +39,19 @@
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp">
<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_info_start"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_info_end"/>
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_info_start"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_info_end"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sport_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sport_date"
android:layout_below="@id/sport_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sport_start"
android:layout_below="@id/sport_date"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sport_end"
android:layout_below="@id/sport_start"/>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/jogging_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Title" />
<TextView
android:id="@+id/jogging_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat" />
<TextView
android:id="@+id/jogging_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="12dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14dp"
android:id="@+id/jogging_track"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/plank_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Title" />
<TextView
android:id="@+id/plank_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat" />
<TextView
android:id="@+id/plank_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="12dp" />
</LinearLayout>
\ No newline at end of file
......@@ -28,4 +28,6 @@
<string name="motivation_situp">Sit Up Challenge : Before and After</string>
<string name="situp_demo">How to do sit up properly</string>
<string name="situp_video">Sit Up Video</string>
<string name="jogging_history">Jogging History</string>
<string name="plank_history">Plank History</string>
</resources>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment