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:com.androzic.MapFragment.java

private void onUpdateNavigationState() {
    boolean isNavigating = application.navigationService != null
            && application.navigationService.isNavigating();
    boolean isNavigatingViaRoute = isNavigating && application.navigationService.isNavigatingViaRoute();

    View rootView = getView();/*from   ww w .ja v a 2  s  .c o 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:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

private void setAncestorsShouldClipChildren(boolean clip) {
    if (!isLocationBarShownInNTP())
        return;/*ww w .  ja v a  2s  . c o  m*/
    ViewGroup parent = this;
    while (parent != null) {
        parent.setClipChildren(clip);
        if (!(parent.getParent() instanceof ViewGroup))
            break;
        if (parent.getId() == android.R.id.content)
            break;
        parent = (ViewGroup) parent.getParent();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    PackageManager pm = context.getPackageManager();
    Drawable icon = null;/*from  w  w w. ja va  2  s  .  c  om*/
    String appName;
    if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
    } else {
        appName = "Unknown";
    }
    if (!(obj instanceof DbObj)) {
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Preparing application " + appName + "...";
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
        return;
    }

    DbObj dbParentObj = (DbObj) obj;
    boolean rendered = false;

    Intent launch = getLaunchIntent(context, dbParentObj);
    List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0);
    if (infos.size() > 0) {
        ResolveInfo info = infos.get(0);
        if (info.activityInfo.labelRes != 0) {
            appName = info.activityInfo.loadLabel(pm).toString();
            icon = info.loadIcon(pm);
        } else {
            appName = info.activityInfo.name;
        }
    } else {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
    }
    // TODO: Safer reference to containing view
    if (icon != null) {
        View parentView = (View) frame.getParent().getParent();
        ImageView avatar = (ImageView) parentView.findViewById(R.id.icon);
        avatar.setImageDrawable(icon);

        TextView label = (TextView) parentView.findViewById(R.id.name_text);
        label.setText(appName);
    }

    // TODO: obj.getLatestChild().render();
    String selection = getRenderableClause();
    String[] selectionArgs = null;
    Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs);
    if (cursor.moveToFirst()) {
        DbObj dbObj = App.instance().getMusubi().objForCursor(cursor);
        DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions);
        rendered = true;
    }

    if (!rendered) {
        String text;
        if (icon != null) {
            ImageView iv = new ImageView(context);
            iv.setImageDrawable(icon);
            iv.setAdjustViewBounds(true);
            iv.setMaxWidth(60);
            iv.setMaxHeight(60);
            iv.setLayoutParams(CommonLayouts.WRAPPED);
            frame.addView(iv);
            text = appName;
        } else {
            text = "New application: " + appName + ".";
        }
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:com.androzic.MapActivity.java

protected void updateNavigationStatus() {
    boolean isNavigating = navigationService != null && navigationService.isNavigating();
    boolean isNavigatingViaRoute = isNavigating && navigationService.isNavigatingViaRoute();

    // waypoint panel
    findViewById(R.id.waypointinfo).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // route panel
    findViewById(R.id.routeinfo).setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    // distance//from  w  w w . j  a v  a2  s  . c om
    distanceValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.distancelt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // bearing
    bearingValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.bearinglt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // turn
    turnValue.setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    findViewById(R.id.turnlt).setVisibility(isNavigating ? View.VISIBLE : View.GONE);
    // xtk
    xtkValue.setVisibility(isNavigatingViaRoute ? View.VISIBLE : View.GONE);
    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);
            findViewById(R.id.elevationlt).setVisibility(View.GONE);

            ViewGroup row = (ViewGroup) findViewById(R.id.movingrow);
            int pos = row.indexOfChild(elevationValue);
            View xtklt = 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);
            findViewById(R.id.elevationlt).setVisibility(View.VISIBLE);

            ViewGroup row = (ViewGroup) findViewById(R.id.movingrow);
            int pos = row.indexOfChild(xtkValue);
            View elevationlt = 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(" " + navigationService.navRoute.name);
    }
    if (isNavigating) {
        waypointName.setText(" " + navigationService.navWaypoint.name);
        if (application.navigationOverlay == null) {
            application.navigationOverlay = new NavigationOverlay(this);
            application.navigationOverlay.onMapChanged();
        }
    } else if (application.navigationOverlay != null) {
        application.navigationOverlay.onBeforeDestroy();
        application.navigationOverlay = null;
    }

    updateMapViewArea();
    map.update();
}

From source file:com.isapp.android.circularviewpager.CircularViewPager.java

private Rect getChildRectInPagerCoordinates(Rect outRect, View child) {
    if (outRect == null) {
        outRect = new Rect();
    }//from  ww w  .j  a va 2 s . c o m
    if (child == null) {
        outRect.set(0, 0, 0, 0);
        return outRect;
    }
    outRect.left = child.getLeft();
    outRect.right = child.getRight();
    outRect.top = child.getTop();
    outRect.bottom = child.getBottom();
    ViewParent parent = child.getParent();
    while (parent instanceof ViewGroup && parent != this) {
        final ViewGroup group = (ViewGroup) parent;
        outRect.left += group.getLeft();
        outRect.right += group.getRight();
        outRect.top += group.getTop();
        outRect.bottom += group.getBottom();
        parent = group.getParent();
    }
    return outRect;
}

From source file:VerticalViewPager.java

private Rect getChildRectInPagerCoordinates(Rect outRect, View child) {
    if (outRect == null) {
        outRect = new Rect();
    }/*from  w  w  w  .ja  va  2  s  .  c o m*/
    if (child == null) {
        outRect.set(0, 0, 0, 0);
        return outRect;
    }
    outRect.left = child.getLeft();
    outRect.right = child.getRight();
    outRect.top = child.getTop();
    outRect.bottom = child.getBottom();

    ViewParent parent = child.getParent();
    while (parent instanceof ViewGroup && parent != this) {
        final ViewGroup group = (ViewGroup) parent;
        outRect.left += group.getLeft();
        outRect.right += group.getRight();
        outRect.top += group.getTop();
        outRect.bottom += group.getBottom();

        parent = group.getParent();
    }
    return outRect;
}

From source file:example.luojing.androidsourceanalysis.ViewPager.java

/**
 * ViewPager????View??/*from  w ww.  ja v a  2 s .c o m*/
 */
private Rect getChildRectInPagerCoordinates(Rect outRect, View child) {
    if (outRect == null) {
        outRect = new Rect();
    }
    if (child == null) {
        outRect.set(0, 0, 0, 0);
        return outRect;
    }
    outRect.left = child.getLeft();
    outRect.right = child.getRight();
    outRect.top = child.getTop();
    outRect.bottom = child.getBottom();

    ViewParent parent = child.getParent();
    while (parent instanceof ViewGroup && parent != this) {
        final ViewGroup group = (ViewGroup) parent;
        outRect.left += group.getLeft();
        outRect.right += group.getRight();
        outRect.top += group.getTop();
        outRect.bottom += group.getBottom();

        parent = group.getParent();
    }
    return outRect;
}