PickerViewModule.java 18.7 KB
Newer Older
xwenliang's avatar
xwenliang committed
1 2 3
package com.beefe.picker;

import android.app.Activity;
4
import android.app.Dialog;
xwenliang's avatar
xwenliang committed
5
import android.graphics.Color;
6
import android.graphics.PixelFormat;
xwenliang's avatar
xwenliang committed
7 8 9 10
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
11
import android.view.Window;
xwenliang's avatar
xwenliang committed
12 13 14 15
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

travelgeezer's avatar
travelgeezer committed
16
import com.beefe.picker.util.MIUIUtils;
xwenliang's avatar
xwenliang committed
17 18 19
import com.beefe.picker.view.OnSelectedListener;
import com.beefe.picker.view.PickerViewAlone;
import com.beefe.picker.view.PickerViewLinkage;
xwenliang's avatar
xwenliang committed
20
import com.beefe.picker.view.ReturnData;
xwenliang's avatar
xwenliang committed
21 22
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
xwenliang's avatar
xwenliang committed
23
import com.facebook.react.bridge.LifecycleEventListener;
xwenliang's avatar
xwenliang committed
24 25 26 27 28 29 30 31 32 33 34 35
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.util.ArrayList;

xwenliang's avatar
xwenliang committed
36 37
import static android.graphics.Color.argb;

xwenliang's avatar
xwenliang committed
38
/**
xwenliang's avatar
xwenliang committed
39
 * Author: <a href="https://github.com/shexiaoheng">heng</a>
40
 * <p>
xwenliang's avatar
xwenliang committed
41
 * Created by heng on 16/9/5.
42
 * <p>
xwenliang's avatar
xwenliang committed
43
 * Edited by heng on 16/9/22.
44 45
 * 1. PopupWindow height : full screen -> assignation
 * 2. Added pickerToolBarHeight support
46
 * <p>
47 48 49
 * Edited by heng on 2016/10/19.
 * 1. Added weights support
 * 2. Fixed return data bug
50 51 52 53 54 55 56 57 58
 * <p>
 * Edited by heng on 2016/11/16.
 * 1. Used WindowManager replace PopupWindow
 * 2. Removed method initOK() toggle() show() isPickerShow()
 * 3. Implements Application.ActivityLifecycleCallbacks
 * <p>
 * Edited by heng on 2016/11/17
 * 1. Used Dialog replace WindowManger
 * 2. Restore method show() isPickerShow()
xwenliang's avatar
xwenliang committed
59 60 61 62
 * <p>
 * Edited by heng on 2016/12/23
 * 1. Changed returnData type
 * 2. Added pickerToolBarFontSize
xwenliang's avatar
xwenliang committed
63
 * <p>
xwenliang's avatar
xwenliang committed
64 65 66 67 68 69
 * Edited by heng on 2016/12/26
 * 1. Fixed returnData bug
 * 2. Added pickerFontColor
 * 3. Added pickerFontSize
 * 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
 * 5. Fixed other bug
xwenliang's avatar
xwenliang committed
70 71 72 73
 *
 * Edited by heng on 2017/01/17
 * 1. Added select(ReadableArray array, Callback callback)
 * 2. Optimization code
xwenliang's avatar
xwenliang committed
74 75
 */

xwenliang's avatar
xwenliang committed
76
public class PickerViewModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
xwenliang's avatar
xwenliang committed
77 78 79 80 81

    private static final String REACT_CLASS = "BEEPickerManager";

    private static final String PICKER_DATA = "pickerData";
    private static final String SELECTED_VALUE = "selectedValue";
82

xwenliang's avatar
xwenliang committed
83
    private static final String IS_LOOP = "isLoop";
84 85 86

    private static final String WEIGHTS = "wheelFlex";

xwenliang's avatar
xwenliang committed
87
    private static final String PICKER_BG_COLOR = "pickerBg";
88

xwenliang's avatar
xwenliang committed
89 90 91
    private static final String PICKER_TOOL_BAR_BG = "pickerToolBarBg";
    private static final String PICKER_TOOL_BAR_HEIGHT = "pickerToolBarHeight";
    private static final String PICKER_TOOL_BAR_TEXT_SIZE = "pickerToolBarFontSize";
92

xwenliang's avatar
xwenliang committed
93 94
    private static final String PICKER_CONFIRM_BTN_TEXT = "pickerConfirmBtnText";
    private static final String PICKER_CONFIRM_BTN_COLOR = "pickerConfirmBtnColor";
95

xwenliang's avatar
xwenliang committed
96 97
    private static final String PICKER_CANCEL_BTN_TEXT = "pickerCancelBtnText";
    private static final String PICKER_CANCEL_BTN_COLOR = "pickerCancelBtnColor";
98

xwenliang's avatar
xwenliang committed
99 100 101 102 103
    private static final String PICKER_TITLE_TEXT = "pickerTitleText";
    private static final String PICKER_TITLE_TEXT_COLOR = "pickerTitleColor";

    private static final String PICKER_TEXT_COLOR = "pickerFontColor";
    private static final String PICKER_TEXT_SIZE = "pickerFontSize";
xwenliang's avatar
xwenliang committed
104 105 106 107 108 109

    private static final String PICKER_EVENT_NAME = "pickerEvent";
    private static final String EVENT_KEY_CONFIRM = "confirm";
    private static final String EVENT_KEY_CANCEL = "cancel";
    private static final String EVENT_KEY_SELECTED = "select";

xwenliang's avatar
xwenliang committed
110
    private static final String ERROR_NOT_INIT = "please initialize the component first";
xwenliang's avatar
xwenliang committed
111

112
    private Dialog dialog = null;
xwenliang's avatar
xwenliang committed
113 114 115 116 117 118 119

    private boolean isLoop = true;

    private String confirmText;
    private String cancelText;
    private String titleText;

120 121
    private double[] weights;

xwenliang's avatar
xwenliang committed
122
    private ArrayList<ReturnData> returnData;
xwenliang's avatar
xwenliang committed
123

124
    private int curStatus;
xwenliang's avatar
xwenliang committed
125

xwenliang's avatar
xwenliang committed
126 127 128
    private PickerViewLinkage pickerViewLinkage;
    private PickerViewAlone pickerViewAlone;

xwenliang's avatar
xwenliang committed
129 130
    public PickerViewModule(ReactApplicationContext reactContext) {
        super(reactContext);
xwenliang's avatar
xwenliang committed
131
        reactContext.addLifecycleEventListener(this);
xwenliang's avatar
xwenliang committed
132 133 134 135 136 137 138 139 140 141 142
    }

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @ReactMethod
    public void _init(ReadableMap options) {
        Activity activity = getCurrentActivity();
        if (activity != null && options.hasKey(PICKER_DATA)) {
143
            View view = activity.getLayoutInflater().inflate(R.layout.picker_view, null);
144 145 146 147
            RelativeLayout barLayout = (RelativeLayout) view.findViewById(R.id.barLayout);
            TextView cancelTV = (TextView) view.findViewById(R.id.cancel);
            TextView titleTV = (TextView) view.findViewById(R.id.title);
            TextView confirmTV = (TextView) view.findViewById(R.id.confirm);
148
            RelativeLayout pickerLayout = (RelativeLayout) view.findViewById(R.id.pickerLayout);
jinlongtao's avatar
jinlongtao committed
149 150
            pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage);
            pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone);
151 152

            int barViewHeight;
xwenliang's avatar
xwenliang committed
153
            if (options.hasKey(PICKER_TOOL_BAR_HEIGHT)) {
xwenliang's avatar
xwenliang committed
154
                try {
xwenliang's avatar
xwenliang committed
155
                    barViewHeight = options.getInt(PICKER_TOOL_BAR_HEIGHT);
xwenliang's avatar
xwenliang committed
156
                } catch (Exception e) {
xwenliang's avatar
xwenliang committed
157
                    barViewHeight = (int) options.getDouble(PICKER_TOOL_BAR_HEIGHT);
xwenliang's avatar
xwenliang committed
158
                }
xwenliang's avatar
xwenliang committed
159 160 161 162 163 164 165
            } else {
                barViewHeight = (int) (activity.getResources().getDisplayMetrics().density * 40);
            }
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT,
                    barViewHeight);
            barLayout.setLayoutParams(params);
xwenliang's avatar
xwenliang committed
166

xwenliang's avatar
xwenliang committed
167 168
            if (options.hasKey(PICKER_TOOL_BAR_BG)) {
                ReadableArray array = options.getArray(PICKER_TOOL_BAR_BG);
169
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
170
                barLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
171 172
            }

xwenliang's avatar
xwenliang committed
173 174 175 176 177 178
            if (options.hasKey(PICKER_TOOL_BAR_TEXT_SIZE)) {
                int toolBarTextSize = options.getInt(PICKER_TOOL_BAR_TEXT_SIZE);
                cancelTV.setTextSize(toolBarTextSize);
                titleTV.setTextSize(toolBarTextSize);
                confirmTV.setTextSize(toolBarTextSize);
            }
xwenliang's avatar
xwenliang committed
179

xwenliang's avatar
xwenliang committed
180 181
            if (options.hasKey(PICKER_CONFIRM_BTN_TEXT)) {
                confirmText = options.getString(PICKER_CONFIRM_BTN_TEXT);
xwenliang's avatar
xwenliang committed
182 183 184
            }
            confirmTV.setText(!TextUtils.isEmpty(confirmText) ? confirmText : "");

xwenliang's avatar
xwenliang committed
185 186
            if (options.hasKey(PICKER_CONFIRM_BTN_COLOR)) {
                ReadableArray array = options.getArray(PICKER_CONFIRM_BTN_COLOR);
187
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
188
                confirmTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
189 190 191 192
            }
            confirmTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
193
                    switch (curStatus) {
194 195 196 197 198 199 200
                        case 0:
                            returnData = pickerViewAlone.getSelectedData();
                            break;
                        case 1:
                            returnData = pickerViewLinkage.getSelectedData();
                            break;
                    }
xwenliang's avatar
xwenliang committed
201 202 203 204 205 206
                    commonEvent(EVENT_KEY_CONFIRM);
                    hide();
                }
            });


xwenliang's avatar
xwenliang committed
207 208
            if (options.hasKey(PICKER_TITLE_TEXT)) {
                titleText = options.getString(PICKER_TITLE_TEXT);
xwenliang's avatar
xwenliang committed
209 210
            }
            titleTV.setText(!TextUtils.isEmpty(titleText) ? titleText : "");
xwenliang's avatar
xwenliang committed
211 212
            if (options.hasKey(PICKER_TITLE_TEXT_COLOR)) {
                ReadableArray array = options.getArray(PICKER_TITLE_TEXT_COLOR);
213
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
214
                titleTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
215 216
            }

xwenliang's avatar
xwenliang committed
217 218
            if (options.hasKey(PICKER_CANCEL_BTN_TEXT)) {
                cancelText = options.getString(PICKER_CANCEL_BTN_TEXT);
xwenliang's avatar
xwenliang committed
219 220
            }
            cancelTV.setText(!TextUtils.isEmpty(cancelText) ? cancelText : "");
xwenliang's avatar
xwenliang committed
221 222
            if (options.hasKey(PICKER_CANCEL_BTN_COLOR)) {
                ReadableArray array = options.getArray(PICKER_CANCEL_BTN_COLOR);
223
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
224
                cancelTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
225 226 227 228
            }
            cancelTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
229
                    switch (curStatus) {
230 231 232 233 234 235 236
                        case 0:
                            returnData = pickerViewAlone.getSelectedData();
                            break;
                        case 1:
                            returnData = pickerViewLinkage.getSelectedData();
                            break;
                    }
xwenliang's avatar
xwenliang committed
237 238 239 240 241 242 243 244 245
                    commonEvent(EVENT_KEY_CANCEL);
                    hide();
                }
            });

            if (options.hasKey(IS_LOOP)) {
                isLoop = options.getBoolean(IS_LOOP);
            }

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
            if (options.hasKey(WEIGHTS)) {
                ReadableArray array = options.getArray(WEIGHTS);
                weights = new double[array.size()];
                for (int i = 0; i < array.size(); i++) {
                    switch (array.getType(i).name()) {
                        case "Number":
                            try {
                                weights[i] = array.getInt(i);
                            } catch (Exception e) {
                                weights[i] = array.getDouble(i);
                            }
                            break;
                        case "String":
                            try {
                                weights[i] = Double.parseDouble(array.getString(i));
                            } catch (Exception e) {
                                weights[i] = 1.0;
                            }
                            break;
                        default:
                            weights[i] = 1.0;
                            break;
                    }
                }
            }

xwenliang's avatar
xwenliang committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
            int pickerTextColor = 0xff000000;
            if (options.hasKey(PICKER_TEXT_COLOR)) {
                ReadableArray array = options.getArray(PICKER_TEXT_COLOR);
                int[] colors = getColor(array);
                pickerTextColor = Color.argb(colors[3], colors[0], colors[1], colors[2]);
            }

            int pickerTextSize = 16;
            if (options.hasKey(PICKER_TEXT_SIZE)) {
                try {
                    pickerTextSize = options.getInt(PICKER_TEXT_SIZE);
                } catch (Exception e) {
                    pickerTextSize = (int) options.getDouble(PICKER_TEXT_SIZE);
                }
            }

xwenliang's avatar
xwenliang committed
288 289
            ReadableArray pickerData = options.getArray(PICKER_DATA);

290
            int pickerViewHeight;
xwenliang's avatar
xwenliang committed
291 292
            String name = pickerData.getType(0).name();
            switch (name) {
xwenliang's avatar
xwenliang committed
293
                case "Map":
294
                    curStatus = 1;
xwenliang's avatar
xwenliang committed
295 296
                    pickerViewLinkage.setVisibility(View.VISIBLE);
                    pickerViewAlone.setVisibility(View.GONE);
297

298
                    pickerViewLinkage.setPickerData(pickerData, weights);
xwenliang's avatar
xwenliang committed
299 300
                    pickerViewLinkage.setTextColor(pickerTextColor);
                    pickerViewLinkage.setTextSize(pickerTextSize);
xwenliang's avatar
xwenliang committed
301
                    pickerViewLinkage.setIsLoop(isLoop);
302

xwenliang's avatar
xwenliang committed
303 304
                    pickerViewLinkage.setOnSelectListener(new OnSelectedListener() {
                        @Override
xwenliang's avatar
xwenliang committed
305
                        public void onSelected(ArrayList<ReturnData> selectedList) {
306
                            returnData = selectedList;
xwenliang's avatar
xwenliang committed
307 308 309
                            commonEvent(EVENT_KEY_SELECTED);
                        }
                    });
xwenliang's avatar
xwenliang committed
310
                    pickerViewHeight = pickerViewLinkage.getViewHeight();
xwenliang's avatar
xwenliang committed
311
                    break;
xwenliang's avatar
xwenliang committed
312
                default:
313
                    curStatus = 0;
xwenliang's avatar
xwenliang committed
314 315
                    pickerViewAlone.setVisibility(View.VISIBLE);
                    pickerViewLinkage.setVisibility(View.GONE);
xwenliang's avatar
xwenliang committed
316

317
                    pickerViewAlone.setPickerData(pickerData, weights);
xwenliang's avatar
xwenliang committed
318 319
                    pickerViewAlone.setTextColor(pickerTextColor);
                    pickerViewAlone.setTextSize(pickerTextSize);
xwenliang's avatar
xwenliang committed
320 321 322 323
                    pickerViewAlone.setIsLoop(isLoop);

                    pickerViewAlone.setOnSelectedListener(new OnSelectedListener() {
                        @Override
xwenliang's avatar
xwenliang committed
324
                        public void onSelected(ArrayList<ReturnData> selectedList) {
325
                            returnData = selectedList;
xwenliang's avatar
xwenliang committed
326 327 328 329
                            commonEvent(EVENT_KEY_SELECTED);
                        }
                    });

xwenliang's avatar
xwenliang committed
330
                    pickerViewHeight = pickerViewAlone.getViewHeight();
xwenliang's avatar
xwenliang committed
331 332 333
                    break;
            }

xwenliang's avatar
xwenliang committed
334 335 336 337 338 339
            if (options.hasKey(SELECTED_VALUE)) {
                ReadableArray array = options.getArray(SELECTED_VALUE);
                String[] selectedValue = getSelectedValue(array);
                select(selectedValue);
            }

340 341 342
            if (options.hasKey(PICKER_BG_COLOR)) {
                ReadableArray array = options.getArray(PICKER_BG_COLOR);
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
343
                pickerLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
344 345 346 347 348 349 350 351 352
            }

            int height = barViewHeight + pickerViewHeight;
            if (dialog == null) {
                dialog = new Dialog(activity, R.style.Dialog_Full_Screen);
                dialog.setContentView(view);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                Window window = dialog.getWindow();
                if (window != null) {
travelgeezer's avatar
travelgeezer committed
353 354 355
                    if (MIUIUtils.isMIUI()) {
                        layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
                    }else {
zooble's avatar
zooble committed
356
                        //layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
travelgeezer's avatar
travelgeezer committed
357
                    }
358 359 360 361 362 363 364 365
                    layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
                    layoutParams.format = PixelFormat.TRANSPARENT;
                    layoutParams.windowAnimations = R.style.PickerAnim;
                    layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
                    layoutParams.height = height;
                    layoutParams.gravity = Gravity.BOTTOM;
                    window.setAttributes(layoutParams);
                }
366
            } else {
367 368
                dialog.dismiss();
                dialog.setContentView(view);
xwenliang's avatar
xwenliang committed
369 370 371 372
            }
        }
    }

xwenliang's avatar
xwenliang committed
373 374 375 376 377 378 379 380 381 382 383 384
    @ReactMethod
    public void select(ReadableArray array, Callback callback) {
        if (dialog == null) {
            if (callback != null) {
                callback.invoke(ERROR_NOT_INIT);
            }
            return;
        }
        String[] selectedValue = getSelectedValue(array);
        select(selectedValue);
    }

xwenliang's avatar
xwenliang committed
385
    @ReactMethod
386 387
    public void show() {
        if (dialog == null) {
xwenliang's avatar
xwenliang committed
388 389
            return;
        }
390 391
        if (!dialog.isShowing()) {
            dialog.show();
xwenliang's avatar
xwenliang committed
392 393 394 395 396
        }
    }

    @ReactMethod
    public void hide() {
397 398 399 400 401
        if (dialog == null) {
            return;
        }
        if (dialog.isShowing()) {
            dialog.dismiss();
xwenliang's avatar
xwenliang committed
402 403 404 405 406
        }
    }

    @ReactMethod
    public void isPickerShow(Callback callback) {
xwenliang's avatar
xwenliang committed
407 408
        if (callback == null)
            return;
409
        if (dialog == null) {
xwenliang's avatar
xwenliang committed
410 411
            callback.invoke(ERROR_NOT_INIT);
        } else {
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
            callback.invoke(null, dialog.isShowing());
        }
    }

    private int[] getColor(ReadableArray array) {
        int[] colors = new int[4];
        for (int i = 0; i < array.size(); i++) {
            switch (i) {
                case 0:
                case 1:
                case 2:
                    colors[i] = array.getInt(i);
                    break;
                case 3:
                    colors[i] = (int) (array.getDouble(i) * 255);
                    break;
                default:
                    break;
            }
xwenliang's avatar
xwenliang committed
431
        }
432
        return colors;
xwenliang's avatar
xwenliang committed
433 434
    }

xwenliang's avatar
xwenliang committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
    private String[] getSelectedValue(ReadableArray array) {
        String[] selectValue = new String[array.size()];
        String value = "";
        for (int i = 0; i < array.size(); i++) {
            switch (array.getType(i).name()) {
                case "Boolean":
                    value = String.valueOf(array.getBoolean(i));
                    break;
                case "Number":
                    try {
                        value = String.valueOf(array.getInt(i));
                    } catch (Exception e) {
                        value = String.valueOf(array.getDouble(i));
                    }
                    break;
                case "String":
                    value = array.getString(i);
                    break;
            }
            selectValue[i] = value;
        }
        return selectValue;
    }

    private void select(String[] selectedValue) {
        switch (curStatus) {
            case 0:
                pickerViewAlone.setSelectValue(selectedValue);
                break;
            case 1:
                pickerViewLinkage.setSelectValue(selectedValue);
                break;
        }
    }

xwenliang's avatar
xwenliang committed
470 471
    private void commonEvent(String eventKey) {
        WritableMap map = Arguments.createMap();
xwenliang's avatar
xwenliang committed
472 473 474 475 476 477
        map.putString("type", eventKey);
        WritableArray indexes = Arguments.createArray();
        WritableArray values = Arguments.createArray();
        for (ReturnData data : returnData) {
            indexes.pushInt(data.getIndex());
            values.pushString(data.getItem());
xwenliang's avatar
xwenliang committed
478
        }
xwenliang's avatar
xwenliang committed
479 480
        map.putArray("selectedValue", values);
        map.putArray("selectedIndex", indexes);
xwenliang's avatar
xwenliang committed
481 482 483 484 485 486 487 488 489 490
        sendEvent(getReactApplicationContext(), PICKER_EVENT_NAME, map);
    }

    private void sendEvent(ReactContext reactContext,
                           String eventName,
                           @Nullable WritableMap params) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }
491 492

    @Override
xwenliang's avatar
xwenliang committed
493
    public void onHostResume() {
494 495 496 497

    }

    @Override
xwenliang's avatar
xwenliang committed
498
    public void onHostPause() {
499
        hide();
xwenliang's avatar
xwenliang committed
500
        dialog = null;
501 502 503
    }

    @Override
xwenliang's avatar
xwenliang committed
504
    public void onHostDestroy() {
505 506
        hide();
        dialog = null;
507
    }
xwenliang's avatar
xwenliang committed
508
}