Android Open Source - NoiseBridge_General Key






From Project

Back to project page NoiseBridge_General.

License

The source code is released under:

GPLv3.txt

If you think the Android project NoiseBridge_General 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 com.metamage.noisegate;
/*  www  .  jav  a 2 s .  c o m*/
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import com.noysbrij.noisebridgeGeneral.*;
import android.util.*;


public class Key extends Button
{
  
  private boolean dragging    = false;
  private boolean outOfBounds = false;
  
  private View counterpart;
  private Context context;
  
  public Key( Context context, AttributeSet attrs, int defStyle )
  {
    super( context, attrs, defStyle );
    
    init();
  }
  
  public Key( Context context, AttributeSet attrs )
  {
    super( context, attrs );
    
    init();
  }
  
  public Key( Context context ){
    super( context );
    setKeyContext(context);
    init();
  }
  
  private void init()
  {
    F.setKeyColor( this, Data.normalColor );
  }
  
  public void setKeyContext(Context thisContext){
    this.context = thisContext;
    
    Log.e("NBG", "context for "+this.context+ " is "+thisContext);
  }
  
  public void setCounterpart( int id )
  {
    Activity activityContext = (Activity) this.context;
    
    counterpart = activityContext.findViewById( id );
  }
  
  private Button getCounterpart()
  {
    if ( counterpart == null )
    {
      final int i = Character.digit( getText().charAt( 0 ), 10 );
      
      if ( i >= 0 )
      {
        final int id = Data.fakeKeyIds[ i ];
        
        setCounterpart( id );
      }
    }
    
    return (Button) counterpart;
  }
  
  public boolean isDragging()
  {
    return dragging;
  }
  
  private boolean hitFeedback()
  {
    return true;
  }
  
  private void beginDrag()
  {
     F.setKeyColor( this, Data.pressedColor );
  }
  
  private void updateDrag( float x, float y )
  {
    final boolean inside = getBackground().getBounds().contains( (int) x, (int) y );
    
    if ( inside == outOfBounds )
    {
      int color;
      
      if ( inside )
      {
        color = Data.pressedColor;
      }
      else
      {
        color = Data.normalColor;
      }
      
      F.setKeyColor( this, color );
      
      outOfBounds = !inside;
    }
  }
  
  private void endDrag()
  {
    if ( !outOfBounds )
    {
      F.setKeyColor( this, Data.normalColor );
       
       performClick();
       
       Button fakeKey = getCounterpart();
       
       if ( fakeKey != null )
       {
        F.setKeyColor( fakeKey, Data.pressedColor );
        
        F.fadeViewToAlpha( fakeKey, 0 );
       }
    }
  }
  
  @Override
  public boolean onTouchEvent( MotionEvent event )
  {
    final int action = event.getActionMasked();
    
    switch ( action )
    {
      case MotionEvent.ACTION_DOWN:
        break;
      
      case MotionEvent.ACTION_MOVE:
      case MotionEvent.ACTION_UP:
        if ( dragging )
        {
          break;
        }
        
        // fall through
      
      default:
        return super.onTouchEvent( event );
    }
    
    final float x = event.getX();
    final float y = event.getY();
    
    if ( action == MotionEvent.ACTION_DOWN )
    {
      dragging    = true;
      outOfBounds = false;
      
      beginDrag();
      
      return hitFeedback();
    }
    else  // MOVE or UP
    {
      updateDrag( x, y );
      
      if ( action == MotionEvent.ACTION_UP )
      {
        endDrag();
        
        dragging = false;
      }
    }
    
    return true;
  }
}




Java Source Code List

com.loopj.android.http.AsyncHttpClient.java
com.loopj.android.http.AsyncHttpRequest.java
com.loopj.android.http.AsyncHttpResponseHandler.java
com.loopj.android.http.BinaryHttpResponseHandler.java
com.loopj.android.http.JsonHttpResponseHandler.java
com.loopj.android.http.PersistentCookieStore.java
com.loopj.android.http.RequestParams.java
com.loopj.android.http.RetryHandler.java
com.loopj.android.http.SerializableCookie.java
com.loopj.android.http.SimpleMultipartEntity.java
com.loopj.android.http.SyncHttpClient.java
com.metamage.noisegate.Completion.java
com.metamage.noisegate.Data.java
com.metamage.noisegate.F.java
com.metamage.noisegate.GetAndDiscardUrlTask.java
com.metamage.noisegate.Key.java
com.metamage.noisegate.Noisegate.java
com.metamage.noisegate.Teletype.java
com.noysbrij.fragments.DatePickerFragment.java
com.noysbrij.fragments.JSInterface.java
com.noysbrij.fragments.ListViewFragment.java
com.noysbrij.fragments.NBWebViewFragment.java
com.noysbrij.fragments.TicketsArrayAdapter.java
com.noysbrij.fragments.TimePickerFragment.java
com.noysbrij.noisebridgeGeneral.NoiseBridgeGeneral.java
com.noysbrij.noisebridgeGeneral.ReadJson.java
com.noysbrij.noisebridgeGeneral.Ticket.java
com.noysbrij.noisebridgeGeneral.TicketsExpandableListAdapter.java
com.noysbrij.noisebridgeGeneral.Tickets.java