zoukankan      html  css  js  c++  java
  • 结对项目 sport club(三)

    好友搜索代码:

    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Typeface;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.View;
    
    public class LetterlistViewForFriend extends View {
    
    	public LetterlistViewForFriend(Context context, AttributeSet attrs)
    	{
    		super(context, attrs);
    		// TODO Auto-generated constructor stub
    	}
    	public LetterlistViewForFriend(Context context)
    	{
    		super(context);
    	}
    
    	public LetterlistViewForFriend(Context context, AttributeSet attrs, int defStyle)
    	{
    		super(context, attrs, defStyle);
    	}
    
    	OnTouchingLetterChangedListener onTouchingLetterChangedListener;
    	String[] b =
    	{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    	int choose = -1;
    	Paint paint = new Paint();
    	
    	boolean showBkg = false;
    
    	@Override
    	protected void onDraw(Canvas canvas)
    	{
    		super.onDraw(canvas);
    		
    		if (showBkg)
    		{
    			canvas.drawColor(Color.parseColor("#40000000"));
    		}
    
    		int height = getHeight();
    		int width = getWidth();
    		int singleHeight = height / b.length;
    		for (int i = 0; i < b.length; i++)
    		{
    			//paint.setTextSize(19) ;
    			paint.setColor(Color.BLACK);
    			paint.setTypeface(Typeface.DEFAULT_BOLD);
    			
    			paint.setAntiAlias(true);
    			if (i == choose)
    			{
    				paint.setColor(Color.parseColor("#3399ff"));
    				paint.setFakeBoldText(true);
    			}
    			float xPos = width / 2 - paint.measureText(b[i]) / 2;
    			float yPos = singleHeight * i + singleHeight;
    			
    			canvas.drawText(b[i], xPos, yPos, paint);
    			paint.reset();
    		}
    
    	}
    
    	@Override
    	public boolean dispatchTouchEvent(MotionEvent event)
    	{
    		final int action = event.getAction();
    		final float y = event.getY();
    		final int oldChoose = choose;
    		final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
    		final int c = (int) (y / getHeight() * b.length);
    
    		switch (action)
    		{
    		case MotionEvent.ACTION_DOWN:
    			showBkg = true;
    			if (oldChoose != c && listener != null)
    			{
    				if (c > 0 && c < b.length)
    				{
    					listener.onTouchingLetterChanged(b[c]);
    					choose = c;
    					invalidate();
    				}
    			}
    
    			break;
    		case MotionEvent.ACTION_MOVE:
    			if (oldChoose != c && listener != null)
    			{
    				if (c > 0 && c < b.length)
    				{
    					listener.onTouchingLetterChanged(b[c]);
    					choose = c;
    					invalidate();
    				}
    			}
    			break;
    		case MotionEvent.ACTION_UP:
    			showBkg = true;
    			if (oldChoose != c && listener != null)
    			{
    				if (c > 0 && c < b.length)
    				{
    					listener.onTouchingLetterChanged(b[c]);
    					choose = c;
    					invalidate();
    				}
    			}
    			
    			break;
    		}
    		return true;
    	}
    
    	
    	@Override
    	public boolean onTouchEvent(MotionEvent event)
    	{
    		return super.onTouchEvent(event);
    	}
    
    	public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener onTouchingLetterChangedListener)
    	{
    		this.onTouchingLetterChangedListener = onTouchingLetterChangedListener;
    	}
    
    	public interface OnTouchingLetterChangedListener
    	{
    		public void onTouchingLetterChanged(String s);
    	}
    }
    

      

  • 相关阅读:
    CodeForces 279B Books (滑动窗口)
    LightOJ 1010 Knights in Chessboard (规律)
    HDU 2665 Kth number (主席树)
    URAL 2014 Zhenya moves from parents (线段树)
    HDU 5973 Game of Taking Stones (威佐夫博弈+高精度)
    HDU 5974 A Simple Math Problem (解方程)
    HDU 5980 Find Small A (水题)
    Spring入门篇——第5章 Spring AOP基本概念
    Java入门第二季——第4章 多态
    Spring入门篇——第4章 Spring Bean装配(下)
  • 原文地址:https://www.cnblogs.com/wanghao1521/p/7031168.html
Copyright © 2011-2022 走看看