blob: f7be4f21c3300ade797d981e07afdd63568fd048 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package com.cyanogenmod.eleven.dragdrop;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
/**
* Simple implementation of the FloatViewManager class. Uses list items as they
* appear in the ListView to create the floating View.
*/
public class SimpleFloatViewManager implements DragSortListView.FloatViewManager {
private final ListView mListView;
private Bitmap mFloatBitmap;
private int mFloatBGColor = Color.BLACK;
public SimpleFloatViewManager(ListView lv) {
mListView = lv;
}
public void setBackgroundColor(int color) {
mFloatBGColor = color;
}
/**
* This simple implementation creates a Bitmap copy of the list item
* currently shown at ListView <code>position</code>.
*/
@Override
public View onCreateFloatView(int position) {
View v = mListView.getChildAt(position + mListView.getHeaderViewsCount()
- mListView.getFirstVisiblePosition());
if (v == null) {
return null;
}
v.setPressed(false);
v.setDrawingCacheEnabled(true);
mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
ImageView iv = new ImageView(mListView.getContext());
iv.setBackgroundColor(mFloatBGColor);
iv.setPadding(0, 0, 0, 0);
iv.setImageBitmap(mFloatBitmap);
return iv;
}
/**
* Removes the Bitmap from the ImageView created in onCreateFloatView() and
* tells the system to recycle it.
*/
@Override
public void onDestroyFloatView(View floatView) {
((ImageView)floatView).setImageDrawable(null);
mFloatBitmap.recycle();
mFloatBitmap = null;
}
/**
* {@inheritDoc}
*/
@Override
public void onDragFloatView(View floatView, Point position, Point touch) {
/* Nothing to do */
}
}
|