Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

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

Prototype

@Override
public void addView(View child, LayoutParams params) 

Source Link

Document

Adds a child view with the specified layout parameters.

Usage

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//from w  ww  .j a  v  a2 s .c om
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void addContentView(View v, ViewGroup.LayoutParams lp) {
    ensureSubDecor();//from   w  w  w  .  ja  va  2  s .c o m
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.addView(v, lp);
    mOriginalWindowCallback.onContentChanged();
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void setContentView(View v, ViewGroup.LayoutParams lp) {
    ensureSubDecor();/*from ww  w  . j ava  2s.c  om*/
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.removeAllViews();
    contentParent.addView(v, lp);
    mOriginalWindowCallback.onContentChanged();
}

From source file:com.cairoconfessions.MainActivity.java

public void addLocation(View view) {
    TextView newView = new TextView(this);
    AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation));
    String newLoc = addLoc.getText().toString();
    ViewGroup locList = ((ViewGroup) findViewById(R.id.locations));
    boolean notFound = true;
    for (int i = 0; i < locList.getChildCount(); i++) {
        if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString()))
            notFound = false;//from   w w  w.jav a 2s.  c  om
        break;
    }
    if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) {
        newView.setText(newLoc);
        newView.setClickable(true);
        newView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                addItem(view);
            }
        });
        float scale = getResources().getDisplayMetrics().density;
        newView.setGravity(17);
        newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

        newView.setBackgroundResource(R.drawable.city2);

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                (int) (150 * scale));
        lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale));
        newView.setLayoutParams(lp);
        locList.addView(newView, 0);
        addLoc.setText("");
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0);
        addLoc.setCursorVisible(false);

    } else {
        Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show();
    }
}

From source file:com.dk.view.FolderDrawerLayout.java

private void replaceView() {
    ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT);
    mLeftCache = left.getChildAt(0);/*w  w  w . j a v a2 s .  c  o m*/
    left.removeAllViews();
    mMeshImageView = new MeshImageView(getContext());
    mMeshImageView.setImageBitmap(mDrawingCache);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-1, -1);
    left.addView(mMeshImageView, params);
    if (isDrawerOpen(Gravity.LEFT)) {
        mCoreCalc.setDirection(Direction.LEFT);
    } else {
        mCoreCalc.setDirection(Direction.RIGHT);
    }

    mMeshImageView.setMeshVerts(mCoreCalc.createOffsetVerts(1, mInitialMotionY));

    // mMeshImageView.getViewTreeObserver().addOnPreDrawListener(new
    // OnPreDrawListener() {
    //
    // @Override
    // public boolean onPreDraw() {
    //
    //
    // return false;
    // }
    // });
}

From source file:com.mark.quick.ui.view.swipebacklayout.SwipeBackLayout.java

/**
 *  Activity //  w  w w  .jav a  2s  .  c  o  m
 *
 * @param activity
 */
void attachToActivity(Activity activity) {

    mActivity = activity;
    setSliderFadeColor(Color.TRANSPARENT);

    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();

    //view
    mShadowView = new SwipeBackShadowView(activity);
    addView(mShadowView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    //??DecorViewchild
    ViewGroup contentView = (ViewGroup) decorView.getChildAt(0);
    decorView.removeView(contentView);
    addView(contentView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    //??DecorViewchild
    decorView.addView(this, 0);

}

From source file:com.imagersliderlib.adapter.ImagePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup view, int position) {
    View imageLayout = inflater.inflate(R.layout.image_pager_layout, view, false);
    assert imageLayout != null;
    ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);

    // image loding progressbar
    final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);

    // image scale set
    imageView.setScaleType(ScaleType.FIT_XY);

    // init ImageLoader
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));

    // ImageLoader set option
    options = new DisplayImageOptions.Builder().showImageForEmptyUri(new ColorDrawable(0xff6e6e6e))
            .showImageOnFail(new ColorDrawable(0xff6e6e6e)).showImageOnLoading(new ColorDrawable(0xff6e6e6e))
            .cacheInMemory(true).cacheOnDisk(true).build();

    imageLoader.displayImage(mImages.get(position), imageView, options, new SimpleImageLoadingListener() {
        @Override//from  ww w . j  av a2 s  .co m
        public void onLoadingStarted(String imageUri, View view) {
            spinner.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            String message = null;
            switch (failReason.getType()) {
            case IO_ERROR:
                message = "Input/Output error";
                break;
            case DECODING_ERROR:
                message = "Image can't be decoded";
                break;
            case NETWORK_DENIED:
                message = "Downloads are denied";
                break;
            case OUT_OF_MEMORY:
                message = "Out Of Memory error";
                break;
            case UNKNOWN:
                message = "Unknown error";
                break;
            }
            Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();

            spinner.setVisibility(View.GONE);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            spinner.setVisibility(View.GONE);
        }
    });

    view.addView(imageLayout, 0);
    return imageLayout;
}

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  ww  w . j ava 2 s .  c o m*/
    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:de.mrapp.android.bottomsheet.BottomSheet.java

/**
 * Initializes the bottom sheet's root view.
 *///from   ww  w  . j  ava 2  s  . c  om
private void inflateRootView() {
    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.removeAllViews();
    LayoutInflater layoutInflater = LayoutInflater.from(getContext());
    rootView = (DraggableView) layoutInflater.inflate(R.layout.bottom_sheet, contentView, false);
    rootView.setCallback(this);
    contentView.addView(rootView, createRootViewLayoutParams());
}