Android Open Source - GestureViews Gesture Text View






From Project

Back to project page GestureViews.

License

The source code is released under:

Apache License

If you think the Android project GestureViews 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.alexvasilkov.gestures.widgets;
/*from   w ww  . j  a v a2s .c o m*/
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.ViewParent;
import android.widget.TextView;
import com.alexvasilkov.gestures.GesturesController;
import com.alexvasilkov.gestures.R;
import com.alexvasilkov.gestures.State;

public class GestureTextView extends TextView implements GesturesController.OnStateChangedListener {

    private final GesturesController mController;

    private float mMinTextSize, mMaxTextSize;
    private float mSize;

    public GestureTextView(Context context) {
        this(context, null, 0);
    }

    public GestureTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GestureTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mController = new GesturesController(context, this);

        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GestureTextView);
            mMinTextSize = a.getDimension(R.styleable.GestureTextView_gvMinTextSize, 0f);
            mMaxTextSize = a.getDimension(R.styleable.GestureTextView_gvMaxTextSize, 0f);
            a.recycle();
        }

        if (mMinTextSize != 0f) {
            applySize(mMinTextSize);
            if (mMaxTextSize != 0f) mController.getSettings().setMaxZoom(mMaxTextSize / mMinTextSize);
        }

        mController.getSettings().setOverzoomFactor(1f).setPanEnabled(false);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
            ViewParent parent = getParent();
            if (parent != null) parent.requestDisallowInterceptTouchEvent(true);
        }

        return mController.onTouch(this, event);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mController.getSettings()
                .setViewport(w - getPaddingLeft() - getPaddingRight(), h - getPaddingTop() - getPaddingBottom())
                .setSize(w, h);
        mController.updateState();
    }

    @Override
    public void onStateChanged(State state) {
        if (mMinTextSize == 0f) return; // Nothing to do

        float size = mMinTextSize * state.getZoom();
        if (mMaxTextSize != 0f && size > mMaxTextSize) size = mMaxTextSize;
        applySize(Math.round(size));
    }

    private void applySize(float size) {
        if (mSize != size) {
            mSize = size;
            setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
        }
    }

}




Java Source Code List

com.alexvasilkov.gestures.GesturesAdapter.java
com.alexvasilkov.gestures.GesturesControllerPagerFix.java
com.alexvasilkov.gestures.GesturesController.java
com.alexvasilkov.gestures.Settings.java
com.alexvasilkov.gestures.StateController.java
com.alexvasilkov.gestures.State.java
com.alexvasilkov.gestures.detectors.RotationGestureDetector.java
com.alexvasilkov.gestures.detectors.ScaleGestureDetectorFixed.java
com.alexvasilkov.gestures.sample.activities.BaseActivity.java
com.alexvasilkov.gestures.sample.activities.ImageCroppingActivity.java
com.alexvasilkov.gestures.sample.activities.ImageSnapshotActivity.java
com.alexvasilkov.gestures.sample.activities.ImagesPagerActivity.java
com.alexvasilkov.gestures.sample.activities.LayoutPagerActivity.java
com.alexvasilkov.gestures.sample.activities.MainActivity.java
com.alexvasilkov.gestures.sample.activities.TextViewActivity.java
com.alexvasilkov.gestures.sample.items.Painting.java
com.alexvasilkov.gestures.sample.items.PaintingsImagesAdapter.java
com.alexvasilkov.gestures.sample.items.PaintingsLayoutsAdapter.java
com.alexvasilkov.gestures.sample.utils.PicassoHelper.java
com.alexvasilkov.gestures.utils.FloatScroller.java
com.alexvasilkov.gestures.utils.MovementBounds.java
com.alexvasilkov.gestures.utils.SmoothViewPagerScroller.java
com.alexvasilkov.gestures.utils.Snapshot.java
com.alexvasilkov.gestures.widgets.GestureImageView.java
com.alexvasilkov.gestures.widgets.GestureLayout.java
com.alexvasilkov.gestures.widgets.GestureTextView.java