Skip to content

Commit

Permalink
v1.5.2 - added update button
Browse files Browse the repository at this point in the history
  • Loading branch information
sssemil committed Mar 19, 2014
1 parent 624b83c commit 1ddc5cc
Show file tree
Hide file tree
Showing 13 changed files with 711 additions and 603 deletions.
Binary file modified .gradle/1.10/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/1.10/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/1.10/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/1.10/taskArtifacts/outputFileStates.bin
Binary file not shown.
Binary file modified .gradle/1.10/taskArtifacts/taskArtifacts.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions .idea/dictionaries/emil.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,066 changes: 480 additions & 586 deletions .idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions ir/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest android:versionCode="1" android:versionName="1.5.2" xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sssemil.sonyirremoute.ir" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Expand All @@ -9,9 +9,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:versionCode="2"
android:versionName="1.5.1">
android:theme="@style/AppTheme">
<activity
android:name="com.sssemil.sonyirremoute.ir.ir"
android:label="@string/app_name" >
Expand Down
226 changes: 217 additions & 9 deletions ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
Expand Down Expand Up @@ -47,6 +48,8 @@
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;

/**
* Copyright (c) 2014 Emil Suleymanov
Expand All @@ -71,7 +74,7 @@ public void run() {
}).start();
prepIRKeys();
prepItemBrandArray();

cur_ver = "1.5.2";
/*Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
Expand Down Expand Up @@ -283,6 +286,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
stopIR();
System.exit(0);
return true;
} else if (id == R.id.action_update) {
update();
return true;
}
return super.onOptionsItemSelected(item);
}
Expand All @@ -292,8 +298,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public boolean wrt = false;

@Override
public void onBackPressed()
{
public void onBackPressed() {
setContentView(R.layout.activity_ir);
prepItemBrandArray();
//super.onBackPressed();
Expand Down Expand Up @@ -335,11 +340,11 @@ public void onRemoveClick(View view) {
String[] remove = {"rm", "-rf", irpath + brand + "/" + item};
try {
Process p = Runtime.getRuntime().exec(remove);
Log.i("rm","Waiting... " + irpath + brand + "/" + item);
Log.i("rm", "Waiting... " + irpath + brand + "/" + item);
p.waitFor();
Log.i("rm","Done! " + irpath + brand + "/" + item);
Log.i("rm", "Done! " + irpath + brand + "/" + item);
} catch (Exception e) {
Log.e("rm","Failed! " + irpath + brand + "/" + item);
Log.e("rm", "Failed! " + irpath + brand + "/" + item);
e.printStackTrace();
}

Expand All @@ -349,11 +354,11 @@ public void onRemoveClick(View view) {
String[] remove2 = {"rm", "-rf", irpath + brand};
try {
Process p2 = Runtime.getRuntime().exec(remove2);
Log.i("rm","Waiting... " + irpath + brand);
Log.i("rm", "Waiting... " + irpath + brand);
p2.waitFor();
Log.i("rm","Done! " + irpath + brand);
Log.i("rm", "Done! " + irpath + brand);
} catch (Exception e) {
Log.e("rm","Failed! " + irpath + brand);
Log.e("rm", "Failed! " + irpath + brand);
e.printStackTrace();
}
}
Expand Down Expand Up @@ -897,6 +902,209 @@ public void onCancel(DialogInterface dialog) {
}

public ArrayList<String> ar = new ArrayList<String>();
public String last_ver = "zirt";
public String cur_ver;

public String compare(String v1, String v2) {
String s1 = normalisedVersion(v1);
String s2 = normalisedVersion(v2);
int cmp = s1.compareTo(s2);
String cmpStr = cmp < 0 ? "<" : cmp > 0 ? ">" : "==";
//System.out.printf("'%s' %s '%s'%n", v1, cmpStr, v2);
return cmpStr;
}

public static String normalisedVersion(String version) {
return normalisedVersion(version, ".", 4);
}

public static String normalisedVersion(String version, String sep, int maxWidth) {
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(String.format("%" + maxWidth + 's', s));
}
return sb.toString();
}



class DownloadApp extends AsyncTask<String, Integer, String> {

private Context context;
private PowerManager.WakeLock mWakeLock;

public DownloadApp(Context context) {
this.context = context;
}

protected String doInBackground(String... sUrl) {
InputStream input = null;
OutputStream output = null;
HttpURLConnection connection = null;
try {
Log.v("DownloadApp", "Starting... ");
URL url = new URL(sUrl[0]);

connection = (HttpURLConnection) url.openConnection();
connection.connect();

// expect HTTP 200 OK, so we don't mistakenly save error report
// instead of the file
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage();
}

// this will be useful to display download percentage
// might be -1: server did not report the length
int fileLength = connection.getContentLength();

// download the file
input = connection.getInputStream();
output = new FileOutputStream("/sdcard/upd.apk");
Log.v("DownloadApp", "output " + "/sdcard/upd.apk");

byte data[] = new byte[4096];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
if (isCancelled()) {
input.close();
return null;
}
total += count;
// publishing the progress....
if (fileLength > 0) // only if total length is known
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
Log.v("DownloadApp", "Done!");
Log.v("pm", "pm install /sdcard/upd.apk");
String[] pm = {"pm", "install -r", "/sdcard/upd.apk"};
try {
Runtime.getRuntime().exec(pm);
Log.v("pm", "Done! pm install -r /sdcard/upd.apk");
} catch (IOException e) {
Log.e("pm", e.getMessage());
}
} catch (Exception e) {
Log.e("DownloadApp", e.getMessage());
return e.toString();
} finally {
try {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
}

if (connection != null)
connection.disconnect();
}
return null;
}
}

public void update() {
final GetLastVer getLastVer1 = new GetLastVer(ir.this);
try {
Toast.makeText(this, "last_ver : " + getLastVer1.execute().get() + " cur_ver : " + cur_ver, Toast.LENGTH_SHORT).show();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

String result = compare(cur_ver, last_ver);
boolean doUpdate = false;
Log.i("Compare", result);
if (result == ">") {
doUpdate = false;
} else if (result == "<") {
doUpdate = true;
} else if (result == "==") {
doUpdate = false;
}

if (doUpdate == true) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Update");
adb.setMessage("New version available!\n\nDo you want to update to a newer version?");
adb.setIcon(android.R.drawable.ic_dialog_alert);
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mProgressDialog = new ProgressDialog(ir.this);
mProgressDialog.setMessage("Downloading new version...");
mProgressDialog.setIndeterminate(true);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);

final DownloadApp downloadApp1 = new DownloadApp(ir.this);
downloadApp1.execute("http://sssemil.or.gs/sonyirremote/download.php?v=last");

mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
downloadApp1.cancel(true);
}
});
} });

adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

finish();
} });
adb.show();
} else if (doUpdate == false) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Update");
builder.setMessage("You already have the latest version installed!");
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.show();
}
}

class GetLastVer extends AsyncTask<String, Integer, String> {

private Context context;
private PowerManager.WakeLock mWakeLock;

DefaultHttpClient httpclient = new DefaultHttpClient();

public GetLastVer(Context context) {
this.context = context;
}

protected String doInBackground(String... sUrl) {
try {
Log.i("GetLastVer", "Starting with http://sssemil.or.gs/sonyirremote/last.php");
HttpGet httppost = new HttpGet("http://sssemil.or.gs/sonyirremote/last.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();

BufferedHttpEntity buf = new BufferedHttpEntity(ht);

InputStream is = buf.getContent();

BufferedReader r = new BufferedReader(new InputStreamReader(is));

String line;
last_ver = "";
while ((line = r.readLine()) != null) {
last_ver += line;
}
Log.i("GetLastVer", last_ver);
return last_ver;
} catch (IOException ex) {
Log.e("GetLastVer", ex.getMessage());
return null;
}
}
}

class GetAwItems extends AsyncTask<String, Integer, String> {

Expand Down
5 changes: 2 additions & 3 deletions ir/src/main/res/layout/activity_ir.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@
android:text="@string/mute"
android:id="@+id/button22"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button21"
android:layout_alignEnd="@+id/button21"
android:layout_toRightOf="@+id/button9"
android:onClick="onMuteClick" />
android:onClick="onMuteClick"
android:layout_toLeftOf="@+id/button17" />

<Button
android:layout_width="wrap_content"
Expand Down
5 changes: 5 additions & 0 deletions ir/src/main/res/menu/ir.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="97"
android:showAsAction="never" />

<item android:id="@+id/action_update"
android:title="@string/update"
android:orderInCategory="98"
android:showAsAction="never" />

Expand Down
3 changes: 2 additions & 1 deletion ir/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<string name="license3">Исходный код доступен на https://github.com/sssemil/SonyIRRemote .</string>
<string name="license4">Используется lib_sony_ir от BuzzBumbleBee (https://github.com/BuzzBumbleBee/lib_sony_ir).</string>

<string name="mute">Без.зв.</string>
<string name="mute">Зв.0</string>
<string name="input">ТВ</string>
<string name="home">Дом</string>

Expand All @@ -53,4 +53,5 @@
<string name="remove">Удалить</string>

<string name="exit">Выход</string>
<string name="update">Обновить</string>
</resources>
1 change: 1 addition & 0 deletions ir/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@
<string name="remove">Remove</string>

<string name="exit">Exit</string>
<string name="update">Update</string>
</resources>

0 comments on commit 1ddc5cc

Please sign in to comment.