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

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

Issue 12045081: Android implementation of WebsiteSettingsUi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix memory leak Created 7 years, 11 months 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
(Empty)
1 // Copyright (c) 2013 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.chrome.browser;
6
7 import android.app.Dialog;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.content.Intent;
11 import android.graphics.Bitmap;
12 import android.graphics.Color;
13 import android.graphics.Typeface;
14 import android.provider.Browser;
15 import android.text.Html;
16 import android.view.LayoutInflater;
17 import android.view.View;
18 import android.view.View.OnClickListener;
19 import android.view.ViewGroup.LayoutParams;
20 import android.view.Window;
21 import android.widget.ImageView;
22 import android.widget.LinearLayout;
23 import android.widget.ScrollView;
24 import android.widget.TextView;
25
26 import org.chromium.base.CalledByNative;
27 import org.chromium.chrome.R;
28 import org.chromium.content.browser.ContentViewCore;
29
30 import java.net.URISyntaxException;
31
32 /**
33 * Java side of Android implementation of the website settings UI.
34 */
35 public class WebsiteSettingsPopup implements OnClickListener {
36 private static final String HELP_URL =
37 "http://www.google.com/support/chrome/bin/answer.py?answer=95617";
38 private final Context mContext;
39 private final Dialog mDialog;
40 private final LinearLayout mContainer;
41 private TextView mCertificateViewer, mMoreInfoLink;
42 private String mLinkUrl;
43 ContentViewCore mContentViewCore;
Ted C 2013/01/25 02:04:05 private?
Yaron 2013/01/25 19:25:17 Done.
44 private final int mPadding;
45
46 WebsiteSettingsPopup(Context context, ContentViewCore contentViewCore,
47 final int nativeWebsiteSettingsPopup) {
48 mContext = context;
49 mDialog = new Dialog(mContext);
50 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
51 mDialog.setCanceledOnTouchOutside(true);
52 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
53 @Override
54 public void onCancel(DialogInterface dialogInterface) {
55 assert nativeWebsiteSettingsPopup != 0;
56 nativeDestroy(nativeWebsiteSettingsPopup);
57 }
58 });
59 mContainer = new LinearLayout(mContext);
60 mContainer.setOrientation(LinearLayout.VERTICAL);
61 mContentViewCore = contentViewCore;
62 mPadding = (int) context.getResources().getDimension(R.dimen.certificate _viewer_padding);
63 mContainer.setPadding(mPadding, 0, mPadding, 0);
64 }
65
66 /** Adds a section, which contains an icon, a headline, and a description. * /
67 @CalledByNative
68 void addSection(Bitmap icon, String headline, String description) {
69 View section = LayoutInflater.from(mContext).inflate(R.layout.website_se ttings, null);
70 ImageView i = (ImageView) section.findViewById(R.id.website_settings_ico n);
71 i.setImageBitmap(icon);
72 TextView h = (TextView) section.findViewById(R.id.website_settings_headl ine);
73 h.setText(headline);
74 h.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
Ted C 2013/01/25 02:04:05 any reason it's not configured to be bold in the x
Yaron 2013/01/25 19:25:17 Done.
75 if (headline == null || headline.length() == 0) h.setVisibility(View.GON E);
Ted C 2013/01/25 02:04:05 TextUtils.isEmpty(headline)
Yaron 2013/01/25 19:25:17 Done.
76
77 TextView d = (TextView) section.findViewById(R.id.website_settings_descr iption);
78 d.setText(description);
79 if (description == null || description.length() == 0) d.setVisibility(Vi ew.GONE);
Ted C 2013/01/25 02:04:05 same thing here about TextUtils.
Yaron 2013/01/25 19:25:17 Done.
80
81 mContainer.addView(section);
82 }
83
84 /** Adds a horizontal dividing line to separate sections. */
85 @CalledByNative
86 void addDivider() {
Ted C 2013/01/25 02:04:05 private?
Yaron 2013/01/25 19:25:17 Done.
87 View divider = new View(mContext);
88 divider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 2));
Ted C 2013/01/25 02:04:05 should the 2 be in DP or pixels?
Yaron 2013/01/25 19:25:17 I guess dp?
89 divider.setBackgroundColor(Color.GRAY);
90 mContainer.addView(divider);
91 }
92
93 @CalledByNative
94 private void setCertificateViewer(String label) {
95 assert mCertificateViewer == null;
96 mCertificateViewer = new TextView(mContext);
97 mCertificateViewer.setText(Html.fromHtml("<a href='#'>" + label + "</a>" ));
98 mCertificateViewer.setOnClickListener(this);
99 mCertificateViewer.setPadding(0, 0, 0, mPadding);
100 mContainer.addView(mCertificateViewer);
101 }
102
103 @CalledByNative
104 private void addMoreInfoLink() {
105 addUrl(mContext.getResources().getString(R.string.website_settings_more_ info),
106 HELP_URL);
Ted C 2013/01/25 02:04:05 I think this is only indented 7 instead of 8.
Yaron 2013/01/25 19:25:17 Done.
107 }
108
109 /** Adds a section containing a description and a hyperlink. */
110 void addUrl(String label, String url) {
Ted C 2013/01/25 02:04:05 private?
Yaron 2013/01/25 19:25:17 Done.
111 mMoreInfoLink = new TextView(mContext);
112 mLinkUrl = url;
113 mMoreInfoLink.setText(Html.fromHtml("<a href='#'>" + label + "</a>"));
114 mMoreInfoLink.setPadding(0, mPadding, 0, mPadding);
115 mMoreInfoLink.setOnClickListener(this);
116 mContainer.addView(mMoreInfoLink);
117 }
118
119 /** Displays the WebsiteSettingsPopup. */
120 @CalledByNative
121 void show() {
Ted C 2013/01/25 02:04:05 private
Yaron 2013/01/25 19:25:17 Done.
122 ScrollView scrollView = new ScrollView(mContext);
123 scrollView.addView(mContainer);
124 mDialog.addContentView(scrollView,
125 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA RENT,
126 LinearLayout.LayoutParams.MATCH_PA RENT));
Ted C 2013/01/25 02:04:05 same thing here too..should be indented 8 from pre
Yaron 2013/01/25 19:25:17 Done.
127 mDialog.show();
128 }
129
130 @Override
131 public void onClick(View v) {
132 mDialog.dismiss();
133 if (mCertificateViewer == v) {
134 byte[][] certChain = nativeGetCertChain(mContentViewCore);
135 CertificateViewer.showCertChain(mContext, certChain);
136 } else if (mMoreInfoLink == v) {
137 try {
138 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
139 i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
140 i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName ());
141 mContext.startActivity(i);
142 } catch (URISyntaxException ex) {}
143 }
144 }
145
146 @CalledByNative
147 private static WebsiteSettingsPopup create(Context context, ContentViewCore contentViewCore,
148 int nativeWebsiteSettingsPopup) {
149 return new WebsiteSettingsPopup(context, contentViewCore, nativeWebsiteS ettingsPopup);
150 }
151
152 private native void nativeDestroy(int nativeWebsiteSettingsPopupAndroid);
153 private native byte[][] nativeGetCertChain(ContentViewCore contentViewCore);
154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698