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.browser; 18 19 import android.content.Context; 20 import android.view.View; 21 import android.view.animation.AnimationUtils; 22 import android.view.inputmethod.InputMethodManager; 23 import android.webkit.WebView; 24 import android.widget.LinearLayout; 25 26 /* package */ class WebDialog extends LinearLayout { 27 protected WebView mWebView; 28 protected BrowserActivity mBrowserActivity; 29 private boolean mIsVisible; 30 31 /* package */ WebDialog(BrowserActivity context) { 32 super(context); 33 mBrowserActivity = context; 34 } 35 36 /* dialogs that have cancel buttons can optionally share code by including a 37 * view with an id of 'done'. 38 */ 39 protected void addCancel() { 40 View button = findViewById(R.id.done); 41 if (button != null) button.setOnClickListener(mCancelListener); 42 } 43 44 private View.OnClickListener mCancelListener = new View.OnClickListener() { 45 public void onClick(View v) { 46 mBrowserActivity.closeDialogs(); 47 } 48 }; 49 50 protected void dismiss() { 51 startAnimation(AnimationUtils.loadAnimation(mBrowserActivity, 52 R.anim.dialog_exit)); 53 mIsVisible = false; 54 } 55 56 /* 57 * Remove the soft keyboard from the screen. 58 */ 59 protected void hideSoftInput() { 60 InputMethodManager imm = (InputMethodManager) 61 mBrowserActivity.getSystemService(Context.INPUT_METHOD_SERVICE); 62 imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); 63 } 64 65 protected boolean isVisible() { 66 return mIsVisible; 67 } 68 69 /* package */ void setWebView(WebView webview) { 70 mWebView = webview; 71 } 72 73 protected void show() { 74 startAnimation(AnimationUtils.loadAnimation(mBrowserActivity, 75 R.anim.dialog_enter)); 76 mIsVisible = true; 77 } 78 79 } 80