Android Open Source - PassGraph Pass Graph Widget






From Project

Back to project page PassGraph.

License

The source code is released under:

GNU General Public License

If you think the Android project PassGraph listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package littlesoft.widgets;
//ww  w . java2  s. c  o  m
import java.util.LinkedList;


import littlesoft.Firer;
import littlesoft.FirerObserver;


import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


public class PassGraphWidget extends LinearLayout implements View.OnTouchListener{
  private LinkedList<SensitivePoint> imgs = new LinkedList<SensitivePoint>();
  private Firer<Integer> firer= new Firer<Integer>(); 
  
  
  
  private void init(){
    setOrientation(VERTICAL);
    
    for(int j=0; j<4; j++){
      LinearLayout row = new LinearLayout(getContext());
      row.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      for(int i=0; i<4 ; i++){
        SensitivePoint img = new SensitivePoint(getContext());
        img.setScaleType(ImageView.ScaleType.FIT_END);
        img.setImageResource(R.drawable.node);
        imgs.add(img);
        row.addView(img, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
      }
      addView(row);
    }
    setOnTouchListener(this);
    

  }
  
  public PassGraphWidget( Context c) {
    super(c);
    init();
      
  }
  
  public PassGraphWidget(Context context, AttributeSet attrs){
      super(context, attrs);
      init();
  } 
  
  
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev){
    
    for(ImageView i : imgs){
      i.dispatchTouchEvent(ev);
    }
    onTouch(null, ev);
    return false;
  }
  
  @Override
  public boolean onTouch(View v, MotionEvent ev){
    if(ev.getAction() == MotionEvent.ACTION_UP){
      Integer token = 0;
      
      for(SensitivePoint p : imgs){
        token = (token <<3) + p.getValue();
      }
      firer.fire(token);
      return true;
    }
    else if(ev.getAction() == MotionEvent.ACTION_DOWN){
      System.out.println("Action Down reset sensitive point status");
      for(SensitivePoint p : imgs){
        p.reset();
      }
      return true;
    }
    
    return false;
    
  }
  public void registerObserver(FirerObserver<Integer> obs){
    firer.registerObserver(obs);
  }

}




Java Source Code List

littlesoft.FirerObserver.java
littlesoft.Firer.java
littlesoft.MutableDouble.java
littlesoft.widgets.PassGraphTest.java
littlesoft.widgets.PassGraphWidget.java
littlesoft.widgets.SensitivePoint.java
littlesoft.widgets.util.SystemUiHiderBase.java
littlesoft.widgets.util.SystemUiHiderHoneycomb.java
littlesoft.widgets.util.SystemUiHider.java