5package org.qtproject.qt.android;
7import android.app.Activity;
8import android.app.AlertDialog;
9import android.content.Context;
10import android.content.DialogInterface;
11import android.content.res.Resources;
12import android.content.res.TypedArray;
13import android.graphics.drawable.Drawable;
14import android.os.Build;
15import android.text.ClipboardManager;
16import android.text.Html;
17import android.text.Spanned;
18import android.util.TypedValue;
19import android.view.View;
20import android.widget.Button;
21import android.widget.ImageView;
22import android.widget.LinearLayout;
23import android.widget.RelativeLayout;
24import android.widget.ScrollView;
25import android.widget.TextView;
26import android.widget.Toast;
28import java.util.ArrayList;
30class QtNativeDialogHelper
32 static native
void dialogResult(
long handler,
int buttonID);
35class ButtonStruct
implements View.OnClickListener
37 ButtonStruct(QtMessageDialogHelper
dialog,
int id, String
text)
41 m_text = Html.fromHtml(
text);
43 QtMessageDialogHelper m_dialog;
49 QtNativeDialogHelper.dialogResult(m_dialog.handler(), m_id);
58 m_activity = activity;
64 m_standardIcon =
icon;
70 if (m_standardIcon == 0)
74 TypedValue typedValue =
new TypedValue();
75 m_theme.resolveAttribute(android.R.attr.alertDialogIcon, typedValue,
true);
76 return m_activity.getResources().getDrawable(typedValue.resourceId,
77 m_activity.getTheme());
78 }
catch (Exception
e) {
83 switch (m_standardIcon)
87 return m_activity.getResources().getDrawable(android.R.drawable.ic_dialog_info,
88 m_activity.getTheme());
89 }
catch (Exception
e) {
102 return m_activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert,
103 m_activity.getTheme());
104 }
catch (Exception
e) {
110 return m_activity.getResources().getDrawable(android.R.drawable.ic_menu_help,
111 m_activity.getTheme());
112 }
catch (Exception
e) {
122 m_title = Html.fromHtml(
title);
127 m_text = Html.fromHtml(
text);
132 m_informativeText = Html.fromHtml(informativeText);
137 m_detailedText = Html.fromHtml(
text);
142 if (m_buttonsList ==
null)
143 m_buttonsList =
new ArrayList<ButtonStruct>();
144 m_buttonsList.add(
new ButtonStruct(
this,
id,
text));
147 private Drawable getStyledDrawable(String drawable)
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
149 int[]
attrs = {Class.forName(
"android.R$attr").getDeclaredField(drawable).getInt(
null)};
150 final TypedArray
a = m_theme.obtainStyledAttributes(
attrs);
160 m_activity.runOnUiThread(
new Runnable() {
163 if (m_dialog !=
null && m_dialog.isShowing())
166 m_dialog =
new AlertDialog.Builder(m_activity).create();
167 m_theme = m_dialog.getWindow().getContext().getTheme();
170 m_dialog.setTitle(m_title);
171 m_dialog.setOnCancelListener(
new DialogInterface.OnCancelListener() {
173 public void onCancel(DialogInterface dialogInterface) {
174 QtNativeDialogHelper.dialogResult(handler(), -1);
177 m_dialog.setCancelable(m_buttonsList ==
null);
178 m_dialog.setCanceledOnTouchOutside(m_buttonsList ==
null);
179 m_dialog.setIcon(getIconDrawable());
180 ScrollView scrollView =
new ScrollView(m_activity);
181 RelativeLayout dialogLayout =
new RelativeLayout(m_activity);
183 View lastView =
null;
184 View.OnLongClickListener copyText =
new View.OnLongClickListener() {
186 public boolean onLongClick(View
view) {
187 TextView tv = (TextView)
view;
189 ClipboardManager cm = (android.text.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
190 cm.setText(tv.getText());
197 TextView
view =
new TextView(m_activity);
199 view.setOnLongClickListener(copyText);
200 view.setLongClickable(
true);
202 view.setText(m_text);
203 view.setTextAppearance(m_activity, android.R.style.TextAppearance_Medium);
205 RelativeLayout.LayoutParams
layout =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
206 layout.setMargins(16, 8, 16, 8);
207 layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
212 if (m_informativeText !=
null)
214 TextView
view=
new TextView(m_activity);
216 view.setOnLongClickListener(copyText);
217 view.setLongClickable(
true);
219 view.setText(m_informativeText);
220 view.setTextAppearance(m_activity, android.R.style.TextAppearance_Medium);
222 RelativeLayout.LayoutParams
layout =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
223 layout.setMargins(16, 8, 16, 8);
224 if (lastView !=
null)
225 layout.addRule(RelativeLayout.BELOW, lastView.getId());
227 layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
232 if (m_detailedText !=
null)
234 TextView
view=
new TextView(m_activity);
236 view.setOnLongClickListener(copyText);
237 view.setLongClickable(
true);
239 view.setText(m_detailedText);
240 view.setTextAppearance(m_activity, android.R.style.TextAppearance_Small);
242 RelativeLayout.LayoutParams
layout =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
243 layout.setMargins(16, 8, 16, 8);
244 if (lastView !=
null)
245 layout.addRule(RelativeLayout.BELOW, lastView.getId());
247 layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
252 if (m_buttonsList !=
null)
254 LinearLayout buttonsLayout =
new LinearLayout(m_activity);
255 buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);
256 buttonsLayout.setId(
id++);
257 boolean firstButton =
true;
258 for (ButtonStruct
button: m_buttonsList)
262 bv =
new Button(m_activity,
null, Class.forName(
"android.R$attr").getDeclaredField(
"borderlessButtonStyle").getInt(
null));
263 }
catch (Exception
e) {
264 bv =
new Button(m_activity);
268 bv.setText(
button.m_text);
269 bv.setOnClickListener(
button);
272 LinearLayout.LayoutParams
layout =
null;
273 View spacer =
new View(m_activity);
275 layout =
new LinearLayout.LayoutParams(1, RelativeLayout.LayoutParams.MATCH_PARENT);
276 spacer.setBackgroundDrawable(getStyledDrawable(
"dividerVertical"));
277 buttonsLayout.addView(spacer,
layout);
278 }
catch (Exception
e) {
282 LinearLayout.LayoutParams
layout =
null;
283 layout =
new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT, 1.0f);
284 buttonsLayout.addView(bv,
layout);
289 View horizontalDevider =
new View(m_activity);
290 horizontalDevider.setId(
id++);
291 horizontalDevider.setBackgroundDrawable(getStyledDrawable(
"dividerHorizontal"));
292 RelativeLayout.LayoutParams relativeParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 1);
293 relativeParams.setMargins(0, 10, 0, 0);
294 if (lastView !=
null) {
295 relativeParams.addRule(RelativeLayout.BELOW, lastView.getId());
298 relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
299 dialogLayout.addView(horizontalDevider, relativeParams);
300 lastView = horizontalDevider;
301 }
catch (Exception
e) {
304 RelativeLayout.LayoutParams relativeParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
305 if (lastView !=
null) {
306 relativeParams.addRule(RelativeLayout.BELOW, lastView.getId());
309 relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
310 relativeParams.setMargins(2, 0, 2, 0);
311 dialogLayout.addView(buttonsLayout, relativeParams);
313 scrollView.addView(dialogLayout);
314 m_dialog.setView(scrollView);
322 m_activity.runOnUiThread(
new Runnable() {
325 if (m_dialog !=
null && m_dialog.isShowing())
342 m_informativeText =
null;
343 m_detailedText =
null;
344 m_buttonsList =
null;
349 private Activity m_activity;
350 private int m_standardIcon = 0;
351 private Spanned m_title, m_text, m_informativeText, m_detailedText;
352 private ArrayList<ButtonStruct> m_buttonsList;
353 private AlertDialog m_dialog;
354 private long m_handler = 0;
355 private Resources.Theme m_theme;
void setText(String text)
void addButton(int id, String text)
void setInformativeText(String informativeText)
void setTile(String title)
void setDetailedText(String text)
QtMessageDialogHelper(Activity activity)
void setStandardIcon(int icon)
static struct AttrInfo attrs[]
GLboolean GLboolean GLboolean GLboolean a
[7]
QFileDialog dialog(this)
[1]