List of usage examples for android.view View getParent
public final ViewParent getParent()
From source file:com.yanzhenjie.album.widget.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w w w. j a v a 2 s . 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); } // 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.simas.vc.editor.player.PlayerFragment.java
void toggleFullscreen() { // Disable touch listener (to prevent multiple toggles until done) getContainer().setOnTouchListener(null); final ViewGroup root = (ViewGroup) getActivity().findViewById(android.R.id.content); final View progressOverlay = (getActivity() instanceof MainActivity) ? ((MainActivity) getActivity()).getProgressOverlay() : null;// w ww . jav a2 s . c om if (progressOverlay != null) { progressOverlay.setVisibility(View.VISIBLE); ViewGroup progressParent = (ViewGroup) progressOverlay.getParent(); if (progressParent != null) { progressParent.removeView(progressOverlay); } } // Toggle state mFullscreen = !isFullscreen(); if (isFullscreen()) { // Add preview to the root view if (progressOverlay != null) { root.addView(progressOverlay); } // All APIs can go fullscreen getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Low profile is only for APIs 14+ if (Build.VERSION.SDK_INT >= 14) { // Enable the low profile mode getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); } } else { // Add preview to the default parent if (mDefaultContainerParent != null && progressOverlay != null) { mDefaultContainerParent.addView(progressOverlay); } // All APIs can go fullscreen getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Low profile is only for APIs 14+ if (Build.VERSION.SDK_INT >= 14) { // Remove low profile getActivity().getWindow().getDecorView().setSystemUiVisibility(ViewGroup.SYSTEM_UI_FLAG_VISIBLE); } } final Runnable changeContainerParent = new Runnable() { @Override public void run() { // Hide surface view while doing all the work, this is to make sure it's not being re-drawn mSurfaceView.setVisibility(View.GONE); // Controls should be hidden while working final boolean controlsWereShown = getControls().isShown(); getControls().hide(); // Video should be paused while working boolean playing = false; if (getPlayer().getState() == Player.State.STARTED) { // Pause if started playing = true; getPlayer().pause(); } final boolean wasPlaying = playing; // Expand or collapse the PlayerView if (isFullscreen()) { // Save current params mDefaultContainerParams = new ViewGroup.LayoutParams(getContainer().getLayoutParams()); // Remove from current parent mDefaultContainerParent = (ViewGroup) getContainer().getParent(); mDefaultContainerParent.removeView(getContainer()); // Set new params ViewGroup.LayoutParams params = getContainer().getLayoutParams(); params.width = LinearLayout.LayoutParams.MATCH_PARENT; params.height = LinearLayout.LayoutParams.MATCH_PARENT; // Re-measure the SurfaceView invalidateSurface(); // Add to the root view before the progressOverlay (if it's added) int progressIndex = root.indexOfChild(progressOverlay); root.addView(getContainer(), progressIndex); getContainer().requestFocus(); } else { if (mDefaultContainerParams != null && mDefaultContainerParent != null) { // Remove from current parent ((ViewGroup) getContainer().getParent()).removeView(getContainer()); // Restore params getContainer().setLayoutParams(mDefaultContainerParams); // Re-measure the SurfaceView invalidateSurface(); // Add as the first child to the default parent mDefaultContainerParent.addView(getContainer(), 0); } } getContainer().post(new Runnable() { @Override public void run() { mSurfaceView.setVisibility(View.VISIBLE); // Check if fragment and player data sources match if (getItem() != null && getItem().getFile().getPath().equals(getPlayer().getDataSource())) { switch (getPlayer().getState()) { case PAUSED: case PREPARED: case STARTED: if (wasPlaying) { getPlayer().start(); } else { updatePreview(); } break; } } else { setPreviewVisible(true); } if (controlsWereShown) { getControls().show(); } if (progressOverlay != null) { progressOverlay.setVisibility(View.INVISIBLE); } // Re-enable touch listener getContainer().post(new Runnable() { @Override public void run() { getContainer().setOnTouchListener(PlayerFragment.this); } }); } }); } }; if (getPlayer().getState() == Player.State.PREPARING) { getPlayer().addOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { changeContainerParent.run(); } }); } else { changeContainerParent.run(); } }
From source file:com.facebook.litho.ComponentHost.java
private void mountView(View view, int flags) { view.setDuplicateParentStateEnabled(MountItem.isDuplicateParentState(flags)); mIsChildDrawingOrderDirty = true;/*from w w w . ja v a 2 s .c o m*/ // A host has been recycled and is already attached. if (view instanceof ComponentHost && view.getParent() == this) { finishTemporaryDetach(view); view.setVisibility(VISIBLE); return; } LayoutParams lp = view.getLayoutParams(); if (lp == null) { lp = generateDefaultLayoutParams(); view.setLayoutParams(lp); } if (mInLayout) { addViewInLayout(view, -1, view.getLayoutParams(), true); } else { addView(view, -1, view.getLayoutParams()); } }
From source file:com.android.calculator2.EventListener.java
@Override public void onClick(View view) { View v;//from w ww . j a v a 2 s. 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.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.HEXADECIMAL); break; case R.id.bin: mHandler.setText(mHandler.mBaseModule.setMode(Mode.BINARY)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.BINARY); break; case R.id.dec: mHandler.setText(mHandler.mBaseModule.setMode(Mode.DECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.DECIMAL); break; case R.id.matrix: mHandler.insert(MatrixView.getPattern(mContext)); 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: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); 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; // +/-, changes the sign of the current number. Might be useful later // (but removed for now) // case R.id.sign: // if(mHandler.getText().equals(mErrorString)) mHandler.setText(""); // 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) { 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.linkbubble.ui.BubbleFlowView.java
public void add(View view, boolean insertNextToCenterItem) { //view.setBackgroundColor(mViews.size() % 2 == 0 ? 0xff660066 : 0xff666600); view.setOnClickListener(mViewOnClickListener); view.setOnTouchListener(mViewOnTouchListener); int centerIndex = getCenterIndex(); int insertAtIndex = insertNextToCenterItem ? centerIndex + 1 : mViews.size(); if (view.getParent() != null) { ((ViewGroup) view.getParent()).removeView(view); }/*from www . jav a 2 s . co m*/ FrameLayout.LayoutParams lp = new LayoutParams(mItemWidth, mItemHeight, Gravity.TOP | Gravity.LEFT); lp.leftMargin = mEdgeMargin + insertAtIndex * mItemWidth; mContent.addView(view, lp); mContent.invalidate(); if (insertNextToCenterItem) { mViews.add(centerIndex + 1, view); } else { mViews.add(view); } updatePositions(); updateScales(getScrollX()); if (insertNextToCenterItem) { TranslateAnimation slideOnAnim = new TranslateAnimation(0, 0, -mItemHeight, 0); slideOnAnim.setDuration(Constant.BUBBLE_FLOW_ANIM_TIME); slideOnAnim.setFillAfter(true); view.startAnimation(slideOnAnim); for (int i = centerIndex + 2; i < mViews.size(); i++) { View viewToShift = mViews.get(i); TranslateAnimation slideRightAnim = new TranslateAnimation(-mItemWidth, 0, 0, 0); slideRightAnim.setDuration(Constant.BUBBLE_FLOW_ANIM_TIME); slideRightAnim.setFillAfter(true); viewToShift.startAnimation(slideRightAnim); } } ViewGroup.LayoutParams contentLP = mContent.getLayoutParams(); contentLP.width = (mViews.size() * mItemWidth) + mItemWidth + (2 * mEdgeMargin); mContent.setLayoutParams(contentLP); }
From source file:com.homechart.app.commont.imagedetail.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w .j av a2 s. 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 { } // 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.example.imagegallerydemo.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w. ja v a 2s .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 { Log.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.sflib.CustomView.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/* w ww . jav 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.info(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:android.support.design.widget.CollapsingToolbarLayout.java
/** * Returns the direct child of this layout, which itself is the ancestor of the * given view.//from w ww. j av a 2 s.com */ private View findDirectChild(final View descendant) { View directChild = descendant; for (ViewParent p = descendant.getParent(); p != this && p != null; p = p.getParent()) { if (p instanceof View) { directChild = (View) p; } } return directChild; }
From source file:com.kf5.sdk.system.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w w w. ja va 2 s . com*/ 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 { } // 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; }