From e1be96be1d6e4d52d58fb784ddcff79db205f029 Mon Sep 17 00:00:00 2001 From: rizkihalasan <13515095@std.stei.itb.ac.id> Date: Fri, 23 Feb 2018 14:13:08 +0700 Subject: [PATCH] integrasi history plank --- .idea/modules.xml | 3 +- .../example/leo/fitnessdiy/PlankActivity.java | 60 ++++++++++++++++++- .../example/leo/fitnessdiy/routes/api.java | 2 + gradle.properties | 6 +- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index bb30654..e7f8ce2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,10 @@ <project version="4"> <component name="ProjectModuleManager"> <modules> + <module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" /> <module fileurl="file://F:\informatika\pbd\fitness\android.iml" filepath="F:\informatika\pbd\fitness\android.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> - <module fileurl="file://$PROJECT_DIR$/fitness.iml" filepath="$PROJECT_DIR$/fitness.iml" /> + <module fileurl="file://D:\tugas\sem6\pbd\tubes\android\fitness.iml" filepath="D:\tugas\sem6\pbd\tubes\android\fitness.iml" /> <module fileurl="file://D:\Semester 6\PBD\Tugas Besar\android\fitness.iml" filepath="D:\Semester 6\PBD\Tugas Besar\android\fitness.iml" /> </modules> </component> diff --git a/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java index fd56f20..cd4adc4 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.CountDownTimer; +import android.os.StrictMode; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; @@ -20,33 +21,58 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.Scanner; public class PlankActivity extends AppCompatActivity { private String LOG_TAG = "TES PLANK ACTIVITY"; String sharedPrefFile = "com.example.leo.fitnessdiy"; + private String user; + private String plank_date; + private String plank_time_start; + private String plank_time_end; + private String plank_duration; + private SharedPreferences mPreferences; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_plank); - SharedPreferences mPreferences; - final String BACKGROUND_KEY = "background"; mPreferences = getSharedPreferences(sharedPrefFile, MODE_PRIVATE); int background = mPreferences.getInt(BACKGROUND_KEY, R.drawable.green_theme); getWindow().getDecorView().setBackground(getResources().getDrawable(background)); + + SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); + Date date = new Date(); + + plank_date = formatDate.format(date); + Log.d(LOG_TAG, plank_date); + + plank_time_start = formatTime.format(date); + Log.d(LOG_TAG, plank_time_start); } public int setCountTime(String level){ if(level.equals("begineer")){ + plank_duration = ""+60; return 60000; } else if(level.equals("intermediate")){ + plank_duration = ""+120; return 120000; } else { + plank_duration = ""+180; return 180000; } } @@ -74,11 +100,41 @@ public class PlankActivity extends AppCompatActivity { @Override public void onFinish() { countText.setText("BERHASIL"); + + SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); + plank_time_end = formatTime.format(new Date()); + Log.d(LOG_TAG, plank_time_end); + String user = Integer.toString(mPreferences.getInt(UsersSharedPreferences.ID_USERS, -999)); + addThePlankHistory(user, plank_date, plank_time_start, plank_time_end, plank_duration); } }.start(); } + public void addThePlankHistory(String user, String plank_date, String plank_time_start, + String plank_time_end, String plank_duration){ + String urlstring = api.ADD_PLANK_HISTORY_URL+"user="+user+"&plank_date="+plank_date+"&plank_time_start="+plank_time_start+ + "&plank_time_end="+plank_time_end+"&plank_duration="+plank_duration; + if (android.os.Build.VERSION.SDK_INT > 9) { + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + } + try{ + URL url = new URL(urlstring); + HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); + + try{ + InputStream in = urlConnection.getInputStream(); + Scanner scanner = new Scanner(in); + } finally { + urlConnection.disconnect(); + } + } catch (MalformedURLException e){ + e.printStackTrace(); + }catch (IOException e) { + e.printStackTrace(); + } + } public void openVideo(View view) { String url = (String)view.getTag(); diff --git a/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java b/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java index f1d5dbf..59e9ef2 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java @@ -30,4 +30,6 @@ public class api { public static final String SITUP_HISTORY_URL = BASE_URL + "situp_history.php?user="; public static final String EDIT_LEVEL_URL = BASE_URL + "edit_level.php?"; + + public static final String ADD_PLANK_HISTORY_URL = BASE_URL + "add_plank_history.php?"; } diff --git a/gradle.properties b/gradle.properties index 028b47c..7ef7bae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,8 +12,4 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -#Fri Feb 23 11:16:21 GMT+07:00 2018 -systemProp.http.proxyPassword=02414056 -systemProp.http.proxyHost=cache.itb.ac.id -systemProp.http.proxyUser=leo16515325 -systemProp.http.proxyPort=8080 +#Fri Feb 23 11:52:54 ICT 2018 -- GitLab