blob: 2218e6dcea22ffecd4a367209b0457c794417d96 [file] [log] [blame]
Michael Jurka4bb4f732010-08-04 18:46:01 -07001/*
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 Jurkaaf442092010-06-10 17:01:57 -070017package com.android.launcher2;
18
19import android.appwidget.AppWidgetProviderInfo;
20import android.content.Context;
Michael Jurkaaf442092010-06-10 17:01:57 -070021import android.graphics.Bitmap;
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -070022import android.graphics.drawable.BitmapDrawable;
23import android.graphics.drawable.Drawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070024import android.util.AttributeSet;
Michael Jurkaaf442092010-06-10 17:01:57 -070025import android.view.View;
26import android.widget.AdapterView;
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -070027import android.widget.TextView;
Michael Jurkaaf442092010-06-10 17:01:57 -070028
Michael Jurka0e260592010-06-30 17:07:39 -070029public class WidgetChooser extends HomeCustomizationItemGallery implements DragSource {
Michael Jurkaaf442092010-06-10 17:01:57 -070030 private DragController mDragController;
Michael Jurkaaf442092010-06-10 17:01:57 -070031
32 public WidgetChooser(Context context, AttributeSet attrs) {
33 super(context, attrs);
Michael Jurkaaf442092010-06-10 17:01:57 -070034 }
35
36 public void setDragController(DragController dragger) {
37 mDragController = dragger;
38 }
39
Michael Jurkaaf442092010-06-10 17:01:57 -070040 public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -070041 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 Jurka0e260592010-06-30 17:07:39 -070050 AppWidgetProviderInfo info = (AppWidgetProviderInfo)getAdapter().getItem(position);
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -070051 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 Jurka4bb4f732010-08-04 18:46:01 -070057 mLauncher.hideCustomizationDrawer();
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -070058 return true;
Michael Jurkaaf442092010-06-10 17:01:57 -070059 }
60
Michael Jurka0e260592010-06-30 17:07:39 -070061 public void onDropCompleted(View target, boolean success) {
Michael Jurkaaf442092010-06-10 17:01:57 -070062 }
63}
Michael Jurka0e260592010-06-30 17:07:39 -070064