Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java

Issue 11360207: Add Java resources to content and chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove obsolete findbugs warnings Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.app.AlertDialog; 7 import android.app.AlertDialog;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 import android.widget.Button; 13 import android.widget.Button;
14 import android.widget.CheckBox; 14 import android.widget.CheckBox;
15 import android.widget.EditText; 15 import android.widget.EditText;
16 import android.widget.TextView; 16 import android.widget.TextView;
17 17
18 import org.chromium.base.CalledByNative; 18 import org.chromium.base.CalledByNative;
19 import org.chromium.content.app.AppResource; 19 import org.chromium.chrome.R;
20 import org.chromium.ui.gfx.NativeWindow; 20 import org.chromium.ui.gfx.NativeWindow;
21 21
22 public class JavascriptAppModalDialog { 22 public class JavascriptAppModalDialog {
23 private String mTitle; 23 private String mTitle;
24 private String mMessage; 24 private String mMessage;
25 private boolean mShouldShowSuppressCheckBox; 25 private boolean mShouldShowSuppressCheckBox;
26 private int mNativeDialogPointer; 26 private int mNativeDialogPointer;
27 private AlertDialog mDialog; 27 private AlertDialog mDialog;
28 28
29 private JavascriptAppModalDialog(String title, String message, 29 private JavascriptAppModalDialog(String title, String message,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 assert window != null; 64 assert window != null;
65 Context context = window.getContext(); 65 Context context = window.getContext();
66 66
67 // Cache the native dialog pointer so that we can use it to return the 67 // Cache the native dialog pointer so that we can use it to return the
68 // response. 68 // response.
69 mNativeDialogPointer = nativeDialogPointer; 69 mNativeDialogPointer = nativeDialogPointer;
70 70
71 LayoutInflater inflater = 71 LayoutInflater inflater =
72 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATE R_SERVICE); 72 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATE R_SERVICE);
73 73
74 assert AppResource.LAYOUT_JS_MODAL_DIALOG != 0; 74 ViewGroup dialogLayout = (ViewGroup) inflater.inflate(R.layout.js_modal_ dialog, null);
75 ViewGroup dialogLayout = (ViewGroup) inflater.inflate(AppResource.LAYOUT _JS_MODAL_DIALOG,
76 null);
77 75
78 prepare(dialogLayout); 76 prepare(dialogLayout);
79 77
80 mDialog = new AlertDialog.Builder(context) 78 mDialog = new AlertDialog.Builder(context)
81 .setView(dialogLayout) 79 .setView(dialogLayout)
82 .setOnCancelListener(new DialogInterface.OnCancelListener() { 80 .setOnCancelListener(new DialogInterface.OnCancelListener() {
83 @Override 81 @Override
84 public void onCancel(DialogInterface dialog) { 82 public void onCancel(DialogInterface dialog) {
85 cancel(false); 83 cancel(false);
86 } 84 }
87 }) 85 })
88 .create(); 86 .create();
89 mDialog.setCanceledOnTouchOutside(false); 87 mDialog.setCanceledOnTouchOutside(false);
90 mDialog.show(); 88 mDialog.show();
91 } 89 }
92 90
93 @CalledByNative 91 @CalledByNative
94 void dismiss() { 92 void dismiss() {
95 mDialog.dismiss(); 93 mDialog.dismiss();
96 } 94 }
97 95
98 void prepare(final ViewGroup layout) { 96 void prepare(final ViewGroup layout) {
99 // Set the title and message. 97 // Set the title and message.
100 assert AppResource.ID_JS_MODAL_DIALOG_TEXT_TITLE != 0; 98 TextView titleView = (TextView) layout.findViewById(R.id.js_modal_dialog _title);
101 assert AppResource.ID_JS_MODAL_DIALOG_TEXT_MESSAGE != 0; 99 TextView messageView = (TextView) layout.findViewById(R.id.js_modal_dial og_message);
102
103 TextView titleView = (TextView) layout.findViewById(
104 AppResource.ID_JS_MODAL_DIALOG_TEXT_TITLE);
105 TextView messageView = (TextView) layout.findViewById(
106 AppResource.ID_JS_MODAL_DIALOG_TEXT_MESSAGE);
107 titleView.setText(mTitle); 100 titleView.setText(mTitle);
108 messageView.setText(mMessage); 101 messageView.setText(mMessage);
109 102
110 // Setup the OK button. 103 // Setup the OK button.
111 assert AppResource.ID_JS_MODAL_DIALOG_BUTTON_CONFIRM != 0; 104 Button okButton = (Button) layout.findViewById(R.id.js_modal_dialog_butt on_confirm);
112 assert AppResource.ID_JS_MODAL_DIALOG_CHECKBOX_SUPPRESS_DIALOGS != 0;
113
114 Button okButton = (Button) layout.findViewById(
115 AppResource.ID_JS_MODAL_DIALOG_BUTTON_CONFIRM);
116 okButton.setOnClickListener(new View.OnClickListener() { 105 okButton.setOnClickListener(new View.OnClickListener() {
117 @Override 106 @Override
118 public void onClick(View v) { 107 public void onClick(View v) {
119 boolean suppress = ((CheckBox) layout.findViewById( 108 boolean suppress = ((CheckBox) layout.findViewById(
120 AppResource.ID_JS_MODAL_DIALOG_CHECKBOX_SUPPRESS_DIALOGS )).isChecked(); 109 R.id.suppress_js_modal_dialogs)).isChecked();
121 110
122 assert AppResource.ID_JS_MODAL_DIALOG_TEXT_PROMPT != 0;
123 String prompt = ((TextView) layout.findViewById( 111 String prompt = ((TextView) layout.findViewById(
124 AppResource.ID_JS_MODAL_DIALOG_TEXT_PROMPT)).getText().t oString(); 112 R.id.js_modal_dialog_prompt)).getText().toString();
125 113
126 confirm(prompt, suppress); 114 confirm(prompt, suppress);
127 mDialog.dismiss(); 115 mDialog.dismiss();
128 } 116 }
129 }); 117 });
130 118
131 // Setup the Cancel button. 119 // Setup the Cancel button.
132 assert AppResource.ID_JS_MODAL_DIALOG_BUTTON_CANCEL != 0; 120 Button cancelButton = (Button) layout.findViewById(R.id.js_modal_dialog_ button_cancel);
133
134 Button cancelButton = (Button) layout.findViewById(
135 AppResource.ID_JS_MODAL_DIALOG_BUTTON_CANCEL);
136 cancelButton.setOnClickListener(new View.OnClickListener() { 121 cancelButton.setOnClickListener(new View.OnClickListener() {
137 @Override 122 @Override
138 public void onClick(View v) { 123 public void onClick(View v) {
139 boolean suppress = ((CheckBox) layout.findViewById( 124 boolean suppress = ((CheckBox) layout.findViewById(
140 AppResource.ID_JS_MODAL_DIALOG_CHECKBOX_SUPPRESS_DIALOGS )).isChecked(); 125 R.id.suppress_js_modal_dialogs)).isChecked();
141 cancel(suppress); 126 cancel(suppress);
142 mDialog.dismiss(); 127 mDialog.dismiss();
143 } 128 }
144 }); 129 });
145 130
146 // Display the checkbox for supressing dialogs if necessary. 131 // Display the checkbox for supressing dialogs if necessary.
147 layout.findViewById(AppResource.ID_JS_MODAL_DIALOG_CHECKBOX_SUPPRESS_DIA LOGS).setVisibility( 132 layout.findViewById(R.id.suppress_js_modal_dialogs).setVisibility(
148 mShouldShowSuppressCheckBox ? View.VISIBLE : View.GONE); 133 mShouldShowSuppressCheckBox ? View.VISIBLE : View.GONE);
149 } 134 }
150 135
151 public void confirm(String promptResult, boolean suppressDialogs) { 136 public void confirm(String promptResult, boolean suppressDialogs) {
152 nativeDidAcceptAppModalDialog(mNativeDialogPointer, promptResult, suppre ssDialogs); 137 nativeDidAcceptAppModalDialog(mNativeDialogPointer, promptResult, suppre ssDialogs);
153 } 138 }
154 139
155 public void cancel(boolean suppressDialogs) { 140 public void cancel(boolean suppressDialogs) {
156 nativeDidCancelAppModalDialog(mNativeDialogPointer, suppressDialogs); 141 nativeDidCancelAppModalDialog(mNativeDialogPointer, suppressDialogs);
157 } 142 }
158 143
159 private static class JavascriptAppAlertDialog extends JavascriptAppModalDial og { 144 private static class JavascriptAppAlertDialog extends JavascriptAppModalDial og {
160 public JavascriptAppAlertDialog(String title, String message, 145 public JavascriptAppAlertDialog(String title, String message,
161 boolean shouldShowSuppressCheckBox) { 146 boolean shouldShowSuppressCheckBox) {
162 super(title, message, shouldShowSuppressCheckBox); 147 super(title, message, shouldShowSuppressCheckBox);
163 } 148 }
164 149
165 @Override 150 @Override
166 public void prepare(ViewGroup layout) { 151 public void prepare(ViewGroup layout) {
167 super.prepare(layout); 152 super.prepare(layout);
168 layout.findViewById(AppResource.ID_JS_MODAL_DIALOG_BUTTON_CANCEL) 153 layout.findViewById(R.id.js_modal_dialog_button_cancel).setVisibilit y(View.GONE);
169 .setVisibility(View.GONE);
170 } 154 }
171 } 155 }
172 156
173 private static class JavascriptAppConfirmDialog extends JavascriptAppModalDi alog { 157 private static class JavascriptAppConfirmDialog extends JavascriptAppModalDi alog {
174 public JavascriptAppConfirmDialog(String title, String message, 158 public JavascriptAppConfirmDialog(String title, String message,
175 boolean shouldShowSuppressCheckBox) { 159 boolean shouldShowSuppressCheckBox) {
176 super(title, message, shouldShowSuppressCheckBox); 160 super(title, message, shouldShowSuppressCheckBox);
177 } 161 }
178 162
179 @Override 163 @Override
(...skipping 10 matching lines...) Expand all
190 super(title, message, shouldShowSuppressCheckBox); 174 super(title, message, shouldShowSuppressCheckBox);
191 mIsReload = isReload; 175 mIsReload = isReload;
192 } 176 }
193 177
194 @Override 178 @Override
195 public void prepare(ViewGroup layout) { 179 public void prepare(ViewGroup layout) {
196 super.prepare(layout); 180 super.prepare(layout);
197 181
198 // Cancel and confirm button resources are checked in 182 // Cancel and confirm button resources are checked in
199 // JavascriptAppModalDialog.prepare. 183 // JavascriptAppModalDialog.prepare.
200 assert AppResource.STRING_JS_MODAL_DIALOG_DONT_RELOAD_THIS_PAGE != 0 ;
201 assert AppResource.STRING_JS_MODAL_DIALOG_LEAVE_THIS_PAGE != 0;
202 assert AppResource.STRING_JS_MODAL_DIALOG_RELOAD_THIS_PAGE != 0;
203 assert AppResource.STRING_JS_MODAL_DIALOG_STAY_ON_THIS_PAGE != 0;
204
205 TextView stayOnThisPage = 184 TextView stayOnThisPage =
206 (TextView) layout.findViewById(AppResource.ID_JS_MODAL_DIALO G_BUTTON_CANCEL); 185 (TextView) layout.findViewById(R.id.js_modal_dialog_button_c ancel);
207 stayOnThisPage.setText(mIsReload ? 186 stayOnThisPage.setText(mIsReload ?
208 AppResource.STRING_JS_MODAL_DIALOG_DONT_RELOAD_THIS_PAGE : 187 R.string.dont_reload_this_page :
209 AppResource.STRING_JS_MODAL_DIALOG_STAY_ON_THIS_PAGE); 188 R.string.stay_on_this_page);
210 TextView leaveThisPage = 189 TextView leaveThisPage =
211 (TextView) layout.findViewById(AppResource.ID_JS_MODAL_DIALO G_BUTTON_CONFIRM); 190 (TextView) layout.findViewById(R.id.js_modal_dialog_button_c onfirm);
212 leaveThisPage.setText(mIsReload ? 191 leaveThisPage.setText(mIsReload ?
213 AppResource.STRING_JS_MODAL_DIALOG_RELOAD_THIS_PAGE : 192 R.string.reload_this_page :
214 AppResource.STRING_JS_MODAL_DIALOG_LEAVE_THIS_PAGE); 193 R.string.leave_this_page);
215 } 194 }
216 } 195 }
217 196
218 private static class JavascriptAppPromptDialog extends JavascriptAppModalDia log { 197 private static class JavascriptAppPromptDialog extends JavascriptAppModalDia log {
219 private String mDefaultPromptText; 198 private String mDefaultPromptText;
220 199
221 public JavascriptAppPromptDialog(String title, String message, 200 public JavascriptAppPromptDialog(String title, String message,
222 boolean shouldShowSuppressCheckBox, String defaultPromptText) { 201 boolean shouldShowSuppressCheckBox, String defaultPromptText) {
223 super(title, message, shouldShowSuppressCheckBox); 202 super(title, message, shouldShowSuppressCheckBox);
224 mDefaultPromptText = defaultPromptText; 203 mDefaultPromptText = defaultPromptText;
225 } 204 }
226 205
227 @Override 206 @Override
228 public void prepare(ViewGroup layout) { 207 public void prepare(ViewGroup layout) {
229 super.prepare(layout); 208 super.prepare(layout);
230 EditText prompt = (EditText) layout.findViewById( 209 EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialo g_prompt);
231 AppResource.ID_JS_MODAL_DIALOG_TEXT_PROMPT);
232 prompt.setVisibility(View.VISIBLE); 210 prompt.setVisibility(View.VISIBLE);
233 211
234 if (mDefaultPromptText.length() > 0) { 212 if (mDefaultPromptText.length() > 0) {
235 prompt.setText(mDefaultPromptText); 213 prompt.setText(mDefaultPromptText);
236 prompt.selectAll(); 214 prompt.selectAll();
237 } 215 }
238 } 216 }
239 } 217 }
240 218
241 private native void nativeDidAcceptAppModalDialog(int nativeJavascriptAppMod alDialogAndroid, 219 private native void nativeDidAcceptAppModalDialog(int nativeJavascriptAppMod alDialogAndroid,
242 String prompt, boolean suppress); 220 String prompt, boolean suppress);
243 221
244 private native void nativeDidCancelAppModalDialog(int nativeJavascriptAppMod alDialogAndroid, 222 private native void nativeDidCancelAppModalDialog(int nativeJavascriptAppMod alDialogAndroid,
245 boolean suppress); 223 boolean suppress);
246 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698