2013-11-21 10:13:38 -04:30
|
|
|
package ve.ucv.ciens.ccg.nxtcam.dialogs;
|
|
|
|
|
|
|
|
|
|
import ve.ucv.ciens.ccg.nxtcam.R;
|
|
|
|
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.app.DialogFragment;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
|
|
public class WifiOnDialog extends DialogFragment {
|
2013-11-22 11:13:08 -04:30
|
|
|
private final String TAG = "NXTCAM_WIFI_DIALOG";
|
2013-11-21 10:13:38 -04:30
|
|
|
private final String CLASS_NAME = WifiOnDialog.class.getSimpleName();
|
|
|
|
|
|
2013-11-22 11:13:08 -04:30
|
|
|
private WifiOnDialogListener listener;
|
2013-11-21 10:13:38 -04:30
|
|
|
private WifiManager wifiManager;
|
|
|
|
|
|
|
|
|
|
public interface WifiOnDialogListener{
|
|
|
|
|
public void onWifiOnDialogPositiveClick(DialogFragment dialog);
|
|
|
|
|
public void onWifiOnDialogNegativeClick(DialogFragment dialog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWifiManager(WifiManager wifiManager){
|
|
|
|
|
this.wifiManager = wifiManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-11-22 11:13:08 -04:30
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState){
|
2013-11-21 10:13:38 -04:30
|
|
|
// Use the Builder class for convenient dialog construction
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
|
|
|
|
|
|
builder.setMessage(R.string.wifi_on_msg).setPositiveButton(R.string.wifi_on_button, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
2013-11-22 11:13:08 -04:30
|
|
|
public void onClick(DialogInterface dialog, int id){
|
2013-11-21 10:13:38 -04:30
|
|
|
if(wifiManager != null){
|
|
|
|
|
wifiManager.setWifiEnabled(true);
|
2013-11-22 11:13:08 -04:30
|
|
|
Logger.log_d(TAG, CLASS_NAME + ".setPositiveButton().onClick() :: setting wifi to on.");
|
|
|
|
|
if(listener != null)
|
|
|
|
|
listener.onWifiOnDialogPositiveClick(WifiOnDialog.this);
|
|
|
|
|
}else{
|
|
|
|
|
Logger.log_wtf(TAG, CLASS_NAME + ".setPositiveButton().onClick( :: wifiManager is null! Doing nothing.");
|
|
|
|
|
if(listener != null)
|
|
|
|
|
listener.onWifiOnDialogNegativeClick(WifiOnDialog.this);
|
|
|
|
|
}
|
2013-11-21 10:13:38 -04:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
2013-11-22 11:13:08 -04:30
|
|
|
public void onClick(DialogInterface dialog, int id){
|
|
|
|
|
Logger.log_d(TAG, CLASS_NAME + ".setPositiveButton().onClick( :: User canceled.");
|
|
|
|
|
if(listener != null)
|
|
|
|
|
listener.onWifiOnDialogNegativeClick(WifiOnDialog.this);
|
|
|
|
|
}
|
2013-11-21 10:13:38 -04:30
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create the AlertDialog object and return it
|
|
|
|
|
return builder.create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAttach(Activity activity){
|
2013-11-22 11:13:08 -04:30
|
|
|
super.onAttach(activity);
|
|
|
|
|
|
2013-11-21 10:13:38 -04:30
|
|
|
try{
|
2013-11-22 11:13:08 -04:30
|
|
|
listener = (WifiOnDialogListener)activity;
|
2013-11-21 10:13:38 -04:30
|
|
|
}catch(ClassCastException cce){
|
2013-11-22 11:13:08 -04:30
|
|
|
listener = null;
|
|
|
|
|
throw new ClassCastException(CLASS_NAME + ".onAttach() :: " + activity.toString() + "Must implement WifiOnDialogListener.");
|
2013-11-21 10:13:38 -04:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|