Michael Jurka | 4bb4f73 | 2010-08-04 18:46:01 -0700 | [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 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
| 18 | |
| 19 | import android.appwidget.AppWidgetProviderInfo; |
| 20 | import android.content.Context; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 22 | import android.graphics.drawable.BitmapDrawable; |
| 23 | import android.graphics.drawable.Drawable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.widget.AdapterView; |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 27 | import android.widget.TextView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 28 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 29 | public class WidgetChooser extends HomeCustomizationItemGallery implements DragSource { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 30 | private DragController mDragController; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 31 | |
| 32 | public WidgetChooser(Context context, AttributeSet attrs) { |
| 33 | super(context, attrs); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | public void setDragController(DragController dragger) { |
| 37 | mDragController = dragger; |
| 38 | } |
| 39 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 40 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 41 | Drawable[] drawables = ((TextView)view).getCompoundDrawables(); |
| 42 | Bitmap bmp = ((BitmapDrawable)drawables[1]).getBitmap(); |
| 43 | final int w = bmp.getWidth(); |
| 44 | final int h = bmp.getHeight(); |
| 45 | |
| 46 | // We don't really have an accurate location to use. This will do. |
| 47 | int screenX = mMotionDownRawX - (w / 2); |
| 48 | int screenY = mMotionDownRawY - h; |
| 49 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 50 | AppWidgetProviderInfo info = (AppWidgetProviderInfo)getAdapter().getItem(position); |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 51 | LauncherAppWidgetInfo dragInfo = new LauncherAppWidgetInfo(info.provider); |
| 52 | // TODO: Is this really the best place to do this? |
| 53 | dragInfo.minWidth = info.minWidth; |
| 54 | dragInfo.minHeight = info.minHeight; |
| 55 | mDragController.startDrag(bmp, screenX, screenY, |
| 56 | 0, 0, w, h, this, dragInfo, DragController.DRAG_ACTION_COPY); |
Michael Jurka | 4bb4f73 | 2010-08-04 18:46:01 -0700 | [diff] [blame] | 57 | mLauncher.hideCustomizationDrawer(); |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 58 | return true; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 61 | public void onDropCompleted(View target, boolean success) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 64 | |