diff --git a/.gradle/1.10/taskArtifacts/cache.properties.lock b/.gradle/1.10/taskArtifacts/cache.properties.lock index da38b19..5eef7c3 100644 Binary files a/.gradle/1.10/taskArtifacts/cache.properties.lock and b/.gradle/1.10/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/1.10/taskArtifacts/fileHashes.bin b/.gradle/1.10/taskArtifacts/fileHashes.bin index 70f0d94..2d2e688 100644 Binary files a/.gradle/1.10/taskArtifacts/fileHashes.bin and b/.gradle/1.10/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/1.10/taskArtifacts/fileSnapshots.bin b/.gradle/1.10/taskArtifacts/fileSnapshots.bin index 01da2bc..dbce242 100644 Binary files a/.gradle/1.10/taskArtifacts/fileSnapshots.bin and b/.gradle/1.10/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/1.10/taskArtifacts/outputFileStates.bin b/.gradle/1.10/taskArtifacts/outputFileStates.bin index 495a07f..deba2d6 100644 Binary files a/.gradle/1.10/taskArtifacts/outputFileStates.bin and b/.gradle/1.10/taskArtifacts/outputFileStates.bin differ diff --git a/.gradle/1.10/taskArtifacts/taskArtifacts.bin b/.gradle/1.10/taskArtifacts/taskArtifacts.bin index 5d35cbf..60fa91f 100644 Binary files a/.gradle/1.10/taskArtifacts/taskArtifacts.bin and b/.gradle/1.10/taskArtifacts/taskArtifacts.bin differ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0bdd3e1..009cd58 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -104,35 +104,34 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -140,15 +139,15 @@ - - - + + + @@ -156,32 +155,28 @@ - - - - - + - - - - - + + + + + - + @@ -871,8 +866,8 @@ @@ -910,7 +905,6 @@ - @@ -1143,6 +1137,7 @@ + @@ -1199,6 +1194,19 @@ - - - - - - - - - - - @@ -1414,15 +1398,15 @@ - - - + + + @@ -1437,46 +1421,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1487,15 +1470,15 @@ - - - + + + @@ -1510,46 +1493,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1560,15 +1542,15 @@ - - - + + + @@ -1583,46 +1565,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1633,15 +1614,15 @@ - - - + + + @@ -1656,46 +1637,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1706,61 +1686,60 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1771,61 +1750,60 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1836,61 +1814,60 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1901,61 +1878,60 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -1966,61 +1942,60 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -2031,15 +2006,15 @@ - - - + + + @@ -2057,13 +2032,10 @@ - - - - - - - + + + + @@ -2072,11 +2044,15 @@ - - - - - + + + + + + + + + @@ -2089,55 +2065,57 @@ - - - - - + + + + + - - - - + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ir/src/main/AndroidManifest.xml b/ir/src/main/AndroidManifest.xml index 12407d0..0a98ff5 100644 --- a/ir/src/main/AndroidManifest.xml +++ b/ir/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - diff --git a/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java b/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java index 46975e0..93e2e7a 100644 --- a/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java +++ b/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java @@ -5,9 +5,11 @@ import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.graphics.Color; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; @@ -74,33 +76,72 @@ public void run() { }).start(); prepIRKeys(); prepItemBrandArray(); - cur_ver = "1.5.2"; - /*Timer t = new Timer(); - t.schedule(new TimerTask() { - @Override + cur_ver = "1.5.3"; + Thread thread = new Thread() { public void run() { - File f = new File(irpath + brand + "/" + item + "/disable.ini"); - prepItemBrandArray(); - if (f.exists()) { - try { - FileInputStream is = new FileInputStream(f); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - String line = null; - while ((line = reader.readLine()) != null) { - int id = getResources().getIdentifier(line, "id", null); - button = ((Button) findViewById(id)); - button.setEnabled(false); + Log.i("SonyIRRemote", "new Thread()"); + File f; + while (true) { + f = new File(irpath + brand + "/" + item + "/disable.ini"); + /*runOnUiThread(new Runnable() { + @Override + public void run() { + prepItemBrandArray(); } - reader.close(); - //String ret = convertStreamToString(is); - is.close(); - //Toast.makeText(this, ret, Toast.LENGTH_SHORT).show(); + });*/ + if (f.exists() && wrt == false) { + try { + FileInputStream is = new FileInputStream(f); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line = null; + while ((line = reader.readLine()) != null) { + final String finalLine = line; + runOnUiThread(new Runnable() { + @Override + public void run() { + int id = getResources().getIdentifier(finalLine, "id", "com.sssemil.sonyirremoute.ir"); + //Log.i("SonyIRRemote", "name: " + finalLine + " id: " + id ); + Button button = ((Button) findViewById(id)); + try { + button.setEnabled(false); + } catch (Exception ex) { + } + } + }); + } + reader.close(); + //String ret = convertStreamToString(is); + is.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + for(int i = 0; i<25; i++) + { + final String btn = "button" + i; + runOnUiThread(new Runnable() { + @Override + public void run() { + int id = getResources().getIdentifier(btn, "id", "com.sssemil.sonyirremoute.ir"); + //Log.i("SonyIRRemote", "name: " + finalLine + " id: " + id ); + Button button = ((Button) findViewById(id)); + try { + button.setEnabled(true); + } catch (Exception ex) { + } + } + }); + } + } + try { + Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); } } } - }, 500);*/ + }; + thread.start(); } static { @@ -115,10 +156,43 @@ public void run() { public native int sendKey(String filename); + public void errorT(String msg) + { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + private void learnKeyBool(final String filename) { new Thread(new Runnable() { public void run() { - learnKey(filename); + state = learnKey(filename); + Log.i("stateLearn", String.valueOf(state)); + if(state < 0) { + runOnUiThread(new Runnable() { + @Override + public void run() { + errorT("Failed! - learnKey " + filename); + } + }); + } + } + }).start(); + } + + public int state = 0; + + private void sendKeyBool(final String filename) { + new Thread(new Runnable() { + public void run() { + state = sendKey(filename); + Log.i("stateSend", String.valueOf(state)); + if(state < 0) { + runOnUiThread(new Runnable() { + @Override + public void run() { + errorT("Failed! - sendKey " + filename); + } + }); + } } }).start(); } @@ -147,7 +221,7 @@ public void prepIRKeys() { } } - Button button; + Spinner spinner, spinner2, spinner6; private ArrayList localArrayList1, localArrayList2; @@ -157,26 +231,32 @@ public void prepItemBrandArray() { localArrayList1 = new ArrayList(); spinner2 = ((Spinner) findViewById(R.id.spinner)); localArrayList2 = new ArrayList(); + boolean edited = false; + for (File localFile1 : new File(this.irpath).listFiles()) { if (localFile1.isDirectory()) { if (!localArrayList1.contains(localFile1.getName())) { localArrayList1.add(localFile1.getName()); + edited = true; } for (File localFile2 : new File(localFile1.getPath() + "/").listFiles()) if (localFile2.isDirectory()) { if (!localArrayList2.contains(localFile2.getName())) { localArrayList2.add(localFile2.getName()); + edited = true; } } } - ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList1); - dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner2.setAdapter(dataAdapter); + if (edited == true) { + ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList1); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter(dataAdapter); - ArrayAdapter dataAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList2); - dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(dataAdapter2); + ArrayAdapter dataAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList2); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(dataAdapter2); + } } } @@ -188,11 +268,14 @@ public void onAddDeviceClick(View paramView) { itemN = ((EditText) findViewById(R.id.editText)); brandN = ((EditText) findViewById(R.id.editText2)); File localFile1 = new File(irpath + brandN.getText().toString()); - if (!localFile1.isDirectory()) + if (!localFile1.isDirectory()) { localFile1.mkdirs(); + } File localFile2 = new File(irpath + brandN.getText().toString() + "/" + itemN.getText().toString()); - if (!localFile2.isDirectory()) + if (!localFile2.isDirectory()) { localFile2.mkdirs(); + } + prepItemBrandArray(); //Toast.makeText(this, this.irpath + this.brandN.getText().toString() + "/" + this.itemN.getText().toString(), 0).show(); } catch (Exception ex) { @@ -266,8 +349,6 @@ public boolean onOptionsItemSelected(MenuItem item) { dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner6.setAdapter(dataAdapter); - Toast.makeText(this, ar.toString(), Toast.LENGTH_SHORT).show(); - prepItemBrandArray(); return true; @@ -401,7 +482,7 @@ public void onPowerClick(View view) { Toast.makeText(this, "Power" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/power.bin"); + sendKeyBool(irpath + brand + "/" + item + "/power.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -423,7 +504,7 @@ public void onChanelPlClick(View view) { Toast.makeText(this, "ChanelPl" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/chanelPl.bin"); + sendKeyBool(irpath + brand + "/" + item + "/chanelPl.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -444,7 +525,7 @@ public void onChanelMnSonClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "ChanelMn" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/chanelMn.bin"); + sendKeyBool(irpath + brand + "/" + item + "/chanelMn.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -464,7 +545,7 @@ public void onVolumePlClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "VolumePl" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/volPl.bin"); + sendKeyBool(irpath + brand + "/" + item + "/volPl.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -484,7 +565,7 @@ public void onVolumeMnClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "VolumeMn" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/volMn.bin"); + sendKeyBool(irpath + brand + "/" + item + "/volMn.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -504,7 +585,7 @@ public void on1Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "1" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/1.bin"); + sendKeyBool(irpath + brand + "/" + item + "/1.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -524,7 +605,7 @@ public void on2Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "2" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/2.bin"); + sendKeyBool(irpath + brand + "/" + item + "/2.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -544,7 +625,7 @@ public void on3Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "3" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/3.bin"); + sendKeyBool(irpath + brand + "/" + item + "/3.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -564,7 +645,7 @@ public void on4Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "4" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/4.bin"); + sendKeyBool(irpath + brand + "/" + item + "/4.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -584,7 +665,7 @@ public void on5Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "5" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/5.bin"); + sendKeyBool(irpath + brand + "/" + item + "/5.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -604,7 +685,7 @@ public void on6Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "6" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/6.bin"); + sendKeyBool(irpath + brand + "/" + item + "/6.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -624,7 +705,7 @@ public void on7Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "7" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/7.bin"); + sendKeyBool(irpath + brand + "/" + item + "/7.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -644,7 +725,7 @@ public void on8Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "8" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/8.bin"); + sendKeyBool(irpath + brand + "/" + item + "/8.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -664,7 +745,7 @@ public void on9Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "9" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/9.bin"); + sendKeyBool(irpath + brand + "/" + item + "/9.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -684,7 +765,7 @@ public void on0Click(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "0" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/0.bin"); + sendKeyBool(irpath + brand + "/" + item + "/0.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -704,7 +785,7 @@ public void onUpClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "up" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/up.bin"); + sendKeyBool(irpath + brand + "/" + item + "/up.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -724,7 +805,7 @@ public void onDownClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "down" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/down.bin"); + sendKeyBool(irpath + brand + "/" + item + "/down.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -744,7 +825,7 @@ public void onLeftClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "left" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/left.bin"); + sendKeyBool(irpath + brand + "/" + item + "/left.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -764,7 +845,7 @@ public void onRightClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "right" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/right.bin"); + sendKeyBool(irpath + brand + "/" + item + "/right.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -784,7 +865,7 @@ public void onEnterClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "enter" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/enter.bin"); + sendKeyBool(irpath + brand + "/" + item + "/enter.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -805,7 +886,7 @@ public void onMuteClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "mute" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/mute.bin"); + sendKeyBool(irpath + brand + "/" + item + "/mute.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -826,7 +907,7 @@ public void onHomeClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "home" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/home.bin"); + sendKeyBool(irpath + brand + "/" + item + "/home.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -847,7 +928,7 @@ public void onInputClick(View view) { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "input" + brand, Toast.LENGTH_SHORT).show(); - sendKey(irpath + brand + "/" + item + "/input.bin"); + sendKeyBool(irpath + brand + "/" + item + "/input.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -928,7 +1009,6 @@ public static String normalisedVersion(String version, String sep, int maxWidth) } - class DownloadApp extends AsyncTask { private Context context; @@ -981,14 +1061,20 @@ protected String doInBackground(String... sUrl) { output.write(data, 0, count); } Log.v("DownloadApp", "Done!"); - Log.v("pm", "pm install /sdcard/upd.apk"); + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.fromFile(new File("/sdcard/upd.apk")), "application/vnd.android.package-archive"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + + /*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(); @@ -1051,13 +1137,15 @@ 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); diff --git a/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java~ b/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java~ index 50cb1c0..cccf371 100644 --- a/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java~ +++ b/ir/src/main/java/com/sssemil/sonyirremoute/ir/ir.java~ @@ -5,17 +5,22 @@ import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.graphics.Color; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.os.PowerManager; +import android.text.Html; import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; @@ -23,14 +28,30 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.entity.BufferedHttpEntity; +import org.apache.http.impl.client.DefaultHttpClient; + +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; 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 @@ -47,6 +68,7 @@ public class ir extends Activity { fixPermissionsForIr(); spinner = ((Spinner) findViewById(R.id.spinner2)); spinner2 = ((Spinner) findViewById(R.id.spinner)); + spinner6 = ((Spinner) findViewById(R.id.spinner6)); new Thread(new Runnable() { public void run() { startIR(); @@ -54,13 +76,72 @@ public class ir extends Activity { }).start(); prepIRKeys(); prepItemBrandArray(); - //SharedPreferences irPrefs = getSharedPreferences("irPrefs", MODE_PRIVATE); - //irpath = irPrefs.getString("irpath", ""); - /*new Thread(new Runnable() { + cur_ver = "1.5.3"; + Thread thread = new Thread() { public void run() { - IrHelper.getInstance().startIrNative(); + Log.i("SonyIRRemote", "new Thread()"); + File f; + while (true) { + f = new File(irpath + brand + "/" + item + "/disable.ini"); + /*runOnUiThread(new Runnable() { + @Override + public void run() { + prepItemBrandArray(); + } + });*/ + if (f.exists() && wrt == false) { + try { + FileInputStream is = new FileInputStream(f); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line = null; + while ((line = reader.readLine()) != null) { + final String finalLine = line; + runOnUiThread(new Runnable() { + @Override + public void run() { + int id = getResources().getIdentifier(finalLine, "id", "com.sssemil.sonyirremoute.ir"); + //Log.i("SonyIRRemote", "name: " + finalLine + " id: " + id ); + Button button = ((Button) findViewById(id)); + try { + button.setEnabled(false); + } catch (Exception ex) { + } + } + }); + } + reader.close(); + //String ret = convertStreamToString(is); + is.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + for(int i = 0; i<25; i++) + { + final String btn = "button" + i; + runOnUiThread(new Runnable() { + @Override + public void run() { + int id = getResources().getIdentifier(btn, "id", "com.sssemil.sonyirremoute.ir"); + //Log.i("SonyIRRemote", "name: " + finalLine + " id: " + id ); + Button button = ((Button) findViewById(id)); + try { + button.setEnabled(true); + } catch (Exception ex) { + } + } + }); + } + } + try { + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } + } } - }).start();*/ + }; + thread.start(); } static { @@ -75,20 +156,48 @@ public class ir extends Activity { public native int sendKey(String filename); + private void learnKeyBool(final String filename) { + new Thread(new Runnable() { + public void run() { + learnKey(filename); + } + }).start(); + } + + private void sendKeyBool(final String filename) { + new Thread(new Runnable() { + public void run() { + sendKey(filename); + } + }).start(); + } public String irpath = "/data/data/com.sssemil.sonyirremoute.ir/ir/"; + public static String convertStreamToString(InputStream is) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + StringBuilder sb = new StringBuilder(); + String line = null; + while ((line = reader.readLine()) != null) { + sb.append(line).append("\n"); + } + reader.close(); + return sb.toString(); + } + + ProgressDialog progress; + public void prepIRKeys() { File f = new File(irpath); if (!f.isDirectory()) { f.mkdirs(); - DownloadALL(); - UnzipALL(); + //DownloadALL(); + //UnzipALL(); } } - Spinner spinner; - Spinner spinner2; + + Spinner spinner, spinner2, spinner6; private ArrayList localArrayList1, localArrayList2; @@ -97,34 +206,35 @@ public class ir extends Activity { localArrayList1 = new ArrayList(); spinner2 = ((Spinner) findViewById(R.id.spinner)); localArrayList2 = new ArrayList(); + boolean edited = false; + for (File localFile1 : new File(this.irpath).listFiles()) { if (localFile1.isDirectory()) { if (!localArrayList1.contains(localFile1.getName())) { localArrayList1.add(localFile1.getName()); + edited = true; } for (File localFile2 : new File(localFile1.getPath() + "/").listFiles()) if (localFile2.isDirectory()) { if (!localArrayList2.contains(localFile2.getName())) { localArrayList2.add(localFile2.getName()); + edited = true; } } } - ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList1); - dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner2.setAdapter(dataAdapter); + if (edited == true) { + ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList1); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter(dataAdapter); - ArrayAdapter dataAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList2); - dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(dataAdapter2); + ArrayAdapter dataAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList2); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(dataAdapter2); + } } } - public void onMainClick(View paramView) { - setContentView(R.layout.activity_ir); - } - - EditText brandN; EditText itemN; @@ -133,11 +243,14 @@ public class ir extends Activity { itemN = ((EditText) findViewById(R.id.editText)); brandN = ((EditText) findViewById(R.id.editText2)); File localFile1 = new File(irpath + brandN.getText().toString()); - if (!localFile1.isDirectory()) + if (!localFile1.isDirectory()) { localFile1.mkdirs(); + } File localFile2 = new File(irpath + brandN.getText().toString() + "/" + itemN.getText().toString()); - if (!localFile2.isDirectory()) + if (!localFile2.isDirectory()) { localFile2.mkdirs(); + } + prepItemBrandArray(); //Toast.makeText(this, this.irpath + this.brandN.getText().toString() + "/" + this.itemN.getText().toString(), 0).show(); } catch (Exception ex) { @@ -161,8 +274,8 @@ public class ir extends Activity { ArrayAdapter dataAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList2); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter2); + } catch (Exception ex) { } - catch (Exception ex){} } public static boolean fixPermissionsForIr() { @@ -201,6 +314,18 @@ public class ir extends Activity { int id = item.getItemId(); if (id == R.id.action_settings) { setContentView(R.layout.settings_ir); + + final GetAwItems getAwItems1 = new GetAwItems(ir.this); + getAwItems1.execute(); + + spinner6 = ((Spinner) findViewById(R.id.spinner6)); + + ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, ar); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner6.setAdapter(dataAdapter); + + prepItemBrandArray(); + return true; } else if (id == R.id.action_about) { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -213,6 +338,13 @@ public class ir extends Activity { TextView messageView = (TextView) dialog.findViewById(android.R.id.message); messageView.setGravity(Gravity.CENTER); return true; + } else if (id == R.id.action_exit) { + stopIR(); + System.exit(0); + return true; + } else if (id == R.id.action_update) { + update(); + return true; } return super.onOptionsItemSelected(item); } @@ -221,6 +353,13 @@ public class ir extends Activity { public String item; public boolean wrt = false; + @Override + public void onBackPressed() { + setContentView(R.layout.activity_ir); + prepItemBrandArray(); + //super.onBackPressed(); + } + public void onWrtClick(View view) { if (wrt) { wrt = false; @@ -245,6 +384,70 @@ public class ir extends Activity { } } + + public void onRemoveClick(View view) { + Spinner spinner = (Spinner) findViewById(R.id.spinner); + brand = spinner.getSelectedItem().toString(); + Spinner spinner2 = (Spinner) findViewById(R.id.spinner2); + item = spinner2.getSelectedItem().toString(); + + Toast.makeText(this, brand + "/" + item, Toast.LENGTH_SHORT).show(); + + String[] remove = {"rm", "-rf", irpath + brand + "/" + item}; + try { + Process p = Runtime.getRuntime().exec(remove); + Log.i("rm", "Waiting... " + irpath + brand + "/" + item); + p.waitFor(); + Log.i("rm", "Done! " + irpath + brand + "/" + item); + } catch (Exception e) { + Log.e("rm", "Failed! " + irpath + brand + "/" + item); + e.printStackTrace(); + } + + File directory = new File(irpath + brand); + File[] contents = directory.listFiles(); + if (contents.length == 0 && contents != null) { + String[] remove2 = {"rm", "-rf", irpath + brand}; + try { + Process p2 = Runtime.getRuntime().exec(remove2); + Log.i("rm", "Waiting... " + irpath + brand); + p2.waitFor(); + Log.i("rm", "Done! " + irpath + brand); + } catch (Exception e) { + Log.e("rm", "Failed! " + irpath + brand); + e.printStackTrace(); + } + } + + + /*File dir = new File(irpath + brand + "/" + item); + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i = 0; i < children.length; i++) { + new File(dir, children[i]).delete(); + } + } + + File dir2 = new File(irpath + brand ); + if (dir2.isDirectory()) { + String[] children = dir2.list(); + if(children.length < 1) + { + new File(dir2, children[0]).delete(); + } + }*/ + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Done!"); + builder.setMessage("Done removing " + brand + "/" + item + " files!"); + builder.setPositiveButton("OK", null); + AlertDialog dialog = builder.show(); + +// Must call show() prior to fetching text view + TextView messageView = (TextView) dialog.findViewById(android.R.id.message); + messageView.setGravity(Gravity.CENTER); + } + public void onPowerClick(View view) { if (!wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); @@ -253,8 +456,11 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "Power" + brand, Toast.LENGTH_SHORT).show(); + int state = 0; + state = sendKey(irpath + brand + "/" + item + "/power.bin"); + + Log.i("state", String.valueOf(state)); - sendKey(irpath + brand + "/" + item + "/power.bin"); } else if (wrt) { Spinner spinner = (Spinner) findViewById(R.id.spinner); brand = spinner.getSelectedItem().toString(); @@ -263,7 +469,7 @@ public class ir extends Activity { Toast.makeText(this, "Power" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/power.bin"); + learnKeyBool(irpath + brand + "/" + item + "/power.bin"); } } @@ -285,7 +491,7 @@ public class ir extends Activity { Toast.makeText(this, "ChanelPl" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/chanelPl.bin"); + learnKeyBool(irpath + brand + "/" + item + "/chanelPl.bin"); } } @@ -305,7 +511,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "ChanelMn" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/chanelMn.bin"); + learnKeyBool(irpath + brand + "/" + item + "/chanelMn.bin"); } } @@ -325,7 +531,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "VolumePl" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/volPl.bin"); + learnKeyBool(irpath + brand + "/" + item + "/volPl.bin"); } } @@ -345,7 +551,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "VolumeMn" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/volMn.bin"); + learnKeyBool(irpath + brand + "/" + item + "/volMn.bin"); } } @@ -365,7 +571,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "1" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/1.bin"); + learnKeyBool(irpath + brand + "/" + item + "/1.bin"); } } @@ -385,7 +591,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "2" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/2.bin"); + learnKeyBool(irpath + brand + "/" + item + "/2.bin"); } } @@ -405,7 +611,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "3" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/3.bin"); + learnKeyBool(irpath + brand + "/" + item + "/3.bin"); } } @@ -425,7 +631,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "4" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/4.bin"); + learnKeyBool(irpath + brand + "/" + item + "/4.bin"); } } @@ -445,7 +651,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "5" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/5.bin"); + learnKeyBool(irpath + brand + "/" + item + "/5.bin"); } } @@ -465,7 +671,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "6" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/6.bin"); + learnKeyBool(irpath + brand + "/" + item + "/6.bin"); } } @@ -485,7 +691,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "7" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/7.bin"); + learnKeyBool(irpath + brand + "/" + item + "/7.bin"); } } @@ -505,7 +711,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "8" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/8.bin"); + learnKeyBool(irpath + brand + "/" + item + "/8.bin"); } } @@ -525,7 +731,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "9" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/9.bin"); + learnKeyBool(irpath + brand + "/" + item + "/9.bin"); } } @@ -545,7 +751,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "0" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/0.bin"); + learnKeyBool(irpath + brand + "/" + item + "/0.bin"); } } @@ -565,7 +771,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "up" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/up.bin"); + learnKeyBool(irpath + brand + "/" + item + "/up.bin"); } } @@ -585,7 +791,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "down" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/down.bin"); + learnKeyBool(irpath + brand + "/" + item + "/down.bin"); } } @@ -605,7 +811,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "left" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/left.bin"); + learnKeyBool(irpath + brand + "/" + item + "/left.bin"); } } @@ -625,7 +831,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "right" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/right.bin"); + learnKeyBool(irpath + brand + "/" + item + "/right.bin"); } } @@ -645,7 +851,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "enter" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/enter.bin"); + learnKeyBool(irpath + brand + "/" + item + "/enter.bin"); } } @@ -666,7 +872,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "mute" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/mute.bin"); + learnKeyBool(irpath + brand + "/" + item + "/mute.bin"); } } @@ -687,7 +893,7 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "home" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/home.bin"); + learnKeyBool(irpath + brand + "/" + item + "/home.bin"); } } @@ -708,35 +914,43 @@ public class ir extends Activity { item = spinner2.getSelectedItem().toString(); Toast.makeText(this, "input" + brand + " LEARNING!", Toast.LENGTH_SHORT).show(); - learnKey(irpath + brand + "/" + item + "/input.bin"); + learnKeyBool(irpath + brand + "/" + item + "/input.bin"); } } public void UnzipALL() { - String zipFile = Environment.getExternalStorageDirectory() + "/ir.zip"; - String unzipLocation = irpath + "/"; + progress = ProgressDialog.show(this, "Please wait..", + "Extracting files...", true); + + new Thread(new Runnable() { + @Override + public void run() { + String zipFile = "/sdcard/sony-tv.zip"; + String unzipLocation = irpath; - Decompress d = new Decompress(zipFile, unzipLocation); - d.unzip(); + Decompress d = new Decompress(zipFile, unzipLocation); + d.unzip(); + progress.cancel(); + } + }).start(); } + ProgressDialog mProgressDialog; + public void DownloadALL() { /*final ProgressDialog mProgressDialog = ProgressDialog.show(ir.this, "Please wait ...", "Downloading keys ...", true); final DownloadTask downloadTask = new DownloadTask(ir.this); - downloadTask.execute("http://sssemil.or.gs/sony.zip");*/ - ProgressDialog mProgressDialog; + downloadTask.execute("http://sssemil.or.gs/sony-tv.zip");*/ -// instantiate it within the onCreate method mProgressDialog = new ProgressDialog(ir.this); mProgressDialog.setMessage("Downloading keys..."); mProgressDialog.setIndeterminate(true); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.setCancelable(true); -// execute this when the downloader must be fired final DownloadTask downloadTask = new DownloadTask(ir.this); - downloadTask.execute("http://sssemil.or.gs/sonyirremote/sony.zip"); + downloadTask.execute("http://sssemil.or.gs/sonyirremote/sony-tv.zip"); mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override @@ -746,7 +960,344 @@ public class ir extends Activity { }); } - private class DownloadTask extends AsyncTask { + public ArrayList ar = new ArrayList(); + 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 { + + 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!"); + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.fromFile(new File("/sdcard/upd.apk")), "application/vnd.android.package-archive"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + + /*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 { + + 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 { + + private Context context; + private PowerManager.WakeLock mWakeLock; + + DefaultHttpClient httpclient = new DefaultHttpClient(); + + public GetAwItems(Context context) { + this.context = context; + } + + protected String doInBackground(String... sUrl) { + try { + HttpGet httppost = new HttpGet("http://sssemil.or.gs/sonyirremote/files.txt"); + 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)); + + StringBuilder total = new StringBuilder(); + String line; + ar.clear(); + while ((line = r.readLine()) != null) { + total.append(line + "\n"); + ar.add(line); + } + + return total.toString(); + } catch (IOException ex) { + return null; + } + } + } + + /*public void prepItemBrandArray() { + spinner = ((Spinner) findViewById(R.id.spinner6)); + ArrayList localArrayList3 = new ArrayList(); + + localArrayList1.add(localFile1.getName()); + ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, localArrayList3); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter(dataAdapter); + }*/ + + public void onDownItemsClick(View view) { + spinner6 = ((Spinner) findViewById(R.id.spinner6)); + String test = spinner6.getSelectedItem().toString(); + String lastWord = test.substring(test.lastIndexOf(" ") + 1); + /*AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Test"); + builder.setMessage(lastWord); + builder.setPositiveButton("OK", null); + AlertDialog dialog = builder.show(); + +// Must call show() prior to fetching text view + TextView messageView = (TextView) dialog.findViewById(android.R.id.message); + messageView.setGravity(Gravity.CENTER);*/ + if (!lastWord.isEmpty()) { + mProgressDialog = new ProgressDialog(ir.this); + mProgressDialog.setMessage("Downloading keys..."); + mProgressDialog.setIndeterminate(true); + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mProgressDialog.setCancelable(true); + +// execute this when the downloader must be fired + final DownloadTask downloadTask = new DownloadTask(ir.this); + downloadTask.execute(lastWord); + /*mProgressDialog = ProgressDialog.show(this, "Please wait..", + "Extracting files...", true); + + final String fileName = lastWord.substring(lastWord.lastIndexOf("/")+1); + + new Thread(new Runnable() { + @Override + public void run() + { + String zipFile = "/sdcard/"+ fileName; + String unzipLocation = irpath; + + Decompress d = new Decompress(zipFile, unzipLocation); + d.unzip(); + mProgressDialog.cancel(); + } + }).start();*/ + + mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + downloadTask.cancel(true); + } + }); + } + } + + public void onGetAwItemsClick(View view) { + mProgressDialog = new ProgressDialog(ir.this); + mProgressDialog.setMessage("Getting list..."); + mProgressDialog.setIndeterminate(true); + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mProgressDialog.setCancelable(true); + +// execute this when the downloader must be fired + final GetAwItems getAwItems1 = new GetAwItems(ir.this); + getAwItems1.execute(); + + spinner6 = ((Spinner) findViewById(R.id.spinner6)); + + ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, ar); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner6.setAdapter(dataAdapter); + + Toast.makeText(this, ar.toString(), Toast.LENGTH_SHORT).show(); + + mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + getAwItems1.cancel(true); + } + }); + } + + class DownloadTask extends AsyncTask { private Context context; private PowerManager.WakeLock mWakeLock; @@ -760,7 +1311,11 @@ public class ir extends Activity { OutputStream output = null; HttpURLConnection connection = null; try { + Log.v("DownloadTask", "Starting... "); URL url = new URL(sUrl[0]); + String filePath = url.getFile(); + String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); + connection = (HttpURLConnection) url.openConnection(); connection.connect(); @@ -777,7 +1332,8 @@ public class ir extends Activity { // download the file input = connection.getInputStream(); - output = new FileOutputStream(irpath + "/sony.zip"); + output = new FileOutputStream("/sdcard/" + fileName); + Log.v("DownloadTask", "output " + "/sdcard/" + fileName); byte data[] = new byte[4096]; long total = 0; @@ -794,7 +1350,16 @@ public class ir extends Activity { publishProgress((int) (total * 100 / fileLength)); output.write(data, 0, count); } + Log.v("DownloadTask", "Done!"); + //---------Unzip-------- + String zipFile = "/sdcard/" + fileName; + String unzipLocation = irpath; + + Decompress d = new Decompress(zipFile, unzipLocation); + d.unzip(); + //---------------------- } catch (Exception e) { + Log.e("DownloadTask", e.getMessage()); return e.toString(); } finally { try { diff --git a/ir/src/main/res/layout/activity_ir.xml b/ir/src/main/res/layout/activity_ir.xml index c57494a..eef31cd 100644 --- a/ir/src/main/res/layout/activity_ir.xml +++ b/ir/src/main/res/layout/activity_ir.xml @@ -164,8 +164,8 @@ android:layout_alignParentTop="true" android:layout_toRightOf="@+id/button21" android:layout_above="@+id/button19" - android:layout_alignRight="@+id/button18" - android:layout_alignEnd="@+id/button18" /> + android:layout_alignParentRight="true" + android:layout_alignParentEnd="true" />