@Override
  public boolean onTouchEventInternal(MotionEvent e) {
    final int action = e.getActionMasked();

    // This path mimics the Android long press detection while still allowing
    // other touch events to come through the gesture detector.
    if (!mUseDefaultLongPress) {
      if (e.getPointerCount() > 1) {
        // If there's more than one pointer ignore the long press.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
      } else if (action == MotionEvent.ACTION_DOWN) {
        // If there was a pending event kill it off.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
        mLongPressRunnable.init(e);
        mLongPressHandler.postDelayed(mLongPressRunnable, mLongPressTimeoutMs);
      } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        cancelLongPress();
      } else if (mLongPressRunnable.isPending()) {
        // Allow for a little bit of touch slop.
        MotionEvent initialEvent = mLongPressRunnable.getInitialEvent();
        float distanceX = initialEvent.getX() - e.getX();
        float distanceY = initialEvent.getY() - e.getY();
        float distance = distanceX * distanceX + distanceY * distanceY;

        // Save a square root here by comparing to squared touch slop
        if (distance > mScaledTouchSlop * mScaledTouchSlop) {
          cancelLongPress();
        }
      }
    }

    // Sends the pinch event if two or more fingers touch the screen. According to test
    // Android handles the fingers order pretty consistently so always requesting
    // index 0 and 1 works here.
    // This might need some rework if 3 fingers event are supported.
    if (e.getPointerCount() > 1) {
      mHandler.onPinch(
          e.getX(0) * mPxToDp,
          e.getY(0) * mPxToDp,
          e.getX(1) * mPxToDp,
          e.getY(1) * mPxToDp,
          action == MotionEvent.ACTION_POINTER_DOWN);
      mDetector.setIsLongpressEnabled(false);
      mSingleInput = false;
    } else {
      mDetector.setIsLongpressEnabled(mUseDefaultLongPress);
      mSingleInput = true;
    }
    mDetector.onTouchEvent(e);

    // Propagate the up event after any gesture events.
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
      mHandler.onUpOrCancel();
    }
    return true;
  }
 private void init(Context context, AttributeSet attributeset, int i)
 {
     ViewConfiguration viewconfiguration = ViewConfiguration.get(context);
     mScaledDensity = context.getResources().getDisplayMetrics().density / 2.0F;
     attributeset = context.getTheme().obtainStyledAttributes(attributeset, com.aviary.android.feather.sdk.R.styleable.AviaryWheel, i, 0);
     mShadowBottom = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelShadowTop);
     mLinesSingle = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelLine);
     mLinesIndicator = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelIndicator);
     mEdgeStyle = attributeset.getResourceId(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviary_edgeStyle, 0);
     attributeset.recycle();
     mEdgeOffset = (float)(20D * (double)mScaledDensity);
     mLineWidth = mLinesSingle.getIntrinsicWidth();
     mLinesPaint = new Paint(7);
     if (!isInEditMode())
     {
         mGestureDetector = new GestureDetector(context, this);
         mGestureDetector.setIsLongpressEnabled(false);
     }
     mScroller = new ScrollerRunnable(this, 200, viewconfiguration.getScaledOverflingDistance(), null);
     mVibrationHelper = new VibrationHelper(context, true);
     mEdgeLeft = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeRight = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeLeft.setEdgeMaxAlpha(100);
     mEdgeRight.setEdgeMaxAlpha(100);
     mNextValue = -1;
     mCurrentValue = 0.0D;
 }
  /**
   * Constructor
   *
   * @param context the current context
   * @param listener the scrolling listener
   */
  public WheelScroller(Context context, ScrollingListener listener) {
    gestureDetector =
        new GestureDetector(
            context,
            new SimpleOnGestureListener() {
              public boolean onScroll(
                  MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // Do scrolling in onTouchEvent() since onScroll() are not call immediately
                //  when user touch and move the spinnerwheel
                return true;
              }

              public boolean onFling(
                  MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                lastScrollPosition = 0;
                scrollerFling(lastScrollPosition, (int) velocityX, (int) velocityY);
                setNextMessage(MESSAGE_SCROLL);
                return true;
              }

              // public boolean onDown(MotionEvent motionEvent);

            });
    gestureDetector.setIsLongpressEnabled(false);

    scroller = new Scroller(context);

    this.listener = listener;
    this.context = context;
  }
  public TrackingInputHandler(DesktopViewInterface viewer, Context context, RenderData renderData) {
    mViewer = viewer;
    mRenderData = renderData;

    GestureListener listener = new GestureListener();
    mScroller = new GestureDetector(context, listener, null, false);

    // If long-press is enabled, the gesture-detector will not emit any further onScroll
    // notifications after the onLongPress notification. Since onScroll is being used for
    // moving the cursor, it means that the cursor would become stuck if the finger were held
    // down too long.
    mScroller.setIsLongpressEnabled(false);

    mZoomer = new ScaleGestureDetector(context, listener);
    mTapDetector = new TapGestureDetector(context, listener);
    mFlingScroller = new Scroller(context);
    mSwipePinchDetector = new SwipePinchDetector(context);

    mCursorPosition = new PointF();

    // The threshold needs to be bigger than the ScaledTouchSlop used by the gesture-detectors,
    // so that a gesture cannot be both a tap and a swipe. It also needs to be small enough so
    // that intentional swipes are usually detected.
    float density = context.getResources().getDisplayMetrics().density;
    mSwipeThreshold = 40 * density;
  }
Beispiel #5
0
  public ShSwitchView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShSwitchView);

    tintColor = ta.getColor(R.styleable.ShSwitchView_tintColor, 0xFF9CE949);
    tempTintColor = tintColor;

    int defaultOuterStrokeWidth =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1.5F, context.getResources().getDisplayMetrics());
    int defaultShadowSpace =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 5, context.getResources().getDisplayMetrics());

    outerStrokeWidth =
        ta.getDimensionPixelOffset(
            R.styleable.ShSwitchView_outerStrokeWidth, defaultOuterStrokeWidth);
    shadowSpace =
        ta.getDimensionPixelOffset(R.styleable.ShSwitchView_shadowSpace, defaultShadowSpace);

    ta.recycle();

    knobBound = new RectF();
    innerContentBound = new RectF();
    ovalForPath = new RectF();

    tempForRoundRect = new RectF();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    roundRectPath = new Path();

    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    if (Build.VERSION.SDK_INT >= 11) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    innerContentAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, innerContentProperty, innerContentRate, 1.0F);
    innerContentAnimator.setDuration(commonDuration);
    innerContentAnimator.setInterpolator(new DecelerateInterpolator());

    knobExpandAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobExpandProperty, knobExpandRate, 1.0F);
    knobExpandAnimator.setDuration(commonDuration);
    knobExpandAnimator.setInterpolator(new DecelerateInterpolator());

    knobMoveAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobMoveProperty, knobMoveRate, 1.0F);
    knobMoveAnimator.setDuration(commonDuration);
    knobMoveAnimator.setInterpolator(new DecelerateInterpolator());

    shadowDrawable = context.getResources().getDrawable(R.drawable.shadow);
  }
Beispiel #6
0
  /**
   * Constructor
   *
   * @param context the current context
   * @param listener the scrolling listener
   */
  public WheelScroller(Context context, ScrollingListener listener) {
    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    scroller = new Scroller(context);

    this.listener = listener;
    this.context = context;
  }
 /**
  * Initializes class data.
  *
  * @param context the context
  */
 private void initData(Context context) {
   mContext = context;
   gestureDetector = new GestureDetector(context, gestureListener);
   gestureDetector.setIsLongpressEnabled(false);
   scroller = new Scroller(context);
   DisplayMetrics displayMetrics = new DisplayMetrics();
   ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
   screenWidth = displayMetrics.widthPixels;
   screenHeight = displayMetrics.heightPixels;
 }
Beispiel #8
0
  /**
   * Constructor for XML inflation.
   *
   * @param context the context to inflate with
   * @param attrs the XML attrs
   * @param defStyle the default style resource id
   */
  public LeftGallery(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    mGestureDetector = new GestureDetector(context, this);
    mGestureDetector.setIsLongpressEnabled(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LeftGallery, defStyle, 0);
    int spacing = a.getDimensionPixelOffset(R.styleable.LeftGallery_spacing, 0);
    setSpacing(spacing);

    a.recycle();
  }
  private void initLoopView(Context context) {
    this.context = context;
    handler = new MessageHandler(this);
    gestureDetector = new GestureDetector(context, new LoopViewGestureListener(this));
    gestureDetector.setIsLongpressEnabled(false);

    isLoop = true;

    totalScrollY = 0;
    initPosition = -1;

    initPaints();
  }
Beispiel #10
0
 /**
  * By default, sorting is enabled, and removal is disabled.
  *
  * @param dslv The DSLV instance
  * @param dragHandleId The resource id of the View that represents the drag handle in a list item.
  */
 public DragSortController(
     DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode) {
   super(dslv);
   mDslv = dslv;
   mDetector = new GestureDetector(dslv.getContext(), this);
   mFlingRemoveDetector = new GestureDetector(dslv.getContext(), mFlingRemoveListener);
   mFlingRemoveDetector.setIsLongpressEnabled(false);
   mTouchSlop = ViewConfiguration.get(dslv.getContext()).getScaledTouchSlop();
   mDragHandleId = dragHandleId;
   setRemoveMode(removeMode);
   setDragInitMode(dragInitMode);
   mOrigFloatAlpha = dslv.getFloatAlpha();
 }
Beispiel #11
0
  public void Init(Context context) {
    Log.d(LOG_TAG, "Init");
    totalPageNum = 0;
    mContext = context;
    mSelectCorner = Corner.None;

    mGestureListener = new BookOnGestureListener();
    mGestureDetector = new GestureDetector(mGestureListener);
    mGestureDetector.setIsLongpressEnabled(false);
    aniEndHandle = new Handler();

    this.setOnTouchListener(touchListener);
    this.setLongClickable(true);
  }
  public TouchRoateImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setScaleType(ScaleType.MATRIX); // 重点
    // DisplayMetrics dm = new DisplayMetrics();
    // ((Activity) context).getWindowManager().getDefaultDisplay()
    // .getMetrics(dm);
    // windowWidth = dm.widthPixels; // 得到宽度
    // windowHeight = dm.heightPixels; // 得到高度
    currentContext = context;
    current = this;
    mGestureDetector = new GestureDetector(context, this);
    mGestureDetector.setIsLongpressEnabled(true);

    m = new Matrix();
  }
Beispiel #13
0
  public Panel(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel);
    mDuration =
        a.getInteger(R.styleable.Panel_animationDuration, 750); // duration defaults to 750 ms
    mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM); // position defaults to BOTTOM
    mLinearFlying =
        a.getBoolean(R.styleable.Panel_linearFlying, false); // linearFlying defaults to false
    mWeight = a.getFraction(R.styleable.Panel_weight, 0, 1, 0.0f); // weight defaults to 0.0
    if (mWeight < 0 || mWeight > 1) {
      mWeight = 0.0f;
      Log.w(TAG, a.getPositionDescription() + ": weight must be > 0 and <= 1");
    }
    mOpenedHandle = a.getDrawable(R.styleable.Panel_openedHandle);
    mClosedHandle = a.getDrawable(R.styleable.Panel_closedHandle);

    RuntimeException e = null;
    mHandleId = a.getResourceId(R.styleable.Panel_handle, 0);
    if (mHandleId == 0) {
      e =
          new IllegalArgumentException(
              a.getPositionDescription()
                  + ": The handle attribute is required and must refer to a valid child.");
    }
    mContentId = a.getResourceId(R.styleable.Panel_content, 0);
    if (mContentId == 0) {
      e =
          new IllegalArgumentException(
              a.getPositionDescription()
                  + ": The content attribute is required and must refer to a valid child.");
    }
    a.recycle();

    if (e != null) {
      throw e;
    }
    mOrientation = (mPosition == TOP || mPosition == BOTTOM) ? VERTICAL : HORIZONTAL;
    setOrientation(mOrientation);
    mState = State.READY;
    mGestureListener = new PanelOnGestureListener();
    mGestureDetector = new GestureDetector(mGestureListener);
    mGestureDetector.setIsLongpressEnabled(false);

    // i DON'T really know why i need this...
    setBaselineAligned(false);
  }
Beispiel #14
0
 @SuppressWarnings("deprecation")
 public Panel(Context context, AttributeSet attrs) {
   super(context, attrs);
   TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel);
   mDuration =
       a.getInteger(R.styleable.Panel_animationDuration, 750); // duration defaults to 750 ms
   mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM); // position defaults to BOTTOM
   mLinearFlying =
       a.getBoolean(R.styleable.Panel_linearFlying, false); // linearFlying defaults to false
   mOpenedHandle = a.getDrawable(R.styleable.Panel_openedHandle);
   mClosedHandle = a.getDrawable(R.styleable.Panel_closedHandle);
   a.recycle();
   mOrientation = (mPosition == TOP || mPosition == BOTTOM) ? VERTICAL : HORIZONTAL;
   setOrientation(mOrientation);
   mState = State.READY;
   mGestureListener = new PanelOnGestureListener();
   mGestureDetector = new GestureDetector(mGestureListener);
   mGestureDetector.setIsLongpressEnabled(false);
 }
Beispiel #15
0
  private void initLoopView(Context context) {
    this.context = context;
    handler = new MessageHandler(this);
    gestureDetector = new GestureDetector(context, new LoopViewGestureListener(this));
    gestureDetector.setIsLongpressEnabled(false);

    isLoop = true;
    textSize = 0;
    colorGray = 0xffafafaf;
    colorBlack = 0xff313131;
    colorLightGray = 0xffc5c5c5;

    totalScrollY = 0;
    initPosition = -1;

    initPaints();

    setTextSize(16F);
  }
Beispiel #16
0
 private void d() {
   if (arrayList == null) {
     return;
   }
   paintA = new Paint();
   paintA.setColor(colorGray);
   paintA.setAntiAlias(true);
   paintA.setTypeface(Typeface.MONOSPACE);
   paintA.setTextSize(textSize);
   paintB = new Paint();
   paintB.setColor(colorBlack);
   paintB.setAntiAlias(true);
   paintB.setTextScaleX(1.05F);
   paintB.setTypeface(Typeface.MONOSPACE);
   paintB.setTextSize(textSize);
   paintC = new Paint();
   paintC.setColor(colorGrayLight);
   paintC.setAntiAlias(true);
   paintC.setTypeface(Typeface.MONOSPACE);
   paintC.setTextSize(textSize);
   if (android.os.Build.VERSION.SDK_INT >= 11) {
     setLayerType(1, null);
   }
   gestureDetector = new GestureDetector(context, simpleOnGestureListener);
   gestureDetector.setIsLongpressEnabled(false);
   e();
   t = (int) ((float) h * l * (float) (r - 1));
   s = (int) ((double) (t * 2) / Math.PI);
   u = (int) ((double) t / Math.PI);
   v = g + textSize;
   n = (int) (((float) s - l * (float) h) / 2.0F);
   o = (int) (((float) s + l * (float) h) / 2.0F);
   if (positon == -1) {
     if (isLoop) {
       positon = (arrayList.size() + 1) / 2;
     } else {
       positon = 0;
     }
   }
   p = positon;
 }
Beispiel #17
0
  public AnSwitch(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
    tintColor = typedValue.data;
    tempTintColor = tintColor;

    float density = getResources().getDisplayMetrics().density;
    outerStrokeWidth = (int) (density * 1.5f);
    shadowSpace = (int) (density * 5);

    knobBound = new RectF();
    innerContentBound = new RectF();

    tempForRoundRect = new RectF();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    if (Build.VERSION.SDK_INT >= 11) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    innerContentAnimator =
        ObjectAnimator.ofFloat(AnSwitch.this, innerContentProperty, innerContentRate, 1.0F);
    innerContentAnimator.setDuration(commonDuration);
    innerContentAnimator.setInterpolator(new DecelerateInterpolator());

    knobExpandAnimator =
        ObjectAnimator.ofFloat(AnSwitch.this, knobExpandProperty, knobExpandRate, 1.0F);
    knobExpandAnimator.setDuration(commonDuration);
    knobExpandAnimator.setInterpolator(new DecelerateInterpolator());

    knobMoveAnimator = ObjectAnimator.ofFloat(AnSwitch.this, knobMoveProperty, knobMoveRate, 1.0F);
    knobMoveAnimator.setDuration(commonDuration);
    knobMoveAnimator.setInterpolator(new DecelerateInterpolator());
  }
Beispiel #18
0
  /**
   * Instantiates a new carousel view.
   *
   * @param context the context
   * @param attrs the attrs
   * @param defStyle the def style
   */
  public CarouselView(Context context, AttributeSet attrs, int defStyle) {

    super(context, attrs, defStyle);

    // It's needed to make items with greater value of
    // z coordinate to be behind items with lesser z-coordinate
    setChildrenDrawingOrderEnabled(true);

    // Making user gestures available
    mGestureDetector = new GestureDetector(this.getContext(), this);
    mGestureDetector.setIsLongpressEnabled(true);

    // It's needed to apply 3D transforms to items
    // before they are drawn
    setStaticTransformationsEnabled(true);

    // Retrieve settings
    mAnimationDuration = 400;
    mUseReflection = false;
    int selectedItem = 0;

    // next time we go through layout with this value
    setNextSelectedPositionInt(selectedItem);
  }
 @Override
 public void setIsLongpressEnabled(boolean enabled) {
   mDetector.setIsLongpressEnabled(enabled);
 }
 public ScrollKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
   super(context, attrs, defStyle);
   mGestureDetector = new GestureDetector(context, this);
   mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */);
   mScroller = new Scroller(context);
 }
  private void init() {
    // make this view focusable
    setFocusable(true);

    // init fields
    viewportTransformation = new Matrix();
    newViewportTransformation = new Matrix();
    inverseViewportTransformation = new Matrix();

    selectionOffset = new float[2];
    touchPoint = new float[2];

    buffer = ByteBuffer.allocate(1024);

    scalingInterpolator = new TimedInterpolator();
    scalingInterpolator.setDuration(800);
    translationXInterpolator = new TimedInterpolator();
    translationXInterpolator.setDuration(800);
    translationYInterpolator = new TimedInterpolator();
    translationYInterpolator.setDuration(800);
    rotationInterpolator = new TimedInterpolator();
    rotationInterpolator.setDuration(800);
    centerRotationInterpolator = new TimedInterpolator();
    centerRotationInterpolator.setDuration(800);

    currentOrientation = getContext().getResources().getConfiguration().orientation;
    setOrientationFlag(true);

    if (SourcesView.paint == null) {
      SourcesView.paint = new Paint();
      SourcesView.paint.setAntiAlias(false);
      SourcesView.paint.setStrokeWidth(0);
      SourcesView.paint.setTextAlign(Paint.Align.CENTER);
      SourcesView.paint.setTextSize(9.0f);
    }

    // set up orientation event listener
    orientationEventListener =
        new OrientationEventListener(getContext(), SensorManager.SENSOR_DELAY_NORMAL) {
          @Override
          public void onOrientationChanged(int orientation) {
            if ((orientation >= 80 && orientation <= 100)
                || (orientation >= 260 && orientation <= 280)) { // landscape
              setOrientation(Configuration.ORIENTATION_LANDSCAPE);
            } else if ((orientation >= 350 || orientation <= 10)
                || (orientation >= 170 && orientation <= 190)) { // portrait
              setOrientation(Configuration.ORIENTATION_PORTRAIT);
            }
          }
        };
    if (!GlobalData
        .orientationTrackingEnabled) // orientation tracking and screen rotation tracking don't go
      // together
      orientationEventListener.enable();

    // set up gesture detector
    gestureDetector = new GestureDetector(getContext(), this);
    gestureDetector.setIsLongpressEnabled(false);
    gestureDetector.setOnDoubleTapListener(this);

    // init viewport transformation matrix
    recalculateViewportTransformation();
  }
Beispiel #22
0
 private void init() {
   // GestureDetector
   mDetector = new GestureDetector(getContext(), mSimpleOnGestureListener);
   mDetector.setOnDoubleTapListener(null);
   mDetector.setIsLongpressEnabled(false);
 }
  /**
   * Creates a {@link GestureEventFilter}.
   *
   * @param useDefaultLongPress If true, use Android's long press behavior which does not send any
   *     more events after a long press. If false, use a custom implementation that will send events
   *     after a long press.
   */
  public GestureEventFilter(
      Context context,
      EventFilterHost host,
      GestureHandler handler,
      boolean autoOffset,
      boolean useDefaultLongPress) {
    super(host, autoOffset);
    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mLongPressTimeoutMs = ViewConfiguration.get(context).getLongPressTimeout();
    mUseDefaultLongPress = useDefaultLongPress;
    mHandler = handler;
    context.getResources();

    mDetector =
        new GestureDetector(
            context,
            new GestureDetector.SimpleOnGestureListener() {

              private float mOnScrollBeginX;
              private float mOnScrollBeginY;

              @Override
              public boolean onScroll(
                  MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                if (!mSeenFirstScrollEvent) {
                  // Remove the touch slop region from the first scroll event to avoid a
                  // jump.
                  mSeenFirstScrollEvent = true;
                  float distance = (float) Math.sqrt(distanceX * distanceX + distanceY * distanceY);
                  if (distance > 0.0f) {
                    float ratio = Math.max(0, distance - mScaledTouchSlop) / distance;
                    mOnScrollBeginX = e1.getX() + distanceX * (1.0f - ratio);
                    mOnScrollBeginY = e1.getY() + distanceY * (1.0f - ratio);
                    distanceX *= ratio;
                    distanceY *= ratio;
                  }
                }
                if (mHandler != null && mSingleInput) {
                  // distanceX/Y only represent the distance since the last event, not the total
                  // distance for the full scroll.  Calculate the total distance here.
                  float totalX = e2.getX() - mOnScrollBeginX;
                  float totalY = e2.getY() - mOnScrollBeginY;
                  mHandler.drag(
                      e2.getX() * mPxToDp,
                      e2.getY() * mPxToDp,
                      -distanceX * mPxToDp,
                      -distanceY * mPxToDp,
                      totalX * mPxToDp,
                      totalY * mPxToDp);
                }
                return true;
              }

              @Override
              public boolean onSingleTapUp(MotionEvent e) {
                /* Android's GestureDector calls listener.onSingleTapUp on MotionEvent.ACTION_UP
                 * during long press, so we need to explicitly not call handler.click if a
                 * long press has been detected.
                 */
                if (mHandler != null && mSingleInput && !mInLongPress) {
                  mHandler.click(e.getX() * mPxToDp, e.getY() * mPxToDp);
                }
                return true;
              }

              @Override
              public boolean onFling(
                  MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if (mHandler != null && mSingleInput) {
                  mHandler.fling(
                      e1.getX() * mPxToDp,
                      e1.getY() * mPxToDp,
                      velocityX * mPxToDp,
                      velocityY * mPxToDp);
                }
                return true;
              }

              @Override
              public boolean onDown(MotionEvent e) {
                mInLongPress = false;
                mSeenFirstScrollEvent = false;
                if (mHandler != null && mSingleInput) {
                  mHandler.onDown(e.getX() * mPxToDp, e.getY() * mPxToDp);
                }
                return true;
              }

              @Override
              public void onLongPress(MotionEvent e) {
                longPress(e);
              }
            });

    mDetector.setIsLongpressEnabled(mUseDefaultLongPress);
  }
Beispiel #24
0
  /**
   * Initialize the control. This code is in a separate method so that it can be called from both
   * constructors.
   */
  private void init() {
    // Force the background to software rendering because otherwise the Blur
    // filter won't work.
    setLayerToSW(this);

    // Set up the paint for the label text
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    if (mTextHeight == 0) {
      mTextHeight = mTextPaint.getTextSize();
    } else {
      mTextPaint.setTextSize(mTextHeight);
    }

    // Set up the paint for the pie slices
    mPiePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPiePaint.setStyle(Paint.Style.FILL);
    mPiePaint.setTextSize(mTextHeight);

    cSlicePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    cSlicePaint.setStyle(Paint.Style.FILL);

    // Set up the paint for the shadow
    mShadowPaint = new Paint(0);
    mShadowPaint.setColor(0xff101010);
    mShadowPaint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL));

    // Add a child view to draw the pie. Putting this in a child view
    // makes it possible to draw it on a separate hardware layer that rotates
    // independently
    mPieView = new PieView(getContext());
    addView(mPieView);
    mPieView.rotateTo(mPieRotation);

    // The pointer doesn't need hardware acceleration, but in order to show up
    // in front of the pie it also needs to be on a separate view.
    mPointerView = new PointerView(getContext());
    addView(mPointerView);

    // Set up an animator to animate the PieRotation property. This is used to
    // correct the pie's orientation after the user lets go of it.
    if (Build.VERSION.SDK_INT >= 11) {
      mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);

      // Add a listener to hook the onAnimationEnd event so that we can do
      // some cleanup when the pie stops moving.
      mAutoCenterAnimator.addListener(
          new Animator.AnimatorListener() {
            public void onAnimationStart(Animator animator) {}

            public void onAnimationEnd(Animator animator) {
              mPieView.decelerate();
            }

            public void onAnimationCancel(Animator animator) {}

            public void onAnimationRepeat(Animator animator) {}
          });
    }

    // Create a Scroller to handle the fling gesture.
    if (Build.VERSION.SDK_INT < 11) {
      mScroller = new Scroller(getContext());
    } else {
      mScroller = new Scroller(getContext(), null, true);
    }
    // The scroller doesn't have any built-in animation functions--it just supplies
    // values when we ask it to. So we have to have a way to call it every frame
    // until the fling ends. This code (ab)uses a ValueAnimator object to generate
    // a callback on every animation frame. We don't use the animated value at all.
    if (Build.VERSION.SDK_INT >= 11) {
      mScrollAnimator = ValueAnimator.ofFloat(0, 1);
      mScrollAnimator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
              tickScrollAnimation();
            }
          });
    }

    // Create a gesture detector to handle onTouch messages
    mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());

    // Turn off long press--this control doesn't use it, and if long press is enabled,
    // you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
    // as a long press, apparently)
    mDetector.setIsLongpressEnabled(false);
  }
  /**
   * Initializes class data
   *
   * @param context the context
   */
  private void initData(Context context) {
    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    scroller = new Scroller(context);
  }
  // public AccessibleFrameLayout(Context context, ServiceConnection demonstrationConnection) {
  public AccessibleFrameLayout(Context context, IBinder binder) {
    super(context);

    mHandler = new Handler();
    mInstrumentation = new Instrumentation();

    if (ENABLE_VIBRATE) {
      mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    } else {
      mVibrator = null;
    }

    mDetector = new GestureDetector(context, gestureListener);
    mDetector.setIsLongpressEnabled(false);

    mSelectedView = null;
    mSelectedRect = new Rect();

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeWidth(3);
    mPaint.setColor(0xFF8CD2FF);

    mSelectedView = null;
    mSpeechAvailable = false;

    mTTS = new TextToSpeech(context, ttsInit);

    updateExplorationEnabled();

    getViewTreeObserver().addOnGlobalFocusChangeListener(focusChangeListener);

    boolean compatibilityMode = true;

    /* XXX: removed so it works on android-8, which lacks PointerCoords
    try {
        Class.forName("android.view.MotionEvent.PointerCoords");
        compatibilityMode = false;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    */

    mCompatibilityMode = compatibilityMode;

    mDemonstration = new Demonstration();

    try {
      mExternalDir = context.getExternalFilesDir(null);
      Log.i(LOG_STRING, "External directory: " + mExternalDir);
    } catch (Exception e) {
      Log.e(LOG_STRING, "Error getting external dir: " + e.toString());
    }
    Log.i(LOG_STRING, "Assigning binder");
    if (binder == null) {
      Log.e(LOG_STRING, "Null binder in constructor");
    }
    mBinder = binder;

    // unserializeDemonstration();
    // unserializeMotionEvents();
    // setOnClickListener(mCorkyListener);
    // setOnTouchListener(mTouchListener);
    // clearSerialization();
  }
  private void setupClickHandlers() {
    GestureDetector gestureDetector =
        new GestureDetector(
            this.context,
            new SimpleOnGestureListener() {
              int deltaX;
              int deltaY;
              eTabSizeState tabSizeOnMouseDown;

              {
                this.deltaX = 0;
                this.deltaY = 0;
                this.tabSizeOnMouseDown = eTabSizeState.FullSize;
              }

              @Override
              public boolean onDown(MotionEvent motionEvent) {
                this.deltaX = 0;
                this.deltaY = 0;
                this.tabSizeOnMouseDown = SwipeTabViewController.this.tabSizeState;
                if (SwipeTabViewController.this.tabSizeState == eTabSizeState.Minimized
                    && SwipeTabViewController.this.getTabView() != null) {
                  SwipeTabViewController.this.getTabView().performHapticFeedback(3, 2);
                  Log.d(TAG, "You found the minimized tab.... vibrating!");
                }
                return true;
              }

              @Override
              public boolean onFling(
                  MotionEvent motionEvent, MotionEvent motionEvent2, float v, float v2) {
                if (SwipeTabViewController.this.relocationManager.isInProgress()) {
                  return false;
                }
                eTabSizeState lMinimizedState =
                    SwipeTabViewController.this.getTabGravity() == 5
                        ? v < 0.0f ? eTabSizeState.FullSize : eTabSizeState.Minimized
                        : v > 0.0f ? eTabSizeState.FullSize : eTabSizeState.Minimized;
                SwipeTabViewController.this.setTabSizeState(
                    lMinimizedState,
                    Boolean.valueOf(true),
                    new Runnable() {
                      @Override
                      public void run() {
                        if (SwipeTabViewController.this.getUnreadCount() == 0) {
                          SwipeTabViewController.this.swipeTabView.playRandomAnimationAfterDelay(0);
                        }
                      }
                    });
                return true;
              }

              @Override
              public void onLongPress(MotionEvent e) {}

              @Override
              public boolean onSingleTapConfirmed(MotionEvent e) {
                if (SwipeTabViewController.this.tabSizeState == eTabSizeState.Minimized) {
                  return false;
                }
                SwipeTabViewController.this.fireOnTap();
                return true;
              }

              @Override
              public boolean onScroll(
                  MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                this.deltaX =
                    (int)
                        (((SwipeTabViewController.this.getTabGravity() == 5
                                    ? DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
                                    : -1.0f)
                                * distanceX)
                            + (this.deltaX));
                this.deltaY = (int) ((this.deltaY) + distanceY);
                if ((this.deltaX) > DRAG_DISTANCE_OPEN
                    && SwipeTabViewController.this.tabSizeState == eTabSizeState.Minimized) {
                  SwipeTabViewController.this.setTabSizeState(
                      eTabSizeState.FullSize,
                      Boolean.valueOf(true),
                      new Runnable() {
                        @Override
                        public void run() {
                          if (SwipeTabViewController.this.getUnreadCount() == 0) {
                            SwipeTabViewController.this.swipeTabView.playRandomAnimationAfterDelay(
                                0);
                          }
                        }
                      });
                } else if ((this.deltaX) < (-DRAG_DISTANCE_OPEN)
                    && SwipeTabViewController.this.tabSizeState == eTabSizeState.FullSize) {
                  SwipeTabViewController.this.setTabSizeState(eTabSizeState.Minimized);
                } else if (((this.deltaX) > DRAG_DISTANCE_OPEN
                        || (Math.abs(this.deltaY)) > DRAG_DISTANCE_OPEN)
                    && SwipeTabViewController.this.tabSizeState == eTabSizeState.FullSize
                    && !SwipeTabViewController.this.tabSizeAnimating
                    && this.tabSizeOnMouseDown == eTabSizeState.FullSize
                    && !SwipeTabViewController.this.relocationManager.isInProgress()) {
                  SwipeTabViewController.this.relocationManager.startRelocation(
                      e2, SwipeTabViewController.this.unreadCount);
                  SwipeTabViewController.this.clearAutoHideTimer();
                }
                return true;
              }
            });
    OnTouchListener touchListener = new AnonymousClass_3(gestureDetector);
    gestureDetector.setIsLongpressEnabled(false);
    this.swipeTabTouchView.setOnTouchListener(touchListener);
    this.swipeTabMinimizedTouchView.setOnTouchListener(touchListener);
  }