@Test
  public void getOnDoubleTapListener_shouldReturnSetDoubleTapListener() throws Exception {
    GestureDetector subject = new GestureDetector(Robolectric.application, null);
    GestureDetector.OnDoubleTapListener onDoubleTapListener =
        new GestureDetector.OnDoubleTapListener() {
          @Override
          public boolean onSingleTapConfirmed(MotionEvent e) {
            return false;
          }

          @Override
          public boolean onDoubleTap(MotionEvent e) {
            return false;
          }

          @Override
          public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
          }
        };

    subject.setOnDoubleTapListener(onDoubleTapListener);
    assertEquals(shadowOf(subject).getOnDoubleTapListener(), onDoubleTapListener);

    subject.setOnDoubleTapListener(null);
    assertEquals(shadowOf(subject).getOnDoubleTapListener(), null);
  }
 public FilmStripGestureRecognizer(Context context, Listener listener) {
   mListener = listener;
   mGestureDetector =
       new GestureDetector(context, new MyGestureListener(), null, true /* ignoreMultitouch */);
   mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
   mScaleDetector = new ScaleGestureDetector(context, new MyScaleListener());
 }
Ejemplo n.º 3
0
  /**
   * Clean-up the resources attached to this object. This needs to be called when the ImageView is
   * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or from
   * {@link android.app.Activity#onDestroy()}. This is automatically called if you are using {@link
   * uk.co.senab.photoview.PhotoView}.
   */
  @SuppressWarnings("deprecation")
  public void cleanup() {
    if (null != mImageView) {
      // Remove this as a global layout listener
      ViewTreeObserver observer = mImageView.getViewTreeObserver();
      if (null != observer && observer.isAlive()) {
        observer.removeGlobalOnLayoutListener(this);
      }

      // Remove the ImageView's reference to this
      mImageView.setOnTouchListener(null);

      // make sure a pending fling runnable won't be run
      cancelFling();
    }

    if (null != mGestureDetector) {
      mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
  }
  private void initialize(Context context) {
    Context applicationContext = context.getApplicationContext();
    Injector injector = AirCastingApplication.class.cast(applicationContext).getInjector();
    injector.injectMembers(this);

    gestureDetector.setOnDoubleTapListener(this);
  }
Ejemplo n.º 5
0
  public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
      // Create Gesture Detectors...
      mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

      mGestureDetector =
          new GestureDetector(
              imageView.getContext(),
              new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                  if (null != mLongClickListener) {
                    mLongClickListener.onLongClick(mImageView.get());
                  }
                }
              });

      mGestureDetector.setOnDoubleTapListener(this);

      // Finally, update the UI so that we're zoomable
      setZoomable(true);
    }
  }
Ejemplo n.º 6
0
  @Override
  public void onDestroy() {
    inCallActivity = null;

    mCaptureView = null;
    if (mVideoView != null) {
      mVideoView.setOnTouchListener(null);
      mVideoView = null;
    }
    if (androidVideoWindowImpl != null) {
      // Prevent linphone from crashing if correspondent hang up while you are rotating
      androidVideoWindowImpl.release();
      androidVideoWindowImpl = null;
    }
    if (mGestureDetector != null) {
      mGestureDetector.setOnDoubleTapListener(null);
      mGestureDetector = null;
    }
    if (mScaleDetector != null) {
      mScaleDetector.destroy();
      mScaleDetector = null;
    }

    super.onDestroy();
  }
Ejemplo n.º 7
0
  // ///////////////////////////// INITIALIZING UI PART ///////////////////////////////////
  public void initView() {
    paintGrayFill = new Paint();
    paintGrayFill.setColor(Color.GRAY);
    paintGrayFill.setStyle(Style.FILL);
    // when map rotate
    paintGrayFill.setAntiAlias(true);

    paintBlackFill = new Paint();
    paintBlackFill.setColor(Color.BLACK);
    paintBlackFill.setStyle(Style.FILL);
    // when map rotate
    paintBlackFill.setAntiAlias(true);

    paintWhiteFill = new Paint();
    paintWhiteFill.setColor(Color.WHITE);
    paintWhiteFill.setStyle(Style.FILL);
    // when map rotate
    paintWhiteFill.setAntiAlias(true);

    paintCenter = new Paint();
    paintCenter.setStyle(Style.STROKE);
    paintCenter.setColor(Color.rgb(60, 60, 60));
    paintCenter.setStrokeWidth(2);
    paintCenter.setAntiAlias(true);

    paintImg = new Paint();
    //		paintImg.setFilterBitmap(true);
    //		paintImg.setDither(true);

    setClickable(true);
    setLongClickable(true);
    setFocusable(true);

    handler = new Handler();

    baseHandler =
        new Handler(application.getResourceManager().getRenderingBufferImageThread().getLooper());
    getHolder().addCallback(this);
    animatedDraggingThread = new AnimateDraggingMapThread(this);
    gestureDetector =
        new GestureDetector(
            getContext(), new MapExplorer(this, new MapTileViewOnGestureListener()));
    multiTouchSupport =
        new MultiTouchSupport(getContext(), new MapTileViewMultiTouchZoomListener());
    gestureDetector.setOnDoubleTapListener(new MapTileViewOnDoubleTapListener());

    WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    dm = new DisplayMetrics();
    mgr.getDefaultDisplay().getMetrics(dm);
    currentViewport =
        new RotatedTileBox.RotatedTileBoxBuilder()
            .setLocation(0, 0)
            .setZoomAndScale(3, 0)
            .setPixelDimensions(getWidth(), getHeight())
            .build();
    currentViewport.setDensity(dm.density);
  }
    public MultiGestureDetector(Context context) {
      scaleGestureDetector = new ScaleGestureDetector(context, this);

      gestureDetector = new GestureDetector(context, this);
      gestureDetector.setOnDoubleTapListener(this);

      final ViewConfiguration configuration = ViewConfiguration.get(context);
      scaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
      scaledTouchSlop = configuration.getScaledTouchSlop();
    }
 @Override
 public void setOnDoubleTapListener(OnDoubleTapListener listener) {
   mDetector.setOnDoubleTapListener(listener);
 }
  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();
  }
 public void setDoubleTapClickListener(OnDoubleTapListener listener) {
   gestureDetector.setOnDoubleTapListener(listener);
 }
Ejemplo n.º 12
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Logger.v("onCreateView");
    View view = inflater.inflate(R.layout.fragment_thread_detail, container, false);

    mDetailListView = (XListView) view.findViewById(R.id.lv_thread_details);
    mDetailListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mTipBar = (TextView) view.findViewById(R.id.thread_detail_tipbar);
    mTipBar.bringToFront();

    mFam = (FloatingActionMenu) view.findViewById(R.id.multiple_actions);
    mFam.setVisibility(View.INVISIBLE);

    FloatingActionButton fabRefresh =
        (FloatingActionButton) view.findViewById(R.id.action_fab_refresh);
    fabRefresh.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_refresh).color(Color.WHITE));
    fabRefresh.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(true);
            mFloorOfPage = LAST_FLOOR;
            refresh();
          }
        });

    FloatingActionButton fabQuickReply =
        (FloatingActionButton) view.findViewById(R.id.action_fab_quick_reply);
    fabQuickReply.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_reply).color(Color.WHITE));
    fabQuickReply.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(false);
            mFam.setVisibility(View.INVISIBLE);
            quickReply.setVisibility(View.VISIBLE);
            quickReply.bringToFront();
            (new Handler())
                .postDelayed(
                    new Runnable() {
                      public void run() {
                        mReplyTextTv.requestFocus();
                        mReplyTextTv.dispatchTouchEvent(
                            MotionEvent.obtain(
                                SystemClock.uptimeMillis(),
                                SystemClock.uptimeMillis(),
                                MotionEvent.ACTION_DOWN,
                                0,
                                0,
                                0));
                        mReplyTextTv.dispatchTouchEvent(
                            MotionEvent.obtain(
                                SystemClock.uptimeMillis(),
                                SystemClock.uptimeMillis(),
                                MotionEvent.ACTION_UP,
                                0,
                                0,
                                0));
                      }
                    },
                    200);
          }
        });

    FloatingActionButton fabGotoPage =
        (FloatingActionButton) view.findViewById(R.id.action_fab_goto_page);
    fabGotoPage.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_swap_horiz).color(Color.WHITE));
    fabGotoPage.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(true);
            showGotoPageDialog();
          }
        });

    if (!HiSettingsHelper.getInstance().getIsLandscape()) {
      mDetailListView.addHeaderView(inflater.inflate(R.layout.head_thread_detail, null));
      mTitleView = (TextView) view.findViewById(R.id.thread_detail_title);
      mTitleView.setTextSize(HiSettingsHelper.getTitleTextSize());
      mTitleView.setText(mTitle);
    }
    mDetailListView.setPullLoadEnable(false);
    mDetailListView.setPullRefreshEnable(false);
    mDetailListView.setXListViewListener(
        new XListView.IXListViewListener() {
          @Override
          public void onRefresh() {
            // Previous Page
            if (mCurrentPage > 1) {
              mCurrentPage--;
            }
            mDetailListView.stopRefresh();
            mFloorOfPage = LAST_FLOOR;
            showOrLoadPage();
            quickReply.setVisibility(View.INVISIBLE);
          }

          @Override
          public void onLoadMore() {
            // Next Page
            if (mCurrentPage < mMaxPage) {
              mCurrentPage++;
            }
            mDetailListView.stopLoadMore();
            showOrLoadPage();
          }
        });

    final GestureDetector.SimpleOnGestureListener listener =
        new GestureDetector.SimpleOnGestureListener() {
          @Override
          public boolean onDoubleTap(MotionEvent e) {
            if (mDetailListView.isFastScrollEnabled()) {
              mDetailListView.setFastScrollEnabled(false);
              mDetailListView.setFastScrollAlwaysVisible(false);
            } else {
              mDetailListView.setFastScrollEnabled(true);
              mDetailListView.setFastScrollAlwaysVisible(true);
            }
            return true;
          }
        };

    final GestureDetector detector = new GestureDetector(mCtx, listener);
    detector.setOnDoubleTapListener(listener);

    mDetailListView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent event) {
            if (mFam.isOpened()) {
              mFam.close(false);
            }
            return detector.onTouchEvent(event);
          }
        });

    quickReply = view.findViewById(R.id.quick_reply);
    mReplyTextTv = (TextView) quickReply.findViewById(R.id.tv_reply_text);
    mReplyTextTv.setTextSize(HiSettingsHelper.getPostTextSize());
    mPostReplyIb = (ImageButton) quickReply.findViewById(R.id.ib_reply_post);
    mPostReplyIb.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String replyText = mReplyTextTv.getText().toString();
            if (replyText.length() < 5) {
              Toast.makeText(getActivity(), "字数必须大于5", Toast.LENGTH_LONG).show();
            } else {
              mReplyTextTv.setText("");
              quickReply.setVisibility(View.INVISIBLE);
              PostBean postBean = new PostBean();
              postBean.setContent(replyText);
              postBean.setTid(mTid);
              new PostAsyncTask(
                      getActivity(),
                      PostAsyncTask.MODE_QUICK_REPLY,
                      null,
                      ThreadDetailFragment.this)
                  .execute(postBean);
              // Close SoftKeyboard
              InputMethodManager imm =
                  (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(mReplyTextTv.getWindowToken(), 0);
              mFam.setVisibility(View.VISIBLE);
            }
          }
        });

    return view;
  }
Ejemplo n.º 13
0
 private void init() {
   // GestureDetector
   mDetector = new GestureDetector(getContext(), mSimpleOnGestureListener);
   mDetector.setOnDoubleTapListener(null);
   mDetector.setIsLongpressEnabled(false);
 }