The Android Open Source Project | d097a18 | 2008-12-17 18:05:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.launcher; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.util.AttributeSet; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.widget.AdapterView; |
| 25 | import android.net.Uri; |
| 26 | import android.provider.LiveFolders; |
| 27 | |
| 28 | public class LiveFolder extends Folder { |
| 29 | public LiveFolder(Context context, AttributeSet attrs) { |
| 30 | super(context, attrs); |
| 31 | } |
| 32 | |
| 33 | static LiveFolder fromXml(Context context, FolderInfo folderInfo) { |
| 34 | final int layout = isDisplayModeList(folderInfo) ? |
| 35 | R.layout.live_folder_list : R.layout.live_folder_grid; |
| 36 | return (LiveFolder) LayoutInflater.from(context).inflate(layout, null); |
| 37 | } |
| 38 | |
| 39 | private static boolean isDisplayModeList(FolderInfo folderInfo) { |
| 40 | return ((LiveFolderInfo) folderInfo).displayMode == |
| 41 | LiveFolders.DISPLAY_MODE_LIST; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void onItemClick(AdapterView parent, View v, int position, long id) { |
| 46 | LiveFolderAdapter.ViewHolder holder = (LiveFolderAdapter.ViewHolder) v.getTag(); |
| 47 | |
| 48 | if (holder.useBaseIntent) { |
| 49 | final Intent baseIntent = ((LiveFolderInfo) mInfo).baseIntent; |
| 50 | if (baseIntent != null) { |
| 51 | final Intent intent = new Intent(baseIntent); |
| 52 | Uri uri = baseIntent.getData(); |
| 53 | uri = uri.buildUpon().appendPath(Long.toString(holder.id)).build(); |
| 54 | intent.setData(uri); |
| 55 | mLauncher.startActivitySafely(intent); |
| 56 | } |
| 57 | } else if (holder.intent != null) { |
| 58 | mLauncher.startActivitySafely(holder.intent); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | void bind(FolderInfo info) { |
| 68 | super.bind(info); |
The Android Open Source Project | 38a75b2 | 2009-03-03 14:04:32 -0800 | [diff] [blame^] | 69 | setContentAdapter(new LiveFolderAdapter(mLauncher, (LiveFolderInfo) info)); |
The Android Open Source Project | d097a18 | 2008-12-17 18:05:58 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | void onOpen() { |
| 74 | super.onOpen(); |
| 75 | requestFocus(); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | void onClose() { |
| 80 | super.onClose(); |
| 81 | ((LiveFolderAdapter) mContent.getAdapter()).cleanup(); |
| 82 | } |
The Android Open Source Project | d097a18 | 2008-12-17 18:05:58 -0800 | [diff] [blame] | 83 | } |