List of usage examples for android.view View getParent
public final ViewParent getParent()
From source file:com.todoroo.astrid.activity.TaskEditFragment.java
public void scrollToView(View v) { View child = v; ScrollView scrollView = (ScrollView) getView().findViewById(R.id.edit_scroll); int top = v.getTop(); while (!child.equals(scrollView)) { top += child.getTop();/*www. j av a 2 s . com*/ ViewParent parentView = child.getParent(); if (parentView != null && View.class.isInstance(parentView)) { child = (View) parentView; } else { break; } } scrollView.smoothScrollTo(0, top); }
From source file:android.support.transition.TransitionPort.java
public TransitionValues getTransitionValues(View view, boolean start) { if (mParent != null) { return mParent.getTransitionValues(view, start); }/* ww w . j a v a 2s . co m*/ TransitionValuesMaps valuesMaps = start ? mStartValues : mEndValues; TransitionValues values = valuesMaps.viewValues.get(view); if (values == null) { int id = view.getId(); if (id >= 0) { values = valuesMaps.idValues.get(id); } if (values == null && view.getParent() instanceof ListView) { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); long itemId = listview.getItemIdAtPosition(position); values = valuesMaps.itemIdValues.get(itemId); } // TODO: Doesn't handle the case where a view was parented to a // ListView (with an itemId), but no longer is } return values; }
From source file:com.android.launcher3.Utilities.java
/** * Given a coordinate relative to the descendant, find the coordinate in a parent view's * coordinates./*from www. j a va 2 s .com*/ * * @param descendant The descendant to which the passed coordinate is relative. * @param ancestor The root view to make the coordinates relative to. * @param coord The coordinate that we want mapped. * @param includeRootScroll Whether or not to account for the scroll of the descendant: * sometimes this is relevant as in a child's coordinates within the descendant. * @return The factor by which this descendant is scaled relative to this DragLayer. Caution * this scale factor is assumed to be equal in X and Y, and so if at any point this * assumption fails, we will need to return a pair of scale factors. */ public static float getDescendantCoordRelativeToAncestor(View descendant, View ancestor, int[] coord, boolean includeRootScroll) { float[] pt = { coord[0], coord[1] }; float scale = 1.0f; View v = descendant; while (v != ancestor && v != null) { // For TextViews, scroll has a meaning which relates to the text position // which is very strange... ignore the scroll. if (v != descendant || includeRootScroll) { pt[0] -= v.getScrollX(); pt[1] -= v.getScrollY(); } v.getMatrix().mapPoints(pt); pt[0] += v.getLeft(); pt[1] += v.getTop(); scale *= v.getScaleX(); v = (View) v.getParent(); } coord[0] = Math.round(pt[0]); coord[1] = Math.round(pt[1]); return scale; }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
@Override public void focusableViewAvailable(View focused) { View current = getChildAt(mCurrentScreen); View v = focused; while (true) { if (v == current) { super.focusableViewAvailable(focused); return; }/*from www .j av a2 s.com*/ if (v == this) { return; } ViewParent parent = v.getParent(); if (parent instanceof View) { v = (View) v.getParent(); } else { return; } } }
From source file:cn.ieclipse.af.view.StaggeredGridView.java
/** * Should be called with mPopulating set to true * * @param fromPosition Position to start filling from * @param overhang the number of extra pixels to fill beyond the current top edge * @return the max overhang beyond the beginning of the view of any added items at the top *//* w w w . ja va 2 s . com*/ final int fillUp(int fromPosition, int overhang) { final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int itemMargin = mItemMargin; final int colWidth = (getWidth() - paddingLeft - paddingRight - itemMargin * (mColCount - 1)) / mColCount; final int gridTop = getPaddingTop(); final int fillTo = gridTop - overhang; int nextCol = getNextColumnUp(); int position = fromPosition; while (nextCol >= 0 && mItemTops[nextCol] > fillTo && position >= 0) { final View child = obtainView(position, null); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getParent() != this) { if (mInLayout) { addViewInLayout(child, 0, lp); } else { addView(child, 0); } } final int span = Math.min(mColCount, lp.span); final int widthSize = colWidth * span + itemMargin * (span - 1); final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); LayoutRecord rec; if (span > 1) { rec = getNextRecordUp(position, span); nextCol = rec.column; } else { rec = mLayoutRecords.get(position); } boolean invalidateBefore = false; if (rec == null) { rec = new LayoutRecord(); mLayoutRecords.put(position, rec); rec.column = nextCol; rec.span = span; } else if (span != rec.span) { rec.span = span; rec.column = nextCol; invalidateBefore = true; } else { nextCol = rec.column; } if (mHasStableIds) { final long id = mAdapter.getItemId(position); rec.id = id; lp.id = id; } lp.column = nextCol; final int heightSpec; if (lp.height == LayoutParams.WRAP_CONTENT) { heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } else { heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } child.measure(widthSpec, heightSpec); final int childHeight = child.getMeasuredHeight(); if (invalidateBefore || (childHeight != rec.height && rec.height > 0)) { invalidateLayoutRecordsBeforePosition(position); } rec.height = childHeight; final int startFrom; if (span > 1) { int highest = mItemTops[nextCol]; for (int i = nextCol + 1; i < nextCol + span; i++) { final int top = mItemTops[i]; if (top < highest) { highest = top; } } startFrom = highest; } else { startFrom = mItemTops[nextCol]; } final int childBottom = startFrom; final int childTop = childBottom - childHeight; final int childLeft = paddingLeft + nextCol * (colWidth + itemMargin); final int childRight = childLeft + child.getMeasuredWidth(); child.layout(childLeft, childTop, childRight, childBottom); for (int i = nextCol; i < nextCol + span; i++) { mItemTops[i] = childTop - rec.getMarginAbove(i - nextCol) - itemMargin; } nextCol = getNextColumnUp(); mFirstPosition = position--; } int highestView = getHeight(); for (int i = 0; i < mColCount; i++) { if (mItemTops[i] < highestView) { highestView = mItemTops[i]; } } return gridTop - highestView; }
From source file:cn.ieclipse.af.view.StaggeredGridView.java
/** * Should be called with mPopulating set to true * * @param fromPosition Position to start filling from * @param overhang the number of extra pixels to fill beyond the current bottom edge * @return the max overhang beyond the end of the view of any added items at the bottom *///from w w w. j av a 2 s . co m final int fillDown(int fromPosition, int overhang) { final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int itemMargin = mItemMargin; final int colWidth = (getWidth() - paddingLeft - paddingRight - itemMargin * (mColCount - 1)) / mColCount; final int gridBottom = getHeight() - getPaddingBottom(); final int fillTo = gridBottom + overhang; int nextCol = getNextColumnDown(); int position = fromPosition; while (nextCol >= 0 && mItemBottoms[nextCol] < fillTo && position < mItemCount) { final View child = obtainView(position, null); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getParent() != this) { if (mInLayout) { addViewInLayout(child, -1, lp); } else { addView(child); } } final int span = Math.min(mColCount, lp.span); final int widthSize = colWidth * span + itemMargin * (span - 1); final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); LayoutRecord rec; if (span > 1) { rec = getNextRecordDown(position, span); nextCol = rec.column; } else { rec = mLayoutRecords.get(position); } boolean invalidateAfter = false; if (rec == null) { rec = new LayoutRecord(); mLayoutRecords.put(position, rec); rec.column = nextCol; rec.span = span; } else if (span != rec.span) { rec.span = span; rec.column = nextCol; invalidateAfter = true; } else { nextCol = rec.column; } if (mHasStableIds) { final long id = mAdapter.getItemId(position); rec.id = id; lp.id = id; } lp.column = nextCol; final int heightSpec; if (lp.height == LayoutParams.WRAP_CONTENT) { heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } else { heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } child.measure(widthSpec, heightSpec); final int childHeight = child.getMeasuredHeight(); if (invalidateAfter || (childHeight != rec.height && rec.height > 0)) { invalidateLayoutRecordsAfterPosition(position); } rec.height = childHeight; final int startFrom; if (span > 1) { int lowest = mItemBottoms[nextCol]; for (int i = nextCol + 1; i < nextCol + span; i++) { final int bottom = mItemBottoms[i]; if (bottom > lowest) { lowest = bottom; } } startFrom = lowest; } else { startFrom = mItemBottoms[nextCol]; } final int childTop = startFrom + itemMargin; final int childBottom = childTop + childHeight; final int childLeft = paddingLeft + nextCol * (colWidth + itemMargin); final int childRight = childLeft + child.getMeasuredWidth(); child.layout(childLeft, childTop, childRight, childBottom); for (int i = nextCol; i < nextCol + span; i++) { mItemBottoms[i] = childBottom + rec.getMarginBelow(i - nextCol); } nextCol = getNextColumnDown(); position++; } int lowestView = 0; for (int i = 0; i < mColCount; i++) { if (mItemBottoms[i] > lowestView) { lowestView = mItemBottoms[i]; } } return lowestView - gridBottom; }
From source file:com.cairoconfessions.MainActivity.java
public void addItem(View view) { // Instantiate a new "row" view. final ViewGroup mFilter = (ViewGroup) findViewById(R.id.filter_cat); final ViewGroup mFilterLoc = (ViewGroup) findViewById(R.id.filter_loc); final ViewGroup mFilterMain = (ViewGroup) findViewById(R.id.filter_main); final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); final ViewGroup newViewLoc = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null);/*from w ww .ja va 2 s . c o m*/ final ViewGroup newViewMain = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); ArrayList<View> presentView = new ArrayList<View>(); mFilter.findViewsWithText(presentView, ((TextView) view).getText(), 1); if (presentView.size() == 0) { final String filterName = ((TextView) view).getText().toString(); switch (((LinearLayout) view.getParent()).getId()) { case R.id.cat_filter_list: Categories.add(filterName); break; case R.id.locations: Cities.add(filterName); break; } if (filterName.equals("Love")) { newView.getChildAt(0).setBackgroundResource(R.color.love); newViewLoc.getChildAt(0).setBackgroundResource(R.color.love); newViewMain.getChildAt(0).setBackgroundResource(R.color.love); } if (filterName.equals("Pain")) { newView.getChildAt(0).setBackgroundResource(R.color.pain); newViewLoc.getChildAt(0).setBackgroundResource(R.color.pain); newViewMain.getChildAt(0).setBackgroundResource(R.color.pain); } if (filterName.equals("Guilt")) { newView.getChildAt(0).setBackgroundResource(R.color.guilt); newViewLoc.getChildAt(0).setBackgroundResource(R.color.guilt); newViewMain.getChildAt(0).setBackgroundResource(R.color.guilt); } if (filterName.equals("Fantasy")) { newView.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewLoc.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewMain.getChildAt(0).setBackgroundResource(R.color.fantasy); } if (filterName.equals("Dream")) { newView.getChildAt(0).setBackgroundResource(R.color.dream); newViewLoc.getChildAt(0).setBackgroundResource(R.color.dream); newViewMain.getChildAt(0).setBackgroundResource(R.color.dream); } ((TextView) newView.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewLoc.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewMain.findViewById(android.R.id.text1)).setText(filterName); // Set a click listener for the "X" button in the row that will // remove the row. newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilter.removeView(newView); mFilterLoc.removeView(newViewLoc); mFilterMain.removeView(newViewMain); if (mFilter.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewLoc.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterLoc.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewMain.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterMain.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); // Because mFilter has android:animateLayoutChanges set to true, // adding this view is automatically animated. // mFilterCat.addView(newViewCat); mFilter.addView(newView, 0); mFilterLoc.addView(newViewLoc, 0); mFilterMain.addView(newViewMain, 0); findViewById(R.id.content_loc).setVisibility(View.VISIBLE); findViewById(R.id.content_cat).setVisibility(View.VISIBLE); findViewById(R.id.content_main).setVisibility(View.VISIBLE); updateFilters(); Toast.makeText(this, filterName + " filter added!", Toast.LENGTH_LONG).show(); } else Toast.makeText(this, "Already added!", Toast.LENGTH_LONG).show(); }
From source file:com.haibison.android.anhuu.BaseFileAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { Bag bag = (Bag) view.getTag();// w ww .j av a 2 s . c o m if (bag == null) { bag = new Bag(); bag.mImageIcon = (ImageView) view.findViewById(R.id.anhuu_f5be488d_imageview_icon); bag.mImageLockedSymbol = (ImageView) view.findViewById(R.id.anhuu_f5be488d_imageview_locked_symbol); bag.mTxtFileName = (TextView) view.findViewById(R.id.anhuu_f5be488d_textview_filename); bag.mTxtFileInfo = (TextView) view.findViewById(R.id.anhuu_f5be488d_textview_file_info); bag.mCheckboxSelection = (CheckBox) view.findViewById(R.id.anhuu_f5be488d_checkbox_selection); view.setTag(bag); } final int id = cursor.getInt(cursor.getColumnIndex(BaseFile._ID)); final Uri uri = BaseFileProviderUtils.getUri(cursor); final BagInfo bagInfo; if (mSelectedChildrenMap.get(id) == null) { bagInfo = new BagInfo(); bagInfo.mUri = uri; mSelectedChildrenMap.put(id, bagInfo); } else bagInfo = mSelectedChildrenMap.get(id); /* * Update views. */ /* * Use single line for grid view, multiline for list view */ bag.mTxtFileName.setSingleLine(view.getParent() instanceof GridView); /* * File icon. */ bag.mImageLockedSymbol.setVisibility( cursor.getInt(cursor.getColumnIndex(BaseFile.COLUMN_CAN_READ)) > 0 ? View.GONE : View.VISIBLE); bag.mImageIcon.setImageResource(cursor.getInt(cursor.getColumnIndex(BaseFile.COLUMN_ICON_ID))); bag.mImageIcon.setOnTouchListener(mImageIconOnTouchListener); bag.mImageIcon.setOnClickListener( BaseFileProviderUtils.isDirectory(cursor) ? newImageIconOnClickListener(cursor.getPosition()) : null); /* * Filename. */ bag.mTxtFileName.setText(BaseFileProviderUtils.getFileName(cursor)); UI.strikeOutText(bag.mTxtFileName, bagInfo.mMarkedAsDeleted); /* * File info. */ String time = DateUtils.formatDate(context, cursor.getLong(cursor.getColumnIndex(BaseFile.COLUMN_MODIFICATION_TIME))); if (BaseFileProviderUtils.isFile(cursor)) bag.mTxtFileInfo.setText(String.format("%s, %s", Converter.bytesToStr(cursor.getLong(cursor.getColumnIndex(BaseFile.COLUMN_SIZE))), time)); else bag.mTxtFileInfo.setText(time); /* * Check box. */ if (mMultiSelection) { if (mFilterMode == BaseFile.FILTER_FILES_ONLY && BaseFileProviderUtils.isDirectory(cursor)) { bag.mCheckboxSelection.setVisibility(View.GONE); } else { bag.mCheckboxSelection.setVisibility(View.VISIBLE); bag.mCheckboxSelection.setOnCheckedChangeListener(null); bag.mCheckboxSelection.setChecked(bagInfo.mChecked); bag.mCheckboxSelection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { bagInfo.mChecked = isChecked; }// onCheckedChanged() }); bag.mCheckboxSelection.setOnLongClickListener(mCheckboxSelectionOnLongClickListener); } } else bag.mCheckboxSelection.setVisibility(View.GONE); }
From source file:android.support.transition.Transition.java
/** * Recursive method which captures values for an entire view hierarchy, * starting at some root view. Transitions without targetIDs will use this * method to capture values for all possible views. * * @param view The view for which to capture values. Children of this View * will also be captured, recursively down to the leaf nodes. * @param start true if values are being captured in the start scene, false * otherwise./* ww w .j a va2 s. com*/ */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } boolean isListViewItem = false; if (view.getParent() instanceof ListView) { isListViewItem = true; } if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) { // ignore listview children unless we can track them with stable IDs return; } int id = View.NO_ID; long itemId = View.NO_ID; if (!isListViewItem) { id = view.getId(); } else { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); itemId = listview.getItemIdAtPosition(position); ViewCompat.setHasTransientState(view, true); } if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) { return; } if (mTargetExcludes != null && mTargetExcludes.contains(view)) { return; } if (mTargetTypeExcludes != null && view != null) { int numTypes = mTargetTypeExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeExcludes.get(i).isInstance(view)) { return; } } } TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } if (start) { if (!isListViewItem) { mStartValues.viewValues.put(view, values); if (id >= 0) { mStartValues.idValues.put((int) id, values); } } else { mStartValues.itemIdValues.put(itemId, values); } } else { if (!isListViewItem) { mEndValues.viewValues.put(view, values); if (id >= 0) { mEndValues.idValues.put((int) id, values); } } else { mEndValues.itemIdValues.put(itemId, values); } } if (view instanceof ViewGroup) { // Don't traverse child hierarchy if there are any child-excludes on this view if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) { return; } if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) { return; } if (mTargetTypeChildExcludes != null && view != null) { int numTypes = mTargetTypeChildExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeChildExcludes.get(i).isInstance(view)) { return; } } } ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); ++i) { captureHierarchy(parent.getChildAt(i), start); } } }
From source file:com.givewaygames.transition.Transition.java
/** * Recursive method which captures values for an entire view hierarchy, * starting at some root view. Transitions without targetIDs will use this * method to capture values for all possible views. * * @param view The view for which to capture values. Children of this View * will also be captured, recursively down to the leaf nodes. * @param start true if values are being captured in the start scene, false * otherwise.//from www .j a v a2 s . co m */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } boolean isListViewItem = false; if (view.getParent() instanceof ListView) { isListViewItem = true; } if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) { // ignore listview children unless we can track them with stable IDs return; } int id = View.NO_ID; long itemId = View.NO_ID; if (!isListViewItem) { id = view.getId(); } else { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); itemId = listview.getItemIdAtPosition(position); view.setHasTransientState(true); } if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) { return; } if (mTargetExcludes != null && mTargetExcludes.contains(view)) { return; } if (mTargetTypeExcludes != null && view != null) { int numTypes = mTargetTypeExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeExcludes.get(i).isInstance(view)) { return; } } } TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } if (start) { if (!isListViewItem) { mStartValues.viewValues.put(view, values); if (id >= 0) { mStartValues.idValues.put((int) id, values); } } else { mStartValues.itemIdValues.put(itemId, values); } } else { if (!isListViewItem) { mEndValues.viewValues.put(view, values); if (id >= 0) { mEndValues.idValues.put((int) id, values); } } else { mEndValues.itemIdValues.put(itemId, values); } } if (view instanceof ViewGroup) { // Don't traverse child hierarchy if there are any child-excludes on this view if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) { return; } if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) { return; } if (mTargetTypeChildExcludes != null && view != null) { int numTypes = mTargetTypeChildExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeChildExcludes.get(i).isInstance(view)) { return; } } } ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); ++i) { captureHierarchy(parent.getChildAt(i), start); } } }