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.wayhua.framework.adapter.WelcomePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View v = LayoutInflater.from(container.getContext()).inflate(view, container, false);

    TextView titleText = ((TextView) v.findViewById(R.id.tv_title));
    TextView infoText = ((TextView) v.findViewById(R.id.tv_info));
    titleText.setText(titles[position]);
    infoText.setText(info[position]);// w  ww .ja va  2  s . com
    if (position == 0) {
        @ColorInt
        int primaryColor = titleText.getResources().getColor(R.color.colorPrimary);
        titleText.setTextColor(primaryColor);
        infoText.setTextColor(primaryColor);
    }
    ImageView imageView = (ImageView) v.findViewById(R.id.iv_art);
    //.setImageResource(images[position]);
    Glide.with(context).load(images[position]).into(imageView);
    container.addView(v);
    return v;
}

From source file:com.bowyoung.enhancelibrary.libs.swipeback.SwipeBackLayout.java

public void attachToActivity(BaseEnhanceActivity activity) {
    mActivity = activity;/*from   w  ww . j ava  2 s . c o  m*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.finlay.geomonsters.battle.ChooseCreatureDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Get the first six creatures of user
    ArrayList<Creature> creatures = ResourceManager.getUserCreatures(getResources(), 6);

    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // View// w w w. j  a va2s  .c  om
    View contentView = inflater.inflate(R.layout.change_geomonster, null);
    ViewGroup view = (ViewGroup) contentView.findViewById(R.id.ChangeGeomonsterLayout);

    // Add a button for every creature (max of 6)
    Button button;
    for (Creature creature : creatures) {
        button = new Button(contentView.getContext());
        button.setText(creature.getNickName());

        // Can't reselect same creature
        if (creature.getNickName().equals(_currentCreature)) {
            //TODO: Make current more visible
            button.setTextColor(Color.WHITE);
        }

        //TODO: Use better button styles. Change bg colour depending on hp
        button.setBackgroundColor(Color.GREEN);
        button.setOnClickListener(new MyButtonClickListener());
        view.addView(button);
    }

    // Set layout for dialog
    builder.setView(contentView).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    return builder.create();
}

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

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from w ww  . j  a  v  a2  s  .c  om*/
    TextView valueTV = new TextView(context);
    String title;
    if (content.has(TITLE)) {
        title = "Link: " + content.optString(TITLE);
    } else {
        title = content.optString(URI);
    }
    valueTV.setText(title);
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    if (Linkify.addLinks(valueTV, Linkify.ALL)) {
        if (!allowInteractions)
            valueTV.setMovementMethod(null);
    }

    frame.addView(valueTV);
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView, final int x) {
    final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
    final CharSequence debugInfo = debugInfoView.getText();
    if (debugInfo == null) {
        return;/* w w w  .j  a  va2  s.c  o  m*/
    }
    placerView.addView(debugInfoView);
    debugInfoView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int infoWidth = debugInfoView.getMeasuredWidth();
    final int y = debugInfoView.getMeasuredHeight();
    ViewLayoutUtils.placeViewAt(debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}

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

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from   ww  w .  j a  va  2  s.  c  o m*/
    byte[] raw = obj.getRaw();
    if (raw == null) {
        Pair<JSONObject, byte[]> p = splitRaw(content);
        content = p.first;
        raw = p.second;
    }
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    imageView.setImageBitmap(BitmapFactory.decodeByteArray(raw, 0, raw.length));
    //        App.instance().objectImages.lazyLoadImage(raw.hashCode(), raw, imageView);
    frame.addView(imageView);
}

From source file:com.phonemetra.turbo.keyboard.emoji.EmojiPalettesAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {

    final EmojiPageKeyboardView oldKeyboardView = mActiveKeyboardViews.get(position);
    if (oldKeyboardView != null) {
        oldKeyboardView.deallocateMemory();
        // This may be redundant but wanted to be safer..
        mActiveKeyboardViews.remove(position);
    }/* ww w  . j a v a 2s.  c o  m*/
    final Keyboard keyboard = mEmojiCategory.getKeyboardFromPagePosition(position);
    final LayoutInflater inflater = LayoutInflater.from(container.getContext());
    final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView) inflater
            .inflate(R.layout.emoji_keyboard_page, container, false /* attachToRoot */);
    keyboardView.setKeyboard(keyboard);
    keyboardView.setOnKeyEventListener(mListener);
    container.addView(keyboardView);
    mActiveKeyboardViews.put(position, keyboardView);
    return keyboardView;
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.wizard.ChangePictureActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;//from   w ww  .j a va2  s. com
    }

    findViewById(R.id.btn_broadcast).setVisibility(View.GONE);
    mContactId = getIntent().getLongExtra("contact_id", -1);
    if (mContactId == -1) {
        Uri data = getIntent().getData();
        if (data != null) {
            try {
                mContactId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
            }
        }
    }

    Bundle args = new Bundle();
    args.putLong("contact_id", mContactId);
    Fragment profileFragment = new ViewProfileFragment();
    profileFragment.setArguments(args);

    doTitleBar(this, "My Profile");
    mLabels.add("View");
    mLabels.add("Edit");
    mFragments.add(profileFragment);
    mFragments.add(new EditProfileFragment());

    Uri privateUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/private");
    mLabels.add("Notes");
    Fragment feedView = new FeedViewFragment();
    args = new Bundle(args);
    args.putParcelable(FeedViewFragment.ARG_FEED_URI, privateUri);
    feedView.setArguments(args);
    //mFragments.add(feedView);

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(this);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (String s : mLabels) {
        Button button = new Button(this);
        button.setText(s);
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    // Listen for future changes
    Uri feedUri;
    if (mContactId == Contact.MY_ID) {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    } else {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    }
    mProfileContentObserver = new ProfileContentObserver(mHandler);
    getContentResolver().registerContentObserver(feedUri, true, mProfileContentObserver);

    onPageSelected(0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Click on the avatar to take a profile picture of yourself.").setCancelable(false)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:fr.gotorennes.AbstractMapActivity.java

@Override
protected void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
    LocationUtils.activeLocation(this);

    ViewGroup layout = (ViewGroup) findViewById(R.id.adLayout);
    if (layout != null && adView == null) {
        adView = new AdView(this, AdSize.BANNER, "ca-app-pub-5396385527314971/1328911094");
        layout.addView(adView);
    }//from w  ww .  j a v a2  s .c o  m

    if (adView != null) {
        AdRequest adRequest = new AdRequest();
        adRequest.setLocation(LocationUtils.getLocation(this));
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        adRequest.addTestDevice("8A95E7269CA459C74F63A410B14D6444");
        adView.loadAd(adRequest);
    }
}

From source file:com.example.mego.adas.main.adapter.HelpPageViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);

    int resId = 0;
    //set the help photo with current position
    ImageView imageView = itemView.findViewById(R.id.imageView);
    switch (position) {
    case 0:/*from   w w  w  .ja  v  a 2 s. c  o  m*/
        resId = R.drawable.help_start;
        break;
    case 1:
        resId = R.drawable.car_help_zero;
        break;
    case 2:
        resId = R.drawable.car_help_one;
        break;
    case 3:
        resId = R.drawable.car_help_two;
        break;
    case 4:
        resId = R.drawable.car_help_three;
        break;
    case 5:
        resId = R.drawable.car_help_four;
        break;
    }
    imageView.setImageResource(resId);

    container.addView(itemView);

    return itemView;
}