From 691369ad8f66b5df5a314f742606a7bbefff18e4 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Fri, 20 Apr 2012 13:24:14 +0200 Subject: [PATCH 1/5] process kill method to stop process by exe path --- src/com/chrulri/droidtv/utils/ProcessUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/chrulri/droidtv/utils/ProcessUtils.java b/src/com/chrulri/droidtv/utils/ProcessUtils.java index 60259b3..9f67bb5 100644 --- a/src/com/chrulri/droidtv/utils/ProcessUtils.java +++ b/src/com/chrulri/droidtv/utils/ProcessUtils.java @@ -178,6 +178,10 @@ public static Process runBinary(Context ctx, int rawId, String[] envp, String... public static void killBinary(Context ctx, int rawId) throws IOException { File exe = getBinaryExecutableFile(ctx, rawId); String exePath = exe.getCanonicalPath(); + kill(exePath); + } + + public static void kill(String exePath) throws IOException { File[] procs = new File("/proc").listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { From 91f7262a07c9b0105c9a3226e1fe5efa13c7eff2 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Fri, 20 Apr 2012 14:08:58 +0200 Subject: [PATCH 2/5] store dvb type from PreferencesActivity --- .../chrulri/droidtv/PreferencesActivity.java | 18 ++++++++++++++++++ .../chrulri/droidtv/utils/PreferenceUtils.java | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/com/chrulri/droidtv/PreferencesActivity.java b/src/com/chrulri/droidtv/PreferencesActivity.java index d5e48e4..81533c2 100644 --- a/src/com/chrulri/droidtv/PreferencesActivity.java +++ b/src/com/chrulri/droidtv/PreferencesActivity.java @@ -20,10 +20,13 @@ import android.content.Intent; import android.os.Bundle; +import android.preference.ListPreference; import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; +import com.chrulri.droidtv.StreamActivity.DvbType; import com.chrulri.droidtv.utils.PreferenceUtils; public class PreferencesActivity extends PreferenceActivity { @@ -43,5 +46,20 @@ public boolean onPreferenceClick(Preference preference) { return true; } }); + ListPreference dvbtypesList = (ListPreference)findPreference(PreferenceUtils.KEY_DVBTYPE); + dvbtypesList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference arg0, Object arg1) { + PreferenceUtils.setDvbType(PreferencesActivity.this, Enum.valueOf(DvbType.class, (String)arg1)); + return false; + } + }); + dvbtypesList.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference arg0) { + ((ListPreference)arg0).setDefaultValue(PreferenceUtils.getDvbType(PreferencesActivity.this).name().toUpperCase()); + return false; + } + }); } } diff --git a/src/com/chrulri/droidtv/utils/PreferenceUtils.java b/src/com/chrulri/droidtv/utils/PreferenceUtils.java index d0b1a95..16cc2df 100644 --- a/src/com/chrulri/droidtv/utils/PreferenceUtils.java +++ b/src/com/chrulri/droidtv/utils/PreferenceUtils.java @@ -44,7 +44,11 @@ public static SharedPreferences get(Context ctx) { */ public static DvbType getDvbType(Context ctx) { String dvbType = get(ctx).getString(KEY_DVBTYPE, null); - return Enum.valueOf(DvbType.class, dvbType); + return Enum.valueOf(DvbType.class, dvbType.toUpperCase()); + } + + public static void setDvbType(Context ctx, DvbType dvbType) { + get(ctx).edit().putString(KEY_DVBTYPE, dvbType.name().toUpperCase()); } public static void openSettings(Context context) { From 036c935d89207cae0b8e50b9eaf73142640a1c87 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Fri, 20 Apr 2012 14:17:38 +0200 Subject: [PATCH 3/5] Add rescan channels and drop channel to options menu --- src/com/chrulri/droidtv/ChannelsActivity.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/com/chrulri/droidtv/ChannelsActivity.java b/src/com/chrulri/droidtv/ChannelsActivity.java index be41d72..b4bec48 100644 --- a/src/com/chrulri/droidtv/ChannelsActivity.java +++ b/src/com/chrulri/droidtv/ChannelsActivity.java @@ -24,6 +24,8 @@ import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -100,6 +102,10 @@ public void onItemClick(AdapterView parent, View view, int position, }); // start + setupChannelList(); + } + + private void setupChannelList() { loadChannelLists(); setChannelList(null); if (mSpinner.getAdapter().getCount() == 0) { @@ -116,6 +122,31 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { return super.onKeyDown(keyCode, event); } + private static final int MENU_RESCAN = 1; + private static final int MENU_DROP = 2; + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add(0, MENU_RESCAN, 0, "Rescan Channels"); + menu.add(0, MENU_DROP, 0, "Drop Channel"); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int itemid = item.getItemId(); + if (itemid == MENU_RESCAN) { + PreferenceUtils.openSettings(this); + } else if (itemid == MENU_DROP) { + File channelfile = Utils.getConfigsFile(this, (String)mSpinner.getSelectedItem()); + if (channelfile.exists()) channelfile.delete(); + setupChannelList(); + } else { + return super.onOptionsItemSelected(item); + } + return false; + } + // ************************************************************** // // * CHANNEL UTILS ********************************************** // // ************************************************************** // From 407da645211da9ca16ac8d01dafd4948667da418 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Fri, 20 Apr 2012 14:19:30 +0200 Subject: [PATCH 4/5] change the inputstream charset to ISO-8859-2 --- src/com/chrulri/droidtv/utils/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/chrulri/droidtv/utils/StringUtils.java b/src/com/chrulri/droidtv/utils/StringUtils.java index 401de35..107d2e7 100644 --- a/src/com/chrulri/droidtv/utils/StringUtils.java +++ b/src/com/chrulri/droidtv/utils/StringUtils.java @@ -41,7 +41,7 @@ public static String readAll(InputStream in) throws IOException { Writer out = new StringWriter(); char[] buf = new char[BUFFER_SIZE]; int todo = in.available(); - Reader reader = new InputStreamReader(in); + Reader reader = new InputStreamReader(in, "ISO-8859-2"); int len; if (todo == 0) { // nop From aaa0cd0a840c9d7dcf1136912ed1ff90e89679d1 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Fri, 20 Apr 2012 23:09:00 +0200 Subject: [PATCH 5/5] move DvbType enum to PreferenceUtils class --- src/com/chrulri/droidtv/PreferencesActivity.java | 2 +- src/com/chrulri/droidtv/ScanActivity.java | 2 +- src/com/chrulri/droidtv/StreamActivity.java | 4 ---- src/com/chrulri/droidtv/utils/PreferenceUtils.java | 5 ++++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/com/chrulri/droidtv/PreferencesActivity.java b/src/com/chrulri/droidtv/PreferencesActivity.java index 81533c2..23d6752 100644 --- a/src/com/chrulri/droidtv/PreferencesActivity.java +++ b/src/com/chrulri/droidtv/PreferencesActivity.java @@ -26,8 +26,8 @@ import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; -import com.chrulri.droidtv.StreamActivity.DvbType; import com.chrulri.droidtv.utils.PreferenceUtils; +import com.chrulri.droidtv.utils.PreferenceUtils.DvbType; public class PreferencesActivity extends PreferenceActivity { diff --git a/src/com/chrulri/droidtv/ScanActivity.java b/src/com/chrulri/droidtv/ScanActivity.java index 4d82c79..cf2cc18 100644 --- a/src/com/chrulri/droidtv/ScanActivity.java +++ b/src/com/chrulri/droidtv/ScanActivity.java @@ -35,9 +35,9 @@ import android.widget.TextView; import android.widget.Toast; -import com.chrulri.droidtv.StreamActivity.DvbType; import com.chrulri.droidtv.utils.ErrorUtils; import com.chrulri.droidtv.utils.PreferenceUtils; +import com.chrulri.droidtv.utils.PreferenceUtils.DvbType; import com.chrulri.droidtv.utils.ProcessUtils; import com.chrulri.droidtv.utils.StringUtils; import com.chrulri.droidtv.utils.Utils; diff --git a/src/com/chrulri/droidtv/StreamActivity.java b/src/com/chrulri/droidtv/StreamActivity.java index 179d3d1..c7e792e 100644 --- a/src/com/chrulri/droidtv/StreamActivity.java +++ b/src/com/chrulri/droidtv/StreamActivity.java @@ -72,10 +72,6 @@ public class StreamActivity extends Activity { public static final String EXTRA_CHANNELCONFIG = "channelconfig"; - public enum DvbType { - ATSC, DVBT, DVBC, DVBS - } - public class FrontendStatus { public static final int HAS_SIGNAL = 0x001; public static final int HAS_CARRIER = 0x02; diff --git a/src/com/chrulri/droidtv/utils/PreferenceUtils.java b/src/com/chrulri/droidtv/utils/PreferenceUtils.java index 16cc2df..c074ba5 100644 --- a/src/com/chrulri/droidtv/utils/PreferenceUtils.java +++ b/src/com/chrulri/droidtv/utils/PreferenceUtils.java @@ -24,7 +24,6 @@ import android.preference.PreferenceManager; import com.chrulri.droidtv.PreferencesActivity; -import com.chrulri.droidtv.StreamActivity.DvbType; public final class PreferenceUtils { static final String TAG = PreferenceUtils.class.getName(); @@ -38,6 +37,10 @@ public static SharedPreferences get(Context ctx) { .getApplicationContext()); } + public enum DvbType { + ATSC, DVBT, DVBC, DVBS + } + /*** * @return read dvbType from preferences or return default ( * {@link DvbTuner.TYPE_DVBT})