Changed wifi disabled warning dialog.

This commit is contained in:
Felix Ableitner 2014-01-05 22:28:48 +01:00
parent 017c8a6411
commit 86ba981c3c
3 changed files with 29 additions and 39 deletions

View 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>

View file

@ -28,6 +28,8 @@
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>
<!-- Image alt text -->
<string name="album_art">Album Art</string>
@ -36,8 +38,4 @@
<string name="route_description">DLNA Playback</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>

View file

@ -36,7 +36,6 @@ 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.support.v4.app.Fragment;
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.ActionBarActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import com.github.nutomic.controldlna.R;
@ -140,49 +139,29 @@ public class MainActivity extends ActionBarActivity {
.setText(R.string.title_route)
.setTabListener(tabListener));
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
ConnectivityManager connManager = (ConnectivityManager)
getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
final SharedPreferences prefs = getSharedPreferences("preferences.db", 0);
if (!wifi.isConnected() && !prefs.getBoolean("wifi_skip_dialog", false) &&
!prefs.getBoolean("wifi_auto_enable", false)) {
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
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() {
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
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("wifi_skip_dialog", isChecked)
.commit();
}
});
layout.addView(cbShowOnce);
new AlertDialog.Builder(this)
.setView(layout)
.setView(checkBoxView)
.setTitle(R.string.warning_wifi_not_connected)
.setPositiveButton(android.R.string.ok, null)
.show();
}
else if (!wifiManager.isWifiEnabled() && prefs.getBoolean("wifi_auto_enable", false))
wifiManager.setWifiEnabled(true);
if (savedInstanceState != null) {
FragmentManager fm = getSupportFragmentManager();