This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void resetUi(){ | |
| runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { | |
| button.setVisibility(View.VISIBLE); | |
| webView.setVisibility(View.GONE); | |
| } | |
| }); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void findTotalWalkingDistance(JSONArray arrayOfRecords) { | |
| try { | |
| //Each record has activity_type and array of statistics. Traverse to activity_type = Walking | |
| for (int ii = 0; ii < arrayOfRecords.length(); ii++) { | |
| JSONObject statObject = (JSONObject) arrayOfRecords.get(ii); | |
| if ("Walking".equalsIgnoreCase(statObject.getString("activity_type"))) { | |
| //Each activity_type has array of stats, navigate to "Overall" statistic to find the total distance walked. | |
| JSONArray walkingStats = statObject.getJSONArray("stats"); | |
| for (int jj = 0; jj < walkingStats.length(); jj++) { | |
| JSONObject iWalkingStat = (JSONObject) walkingStats.get(jj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void getTotalDistance(String accessToken) { | |
| try { | |
| HttpClient client = new DefaultHttpClient(); | |
| HttpGet get = new HttpGet("http://api.runkeeper.com/records"); | |
| get.addHeader("Authorization", "Bearer " + accessToken); | |
| get.addHeader("Accept", "*/*"); | |
| HttpResponse response = client.execute(get); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void getAccessToken(String authCode) { | |
| String accessTokenUrl = "https://runkeeper.com/apps/token?grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s&redirect_uri=%s"; | |
| final String finalUrl = String.format(accessTokenUrl, authCode, CLIENT_ID, CLIENT_SECRET, CALLBACK_URL); | |
| Thread networkThread = new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| try { | |
| HttpClient client = new DefaultHttpClient(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void getAuthorizationCode() { | |
| String authorizationUrl = "https://runkeeper.com/apps/authorize?response_type=code&client_id=%s&redirect_uri=%s"; | |
| authorizationUrl = String.format(authorizationUrl, CLIENT_ID, CALLBACK_URL); | |
| webView.setWebViewClient(new WebViewClient() { | |
| @Override | |
| public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
| if (url.startsWith(CALLBACK_URL)) { | |
| final String authCode = Uri.parse(url).getQueryParameter("code"); | |
| webView.setVisibility(View.GONE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public void onClick(View v) { | |
| button.setVisibility(View.GONE); | |
| webView.setVisibility(View.VISIBLE); | |
| getAuthorizationCode(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private final static String CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
| private final static String CLIENT_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
| private final static String CALLBACK_URL = "com.example.runkeeperapi://RunKeeperIsCallingBack"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SuppressLint("SetJavaScriptEnabled") | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| //Force to login on every launch. | |
| CookieManager cookieManager = CookieManager.getInstance(); | |
| cookieManager.removeAllCookie(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:paddingBottom="@dimen/activity_vertical_margin" | |
| android:paddingLeft="@dimen/activity_horizontal_margin" | |
| android:paddingRight="@dimen/activity_horizontal_margin" | |
| android:paddingTop="@dimen/activity_vertical_margin" | |
| tools:context=".MainActivity" > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dir /a-d |