Added option to auto-enable wifi on start.
This commit is contained in:
parent
e90039e7e8
commit
c4317782e4
7 changed files with 84 additions and 41 deletions
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dont_show_again"
|
||||
android:text="@string/dont_show_dialog_again"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
8
res/values/arrays.xml
Normal file
8
res/values/arrays.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<array name="enable_wifi_values">
|
||||
<item>yes</item>
|
||||
<item>no</item>
|
||||
<item>ask</item>
|
||||
</array>
|
||||
</resources>
|
|
@ -27,9 +27,8 @@
|
|||
<string name="exit_renderer">Do you really want to exit the renderer?
|
||||
Playback will be stopped.</string>
|
||||
<string name="select_route">Please select a route</string>
|
||||
<string name="warning_wifi_not_connected">Wifi needs to be connected for playback</string>
|
||||
<string name="dont_show_dialog_again">"Do not show this dialog again"</string>
|
||||
<string name="warning">Warning</string>
|
||||
<string name="enable_wifi_dialog">Wifi needs to be connected for playback.
|
||||
Do you want to enable it now?</string>
|
||||
|
||||
<!-- Image alt text -->
|
||||
<string name="album_art">Album Art</string>
|
||||
|
@ -43,6 +42,16 @@
|
|||
<!-- Title for the SettingsActivity -->
|
||||
<string name="settings_title">Preferences</string>
|
||||
|
||||
<!-- Title for preference to enable wifi on start -->
|
||||
<string name="enable_wifi_title">Automatically enable Wifi on start</string>
|
||||
|
||||
<!-- Values for preference to auto-enable wifi on start -->
|
||||
<string-array name="enable_wifi_value_titles">
|
||||
<item>yes</item>
|
||||
<item>no</item>
|
||||
<item>ask</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Title for the pause playback on call preference -->
|
||||
<string name="incoming_phone_call_pause">Pause playback on incoming phone call</string>
|
||||
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ListPreference
|
||||
android:key="enable_wifi_on_start"
|
||||
android:title="@string/enable_wifi_title"
|
||||
android:entries="@array/enable_wifi_value_titles"
|
||||
android:entryValues="@array/enable_wifi_values"
|
||||
android:defaultValue="ask"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="incoming_phone_call_pause"
|
||||
android:title="@string/incoming_phone_call_pause"
|
||||
|
|
|
@ -32,11 +32,15 @@ import java.util.List;
|
|||
import org.teleal.cling.support.model.item.Item;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
@ -139,29 +143,28 @@ public class MainActivity extends ActionBarActivity {
|
|||
.setText(R.string.title_route)
|
||||
.setTabListener(tabListener));
|
||||
|
||||
ConnectivityManager connManager = (ConnectivityManager)
|
||||
getSystemService(CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
final SharedPreferences prefs = getSharedPreferences("preferences.db", 0);
|
||||
final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
if (!wifi.isWifiEnabled()){
|
||||
String value = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getString(PreferencesActivity.KEY_ENABLE_WIFI_ON_START, "ask");
|
||||
if (value.equals("yes")) {
|
||||
wifi.setWifiEnabled(true);
|
||||
}
|
||||
else if (value.equals("ask")) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.enable_wifi_dialog)
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
wifi.setWifiEnabled(true);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
if (!wifi.isConnected() && !prefs.getBoolean("wifi_skip_dialog", false)) {
|
||||
View checkBoxView = View.inflate(this, R.layout.dialog_wifi_disabled, null);
|
||||
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.dont_show_again);
|
||||
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
prefs.edit().putBoolean("wifi_skip_dialog", isChecked)
|
||||
.commit();
|
||||
}
|
||||
});
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setView(checkBoxView)
|
||||
.setTitle(R.string.warning_wifi_not_connected)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
|
|
@ -28,24 +28,33 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
package com.github.nutomic.controldlna.gui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.github.nutomic.controldlna.R;
|
||||
|
||||
public class PreferencesActivity extends PreferenceActivity {
|
||||
public class PreferencesActivity extends PreferenceActivity
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
public static final String KEY_ENABLE_WIFI_ON_START = "enable_wifi_on_start";
|
||||
public static final String KEY_INCOMING_PHONE_CALL_PAUSE = "incoming_phone_call_pause";
|
||||
private static final String KEY_CONTACT_DEV = "contact_dev";
|
||||
|
||||
private ListPreference mEnableWifiOnStart;
|
||||
private Preference mContactDev;
|
||||
|
||||
/**
|
||||
* Initializes preferences from xml.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -53,14 +62,21 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||
// There is currently no way to get ActionBar in PreferenceActivity on pre-honeycomb with
|
||||
// compatibility library, so we'll have to do a version check.
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
mEnableWifiOnStart = (ListPreference) screen.findPreference(KEY_ENABLE_WIFI_ON_START);
|
||||
mEnableWifiOnStart.setSummary(mEnableWifiOnStart.getEntry());
|
||||
mContactDev = screen.findPreference(KEY_CONTACT_DEV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates up from activity on ActionBar back click.
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -72,6 +88,9 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends mail intent on contact dev preference click.
|
||||
*/
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
|
||||
Preference preference) {
|
||||
|
@ -83,5 +102,14 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||
}
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates summary of list preference (from current item).
|
||||
*/
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(KEY_ENABLE_WIFI_ON_START)) {
|
||||
mEnableWifiOnStart.setSummary(mEnableWifiOnStart.getEntry());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,9 @@ public class RouteAdapter extends ArrayAdapter<RouteInfo> {
|
|||
* Replacement for addAll, which is not implemented on lower API levels.
|
||||
*/
|
||||
public void add(List<RouteInfo> routes) {
|
||||
for (RouteInfo r : routes)
|
||||
for (RouteInfo r : routes) {
|
||||
add(r);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue