blob: b57ab0b1924f76b4308ae49398895e78d4a30c51 [file] [log] [blame]
The Android Open Source Projected217d92008-12-17 18:05:52 -08001/*
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
17package com.android.browser;
18
19import android.app.Activity;
20import android.os.Handler;
21import android.util.Log;
22import android.view.Gravity;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.TextView;
26
27import org.json.JSONException;
28import org.json.JSONObject;
29
30/**
31 * Gears permission dialog
32 */
33class GearsPermissionsDialog extends GearsBaseDialog {
34
35 private static final String TAG = "GearsPermissionsDialog";
36
37 private String mDialogType;
38
39 public GearsPermissionsDialog(Activity activity,
40 Handler handler,
41 String arguments) {
42 super (activity, handler, arguments);
43 }
44
45 public void setup() {
46 inflate(R.layout.gears_dialog_permission, R.id.panel_content);
47 setupButtons(R.string.permission_button_alwaysdeny,
48 R.string.permission_button_allow,
49 R.string.permission_button_deny);
50
51 View contentBorder = findViewById(R.id.content_border);
52 if (contentBorder != null) {
53 contentBorder.setBackgroundResource(R.color.permission_border);
54 }
55 View contentBackground = findViewById(R.id.content_background);
56 if (contentBackground != null) {
57 contentBackground.setBackgroundResource(R.color.permission_background);
58 }
59
60 try {
61 JSONObject json = new JSONObject(mDialogArguments);
62
63 if (json.has("dialogType")) {
64 mDialogType = json.getString("dialogType");
65 setupDialog();
66 }
67
68 if (!json.has("customName")) {
69 setLabel(json, "origin", R.id.origin_title);
70 View titleView = findViewById(R.id.origin_title);
71 if (titleView != null) {
72 TextView title = (TextView) titleView;
73 title.setGravity(Gravity.CENTER);
74 }
75 } else {
76 setLabel(json, "customName", R.id.origin_title);
77 setLabel(json, "origin", R.id.origin_subtitle);
78 setLabel(json, "customMessage", R.id.origin_message);
79 }
80
81 if (json.has("customIcon")) {
82 String iconUrl = json.getString("customIcon");
83 mChoosenIconSize = 32;
84 downloadIcon(iconUrl);
85 }
86
87 } catch (JSONException e) {
88 Log.e(TAG, "JSON exception ", e);
89 }
90 }
91
92 public void setupDialog(TextView message, ImageView icon) {
93 if (mDialogType.equalsIgnoreCase(LOCAL_DATA_STRING)) {
94 message.setText(R.string.query_data_message);
95 icon.setImageResource(R.drawable.gears_local_data);
96 } else if (mDialogType.equalsIgnoreCase(LOCATION_DATA_STRING)) {
97 message.setText(R.string.location_message);
98 icon.setImageResource(R.drawable.gears_location_data);
99 View privacyPolicyLabel = findViewById(R.id.privacy_policy_label);
100 if (privacyPolicyLabel != null) {
101 privacyPolicyLabel.setVisibility(View.VISIBLE);
102 }
103 }
104 }
105
106 public String closeDialog(int closingType) {
107 String ret = null;
108 switch (closingType) {
109 case ALWAYS_DENY:
110 ret = "{\"allow\": false, \"permanently\": true }";
111 break;
112 case ALLOW:
113 ret = "{\"allow\": true, \"permanently\": true }";
114 break;
115 case DENY:
116 ret = "{\"allow\": false, \"permanently\": false }";
117 break;
118 }
119 return ret;
120 }
121
122}