2、列表item_圆头像_信息提示

 1 import android.app.Activity;
 2 import android.os.Bundle;
 3 import android.view.LayoutInflater;
 4 import android.view.View;
 5 import android.view.ViewGroup;
 6 import android.widget.BaseAdapter;
 7 import android.widget.ListView;
 8 import android.widget.Toast;
 9 import com.dk.view.drop.CoverManager;
10 import com.dk.view.drop.WaterDrop;
11 import com.dk.view.drop.DropCover.OnDragCompeteListener;
12
13 public class MainActivity extends Activity {
14
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19         getActionBar().hide();
20         CoverManager.getInstance().init(this);
21
22         ListView mList = (ListView) findViewById(R.id.list);
23         mList.setAdapter(new DemoAdapter());
24
25         CoverManager.getInstance().setMaxDragDistance(150);
26         CoverManager.getInstance().setExplosionTime(150);
27     }
28
29     class DemoAdapter extends BaseAdapter {
30         @Override
31         public int getCount() {
32             return 99;
33         }
34         @Override
35         public Object getItem(int position) {
36             return null;
37         }
38         @Override
39         public long getItemId(int position) {
40             return 0;
41         }
42         @Override
43         public View getView(final int position, View convertView,
44                 ViewGroup parent) {
45             convertView = LayoutInflater.from(MainActivity.this).inflate(
46                     R.layout.view_list_item, null);
47         WaterDrop drop = (WaterDrop) convertView.findViewById(R.id.drop);
48         drop.setText(String.valueOf(position));
49         drop.setOnDragCompeteListener(new OnDragCompeteListener() {
52                 @Override
53                 public void onDrag() {
54                   Toast.makeText(MainActivity.this, "remove:" + position,
55                             Toast.LENGTH_SHORT).show();
56                 }
57             });
58             return convertView;
59         }
60     }
61 }
 1 <?xml version="1.0" encoding="utf-8"?>
 2
 3 <!-- R.layout.view_list_item -->
 4 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 5     xmlns:app="http://schemas.android.com/apk/res/com.view.drop"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     android:gravity="center_vertical"
 9     android:orientation="horizontal" >
10
11     <com.view.drop.CircleImageView
12         android:layout_width="50dp"
13         android:layout_height="50dp"
14         android:src="@drawable/p3"
15         app:border_color="#92DDED"
16         app:border_width="3dp" />
17
18     <LinearLayout
19         android:layout_width="match_parent"
20         android:layout_height="60dp"
21         android:orientation="vertical" >
22         <LinearLayout
23             android:layout_width="match_parent"
24             android:layout_height="30dp"
25             android:layout_marginLeft="10dp"
26             android:layout_marginRight="10dp"
27             android:gravity="center_vertical" >
28             <TextView
29                 android:layout_width="match_parent"
30                 android:layout_height="30dp"
31                 android:layout_weight="1"
32                 android:gravity="center_vertical"
33                 android:text="Dean Ding"
34                 android:textColor="#444444" />
35             <TextView
36                 android:layout_width="40dp"
37                 android:layout_height="30dp"
38                 android:gravity="center_vertical"
39                 android:text="11:11"
40                 android:textColor="#666666" />
41         </LinearLayout>
42
43         <LinearLayout
44             android:layout_width="match_parent"
45             android:layout_height="30dp"
46             android:layout_marginLeft="10dp"
47             android:layout_marginRight="10dp"
48             android:gravity="center_vertical" >
49             <TextView
50                 android:layout_width="match_parent"
51                 android:layout_height="30dp"
52                 android:layout_weight="1"
53                 android:gravity="center_vertical"
54                 android:text="Hello World"
55                 android:textColor="#666666" />
56
57             <com.dk.view.drop.WaterDrop
58                 android:id="@+id/drop"
59                 android:layout_width="25dp"
60                 android:layout_height="25dp"
61                 android:gravity="center_vertical" />
62         </LinearLayout>
63     </LinearLayout>
64
65 </LinearLayout>
  1 import android.content.Context;
  2 import android.content.res.TypedArray;
  3 import android.graphics.Bitmap;
  4 import android.graphics.BitmapShader;
  5 import android.graphics.Canvas;
  6 import android.graphics.Color;
  7 import android.graphics.Matrix;
  8 import android.graphics.Paint;
  9 import android.graphics.RectF;
 10 import android.graphics.Shader;
 11 import android.graphics.drawable.BitmapDrawable;
 12 import android.graphics.drawable.ColorDrawable;
 13 import android.graphics.drawable.Drawable;
 14 import android.util.AttributeSet;
 15 import android.widget.ImageView;
 16
 17 /**
 18  * Copyright 2014 Henning Dodenhof
 19  *
 20  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 21  * use this file except in compliance with the License. You may obtain a copy of
 22  * the License at
 23  *
 24  * http://www.apache.org/licenses/LICENSE-2.0
 25  *
 26  * Unless required by applicable law or agreed to in writing, software
 27  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 28  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 29  * License for the specific language governing permissions and limitations under
 30  * the License.
 31  *
 32  * 圆头像
 33  *
 34  */
 35 public class CircleImageView extends ImageView {
 36
 37     private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
 38
 39     private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
 40     private static final int COLORDRAWABLE_DIMENSION = 1;
 41
 42     private static final int DEFAULT_BORDER_WIDTH = 0;
 43     private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
 44
 45     private final RectF mDrawableRect = new RectF();
 46     private final RectF mBorderRect = new RectF();
 47
 48     private final Matrix mShaderMatrix = new Matrix();
 49     private final Paint mBitmapPaint = new Paint();
 50     private final Paint mBorderPaint = new Paint();
 51
 52     private int mBorderColor = DEFAULT_BORDER_COLOR;
 53     private int mBorderWidth = DEFAULT_BORDER_WIDTH;
 54
 55     private Bitmap mBitmap;
 56     private BitmapShader mBitmapShader;
 57     private int mBitmapWidth;
 58     private int mBitmapHeight;
 59
 60     private float mDrawableRadius;
 61     private float mBorderRadius;
 62
 63     private boolean mReady;
 64     private boolean mSetupPending;
 65
 66     public CircleImageView(Context context) {
 67         super(context);
 68     }
 69
 70     public CircleImageView(Context context, AttributeSet attrs) {
 71         this(context, attrs, 0);
 72     }
 73
 74     public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
 75         super(context, attrs, defStyle);
 76         super.setScaleType(SCALE_TYPE);
 77
 78         TypedArray a = context.obtainStyledAttributes(attrs,
 79                 R.styleable.CircleImageView, defStyle, 0);
 80
 81         mBorderWidth = a.getDimensionPixelSize(
 82                 R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
 83         mBorderColor = a.getColor(R.styleable.CircleImageView_border_color,
 84                 DEFAULT_BORDER_COLOR);
 85
 86         a.recycle();
 87
 88         mReady = true;
 89
 90         if (mSetupPending) {
 91             setup();
 92             mSetupPending = false;
 93         }
 94     }
 95
 96     @Override
 97     public ScaleType getScaleType() {
 98         return SCALE_TYPE;
 99     }
100
101     @Override
102     public void setScaleType(ScaleType scaleType) {
103         if (scaleType != SCALE_TYPE) {
104             throw new IllegalArgumentException(String.format(
105                     "ScaleType %s not supported.", scaleType));
106         }
107     }
108
109     @Override
110     protected void onDraw(Canvas canvas) {
111         if (getDrawable() == null) {
112             return;
113         }
114
115         canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius,
116                 mBitmapPaint);
117         if (mBorderWidth != 0) {
118             canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius,
119                     mBorderPaint);
120         }
121     }
122
123     @Override
124     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
125         super.onSizeChanged(w, h, oldw, oldh);
126         setup();
127     }
128
129     public int getBorderColor() {
130         return mBorderColor;
131     }
132
133     public void setBorderColor(int borderColor) {
134         if (borderColor == mBorderColor) {
135             return;
136         }
137
138         mBorderColor = borderColor;
139         mBorderPaint.setColor(mBorderColor);
140         invalidate();
141     }
142
143     public int getBorderWidth() {
144         return mBorderWidth;
145     }
146
147     public void setBorderWidth(int borderWidth) {
148         if (borderWidth == mBorderWidth) {
149             return;
150         }
151
152         mBorderWidth = borderWidth;
153         setup();
154     }
155
156     @Override
157     public void setImageBitmap(Bitmap bm) {
158         super.setImageBitmap(bm);
159         mBitmap = bm;
160         setup();
161     }
162
163     @Override
164     public void setImageDrawable(Drawable drawable) {
165         super.setImageDrawable(drawable);
166         mBitmap = getBitmapFromDrawable(drawable);
167         setup();
168     }
169
170     @Override
171     public void setImageResource(int resId) {
172         super.setImageResource(resId);
173         mBitmap = getBitmapFromDrawable(getDrawable());
174         setup();
175     }
176
177     private Bitmap getBitmapFromDrawable(Drawable drawable) {
178         if (drawable == null) {
179             return null;
180         }
181
182         if (drawable instanceof BitmapDrawable) {
183             return ((BitmapDrawable) drawable).getBitmap();
184         }
185
186         try {
187             Bitmap bitmap;
188
189             if (drawable instanceof ColorDrawable) {
190                 bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION,
191                         COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
192             } else {
193                 bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
194                         drawable.getIntrinsicHeight(), BITMAP_CONFIG);
195             }
196
197             Canvas canvas = new Canvas(bitmap);
198             drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
199             drawable.draw(canvas);
200             return bitmap;
201         } catch (OutOfMemoryError e) {
202             return null;
203         }
204     }
205
206     private void setup() {
207         if (!mReady) {
208             mSetupPending = true;
209             return;
210         }
211
212         if (mBitmap == null) {
213             return;
214         }
215
216         mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP,
217                 Shader.TileMode.CLAMP);
218
219         mBitmapPaint.setAntiAlias(true);
220         mBitmapPaint.setShader(mBitmapShader);
221
222         mBorderPaint.setStyle(Paint.Style.STROKE);
223         mBorderPaint.setAntiAlias(true);
224         mBorderPaint.setColor(mBorderColor);
225         mBorderPaint.setStrokeWidth(mBorderWidth);
226
227         mBitmapHeight = mBitmap.getHeight();
228         mBitmapWidth = mBitmap.getWidth();
229
230         mBorderRect.set(0, 0, getWidth(), getHeight());
231         mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2,
232                 (mBorderRect.width() - mBorderWidth) / 2);
233
234         mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width()
235                 - mBorderWidth, mBorderRect.height() - mBorderWidth);
236         mDrawableRadius = Math.min(mDrawableRect.height() / 2,
237                 mDrawableRect.width() / 2);
238
239         updateShaderMatrix();
240         invalidate();
241     }
242
243     private void updateShaderMatrix() {
244         float scale;
245         float dx = 0;
246         float dy = 0;
247
248         mShaderMatrix.set(null);
249
250         if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width()
251                 * mBitmapHeight) {
252             scale = mDrawableRect.height() / (float) mBitmapHeight;
253             dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
254         } else {
255             scale = mDrawableRect.width() / (float) mBitmapWidth;
256             dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
257         }
258
259         mShaderMatrix.setScale(scale, scale);
260         mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth,
261                 (int) (dy + 0.5f) + mBorderWidth);
262
263         mBitmapShader.setLocalMatrix(mShaderMatrix);
264     }
265
266 }
  1 import com.dk.view.drop.DropCover.OnDragCompeteListener;
  2 import android.annotation.SuppressLint;
  3 import android.content.Context;
  4 import android.graphics.Canvas;
  5 import android.graphics.Paint;
  6 import android.os.Build.VERSION;
  7 import android.util.AttributeSet;
  8 import android.view.MotionEvent;
  9 import android.view.View;
 10 import android.view.ViewGroup;
 11 import android.widget.ListView;
 12 import android.widget.RelativeLayout;
 13 import android.widget.ScrollView;
 14 import android.widget.TextView;
 15 // 红色圆圈
 16 public class WaterDrop extends RelativeLayout {
 17     private Paint mPaint = new Paint();
 18     private TextView mTextView;
 19     private DropCover.OnDragCompeteListener mOnDragCompeteListener;
 20     private boolean mHolderEventFlag;
 21
 22     public WaterDrop(Context context) {
 23         super(context);
 24         init();
 25     }
 26
 27     public WaterDrop(Context context, AttributeSet attrs) {
 28         super(context, attrs);
 29         init();
 30     }
 31
 32     public void setText(String str) {
 33         mTextView.setText(str);
 34     }
 35
 36     public void setTextSize(int size) {
 37         mTextView.setTextSize(size);
 38     }
 39
 40     @SuppressLint("NewApi")
 41     private void init() {
 42         mPaint.setAntiAlias(true);
 43         if (VERSION.SDK_INT > 11) {
 44             setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 45         }
 46
 47         mTextView = new TextView(getContext());
 48         RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
 49         params.addRule(RelativeLayout.CENTER_IN_PARENT);
 50         mTextView.setTextSize(13);
 51         mTextView.setTextColor(0xffffffff);
 52         mTextView.setLayoutParams(params);
 53         addView(mTextView);
 54     }
 55
 56     @Override
 57     protected void dispatchDraw(Canvas canvas) {
 59         mPaint.setColor(0xffff0000);
 60         canvas.drawCircle(getWidth() / 2, getHeight() / 2,                 getWidth() / 2, mPaint);
 61         super.dispatchDraw(canvas);
 62     }
 63
 64     @Override
 65     protected void onDraw(Canvas canvas) {
 66         super.onDraw(canvas);
 67     }
 68
 69     @Override
 70     public boolean onTouchEvent(MotionEvent event) {
 71         ViewGroup parent = getScrollableParent();
 72         switch (event.getAction()) {
 73         case MotionEvent.ACTION_DOWN:
 74             mHolderEventFlag = !CoverManager.getInstance().isRunning();
 75             if (mHolderEventFlag) {
 76                 if (parent != null)
 77                     parent.requestDisallowInterceptTouchEvent(true);
 78                 CoverManager.getInstance().start(this, event.getRawX(), event.getRawY(), mOnDragCompeteListener);
 79             }
 80             break;
 81         case MotionEvent.ACTION_MOVE:
 82             if (mHolderEventFlag) {
 83                 CoverManager.getInstance().update(event.getRawX(), event.getRawY());
 84             }
 85             break;
 86         case MotionEvent.ACTION_UP:
 87         case MotionEvent.ACTION_CANCEL:
 88             if (mHolderEventFlag) {
 89                 if (parent != null)
 90                     parent.requestDisallowInterceptTouchEvent(false);
 91                 CoverManager.getInstance().finish(this, event.getRawX(), event.getRawY());
 92             }
 93             break;
 94         }
 95
 96         return true;
 97     }
 98
 99     private ViewGroup getScrollableParent() {
100         View target = this;
101         while (true) {
102             View parent;
103             try {
104                 /**
105                  * ViewRootImpl cannot be cast to android.view.View
106                  */
107                 parent = (View) target.getParent();
108             } catch (Exception e) {
109                 return null;
110             }
111             if (parent == null)
112                 return null;
113             if (parent instanceof ListView || parent instanceof ScrollView) {
114                 return (ViewGroup) parent;
115             }
116             target = parent;
117         }
118
119     }
120
121     public void setOnDragCompeteListener(OnDragCompeteListener                  onDragCompeteListener) {
122         mOnDragCompeteListener = onDragCompeteListener;
123     }
124 }
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

WaterDropLibrary  http://download.csdn.net/detail/androidsj/7948845

时间: 2024-08-14 04:14:35

2、列表item_圆头像_信息提示的相关文章

Android SnackBar:你值得拥有的信息提示控件

概述: Snackbar提供了一个介于Toast和AlertDialog之间轻量级控件,它可以很方便的提供消息的提示和动作反馈. 有时我们想这样一种控件,我们想他可以想Toast一样显示完成便可以消失,又想在这个信息提示上进行用户反馈.写Toast没有反馈效果,写Dialog只能点击去dismiss它.是的,可能你会说是可以去自定义它们来达到这样的效果.而事实上也是这样. 实现: 其实要实现这样的一个提示窗口,只是针对自定义控件来说,应该是So easy的,不过这里我们想着会有一些比较完善的功能

[ExtJs5.1.0系列-第二天] 信息提示框组件&lt;Ext.MessageBox&gt;

在介绍ExtJs信息提示框组件之前,我们先来介绍一下ExtJs的组件配置. ExtJs组件通常有两种配置形式: (1) 用逗号分割的参数列表;  (2) 使用JSON对象作为组件提供配置信息.对于比较简单的配置一般采用逗号分隔的参数列表进行设置,对于较复杂的配置一般采用JSON对象的方式为组件提供配置信息. JSON简单介绍: JSON的全称是JavaScript Object Notation(JavaScript对象符号).JSON是一种结构化的,轻量级的,完全独立于语言的,基于文本的数据传

Ext信息提示对话框

Ext.window.MessageBox是一个工具类,他继承自Ext.window.Windoe对象,用来生成各种风格的信息提示对话框,其实例对象可以通过Ext.MessageBox或Ext.Msg进行访问,使用Ext.MessageBox和使用Ext.Msg有相同的效果,而后者提供了更简短的调用方式.为了描述方便后边我们将使用Ext.MessageBox代表Ext.window.MessageBox实例对象. /** **Ext.MessageBox和Ext.Msg只是引用了Ext.wind

Android BadgeView红点更新信息提示

应用市场很多应用程序中都会看见一些数字红点提示的效果,如QQ.微信以及一些提示更新应用的APP,以达到更好的提示功能的应用,本文将介绍一开源控件的使用实现红点更新信息提示效果. 一.BadgeView常用方法介绍: 1.setBadgeCount(int):设置提醒数字 2.setBadgeGravity(Gravity):设置位置布局 3.setTargetView(View):设置提示控件对象 4.setTypeface():设置显示字体 5.setShadowLayer():设置字体阴影

bootstrap错误警告信息提示

bootstrap提供了成功执行.警告和错误信息的样式. 在使用该功能的时候需要引入以下几个文件: bootstrap.css jquery.js(需放在bootstrap.js之前) bootstrap.js(官方推荐引入的是bootstrap-alert.js) 主要使用的样式: .span4 .alert(默认样式) .alert alert-successs .alert alert-error .alert alert-info 实例代码如下: <!DOCTYPE html> <

线程运行栈StackTrace用法,代码调用树查看,出错代码位置信息提示,代码所在类名包名文件名查看

1.代码调用树查看 2.出错代码位置信息提示 功能函数: /** 在LogCat中输出提示信息info,并给出输出该信息在代码中的完整调用树 */ public static void MessageWithSrcTree(String info) { StackTraceElement[] elem = Thread.currentThread().getStackTrace(); //从当前位置,获取代码调用堆栈 for(StackTraceElement e : elem) { Strin

delphi vcl信息提示总结

我现在使用二种信息提示的方式,一种当然是使用Application.messageBox的方式,就是即时提示. 另一种就是将所有的错误和警告写在一起,适用于大批量数据的录入,一条条提示太麻烦了. 1 即时提示 我将Application.messageBox进行了封装,MessageBox的哪些参数太多了,哪个有时间去记.封装如下: //普通提示 procedure MsgInfo(const strInfo,strTitle:String); begin Application.message

高级控件【安卓5】——信息提示框、对话框

Toast信息提示框 1 Button bt1=(Button)findViewById(R.id.Tbt01); 2 Button bt2=(Button)findViewById(R.id.Tbt02); 3 bt1.setOnClickListener(new OnClickListener() { 4 public void onClick(View v) { 5 Toast.makeText(Toast0.this, "按钮1短提示", 6 Toast.LENGTH_SHOR

信息提示框、对话框

Toast信息提示框 1Button bt1=(Button)findViewById(R.id.Tbt01); 2 Button bt2=(Button)findViewById(R.id.Tbt02); 3 bt1.setOnClickListener(new OnClickListener() { 4 public void onClick(View v) { 5 Toast.makeText(Toast0.this, "按钮1短提示", 6 Toast.LENGTH_SHORT