Search in sources :

Example 26 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project Reader by TheKeeperOfPie.

the class ImageViewZoom method initialize.

private void initialize() {
    setClickable(true);
    scroller = new Scroller(getContext());
    scaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            // Log.d(TAG, "onScale() called with: " + "detector = [" + detector + "]");
            // 
            // Log.d(TAG, "onScale() called with: " + "focusX = [" + detector.getFocusX() + "], focusY = [" + detector.getFocusY() + "], width = [" + getWidth() + "], height = [" + getHeight() + "]");
            // float translationX = detector.getFocusX() * (translationMaxX - translationMinX) / getWidth() + translationMinX;
            // float translationY = detector.getFocusY() * (translationMaxY - translationMinY) / getHeight() + translationMinY;
            // setTranslation(translationX, translationY);
            applyScaleFactor(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
            return true;
        }
    });
    gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {

        private int pointerCount;

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            // Log.d(TAG, "onScroll() called with: " + "translationX = [" + translationX + "], translationMinX = [" + translationMinX + "], translationMaxX = [" + translationMaxX + "], scaleStart = [" + scaleStart + "], scaleCurrent = [" + scaleCurrent + "], contentWidth = [" + contentWidth + "]");
            // Log.d(TAG, "onScroll() called with relative: " + "x = [" + getRelativeX() + "], y = [" + getRelativeY() + "]");
            scroller.forceFinished(true);
            if (pointerCount == 1) {
                applyTranslation(-distanceX, -distanceY);
            }
            return super.onScroll(e1, e2, distanceX, distanceY);
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            scroller.forceFinished(true);
            if (pointerCount == 1) {
                Log.d(TAG, "onFling() called with: " + "e1 = [" + e1 + "], e2 = [" + e2 + "], velocityX = [" + velocityX + "], velocityY = [" + velocityY + "]");
                scroller.fling((int) translationX, (int) translationY, (int) velocityX, (int) velocityY, (int) translationMinX, (int) translationMaxX, (int) translationMinY, (int) translationMaxY);
                post(runnableScroll);
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onDown(MotionEvent e) {
            pointerCount = e.getPointerCount();
            return super.onDown(e);
        }
    });
}
Also used : Scroller(android.widget.Scroller) ScaleGestureDetector(android.view.ScaleGestureDetector) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent)

Example 27 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project baker-android by bakerframework.

the class MagazineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // We would like to keep the screen on while reading the magazine
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    // Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.html_pager);
    Intent intent = getIntent();
    try {
        STANDALONE_MODE = intent.getBooleanExtra(Configuration.MAGAZINE_STANDALONE, false);
        RETURN_TO_SHELF = intent.getBooleanExtra(Configuration.MAGAZINE_RETURN_TO_SHELF, true);
        ENABLE_DOUBLE_TAP = intent.getBooleanExtra(Configuration.MAGAZINE_ENABLE_DOUBLE_TAP, true);
        ENABLE_BACK_NEXT_BUTTONS = intent.getBooleanExtra(Configuration.MAGAZINE_ENABLE_BACK_NEXT_BUTTONS, false);
        ENABLE_TUTORIAL = intent.getBooleanExtra(Configuration.MAGAZINE_ENABLE_TUTORIAL, false);
        Log.d(this.getClass().getName(), "Will run in standalone mode: " + STANDALONE_MODE);
        if (!RETURN_TO_SHELF) {
            setResult(GindActivity.STANDALONE_MAGAZINE_ACTIVITY_FINISH);
        } else {
            setResult(0);
        }
        jsonBook = new BookJson();
        jsonBook.setMagazineName(intent.getStringExtra(Configuration.MAGAZINE_NAME));
        Log.d(this.getClass().toString(), "THE RAW BOOK.JSON IS: " + intent.getStringExtra(Configuration.BOOK_JSON_KEY));
        jsonBook.fromJson(intent.getStringExtra(Configuration.BOOK_JSON_KEY));
        this.setOrientation(jsonBook.getOrientation());
        this.setPagerView(jsonBook);
        this.setEnableDoubleTap(ENABLE_DOUBLE_TAP);
        this.setEnableBackNextButton(ENABLE_BACK_NEXT_BUTTONS);
        detectFirstOrLastPage();
        gestureDetector = new GestureDetectorCompat(this, new MyGestureListener());
    } catch (Exception ex) {
        ex.printStackTrace();
        Toast.makeText(this, "Not valid book.json found!", Toast.LENGTH_LONG).show();
    }
    resources = getResources();
}
Also used : BookJson(com.baker.abaker.model.BookJson) Intent(android.content.Intent) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 28 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project Android-Week-View by alamkanak.

the class WeekView method init.

private void init() {
    // Scrolling initialization.
    mGestureDetector = new GestureDetectorCompat(mContext, mGestureListener);
    mScroller = new OverScroller(mContext, new FastOutLinearInInterpolator());
    mMinimumFlingVelocity = ViewConfiguration.get(mContext).getScaledMinimumFlingVelocity();
    mScaledTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
    // Measure settings for time column.
    mTimeTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTimeTextPaint.setTextAlign(Paint.Align.RIGHT);
    mTimeTextPaint.setTextSize(mTextSize);
    mTimeTextPaint.setColor(mHeaderColumnTextColor);
    Rect rect = new Rect();
    mTimeTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mTimeTextHeight = rect.height();
    mHeaderMarginBottom = mTimeTextHeight / 2;
    initTextTimeWidth();
    // Measure settings for header row.
    mHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHeaderTextPaint.setColor(mHeaderColumnTextColor);
    mHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mHeaderTextPaint.setTextSize(mTextSize);
    mHeaderTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mHeaderTextHeight = rect.height();
    mHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    // Prepare header background paint.
    mHeaderBackgroundPaint = new Paint();
    mHeaderBackgroundPaint.setColor(mHeaderRowBackgroundColor);
    // Prepare day background color paint.
    mDayBackgroundPaint = new Paint();
    mDayBackgroundPaint.setColor(mDayBackgroundColor);
    mFutureBackgroundPaint = new Paint();
    mFutureBackgroundPaint.setColor(mFutureBackgroundColor);
    mPastBackgroundPaint = new Paint();
    mPastBackgroundPaint.setColor(mPastBackgroundColor);
    mFutureWeekendBackgroundPaint = new Paint();
    mFutureWeekendBackgroundPaint.setColor(mFutureWeekendBackgroundColor);
    mPastWeekendBackgroundPaint = new Paint();
    mPastWeekendBackgroundPaint.setColor(mPastWeekendBackgroundColor);
    // Prepare hour separator color paint.
    mHourSeparatorPaint = new Paint();
    mHourSeparatorPaint.setStyle(Paint.Style.STROKE);
    mHourSeparatorPaint.setStrokeWidth(mHourSeparatorHeight);
    mHourSeparatorPaint.setColor(mHourSeparatorColor);
    // Prepare the "now" line color paint
    mNowLinePaint = new Paint();
    mNowLinePaint.setStrokeWidth(mNowLineThickness);
    mNowLinePaint.setColor(mNowLineColor);
    // Prepare today background color paint.
    mTodayBackgroundPaint = new Paint();
    mTodayBackgroundPaint.setColor(mTodayBackgroundColor);
    // Prepare today header text color paint.
    mTodayHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTodayHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mTodayHeaderTextPaint.setTextSize(mTextSize);
    mTodayHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTodayHeaderTextPaint.setColor(mTodayHeaderTextColor);
    // Prepare event background color.
    mEventBackgroundPaint = new Paint();
    mEventBackgroundPaint.setColor(Color.rgb(174, 208, 238));
    // Prepare header column background color.
    mHeaderColumnBackgroundPaint = new Paint();
    mHeaderColumnBackgroundPaint.setColor(mHeaderColumnBackgroundColor);
    // Prepare event text size and color.
    mEventTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mEventTextPaint.setStyle(Paint.Style.FILL);
    mEventTextPaint.setColor(mEventTextColor);
    mEventTextPaint.setTextSize(mEventTextSize);
    // Set default event color.
    mDefaultEventColor = Color.parseColor("#9fc6e7");
    mScaleDetector = new ScaleGestureDetector(mContext, new ScaleGestureDetector.OnScaleGestureListener() {

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            mIsZooming = false;
        }

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            mIsZooming = true;
            goToNearestOrigin();
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mNewHourHeight = Math.round(mHourHeight * detector.getScaleFactor());
            invalidate();
            return true;
        }
    });
}
Also used : Rect(android.graphics.Rect) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ScaleGestureDetector(android.view.ScaleGestureDetector) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) OverScroller(android.widget.OverScroller) TextPaint(android.text.TextPaint)

Example 29 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project JJSwipeBack by android-cjj.

the class SwipeBackLayout method init.

/**
 * 初始化
 */
private void init() {
    // 创建ViewDragHelper的实例,第一个参数是ViewGroup,传自己,第二个灵敏度,一般正常是1.0,不正常你自己写,第三个是回调,看下面...
    mViewDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    // 手势操作,第二参数什么意思看下面
    mGestureDetectorCompat = new GestureDetectorCompat(getContext(), new XScrollDetector());
}
Also used : GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat)

Example 30 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project JZAndroidChart by donglua.

the class Chart method setupInteractions.

// -------- -------- --------
private void setupInteractions(Context context) {
    mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener);
    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
    mGestureDetector.setIsLongpressEnabled(false);
    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);
}
Also used : ScaleGestureDetector(android.view.ScaleGestureDetector) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) OverScroller(android.widget.OverScroller)

Aggregations

GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)33 MotionEvent (android.view.MotionEvent)12 ScaleGestureDetector (android.view.ScaleGestureDetector)8 Paint (android.graphics.Paint)6 Intent (android.content.Intent)5 View (android.view.View)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 GestureDetector (android.view.GestureDetector)4 LayoutInflater (android.view.LayoutInflater)4 OverScroller (android.widget.OverScroller)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3 TextPaint (android.text.TextPaint)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 Link (com.winsonchiu.reader.data.reddit.Link)3 Sort (com.winsonchiu.reader.data.reddit.Sort)3 AdapterLink (com.winsonchiu.reader.links.AdapterLink)3 Activity (android.app.Activity)2