Example usage for android.view ViewGroup getParent

List of usage examples for android.view ViewGroup getParent

Introduction

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

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:Main.java

public static int[] getViewCellCoords(View v) {
    int col = ((ViewGroup) v.getParent()).indexOfChild(v);
    ViewGroup vgRow = (ViewGroup) v.getParent();
    int row = ((ViewGroup) vgRow.getParent()).indexOfChild(vgRow);
    return new int[] { col, row };
}

From source file:Main.java

private static void unwrapView(ViewGroup wrapper) {
    final int childCount = wrapper.getChildCount();
    View[] childViews = new View[childCount];

    ViewGroup parent = (ViewGroup) wrapper.getParent();

    if (parent != null) {
        parent.removeView(wrapper);/*from w  w w  .  j  av a2s.  c o m*/
    }

    for (int i = 0; i < childCount; i++) {
        childViews[i] = wrapper.getChildAt(i);
    }

    // If there was just one wrapper reuse the wrapper layout
    // params to ensure correct type for parent
    if (childCount == 1) {
        ViewGroup.LayoutParams wrapperParams = wrapper.getLayoutParams();
        if (wrapperParams != null) {
            childViews[0].setLayoutParams(wrapperParams);
        }
    }

    for (int i = 0; i < childCount; i++) {
        final View childView = childViews[i];

        wrapper.removeView(childView);
        if (parent != null) {
            parent.addView(childView);
        }
    }
}

From source file:Main.java

public static ViewGroup getParent(View v, int parentId) {
    ViewGroup p = (ViewGroup) v.getParent();
    while (true) {
        if (p == null) {
            return null;
        }/* w  w w.j a  va 2  s . c om*/
        if (p.getId() == parentId) {
            return p;
        }
        p = (ViewGroup) p.getParent();
    }
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

private static View.OnClickListener getClickListener(final ViewGroup myParent, final String methodName) {
    return new View.OnClickListener() {
        @Override//  w  ww  .jav a2 s .co m
        public void onClick(View view) {
            ViewGroup root = myParent;
            DynamicLayoutInfo info = null;
            while (root != null && (root.getParent() instanceof ViewGroup)) {
                if (root.getTag() != null && root.getTag() instanceof DynamicLayoutInfo) {
                    info = (DynamicLayoutInfo) root.getTag();
                    if (info.delegate != null)
                        break;
                }
                root = (ViewGroup) root.getParent();
            }
            if (info != null && info.delegate != null) {
                final Object delegate = info.delegate;
                invokeMethod(delegate, methodName, false, view);
            } else {
                Log.e("DynamicLayoutInflator", "Unable to find valid delegate for click named " + methodName);
            }
        }

        private void invokeMethod(Object delegate, final String methodName, boolean withView, View view) {
            Object[] args = null;
            String finalMethod = methodName;
            if (methodName.endsWith(")")) {
                String[] parts = methodName.split("[(]", 2);
                finalMethod = parts[0];
                try {
                    String argText = parts[1].replace("&quot;", "\"");
                    JSONArray arr = new JSONArray("[" + argText.substring(0, argText.length() - 1) + "]");
                    args = new Object[arr.length()];
                    for (int i = 0; i < arr.length(); i++) {
                        args[i] = arr.get(i);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else if (withView) {
                args = new Object[1];
                args[0] = view;
            }
            Class<?> klass = delegate.getClass();
            try {

                Class<?>[] argClasses = null;
                if (args != null && args.length > 0) {
                    argClasses = new Class[args.length];
                    if (withView) {
                        argClasses[0] = View.class;
                    } else {
                        for (int i = 0; i < args.length; i++) {
                            Class<?> argClass = args[i].getClass();
                            if (argClass == Integer.class)
                                argClass = int.class; // Nobody uses Integer...
                            argClasses[i] = argClass;
                        }
                    }
                }
                Method method = klass.getMethod(finalMethod, argClasses);
                method.invoke(delegate, args);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
                if (!withView && !methodName.endsWith(")")) {
                    invokeMethod(delegate, methodName, true, view);
                }
            }
        }
    };
}

From source file:com.robotsandpencils.walkthrough.presentation.main.paging.screens.ScreensAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ViewGroup viewGroup = mLayouts.get(position).getView();
    ViewGroup parent = (ViewGroup) viewGroup.getParent();
    if (parent != null) {
        parent.removeView(viewGroup);//from   w  ww  .  j  av a  2 s  .c om
    }
    container.addView(viewGroup);
    return viewGroup;
}

From source file:gr.plushost.prototypeapp.widgets.LabelView.java

public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;//  ww  w  .j a v  a 2 s  . c o m
    }

    ViewGroup frameContainer = (ViewGroup) getParent();
    assert (frameContainer.getChildCount() == 2);
    View target = frameContainer.getChildAt(0);

    ViewGroup parentContainer = (ViewGroup) frameContainer.getParent();
    int groupIndex = parentContainer.indexOfChild(frameContainer);
    if (frameContainer.getParent() instanceof RelativeLayout) {
        for (int i = 0; i < parentContainer.getChildCount(); i++) {
            if (i == groupIndex) {
                continue;
            }
            View view = parentContainer.getChildAt(i);
            RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
            for (int j = 0; j < para.getRules().length; j++) {
                if (para.getRules()[j] == _labelViewContainerID) {
                    para.getRules()[j] = target.getId();
                }
            }
            view.setLayoutParams(para);
        }
    }

    ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams();
    target.setLayoutParams(frameLayoutParam);
    parentContainer.removeViewAt(groupIndex);
    frameContainer.removeView(target);
    frameContainer.removeView(this);
    parentContainer.addView(target, groupIndex);
    _labelViewContainerID = -1;
}

From source file:de.fhb.mi.paperfly.user.FriendListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView");

    this.rootView = inflater.inflate(R.layout.fragment_friends, container, false);
    initViewsById();/*from   w  w  w  . java  2s .  c  om*/
    this.drawerLayout = (DrawerLayout) container.getParent();
    setHasOptionsMenu(true);
    getActivity().setTitle(R.string.nav_item_open_friendlist);

    UpdateAccountTask updateAccountTask = new UpdateAccountTask(this);
    updateAccountTask.execute();

    listAdapter = new FriendListAdapter(rootView.getContext());
    setListAdapter(listAdapter);
    return rootView;
}

From source file:com.microsoft.mimickeralarm.settings.AlarmSettingsFragment.java

@Override
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    LinearLayout rootLayout = (LinearLayout) parent.getParent();
    AppBarLayout appBarLayout = (AppBarLayout) LayoutInflater.from(getContext())
            .inflate(R.layout.settings_toolbar, rootLayout, false);
    rootLayout.addView(appBarLayout, 0); // insert at top
    Toolbar bar = (Toolbar) appBarLayout.findViewById(R.id.settings_toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(bar);
    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*  www  .  j  av  a 2  s.  c o m*/
        public void onClick(View v) {
            onCancel();
        }
    });

    Loggable.UserAction userAction;
    if (mAlarm.isNew()) {
        userAction = new Loggable.UserAction(Loggable.Key.ACTION_ALARM_CREATE);
        bar.setTitle(R.string.pref_title_new);
    } else {
        userAction = new Loggable.UserAction(Loggable.Key.ACTION_ALARM_EDIT);
        bar.setTitle(R.string.pref_title_edit);
    }
    Logger.track(userAction);

    RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState);
    int timePreferenceOrder = mTimePreference.getOrder();
    int buttonsPreferenceOrder = mButtonsPreference.getOrder();
    int[] excludeDividerList = new int[] { timePreferenceOrder, buttonsPreferenceOrder };
    recyclerView.addItemDecoration(new SettingsDividerItemDecoration(getContext(), excludeDividerList));

    return recyclerView;
}

From source file:com.just.agentweb.AgentWebUtils.java

static WebParentLayout getWebParentLayoutByWebView(WebView webView) {
    ViewGroup mViewGroup = null;
    if (!(webView.getParent() instanceof ViewGroup)) {
        throw new IllegalStateException("please check webcreator's create method was be called ?");
    }/*from  w  w w  .  j a  v  a  2s. com*/
    mViewGroup = (ViewGroup) webView.getParent();
    AbsAgentWebUIController mAgentWebUIController;
    while (mViewGroup != null) {

        LogUtils.i(TAG, "ViewGroup:" + mViewGroup);
        if (mViewGroup.getId() == R.id.web_parent_layout_id) {
            WebParentLayout mWebParentLayout = (WebParentLayout) mViewGroup;
            LogUtils.i(TAG, "found WebParentLayout");
            return mWebParentLayout;
        } else {
            ViewParent mViewParent = mViewGroup.getParent();
            if (mViewParent instanceof ViewGroup) {
                mViewGroup = (ViewGroup) mViewParent;
            } else {
                mViewGroup = null;
            }
        }
    }
    throw new IllegalStateException("please check webcreator's create method was be called ?");
}

From source file:org.rm3l.ddwrt.fragments.DDWRTBaseFragment.java

@NotNull
private ViewGroup getLayout() {
    @NotNull//from   ww w .ja v  a 2 s.  c  o m
    final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());
    params.setMargins(margin, margin, margin, margin);

    boolean atLeastOneTileAdded = false;

    final SherlockFragmentActivity sherlockActivity = getSherlockActivity();
    if (this.fragmentTiles != null && !this.fragmentTiles.isEmpty()) {

        @NotNull
        final List<CardView> cards = new ArrayList<CardView>();

        final CardView.LayoutParams cardViewLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);

        final int themeBackgroundColor = getThemeBackgroundColor(sherlockActivity, router.getUuid());

        final boolean isThemeLight = isThemeLight(sherlockActivity, themeBackgroundColor);

        for (@NotNull
        final DDWRTTile ddwrtTile : this.fragmentTiles) {
            @Nullable
            final ViewGroup viewGroupLayout = ddwrtTile.getViewGroupLayout();
            atLeastOneTileAdded |= (viewGroupLayout != null);

            if (viewGroupLayout == null) {
                continue;
            }

            if (isThemeLight) {
                ((TextView) viewGroupLayout.findViewById(ddwrtTile.getTileTitleViewId()))
                        .setTextColor(getResources().getColor(android.R.color.holo_blue_dark));
            }

            //Detach this from Parent
            final ViewParent parent = viewGroupLayout.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(viewGroupLayout);
            }

            viewGroupLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));

            final CardView cardView = new CardView(sherlockActivity);
            cardView.setOnClickListener(ddwrtTile);
            cardView.setLayoutParams(cardViewLayoutParams);
            cardView.setCardBackgroundColor(themeBackgroundColor);
            //Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.
            cardView.setPreventCornerOverlap(true);
            //Add padding in API v21+ as well to have the same measurements with previous versions.
            cardView.setUseCompatPadding(true);

            cardView.addView(viewGroupLayout);

            cards.add(cardView);
        }

        atLeastOneTileAdded = (!cards.isEmpty());

        Log.d(LOG_TAG, "atLeastOneTileAdded: " + atLeastOneTileAdded + ", rows: " + cards.size());

        if (atLeastOneTileAdded) {
            //Drop Everything
            //                viewGroup.removeAllViews();

            mLayout = (LinearLayout) viewGroup.findViewById(R.id.tiles_container_scrollview_layout);

            for (@NotNull
            final CardView card : cards) {
                //                    mTableLayout.removeView(row);
                mLayout.addView(card);
            }

        }

        ((ScrollView) viewGroup).setFillViewport(true);
    }

    if (viewGroup == null || !atLeastOneTileAdded) {
        viewGroup = new FrameLayout(sherlockActivity);
        @NotNull
        final TextView view = new TextView(sherlockActivity);
        view.setGravity(Gravity.CENTER);
        view.setText(getResources().getString(R.string.no_data));
        view.setBackgroundResource(R.drawable.background_card);
        view.setLayoutParams(params);

        viewGroup.addView(view);
    }

    viewGroup.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    viewGroup.setLayoutParams(params);

    return viewGroup;

}