diff options
author | John Reck <jreck@google.com> | 2011-05-25 18:14:01 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-05-26 09:49:46 -0700 |
commit | 9b8cd1e564984874f2a6f5cc9bdc68cda8aa15ce (patch) | |
tree | 704f0d7ed1ea309f806b3a385fdeb44a5322636d /src/com/android/browser/widget/BookmarkWidgetConfigure.java | |
parent | 2814a362c21ac219410d9b54e1bd3e8152b845c7 (diff) | |
download | packages_apps_Browser-9b8cd1e564984874f2a6f5cc9bdc68cda8aa15ce.zip packages_apps_Browser-9b8cd1e564984874f2a6f5cc9bdc68cda8aa15ce.tar.gz packages_apps_Browser-9b8cd1e564984874f2a6f5cc9bdc68cda8aa15ce.tar.bz2 |
Configure bookmark widget
Add a configuration step when adding the bookmark widget to
pick what account to use
Change-Id: I2be723c411ec5b9f32d6819a5e2e65995921a252
Diffstat (limited to 'src/com/android/browser/widget/BookmarkWidgetConfigure.java')
-rw-r--r-- | src/com/android/browser/widget/BookmarkWidgetConfigure.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/com/android/browser/widget/BookmarkWidgetConfigure.java b/src/com/android/browser/widget/BookmarkWidgetConfigure.java new file mode 100644 index 0000000..4231f37 --- /dev/null +++ b/src/com/android/browser/widget/BookmarkWidgetConfigure.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser.widget; + +import android.app.ListActivity; +import android.app.LoaderManager.LoaderCallbacks; +import android.appwidget.AppWidgetManager; +import android.content.Intent; +import android.content.Loader; +import android.database.Cursor; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +import com.android.browser.AddBookmarkPage.AccountsLoader; +import com.android.browser.AddBookmarkPage.BookmarkAccount; +import com.android.browser.R; +import com.android.browser.provider.BrowserProvider2; + +public class BookmarkWidgetConfigure extends ListActivity + implements OnClickListener, LoaderCallbacks<Cursor> { + + static final int LOADER_ACCOUNTS = 1; + + private ArrayAdapter<BookmarkAccount> mAccountAdapter; + private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setResult(RESULT_CANCELED); + setVisible(false); + setContentView(R.layout.widget_account_selection); + findViewById(R.id.cancel).setOnClickListener(this); + mAccountAdapter = new ArrayAdapter<BookmarkAccount>(this, + android.R.layout.simple_list_item_1); + setListAdapter(mAccountAdapter); + Intent intent = getIntent(); + Bundle extras = intent.getExtras(); + if (extras != null) { + mAppWidgetId = extras.getInt( + AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } + if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { + finish(); + } else { + getLoaderManager().initLoader(LOADER_ACCOUNTS, null, this); + } + } + + @Override + public void onClick(View v) { + finish(); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + BookmarkAccount account = mAccountAdapter.getItem(position); + pickAccount(account.rootFolderId); + } + + @Override + public Loader<Cursor> onCreateLoader(int id, Bundle args) { + return new AccountsLoader(this); + } + + void pickAccount(long rootId) { + BookmarkThumbnailWidgetService.setupWidgetState(this, mAppWidgetId, rootId); + Intent result = new Intent(); + result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); + setResult(RESULT_OK, result); + finish(); + } + + @Override + public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { + if (cursor == null || cursor.getCount() <= 1) { + // We always have the local account, so if count == 1 it must + // be the local account + pickAccount(BrowserProvider2.FIXED_ID_ROOT); + } else { + mAccountAdapter.clear(); + while (cursor.moveToNext()) { + mAccountAdapter.add(new BookmarkAccount(this, cursor)); + } + setVisible(true); + } + getLoaderManager().destroyLoader(LOADER_ACCOUNTS); + } + + @Override + public void onLoaderReset(Loader<Cursor> loader) { + // Don't care + } + +} |