Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [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.contacts; |
| 18 | |
| 19 | import com.android.contacts.NotifyingAsyncQueryHandler.QueryCompleteListener; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 20 | import com.android.contacts.SocialStreamActivity.MappingCache; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 21 | import com.android.contacts.SocialStreamActivity.Mapping; |
| 22 | import com.android.internal.policy.PolicyManager; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 23 | import com.android.providers.contacts2.ContactsContract; |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 24 | import com.android.providers.contacts2.ContactsContract.Aggregates; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 25 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds; |
| 26 | import com.android.providers.contacts2.ContactsContract.Data; |
| 27 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Email; |
| 28 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Im; |
| 29 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Phone; |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 30 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Photo; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 31 | import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Postal; |
| 32 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 33 | import android.app.Activity; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 34 | import android.content.ActivityNotFoundException; |
| 35 | import android.content.ContentUris; |
| 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
| 38 | import android.content.res.Resources; |
| 39 | import android.database.Cursor; |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
| 41 | import android.graphics.BitmapFactory; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 42 | import android.graphics.Color; |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 43 | import android.graphics.drawable.BitmapDrawable; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 44 | import android.net.Uri; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 45 | import android.provider.Contacts.Phones; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 46 | import android.text.SpannableStringBuilder; |
| 47 | import android.text.style.CharacterStyle; |
| 48 | import android.text.style.ForegroundColorSpan; |
| 49 | import android.text.style.StyleSpan; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 50 | import android.util.Log; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 51 | import android.view.ContextThemeWrapper; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 52 | import android.view.Gravity; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 53 | import android.view.KeyEvent; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 54 | import android.view.LayoutInflater; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 55 | import android.view.Menu; |
| 56 | import android.view.MenuItem; |
| 57 | import android.view.MotionEvent; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 58 | import android.view.View; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 59 | import android.view.ViewConfiguration; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 60 | import android.view.ViewGroup; |
| 61 | import android.view.ViewTreeObserver; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 62 | import android.view.Window; |
| 63 | import android.view.WindowManager; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 64 | import android.view.View.OnClickListener; |
| 65 | import android.view.ViewTreeObserver.OnScrollChangedListener; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 66 | import android.view.accessibility.AccessibilityEvent; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 67 | import android.widget.AbsListView; |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 68 | import android.widget.AdapterView; |
| 69 | import android.widget.BaseAdapter; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 70 | import android.widget.ImageView; |
| 71 | import android.widget.LinearLayout; |
| 72 | import android.widget.ListView; |
| 73 | import android.widget.PopupWindow; |
| 74 | import android.widget.TextView; |
| 75 | import android.widget.Toast; |
| 76 | import android.widget.AbsListView.OnScrollListener; |
| 77 | import android.widget.Gallery.LayoutParams; |
| 78 | |
| 79 | import java.lang.ref.WeakReference; |
| 80 | import java.util.ArrayList; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 81 | import java.util.Arrays; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 82 | import java.util.Collections; |
| 83 | import java.util.Comparator; |
| 84 | import java.util.HashMap; |
| 85 | import java.util.Iterator; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 86 | import java.util.LinkedList; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 87 | import java.util.PriorityQueue; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 88 | import java.util.Set; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 91 | * Window that shows fast-track contact details for a specific |
| 92 | * {@link Aggregate#_ID}. |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 93 | */ |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 94 | public class FastTrackWindow implements Window.Callback, QueryCompleteListener, OnClickListener, AbsListView.OnItemClickListener { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 95 | private static final String TAG = "FastTrackWindow"; |
| 96 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Interface used to allow the person showing a {@link FastTrackWindow} to |
| 99 | * know when the window has been dismissed. |
| 100 | */ |
| 101 | interface OnDismissListener { |
| 102 | public void onDismiss(FastTrackWindow dialog); |
| 103 | } |
| 104 | |
| 105 | final Context mContext; |
| 106 | final LayoutInflater mInflater; |
| 107 | final WindowManager mWindowManager; |
| 108 | Window mWindow; |
| 109 | View mDecor; |
| 110 | |
| 111 | private boolean mQuerying = false; |
| 112 | private boolean mShowing = false; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 113 | |
| 114 | /** Mapping cache from mime-type to icons and actions */ |
| 115 | private MappingCache mMappingCache; |
| 116 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 117 | private NotifyingAsyncQueryHandler mHandler; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 118 | private OnDismissListener mDismissListener; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 119 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 120 | private long mAggId; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 121 | private int mAnchorX; |
| 122 | private int mAnchorY; |
| 123 | private int mAnchorHeight; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 124 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 125 | private boolean mHasProfile = false; |
| 126 | private boolean mHasActions = false; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 127 | |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 128 | private View mArrowUp; |
| 129 | private View mArrowDown; |
| 130 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 131 | private ImageView mPhoto; |
| 132 | private ImageView mPresence; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 133 | private TextView mContent; |
| 134 | private TextView mPublished; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 135 | private ViewGroup mTrack; |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 136 | private ListView mResolveList; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 137 | |
| 138 | // TODO: read from a resource somewhere |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 139 | private static final int mHeight = 138; |
| 140 | private static final int mArrowHeight = 10; |
| 141 | private static final int mArrowWidth = 24; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Set of {@link ActionInfo} that are associated with the aggregate |
| 145 | * currently displayed by this fast-track window. |
| 146 | */ |
| 147 | private ActionSet mActions = new ActionSet(); |
| 148 | |
| 149 | /** |
| 150 | * Specific mime-type for {@link Phone#CONTENT_ITEM_TYPE} entries that |
| 151 | * distinguishes actions that should initiate a text message. |
| 152 | */ |
| 153 | public static final String MIME_SMS_ADDRESS = "vnd.android.cursor.item/sms-address"; |
| 154 | |
| 155 | /** |
| 156 | * Specific mime-types that should be bumped to the front of the fast-track. |
| 157 | * Other mime-types not appearing in this list follow in alphabetic order. |
| 158 | */ |
| 159 | private static final String[] ORDERED_MIMETYPES = new String[] { |
| 160 | Aggregates.CONTENT_ITEM_TYPE, |
| 161 | Phones.CONTENT_ITEM_TYPE, |
| 162 | MIME_SMS_ADDRESS, |
| 163 | Email.CONTENT_ITEM_TYPE, |
| 164 | }; |
| 165 | |
Jeff Sharkey | 9bd858b | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 166 | // public static final int ICON_SIZE = 42; |
| 167 | // public static final int ICON_PADDING = 3; |
| 168 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 169 | // TODO: read this status from actual query |
| 170 | private static final String STUB_STATUS = "has a really long random status message that would be far too long to read on a single device without the need for tiny reading glasses"; |
| 171 | |
| 172 | private static final boolean INCLUDE_PROFILE_ACTION = true; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 173 | |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 174 | private static final int TOKEN_DISPLAY_NAME = 1; |
| 175 | private static final int TOKEN_DATA = 2; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 176 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 177 | /** Message to show when no activity is found to perform an action */ |
| 178 | // TODO: move this value into a resources string |
| 179 | private static final String NOT_FOUND = "Couldn't find an app to handle this action"; |
| 180 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 181 | /** |
| 182 | * Prepare a fast-track window to show in the given {@link Context}. |
| 183 | */ |
| 184 | public FastTrackWindow(Context context) { |
| 185 | mContext = new ContextThemeWrapper(context, R.style.FastTrack); |
| 186 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 187 | mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 188 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 189 | mWindow = PolicyManager.makeNewWindow(mContext); |
| 190 | mWindow.setCallback(this); |
| 191 | mWindow.setWindowManager(mWindowManager, null, null); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 192 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 193 | mWindow.setContentView(R.layout.fasttrack); |
| 194 | |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 195 | mArrowUp = (View)mWindow.findViewById(R.id.arrow_up); |
| 196 | mArrowDown = (View)mWindow.findViewById(R.id.arrow_down); |
| 197 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 198 | mPhoto = (ImageView)mWindow.findViewById(R.id.photo); |
| 199 | mPresence = (ImageView)mWindow.findViewById(R.id.presence); |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 200 | mContent = (TextView)mWindow.findViewById(R.id.content); |
| 201 | mPublished = (TextView)mWindow.findViewById(R.id.published); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 202 | mTrack = (ViewGroup)mWindow.findViewById(R.id.fasttrack); |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 203 | mResolveList = (ListView)mWindow.findViewById(android.R.id.list); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 204 | |
| 205 | // TODO: move generation of mime-type cache to more-efficient place |
| 206 | generateMappingCache(); |
| 207 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 211 | * Prepare a fast-track window to show in the given {@link Context}, and |
| 212 | * notify the given {@link OnDismissListener} each time this dialog is |
| 213 | * dismissed. |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 214 | */ |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 215 | public FastTrackWindow(Context context, OnDismissListener dismissListener) { |
| 216 | this(context); |
| 217 | mDismissListener = dismissListener; |
| 218 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 219 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 220 | /** |
| 221 | * Generate {@link MappingCache} specifically for fast-track windows. This |
| 222 | * cache knows how to display {@link CommonDataKinds#PACKAGE_COMMON} data |
| 223 | * types using generic icons. |
| 224 | */ |
| 225 | private void generateMappingCache() { |
| 226 | mMappingCache = MappingCache.createAndFill(mContext); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 227 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 228 | Resources res = mContext.getResources(); |
| 229 | Mapping mapping; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 230 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 231 | mapping = new Mapping(CommonDataKinds.PACKAGE_COMMON, Aggregates.CONTENT_ITEM_TYPE); |
| 232 | mapping.icon = BitmapFactory.decodeResource(res, R.drawable.ic_contacts_details); |
| 233 | mMappingCache.addMapping(mapping); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 234 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 235 | mapping = new Mapping(CommonDataKinds.PACKAGE_COMMON, Phone.CONTENT_ITEM_TYPE); |
| 236 | mapping.summaryColumn = Phone.NUMBER; |
| 237 | mapping.icon = BitmapFactory.decodeResource(res, android.R.drawable.sym_action_call); |
| 238 | mMappingCache.addMapping(mapping); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 239 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 240 | mapping = new Mapping(CommonDataKinds.PACKAGE_COMMON, MIME_SMS_ADDRESS); |
| 241 | mapping.summaryColumn = Phone.NUMBER; |
| 242 | mapping.icon = BitmapFactory.decodeResource(res, R.drawable.sym_action_sms); |
| 243 | mMappingCache.addMapping(mapping); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 244 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 245 | mapping = new Mapping(CommonDataKinds.PACKAGE_COMMON, Email.CONTENT_ITEM_TYPE); |
| 246 | mapping.summaryColumn = Email.DATA; |
| 247 | mapping.icon = BitmapFactory.decodeResource(res, android.R.drawable.sym_action_email); |
| 248 | mMappingCache.addMapping(mapping); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 249 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 250 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 251 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 252 | /** |
| 253 | * Start showing a fast-track window for the given {@link Aggregate#_ID} |
| 254 | * pointing towards the given location. |
| 255 | */ |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 256 | public void show(Uri aggUri, int x, int y, int height) { |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 257 | if (mShowing || mQuerying) { |
| 258 | Log.w(TAG, "already in process of showing"); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | mAggId = ContentUris.parseId(aggUri); |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 263 | mAnchorX = x; |
| 264 | mAnchorY = y; |
| 265 | mAnchorHeight = height; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 266 | mQuerying = true; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 267 | |
| 268 | // Start data query in background |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 269 | Uri dataUri = Uri.withAppendedPath(aggUri, |
| 270 | ContactsContract.Aggregates.Data.CONTENT_DIRECTORY); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 271 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 272 | // TODO: also query for latest status message |
| 273 | mHandler = new NotifyingAsyncQueryHandler(mContext, this); |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 274 | mHandler.startQuery(TOKEN_DISPLAY_NAME, null, aggUri, null, null, null, null); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 275 | mHandler.startQuery(TOKEN_DATA, null, dataUri, null, null, null, null); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 276 | |
| 277 | } |
| 278 | |
| 279 | /** |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 280 | * Show the correct callout arrow based on a {@link R.id} reference. |
| 281 | */ |
| 282 | private void showArrow(int whichArrow, int requestedX) { |
| 283 | final View showArrow = (whichArrow == R.id.arrow_up) ? mArrowUp : mArrowDown; |
| 284 | final View hideArrow = (whichArrow == R.id.arrow_up) ? mArrowDown : mArrowUp; |
| 285 | |
| 286 | showArrow.setVisibility(View.VISIBLE); |
| 287 | LinearLayout.LayoutParams param = (LinearLayout.LayoutParams)showArrow.getLayoutParams(); |
| 288 | param.leftMargin = requestedX - mArrowWidth / 2; |
| 289 | |
| 290 | hideArrow.setVisibility(View.INVISIBLE); |
| 291 | } |
| 292 | |
| 293 | /** |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 294 | * Actual internal method to show this fast-track window. Called only by |
| 295 | * {@link #considerShowing()} when all data requirements have been met. |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 296 | */ |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 297 | private void showInternal() { |
| 298 | mDecor = mWindow.getDecorView(); |
| 299 | WindowManager.LayoutParams l = mWindow.getAttributes(); |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 300 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 301 | l.gravity = Gravity.TOP | Gravity.LEFT; |
| 302 | l.x = 0; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 303 | |
| 304 | if (mAnchorY > mHeight) { |
| 305 | // Show downwards callout when enough room |
| 306 | showArrow(R.id.arrow_down, mAnchorX); |
| 307 | l.y = mAnchorY - (mHeight - (mArrowHeight * 2) - 5); |
| 308 | |
| 309 | } else { |
| 310 | // Otherwise show upwards callout |
| 311 | showArrow(R.id.arrow_up, mAnchorX); |
| 312 | l.y = mAnchorY + mAnchorHeight - 10; |
| 313 | |
| 314 | } |
| 315 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 316 | l.width = WindowManager.LayoutParams.FILL_PARENT; |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 317 | l.height = mHeight; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 318 | |
| 319 | l.dimAmount = 0.6f; |
| 320 | l.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 321 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 322 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 323 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 324 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 325 | |
| 326 | mWindowManager.addView(mDecor, l); |
| 327 | mShowing = true; |
| 328 | mQuerying = false; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Dismiss this fast-track window if showing. |
| 333 | */ |
| 334 | public void dismiss() { |
| 335 | if (!mQuerying && !mShowing) { |
| 336 | Log.d(TAG, "not visible, ignore"); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | // Cancel any pending queries |
| 341 | mHandler.cancelOperation(TOKEN_DISPLAY_NAME); |
| 342 | mHandler.cancelOperation(TOKEN_DATA); |
| 343 | |
| 344 | // Reset all views to prepare for possible recycling |
| 345 | mPhoto.setImageResource(R.drawable.ic_contact_list_picture); |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 346 | // mPresence.setImageDrawable(null); |
| 347 | // mPublished.setText(null); |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 348 | mContent.setText(null); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 349 | |
| 350 | mActions.clear(); |
| 351 | mTrack.removeAllViews(); |
| 352 | |
| 353 | mHasProfile = false; |
| 354 | mHasActions = false; |
| 355 | |
| 356 | if (mDecor == null || !mShowing) { |
| 357 | Log.d(TAG, "not showing, ignore"); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | mWindowManager.removeView(mDecor); |
| 362 | mDecor = null; |
| 363 | mWindow.closeAllPanels(); |
| 364 | mShowing = false; |
| 365 | |
| 366 | // Notify any listeners that we've been dismissed |
| 367 | if (mDismissListener != null) { |
| 368 | mDismissListener.onDismiss(this); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 372 | /** |
| 373 | * Returns true if this fast-track window is showing or querying. |
| 374 | */ |
| 375 | public boolean isShowing() { |
| 376 | return mShowing || mQuerying; |
| 377 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 378 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 379 | /** |
| 380 | * Consider showing this window, which will only call through to |
| 381 | * {@link #showInternal()} when all data items are present. |
| 382 | */ |
| 383 | private synchronized void considerShowing() { |
| 384 | if (mHasActions && mHasProfile && !mShowing) { |
| 385 | showInternal(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | /** {@inheritDoc} */ |
| 390 | public void onQueryComplete(int token, Object cookie, Cursor cursor) { |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 391 | if (cursor == null) { |
| 392 | return; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 393 | } else if (token == TOKEN_DISPLAY_NAME) { |
| 394 | handleDisplayName(cursor); |
| 395 | } else if (token == TOKEN_DATA) { |
| 396 | handleData(cursor); |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 397 | } |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 398 | } |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 399 | |
| 400 | private SpannableStringBuilder mBuilder = new SpannableStringBuilder(); |
| 401 | private CharacterStyle mStyleBold = new StyleSpan(android.graphics.Typeface.BOLD); |
| 402 | private CharacterStyle mStyleBlack = new ForegroundColorSpan(Color.BLACK); |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 403 | |
| 404 | /** |
| 405 | * Handle the result from the {@link TOKEN_DISPLAY_NAME} query. |
| 406 | */ |
| 407 | private void handleDisplayName(Cursor cursor) { |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 408 | final int COL_DISPLAY_NAME = cursor.getColumnIndex(Aggregates.DISPLAY_NAME); |
| 409 | |
| 410 | if (cursor.moveToNext()) { |
| 411 | String foundName = cursor.getString(COL_DISPLAY_NAME); |
Jeff Sharkey | 80a193a | 2009-05-21 14:18:18 -0700 | [diff] [blame] | 412 | |
| 413 | mBuilder.clear(); |
| 414 | mBuilder.append(foundName); |
| 415 | mBuilder.append(" "); |
| 416 | mBuilder.append(STUB_STATUS); |
| 417 | mBuilder.setSpan(mStyleBold, 0, foundName.length(), 0); |
| 418 | mBuilder.setSpan(mStyleBlack, 0, foundName.length(), 0); |
| 419 | mContent.setText(mBuilder); |
| 420 | |
| 421 | mPublished.setText("4 hours ago"); |
| 422 | |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 425 | mHasProfile = true; |
| 426 | considerShowing(); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Description of a specific, actionable {@link Data#_ID} item. May have a |
| 431 | * {@link Mapping} associated with it to find {@link RemoteViews} or icon, |
| 432 | * and may have built a summary of itself for UI display. |
| 433 | */ |
| 434 | private class ActionInfo { |
| 435 | long dataId; |
| 436 | String packageName; |
| 437 | String mimeType; |
| 438 | |
| 439 | Mapping mapping; |
| 440 | String summaryValue; |
| 441 | |
| 442 | /** |
| 443 | * Create an action from common {@link Data} elements. |
| 444 | */ |
| 445 | public ActionInfo(long dataId, String packageName, String mimeType) { |
| 446 | this.dataId = dataId; |
| 447 | this.packageName = packageName; |
| 448 | this.mimeType = mimeType; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Attempt to find a {@link Mapping} for the package and mime-type |
| 453 | * defined by this action. Returns true if one was found. |
| 454 | */ |
| 455 | public boolean findMapping(MappingCache cache) { |
| 456 | mapping = cache.findMapping(packageName, mimeType); |
| 457 | return (mapping != null); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Given a {@link Cursor} pointed at the {@link Data} row associated |
| 462 | * with this action, use the {@link Mapping} to build a text summary. |
| 463 | */ |
| 464 | public void buildSummary(Cursor cursor) { |
| 465 | if (mapping == null || mapping.summaryColumn == null) return; |
| 466 | int index = cursor.getColumnIndex(mapping.summaryColumn); |
| 467 | if (index != -1) { |
| 468 | summaryValue = cursor.getString(index); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Build an {@link Intent} that will perform this action. |
| 474 | */ |
| 475 | public Intent buildIntent() { |
| 476 | // Handle well-known mime-types with special care |
| 477 | if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 478 | Uri callUri = Uri.parse("tel:" + Uri.encode(summaryValue)); |
| 479 | return new Intent(Intent.ACTION_DIAL, callUri); |
| 480 | |
| 481 | } else if (MIME_SMS_ADDRESS.equals(mimeType)) { |
| 482 | Uri smsUri = Uri.fromParts("smsto", summaryValue, null); |
| 483 | return new Intent(Intent.ACTION_SENDTO, smsUri); |
| 484 | |
| 485 | } else if (CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 486 | Uri mailUri = Uri.fromParts("mailto", summaryValue, null); |
| 487 | return new Intent(Intent.ACTION_SENDTO, mailUri); |
| 488 | |
| 489 | } |
| 490 | |
| 491 | // Otherwise fall back to default VIEW action |
| 492 | Uri dataUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, dataId); |
| 493 | |
| 494 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 495 | intent.setData(dataUri); |
| 496 | |
| 497 | return intent; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Provide a simple way of collecting one or more {@link ActionInfo} objects |
| 503 | * under a mime-type key. |
| 504 | */ |
| 505 | private class ActionSet extends HashMap<String, LinkedList<ActionInfo>> { |
| 506 | private void collect(String mimeType, ActionInfo info) { |
| 507 | // Create mime-type set if needed |
| 508 | if (!containsKey(mimeType)) { |
| 509 | put(mimeType, new LinkedList<ActionInfo>()); |
| 510 | } |
| 511 | LinkedList<ActionInfo> collectList = get(mimeType); |
| 512 | collectList.add(info); |
| 513 | } |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Handle the result from the {@link TOKEN_DATA} query. |
| 518 | */ |
| 519 | private void handleData(Cursor cursor) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 520 | final int COL_ID = cursor.getColumnIndex(Data._ID); |
| 521 | final int COL_PACKAGE = cursor.getColumnIndex(Data.PACKAGE); |
| 522 | final int COL_MIMETYPE = cursor.getColumnIndex(Data.MIMETYPE); |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 523 | final int COL_PHOTO = cursor.getColumnIndex(Photo.PHOTO); |
| 524 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 525 | ActionInfo info; |
| 526 | |
| 527 | // Add the profile shortcut action if requested |
| 528 | if (INCLUDE_PROFILE_ACTION) { |
| 529 | final String mimeType = Aggregates.CONTENT_ITEM_TYPE; |
| 530 | info = new ActionInfo(mAggId, CommonDataKinds.PACKAGE_COMMON, mimeType); |
| 531 | if (info.findMapping(mMappingCache)) { |
| 532 | mActions.collect(mimeType, info); |
| 533 | } |
| 534 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 535 | |
| 536 | while (cursor.moveToNext()) { |
| 537 | final long dataId = cursor.getLong(COL_ID); |
| 538 | final String packageName = cursor.getString(COL_PACKAGE); |
| 539 | final String mimeType = cursor.getString(COL_MIMETYPE); |
| 540 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 541 | // Handle when a photo appears in the various data items |
| 542 | // TODO: accept a photo only if its marked as primary |
| 543 | if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { |
Jeff Sharkey | ecedf75 | 2009-05-18 22:07:40 -0700 | [diff] [blame] | 544 | byte[] photoBlob = cursor.getBlob(COL_PHOTO); |
| 545 | Bitmap photoBitmap = BitmapFactory.decodeByteArray(photoBlob, 0, photoBlob.length); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 546 | mPhoto.setImageBitmap(photoBitmap); |
Jeff Sharkey | 6912668 | 2009-05-18 21:33:41 -0700 | [diff] [blame] | 547 | continue; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 550 | // Build an action for this data entry, find a mapping to a UI |
| 551 | // element, build its summary from the cursor, and collect it along |
| 552 | // with all others of this mime-type. |
| 553 | info = new ActionInfo(dataId, packageName, mimeType); |
| 554 | if (info.findMapping(mMappingCache)) { |
| 555 | info.buildSummary(cursor); |
| 556 | mActions.collect(info.mimeType, info); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 559 | // If phone number, also insert as text message action |
| 560 | if (Phones.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 561 | info = new ActionInfo(dataId, packageName, MIME_SMS_ADDRESS); |
| 562 | if (info.findMapping(mMappingCache)) { |
| 563 | info.buildSummary(cursor); |
| 564 | mActions.collect(info.mimeType, info); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 565 | } |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 566 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | cursor.close(); |
| 570 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 571 | // Turn our list of actions into UI elements, starting with common types |
| 572 | Set<String> containedTypes = mActions.keySet(); |
| 573 | for (String mimeType : ORDERED_MIMETYPES) { |
| 574 | if (containedTypes.contains(mimeType)) { |
| 575 | mTrack.addView(inflateAction(mimeType)); |
| 576 | containedTypes.remove(mimeType); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 577 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 580 | // Then continue with remaining mime-types in alphabetical order |
| 581 | String[] remainingTypes = containedTypes.toArray(new String[containedTypes.size()]); |
| 582 | Arrays.sort(remainingTypes); |
| 583 | for (String mimeType : remainingTypes) { |
| 584 | mTrack.addView(inflateAction(mimeType)); |
| 585 | } |
| 586 | |
| 587 | mHasActions = true; |
| 588 | considerShowing(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 592 | * Inflate the in-track view for the action of the given mime-type. Will use |
| 593 | * the icon provided by the {@link Mapping}. |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 594 | */ |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 595 | private View inflateAction(String mimeType) { |
| 596 | ImageView view = (ImageView)mInflater.inflate(R.layout.fasttrack_item, mTrack, false); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 597 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 598 | // Add direct intent if single child, otherwise flag for multiple |
| 599 | LinkedList<ActionInfo> children = mActions.get(mimeType); |
| 600 | ActionInfo firstInfo = children.get(0); |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 601 | // if (children.size() == 1) { |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 602 | view.setTag(firstInfo.buildIntent()); |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 603 | // } else { |
| 604 | // view.setTag(children); |
| 605 | // } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 606 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 607 | // Set icon and listen for clicks |
| 608 | view.setImageBitmap(firstInfo.mapping.icon); |
| 609 | view.setOnClickListener(this); |
| 610 | return view; |
| 611 | } |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 612 | |
| 613 | /** {@inheritDoc} */ |
| 614 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 615 | // Pass list item clicks along so that Intents are handled uniformly |
| 616 | onClick(view); |
| 617 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 618 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 619 | /** {@inheritDoc} */ |
| 620 | public void onClick(View v) { |
| 621 | final Object tag = v.getTag(); |
| 622 | if (tag instanceof Intent) { |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 623 | // Hide the resolution list, if present |
| 624 | mResolveList.setVisibility(View.GONE); |
| 625 | |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 626 | // Incoming tag is concrete intent, so launch |
| 627 | try { |
| 628 | mContext.startActivity((Intent)tag); |
| 629 | } catch (ActivityNotFoundException e) { |
| 630 | Log.w(TAG, NOT_FOUND); |
| 631 | Toast.makeText(mContext, NOT_FOUND, Toast.LENGTH_SHORT).show(); |
| 632 | } |
Jeff Sharkey | 51ca544 | 2009-05-21 16:12:18 -0700 | [diff] [blame^] | 633 | // } else if (tag instanceof LinkedList) { |
| 634 | // // Incoming tag is a mime-type, so show resolution list |
| 635 | // final LinkedList<ActionInfo> children = (LinkedList<ActionInfo>)tag; |
| 636 | // Log.d(TAG, "found chidlren=" + children); |
| 637 | // |
| 638 | // mResolveList.setVisibility(View.VISIBLE); |
| 639 | // mResolveList.setOnItemClickListener(this); |
| 640 | // mResolveList.setAdapter(new BaseAdapter() { |
| 641 | // public int getCount() { |
| 642 | // return children.size(); |
| 643 | // } |
| 644 | // |
| 645 | // public Object getItem(int position) { |
| 646 | // return children.get(position); |
| 647 | // } |
| 648 | // |
| 649 | // public long getItemId(int position) { |
| 650 | // return position; |
| 651 | // } |
| 652 | // |
| 653 | // public View getView(int position, View convertView, ViewGroup parent) { |
| 654 | // if (convertView == null) { |
| 655 | // convertView = mInflater.inflate(R.layout.fasttrack_resolve_item, parent, false); |
| 656 | // } |
| 657 | // |
| 658 | // // Set action title based on summary value |
| 659 | // ActionInfo info = (ActionInfo)getItem(position); |
| 660 | // TextView textView = (TextView)convertView; |
| 661 | // textView.setText(info.summaryValue); |
| 662 | // textView.setTag(info.buildIntent()); |
| 663 | // textView.setCompoundDrawablesWithIntrinsicBounds( |
| 664 | // new BitmapDrawable(info.mapping.icon), null, null, null); |
| 665 | // |
| 666 | // return convertView; |
| 667 | // } |
| 668 | // }); |
| 669 | // |
| 670 | // // Make sure we resize to make room for ListView |
| 671 | // onWindowAttributesChanged(mWindow.getAttributes()); |
| 672 | // |
| 673 | // // TODO: show drop-down resolution list |
| 674 | // Log.d(TAG, "would show list between several options here"); |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 675 | |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** {@inheritDoc} */ |
| 680 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 681 | return mWindow.superDispatchKeyEvent(event); |
| 682 | } |
| 683 | |
| 684 | /** {@inheritDoc} */ |
| 685 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 686 | // TODO: make this window accessible |
| 687 | return false; |
| 688 | } |
| 689 | |
| 690 | /** {@inheritDoc} */ |
| 691 | public boolean dispatchTouchEvent(MotionEvent event) { |
| 692 | if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
| 693 | dismiss(); |
| 694 | return true; |
| 695 | } |
| 696 | return mWindow.superDispatchTouchEvent(event); |
| 697 | } |
| 698 | |
| 699 | /** {@inheritDoc} */ |
| 700 | public boolean dispatchTrackballEvent(MotionEvent event) { |
| 701 | return mWindow.superDispatchTrackballEvent(event); |
| 702 | } |
| 703 | |
| 704 | /** {@inheritDoc} */ |
| 705 | public void onContentChanged() { |
| 706 | } |
| 707 | |
| 708 | /** {@inheritDoc} */ |
| 709 | public boolean onCreatePanelMenu(int featureId, Menu menu) { |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | /** {@inheritDoc} */ |
| 714 | public View onCreatePanelView(int featureId) { |
| 715 | return null; |
| 716 | } |
| 717 | |
| 718 | /** {@inheritDoc} */ |
| 719 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
| 720 | return false; |
| 721 | } |
| 722 | |
| 723 | /** {@inheritDoc} */ |
| 724 | public boolean onMenuOpened(int featureId, Menu menu) { |
| 725 | return false; |
| 726 | } |
| 727 | |
| 728 | /** {@inheritDoc} */ |
| 729 | public void onPanelClosed(int featureId, Menu menu) { |
| 730 | } |
| 731 | |
| 732 | /** {@inheritDoc} */ |
| 733 | public boolean onPreparePanel(int featureId, View view, Menu menu) { |
| 734 | return false; |
| 735 | } |
| 736 | |
| 737 | /** {@inheritDoc} */ |
| 738 | public boolean onSearchRequested() { |
| 739 | return false; |
| 740 | } |
| 741 | |
| 742 | /** {@inheritDoc} */ |
| 743 | public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams attrs) { |
| 744 | if (mDecor != null) { |
| 745 | mWindowManager.updateViewLayout(mDecor, attrs); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /** {@inheritDoc} */ |
| 750 | public void onWindowFocusChanged(boolean hasFocus) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 751 | } |
| 752 | } |