OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.webapk.shell_apk; | |
6 | |
7 import android.app.AlertDialog; | |
8 import android.content.Context; | |
9 import android.content.DialogInterface; | |
10 import android.view.ContextThemeWrapper; | |
11 import android.view.LayoutInflater; | |
12 import android.view.View; | |
13 import android.widget.ImageView; | |
14 import android.widget.TextView; | |
15 | |
16 /** Shows the dialog to install a host browser for launching WebAPK. */ | |
17 public class InstallHostBrowserDialog { | |
18 /** | |
19 * A listener to receive updates when user chooses to install the host brows er, or dismisses the | |
20 * dialog. | |
pkotwicz
2017/06/05 19:18:20
Nit: "A listener to receive updates" -> "A listene
Xi Han
2017/06/06 15:12:28
Done.
| |
21 */ | |
22 public interface DialogListener { | |
23 void onConfirmInstall(String packageName); | |
24 void onConfirmQuit(); | |
25 } | |
26 | |
27 /** | |
28 * Shows the dialog to install a host browser. | |
29 * @param context The current context. | |
30 * @param listener The listener for the dialog. | |
31 * @param url URL of the WebAPK for which the dialog is shown. | |
32 * @param hostBrowserPackageName The package name of the host browser. | |
33 * @param hostBrowserApplicationName The application name of the host browse r. | |
34 * @param hostBrowserIconId The resource id of the icon of the host browser. | |
35 */ | |
36 public static void show(Context context, final DialogListener listener, Stri ng url, | |
37 final String hostBrowserPackageName, String hostBrowserApplicationNa me, | |
38 int hostBrowserIconId) { | |
39 View view = LayoutInflater.from(context).inflate( | |
40 R.layout.choose_host_browser_dialog_list, null); | |
41 TextView name = (TextView) view.findViewById(R.id.browser_name); | |
42 ImageView icon = (ImageView) view.findViewById(R.id.browser_icon); | |
43 | |
44 name.setText(hostBrowserApplicationName); | |
45 icon.setImageResource(hostBrowserIconId); | |
46 | |
47 AlertDialog.Builder builder = new AlertDialog.Builder( | |
48 new ContextThemeWrapper(context, android.R.style.Theme_DeviceDef ault_Light_Dialog)); | |
49 builder.setTitle(context.getString(R.string.install_host_browser_dialog_ title, url)) | |
50 .setView(view) | |
51 .setNegativeButton(R.string.choose_host_browser_dialog_quit, | |
52 new DialogInterface.OnClickListener() { | |
53 @Override | |
54 public void onClick(DialogInterface dialog, int whic h) { | |
55 listener.onConfirmQuit(); | |
56 } | |
57 }) | |
58 .setPositiveButton(R.string.install_host_browser_dialog_install_ button, | |
59 new DialogInterface.OnClickListener() { | |
60 @Override | |
61 public void onClick(DialogInterface dialog, int whic h) { | |
62 listener.onConfirmInstall(hostBrowserPackageName ); | |
63 } | |
64 }); | |
65 | |
66 AlertDialog dialog = builder.create(); | |
67 dialog.show(); | |
68 }; | |
69 } | |
OLD | NEW |