Example usage for android.view View getParent

List of usage examples for android.view View getParent

Introduction

In this page you can find the example usage for android.view View getParent.

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:com.android.inputmethod.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.// ww  w  .ja va  2  s .c  o  m
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        Log.e(TAG, "Attempted to speak when accessibility was disabled!");
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@SuppressLint("SetTextI18n")
public void update(Lyrics lyrics, View layout, boolean animation) {
    File musicFile = null;//from   w ww. j  av a 2 s. c  o  m
    Bitmap cover = null;
    if (PermissionsChecker.hasPermission(getActivity(), "android.permission.READ_EXTERNAL_STORAGE")) {
        musicFile = Id3Reader.getFile(getActivity(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack());
        cover = Id3Reader.getCover(getActivity(), lyrics.getArtist(), lyrics.getTitle());
    }
    setCoverArt(cover, null);
    boolean artCellDownload = Integer.valueOf(
            PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_artworks", "0")) == 0;
    if (cover == null)
        new CoverArtLoader().execute(lyrics, this.getActivity(),
                artCellDownload || OnlineAccessVerifier.isConnectedWifi(getActivity()));
    getActivity().findViewById(R.id.edit_tags_btn).setEnabled(true);
    getActivity().findViewById(R.id.edit_tags_btn)
            .setVisibility(musicFile == null || !musicFile.canWrite() || lyrics.isLRC()
                    || Id3Reader.getLyrics(getActivity(), lyrics.getArtist(), lyrics.getTitle()) == null
                            ? View.GONE
                            : View.VISIBLE);
    TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher));
    LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view);
    View v = getActivity().findViewById(R.id.tracks_msg);
    if (v != null)
        ((ViewGroup) v.getParent()).removeView(v);
    TextView artistTV = (TextView) getActivity().findViewById(R.id.artist);
    TextView songTV = (TextView) getActivity().findViewById(R.id.song);
    final TextView id3TV = (TextView) layout.findViewById(R.id.source_tv);
    TextView writerTV = (TextView) layout.findViewById(R.id.writer_tv);
    TextView copyrightTV = (TextView) layout.findViewById(R.id.copyright_tv);
    RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg);
    this.mLyrics = lyrics;
    if (SDK_INT >= ICE_CREAM_SANDWICH)
        beamLyrics(lyrics, this.getActivity());
    new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTitle(),
            lyrics.getOriginalArtist(), lyrics.getOriginalTrack() });

    if (lyrics.getArtist() != null)
        artistTV.setText(lyrics.getArtist());
    else
        artistTV.setText("");
    if (lyrics.getTitle() != null)
        songTV.setText(lyrics.getTitle());
    else
        songTV.setText("");
    if (lyrics.getCopyright() != null) {
        copyrightTV.setText("Copyright: " + lyrics.getCopyright());
        copyrightTV.setVisibility(View.VISIBLE);
    } else {
        copyrightTV.setText("");
        copyrightTV.setVisibility(View.GONE);
    }
    if (lyrics.getWriter() != null) {
        if (lyrics.getWriter().contains(","))
            writerTV.setText("Writers:\n" + lyrics.getWriter());
        else
            writerTV.setText("Writer:" + lyrics.getWriter());
        writerTV.setVisibility(View.VISIBLE);
    } else {
        writerTV.setText("");
        writerTV.setVisibility(View.GONE);
    }
    if (isActiveFragment)
        ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show();
    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    if (newLyrics != null)
        newLyrics.setText("");

    if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) {
        if (!lyrics.isLRC()) {
            textSwitcher.setVisibility(View.VISIBLE);
            lrcView.setVisibility(View.GONE);
            if (animation)
                textSwitcher.setText(Html.fromHtml(lyrics.getText()));
            else
                textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText()));
        } else {
            textSwitcher.setVisibility(View.GONE);
            lrcView.setVisibility(View.VISIBLE);
            lrcView.setOriginalLyrics(lyrics);
            lrcView.setSourceLrc(lyrics.getText());
            if (isActiveFragment)
                ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true);
            updateLRC();
        }

        bugLayout.setVisibility(View.INVISIBLE);
        id3TV.setMovementMethod(LinkMovementMethod.getInstance());
        if ("Storage".equals(lyrics.getSource())) {
            id3TV.setVisibility(View.VISIBLE);
            SpannableString text = new SpannableString(getString(R.string.from_id3));
            text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0);
            id3TV.setText(text);
            id3TV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((MainActivity) getActivity()).id3PopUp(id3TV);
                }
            });
        } else {
            id3TV.setOnClickListener(null);
            id3TV.setVisibility(View.GONE);
        }
        mScrollView.post(new Runnable() {
            @Override
            public void run() {
                mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment
                mScrollView.smoothScrollTo(0, 0);
            }
        });
    } else {
        textSwitcher.setText("");
        textSwitcher.setVisibility(View.INVISIBLE);
        lrcView.setVisibility(View.INVISIBLE);
        bugLayout.setVisibility(View.VISIBLE);
        int message;
        int whyVisibility;
        if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) {
            message = R.string.connection_error;
            whyVisibility = TextView.GONE;
        } else {
            message = R.string.no_results;
            whyVisibility = TextView.VISIBLE;
            updateSearchView(false, lyrics.getTitle(), false);
        }
        TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why));
        ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message);
        whyTextView.setVisibility(whyVisibility);
        whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
        id3TV.setVisibility(View.GONE);
    }
    stopRefreshAnimation();
    getActivity().getIntent().setAction("");
    getActivity().invalidateOptionsMenu();
}

From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java

@SuppressLint("ClickableViewAccessibility")
@Override// w w  w  .  j  a v a  2  s.  co m
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
        case ACTION_DOWN:
            // First, disable the Parent from intercepting the touch
            // event
            if (null != parent) {
                parent.requestDisallowInterceptTouchEvent(true);
            } else {
                //                        LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
            }

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case ACTION_CANCEL:
        case ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (null != rect) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:com.KittleApps.app.TransCalc.EventListener.java

@Override
public void onClick(View view) {
    View v;//from   ww  w  .  ja  va 2s  . com
    EditText active;
    int id = view.getId();
    switch (id) {
    case R.id.del:
        mHandler.onDelete();
        break;

    case R.id.clear:
        mHandler.onClear();
        break;

    case R.id.equal:
        if (mHandler.getText().contains(mX) || mHandler.getText().contains(mY)) {
            if (!mHandler.getText().contains("=")) {
                mHandler.insert("=");
                returnToBasic();
            }
            break;
        }
        mHandler.onEnter();
        break;

    case R.id.hex:
        mHandler.setText(mHandler.mBaseModule.setMode(Mode.HEXADECIMAL));
        view.setBackgroundResource(R.color.pressed_color);
        ((View) view.getParent()).findViewById(R.id.bin).setBackgroundResource(R.drawable.btn_function);
        ((View) view.getParent()).findViewById(R.id.dec).setBackgroundResource(R.drawable.btn_function);
        for (int i : mHandler.mBaseModule.bannedResourceInBinary) {
            if (mPager != null) {
                v = mPager.findViewById(i);
            } else {
                v = mSmallPager.findViewById(i);
                if (v == null)
                    v = mLargePager.findViewById(i);
            }
            v.setEnabled(true);
        }
        break;

    case R.id.bin:
        mHandler.setText(mHandler.mBaseModule.setMode(Mode.BINARY));
        view.setBackgroundResource(R.color.pressed_color);
        ((View) view.getParent()).findViewById(R.id.hex).setBackgroundResource(R.drawable.btn_function);
        ((View) view.getParent()).findViewById(R.id.dec).setBackgroundResource(R.drawable.btn_function);
        for (int i : mHandler.mBaseModule.bannedResourceInBinary) {
            if (mPager != null) {
                v = mPager.findViewById(i);
            } else {
                v = mSmallPager.findViewById(i);
                if (v == null)
                    v = mLargePager.findViewById(i);
            }
            v.setEnabled(false);
        }
        break;

    case R.id.dec:
        mHandler.setText(mHandler.mBaseModule.setMode(Mode.DECIMAL));
        view.setBackgroundResource(R.color.pressed_color);
        ((View) view.getParent()).findViewById(R.id.bin).setBackgroundResource(R.drawable.btn_function);
        ((View) view.getParent()).findViewById(R.id.hex).setBackgroundResource(R.drawable.btn_function);
        for (int i : mHandler.mBaseModule.bannedResourceInBinary) {
            if (mPager != null) {
                v = mPager.findViewById(i);
            } else {
                v = mSmallPager.findViewById(i);
                if (v == null)
                    v = mLargePager.findViewById(i);
            }
            v.setEnabled(true);
        }
        for (int i : mHandler.mBaseModule.bannedResourceInDecimal) {
            if (mPager != null) {
                v = mPager.findViewById(i);
            } else {
                v = mSmallPager.findViewById(i);
                if (v == null)
                    v = mLargePager.findViewById(i);
            }
            v.setEnabled(false);
        }
        break;

    case R.id.matrix:
        mHandler.insert(MatrixView.PATTERN);
        returnToBasic();
        break;

    case R.id.matrix_inverse:
        mHandler.insert(MatrixInverseView.PATTERN);
        returnToBasic();
        break;

    case R.id.matrix_transpose:
        mHandler.insert(MatrixTransposeView.PATTERN);
        returnToBasic();
        break;

    case R.id.plus_row:
        v = mHandler.mDisplay.getActiveEditText();
        if (v instanceof MatrixEditText)
            ((MatrixEditText) v).getMatrixView().addRow();
        break;

    case R.id.minus_row:
        v = mHandler.mDisplay.getActiveEditText();
        if (v instanceof MatrixEditText)
            ((MatrixEditText) v).getMatrixView().removeRow();
        break;

    case R.id.plus_col:
        v = mHandler.mDisplay.getActiveEditText();
        if (v instanceof MatrixEditText)
            ((MatrixEditText) v).getMatrixView().addColumn();
        break;

    case R.id.minus_col:
        v = mHandler.mDisplay.getActiveEditText();
        if (v instanceof MatrixEditText)
            ((MatrixEditText) v).getMatrixView().removeColumn();
        break;

    case R.id.next:
        active = mHandler.mDisplay.getActiveEditText();
        if (active.getSelectionStart() == active.getText().length()) {
            v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_FORWARD);
            if (v != null)
                v.requestFocus();
            active = mHandler.mDisplay.getActiveEditText();
            active.setSelection(0);
        } else {
            active.setSelection(active.getSelectionStart() + 1);
        }
        break;

    case R.id.sign:
        active = mHandler.mDisplay.getActiveEditText();
        int selection = active.getSelectionStart();
        if (active.getText().toString().matches(Logic.NUMBER)) {
            if (active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) {
                active.setText(active.getText().toString().substring(1));
                selection--;
            } else {
                active.setText(Logic.MINUS + active.getText().toString());
                selection++;
            }
            if (selection > active.length())
                selection--;
            if (selection < 0)
                selection = 0;
            active.setSelection(selection);
        }
        break;

    case R.id.parentheses:
        if (mHandler.getText().equals(mErrorString))
            mHandler.setText("");
        if (mHandler.getText().contains("=")) {
            String[] equation = mHandler.getText().split("=");
            if (equation.length > 1) {
                mHandler.setText(equation[0] + "=(" + equation[1] + ")");
            } else {
                mHandler.setText(equation[0] + "=()");
            }
        } else {
            mHandler.setText("(" + mHandler.getText() + ")");
        }
        returnToBasic();
        break;

    case R.id.mod:
        if (mHandler.getText().equals(mErrorString))
            mHandler.setText("");
        if (mHandler.getText().contains("=")) {
            String[] equation = mHandler.getText().split("=");
            if (equation.length > 1) {
                mHandler.setText(equation[0] + "=" + mModString + "(" + equation[1] + ",");
            } else {
                mHandler.insert(mModString + "(");
            }
        } else {
            if (mHandler.getText().length() > 0) {
                mHandler.setText(mModString + "(" + mHandler.getText() + ",");
            } else {
                mHandler.insert(mModString + "(");
            }
        }
        returnToBasic();
        break;

    case R.id.easter:
        Toast.makeText(mContext, R.string.easter_egg, Toast.LENGTH_SHORT).show();
        break;

    default:
        if (view instanceof Button) {
            if (mHandler.getText().equals(mErrorString))
                mHandler.setText("");
            String text = ((Button) view).getText().toString();
            if (text.equals(mDX) || text.equals(mDY)) {
                // Do nothing
            } else if (text.length() >= 2) {
                // Add paren after sin, cos, ln, etc. from buttons
                text += "(";
            }
            mHandler.insert(text);
            returnToBasic();
        }
    }
}

From source file:com.septrivium.augeo.ui.SipHome.java

private void applyTheme() {
    Theme t = Theme.getCurrentTheme(this);
    if (t != null) {
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            View vg = getWindow().getDecorView().findViewById(android.R.id.content);
            // Action bar container
            ViewGroup abc = (ViewGroup) ((ViewGroup) vg.getParent()).getChildAt(0);
            ////from   ww  w . java 2  s . c  o m
            ArrayList<View> leafs = getVisibleLeafs(abc);
            int i = 0;
            for (View leaf : leafs) {
                if (leaf instanceof ImageView) {
                    Integer id = mTabsAdapter.getIdForPosition(i);
                    if (id != null) {
                        int tabId = id;
                        Drawable customIcon = null;
                        switch (tabId) {
                        case TAB_ID_DIALER:
                            customIcon = t.getDrawableResource("ic_ab_dialer");
                            break;
                        case TAB_ID_CALL_LOG:
                            customIcon = t.getDrawableResource("ic_ab_history");
                            break;
                        case TAB_ID_MESSAGES:
                            customIcon = t.getDrawableResource("ic_ab_text");
                            break;
                        case TAB_ID_FAVORITES:
                            customIcon = t.getDrawableResource("ic_ab_favourites");
                            break;
                        default:
                            break;
                        }
                        if (customIcon != null) {
                            ((ImageView) leaf).setImageDrawable(customIcon);
                        }

                        t.applyBackgroundStateListSelectableDrawable((View) leaf.getParent(), "tab");
                        if (i == 0) {
                            //TODO: Check what this is used for?
                            //                                ViewParent tabLayout = leaf.getParent().getParent();
                            //                                if (tabLayout instanceof LinearLayout) {
                            //                                    Drawable d = t.getDrawableResource("tab_divider");
                            //                                    if (d != null) {
                            //                                        UtilityWrapper.getInstance()
                            //                                                .setLinearLayoutDividerDrawable(
                            //                                                        (LinearLayout) tabLayout, d);
                            //                                    }
                            //                                    Integer dim = t.getDimension("tab_divider_padding");
                            //                                    if (dim != null) {
                            //                                        UtilityWrapper.getInstance().setLinearLayoutDividerPadding(
                            //                                                (LinearLayout) tabLayout, dim);
                            //                                    }
                            //                                }
                        }
                        i++;
                    }
                }
            }
            if (i > 0) {
                t.applyBackgroundDrawable((View) leafs.get(0).getParent().getParent(), "abs_background");
            }

            Drawable d = t.getDrawableResource("split_background");
            if (d != null) {
                ab.setSplitBackgroundDrawable(d);
            }

            t.applyBackgroundDrawable(vg, "content_background");
        }
    }
}

From source file:com.simon.catkins.views.HorizontalListView.java

/**
 * When this HorizontalListView is embedded within a vertical scrolling view it is important to disable the parent view from interacting with
 * any touch events while the user is scrolling within this HorizontalListView. This will start at this view and go up the view tree looking
 * for a vertical scrolling view. If one is found it will enable or disable parent touch interception.
 *
 * @param disallowIntercept If true the parent will be prevented from intercepting child touch events
 *//*w  ww . j ava  2 s. c om*/
private void requestParentListViewToNotInterceptTouchEvents(Boolean disallowIntercept) {
    // Prevent calling this more than once needlessly
    if (mIsParentVerticallyScrollableViewDisallowingInterceptTouchEvent != disallowIntercept) {
        View view = this;

        while (view.getParent() instanceof View) {
            // If the parent is a ListView or ScrollView then disallow intercepting of touch events
            if (view.getParent() instanceof ListView || view.getParent() instanceof ScrollView) {
                view.getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
                mIsParentVerticallyScrollableViewDisallowingInterceptTouchEvent = disallowIntercept;
                return;
            }

            view = (View) view.getParent();
        }
    }
}

From source file:com.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java

@SuppressLint("ClickableViewAccessibility")
@Override/* w w  w.  j  a  v a 2 s .c  o m*/
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
        case ACTION_DOWN:
            // First, disable the Parent from intercepting the touch
            // event
            if (null != parent) {
                parent.requestDisallowInterceptTouchEvent(true);
            } else {
                L.w("onTouch getParent() returned null");
            }

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case ACTION_CANCEL:
        case ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (null != rect) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:aksha.upcomingdemo.HorizontalListView.java

/**
 * When this HorizontalListView is embedded within a vertical scrolling view it is important to disable the parent view from interacting with
 * any touch events while the user is scrolling within this HorizontalListView. This will start at this view and go up the view tree looking
 * for a vertical scrolling view. If one is found it will enable or disable parent touch interception.
 *
 * @param disallowIntercept If true the parent will be prevented from intercepting child touch events
 *//*w  w  w  .  j a  va 2s .c  o  m*/
private void requestParentListViewToNotInterceptTouchEvents(Boolean disallowIntercept) {
    // Prevent calling this more than once needlessly
    if (mIsParentVerticiallyScrollableViewDisallowingInterceptTouchEvent != disallowIntercept) {
        View view = this;

        while (view.getParent() instanceof View) {
            // If the parent is a ListView or ScrollView then disallow intercepting of touch events
            if (view.getParent() instanceof ListView || view.getParent() instanceof ScrollView) {
                view.getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
                mIsParentVerticiallyScrollableViewDisallowingInterceptTouchEvent = disallowIntercept;
                return;
            }

            view = (View) view.getParent();
        }
    }
}

From source file:com.org.lengend.photoview.library.PhotoViewAttacher.java

@SuppressLint("ClickableViewAccessibility")
@Override//from w  w w  . j  ava  2 s .  c  o  m
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
        case ACTION_DOWN:
            // First, disable the Parent from intercepting the touch
            // event
            if (null != parent) {
                parent.requestDisallowInterceptTouchEvent(true);
            } else {
                Logger.i(LOG_TAG, "onTouch getParent() returned null");
            }

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case ACTION_CANCEL:
        case ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (null != rect) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

@SuppressLint("ClickableViewAccessibility")
@Override//from ww w  .j av a2s. c om
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
        case ACTION_DOWN:
            // First, disable the Parent from intercepting the touch
            // event
            if (null != parent) {
                parent.requestDisallowInterceptTouchEvent(true);
            } else {
                LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
            }

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case ACTION_CANCEL:
        case ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (null != rect) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}