Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.CursorLoader; |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 21 | import android.net.Uri; |
Jeff Hamilton | 69bd707 | 2010-08-17 12:38:22 -0500 | [diff] [blame] | 22 | import android.provider.BrowserContract.Bookmarks; |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 23 | import android.text.TextUtils; |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 24 | |
| 25 | public class BookmarksLoader extends CursorLoader { |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 26 | public static final String ARG_ACCOUNT_TYPE = "acct_type"; |
| 27 | public static final String ARG_ACCOUNT_NAME = "acct_name"; |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 28 | |
| 29 | public static final int COLUMN_INDEX_ID = 0; |
| 30 | public static final int COLUMN_INDEX_URL = 1; |
| 31 | public static final int COLUMN_INDEX_TITLE = 2; |
| 32 | public static final int COLUMN_INDEX_FAVICON = 3; |
| 33 | public static final int COLUMN_INDEX_THUMBNAIL = 4; |
| 34 | public static final int COLUMN_INDEX_TOUCH_ICON = 5; |
| 35 | public static final int COLUMN_INDEX_IS_FOLDER = 6; |
| 36 | |
| 37 | public static final String[] PROJECTION = new String[] { |
| 38 | Bookmarks._ID, // 0 |
| 39 | Bookmarks.URL, // 1 |
| 40 | Bookmarks.TITLE, // 2 |
| 41 | Bookmarks.FAVICON, // 3 |
| 42 | Bookmarks.THUMBNAIL, // 4 |
| 43 | Bookmarks.TOUCH_ICON, // 5 |
| 44 | Bookmarks.IS_FOLDER, // 6 |
| 45 | Bookmarks.POSITION, // 7 |
| 46 | }; |
| 47 | |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 48 | private String mAccountType; |
| 49 | private String mAccountName; |
| 50 | |
| 51 | public BookmarksLoader(Context context, String accountType, String accountName) { |
| 52 | super(context, addAccount(Bookmarks.CONTENT_URI_DEFAULT_FOLDER, accountType, accountName), |
| 53 | PROJECTION, null, null, null); |
| 54 | mAccountType = accountType; |
| 55 | mAccountName = accountName; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void setUri(Uri uri) { |
| 60 | super.setUri(addAccount(uri, mAccountType, mAccountName)); |
| 61 | } |
| 62 | |
| 63 | private static Uri addAccount(Uri uri, String accountType, String accountName) { |
| 64 | if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) { |
| 65 | return uri.buildUpon().appendQueryParameter(Bookmarks.PARAM_ACCOUNT_TYPE, accountType). |
| 66 | appendQueryParameter(Bookmarks.PARAM_ACCOUNT_NAME, accountName).build(); |
| 67 | } |
| 68 | return uri; |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 69 | } |
| 70 | } |