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:br.com.bioscada.apps.biotracks.fragments.ChartAndPacerFragment.java

@Override
public void onStart() {
    super.onStart();
    ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.bchart_view_layout);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layout.addView(chartView, layoutParams);
}

From source file:com.google.android.apps.santatracker.dasherdancer.CharacterAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView view = null;//from  w w w.  j  av  a  2s.  c o m

    if (position < mCharacters.length) {
        if (mViews.get(position) != null) {
            view = mViews.get(position);
        } else {
            view = new FrameAnimationView(container.getContext());
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            //Load the first idle frame.
            view.setBackgroundResource(mBackgrounds[position]);
            view.setTag(position);
            mViews.put(position, view);
        }

        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        container.addView(view, lp);
    }

    return view;
}

From source file:br.com.bioscada.apps.biotracks.fragments.ChartFragment.java

@Override
public void onStart() {
    super.onStart();
    ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.chart_view_layout);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layout.removeAllViews();/* w ww  .  jav  a  2  s  .  c o m*/
    layout.addView(chartView, layoutParams);
}

From source file:com.alibaba.android.layoutmanager.RecyclablePagerAdapter.java

/**
 * Get view from position/*from   w  w  w  .j ava2 s.c o  m*/
 *
 * @param container
 * @param position
 * @return
 */
@Override
public Object instantiateItem(ViewGroup container, int position) {
    int itemViewType = getItemViewType(position);
    RecyclerView.ViewHolder holder = mRecycledViewPool.getRecycledView(itemViewType);

    if (holder == null) {
        holder = mAdapter.createViewHolder(container, itemViewType);
    }

    onBindViewHolder((VH) holder, position);
    //itemViews' layoutParam will be reused when there are more than one nested ViewPager in one page,
    //so the attributes of layoutParam such as widthFactor and position will also be reused,
    //while these attributes should be reset to default value during reused.
    //Considering ViewPager.LayoutParams has a few inner attributes which could not be modify outside, we provide a new instance here
    container.addView(holder.itemView, new ViewPager.LayoutParams());

    return holder;
}

From source file:com.momock.binder.container.ViewPagerBinder.java

public void onBind(final ViewPager view, final IDataList<?> dataSource) {
    if (view != null) {
        if (refIndicator != null && refIndicator.get() != null) {
            refIndicator.get().setCount(dataSource.getItemCount());
        }//from   w  w  w  . ja  va  2 s.co  m
        view.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                position = adapter instanceof IRoundAdapter
                        ? ((IRoundAdapter) adapter).getRealPosition(position)
                        : position;
                Object item = dataSource.getItem(position);
                ItemEventArgs args = new ItemEventArgs(view, position, item);
                itemSelectedEvent.fireEvent(view, args);
                if (refIndicator != null && refIndicator.get() != null) {
                    refIndicator.get().setCurrentIndex(position);
                }
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {
                viewPagerState = state;
            }
        });
        view.setOnTouchListener(new View.OnTouchListener() {
            GestureDetector detector = null;

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                view.getParent().requestDisallowInterceptTouchEvent(true);
                if (detector == null) {
                    detector = new GestureDetector(v.getContext(),
                            new GestureDetector.SimpleOnGestureListener() {

                                @Override
                                public boolean onSingleTapConfirmed(MotionEvent e) {
                                    Object item = dataSource.getItem(adapter instanceof IRoundAdapter
                                            ? ((IRoundAdapter) adapter).getRealPosition(view.getCurrentItem())
                                            : view.getCurrentItem());
                                    ItemEventArgs args = new ItemEventArgs(view, view.getCurrentItem(), item);
                                    itemClickedEvent.fireEvent(view, args);
                                    return true;
                                }

                            });
                }
                return detector.onTouchEvent(event);
            }
        });
        adapter = new PagerAdapter() {
            BlockingQueue<View> savedViews = new LinkedBlockingQueue<View>();

            @Override
            public int getCount() {
                return dataSource.getItemCount();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == ((View) object);
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                View convertView = null;
                if (savedViews.size() > 0) {
                    convertView = savedViews.poll();
                }
                Object item = dataSource.getItem(position);
                if (convertView != null)
                    convertView.setTag(null);
                convertView = itemBinder.onCreateItemView(convertView, item, ViewPagerBinder.this);
                convertView.setTag(item);
                container.addView(convertView, 0);
                return convertView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                savedViews.add((View) object);
                container.removeView((View) object);
            }

            long lastDataSetChangedTick = 0;

            @Override
            public void notifyDataSetChanged() {
                lastDataSetChangedTick = System.nanoTime();
                getDataChangedEvent().fireEvent(this, new EventArgs());
                if (refIndicator != null && refIndicator.get() != null) {
                    refIndicator.get().setCount(dataSource.getItemCount());
                }
                super.notifyDataSetChanged();
                Logger.debug("ViewPagerBinder.PagerAdapter.notifyDataSetChanged");
            }

            long updateTick = 0;

            @Override
            public void startUpdate(ViewGroup container) {
                updateTick = System.nanoTime();
                super.startUpdate(container);
            }

            @Override
            public void setPrimaryItem(ViewGroup container, int position, Object object) {
                super.setPrimaryItem(container, position, object);
            }

            @Override
            public void finishUpdate(ViewGroup container) {
                super.finishUpdate(container);
                if (lastDataSetChangedTick < updateTick)
                    lastDataSetChangedTick = 0;
            }

            @Override
            public int getItemPosition(Object object) {
                return lastDataSetChangedTick == 0 ? PagerAdapter.POSITION_UNCHANGED
                        : PagerAdapter.POSITION_NONE;
            }
        };
        if (round)
            adapter = new RoundPagerAdapter(adapter);
        view.setAdapter(adapter);
        dataSource.addDataChangedHandler(new IEventHandler<DataChangedEventArgs>() {

            @Override
            public void process(Object sender, DataChangedEventArgs args) {
                adapter.notifyDataSetChanged();
            }

        });
        if (round)
            view.setCurrentItem(Math.max(100, dataSource.getItemCount() * 100), false);
    }
}

From source file:com.andybotting.tubechaser.activity.Home.java

/**
 * Make a status window/* ww  w. java  2 s.  c  o  m*/
 */
public void setInfoWindow(View infoView) {

    if (mInfoLoadingView == null) // Landscape orientation
        return;

    ViewGroup homeRoot = (ViewGroup) findViewById(R.id.home_root);

    mInfoWindowView = findViewById(R.id.info_window);
    if (mInfoWindowView != null) {
        homeRoot.removeView(mInfoWindowView);
        mInfoWindowView = null;
    }

    mInfoWindowView = infoView;

    homeRoot.addView(infoView, new LayoutParams(LayoutParams.FILL_PARENT,
            (int) getResources().getDimension(R.dimen.info_window_height)));

    mInfoLoadingView.setVisibility(View.GONE);
    mInfoWindowView.setVisibility(View.VISIBLE);
}

From source file:com.github.jorgecastillo.FillableLoader.java

/**
 * Constructor for the {@link FillableLoaderBuilder} class.
 *///  w  w w.  j  ava  2 s . c  o  m
FillableLoader(ViewGroup parent, ViewGroup.LayoutParams params, int strokeColor, int fillColor, int strokeWidth,
        int originalWidth, int originalHeight, int strokeDrawingDuration, int fillDuration,
        ClippingTransform transform, String svgPath) {

    super(parent.getContext());

    this.strokeColor = strokeColor;
    this.fillColor = fillColor;
    this.strokeWidth = strokeWidth;
    this.strokeDrawingDuration = strokeDrawingDuration;
    this.fillDuration = fillDuration;
    this.clippingTransform = transform;
    this.originalWidth = originalWidth;
    this.originalHeight = originalHeight;
    this.svgPath = svgPath;

    init();
    parent.addView(this, params);
}

From source file:com.giovanniterlingen.windesheim.view.Fragments.WebViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_webview, container, false);

    final WebViewController webViewController = new WebViewController(getActivity());
    this.webView = webViewController.createWebView();
    this.webView.setWebViewClient(new WebViewClient() {
        @Override//from   w  w w . ja  v a  2  s. c  o m
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (isAdded() && !url.contains("elo.windesheim.nl")) {
                webViewController.intentCustomTab(url);
                closeWebView();
                getActivity().onBackPressed();
            }
        }
    });

    Bundle bundle = getArguments();
    this.webView.loadUrl(bundle.getString(KEY_URL));

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    viewGroup.addView(this.webView, layoutParams);

    return viewGroup;
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private void addButton(ViewGroup root, View addMe, boolean landscape) {
    if (landscape)
        root.addView(addMe, 0);
    else// ww w  .j  a v a 2  s  .c  o m
        root.addView(addMe);
}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

private void _showBannerAd_split(String position, String size) {
    if (webView != null) {
        //ViewGroup parentView = (ViewGroup)webView.getParent();//cordova5 build error
        ViewGroup parentView = (ViewGroup) getView(webView);
        if (parentView != null) {
            if (position.equals("top-left") || position.equals("top-center") || position.equals("top-right")
                    || position.equals("left") || position.equals("center") || position.equals("right")) {
                parentView.addView(bannerView, 0);
            } else {
                parentView.addView(bannerView);
            }//from   w w  w .j a  v  a  2  s . c  om
            //parentView.bringToFront();
        }
    }
}