List of usage examples for android.view View getParent
public final ViewParent getParent()
From source file:com.arta.lib.widget.crouton.Manager.java
/** * Removes the {@link Crouton}'s view after it's display * durationInMilliseconds.//from w ww .j av a 2 s .c o m * * @param crouton * The {@link Crouton} added to a {@link ViewGroup} and should be * removed. */ protected void removeCrouton(Crouton crouton) { View croutonView = crouton.getView(); ViewGroup croutonParentView = (ViewGroup) croutonView.getParent(); if (null != croutonParentView) { croutonView.startAnimation(crouton.getOutAnimation()); // Remove the Crouton from the queue. Crouton removed = croutonQueue.poll(); // Remove the crouton from the view's parent. croutonParentView.removeView(croutonView); if (null != removed) { removed.detachActivity(); removed.detachViewGroup(); if (null != removed.getLifecycleCallback()) { removed.getLifecycleCallback().onRemoved(); } removed.detachLifecycleCallback(); } // Send a message to display the next crouton but delay it by the out // animation duration to make sure it finishes sendMessageDelayed(crouton, Messages.DISPLAY_CROUTON, crouton.getOutAnimation().getDuration()); } }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
private void removeAllDebugInfoViews() { // The debug info views may be placed as children views of this {@link SuggestionStripView}. for (final View debugInfoView : mDebugInfoViews) { final ViewParent parent = debugInfoView.getParent(); if (parent instanceof ViewGroup) { ((ViewGroup) parent).removeView(debugInfoView); }//from w w w .j av a2 s .c o m } }
From source file:com.svpino.longhorn.activities.DashboardActivity.java
private void performSearch(String query) { this.stockListFragment.hideContextualActionBar(); Cursor cursor = DataProvider.search(getApplicationContext(), query); if (this.searchDialog == null || !this.searchDialog.isShowing()) { this.searchDialog = new Dialog(this); this.searchDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); this.searchDialog.setContentView(R.layout.dialog); TextView messageTextView = (TextView) this.searchDialog.findViewById(R.id.messageTextView); TextView titleTextView = (TextView) this.searchDialog.findViewById(R.id.titleTextView); ListView listView = (ListView) this.searchDialog.findViewById(R.id.listView); if (cursor != null && cursor.getCount() > 0) { titleTextView.setText(String.format(getString(R.string.dialog_search_title), query)); messageTextView.setVisibility(View.GONE); String[] from = new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, LonghornDatabase.KEY_EXCHANGE_SYMBOL }; int[] to = new int[] { R.id.nameTextView, R.id.descriptionTextView, R.id.additionalTextView }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.dialog_item, cursor, from, to, 0); adapter.setViewBinder(new ViewBinder() { @Override/*from ww w . ja v a2s .c o m*/ public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == 0) { ((View) view.getParent()).setTag(cursor.getString(columnIndex)); } return false; } }); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); addStockToWatchList(cursor.getString(0)); DashboardActivity.this.searchDialog.dismiss(); } }); } else { titleTextView.setText(getString(R.string.dialog_search_empty_title)); messageTextView.setText(String.format(getString(R.string.dialog_search_empty_message), query)); messageTextView.setVisibility(View.VISIBLE); listView.setVisibility(View.GONE); } this.searchDialog.show(); } }
From source file:com.arta.lib.widget.crouton.Manager.java
/** * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}. * * @param crouton//from w ww. j a v a 2s . co m * The {@link Crouton} that should be added. */ private void addCroutonToView(final Crouton crouton) { // don't add if it is already showing if (crouton.isShowing()) { return; } final View croutonView = crouton.getView(); if (null == croutonView.getParent()) { ViewGroup.LayoutParams params = croutonView.getLayoutParams(); if (null == params) { params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } // display Crouton in ViewGroup is it has been supplied if (null != crouton.getViewGroup()) { // TODO implement add to last position feature (need to align with how this will be requested for activity) if (crouton.getViewGroup() instanceof FrameLayout) { crouton.getViewGroup().addView(croutonView, params); } else { crouton.getViewGroup().addView(croutonView, 0, params); } } else { Activity activity = crouton.getActivity(); if (null == activity || activity.isFinishing()) { return; } handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity); activity.addContentView(croutonView, params); } } croutonView.requestLayout(); // This is needed so the animation can use the measured with/height ViewTreeObserver observer = croutonView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @TargetApi(16) public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } croutonView.startAnimation(crouton.getInAnimation()); announceForAccessibilityCompat(crouton.getActivity(), crouton.getText()); if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) { sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration()); } } }); } }
From source file:com.grarak.kerneladiutor.views.recyclerview.CardView.java
private void setupLayout() { if (mLayout != null) { mLayout.removeAllViews();// w w w. j a va 2s . c o m for (final RecyclerViewItem item : mItems) { View view; if (mViews.containsKey(item)) { view = mViews.get(item); } else { mViews.put(item, view = LayoutInflater.from(mActivity).inflate(item.getLayoutRes(), null, false)); } ViewGroup viewGroup = (ViewGroup) view.getParent(); if (viewGroup != null) { viewGroup.removeView(view); } item.setOnViewChangeListener(getOnViewChangedListener()); item.onCreateView(view); mLayout.addView(view); } } }
From source file:com.example.androidannotationtesttwo.widget.crouton.Manager.java
/** * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity} * .//from w w w .j av a2 s .co m * * @param crouton The {@link Crouton} that should be added. */ private void addCroutonToView(final Crouton crouton) { // don't add if it is already showing if (crouton.isShowing()) { return; } final View croutonView = crouton.getView(); if (null == croutonView.getParent()) { ViewGroup.LayoutParams params = croutonView.getLayoutParams(); if (null == params) { params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } // display Crouton in ViewGroup is it has been supplied if (null != crouton.getViewGroup()) { // TODO implement add to last position feature (need to align // with how this will be requested for activity) if (crouton.getViewGroup() instanceof FrameLayout) { crouton.getViewGroup().addView(croutonView, params); } else { crouton.getViewGroup().addView(croutonView, 0, params); } } else { Activity activity = crouton.getActivity(); if (null == activity || activity.isFinishing()) { return; } handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity); activity.addContentView(croutonView, params); } } croutonView.requestLayout(); // This is needed so the animation can use // the measured with/height ViewTreeObserver observer = croutonView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @TargetApi(16) public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } croutonView.startAnimation(crouton.getInAnimation()); announceForAccessibilityCompat(crouton.getActivity(), crouton.getText()); if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) { sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration()); } } }); } }
From source file:com.conduit.plastic.widget.NestedWebView.java
private void getEmbeddedParent(View paramView) { ViewParent localViewParent = paramView.getParent(); if (localViewParent != null) { if ((localViewParent instanceof ScrollStateChangedListener)) { this.parentView = ((ViewGroup) localViewParent); setScrollStateChangedListener((ScrollStateChangedListener) localViewParent); } else {/*from w w w . j a v a 2 s . c o m*/ if ((localViewParent instanceof ViewGroup)) { getEmbeddedParent((ViewGroup) localViewParent); } } } }
From source file:com.android.calendar.selectcalendars.SelectCalendarsSimpleAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (position >= mRowCount) { return null; }//from w w w . j av a 2 s. c o m String name = mData[position].displayName; boolean selected = mData[position].selected; int color = Utils.getDisplayColorFromColor(mData[position].color); View view; if (convertView == null) { view = mInflater.inflate(mLayout, parent, false); final View delegate = view.findViewById(R.id.color); final View delegateParent = (View) delegate.getParent(); delegateParent.post(new Runnable() { @Override public void run() { final Rect r = new Rect(); delegate.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } else { view = convertView; } TextView calendarName = (TextView) view.findViewById(R.id.calendar); calendarName.setText(name); View colorView = view.findViewById(R.id.color); colorView.setBackgroundColor(color); colorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Purely for sanity check--view should be disabled if account has no more colors if (!hasMoreColors(position)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(mData[position].id, mIsTablet); } else { mColorPickerDialog.setCalendarId(mData[position].id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); int textColor; if (selected) { textColor = mColorCalendarVisible; } else { textColor = mColorCalendarHidden; } calendarName.setTextColor(textColor); CheckBox syncCheckBox = (CheckBox) view.findViewById(R.id.sync); if (syncCheckBox != null) { // Full screen layout syncCheckBox.setChecked(selected); colorView.setEnabled(hasMoreColors(position)); LayoutParams layoutParam = calendarName.getLayoutParams(); TextView secondaryText = (TextView) view.findViewById(R.id.status); if (!TextUtils.isEmpty(mData[position].ownerAccount) && !mData[position].ownerAccount.equals(name) && !mData[position].ownerAccount.endsWith("calendar.google.com")) { int secondaryColor; if (selected) { secondaryColor = mColorCalendarSecondaryVisible; } else { secondaryColor = mColorCalendarSecondaryHidden; } secondaryText.setText(mData[position].ownerAccount); secondaryText.setTextColor(secondaryColor); secondaryText.setVisibility(View.VISIBLE); layoutParam.height = LayoutParams.WRAP_CONTENT; } else { secondaryText.setVisibility(View.GONE); layoutParam.height = LayoutParams.MATCH_PARENT; } calendarName.setLayoutParams(layoutParam); } else { // Tablet layout view.findViewById(R.id.color).setEnabled(selected && hasMoreColors(position)); view.setBackgroundDrawable(getBackground(position, selected)); ViewGroup.LayoutParams newParams = view.getLayoutParams(); if (position == mData.length - 1) { newParams.height = BOTTOM_ITEM_HEIGHT; } else { newParams.height = NORMAL_ITEM_HEIGHT; } view.setLayoutParams(newParams); CheckBox visibleCheckBox = (CheckBox) view.findViewById(R.id.visible_check_box); if (visibleCheckBox != null) { visibleCheckBox.setChecked(selected); } } view.invalidate(); return view; }
From source file:com.narkii.security.info.BaseDataFragment.java
/** * /*from ww w . jav a2 s . c o m*/ * @param view view */ private void clearPersonInfoView(View view) { final LinearLayout parent = (LinearLayout) view.getParent().getParent(); Log.d(TAG, "remove person view: " + parent.getChildCount()); if (parent.getChildCount() > 1) { parent.removeViews(1, parent.getChildCount() - 1); } }
From source file:com.mishiranu.dashchan.util.DrawerToggle.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void setActionBarUpIndicatorObsolete(Drawable upDrawable) { if (C.API_JELLY_BEAN_MR2) { activity.getActionBar().setHomeAsUpIndicator(upDrawable); } else {/*from w ww . java 2 s . c om*/ if (upIndicatorView == null) { View home = activity.findViewById(android.R.id.home); if (home == null) { return; } ViewGroup parent = (ViewGroup) home.getParent(); int childCount = parent.getChildCount(); if (childCount != 2) { return; } View first = parent.getChildAt(0); View second = parent.getChildAt(1); View up = first.getId() == android.R.id.home ? second : first; if (up instanceof ImageView) { upIndicatorView = (ImageView) up; } } if (upIndicatorView != null) { upIndicatorView.setImageDrawable(upDrawable); } } }