当前位置: 编程技术>移动开发
本页文章导读:
▪联系人字母目录实现 联系人字母索引实现字母索引实现方式主要是通过Adapter继承 SectionIndexer接口,如下
public class HeaderAdapter extends ArrayAdapter<String> implements SectionIndexer {
private List<String> items=new ArrayList<.........
▪ 苹果手机黑屏了,怎么处理 苹果手机黑屏了,怎么办?今天用手机调试的时候,iphone突然就黑屏了,然后按home键不管用,电源键也不管用;
上网查询,解决如下 :
第一种方法直接按住电源键,重新开关机;(这种方.........
▪ 相干图片处理的一些片段-Xfermode属性 有关图片处理的一些片段--Xfermode属性1、PorterDuffXfermode
PorterDuff.Mode的十六种情况可以看APIDemos中的效果,唯一记录一下,做测试时候迷茫的地方
private void drawIntoBitmap(Bitmap bm) {
Canvas .........
[1]联系人字母目录实现
来源: 互联网 发布时间: 2014-02-18
联系人字母索引实现
字母索引实现方式主要是通过Adapter继承 SectionIndexer接口,如下
public class HeaderAdapter extends ArrayAdapter<String> implements SectionIndexer { private List<String> items=new ArrayList<String>(); private LayoutInflater mInflater; private int resource; private int textViewResourceId; private String[] sections; private HashMap<String,Integer> maps=new HashMap<String, Integer>(); public HeaderAdapter(Context context, int resource, int textViewResourceId, List<String> items) { super(context, resource, textViewResourceId, items); this.items=items; mInflater=LayoutInflater.from(context); this.resource=resource; this.textViewResourceId=textViewResourceId; //A-Z字母列表 sections=context.getResources().getStringArray(R.array.sections); initMaps(); // TODO Auto-generated constructor stub } private void initMaps(){
//遍历数据源,用来保存相应字母的position位置
for (int i=0;i<items.size();i++) { String start=items.get(i).substring(0,1).toUpperCase(); if(!maps.containsKey(start)){ maps.put(start, i); } } } @Override public int getCount() { // TODO Auto-generated method stub return items.size(); } @Override public String getItem(int position) { // TODO Auto-generated method stub return items.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return super.getItemId(position); } @Override public int getPosition(String item) { // TODO Auto-generated method stub return super.getPosition(item); } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub convertView =mInflater.inflate(resource, null); TextView textView=(TextView)convertView.findViewById(textViewResourceId); TextView header=(TextView)convertView.findViewById(R.id.header); String text=items.get(position); String start=text.substring(0, 1).toUpperCase(); if(maps.containsKey(start)&&maps.containsValue(position)){ header.setVisibility(View.VISIBLE); header.setText(start); } textView.setText(text); return convertView; } public int getPositionForSection(int sectionIndex) { // TODO Auto-generated method stub
//主要方法根据字母索引位置,获取需要滚动的position位置
if(maps.get(sections[position])==null){ return -1; } return maps.get(sections[sectionIndex]); } public int getSectionForPosition(int position) { // TODO Auto-generated method stub return 0; } public String[] getSections() { // TODO Auto-generated method stub return sections; } }
2.自定义SearchBar,实现字母索引
public class SearchBar extends View { private String[] section; private int height;
private int indexHeight;// private Paint textPaint; private int width; private int sectionLength; private int curSetion; private Rect mIndicatorRect = new Rect(); private Drawable mIndicatorDrawable; private SectionIndexer mIndexer; private ListView mList; private PopupWindow mPopupWindow; private TextView mPromptText; public SearchBar(Context context) { this(context,null); // TODO Auto-generated constructor stub } public SearchBar(Context context,AttributeSet attr) { this(context,attr,0); // TODO Auto-generated constructor stub } public SearchBar(Context context,AttributeSet attr,int def) { super(context,attr,0); // TODO Auto-generated constructor stub
//A-Z
section=getResources().getStringArray(R.array.sections); sectionLength=section.length; textPaint=new Paint(); textPaint.setColor(Color.BLACK); textPaint.setTextSize(14); mIndicatorDrawable = getResources().getDrawable(R.drawable.bladeview_indicator_normal); mPromptText=(TextView)LayoutInflater.from(context).inflate(R.layout.popup_text, null); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); int offsetX=0; mIndicatorRect.set(offsetX, indexHeight*curSetion, width, indexHeight*(curSetion+1)); mIndicatorDrawable.setBounds(mIndicatorRect); mIndicatorDrawable.draw(canvas); for (int i=0;i<section.length;i++) { canvas.drawText(section[i], width/2, (i+1)*indexHeight, textPaint); } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub super.onMeasure(widthMeasureSpec, heightMeasureSpec); height=getHeight(); width=getWidth(); indexHeight=height/section.length; } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: float y=event.getY(); curSetion=getIndex(y); setPromptText(curSetion); showPopupWindows(); int position=0; if(mIndexer!=null){ position=mIndexer.getPositionForSection(curSetion); mList.setSelectionFromTop(position, 0); } break; case MotionEvent.ACTION_MOVE: y=event.getY(); curSetion=getIndex(y); setPromptText(curSetion); showPopupWindows(); position=0; if(mIndexer!=null){ position=mIndexer.getPositionForSection(curSetion); mList.setSelectionFromTop(position, 0); } invalidate(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: disMissPopupWindows(); break; default: break; } return true; } //根据触摸Y值获取字母Index
private int getIndex(float y){ for (int i = 1; i <sectionLength; i++) { if(y>i*indexHeight&&y<(i+1)*indexHeight){ return i; } } return 0; } public void setListView(ListView list){ Adapter adapter=list.getAdapter(); if(adapter instanceof SectionIndexer){ mIndexer=(SectionIndexer)adapter; mList=list; } } private void setPromptText(int sec){ mPromptText.setText(section[sec]); } private void createPopupWindows(){ if(mPopupWindow==null){ mPopupWindow=new PopupWindow(); mPopupWindow.setContentView(mPromptText); mPopupWindow.setHeight(LayoutParams.WRAP_CONTENT); mPopupWindow.setWidth(LayoutParams.WRAP_CONTENT); ColorDrawable d=new ColorDrawable(Color.TRANSPARENT); mPopupWindow.setBackgroundDrawable(d); } } private void showPopupWindows(){ createPopupWindows(); mPopupWindow.showAtLocation(this, Gravity.CENTER, -1, -1); } private void disMissPopupWindows(){ mPopupWindow.dismiss(); } }
3.测试Activity
public class MainActivity extends Activity { private List<String> items=new ArrayList<String>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView list=(ListView)findViewById(R.id.listView1); SearchBar bar=(SearchBar)findViewById(R.id.searchbar); items.add("Action"); items.add("Adventure"); items.add("asg"); items.add("agf"); items.add("bdd"); items.add("ball"); items.add("call"); items.add("Documentary"); items.add("Foreign"); items.add("full"); items.add("History"); items.add("Independent"); items.add("Romance"); list.setAdapter(new HeaderAdapter(this, R.layout.listitem, R.id.items, items)); bar.setListView(list); } @Override public boolean onCreateOptionsMenu(Menu menu) { // getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
4.效果图
[2] 苹果手机黑屏了,怎么处理
来源: 互联网 发布时间: 2014-02-18
苹果手机黑屏了,怎么办?
今天用手机调试的时候,iphone突然就黑屏了,然后按home键不管用,电源键也不管用;
上网查询,解决如下 :
第一种方法直接按住电源键,重新开关机;(这种方法试了不管用,接着看下一个)
第二种方法,按住home键和电源键一起十几秒左右;(这种我行的通了,如果再不行看第三方方法)
第三种方法,连接电脑,进入itunes恢复系统。
1楼mm22233天前 17:34直接扣电池嘛,嘿嘿
[3] 相干图片处理的一些片段-Xfermode属性
来源: 互联网 发布时间: 2014-02-18
有关图片处理的一些片段--Xfermode属性
1、PorterDuffXfermode
1、PorterDuffXfermode
PorterDuff.Mode的十六种情况可以看APIDemos中的效果,唯一记录一下,做测试时候迷茫的地方
private void drawIntoBitmap(Bitmap bm) { Canvas canvas = new Canvas(bm); Paint paint = new Paint(); InputStream stream = null; try { stream = mContext.getAssets().open("icon.jpg"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(stream); bitmap = RoundActivity.getRoundCornerBitmap(bitmap);//只是获取一个圆角的图片 stream = getResources().openRawResource(R.drawable.ic_launcher); Bitmap src = BitmapFactory.decodeStream(stream); canvas.drawBitmap(bitmap, 100, 100, paint); canvas.drawBitmap(bitmap, 0, 0, paint); //SRC_OVER与SRC模式相比,主要区别SRC_OVER是会有透明度影响。而DST的话,则是src区域不显示,不像SRC模式,只是src区域所占的地方,det区对应地方被覆盖 //Over 类型的MODE只有Config为ARGB,以及Alph8类型的位图才会有效果 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER)); //只有src占用的区间才会用到Xfermode模式进行运算,而不是整个Canvas区域生效。当然可以指定dst区域.或着如下边注释行的方法,设置了dirst区域。 // canvas.drawBitmap(src,new Rect(0, 0, src.getWidth(), src.getHeight()),new Rect(0, 0, 200 , 200),paint); canvas.drawBitmap(src, 0, 0,paint); paint.setARGB(0x80, 0x0, 0xff, 0x0); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); paint.setTextSize(60) ;// paint.setShader(mShader); paint.setTextAlign(Paint.Align.CENTER);//如果是这个属性,则drawtext中的x,y坐标指的是文字所占区域的中心 Paint.FontMetrics fm = paint.getFontMetrics(); //如果是文字的话,XFermode设置后,只有文字的轨迹占用的地方才会生效 canvas.drawText("text", bm.getWidth()/2, (bm.getWidth()-fm.ascent)/2, paint); }
如图
2、AvoidXfermode
private void drawInBitmapAvoid(Bitmap bm) { Canvas canvas = new Canvas(bm); Paint paint = new Paint(); canvas.drawBitmap(mBitmap, new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight()), new Rect(0, 0, bm.getWidth(), bm.getHeight()), paint); paint.setARGB(0xff, 0xff, 0x00, 0x00); //Mode.AVOID 模式下是给op-color不一样的地方才绘制 // 如果tolerance 即误差为0,或者说完全不一样,才会绘制 // 如果tolerance 即误差为255,或者说稍微不一样,就可以绘制 //这边有点拗口,看另外一个模式就明白了 paint.setXfermode(new AvoidXfermode(0xff505050, 0, AvoidXfermode.Mode.AVOID));; canvas.drawCircle(0, 0, bm.getWidth()/2, paint); paint.setXfermode(new AvoidXfermode(0xff505050, 255, AvoidXfermode.Mode.AVOID));; canvas.drawCircle(bm.getWidth(), 0, bm.getWidth()/2, paint); // 如果是Mode.TARGET模式,只给与op-color一样的像素点上绘制 //如果tolerance为0,即完全一样,才会给这个像素点绘制 //如果tolerance为255,即稍微一样一点,就会给这个像素点绘制 paint.setXfermode(new AvoidXfermode(0xff505050, 0, AvoidXfermode.Mode.TARGET));; canvas.drawCircle(0, bm.getHeight(), bm.getWidth()/2, paint); paint.setXfermode(new AvoidXfermode(0xff505050, 255, AvoidXfermode.Mode.TARGET));; canvas.drawCircle(bm.getWidth(), bm.getHeight(), bm.getWidth()/2, paint); }
如图
3、PixelXorXfermode
文档中说PixelXorXfermode implements a simple pixel xor (op ^ src ^ dst). 我自认为模块一和模块二效果会一样,但是实验结果不同。
这个类,我完全被他打败了。测试了一下午也没测出规律和原因来,如果有懂的,望不吝赐教
而且经常不同的是R值和B值互换,有时候又正常。真不知道哪里错了
private void drawInBitmapPixel(Bitmap bm) { Canvas canvas = new Canvas(bm); Paint paint = new Paint(); int dst = 0xff00ffff; paint.setColor(dst); Rect rect = new Rect(0, 0, bm.getWidth(), bm.getHeight()/2-8); canvas.drawRect(rect, paint); int src = 0xffffff00; int opr = 0xffff0000; //模块一 paint.setXfermode(new PixelXorXfermode(opr)); paint.setColor(src); canvas.drawRect(rect, paint); //模块二 paint.setXfermode(null); int result = opr^src^dst; /*//R和B 互换 0x ff ff ff ff // 取B值 int b = result&0x000000ff; //取R值 int r = result&0x00ff0000; //移动到对应位置 b = b<<16; r = r>>16; //过滤RB值 result = result&0xff00ff00; //放入RB值 result |= r; result |= b;*/ paint.setColor(result); rect = new Rect(0,bm.getHeight()/2+8,bm.getWidth(),bm.getHeight()); canvas.drawRect(rect, paint); paint.setXfermode(null); paint.setTextSize(15); paint.setTextAlign(Align.CENTER); canvas.drawText("^color="+Integer.toHexString(paint.getColor()), bm.getWidth()/2, (bm.getHeight()-paint.getFontMetrics().ascent)/2, paint); }
最新技术文章: