Example usage for android.view ViewGroup removeAllViews

List of usage examples for android.view ViewGroup removeAllViews

Introduction

In this page you can find the example usage for android.view ViewGroup removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:Main.java

public static void addViewOnly(ViewGroup layout, View view) {
    try {/*from  www .j  a  va 2 s.  c  om*/
        if (layout.getChildCount() > 0) {
            layout.removeAllViews();
        }
        layout.addView(view);
    } catch (Exception e) {
        // e.printStackTrace();
    }
}

From source file:Main.java

public static void addViewOnly(ViewGroup layout, View view) {
    try {/*from w ww.j a v a2s.  c o  m*/
        if (layout.getChildCount() > 0) {
            layout.removeAllViews();
        }
        layout.addView(view);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.ayo.robot.anim.transitioneverywhere.TransitionNameSample.java

private static void createViews(LayoutInflater inflater, ViewGroup layout, List<String> titles) {
    layout.removeAllViews();
    for (String title : titles) {
        TextView textView = (TextView) inflater.inflate(R.layout.fragment_names_item, layout, false);
        textView.setText(title);/*ww w  .  j  a  v  a  2s  . c  o m*/
        TransitionManager.setTransitionName(textView, title);
        layout.addView(textView);
    }
}

From source file:Main.java

public static void unBindDrawables(View view) {
    if (view != null) {
        try {//from  w ww. j  a v  a 2  s .co m
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
                ViewGroup viewGroup = (ViewGroup) view;
                int viewGroupChildCount = viewGroup.getChildCount();
                for (int j = 0; j < viewGroupChildCount; j++) {
                    unBindDrawables(viewGroup.getChildAt(j));
                }
                viewGroup.removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:Main.java

public static void setView(Activity activity, int id) {
    LayoutInflater layoutInflater = LayoutInflater.from(activity);
    setTranslucentStatus(activity);//from  w w w .  j a  v  a  2s  . c om
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content);
    int height = getStatusBarHeight(activity);
    ViewGroup linearLayout = (ViewGroup) layoutInflater.from(activity).inflate(id, null);
    linearLayout.setPadding(0, height, 0, 0);
    decorView.removeAllViews();
    decorView.addView(linearLayout);

}

From source file:Main.java

@SuppressWarnings("unchecked")
public static void unbindRecursively(View view) {
    if (view == null)
        return;/*from  w w w . j  a v  a  2 s  .  c  o  m*/

    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
        setBackgroundDrawable(view, null);
    }

    if (view instanceof Button) {
        if (view.getBackground() != null) {
            view.getBackground().setCallback(null);
        }
        setBackgroundDrawable(view, null);
    }

    if (view instanceof ImageView) {
        unbindImageView((ImageView) view);
        setBackgroundDrawable(view, null);
    }

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            unbindRecursively(viewGroup.getChildAt(i));
        }
        if (viewGroup instanceof AdapterView) {
            ((AdapterView) viewGroup).setAdapter(null);
        } else {
            viewGroup.removeAllViews();
        }
    }
    view.destroyDrawingCache();
    view = null;
}

From source file:com.battlelancer.seriesguide.util.PeopleListHelper.java

/**
 * Add views for at most three cast members to the given {@link android.view.ViewGroup} and a
 * "Show all" link if there are more.//from w ww.  ja v a 2 s .c o  m
 */
private static void populateCast(Context context, LayoutInflater inflater, ViewGroup peopleContainer,
        Credits credits, PeopleActivity.MediaType mediaType) {
    if (peopleContainer == null) {
        // nothing we can do, view is already gone
        Timber.d("populateCast: container reference gone, aborting");
        return;
    }

    peopleContainer.removeAllViews();

    // show at most 3 cast members
    List<Credits.CastMember> cast = credits.cast;
    for (int i = 0; i < Math.min(3, cast.size()); i++) {
        Credits.CastMember castMember = cast.get(i);

        View personView = createPersonView(context, inflater, peopleContainer, castMember.name,
                castMember.character, castMember.profile_path);
        personView.setOnClickListener(new OnPersonClickListener(mediaType, credits.id,
                PeopleActivity.PeopleType.CAST, castMember.id));

        peopleContainer.addView(personView);
    }

    if (cast.size() > 3) {
        addShowAllView(inflater, peopleContainer,
                new OnPersonClickListener(mediaType, credits.id, PeopleActivity.PeopleType.CAST));
    }
}

From source file:com.battlelancer.seriesguide.util.PeopleListHelper.java

/**
 * Add views for at most three crew members to the given {@link android.view.ViewGroup} and a
 * "Show all" link if there are more./* w  w w  .java 2 s  .  c o  m*/
 */
private static void populateCrew(Context context, LayoutInflater inflater, ViewGroup peopleContainer,
        Credits credits, PeopleActivity.MediaType mediaType) {
    if (peopleContainer == null) {
        // nothing we can do, view is already gone
        Timber.d("populateCrew: container reference gone, aborting");
        return;
    }

    peopleContainer.removeAllViews();

    // show at most 3 crew members
    List<Credits.CrewMember> crew = credits.crew;
    for (int i = 0; i < Math.min(3, crew.size()); i++) {
        Credits.CrewMember castMember = crew.get(i);

        View personView = createPersonView(context, inflater, peopleContainer, castMember.name, castMember.job,
                castMember.profile_path);
        personView.setOnClickListener(new OnPersonClickListener(mediaType, credits.id,
                PeopleActivity.PeopleType.CREW, castMember.id));

        peopleContainer.addView(personView);
    }

    if (crew.size() > 3) {
        addShowAllView(inflater, peopleContainer,
                new OnPersonClickListener(mediaType, credits.id, PeopleActivity.PeopleType.CREW));
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

/**
 * @param v the view to bind// w w  w . j ava  2 s. c om
 * @param context standard activity context
 * @param c the cursor source for the object in the db object table.
 * Must include _id in the projection.
 * 
 * @param allowInteractions controls whether the bound view is
 * allowed to intercept touch events and do its own processing.
 */
public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) {
    TextView nameText = (TextView) v.findViewById(R.id.name_text);
    ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content);
    frame.removeAllViews();

    // make sure we have all the columns we need
    Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID));
    String[] projection = null;
    String selection = DbObj.COL_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(objId) };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs,
            sortOrder);
    if (!c.moveToFirst()) {
        Log.w(TAG, "could not find obj " + objId);
        c.close();
        return;
    }
    DbObj obj = App.instance().getMusubi().objForCursor(c);
    if (obj == null) {
        nameText.setText("Failed to access database.");
        Log.e("DbObject", "cursor was null for bindView of DbObject");
        return;
    }
    DbUser sender = obj.getSender();
    Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP));
    Long hash = obj.getHash();
    short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED));
    String feedName = obj.getFeedName();
    String type = obj.getType();
    Date date = new Date(timestamp);
    c.close();
    c = null;

    if (sender == null) {
        nameText.setText("Message from unknown contact.");
        return;
    }
    nameText.setText(sender.getName());

    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
    if (sViewProfileAction == null) {
        sViewProfileAction = new OnClickViewProfile((Activity) context);
    }
    icon.setTag(sender.getLocalId());
    if (allowInteractions) {
        icon.setOnClickListener(sViewProfileAction);
        v.setTag(objId);
    }
    icon.setImageBitmap(sender.getPicture());

    if (deleted == 1) {
        v.setBackgroundColor(sDeletedColor);
    } else {
        v.setBackgroundColor(Color.TRANSPARENT);
    }

    TextView timeText = (TextView) v.findViewById(R.id.time_text);
    timeText.setText(RelativeDate.getRelativeDate(date));

    frame.setTag(objId); // TODO: error prone! This is database id
    frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id
    FeedRenderer renderer = DbObjects.getFeedRenderer(type);
    if (renderer != null) {
        renderer.render(context, frame, obj, allowInteractions);
    }

    if (!allowInteractions) {
        v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
        v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
    } else {
        if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) {
            v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
            v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
        } else {
            ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon);
            TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments);
            attachmentCountButton.setVisibility(View.VISIBLE);

            if (hash == 0) {
                attachmentCountButton.setVisibility(View.GONE);
            } else {
                //int color = DbObject.colorFor(hash);
                boolean selfPost = false;
                DBHelper helper = new DBHelper(context);
                try {
                    Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE });
                    try {
                        attachmentCountText.setText("+" + attachments.getCount());

                        if (attachments.moveToFirst()) {
                            while (!attachments.isAfterLast()) {
                                if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) {
                                    selfPost = true;
                                    break;
                                }
                                attachments.moveToNext();

                            }
                        }
                    } finally {
                        attachments.close();
                    }
                } finally {
                    helper.close();
                }
                if (selfPost) {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red);
                } else {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love);
                }
                attachmentCountText.setTag(R.id.object_entry, hash);
                attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName));
                attachmentCountText.setOnClickListener(LikeListener.getInstance(context));
            }
        }
    }
}

From source file:com.micabyte.android.app.BaseActivity.java

private static void unbindViewGroupReferences(ViewGroup viewGroup) {
    final int nrOfChildren = viewGroup.getChildCount();
    for (int i = 0; i < nrOfChildren; i++) {
        final View view = viewGroup.getChildAt(i);
        unbindViewReferences(view);//  ww  w . ja  va2s  . com
        if (view instanceof ViewGroup)
            unbindViewGroupReferences((ViewGroup) view);
    }
    try {
        viewGroup.removeAllViews();
    } catch (Throwable mayHappen) {
        // AdapterViews, ListViews and potentially other ViewGroups don't
        // support the removeAllViews operation
    }
}