Example usage for android.view ViewGroup requestLayout

List of usage examples for android.view ViewGroup requestLayout

Introduction

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

Prototype

@CallSuper
public void requestLayout() 

Source Link

Document

Call this when something has changed which has invalidated the layout of this view.

Usage

From source file:Main.java

/**
 * Assert run an AbsListView with LayoutAnimationController successfully.
 * @param instrumentation//from   w  w w  .  ja  v a  2s. c  om
 * @param view
 * @param controller
 * @param duration
 * @throws InterruptedException
 */
public static void assertRunController(final Instrumentation instrumentation, final ViewGroup view,
        final LayoutAnimationController controller, final long duration) throws InterruptedException {

    instrumentation.runOnMainSync(new Runnable() {
        public void run() {
            view.setLayoutAnimation(controller);
            view.requestLayout();
        }
    });

    // LayoutAnimationController.isDone() always returns true, it's no use for stopping
    // the running, so just using sleeping fixed time instead. we reported issue 1799434 for it.
    Thread.sleep(duration + TIMEOUT_DELTA);
}

From source file:Main.java

public static void collapse(final ViewGroup v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override/*from w w  w. j a v  a2  s  .c o  m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.setAlpha(1 - interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void expand(final ViewGroup v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;/*  w  w  w  .j av a 2s . co  m*/
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.setAlpha(interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java

/**
 * creates a grid of textViews from layout files based on the gridSize
 *  and sets the new textViews to use the controller as their listener
 * //from  ww  w.  j  a va2s  . co  m
 * @param gridSize square size of the new grid to make
 * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid
 */
public void setupViewGrid() {
    control.setLetter(null);
    int gridSize = control.getGridSize();
    TextViewGridController controller = control.getGridManager();
    ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable);
    if (gridTable.getChildCount() != gridSize) {
        if (gridTable.getChildCount() == 0) {
            gridTable.setKeepScreenOn(true);
            gridTable.setOnTouchListener(controller);
        }
        controller.clearPointDemension();
        gridTable.removeAllViews();
        Point point = new Point();
        controller.setGridView(new TextView[gridSize][]);
        TextView[][] gridView = controller.getGridView();
        for (point.y = 0; point.y < gridSize; point.y++) {
            this.getLayoutInflater().inflate(R.layout.grid_row, gridTable, true);
            ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y);
            TextView[] rowText = new TextView[gridSize];
            for (point.x = 0; point.x < gridSize; point.x++) {
                this.getLayoutInflater().inflate(R.layout.grid_text_view, row, true);
                TextView view = (TextView) row.getChildAt(point.x);
                view.setId(ConversionUtil.convertPointToID(point, control.getGridSize()));
                view.setOnKeyListener(controller);

                rowText[point.x] = view;
            }
            gridView[point.y] = rowText;
        }
        gridTable.requestLayout();
    }
}

From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java

/**
 * creates a grid of textViews from layout files based on the gridSize
 *  and sets the new textViews to use the controller as their listener
 * /*from w  w w .  j av a 2s . c  om*/
 * @param gridSize square size of the new grid to make
 * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid
 */
public void setupViewGrid() {
    control.setLetter(null);
    int gridSize = control.getGridSize();
    TextViewGridController controller = control.getGridManager();
    ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable);
    if (gridTable.getChildCount() != gridSize) {
        if (gridTable.getChildCount() == 0) {
            gridTable.setKeepScreenOn(true);
            gridTable.setOnTouchListener(controller);
        }
        controller.clearPointDemension();
        gridTable.removeAllViews();
        Point point = new Point();
        controller.setGridView(new TextView[gridSize][]);
        TextView[][] gridView = controller.getGridView();
        for (point.y = 0; point.y < gridSize; point.y++) {
            this.getLayoutInflater().inflate(R.layout.ws_grid_row, gridTable, true);
            ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y);
            TextView[] rowText = new TextView[gridSize];
            for (point.x = 0; point.x < gridSize; point.x++) {
                this.getLayoutInflater().inflate(R.layout.ws_grid_text_view, row, true);
                TextView view = (TextView) row.getChildAt(point.x);
                view.setId(ConversionUtil.convertPointToID(point, control.getGridSize()));
                view.setOnKeyListener(controller);

                rowText[point.x] = view;
            }
            gridView[point.y] = rowText;
        }
        gridTable.requestLayout();
    }
}

From source file:com.android.leanlauncher.Workspace.java

/**
 * Removes items that match the item info specified. When applications are removed
 * as a part of an update, this is called to ensure that other widgets and application
 * shortcuts are not removed.//  w  ww  . j av  a2 s  .  c o m
 */
void removeItemsByComponentName(final HashSet<ComponentName> componentNames, final UserHandleCompat user) {
    final ViewGroup layout = mWorkspace.getShortcutsAndWidgets();

    final ArrayMap<ItemInfo, View> children = new ArrayMap<>();
    for (int j = 0; j < layout.getChildCount(); j++) {
        final View view = layout.getChildAt(j);
        children.put((ItemInfo) view.getTag(), view);
    }

    final ArrayList<View> childrenToRemove = new ArrayList<View>();
    LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
        @Override
        public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
            if (componentNames.contains(cn) && info.user.equals(user)) {
                childrenToRemove.add(children.get(info));
                return true;
            }
            return false;
        }
    };
    LauncherModel.filterItemInfos(children.keySet(), filter);

    // Remove all the other children
    for (View child : childrenToRemove) {
        // Note: We can not remove the view directly from CellLayoutChildren as this
        // does not re-mark the spaces as unoccupied.
        mWorkspace.removeViewInLayout(child);
        if (child instanceof DropTarget) {
            mDragController.removeDropTarget((DropTarget) child);
        }
    }

    if (childrenToRemove.size() > 0) {
        layout.requestLayout();
        layout.invalidate();
    }
}

From source file:cc.flydev.launcher.Workspace.java

void removeItemsByComponentName(final HashSet<ComponentName> componentNames) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            children.put((ItemInfo) view.getTag(), view);
        }/*  ww  w .  j a  v a  2s  .c o m*/

        final ArrayList<View> childrenToRemove = new ArrayList<View>();
        final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfo, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
                if (parent instanceof FolderInfo) {
                    if (componentNames.contains(cn)) {
                        FolderInfo folder = (FolderInfo) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    if (componentNames.contains(cn)) {
                        childrenToRemove.add(children.get(info));
                        return true;
                    }
                }
                return false;
            }
        };
        LauncherModel.filterItemInfos(children.keySet(), filter);

        // Remove all the apps from their folders
        for (FolderInfo folder : folderAppsToRemove.keySet()) {
            ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }

        // Remove all the other children
        for (View child : childrenToRemove) {
            // Note: We can not remove the view directly from CellLayoutChildren as this
            // does not re-mark the spaces as unoccupied.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.example.launcher3.Workspace.java

void removeItemsByComponentName(final HashSet<ComponentName> componentNames) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            children.put((ItemInfo) view.getTag(), view);
        }//from   w ww .jav  a2 s. c o  m

        final ArrayList<View> childrenToRemove = new ArrayList<View>();
        final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfo, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
                if (parent instanceof FolderInfo) {
                    if (componentNames.contains(cn)) {
                        FolderInfo folder = (FolderInfo) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    if (componentNames.contains(cn)) {
                        childrenToRemove.add(children.get(info));
                        return true;
                    }
                }
                return false;
            }
        };
        LauncherModel.filterItemInfos(children.keySet(), filter);

        // Remove all the apps from their folders
        for (FolderInfo folder : folderAppsToRemove.keySet()) {
            ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }

        // Remove all the other children
        for (View child : childrenToRemove) {
            // Note: We can not remove the view directly from
            // CellLayoutChildren as this
            // does not re-mark the spaces as unoccupied.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

public void removeItemsByComponentName(final HashSet<ComponentName> componentNames) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfoBean, View> children = new HashMap<ItemInfoBean, View>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            children.put((ItemInfoBean) view.getTag(), view);
        }/*w  ww  .  ja va  2s  . co m*/

        final ArrayList<View> childrenToRemove = new ArrayList<View>();
        final HashMap<FolderInfoBean, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfoBean, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfoBean parent, ItemInfoBean info, ComponentName cn) {
                if (parent instanceof FolderInfoBean) {
                    if (componentNames.contains(cn)) {
                        FolderInfoBean folder = (FolderInfoBean) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    if (componentNames.contains(cn)) {
                        childrenToRemove.add(children.get(info));
                        return true;
                    }
                }
                return false;
            }
        };
        LauncherModel.filterItemInfos(children.keySet(), filter);

        // Remove all the apps from their folders
        for (FolderInfoBean folder : folderAppsToRemove.keySet()) {
            ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }

        // Remove all the other children
        for (View child : childrenToRemove) {
            // Note: We can not remove the view directly from
            // CellLayoutChildren as this
            // does not re-mark the spaces as unoccupied.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.android.launcher2.Workspace.java

void removeItems(final ArrayList<String> packages) {
    final HashSet<String> packageNames = new HashSet<String>();
    packageNames.addAll(packages);//from   w w  w  .  jav  a2 s  .c  om

    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        // Avoid ANRs by treating each screen separately
        post(new Runnable() {
            public void run() {
                final ArrayList<View> childrenToRemove = new ArrayList<View>();
                childrenToRemove.clear();

                int childCount = layout.getChildCount();
                for (int j = 0; j < childCount; j++) {
                    final View view = layout.getChildAt(j);
                    Object tag = view.getTag();

                    if (tag instanceof ShortcutInfo) {
                        final ShortcutInfo info = (ShortcutInfo) tag;
                        final Intent intent = info.intent;
                        final ComponentName name = intent.getComponent();

                        if (name != null) {
                            if (packageNames.contains(name.getPackageName())) {
                                LauncherModel.deleteItemFromDatabase(mLauncher, info);
                                childrenToRemove.add(view);
                            }
                        }
                    } else if (tag instanceof FolderInfo) {
                        final FolderInfo info = (FolderInfo) tag;
                        final ArrayList<ShortcutInfo> contents = info.contents;
                        final int contentsCount = contents.size();
                        final ArrayList<ShortcutInfo> appsToRemoveFromFolder = new ArrayList<ShortcutInfo>();

                        for (int k = 0; k < contentsCount; k++) {
                            final ShortcutInfo appInfo = contents.get(k);
                            final Intent intent = appInfo.intent;
                            final ComponentName name = intent.getComponent();

                            if (name != null) {
                                if (packageNames.contains(name.getPackageName())) {
                                    appsToRemoveFromFolder.add(appInfo);
                                }
                            }
                        }
                        for (ShortcutInfo item : appsToRemoveFromFolder) {
                            info.remove(item);
                            LauncherModel.deleteItemFromDatabase(mLauncher, item);
                        }
                    } else if (tag instanceof LauncherAppWidgetInfo) {
                        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag;
                        final ComponentName provider = info.providerName;
                        if (provider != null) {
                            if (packageNames.contains(provider.getPackageName())) {
                                LauncherModel.deleteItemFromDatabase(mLauncher, info);
                                childrenToRemove.add(view);
                            }
                        }
                    }
                }

                childCount = childrenToRemove.size();
                for (int j = 0; j < childCount; j++) {
                    View child = childrenToRemove.get(j);
                    // Note: We can not remove the view directly from CellLayoutChildren as this
                    // does not re-mark the spaces as unoccupied.
                    layoutParent.removeViewInLayout(child);
                    if (child instanceof DropTarget) {
                        mDragController.removeDropTarget((DropTarget) child);
                    }
                }

                if (childCount > 0) {
                    layout.requestLayout();
                    layout.invalidate();
                }
            }
        });
    }

    // Clean up new-apps animation list
    final Context context = getContext();
    post(new Runnable() {
        @Override
        public void run() {
            String spKey = LauncherApplication.getSharedPreferencesKey();
            SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
            Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null);

            // Remove all queued items that match the same package
            if (newApps != null) {
                synchronized (newApps) {
                    Iterator<String> iter = newApps.iterator();
                    while (iter.hasNext()) {
                        try {
                            Intent intent = Intent.parseUri(iter.next(), 0);
                            String pn = ItemInfo.getPackageName(intent);
                            if (packageNames.contains(pn)) {
                                iter.remove();
                            }

                            // It is possible that we've queued an item to be loaded, yet it has
                            // not been added to the workspace, so remove those items as well.
                            ArrayList<ItemInfo> shortcuts;
                            shortcuts = LauncherModel.getWorkspaceShortcutItemInfosWithIntent(intent);
                            for (ItemInfo info : shortcuts) {
                                LauncherModel.deleteItemFromDatabase(context, info);
                            }
                        } catch (URISyntaxException e) {
                        }
                    }
                }
            }
        }
    });
}