Plugin.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1/* 2 * Copyright (C) 2007 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 android.webkit; 18 19import com.android.internal.R; 20 21import android.app.AlertDialog; 22import android.content.Context; 23import android.content.DialogInterface; 24import android.webkit.WebView; 25 26/** 27 * Represents a plugin (Java equivalent of the PluginPackageAndroid 28 * C++ class in libs/WebKitLib/WebKit/WebCore/plugins/android/) 29 */ 30public class Plugin { 31 public interface PreferencesClickHandler { 32 public void handleClickEvent(Context context); 33 } 34 35 private String mName; 36 private String mPath; 37 private String mFileName; 38 private String mDescription; 39 private PreferencesClickHandler mHandler; 40 41 public Plugin(String name, 42 String path, 43 String fileName, 44 String description) { 45 mName = name; 46 mPath = path; 47 mFileName = fileName; 48 mDescription = description; 49 mHandler = new DefaultClickHandler(); 50 } 51 52 public String toString() { 53 return mName; 54 } 55 56 public String getName() { 57 return mName; 58 } 59 60 public String getPath() { 61 return mPath; 62 } 63 64 public String getFileName() { 65 return mFileName; 66 } 67 68 public String getDescription() { 69 return mDescription; 70 } 71 72 public void setName(String name) { 73 mName = name; 74 } 75 76 public void setPath(String path) { 77 mPath = path; 78 } 79 80 public void setFileName(String fileName) { 81 mFileName = fileName; 82 } 83 84 public void setDescription(String description) { 85 mDescription = description; 86 } 87 88 public void setClickHandler(PreferencesClickHandler handler) { 89 mHandler = handler; 90 } 91 92 /** 93 * Invokes the click handler for this plugin. 94 */ 95 public void dispatchClickEvent(Context context) { 96 if (mHandler != null) { 97 mHandler.handleClickEvent(context); 98 } 99 } 100 101 /** 102 * Default click handler. The plugins should implement their own. 103 */ 104 private class DefaultClickHandler implements PreferencesClickHandler, 105 DialogInterface.OnClickListener { 106 private AlertDialog mDialog; 107 108 public void handleClickEvent(Context context) { 109 // Show a simple popup dialog containing the description 110 // string of the plugin. 111 if (mDialog == null) { 112 mDialog = new AlertDialog.Builder(context) 113 .setTitle(mName) 114 .setMessage(mDescription) 115 .setPositiveButton(R.string.ok, this) 116 .setCancelable(false) 117 .show(); 118 } 119 } 120 121 public void onClick(DialogInterface dialog, int which) { 122 mDialog.dismiss(); 123 mDialog = null; 124 } 125 } 126} 127