Home | History | Annotate | Download | only in wifi
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.settings.wifi;
     18 
     19 import com.android.settings.R;
     20 
     21 import android.app.AlertDialog;
     22 import android.content.Context;
     23 import android.content.DialogInterface;
     24 import android.os.Bundle;
     25 import android.view.View;
     26 import android.widget.Button;
     27 
     28 class WifiDialog extends AlertDialog implements WifiConfigUiBase {
     29     static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
     30     static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
     31 
     32     private final boolean mEdit;
     33     private final DialogInterface.OnClickListener mListener;
     34     private final AccessPoint mAccessPoint;
     35 
     36     private View mView;
     37     private WifiConfigController mController;
     38     private boolean mHideSubmitButton;
     39 
     40     public WifiDialog(Context context, DialogInterface.OnClickListener listener,
     41             AccessPoint accessPoint, boolean edit, boolean hideSubmitButton) {
     42         this(context, listener, accessPoint, edit);
     43         mHideSubmitButton = hideSubmitButton;
     44     }
     45 
     46     public WifiDialog(Context context, DialogInterface.OnClickListener listener,
     47             AccessPoint accessPoint, boolean edit) {
     48         super(context);
     49         mEdit = edit;
     50         mListener = listener;
     51         mAccessPoint = accessPoint;
     52         mHideSubmitButton = false;
     53     }
     54 
     55     @Override
     56     public WifiConfigController getController() {
     57         return mController;
     58     }
     59 
     60     @Override
     61     protected void onCreate(Bundle savedInstanceState) {
     62         mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
     63         setView(mView);
     64         setInverseBackgroundForced(true);
     65         mController = new WifiConfigController(this, mView, mAccessPoint, mEdit);
     66         super.onCreate(savedInstanceState);
     67 
     68         if (mHideSubmitButton) {
     69             mController.hideSubmitButton();
     70         } else {
     71             /* During creation, the submit button can be unavailable to determine
     72              * visibility. Right after creation, update button visibility */
     73             mController.enableSubmitIfAppropriate();
     74         }
     75     }
     76 
     77     @Override
     78     public boolean isEdit() {
     79         return mEdit;
     80     }
     81 
     82     @Override
     83     public Button getSubmitButton() {
     84         return getButton(BUTTON_SUBMIT);
     85     }
     86 
     87     @Override
     88     public Button getForgetButton() {
     89         return getButton(BUTTON_FORGET);
     90     }
     91 
     92     @Override
     93     public Button getCancelButton() {
     94         return getButton(BUTTON_NEGATIVE);
     95     }
     96 
     97     @Override
     98     public void setSubmitButton(CharSequence text) {
     99         setButton(BUTTON_SUBMIT, text, mListener);
    100     }
    101 
    102     @Override
    103     public void setForgetButton(CharSequence text) {
    104         setButton(BUTTON_FORGET, text, mListener);
    105     }
    106 
    107     @Override
    108     public void setCancelButton(CharSequence text) {
    109         setButton(BUTTON_NEGATIVE, text, mListener);
    110     }
    111 }
    112