List of usage examples for android.view ViewGroup removeView
@Override public void removeView(View view)
Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.
From source file:org.zywx.wbpalmstar.engine.EBrowserView.java
@Override public void destroy() { if (mDestroyed) { return;//from w ww. ja v a 2 s . com } mDestroyed = true; mBroWind = null; mContext = null; clearView(); clearHistory(); ViewGroup parent = (ViewGroup) getParent(); if (null != parent) { parent.removeView(this); } mUExMgr.notifyDestroy(this); mUExMgr = null; super.destroy(); }
From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java
private void updateHeaderAmPm() { if (mIs24HourView) { mAmPmLayout.setVisibility(View.GONE); } else {//from ww w .jav a 2 s .co m // Ensure that AM/PM layout is in the correct position. final String dateTimePattern = getBestTimePattern(mCurrentLocale, false); final boolean amPmAtStart = dateTimePattern.startsWith("a"); final ViewGroup parent = (ViewGroup) mAmPmLayout.getParent(); final int targetIndex = amPmAtStart ? 0 : parent.getChildCount() - 1; final int currentIndex = parent.indexOfChild(mAmPmLayout); if (targetIndex != currentIndex) { parent.removeView(mAmPmLayout); parent.addView(mAmPmLayout, targetIndex); } updateAmPmLabelStates(mInitialHourOfDay < 12 ? AM : PM); } }
From source file:onion.chat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db = Database.getInstance(this); tor = Tor.getInstance(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w ww. j av a 2 s . c o m t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status != TextToSpeech.ERROR) { t1.setLanguage(Locale.US); } } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final Dialog[] d = new Dialog[1]; View v = getLayoutInflater().inflate(R.layout.dialog_connect, null); ((TextView) v.findViewById(R.id.id)).setText(Tor.getInstance(MainActivity.this).getID()); v.findViewById(R.id.qr_show).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); showQR(); } }); v.findViewById(R.id.qr_scan).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); scanQR(); } }); v.findViewById(R.id.enter_id).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); addContact(); } }); v.findViewById(R.id.share_id).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); inviteFriend(); } }); d[0] = new AlertDialog.Builder(MainActivity.this) //.setTitle(R.string.add_contact) .setView(v).show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); startService(new Intent(this, HostService.class)); findViewById(R.id.myname).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { changeName(); } }); findViewById(R.id.myaddress).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showQR(); } }); contactPage = getLayoutInflater().inflate(R.layout.page_contacts, null); requestPage = getLayoutInflater().inflate(R.layout.page_requests, null); contactRecycler = (RecyclerView) contactPage.findViewById(R.id.contactRecycler); requestRecycler = (RecyclerView) requestPage.findViewById(R.id.requestRecycler); contactEmpty = contactPage.findViewById(R.id.contactEmpty); requestEmpty = requestPage.findViewById(R.id.requestEmpty); contactRecycler.setLayoutManager(new LinearLayoutManager(this)); contactRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() { @Override public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final ContactViewHolder viewHolder = new ContactViewHolder( getLayoutInflater().inflate(R.layout.item_contact, parent, false)); viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String toSpeak = viewHolder.name.getText().toString(); Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show(); t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + viewHolder.address.getText()), getApplicationContext(), ChatActivity.class)); } }); viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { contactLongPress(viewHolder.address.getText().toString(), viewHolder.name.getText().toString()); return true; } }); return viewHolder; } @Override public void onBindViewHolder(ContactViewHolder holder, int position) { contactCursor.moveToPosition(position); holder.address.setText(contactCursor.getString(0)); String name = contactCursor.getString(1); if (name == null || name.equals("")) name = "Anonymous"; holder.name.setText(name); long n = contactCursor.getLong(2); if (n > 0) { holder.badge.setVisibility(View.VISIBLE); holder.count.setText("" + n); } else { holder.badge.setVisibility(View.GONE); } } @Override public int getItemCount() { return contactCursor != null ? contactCursor.getCount() : 0; } }); requestRecycler.setLayoutManager(new LinearLayoutManager(this)); requestRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() { @Override public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final ContactViewHolder viewHolder = new ContactViewHolder( getLayoutInflater().inflate(R.layout.item_contact_request, parent, false)); viewHolder.accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String addr = viewHolder.address.getText().toString(); db.acceptContact(addr); Client.getInstance(getApplicationContext()).startAskForNewMessages(addr); updateContactList(); } }); viewHolder.decline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String address = viewHolder.address.getText().toString(); final String name = viewHolder.name.getText().toString(); db.removeContact(address); updateContactList(); Snackbar.make(findViewById(R.id.drawer_layout), R.string.contact_request_declined, Snackbar.LENGTH_LONG).setAction(R.string.undo, new View.OnClickListener() { @Override public void onClick(View v) { db.addContact(address, false, true, name); updateContactList(); } }).show(); } }); return viewHolder; } @Override public void onBindViewHolder(ContactViewHolder holder, int position) { requestCursor.moveToPosition(position); holder.address.setText(requestCursor.getString(0)); String name = requestCursor.getString(1); if (name == null || name.equals("")) name = "Anonymous"; holder.name.setText(name); } @Override public int getItemCount() { return requestCursor != null ? requestCursor.getCount() : 0; } }); tabLayout = (TabLayout) findViewById(R.id.tabLayout); final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); viewPager.setAdapter(new PagerAdapter() { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(final ViewGroup container, int position) { View v = position == 0 ? contactPage : requestPage; container.addView(v); return v; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } }); tabLayout.setupWithViewPager(viewPager); tabLayout.getTabAt(0).setText(R.string.tab_contacts); tabLayout.getTabAt(1).setText(R.string.tab_requests); for (int i = 0; i < 2; i++) { View v = getLayoutInflater().inflate(R.layout.tab_header, null, false); ((TextView) v.findViewById(R.id.text)).setText(tabLayout.getTabAt(i).getText().toString()); ((TextView) v.findViewById(R.id.badge)).setText(""); v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); tabLayout.getTabAt(i).setCustomView(v); } tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { if (tab.getPosition() == 1) { db.clearNewRequests(); } viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); updateContactList(); handleIntent(); // inform(); listen(); }
From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java
/** * Changes current scene to given one./*from w ww. jav a2 s .c om*/ * * @see #showWidget(com.achep.acdisplay.ui.components.Widget) */ @SuppressLint("NewApi") protected synchronized final void goScene(@NonNull SceneCompat sceneCompat, boolean animate) { if (mCurrentScene == sceneCompat) return; mCurrentScene = sceneCompat; if (DEBUG) Log.d(TAG, "Going to " + sceneCompat); if (Device.hasKitKatApi()) animate &= mSceneContainer.isLaidOut(); if (!animate) { sceneCompat.enter(); return; } if (Device.hasKitKatApi()) { final Scene scene = sceneCompat.getScene(); try { // This must be a synchronization problem with Android's Scene or TransitionManager, // but those were declared as final classes, so I have no idea how to fix it. TransitionManager.go(scene, mTransitionSwitchScene); } catch (IllegalStateException e) { Log.w(TAG, "TransitionManager has failed switching scenes!"); ViewGroup viewGroup = (ViewGroup) getSceneView().getParent(); viewGroup.removeView(getSceneView()); try { // Reset internal scene's tag to make it work again. int id = Resources.getSystem().getIdentifier("current_scene", "id", "android"); Method method = View.class.getMethod("setTagInternal", int.class, Object.class); method.setAccessible(true); method.invoke(viewGroup, id, null); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e2) { throw new RuntimeException("An attempt to fix the TransitionManager has failed."); } TransitionManager.go(scene, mTransitionSwitchScene); } } else { sceneCompat.enter(); if (getActivity() != null) { // TODO: Better animation for Jelly Bean users. float density = getResources().getDisplayMetrics().density; getSceneView().setAlpha(0.6f); getSceneView().setRotationX(6f); getSceneView().setTranslationY(6f * density); getSceneView().animate().alpha(1).rotationX(0).translationY(0); } } }
From source file:android.support.v7.internal.widget.ActionBarView.java
@Override public void setSplitActionBar(boolean splitActionBar) { if (mSplitActionBar != splitActionBar) { if (mMenuView != null) { final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); if (oldParent != null) { oldParent.removeView(mMenuView); }//from ww w . j av a2 s . com if (splitActionBar) { if (mSplitView != null) { mSplitView.addView(mMenuView); } mMenuView.getLayoutParams().width = LayoutParams.FILL_PARENT; } else { addView(mMenuView); mMenuView.getLayoutParams().width = LayoutParams.WRAP_CONTENT; } mMenuView.requestLayout(); } if (mSplitView != null) { mSplitView.setVisibility(splitActionBar ? VISIBLE : GONE); } if (mActionMenuPresenter != null) { if (!splitActionBar) { mActionMenuPresenter.setExpandedActionViewsExclusive( getResources().getBoolean(R.bool.abc_action_bar_expanded_action_views_exclusive)); } else { mActionMenuPresenter.setExpandedActionViewsExclusive(false); // Allow full screen width in split mode. mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true); // No limit to the item count; use whatever will fit. mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); } } super.setSplitActionBar(splitActionBar); } }
From source file:android.support.v7.app.AlertController.java
private void setScrollIndicators(ViewGroup contentPanel, View content, final int indicators, final int mask) { // Set up scroll indicators (if present). View indicatorUp = mWindow.findViewById(R.id.scrollIndicatorUp); View indicatorDown = mWindow.findViewById(R.id.scrollIndicatorDown); if (Build.VERSION.SDK_INT >= 23) { // We're on Marshmallow so can rely on the View APIs ViewCompat.setScrollIndicators(content, indicators, mask); // We can also remove the compat indicator views if (indicatorUp != null) { contentPanel.removeView(indicatorUp); }/* ww w . j a va 2 s . c o m*/ if (indicatorDown != null) { contentPanel.removeView(indicatorDown); } } else { // First, remove the indicator views if we're not set to use them if (indicatorUp != null && (indicators & ViewCompat.SCROLL_INDICATOR_TOP) == 0) { contentPanel.removeView(indicatorUp); indicatorUp = null; } if (indicatorDown != null && (indicators & ViewCompat.SCROLL_INDICATOR_BOTTOM) == 0) { contentPanel.removeView(indicatorDown); indicatorDown = null; } if (indicatorUp != null || indicatorDown != null) { final View top = indicatorUp; final View bottom = indicatorDown; if (mMessage != null) { // We're just showing the ScrollView, set up listener. mScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { manageScrollIndicators(v, top, bottom); } }); // Set up the indicators following layout. mScrollView.post(new Runnable() { @Override public void run() { manageScrollIndicators(mScrollView, top, bottom); } }); } else if (mListView != null) { // We're just showing the AbsListView, set up listener. mListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView v, int firstVisibleItem, int visibleItemCount, int totalItemCount) { manageScrollIndicators(v, top, bottom); } }); // Set up the indicators following layout. mListView.post(new Runnable() { @Override public void run() { manageScrollIndicators(mListView, top, bottom); } }); } else { // We don't have any content to scroll, remove the indicators. if (top != null) { contentPanel.removeView(top); } if (bottom != null) { contentPanel.removeView(bottom); } } } } }
From source file:android.support.v7.internal.widget.ActionBarView.java
public void setMenu(SupportMenu menu, MenuPresenter.Callback cb) { if (menu == mOptionsMenu) { return;//from w w w. j a v a2s .c om } if (mOptionsMenu != null) { mOptionsMenu.removeMenuPresenter(mActionMenuPresenter); mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter); } MenuBuilder builder = (MenuBuilder) menu; mOptionsMenu = builder; if (mMenuView != null) { final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); if (oldParent != null) { oldParent.removeView(mMenuView); } } if (mActionMenuPresenter == null) { mActionMenuPresenter = new ActionMenuPresenter(mContext); mActionMenuPresenter.setCallback(cb); mActionMenuPresenter.setId(R.id.action_menu_presenter); mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); } ActionMenuView menuView; final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); if (!mSplitActionBar) { mActionMenuPresenter.setExpandedActionViewsExclusive( getResources().getBoolean(R.bool.abc_action_bar_expanded_action_views_exclusive)); configPresenters(builder); menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); final ViewGroup oldParent = (ViewGroup) menuView.getParent(); if (oldParent != null && oldParent != this) { oldParent.removeView(menuView); } addView(menuView, layoutParams); } else { mActionMenuPresenter.setExpandedActionViewsExclusive(false); // Allow full screen width in split mode. mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true); // No limit to the item count; use whatever will fit. mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); // Span the whole width layoutParams.width = LayoutParams.FILL_PARENT; configPresenters(builder); menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); if (mSplitView != null) { final ViewGroup oldParent = (ViewGroup) menuView.getParent(); if (oldParent != null && oldParent != mSplitView) { oldParent.removeView(menuView); } menuView.setVisibility(getAnimatedVisibility()); mSplitView.addView(menuView, layoutParams); } else { // We'll add this later if we missed it this time. menuView.setLayoutParams(layoutParams); } } mMenuView = menuView; }
From source file:com.scoreflex.ScoreflexView.java
/** * Closes this ScoreflexView. If the view is attached to the developer * hierarchy it will be detached. If the view is attached to a * ScoreflexActivity, this activity will be terminated. *///w ww . ja v a2 s. co m public void close() { // If we're displayed in the developer view hierarchy, // remove ourselves. final ViewParent parent = this.getParent(); ViewGroup.LayoutParams currentLayoutParams = getLayoutParams(); boolean isFullscreen = currentLayoutParams.height == LayoutParams.MATCH_PARENT; LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mLoginReceiver); if (isFullscreen && null != parent && parent instanceof ViewGroup) { int gravity = getLayoutGravity(); int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_exit_slide_up : R.anim.scoreflex_exit_slide_down; Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation arg0) { ViewGroup parentGroup = (ViewGroup) parent; parentGroup.removeView(ScoreflexView.this); if (mScoreflexViewHandler != null) { mScoreflexViewHandler.onViewClosed(); mScoreflexViewHandler = null; } } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationStart(Animation arg0) { } }); startAnimation(animation); } else if (null != parent && parent instanceof ViewGroup) { ViewGroup parentGroup = (ViewGroup) parent; parentGroup.removeView(this); if (mScoreflexViewHandler != null) { mScoreflexViewHandler.onViewClosed(); mScoreflexViewHandler = null; } } }
From source file:com.androzic.MapFragment.java
private void onUpdateNavigationState() { boolean isNavigating = application.navigationService != null && application.navigationService.isNavigating(); boolean isNavigatingViaRoute = isNavigating && application.navigationService.isNavigatingViaRoute(); View rootView = getView();//w w w. j av a 2 s. co m // waypoint panel rootView.findViewById(R.id.waypointinfo).setVisibility(isNavigating ? View.VISIBLE : View.GONE); // route panel rootView.findViewById(R.id.routeinfo).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE); // distance distanceValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE); rootView.findViewById(R.id.distancelt).setVisibility(isNavigating ? View.VISIBLE : View.GONE); // bearing bearingValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE); rootView.findViewById(R.id.bearinglt).setVisibility(isNavigating ? View.VISIBLE : View.GONE); // turn turnValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE); rootView.findViewById(R.id.turnlt).setVisibility(isNavigating ? View.VISIBLE : View.GONE); // xtk xtkValue.setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE); rootView.findViewById(R.id.xtklt).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE); // we hide elevation in portrait mode due to lack of space if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { if (isNavigatingViaRoute && elevationValue.getVisibility() == View.VISIBLE) { elevationValue.setVisibility(View.GONE); rootView.findViewById(R.id.elevationlt).setVisibility(View.GONE); ViewGroup row = (ViewGroup) rootView.findViewById(R.id.movingrow); int pos = row.indexOfChild(elevationValue); View xtklt = rootView.findViewById(R.id.xtklt); row.removeView(xtkValue); row.removeView(xtklt); row.addView(xtklt, pos); row.addView(xtkValue, pos); row.getParent().requestLayout(); } else if (!isNavigatingViaRoute && elevationValue.getVisibility() == View.GONE) { elevationValue.setVisibility(View.VISIBLE); rootView.findViewById(R.id.elevationlt).setVisibility(View.VISIBLE); ViewGroup row = (ViewGroup) rootView.findViewById(R.id.movingrow); int pos = row.indexOfChild(xtkValue); View elevationlt = rootView.findViewById(R.id.elevationlt); row.removeView(elevationValue); row.removeView(elevationlt); row.addView(elevationlt, pos); row.addView(elevationValue, pos); row.getParent().requestLayout(); } } if (isNavigatingViaRoute) { routeName.setText("\u21d2 " + application.navigationService.navRoute.name); } if (isNavigating) { waypointName.setText("\u2192 " + application.navigationService.navWaypoint.name); } updateMapViewArea(); map.refreshMap(); }
From source file:com.actionbarsherlock.internal.widget.ActionBarView.java
@Override public void setSplitActionBar(boolean splitActionBar) { if (mSplitActionBar != splitActionBar) { if (mMenuView != null) { final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); if (oldParent != null) { oldParent.removeView(mMenuView); }//from ww w .j ava2s .co m if (splitActionBar) { if (mSplitView != null) { mSplitView.addView(mMenuView); } } else { addView(mMenuView); } } if (mSplitView != null) { mSplitView.setVisibility(splitActionBar ? VISIBLE : GONE); } super.setSplitActionBar(splitActionBar); } }