Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.app.AlertDialog; |
| 20 | import android.app.ListActivity; |
| 21 | import android.content.Context; |
| 22 | import android.content.DialogInterface; |
| 23 | import android.database.Cursor; |
| 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.BitmapFactory; |
| 26 | import android.net.Uri; |
| 27 | import android.os.Bundle; |
| 28 | import android.provider.Browser; |
| 29 | import android.util.Log; |
| 30 | import android.view.KeyEvent; |
| 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 34 | import android.webkit.GeolocationPermissions; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 35 | import android.webkit.WebIconDatabase; |
| 36 | import android.webkit.WebStorage; |
| 37 | import android.widget.ArrayAdapter; |
| 38 | import android.widget.AdapterView; |
| 39 | import android.widget.AdapterView.OnItemClickListener; |
| 40 | import android.widget.ImageView; |
| 41 | import android.widget.TextView; |
| 42 | |
| 43 | import java.util.HashMap; |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 44 | import java.util.HashSet; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 45 | import java.util.Iterator; |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 46 | import java.util.Map; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 47 | import java.util.Set; |
| 48 | import java.util.Vector; |
| 49 | |
| 50 | /** |
| 51 | * Manage the settings for an origin. |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 52 | * We use it to keep track of the 'HTML5' settings, i.e. database (webstorage) |
| 53 | * and Geolocation. |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 54 | */ |
| 55 | public class WebsiteSettingsActivity extends ListActivity { |
| 56 | |
| 57 | private String LOGTAG = "WebsiteSettingsActivity"; |
| 58 | private static String sMBStored = null; |
| 59 | private SiteAdapter mAdapter = null; |
| 60 | |
| 61 | class Site { |
| 62 | private String mOrigin; |
| 63 | private String mTitle; |
| 64 | private Bitmap mIcon; |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 65 | private int mFeatures; |
| 66 | |
| 67 | // These constants provide the set of features that a site may support |
| 68 | // They must be consecutive. To add a new feature, add a new FEATURE_XXX |
| 69 | // variable with value equal to the current value of FEATURE_COUNT, then |
| 70 | // increment FEATURE_COUNT. |
| 71 | private final static int FEATURE_WEB_STORAGE = 0; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 72 | private final static int FEATURE_GEOLOCATION = 1; |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 73 | // The number of features available. |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 74 | private final static int FEATURE_COUNT = 2; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 75 | |
Steve Block | 1ad98cf | 2009-07-28 11:07:10 +0100 | [diff] [blame] | 76 | public Site(String origin) { |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 77 | mOrigin = origin; |
Steve Block | 1ad98cf | 2009-07-28 11:07:10 +0100 | [diff] [blame] | 78 | mTitle = null; |
| 79 | mIcon = null; |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 80 | mFeatures = 0; |
| 81 | } |
| 82 | |
| 83 | public void addFeature(int feature) { |
| 84 | mFeatures |= (1 << feature); |
| 85 | } |
| 86 | |
| 87 | public boolean hasFeature(int feature) { |
| 88 | return (mFeatures & (1 << feature)) != 0; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the number of features supported by this site. |
| 93 | */ |
| 94 | public int getFeatureCount() { |
| 95 | int count = 0; |
| 96 | for (int i = 0; i < FEATURE_COUNT; ++i) { |
| 97 | count += hasFeature(i) ? 1 : 0; |
| 98 | } |
| 99 | return count; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Gets the ID of the nth (zero-based) feature supported by this site. |
| 104 | * The return value is a feature ID - one of the FEATURE_XXX values. |
| 105 | * This is required to determine which feature is displayed at a given |
| 106 | * position in the list of features for this site. This is used both |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 107 | * when populating the view and when responding to clicks on the list. |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 108 | */ |
| 109 | public int getFeatureByIndex(int n) { |
| 110 | int j = -1; |
| 111 | for (int i = 0; i < FEATURE_COUNT; ++i) { |
| 112 | j += hasFeature(i) ? 1 : 0; |
| 113 | if (j == n) { |
| 114 | return i; |
| 115 | } |
| 116 | } |
| 117 | return -1; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public String getOrigin() { |
| 121 | return mOrigin; |
| 122 | } |
| 123 | |
| 124 | public void setTitle(String title) { |
| 125 | mTitle = title; |
| 126 | } |
| 127 | |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 128 | public void setIcon(Bitmap icon) { |
| 129 | mIcon = icon; |
| 130 | } |
| 131 | |
| 132 | public Bitmap getIcon() { |
| 133 | return mIcon; |
| 134 | } |
Steve Block | 1ad98cf | 2009-07-28 11:07:10 +0100 | [diff] [blame] | 135 | |
| 136 | public String getPrettyOrigin() { |
| 137 | return mTitle == null ? null : hideHttp(mOrigin); |
| 138 | } |
| 139 | |
| 140 | public String getPrettyTitle() { |
| 141 | return mTitle == null ? hideHttp(mOrigin) : mTitle; |
| 142 | } |
| 143 | |
| 144 | private String hideHttp(String str) { |
| 145 | Uri uri = Uri.parse(str); |
| 146 | return "http".equals(uri.getScheme()) ? str.substring(7) : str; |
| 147 | } |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | class SiteAdapter extends ArrayAdapter<Site> |
| 151 | implements AdapterView.OnItemClickListener { |
| 152 | private int mResource; |
| 153 | private LayoutInflater mInflater; |
| 154 | private Bitmap mDefaultIcon; |
| 155 | private Site mCurrentSite; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 156 | |
| 157 | public SiteAdapter(Context context, int rsc) { |
| 158 | super(context, rsc); |
| 159 | mResource = rsc; |
| 160 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 161 | mDefaultIcon = BitmapFactory.decodeResource(getResources(), |
| 162 | R.drawable.ic_launcher_shortcut_browser_bookmark); |
| 163 | populateOrigins(); |
| 164 | } |
| 165 | |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 166 | /** |
| 167 | * Adds the specified feature to the site corresponding to supplied |
| 168 | * origin in the map. Creates the site if it does not already exist. |
| 169 | */ |
| 170 | private void addFeatureToSite(Map sites, String origin, int feature) { |
| 171 | Site site = null; |
| 172 | if (sites.containsKey(origin)) { |
| 173 | site = (Site) sites.get(origin); |
| 174 | } else { |
| 175 | site = new Site(origin); |
| 176 | sites.put(origin, site); |
| 177 | } |
| 178 | site.addFeature(feature); |
| 179 | } |
| 180 | |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 181 | public void populateOrigins() { |
| 182 | clear(); |
| 183 | |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 184 | // Get the list of origins we want to display. |
| 185 | // All 'HTML 5 modules' (Database, Geolocation etc) form these |
| 186 | // origin strings using WebCore::SecurityOrigin::toString(), so it's |
| 187 | // safe to group origins here. Note that WebCore::SecurityOrigin |
| 188 | // uses 0 (which is not printed) for the port if the port is the |
| 189 | // default for the protocol. Eg http://www.google.com and |
| 190 | // http://www.google.com:80 both record a port of 0 and hence |
| 191 | // toString() == 'http://www.google.com' for both. |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 192 | Set origins = WebStorage.getInstance().getOrigins(); |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 193 | Map sites = new HashMap<String, Site>(); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 194 | if (origins != null) { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 195 | Iterator<String> iter = origins.iterator(); |
| 196 | while (iter.hasNext()) { |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 197 | addFeatureToSite(sites, iter.next(), Site.FEATURE_WEB_STORAGE); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 198 | } |
| 199 | } |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 200 | origins = GeolocationPermissions.getInstance().getOrigins(); |
| 201 | if (origins != null) { |
| 202 | Iterator<String> iter = origins.iterator(); |
| 203 | while (iter.hasNext()) { |
| 204 | addFeatureToSite(sites, iter.next(), Site.FEATURE_GEOLOCATION); |
| 205 | } |
| 206 | } |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 207 | |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 208 | // Create a map from host to origin. This is used to add metadata |
| 209 | // (title, icon) for this origin from the bookmarks DB. |
| 210 | HashMap hosts = new HashMap<String, Set<Site> >(); |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 211 | Set keys = sites.keySet(); |
| 212 | Iterator<String> originIter = keys.iterator(); |
| 213 | while (originIter.hasNext()) { |
| 214 | String origin = originIter.next(); |
| 215 | Site site = (Site) sites.get(origin); |
| 216 | String host = Uri.parse(origin).getHost(); |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 217 | Set hostSites = null; |
| 218 | if (hosts.containsKey(host)) { |
| 219 | hostSites = (Set) hosts.get(host); |
| 220 | } else { |
| 221 | hostSites = new HashSet<Site>(); |
| 222 | hosts.put(host, hostSites); |
| 223 | } |
| 224 | hostSites.add(site); |
| 225 | } |
| 226 | |
| 227 | // Check the bookmark DB. If we have data for a host used by any of |
| 228 | // our origins, use it to set their title and favicon |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 229 | Cursor c = getContext().getContentResolver().query(Browser.BOOKMARKS_URI, |
| 230 | new String[] { Browser.BookmarkColumns.URL, Browser.BookmarkColumns.TITLE, |
| 231 | Browser.BookmarkColumns.FAVICON }, "bookmark = 1", null, null); |
| 232 | |
| 233 | if ((c != null) && c.moveToFirst()) { |
| 234 | int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); |
| 235 | int titleIndex = c.getColumnIndex(Browser.BookmarkColumns.TITLE); |
| 236 | int faviconIndex = c.getColumnIndex(Browser.BookmarkColumns.FAVICON); |
| 237 | do { |
| 238 | String url = c.getString(urlIndex); |
| 239 | String host = Uri.parse(url).getHost(); |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 240 | if (hosts.containsKey(host)) { |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 241 | String title = c.getString(titleIndex); |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 242 | Bitmap bmp = null; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 243 | byte[] data = c.getBlob(faviconIndex); |
| 244 | if (data != null) { |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 245 | bmp = BitmapFactory.decodeByteArray(data, 0, data.length); |
| 246 | } |
| 247 | Set matchingSites = (Set) hosts.get(host); |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 248 | Iterator<Site> sitesIter = matchingSites.iterator(); |
Steve Block | ee0d639 | 2009-07-28 13:49:15 +0100 | [diff] [blame] | 249 | while (sitesIter.hasNext()) { |
| 250 | Site site = sitesIter.next(); |
| 251 | site.setTitle(title); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 252 | if (bmp != null) { |
| 253 | site.setIcon(bmp); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | } while (c.moveToNext()); |
| 258 | } |
| 259 | |
| 260 | // We can now simply populate our array with Site instances |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 261 | keys = sites.keySet(); |
| 262 | originIter = keys.iterator(); |
| 263 | while (originIter.hasNext()) { |
| 264 | String origin = originIter.next(); |
| 265 | Site site = (Site) sites.get(origin); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 266 | add(site); |
| 267 | } |
| 268 | |
| 269 | if (getCount() == 0) { |
| 270 | finish(); // we close the screen |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | public int getCount() { |
| 275 | if (mCurrentSite == null) { |
| 276 | return super.getCount(); |
| 277 | } |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 278 | return mCurrentSite.getFeatureCount(); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Steve Block | 764f0c9 | 2009-09-10 15:01:37 +0100 | [diff] [blame^] | 281 | public String sizeValueToString(long bytes) { |
| 282 | // We display the size in MB, to 1dp, rounding up to the next 0.1MB. |
| 283 | // bytes should always be greater than zero. |
| 284 | if (bytes <= 0) { |
| 285 | Log.e(LOGTAG, "sizeValueToString called with non-positive value"); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 286 | return "0"; |
| 287 | } |
Steve Block | 764f0c9 | 2009-09-10 15:01:37 +0100 | [diff] [blame^] | 288 | float megabytes = (float) bytes / (1024.0F * 1024.0F); |
| 289 | int truncated = (int) Math.ceil(megabytes * 10.0F); |
| 290 | float result = (float) (truncated / 10.0F); |
| 291 | return String.valueOf(result); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* |
| 295 | * If we receive the back event and are displaying |
| 296 | * site's settings, we want to go back to the main |
| 297 | * list view. If not, we just do nothing (see |
| 298 | * dispatchKeyEvent() below). |
| 299 | */ |
| 300 | public boolean backKeyPressed() { |
| 301 | if (mCurrentSite != null) { |
| 302 | mCurrentSite = null; |
| 303 | populateOrigins(); |
| 304 | notifyDataSetChanged(); |
| 305 | return true; |
| 306 | } |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | public View getView(int position, View convertView, ViewGroup parent) { |
| 311 | View view; |
| 312 | TextView title; |
| 313 | TextView subtitle; |
| 314 | ImageView icon; |
| 315 | |
| 316 | if (convertView == null) { |
| 317 | view = mInflater.inflate(mResource, parent, false); |
| 318 | } else { |
| 319 | view = convertView; |
| 320 | } |
| 321 | |
| 322 | title = (TextView) view.findViewById(R.id.title); |
| 323 | subtitle = (TextView) view.findViewById(R.id.subtitle); |
| 324 | icon = (ImageView) view.findViewById(R.id.icon); |
| 325 | |
| 326 | if (mCurrentSite == null) { |
Steve Block | 4d055a5 | 2009-07-31 08:38:58 +0100 | [diff] [blame] | 327 | setTitle(getString(R.string.pref_extras_website_settings)); |
| 328 | |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 329 | Site site = getItem(position); |
Steve Block | 1ad98cf | 2009-07-28 11:07:10 +0100 | [diff] [blame] | 330 | title.setText(site.getPrettyTitle()); |
| 331 | subtitle.setText(site.getPrettyOrigin()); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 332 | icon.setVisibility(View.VISIBLE); |
| 333 | Bitmap bmp = site.getIcon(); |
| 334 | if (bmp == null) { |
| 335 | bmp = mDefaultIcon; |
| 336 | } |
| 337 | icon.setImageBitmap(bmp); |
| 338 | // We set the site as the view's tag, |
| 339 | // so that we can get it in onItemClick() |
| 340 | view.setTag(site); |
| 341 | } else { |
Steve Block | 4d055a5 | 2009-07-31 08:38:58 +0100 | [diff] [blame] | 342 | setTitle(mCurrentSite.getPrettyTitle()); |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 343 | icon.setVisibility(View.GONE); |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 344 | String origin = mCurrentSite.getOrigin(); |
| 345 | switch (mCurrentSite.getFeatureByIndex(position)) { |
| 346 | case Site.FEATURE_WEB_STORAGE: |
| 347 | long usageValue = WebStorage.getInstance().getUsageForOrigin(origin); |
| 348 | String usage = sizeValueToString(usageValue) + " " + sMBStored; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 349 | |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 350 | title.setText(R.string.webstorage_clear_data_title); |
| 351 | subtitle.setText(usage); |
| 352 | break; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 353 | case Site.FEATURE_GEOLOCATION: |
| 354 | title.setText(R.string.geolocation_settings_page_title); |
| 355 | boolean allowed = GeolocationPermissions.getInstance().getAllowed(origin); |
| 356 | subtitle.setText(allowed ? |
| 357 | R.string.geolocation_settings_page_summary_allowed : |
| 358 | R.string.geolocation_settings_page_summary_not_allowed); |
| 359 | break; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | return view; |
| 364 | } |
| 365 | |
| 366 | public void onItemClick(AdapterView<?> parent, |
| 367 | View view, |
| 368 | int position, |
| 369 | long id) { |
| 370 | if (mCurrentSite != null) { |
Steve Block | 089ce3a | 2009-07-29 17:16:01 +0100 | [diff] [blame] | 371 | switch (mCurrentSite.getFeatureByIndex(position)) { |
| 372 | case Site.FEATURE_WEB_STORAGE: |
| 373 | new AlertDialog.Builder(getContext()) |
| 374 | .setTitle(R.string.webstorage_clear_data_dialog_title) |
| 375 | .setMessage(R.string.webstorage_clear_data_dialog_message) |
| 376 | .setPositiveButton(R.string.webstorage_clear_data_dialog_ok_button, |
| 377 | new AlertDialog.OnClickListener() { |
| 378 | public void onClick(DialogInterface dlg, int which) { |
| 379 | WebStorage.getInstance().deleteOrigin(mCurrentSite.getOrigin()); |
| 380 | mCurrentSite = null; |
| 381 | populateOrigins(); |
| 382 | notifyDataSetChanged(); |
| 383 | }}) |
| 384 | .setNegativeButton(R.string.webstorage_clear_data_dialog_cancel_button, null) |
| 385 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 386 | .show(); |
| 387 | break; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 388 | case Site.FEATURE_GEOLOCATION: |
| 389 | new AlertDialog.Builder(getContext()) |
| 390 | .setTitle(R.string.geolocation_settings_page_dialog_title) |
| 391 | .setMessage(R.string.geolocation_settings_page_dialog_message) |
| 392 | .setPositiveButton(R.string.geolocation_settings_page_dialog_ok_button, |
| 393 | new AlertDialog.OnClickListener() { |
| 394 | public void onClick(DialogInterface dlg, int which) { |
| 395 | GeolocationPermissions.getInstance().clear(mCurrentSite.getOrigin()); |
| 396 | mCurrentSite = null; |
| 397 | populateOrigins(); |
| 398 | notifyDataSetChanged(); |
| 399 | }}) |
| 400 | .setNegativeButton(R.string.geolocation_settings_page_dialog_cancel_button, null) |
| 401 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 402 | .show(); |
| 403 | break; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 404 | } |
| 405 | } else { |
| 406 | mCurrentSite = (Site) view.getTag(); |
| 407 | notifyDataSetChanged(); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Intercepts the back key to immediately notify |
| 414 | * NativeDialog that we are done. |
| 415 | */ |
| 416 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 417 | if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) |
| 418 | && (event.getAction() == KeyEvent.ACTION_DOWN)) { |
| 419 | if ((mAdapter != null) && (mAdapter.backKeyPressed())){ |
| 420 | return true; // event consumed |
| 421 | } |
| 422 | } |
| 423 | return super.dispatchKeyEvent(event); |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | protected void onCreate(Bundle icicle) { |
| 428 | super.onCreate(icicle); |
| 429 | if (sMBStored == null) { |
| 430 | sMBStored = getString(R.string.webstorage_origin_summary_mb_stored); |
| 431 | } |
| 432 | mAdapter = new SiteAdapter(this, R.layout.application); |
| 433 | setListAdapter(mAdapter); |
| 434 | getListView().setOnItemClickListener(mAdapter); |
| 435 | } |
| 436 | } |