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

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.grottworkshop.gwsmaterialcalendarview.MonthPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    CalendarDay month = getItem(position);
    MonthView monthView = new MonthView(container.getContext(), month, firstDayOfTheWeek);
    monthView.setAlpha(0);//from   w  w  w.ja  v  a  2 s .  c o  m

    monthView.setWeekDayFormatter(weekDayFormatter);
    monthView.setDayFormatter(dayFormatter);
    monthView.setCallbacks(callbacks);
    if (color != null) {
        monthView.setSelectionColor(color);
    }
    if (dateTextAppearance != null) {
        monthView.setDateTextAppearance(dateTextAppearance);
    }
    if (weekDayTextAppearance != null) {
        monthView.setWeekDayTextAppearance(weekDayTextAppearance);
    }
    if (showOtherDates != null) {
        monthView.setShowOtherDates(showOtherDates);
    }
    monthView.setMinimumDate(minDate);
    monthView.setMaximumDate(maxDate);
    monthView.setSelectedDate(selectedDate);

    container.addView(monthView);
    currentViews.add(monthView);

    monthView.setDayViewDecorators(decoratorResults);

    return monthView;
}

From source file:at.jclehner.rxdroid.DrugListActivity.java

@TargetApi(11)
private void setDate(Date date, int flags) {
    if (DEBUG_DATE_MISMATCH)
        Log.d(TAG, "setDate(" + date + ", " + flags + ")");

    if (!mIsShowing) {
        if (LOGV)
            Log.v(TAG, "setDate: activity is not showing; ignoring");
        return;//from w ww .j av a  2  s .  c  o  m
    }

    if (toastIfPastMaxHistoryAge(date))
        return;

    mCurrentDate = date;
    getIntent().putExtra(EXTRA_DATE, date);

    if ((flags & PAGER_INIT) != 0) {
        mOriginalDate = date;
        mSwipeDirection = 0;

        mPager.setOnPageChangeListener(null);
        mPager.removeAllViews();

        final int drugCount = Database.countAll(Drug.class);
        if (drugCount != 0) {
            final boolean smoothScroll = (flags & PAGER_SCROLL) != 0;

            mPager.setAdapter(new InfiniteViewPagerAdapter(this));
            mPager.setCurrentItem(InfiniteViewPagerAdapter.CENTER, smoothScroll);

            mLastPage = InfiniteViewPagerAdapter.CENTER;

            if (drugCount == 1 && !Settings.wasDisplayedOnce("date_swipe")) {
                ShowcaseViewBuilder2 svb = new ShowcaseViewBuilder2(this);
                svb.setText(R.string._help_title_swipe_date, R.string._help_msg_swipe_date);
                svb.setShotType(ShowcaseView.TYPE_ONE_SHOT);
                svb.setShowcaseId(0xdeadbeef + 0);
                svb.setShowcaseItem(ShowcaseView.ITEM_TITLE, 0, this);

                final DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);

                final float w = metrics.widthPixels;
                final float h = metrics.heightPixels;

                final float y = h * 0.6f;

                svb.setAnimatedGesture(-100, y, w, y);

                mShowcaseQueue.add(svb.build());

                svb = new ShowcaseViewBuilder2(this);
                svb.setText(R.string._help_title_edit_drug, R.string._help_msg_edit_drug);
                svb.setShotType(ShowcaseView.TYPE_ONE_SHOT);
                svb.setShowcaseId(0xdeadbeef + 1);
                svb.setShowcaseView(R.id.drug_name, this);

                mShowcaseQueue.add(svb.build());
            } else if (drugCount >= 2 && !Settings.wasDisplayedOnce(Settings.OnceIds.DRAG_DROP_SORTING)) {
                ShowcaseViewBuilder2 svb = new ShowcaseViewBuilder2(this);
                svb.setShowcaseView(R.id.drug_icon, this);
                svb.setText(R.string._help_title_drag_drop_sort, R.string._msg_drag_drop_sorting);
                svb.setShotType(ShowcaseView.TYPE_ONE_SHOT);
                svb.setShowcaseId(0xdeadbeef + 2);
                svb.setRelativeAnimatedGesture(0, 200);

                mShowcaseQueue.add(svb.build());
            }
        } else {
            mPager.setAdapter(new PagerAdapter() {

                @Override
                public boolean isViewFromObject(View v, Object o) {
                    return v == (View) o;
                }

                @Override
                public int getCount() {
                    // TODO Auto-generated method stub
                    return 1;
                }

                @Override
                public Object instantiateItem(ViewGroup container, int position) {
                    final View v = makeView(0);
                    Util.detachFromParent(v);
                    container.addView(v);
                    return v;
                }

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

            mPager.setCurrentItem(0);
            mLastPage = 0;
        }

        mPager.setOnPageChangeListener(mPageListener);
    }

    supportInvalidateOptionsMenu();
    updateDateString();
}

From source file:com.customdatepicker.date.DatePickerDialog.java

@Override
public void onConfigurationChanged(final Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    ViewGroup viewGroup = (ViewGroup) getView();
    if (viewGroup != null) {
        viewGroup.removeAllViewsInLayout();
        View view = onCreateView(getActivity().getLayoutInflater(), viewGroup, null);
        viewGroup.addView(view);
    }//from   w  w  w .  j  a v  a 2s  . co m
}

From source file:com.wagos.calendarcard.RecyclePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);/*  w  ww .  j  a va  2s  . c om*/
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);

        if (convertView != null) {
            // Re-add existing view before rendering so that we can make change inside getView()
            container.addView(convertView);
            convertView = getView(instantiatedItem, convertView, container);
        } else {
            convertView = getView(instantiatedItem, null, container);
            container.addView(convertView);
        }

        // Set another tag id to not break ViewHolder pattern
        convertView.setTag(R.id.view_data, instantiatedItem);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}

From source file:com.brewcrewfoo.performance.fragments.TimeInState.java

private View generateStateRow(CpuState state, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(context);
    LinearLayout view = (LinearLayout) inflater.inflate(R.layout.state_row, parent, false);

    float per = (float) state.duration * 100 / monitor.getTotalStateTime();
    String sPer = (int) per + "%";

    String sFreq;//from w w w.  j  a  v  a 2s  .  c o  m
    if (state.freq == 0) {
        sFreq = getString(R.string.deep_sleep);
    } else {
        sFreq = state.freq / 1000 + " MHz";
    }

    long tSec = state.duration / 100;
    String sDur = toString(tSec);

    TextView freqText = (TextView) view.findViewById(R.id.ui_freq_text);
    TextView durText = (TextView) view.findViewById(R.id.ui_duration_text);
    TextView perText = (TextView) view.findViewById(R.id.ui_percentage_text);
    ProgressBar bar = (ProgressBar) view.findViewById(R.id.ui_bar);

    freqText.setText(sFreq);
    perText.setText(sPer);
    durText.setText(sDur);
    bar.setProgress((int) per);

    parent.addView(view);
    return view;
}

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

public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from  ww  w .j a  v  a 2s. co m
    // TODO: hack to show object history in app feeds
    JSONObject appState = getAppState(context, content);
    if (appState != null) {
        content = appState;
    } else {
        Log.e(TAG, "Missing inner content, probably because of format changes");
    }

    boolean rendered = false;
    AppState ref = new AppState(content);
    String thumbnail = ref.getThumbnailImage();
    if (thumbnail != null) {
        rendered = true;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView);
        frame.addView(imageView);
    }

    thumbnail = ref.getThumbnailText();
    if (thumbnail != null) {
        rendered = true;
        TextView valueTV = new TextView(context);
        valueTV.setText(thumbnail);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }

    thumbnail = ref.getThumbnailHtml();
    if (thumbnail != null) {
        rendered = true;
        WebView webview = new WebView(context);
        webview.loadData(thumbnail, "text/html", "UTF-8");
        webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        Object o = frame.getTag(R.id.object_entry);
        webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o));
        frame.addView(webview);
    }

    if (!rendered) {
        String appName = content.optString(PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Welcome to " + appName + "!";
        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:es.upv.riromu.arbre.main.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Arrays.fill(state, false);/*from w  ww.  j  ava 2s  .  com*/
    Arrays.fill(colours, 255);
    compressRatio = 100;
    // state[TREAT_IMAGE]=false;
    // image = BitmapFactory.decodeResource(getResources(), R.drawable.platanus_hispanica);
    Log.i(TAG, "Trying to load OpenCV library");
    if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback)) {
        Log.e(TAG, "Cannot connect to OpenCV Manager");
    }
    setContentView(R.layout.intro_activity);
    ImageView imv = (ImageView) findViewById(R.id.image_intro);
    imv.setImageDrawable(getResources().getDrawable(R.drawable.platanus_hispanica));
    // create RangeSeekBar as Integer range between 0 and 180
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String rangepreference = (String) sharedPref.getString("rangepreference", "H");

    RangeSeekBar<Integer> seekBar = null;

    if (rangepreference.equals("H"))
        seekBar = new RangeSeekBar<Integer>(Integer.valueOf(sharedPref.getString("minH_preference", "60")),
                Integer.valueOf(sharedPref.getString("maxH_preference", "130")), this);
    if (rangepreference.equals("S"))
        seekBar = new RangeSeekBar<Integer>(Integer.valueOf(sharedPref.getString("minS_preference", "0")),
                Integer.valueOf(sharedPref.getString("maxS_preference", "255")), this);
    if (rangepreference.equals("V"))
        seekBar = new RangeSeekBar<Integer>(Integer.valueOf(sharedPref.getString("minV_preference", "0")),
                Integer.valueOf(sharedPref.getString("maxV_preference", "255")), this);

    //RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(MIN_TH, MAX_TH, this);
    seekBar.setId(R.id.rangeseekbar);
    seekBar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
            rangeSeekBarChanged(minValue, maxValue);
        }

    });
    setVisibility();
    // add RangeSeekBar to pre-defined layout
    ViewGroup layout = (ViewGroup) findViewById(R.id.seekbarholder);
    layout.addView(seekBar);
    //locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}

From source file:com.xixicm.de.presentation.view.adapter.SentenceDetailPageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = mInflater.inflate(R.layout.sentence_detail, null);
    final Sentence sentence = mSentences.get(position);
    JSONObject content = sentence.getJsonObjectContent();
    final Checkable checkable = (Checkable) view.findViewById(R.id.content);
    checkable.setChecked(sentence.getIsStar());
    final CheckableImageView favoriteBtn = (CheckableImageView) view.findViewById(R.id.favorite);
    favoriteBtn.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w w .  ja v  a 2s. c o m*/
        public void onClick(View v) {
            checkable.toggle();
            if (mFavoriteClickListener != null) {
                mFavoriteClickListener.onFavoriteClick(sentence, checkable.isChecked());
            }
        }
    });
    ((TextView) view.findViewById(R.id.day)).setText(sentence.getDateline());
    ((TextView) view.findViewById(R.id.en_content)).setText("  " + sentence.getContent());
    ((TextView) view.findViewById(R.id.cn_content)).setText("  " + content.optString("note"));
    loadImg(sentence, (NetworkImageView) view.findViewById(R.id.image));
    container.addView(view);
    return view;
}

From source file:android.support.v7.preference.PreferenceFragmentCompat.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);

    a.recycle();/*from   w w w.  jav  a2s .  c  o  m*/

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:com.pdftron.pdf.controls.UserCropDialogFragment.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (mCurrentJob != null && !mCurrentJob.isDone()) {
        mCurrentJob.cancelRasterizing();
    }// ww w . j  av a2 s. c o m

    mCurrentJob = null;

    //        if (mCropImageView.hasBitmap()) {
    //            updatePageCropFromImageView(mPageProperties[mCurrentPage], mCropImageView.getCropRectPercentageMargins());
    //            Bitmap bitmap = mCropImageView.getImageBitmapAndClear();
    //        }

    mImageCache.evictAll();

    if (mSpinnerAlphaAnimation != null && !mSpinnerAlphaAnimation.hasEnded()) {
        mSpinnerAlphaAnimation.cancel();
    }
    if (mDisablingOverlayShowing) {
        mDisablingOverlay.setVisibility(View.VISIBLE);
    }
    if (mSpinnerShowing) {
        mProgressBarHost.setVisibility(View.VISIBLE);
    }

    ViewGroup viewGroup = (ViewGroup) getView();
    viewGroup.removeAllViewsInLayout();
    View view = onCreateView(getActivity().getLayoutInflater(), viewGroup, null);
    viewGroup.addView(view);

}