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:de.jadehs.jadehsnavigator.adapter.VPlanPagerAdapter.java

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

    LayoutInflater layoutInflater = (LayoutInflater) this.context
            .getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View view = null;//from ww  w.  j  a va  2  s.  c o m

    final ArrayList<VPlanItem> vPlanItemsWeekday = new ArrayList<VPlanItem>();

    if (getPageTitle(position).equals(context.getString(R.string.strWeekdayMonday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdayMonday)))
                vPlanItemsWeekday.add(item);
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.strWeekdayTuesday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdayTuesday)))
                vPlanItemsWeekday.add(item);
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.strWeekdayWednesday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdayWednesday)))
                vPlanItemsWeekday.add(item);
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.strWeekdayThursday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdayThursday)))
                vPlanItemsWeekday.add(item);
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.strWeekdayFriday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdayFriday)))
                vPlanItemsWeekday.add(item);
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.strWeekdaySaturday))) {
        for (VPlanItem item : this.vPlanItems) {
            if (item.getDayOfWeek().equals(context.getString(R.string.strWeekdaySaturday)))
                vPlanItemsWeekday.add(item);
        }
    }

    /*
    Innheralb des Tabs wird zunaechst die Listview erstellt.
    Die Listviewitems werden dann mit Hilfe des VPlanAdapters erstellt.
     */
    view = layoutInflater.inflate(R.layout.vplan_list, container, false);
    container.addView(view);

    ListView lv = (ListView) view.findViewById(R.id.list_studiengang);
    TextView lastUpdateVPlan = (TextView) view.findViewById(R.id.textViewFooter);

    if (!isCustomVPlanShown)
        lastUpdateVPlan.setText(
                "Plan fr KW: " + this.kw + "  |  Abgerufen am: " + calendarHelper.getDateRightNow(true));
    else
        lastUpdateVPlan.setText(context.getString(R.string.custom_vplan));

    final VPlanAdapter vPlanAdapter = new VPlanAdapter(context, vPlanItemsWeekday, isCustomVPlanShown);

    lv.setAdapter(vPlanAdapter);
    lv.setLongClickable(true);

    /*
    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        Integer realPosition = (Integer) view.getTag();
        Log.wtf(TAG, "POSITION: " + position);
        Log.wtf(TAG, "ID: " + id);
        Log.wtf(TAG, "REAL POSITION: " + (Integer) view.getTag());
            
        if (!isCustomVPlanShown) {
            try {
                // in normal vplan
                VPlanItem vPlanItem = vPlanItemsWeekday.get(position);
            
                if(!parent.getChildAt(position).isActivated()){
                    // item has already been deleted, reverse decision?
                    CustomVPlanDataSource customVPlanDataSource = new CustomVPlanDataSource(context);
                    customVPlanDataSource.open();
            
                    customVPlanDataSource.createCustomVPlanItem(vPlanItem);
                    customVPlanDataSource.close();
            
                    parent.getChildAt(position).setActivated(true);
            
                    parent.getChildAt(position).setBackgroundResource(R.color.jadehs_grey_muffled);
                    Toast.makeText(context, context.getString(R.string.added_to_vplan), Toast.LENGTH_LONG).show();
                }else{
                    // item has not been touched yet, delete it
                    CustomVPlanDataSource customVPlanDataSource = new CustomVPlanDataSource(context);
                    customVPlanDataSource.open();
            
                    // remove from custom vplan
                    customVPlanDataSource.deleteCustomVPlanItem(vPlanItem);
                    customVPlanDataSource.close();
            
                    parent.getChildAt(position).setActivated(false);
            
                    parent.getChildAt(position).setBackgroundResource(R.color.white);
                    Toast.makeText(context, context.getString(R.string.removed_from_vplan), Toast.LENGTH_LONG).show();
                }
            } catch (Exception ex) {
                Log.wtf(TAG, "Err", ex);
            }
        } else {
            try {
                // in custom vplan
                VPlanItem vPlanItem = vPlanItemsWeekday.get(position);
            
                if(!parent.getChildAt(position).isActivated()){
                    // item has not been touched yet, delete it
                    CustomVPlanDataSource customVPlanDataSource = new CustomVPlanDataSource(context);
                    customVPlanDataSource.open();
            
                    // remove from custom vplan
                    customVPlanDataSource.deleteCustomVPlanItem(vPlanItem);
                    customVPlanDataSource.close();
            
                    parent.getChildAt(position).setActivated(true);
            
                    parent.getChildAt(position).setBackgroundResource(R.color.jadehs_grey_muffled);
                    Toast.makeText(context, context.getString(R.string.removed_from_vplan), Toast.LENGTH_LONG).show();
                }else{
                    // item has already been deleted, reverse decision?
                    CustomVPlanDataSource customVPlanDataSource = new CustomVPlanDataSource(context);
                    customVPlanDataSource.open();
            
                    customVPlanDataSource.createCustomVPlanItem(vPlanItem);
                    customVPlanDataSource.close();
            
                    parent.getChildAt(position).setActivated(false);
            
                    parent.getChildAt(position).setBackgroundResource(R.color.white);
                    Toast.makeText(context, context.getString(R.string.added_to_vplan), Toast.LENGTH_LONG).show();
                }
            } catch (Exception ex) {
                Log.wtf(TAG, "Err", ex);
            }
        }
        return true;
    }
    });*/

    return view;
}

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

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    int availIndex = mWebViewRepository.pop();
    ReflowWebView webView = mWebViewRepository.getWebView(availIndex);
    if (webView == null) {
        AnalyticsHandlerAdapter.getInstance()
                .sendException(new Exception("Reflow: there is no available WebView in repository"));
        Log.e(TAG, "there is no available WebView in repository");
        return null;
    }/*from   w ww  .j  a va 2  s  .c o  m*/
    webView.loadUrl("about:blank");

    int pagePosition = mIsRtlMode ? mPageCount - 1 - position : position;

    boolean need_load_flag = true;
    String filename = mReflowFiles.get(pagePosition);
    if (filename != null) {
        File file = new File(filename);
        if (file.exists()) {
            need_load_flag = false;
            if (DEBUG)
                Log.d(TAG, "the file at page #" + (position + 1) + " already received");
            webView.loadUrl("file:///" + filename);
            setTextZoom(webView);
        }
    }

    if (need_load_flag) {
        webView.loadUrl(mLoadingFile);
        try {
            // request for reflow output
            if (DEBUG)
                Log.d(TAG, "request for page #" + (pagePosition + 1));
            Page page = mDoc.getPage(pagePosition + 1);
            ReflowProcessor.getReflow(page, mRequestHandler, position);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    FrameLayout layout = new FrameLayout(mContext);
    FrameLayout parent = (FrameLayout) webView.getParent();
    if (parent != null) {
        // note that we share WebViews,
        // so before adding a WebView make sure it's not a child of any layout
        parent.removeAllViews();
    }
    layout.addView(webView);
    mViewHolders.put(position, layout);
    mViewIndexes.put(position, new Integer(availIndex));
    container.addView(layout);
    return layout;
}

From source file:com.example.RITW.proximity.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    //final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        //   mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);/*from  w  w w  .j  a v a  2 s .  c  om*/
        //   mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    /*mcpItem.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(final View v) {
    Intent action = mcpIntent;
    if (mcpInfo == null)
       action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
    action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    try {
       startActivity(action);
    } catch (final ActivityNotFoundException e) {
       Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show();
    }
    mDrawerLayout.closeDrawers();
       }
    });*/

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

From source file:com.uzmap.pkg.uzmodules.photoBrowser.ImageBrowserAdapter.java

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

    mViewContainer = container;//from  w w w .j  ava  2 s . co  m

    int item_view_id = UZResourcesIDFinder.getResLayoutID("photo_browser_item_layout");
    View itemView = View.inflate(mContext, item_view_id, null);

    itemView.setTag(position);

    int photo_view_id = UZResourcesIDFinder.getResIdID("photoView");
    final PhotoView imageView = (PhotoView) itemView.findViewById(photo_view_id);

    imageView.setZoomable(this.zoomEnable);

    int load_progress_id = UZResourcesIDFinder.getResIdID("loadProgress");
    final ProgressBar progress = (ProgressBar) itemView.findViewById(load_progress_id);
    progress.setTag(position);

    mImageLoader.load(imageView, progress, mImagePaths.get(position));

    mImageLoader.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(ProgressBar bar) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_LOADSUCCESSED, (Integer) bar.getTag());
        }

        @Override
        public void onLoadFailed(final ProgressBar bar) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_LOADFAILED, (Integer) bar.getTag());
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    bar.setVisibility(View.GONE);
                }
            });
        }
    });

    imageView.setOnViewTapListener(new OnViewTapListener() {

        @Override
        public void onViewTap(View arg0, float arg1, float arg2) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_CLICK, position);
        }
    });

    imageView.setOnPhotoTapListener(new OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View arg0, float arg1, float arg2) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_CLICK, position);
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_CLICK, position);
        }
    });

    imageView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_LONG_CLICK, position);
            return false;
        }
    });

    container.addView(itemView);
    return itemView;
}

From source file:com.buddi.client.dfu.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);// w w  w .j  av  a  2 s .co m
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            try {
                startActivity(action);
            } catch (final ActivityNotFoundException e) {
                Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show();
            }
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.DayPickerPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Log.i("TAG", "rangeHashMapdddffff=" + rangeHashMap);

    final View itemView = mInflater.inflate(mLayoutResId, container, false);
    Log.i("TAG", "instantiateItem");
    final SimpleMonthView v = (SimpleMonthView) itemView.findViewById(mCalendarViewId);
    v.setOnRangeClickListener(this);
    v.setOnDayClickListener(mOnDayClickListener);
    v.setMonthTextAppearance(mMonthTextAppearance);
    v.setDayOfWeekTextAppearance(mDayOfWeekTextAppearance);
    v.setDayTextAppearance(mDayTextAppearance);

    if (mDaySelectorColor != null) {
        v.setDaySelectorColor(mDaySelectorColor);
    }/*  w w  w  .  j ava  2  s  .c o  m*/

    if (mDayHighlightColor != null) {
        v.setDayHighlightColor(mDayHighlightColor);
    }

    if (mCalendarTextColor != null) {
        v.setMonthTextColor(mCalendarTextColor);
        v.setDayOfWeekTextColor(mCalendarTextColor);
        v.setDayTextColor(mCalendarTextColor);
    }

    final int month = getMonthForPosition(position);
    final int year = getYearForPosition(position);
    final int[] selectedDay = resolveSelectedDayBasedOnType(month, year);

    final int enabledDayRangeStart;
    if (mMinDate.get(Calendar.MONTH) == month && mMinDate.get(Calendar.YEAR) == year) {
        enabledDayRangeStart = mMinDate.get(Calendar.DAY_OF_MONTH);
    } else {
        enabledDayRangeStart = 1;
    }

    final int enabledDayRangeEnd;
    if (mMaxDate.get(Calendar.MONTH) == month && mMaxDate.get(Calendar.YEAR) == year) {
        enabledDayRangeEnd = mMaxDate.get(Calendar.DAY_OF_MONTH);
    } else {
        enabledDayRangeEnd = 31;
    }

    if (Config.DEBUG) {
        Log.i(TAG, "mSelectedDay.getType(): " + (mSelectedDay != null ? mSelectedDay.getType() : null));
    }
    v.setMonthParams(month, year, mFirstDayOfWeek, enabledDayRangeStart, enabledDayRangeEnd, selectedDay[0],
            selectedDay[1], mSelectedDay != null ? mSelectedDay.getType() : null, true, position);

    final ViewHolder holder = new ViewHolder(position, itemView, v);
    mItems.put(position, holder);
    container.addView(itemView);
    if (dateList(month + 1) != null) {
        v.setCalendar(dateList(month + 1), isFill);
    }
    return holder;
}

From source file:com.grokkingandroid.sampleapp.samples.about.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Resources res = getResources();
    if (getArguments() == null) {
        throw new IllegalStateException("Arguments bundle must not be empty");
    }//  w  w w  .  java2 s . c om
    int[] resIds = getArguments().getIntArray(KEY_RESOURCE_IDS);
    getDialog().setTitle(res.getString(R.string.about));
    View view = inflater.inflate(R.layout.fragment_about, container, false);
    ViewGroup libParent = (ViewGroup) view.findViewById(R.id.about_container);

    String[] libTitles = null;
    String[] libDescriptions = null;
    if (resIds[0] != -1) {
        libTitles = res.getStringArray(resIds[0]);
        libDescriptions = res.getStringArray(resIds[1]);
    }
    if (getArguments().getBoolean(KEY_ADD_DEFAULT_LIBS, true)) {
        if (resIds[0] == -1) {
            libTitles = res.getStringArray(R.array.grokkingandroidsample_about_titles);
            libDescriptions = res.getStringArray(R.array.grokkingandroidsample_about_contents);
        } else {
            String[] defaultTitles = res.getStringArray(R.array.grokkingandroidsample_about_titles);
            String[] target = new String[defaultTitles.length + libTitles.length];
            System.arraycopy(libTitles, 0, target, 0, libTitles.length);
            System.arraycopy(defaultTitles, 0, target, libTitles.length, defaultTitles.length);
            libTitles = target;
            String[] defaultDescriptions = res.getStringArray(R.array.grokkingandroidsample_about_contents);
            target = new String[defaultDescriptions.length + libTitles.length];
            System.arraycopy(libDescriptions, 0, target, 0, libDescriptions.length);
            System.arraycopy(defaultDescriptions, 0, target, libDescriptions.length,
                    defaultDescriptions.length);
            libDescriptions = target;
        }
    }
    String libraryPlural = res.getQuantityString(R.plurals.plural_libraries, libTitles.length);
    String appTitle = res.getString(resIds[3]);
    String copyrightYear = res.getString(resIds[4]);
    String repositoryLink = res.getString(resIds[5]);
    String aboutText = res.getString(resIds[2], appTitle, copyrightYear, repositoryLink, libraryPlural);
    Spanned spannedAboutText = Html.fromHtml(aboutText);
    TextView aboutTv = (TextView) libParent.findViewById(R.id.about_text);
    aboutTv.setText(spannedAboutText);
    aboutTv.setMovementMethod(LinkMovementMethod.getInstance());

    if (libTitles != null) {
        for (int i = 0; i < libTitles.length; i++) {
            View libContainer = inflater.inflate(R.layout.single_library_layout, libParent, false);
            TextView currLibTitle = (TextView) libContainer.findViewById(R.id.library_title);
            currLibTitle.setText(libTitles[i]);
            TextView currLibDesc = (TextView) libContainer.findViewById(R.id.library_text);
            Spanned spanned = Html.fromHtml(libDescriptions[i]);
            currLibDesc.setText(spanned);
            currLibDesc.setMovementMethod(LinkMovementMethod.getInstance());
            libParent.addView(libContainer);
        }
    }
    return view;
}

From source file:com.mastercard.masterpasswallet.adapters.CardPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Card card = mCards.get(position);

    View view = LayoutInflater.from(mContext).inflate(R.layout.partial_payment_card, null);
    ImageView cardImage = (ImageView) view.findViewById(R.id.img_card);
    cardImage.setImageResource(card.getCardImageFull());
    TextView cardPan = (TextView) view.findViewById(R.id.txt_card_pan);
    cardPan.setText(mContext.getString(R.string.masked_pan, " " + card.getPANEnding()));

    TextView cardName = (TextView) view.findViewById(R.id.txt_card_name);
    cardName.setText(card.getCardName());
    cardName.setVisibility(View.VISIBLE);

    // Show/hide overlay to indicate if card is suspended or not
    View inactiveOverlay = view.findViewById(R.id.img_overlay);
    if (card.IsActive()) {
        inactiveOverlay.setVisibility(View.GONE);
    } else {//from   ww w. ja  va 2s .  c o  m
        inactiveOverlay.setVisibility(View.VISIBLE);
    }

    // Set actions
    if (mListener != null) {
        // Configure card info action
        ImageView imgInfo = (ImageView) view.findViewById(R.id.img_info);
        imgInfo.setVisibility(View.VISIBLE);
        imgInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.showCardInfo(card);
            }
        });

        // Configure making card default
        ImageView imgDefaultCard = (ImageView) view.findViewById(R.id.img_default_card);
        imgDefaultCard.setVisibility(View.VISIBLE);
        if (card.isDefault(PaymentContext.CONTACTLESS)) {
            imgDefaultCard.setImageResource(R.drawable.ic_favourite_selected);
        } else {
            imgDefaultCard.setImageResource(R.drawable.ic_favourite_deselected);
        }
        imgDefaultCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.makeDefaultcard(card);
            }
        });

    }

    // Configure card balance
    View layBalance = view.findViewById(R.id.lay_balance);
    layBalance.setVisibility(View.VISIBLE);

    TextView txtBalanceType = (TextView) view.findViewById(R.id.tvBalanceType);
    TextView txtBalance = (TextView) view.findViewById(R.id.tvBalance);
    if (card.isCreditCard()) {
        txtBalanceType.setText("Current Balance:");
    } else {
        txtBalanceType.setText("Available Balance:");
    }
    DecimalFormat decimalFormat = new DecimalFormat("$##,##0.00");
    String amount = decimalFormat.format(card.getCardBalance() / 100f);
    txtBalance.setText(amount);

    // Add the layout to the container
    container.addView(view);
    return view;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *//*from   www . java2  s  .c  o m*/
private void onSessionQueryComplete(Cursor cursor) {
    mSessionCursor = true;
    if (!cursor.moveToFirst()) {
        if (isAdded()) {
            // TODO: Remove this in favor of a callbacks interface that the activity
            // can implement.
            getActivity().finish();
        }
        return;
    }

    mTitleString = cursor.getString(SessionsQuery.TITLE);

    // Format time block this session occupies
    mType = cursor.getString(SessionsQuery.TYPE);
    mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START);
    mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
    String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
    final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd,
            roomName, mBuffer, getActivity());

    mTitle.setText(mTitleString);

    mUrl = cursor.getString(SessionsQuery.URL);
    if (TextUtils.isEmpty(mUrl)) {
        mUrl = "";
    }

    mHashtags = cursor.getString(SessionsQuery.HASHTAGS);
    if (!TextUtils.isEmpty(mHashtags)) {
        enableSocialStreamMenuItemDeferred();
    }

    mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

    setupShareMenuItemDeferred();
    showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false);

    final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
    if (!TextUtils.isEmpty(sessionAbstract)) {
        UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
        mAbstract.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        mAbstract.setVisibility(View.GONE);
    }

    final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
    final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
    if (!TextUtils.isEmpty(sessionRequirements)) {
        UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
        requirementsBlock.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        requirementsBlock.setVisibility(View.GONE);
    }

    // Show empty message when all data is loaded, and nothing to show
    if (mSpeakersCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }

    // Compile list of links (submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    final Context context = mRootView.getContext();

    List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>();

    // Add session feedback link
    if (getResources().getBoolean(R.bool.has_session_feedback_enabled)) {
        links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink,
                new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class)));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(context);
        int columns = context.getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Intent> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    try {
                        startActivity(link.second);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.GONE);
    }

    // Show past/present/future and livestream status for this block.
    UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle);

    LOGD("Tracker", "Session: " + mTitleString);
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testSetSelectedPositionDetached() throws Throwable {

    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.horizontal_linear);
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 50);
    initActivity(intent);/*from  w w w  .  j  av a2  s  .  co  m*/
    mOrientation = BaseGridView.HORIZONTAL;
    mNumRows = 1;

    final int focusToIndex = 49;
    final ViewGroup parent = (ViewGroup) mGridView.getParent();
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.removeView(mGridView);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            mGridView.setSelectedPositionSmooth(focusToIndex);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.addView(mGridView);
            mGridView.requestFocus();
        }
    });
    waitForTransientStateGone(null);
    waitForScrollIdle();
    assertEquals(mGridView.getSelectedPosition(), focusToIndex);
    assertTrue(mGridView.getLayoutManager().findViewByPosition(focusToIndex).hasFocus());

    final int focusToIndex2 = 0;
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.removeView(mGridView);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            mGridView.setSelectedPosition(focusToIndex2);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.addView(mGridView);
            mGridView.requestFocus();
        }
    });
    assertEquals(mGridView.getSelectedPosition(), focusToIndex2);
    waitForTransientStateGone(null);
    waitForScrollIdle();
    assertTrue(mGridView.getLayoutManager().findViewByPosition(focusToIndex2).hasFocus());
}