The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.app.Activity; |
| 20 | import android.os.Handler; |
| 21 | import android.util.Log; |
| 22 | import android.view.Gravity; |
| 23 | import android.view.View; |
| 24 | import android.widget.ImageView; |
| 25 | import android.widget.TextView; |
| 26 | |
| 27 | import org.json.JSONException; |
| 28 | import org.json.JSONObject; |
| 29 | |
| 30 | /** |
| 31 | * Gears permission dialog |
| 32 | */ |
| 33 | class GearsPermissionsDialog extends GearsBaseDialog { |
| 34 | |
| 35 | private static final String TAG = "GearsPermissionsDialog"; |
| 36 | |
| 37 | private String mDialogType; |
| 38 | private int mNotification = 0; |
| 39 | |
| 40 | public GearsPermissionsDialog(Activity activity, |
| 41 | Handler handler, |
| 42 | String arguments) { |
| 43 | super (activity, handler, arguments); |
| 44 | } |
| 45 | |
| 46 | public void setup() { |
| 47 | inflate(R.layout.gears_dialog_permission, R.id.panel_content); |
| 48 | setupButtons(R.string.permission_button_alwaysdeny, |
| 49 | R.string.permission_button_allow, |
| 50 | R.string.permission_button_deny); |
| 51 | |
| 52 | try { |
| 53 | JSONObject json = new JSONObject(mDialogArguments); |
| 54 | |
| 55 | if (json.has("dialogType")) { |
| 56 | mDialogType = json.getString("dialogType"); |
| 57 | setupDialog(); |
| 58 | } |
| 59 | |
| 60 | if (!json.has("customName")) { |
| 61 | setLabel(json, "origin", R.id.origin_title); |
| 62 | View titleView = findViewById(R.id.origin_title); |
| 63 | if (titleView != null) { |
| 64 | TextView title = (TextView) titleView; |
| 65 | title.setGravity(Gravity.CENTER); |
| 66 | } |
| 67 | } else { |
| 68 | setLabel(json, "customName", R.id.origin_title); |
| 69 | setLabel(json, "origin", R.id.origin_subtitle); |
| 70 | setLabel(json, "customMessage", R.id.origin_message); |
| 71 | } |
| 72 | |
| 73 | if (json.has("customIcon")) { |
| 74 | String iconUrl = json.getString("customIcon"); |
| 75 | mChoosenIconSize = 32; |
| 76 | downloadIcon(iconUrl); |
| 77 | } |
| 78 | |
| 79 | View msg = findViewById(R.id.permission_dialog_message); |
| 80 | if (msg != null) { |
| 81 | TextView dialogMessage = (TextView) msg; |
| 82 | if (mDialogType.equalsIgnoreCase(LOCAL_DATA_STRING)) { |
| 83 | dialogMessage.setText(R.string.query_data_message); |
| 84 | } else if (mDialogType.equalsIgnoreCase(LOCATION_DATA_STRING)) { |
| 85 | dialogMessage.setText(R.string.location_message); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | } catch (JSONException e) { |
| 90 | Log.e(TAG, "JSON exception ", e); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | public void setupDialog(TextView message, ImageView icon) { |
| 95 | if (mDialogType.equalsIgnoreCase(LOCAL_DATA_STRING)) { |
| 96 | message.setText(R.string.query_data_prompt); |
| 97 | icon.setImageResource(android.R.drawable.ic_popup_disk_full); |
| 98 | } else if (mDialogType.equalsIgnoreCase(LOCATION_DATA_STRING)) { |
| 99 | message.setText(R.string.location_prompt); |
| 100 | icon.setImageResource(R.drawable.ic_dialog_menu_generic); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | public String closeDialog(int closingType) { |
| 105 | String ret = null; |
| 106 | switch (closingType) { |
| 107 | case ALWAYS_DENY: |
| 108 | ret = "{\"allow\": false, \"permanently\": true }"; |
| 109 | if (mDialogType.equalsIgnoreCase(LOCAL_DATA_STRING)) { |
| 110 | mNotification = R.string.storage_notification_alwaysdeny; |
| 111 | } else if (mDialogType.equalsIgnoreCase(LOCATION_DATA_STRING)) { |
| 112 | mNotification = R.string.location_notification_alwaysdeny; |
| 113 | } |
| 114 | break; |
| 115 | case ALLOW: |
| 116 | ret = "{\"allow\": true, \"permanently\": true }"; |
| 117 | if (mDialogType.equalsIgnoreCase(LOCAL_DATA_STRING)) { |
| 118 | mNotification = R.string.storage_notification; |
| 119 | } else if (mDialogType.equalsIgnoreCase(LOCATION_DATA_STRING)) { |
| 120 | mNotification = R.string.location_notification; |
| 121 | } |
| 122 | break; |
| 123 | case DENY: |
| 124 | ret = "{\"allow\": false, \"permanently\": false }"; |
| 125 | break; |
| 126 | } |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | public int notification() { |
| 131 | return mNotification; |
| 132 | } |
| 133 | } |