Changed wifi disabled warning dialog.
This commit is contained in:
parent
017c8a6411
commit
86ba981c3c
3 changed files with 29 additions and 39 deletions
13
res/layout/dialog_wifi_disabled.xml
Normal file
13
res/layout/dialog_wifi_disabled.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?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>
|
|
@ -28,6 +28,8 @@
|
||||||
Playback will be stopped.</string>
|
Playback will be stopped.</string>
|
||||||
<string name="select_route">Please select a route</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="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>
|
||||||
|
|
||||||
<!-- Image alt text -->
|
<!-- Image alt text -->
|
||||||
<string name="album_art">Album Art</string>
|
<string name="album_art">Album Art</string>
|
||||||
|
@ -36,8 +38,4 @@
|
||||||
<string name="route_description">DLNA Playback</string>
|
<string name="route_description">DLNA Playback</string>
|
||||||
<string name="upnp_route_provider_service">UPNP Route Provider Service</string>
|
<string name="upnp_route_provider_service">UPNP Route Provider Service</string>
|
||||||
|
|
||||||
<!-- Settings -->
|
|
||||||
<string name="auto_enable_wifi">Enable Wifi automatically on start</string>
|
|
||||||
<string name="dont_show_dialog_again">"Do not show this dialog again"</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -36,7 +36,6 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
@ -48,10 +47,10 @@ import android.support.v7.app.ActionBar.Tab;
|
||||||
import android.support.v7.app.ActionBar.TabListener;
|
import android.support.v7.app.ActionBar.TabListener;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
|
|
||||||
import com.github.nutomic.controldlna.R;
|
import com.github.nutomic.controldlna.R;
|
||||||
|
|
||||||
|
@ -140,49 +139,29 @@ public class MainActivity extends ActionBarActivity {
|
||||||
.setText(R.string.title_route)
|
.setText(R.string.title_route)
|
||||||
.setTabListener(tabListener));
|
.setTabListener(tabListener));
|
||||||
|
|
||||||
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
ConnectivityManager connManager = (ConnectivityManager)
|
||||||
|
getSystemService(CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
|
||||||
final SharedPreferences prefs = getSharedPreferences("preferences.db", 0);
|
final SharedPreferences prefs = getSharedPreferences("preferences.db", 0);
|
||||||
|
|
||||||
if (!wifi.isConnected() && !prefs.getBoolean("wifi_skip_dialog", false) &&
|
if (!wifi.isConnected() && !prefs.getBoolean("wifi_skip_dialog", false)) {
|
||||||
!prefs.getBoolean("wifi_auto_enable", false)) {
|
View checkBoxView = View.inflate(this, R.layout.dialog_wifi_disabled, null);
|
||||||
LinearLayout layout = new LinearLayout(this);
|
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.dont_show_again);
|
||||||
layout.setOrientation(LinearLayout.VERTICAL);
|
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
|
||||||
CheckBox cbAutoEnable = new CheckBox(this);
|
|
||||||
cbAutoEnable.setText(R.string.auto_enable_wifi);
|
|
||||||
cbAutoEnable.setChecked(prefs.getBoolean("wifi_auto_enable", false));
|
|
||||||
cbAutoEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
prefs.edit().putBoolean("wifi_auto_enable", isChecked)
|
|
||||||
.commit();
|
|
||||||
if (isChecked)
|
|
||||||
wifiManager.setWifiEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
layout.addView(cbAutoEnable);
|
|
||||||
|
|
||||||
CheckBox cbShowOnce = new CheckBox(this);
|
|
||||||
cbShowOnce.setText(R.string.dont_show_dialog_again);
|
|
||||||
cbShowOnce.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
prefs.edit().putBoolean("wifi_skip_dialog", isChecked)
|
prefs.edit().putBoolean("wifi_skip_dialog", isChecked)
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
layout.addView(cbShowOnce);
|
|
||||||
|
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setView(layout)
|
.setView(checkBoxView)
|
||||||
.setTitle(R.string.warning_wifi_not_connected)
|
.setTitle(R.string.warning_wifi_not_connected)
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
else if (!wifiManager.isWifiEnabled() && prefs.getBoolean("wifi_auto_enable", false))
|
|
||||||
wifiManager.setWifiEnabled(true);
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
FragmentManager fm = getSupportFragmentManager();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
|
|
Reference in a new issue