diff options
author | Michael Kolb <kolby@google.com> | 2010-08-25 12:57:38 -0700 |
---|---|---|
committer | Michael Kolb <kolby@google.com> | 2010-08-25 13:00:32 -0700 |
commit | 801ecb73006a3062cdfeacf7ad6016e0a358671c (patch) | |
tree | fdada90c88698f5ea20f0a2bcaa40e13262da655 | |
parent | 0998b0a02bcb8606881df8ed6ae204b5367ca4f9 (diff) | |
download | packages_apps_Browser-801ecb73006a3062cdfeacf7ad6016e0a358671c.zip packages_apps_Browser-801ecb73006a3062cdfeacf7ad6016e0a358671c.tar.gz packages_apps_Browser-801ecb73006a3062cdfeacf7ad6016e0a358671c.tar.bz2 |
fixed adding bookmark shortcut from home screen
bug: http://b/issue?id=2948937
added shortcut activity to host bookmarks page fragment
Change-Id: I39db8985b3c07fae6ca800cc57da3747040cb814
-rw-r--r-- | AndroidManifest.xml | 6 | ||||
-rw-r--r-- | res/values-xlarge/styles.xml | 3 | ||||
-rw-r--r-- | res/values/styles.xml | 4 | ||||
-rw-r--r-- | src/com/android/browser/BrowserBookmarksPage.java | 30 | ||||
-rw-r--r-- | src/com/android/browser/ShortcutActivity.java | 69 |
5 files changed, 96 insertions, 16 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 14e8aeb..8ccb634 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -152,8 +152,8 @@ android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden"> </activity> - <activity-alias android:name="ShortcutBookmarksPage" - android:targetActivity="BrowserBookmarksPage" + <activity android:name="ShortcutActivity" + android:theme="@style/ShortcutTheme" android:label="@string/shortcut_bookmark" android:icon="@drawable/ic_launcher_shortcut_browser_bookmark"> @@ -162,7 +162,7 @@ <category android:name="android.intent.category.DEFAULT" /> </intent-filter> - </activity-alias> + </activity> <activity android:name="BrowserDownloadPage" android:label="" android:configChanges="orientation|keyboardHidden"> diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml index 2784e17..fc6adc5 100644 --- a/res/values-xlarge/styles.xml +++ b/res/values-xlarge/styles.xml @@ -29,6 +29,9 @@ <style name="BookmarkTheme" parent="@android:Theme.Panel"> <item name="android:windowBackground">@color/black</item> </style> + <style name="ShortCutTheme" parent="@android:Theme.Holo"> + <item name="android:windowContentOverlay">@null</item> + </style> <style name="ActionBarStyle"> <item name="android:background">#ffdddddd</item> <item name="android:height">48dip</item> diff --git a/res/values/styles.xml b/res/values/styles.xml index b860b42..09dbff1 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -28,6 +28,10 @@ <item name="android:windowNoTitle">true</item> <item name="android:windowContentOverlay">@null</item> </style> + <style name="ShortcutTheme" parent="@android:Theme.Black"> + <item name="android:windowNoTitle">true</item> + <item name="android:windowContentOverlay">@null</item> + </style> <style name="TitleBar"> <item name="android:windowEnterAnimation">@anim/title_bar_enter</item> <item name="android:windowExitAnimation">@anim/title_bar_exit</item> diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java index f9dc5e0..3ef19f3 100644 --- a/src/com/android/browser/BrowserBookmarksPage.java +++ b/src/com/android/browser/BrowserBookmarksPage.java @@ -64,6 +64,9 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte static final int LOADER_BOOKMARKS = 1; + static final String EXTRA_SHORTCUT = "create_shortcut"; + static final String EXTRA_DISABLE_WINDOW = "disable_new_window"; + BookmarksHistoryCallbacks mCallbacks; GridView mGrid; BrowserBookmarksAdapter mAdapter; @@ -103,7 +106,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte // Fill in the "up" button if needed BookmarksLoader bl = (BookmarksLoader) loader; - boolean rootFolder = + boolean rootFolder = (BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER.equals(bl.getUri())); if (rootFolder) { mUpButton.setText(R.string.defaultBookmarksUpButton); @@ -121,7 +124,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte public void onClick(View view) { if (view == mUpButton) { Pair<String, Uri> pair = mFolderStack.pop(); - BookmarksLoader loader = + BookmarksLoader loader = (BookmarksLoader) ((Loader) getLoaderManager().getLoader(LOADER_BOOKMARKS)); loader.setUri(pair.second); loader.forceLoad(); @@ -203,7 +206,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - + final Activity activity = getActivity(); MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); @@ -253,7 +256,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte super.onAttach(activity); mCallbacks = (BookmarksHistoryCallbacks) activity; } - + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -283,7 +286,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte return root; } - + @Override public void onReceivedIcon(String url, Bitmap icon) { // A new favicon has been loaded, so let anything attached to the adapter know about it @@ -300,8 +303,9 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte return; } if (mCreateShortcut) { - // TODO handle this - createShortcutIntent(position); + Intent intent = createShortcutIntent(position); + // the activity handles the intent in startActivityFromFragment + startActivity(intent); return; } @@ -315,10 +319,10 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte title = cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE); } else { // TODO localize - title = "Bookmarks"; + title = "Bookmarks"; } LoaderManager manager = getLoaderManager(); - BookmarksLoader loader = + BookmarksLoader loader = (BookmarksLoader) ((Loader) manager.getLoader(LOADER_BOOKMARKS)); mFolderStack.push(new Pair(title, loader.getUri())); Uri uri = ContentUris.withAppendedId( @@ -349,9 +353,9 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte Intent intent = new Intent(getActivity(), AddBookmarkPage.class); Cursor cursor = (Cursor) mAdapter.getItem(position); Bundle item = new Bundle(); - item.putString(Browser.BookmarkColumns.TITLE, + item.putString(Browser.BookmarkColumns.TITLE, cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE)); - item.putString(Browser.BookmarkColumns.URL, + item.putString(Browser.BookmarkColumns.URL, cursor.getString(BookmarksLoader.COLUMN_INDEX_URL)); byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_FAVICON); if (data != null) { @@ -384,7 +388,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte } /** - * Update a row in the database with new information. + * Update a row in the database with new information. * Requeries the database if the information has changed. * @param map Bundle storing id, title and url of new information */ @@ -450,7 +454,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte Cursor cursor = (Cursor) mAdapter.getItem(position); return cursor.getString(BookmarksLoader.COLUMN_INDEX_URL); } - + private void copy(CharSequence text) { ClipboardManager cm = (ClipboardManager) getActivity().getSystemService( Context.CLIPBOARD_SERVICE); diff --git a/src/com/android/browser/ShortcutActivity.java b/src/com/android/browser/ShortcutActivity.java new file mode 100644 index 0000000..7994d0a --- /dev/null +++ b/src/com/android/browser/ShortcutActivity.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 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; + +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; + +public class ShortcutActivity extends Activity + implements BookmarksHistoryCallbacks { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); + FragmentManager fm = getFragmentManager(); + FragmentTransaction transaction = fm.openTransaction(); + Bundle extras = new Bundle(); + extras.putBoolean(BrowserBookmarksPage.EXTRA_SHORTCUT, true); + extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, true); + Fragment frag = Fragment.instantiate(this, BrowserBookmarksPage.class.getName(), extras); + transaction.add(android.R.id.content, frag); + transaction.commit(); + } + + /** + * not used for shortcuts + */ + @Override + public void onRemoveParentChildRelationShips() {} + + /** + * handle fragment startActivity + */ + @Override + public void startActivityFromFragment(Fragment f, Intent intent, int requestCode) { + setResult(RESULT_OK, intent); + finish(); + } + + @Override + public void finish() { + super.finish(); + } + + /** + * not used for shortcuts + */ + @Override + public void onUrlSelected(String url, boolean newWindow) {} + +} |