Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes #1

Open
wants to merge 5 commits into
base: 3da769dcf88257dc95bb7c89ff6472f38ad4d281
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/com/chrulri/droidtv/ChannelsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 ********************************************** //
// ************************************************************** //
Expand Down
18 changes: 18 additions & 0 deletions src/com/chrulri/droidtv/PreferencesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

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.utils.PreferenceUtils;
import com.chrulri.droidtv.utils.PreferenceUtils.DvbType;

public class PreferencesActivity extends PreferenceActivity {

Expand All @@ -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;
}
});
}
}
2 changes: 1 addition & 1 deletion src/com/chrulri/droidtv/ScanActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/com/chrulri/droidtv/StreamActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/com/chrulri/droidtv/utils/PreferenceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -38,13 +37,21 @@ 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})
*/
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) {
Expand Down
4 changes: 4 additions & 0 deletions src/com/chrulri/droidtv/utils/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/chrulri/droidtv/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down