blob: 4c2554f7e1f826958507b33abf6b6f193c301b19 [file] [log] [blame]
Leon Scroggins III8e4fbf12010-08-17 16:58:15 -04001/*
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
17package com.android.browser;
18
19import android.provider.Browser;
20import android.webkit.WebView;
21import android.view.ActionMode;
22import android.view.Menu;
23import android.view.MenuItem;
24
25class SelectActionModeCallback implements ActionMode.Callback {
26 private WebView mWebView;
27 private BrowserActivity mBrowserActivity;
28
29 SelectActionModeCallback(BrowserActivity context) {
30 mBrowserActivity = context;
31 }
32
33 /*
34 * Set the WebView to be copied from.
35 */
36 void setWebView(WebView webView) {
37 mWebView = webView;
38 }
39
40 // ActionMode.Callback implementation
41
42 @Override
43 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
44 mode.getMenuInflater().inflate(R.menu.copy, menu);
45 mode.setTitle(R.string.text_selection_title);
46 return true;
47 }
48
49 @Override
50 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
51 return true;
52 }
53
54 @Override
55 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
56 switch(item.getItemId()) {
57 case R.id.copy:
58 mWebView.copySelection();
59 mode.finish();
60 break;
61
62 case R.id.share:
63 String selection = mWebView.getSelection();
64 Browser.sendString(mBrowserActivity, selection);
65 mode.finish();
66 break;
67
68 case R.id.select_all:
69 mWebView.selectAll();
70 break;
71
72 case R.id.find:
73 String sel= mWebView.getSelection();
74 mode.finish();
75 mBrowserActivity.showFindDialog(sel);
76 break;
77
78 default:
79 return false;
80 }
81 return true;
82 }
83
84 @Override
85 public void onDestroyActionMode(ActionMode mode) {
86 mBrowserActivity.onEndActionMode();
87 mWebView.notifySelectDialogDismissed();
88 }
89}