Home | History | Annotate | Download | only in browser
      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.provider.Browser;
     20 import android.view.LayoutInflater;
     21 import android.view.View;
     22 
     23 /* package */ class SelectDialog extends WebDialog {
     24     private View mCopyButton;
     25     private View mSelectAllButton;
     26     private View mShareButton;
     27     private View mFindButton;
     28 
     29     SelectDialog(BrowserActivity context) {
     30         super(context);
     31         LayoutInflater factory = LayoutInflater.from(context);
     32         factory.inflate(R.layout.browser_select, this);
     33         addCancel();
     34 
     35         mCopyButton = findViewById(R.id.copy);
     36         mCopyButton.setOnClickListener(mCopyListener);
     37         mSelectAllButton = findViewById(R.id.select_all);
     38         mSelectAllButton.setOnClickListener(mSelectAllListener);
     39         mShareButton = findViewById(R.id.share);
     40         mShareButton.setOnClickListener(mShareListener);
     41         mFindButton = findViewById(R.id.find);
     42         mFindButton.setOnClickListener(mFindListener);
     43     }
     44 
     45     private View.OnClickListener mCopyListener = new View.OnClickListener() {
     46         public void onClick(View v) {
     47             mWebView.copySelection();
     48             mBrowserActivity.closeDialogs();
     49         }
     50     };
     51 
     52     private View.OnClickListener mSelectAllListener = new View.OnClickListener() {
     53         public void onClick(View v) {
     54             mWebView.selectAll();
     55         }
     56     };
     57 
     58     private View.OnClickListener mShareListener = new View.OnClickListener() {
     59         public void onClick(View v) {
     60             String selection = mWebView.getSelection();
     61             Browser.sendString(mBrowserActivity, selection);
     62             mBrowserActivity.closeDialogs();
     63         }
     64     };
     65 
     66     private View.OnClickListener mFindListener = new View.OnClickListener() {
     67         public void onClick(View v) {
     68             String selection = mWebView.getSelection();
     69             mBrowserActivity.closeDialogs();
     70             mBrowserActivity.showFindDialog();
     71             mBrowserActivity.setFindDialogText(selection);
     72         }
     73     };
     74 
     75     /**
     76      * Called by BrowserActivity.closeDialog.  Start the animation to hide
     77      * the dialog, and inform the WebView that the dialog is being dismissed.
     78      */
     79     @Override
     80     public void dismiss() {
     81         super.dismiss();
     82         mWebView.notifySelectDialogDismissed();
     83     }
     84 
     85 }
     86