Skip to content

Commit

Permalink
Update for newer gradle - 2.x beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Bailey committed Feb 28, 2016
1 parent cd2a96a commit 9a68cf9
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 120 deletions.
8 changes: 1 addition & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
buildToolsVersion '23.0.1'

defaultConfig {
applicationId "com.rbware.firetvreboot"
Expand All @@ -13,16 +13,10 @@ android {
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

}

dependencies {
Expand Down

This file was deleted.

89 changes: 9 additions & 80 deletions app/src/main/java/com/rbware/firetvreboot/Main.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,28 @@
package com.rbware.androiddatetime;
package com.rbware.firetvreboot;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.Date;


public class Main extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Run Root Command to set date/time
new RequestTask().execute("http://www.timeapi.org/cdt/now"); // CDT
}

private class RequestTask extends AsyncTask<String, String, String> {

@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);

// Parse
String properFormat = getSuFormat(result);

// Set date properly using SU
// adb shell 'su 0 date -s 20140825.134241'
String suCommand = "su 0 date -s " + properFormat;
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("date -s " + properFormat + "; \n");
} catch (Exception ex) {
Log.i("Settings", "Could not reboot", ex);
}

// Quit everything
Toast.makeText(Main.this, "Date and Time Updated", Toast.LENGTH_SHORT).show();
Main.this.finish();
}

private String getSuFormat(String input){
String output = "";
// 2014-08-25T14:11:34-05:00
output = input.substring(0, input.indexOf("T"));
output = output.replace("-", "");
output += ".";
output += input.substring(input.indexOf("T") + 1, input.lastIndexOf("-"));
output = output.replace(":", "");
}

@Override
protected void onResume() {
super.onResume();

return output;
try {
Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot now"});
} catch (IOException e){
Toast.makeText(this, "Could not reboot your device", Toast.LENGTH_SHORT).show();
}
}
}
5 changes: 0 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Main">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>
8 changes: 0 additions & 8 deletions app/src/main/res/menu/main.xml

This file was deleted.

4 changes: 1 addition & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">AndroidDateTime</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="app_name">FireTV Reboot</string>

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Sun Feb 28 10:23:25 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
2 changes: 1 addition & 1 deletion local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Sat May 23 12:16:26 CDT 2015
#Sun Feb 28 10:18:06 CST 2016
sdk.dir=/Users/ryan/Development/Android/sdk

0 comments on commit 9a68cf9

Please sign in to comment.