Example usage for android.widget ProgressBar setMax

List of usage examples for android.widget ProgressBar setMax

Introduction

In this page you can find the example usage for android.widget ProgressBar setMax.

Prototype

@android.view.RemotableViewMethod
public synchronized void setMax(int max) 

Source Link

Document

Set the upper range of the progress bar max.

Usage

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Sets the range of a ProgressBar to 0...max.
 * //from w ww. j  a va  2  s .  c  o m
 * @param viewId
 *            The view id.
 * @param max
 *            The max value of a ProgressBar.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setMax(int viewId, int max) {
    ProgressBar view = retrieveView(viewId);
    view.setMax(max);
    return this;
}

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Sets the progress and max of a ProgressBar.
 * /*from w  w  w  .ja  va 2s.com*/
 * @param viewId
 *            The view id.
 * @param progress
 *            The progress.
 * @param max
 *            The max value of a ProgressBar.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setProgress(int viewId, int progress, int max) {
    ProgressBar view = retrieveView(viewId);
    view.setMax(max);
    view.setProgress(progress);
    return this;
}

From source file:org.kegbot.app.HomeActivity.java

@Subscribe
public void onVisibleTapListUpdate(VisibleTapsChangedEvent event) {
    assert (Looper.myLooper() == Looper.getMainLooper());
    Log.d(LOG_TAG, "Got tap list change event: " + event + " taps=" + event.getTaps().size());

    final List<KegTap> newTapList = event.getTaps();
    synchronized (mTapsLock) {
        if (newTapList.equals(mTaps)) {
            Log.d(LOG_TAG, "Tap list unchanged.");
            return;
        }// w  ww . jav  a 2 s  .c  om

        mTaps.clear();
        mTaps.addAll(newTapList);
        mTapStatusAdapter.notifyDataSetChanged();
    }

    //for progress bar
    if (mTaps.size() > 0) {
        final KegTap tap = mTaps.get(mTapStatusPager.getCurrentItem());
        if (tap.hasCurrentKeg()) {
            final Models.Keg keg = tap.getCurrentKeg();
            double remainml = keg.getRemainingVolumeMl();
            double totalml = keg.getFullVolumeMl();
            double percent = (remainml) / (totalml) * 100;

            final ProgressBar mTapProgress = (ProgressBar) findViewById(R.id.tapProgress);
            mTapProgress.setMax((int) totalml);
            mTapProgress.setProgress((int) remainml);

            final TextView mTapPercentage = (TextView) findViewById(R.id.tapPercentage);
            mTapPercentage.setText(String.format("%.2f", percent) + "%");
        }
    }

    maybeShowTapWarnings();
}

From source file:com.money.manager.ex.fragment.HomeFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    MainActivity mainActivity = null;//from   w  ww. j  ava 2 s . c  o m
    if (getActivity() != null && getActivity() instanceof MainActivity)
        mainActivity = (MainActivity) getActivity();

    switch (loader.getId()) {
    case ID_LOADER_USER_NAME:
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                String infoValue = data.getString(data.getColumnIndex(infoTable.INFONAME));
                // save into preferences username and basecurrency id
                if (Constants.INFOTABLE_USERNAME.equalsIgnoreCase(infoValue)) {
                    application.setUserName(data.getString(data.getColumnIndex(infoTable.INFOVALUE)));
                } else if (Constants.INFOTABLE_BASECURRENCYID.equalsIgnoreCase(infoValue)) {
                    //application.setBaseCurrencyId(data.getInt(data.getColumnIndex(infoTable.INFOVALUE)));
                }
                data.moveToNext();
            }
        }
        // show username
        if (!TextUtils.isEmpty(application.getUserName()))
            ((SherlockFragmentActivity) getActivity()).getSupportActionBar()
                    .setSubtitle(application.getUserName());
        // set user name on drawer
        if (mainActivity != null)
            mainActivity.setDrawableUserName(application.getUserName());

        break;

    case ID_LOADER_ACCOUNT_BILLS:
        double curTotal = 0, curReconciled = 0;
        AccountBillsAdapter adapter = null;

        linearHome.setVisibility(data != null && data.getCount() > 0 ? View.VISIBLE : View.GONE);
        linearWelcome.setVisibility(linearHome.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);

        // cycle cursor
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                curTotal += data.getDouble(data.getColumnIndex(QueryAccountBills.TOTALBASECONVRATE));
                curReconciled += data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILEDBASECONVRATE));
                data.moveToNext();
            }
            // create adapter
            adapter = new AccountBillsAdapter(getActivity(), data);
        }
        // write accounts total
        txtTotalAccounts.setText(currencyUtils.getBaseCurrencyFormatted(curTotal));
        // manage footer listview
        if (linearFooter == null) {
            linearFooter = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.item_account_bills,
                    null);
            // textview into layout
            txtFooterSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountTotal);
            txtFooterSummaryReconciled = (TextView) linearFooter
                    .findViewById(R.id.textVievItemAccountTotalReconciled);
            // set text
            TextView txtTextSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountName);
            txtTextSummary.setText(R.string.summary);
            // invisibile image
            ImageView imgSummary = (ImageView) linearFooter.findViewById(R.id.imageViewAccountType);
            imgSummary.setVisibility(View.INVISIBLE);
            // set color textview
            txtTextSummary.setTextColor(Color.GRAY);
            txtFooterSummary.setTextColor(Color.GRAY);
            txtFooterSummaryReconciled.setTextColor(Color.GRAY);
        }
        // remove footer
        lstAccountBills.removeFooterView(linearFooter);
        // set text
        txtFooterSummary.setText(txtTotalAccounts.getText());
        txtFooterSummaryReconciled.setText(currencyUtils.getBaseCurrencyFormatted(curReconciled));
        // add footer
        lstAccountBills.addFooterView(linearFooter, null, false);
        // set adapter and shown
        lstAccountBills.setAdapter(adapter);
        setListViewAccountBillsVisible(true);
        // set total accounts in drawer
        if (mainActivity != null) {
            mainActivity.setDrawableTotalAccounts(txtTotalAccounts.getText().toString());
        }
        break;

    case ID_LOADER_BILL_DEPOSITS:
        mainActivity.setDrawableRepeatingTransactions(data != null ? data.getCount() : 0);
        break;

    case ID_LOADER_INCOME_EXPENSES:
        double income = 0, expenses = 0;
        if (data != null && data.moveToFirst()) {
            while (!data.isAfterLast()) {
                expenses = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Expenses));
                income = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Income));
                //move to next record
                data.moveToNext();
            }
        }
        TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome);
        TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses);
        TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference);
        // set value
        if (txtIncome != null)
            txtIncome.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), income));
        if (txtExpenses != null)
            txtExpenses.setText(
                    currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), Math.abs(expenses)));
        if (txtDifference != null)
            txtDifference.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(),
                    income - Math.abs(expenses)));
        // manage progressbar
        final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome);
        final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses);

        if (barIncome != null && barExpenses != null) {
            barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses)));
            barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses)));

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress",
                        (int) Math.abs(income));
                animationIncome.setDuration(1000); // 0.5 second
                animationIncome.setInterpolator(new DecelerateInterpolator());
                animationIncome.start();

                ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress",
                        (int) Math.abs(expenses));
                animationExpenses.setDuration(1000); // 0.5 second
                animationExpenses.setInterpolator(new DecelerateInterpolator());
                animationExpenses.start();
            } else {
                barIncome.setProgress((int) Math.abs(income));
                barExpenses.setProgress((int) Math.abs(expenses));
            }
        }
    }
}

From source file:org.kegbot.app.HomeActivity.java

@Override
protected void onStart() {
    super.onStart();
    mCore = KegbotCore.getInstance(this);
    mConfig = mCore.getConfiguration();/*from   w w  w.  j  a va2 s .c  o m*/
    maybeShowTapWarnings();

    //for dummy pour status
    final Pair<String, String> qty = Units.localizeWithoutScaling(mCore.getConfiguration(), 0.0);
    mPourVolumeBadge.setBadgeValue(qty.first);
    mPourVolumeBadge.setBadgeCaption("Current " + Units.capitalizeUnits(qty.second) + " Poured");

    mImageView0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ActionBar actionBar = getActionBar();
            if (actionBar.isShowing()) {
                actionBar.hide();
                mConfig.setShowActionBar(false);
            } else {
                actionBar.show();
                mConfig.setShowActionBar(true);
            }
        }
    });

    //for start button
    final Context thisContext = this;
    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mConfig.useAccounts()) {
                final Intent intent = KegtabCommon.getAuthDrinkerActivityIntent(thisContext);
                startActivityForResult(intent, REQUEST_AUTHENTICATE);
            } else {
                mCore.getFlowManager().activateUserAmbiguousTap("");
            }

        }
    });

    mNewDrinkerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Intent intent = KegtabCommon.getCreateDrinkerActivityIntent(thisContext);
            startActivityForResult(intent, REQUEST_CREATE_DRINKER);
        }
    });

    mTapStatusPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

            //for progress bar
            if (mTaps.size() > 0) {
                final KegTap tap = mTaps.get(position);
                if (tap.hasCurrentKeg()) {
                    final Models.Keg keg = tap.getCurrentKeg();
                    double remainml = keg.getRemainingVolumeMl();
                    double totalml = keg.getFullVolumeMl();
                    double percent = (remainml) / (totalml) * 100;

                    final ProgressBar mTapProgress = (ProgressBar) findViewById(R.id.tapProgress);
                    mTapProgress.setMax((int) totalml);
                    mTapProgress.setProgress((int) remainml);

                    final TextView mTapPercentage = (TextView) findViewById(R.id.tapPercentage);
                    mTapPercentage.setText(String.format("%.2f", percent) + "%");
                }
            }

            //for backgrounds
            switch (position) {
            case 0:
                mImageView0.setImageResource(R.drawable.e1);
                mImageView1.setBackgroundResource(R.drawable.e2);
                break;
            case 1:
                mImageView0.setImageResource(R.drawable.a1);
                mImageView1.setBackgroundResource(R.drawable.a2);
                break;
            case 2:
                mImageView0.setImageResource(R.drawable.b1);
                mImageView1.setBackgroundResource(R.drawable.b2);
                break;
            case 3:
                mImageView0.setImageResource(R.drawable.c1);
                mImageView1.setBackgroundResource(R.drawable.c2);
                break;
            case 4:
                mImageView0.setImageResource(R.drawable.d1);
                mImageView1.setBackgroundResource(R.drawable.d2);
                break;
            default:
                mImageView0.setImageResource(R.drawable.e1);
                mImageView1.setBackgroundResource(R.drawable.e2);
                break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}

From source file:org.xbmc.kore.ui.sections.video.TVShowProgressFragment.java

/**
 * Display the seasons list//from  ww w. j  a v  a 2  s  . c  o m
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    TextView seasonsListTitle = (TextView) getActivity().findViewById(R.id.seasons_title);
    GridLayout seasonsList = (GridLayout) getActivity().findViewById(R.id.seasons_list);

    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(itemId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        // Get theme colors
        Resources.Theme theme = getActivity().getTheme();
        TypedArray styledAttributes = theme
                .obtainStyledAttributes(new int[] { R.attr.colorinProgress, R.attr.colorFinished });

        int inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(0),
                resources.getColor(R.color.orange_500));
        int finishedColor = styledAttributes.getColor(styledAttributes.getIndex(1),
                resources.getColor(R.color.green_400));
        styledAttributes.recycle();

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            if (Utils.isLollipopOrLater()) {
                int watchedColor = (numEpisodes - watchedEpisodes == 0) ? finishedColor : inProgressColor;
                seasonProgressBar.setProgressTintList(ColorStateList.valueOf(watchedColor));
            }

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}

From source file:com.eugene.fithealthmaingit.UI.MealView.MealViewFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    // Adapter filtered by Id and because the id is unique, we just call position 0

    TextView mealTime = (TextView) v.findViewById(R.id.mealTime);
    long lStartTime = new Date().getTime();
    long lEndTime = mLogMeal.getDate().getTime();
    long difference = lEndTime - lStartTime;
    int seconds = (int) (difference / 1000) * (-1);
    int minutes = (int) ((difference / (1000 * 60)));
    int min = minutes * -1;
    int hours = (int) ((difference / (1000 * 60 * 60)) % 24);
    int hour = hours * -1;
    if (seconds < 60 && minutes < 60) {
        mealTime.setText("Seconds ago");
    } else if (seconds >= 60 && min < 60 && hour < 1) {
        mealTime.setText(min + "  Minutes Ago");
    } else {/*  ww w.  ja  v a2 s.  c  o  m*/
        mealTime.setText(DateFormat.format("MMM d, h:m a", mLogMeal.getDate()));
    }

    // All TextViews.  Formatted like this because they are extremely local and are not changed after the OnCreate
    ((TextView) v.findViewById(R.id.mMealName)).setText(mLogMeal.getMealName());
    ((TextView) v.findViewById(R.id.servingCOnsumed)).setText(df.format(mLogMeal.getServingSize()));
    ((TextView) v.findViewById(R.id.caloriesNutrition)).setText(df.format(mLogMeal.getCalorieCount()));
    ((TextView) v.findViewById(R.id.fatNutrition)).setText(df.format(mLogMeal.getFatCount()) + " g");
    ((TextView) v.findViewById(R.id.saturatedFat)).setText(df.format(mLogMeal.getSaturatedFat()) + " g");
    ((TextView) v.findViewById(R.id.cholesterol)).setText(df.format(mLogMeal.getCholesterol()) + " mg");
    ((TextView) v.findViewById(R.id.sodium)).setText(df.format(mLogMeal.getSodium()) + " mg");
    ((TextView) v.findViewById(R.id.carbohydratesNutrition)).setText(df.format(mLogMeal.getCarbCount()) + " g");
    ((TextView) v.findViewById(R.id.fiber)).setText(df.format(mLogMeal.getFiber()) + " g");
    ((TextView) v.findViewById(R.id.sugars)).setText(df.format(mLogMeal.getSugars()) + " g");
    ((TextView) v.findViewById(R.id.proteinNutrition)).setText(df.format(mLogMeal.getProteinCount()) + " g");
    ((TextView) v.findViewById(R.id.vitiminA)).setText(df.format(mLogMeal.getVitA()) + "%");
    ((TextView) v.findViewById(R.id.vitiminC)).setText(df.format(mLogMeal.getVitC()) + "%");
    ((TextView) v.findViewById(R.id.calcium)).setText(df.format(mLogMeal.getCalcium()) + "%");
    ((TextView) v.findViewById(R.id.iron)).setText(df.format(mLogMeal.getIron()) + "%");
    // Progress Bars
    ProgressBar mPbCal = (ProgressBar) v.findViewById(R.id.pbCal);
    ProgressBar mPbFat = (ProgressBar) v.findViewById(R.id.pbFat);
    ProgressBar mPbCarb = (ProgressBar) v.findViewById(R.id.pbCarb);
    ProgressBar mPbPro = (ProgressBar) v.findViewById(R.id.pbPro);

    // Saved user information
    double mCalorieGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, ""));
    double mFatGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_FAT, ""));
    double mCarbGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_CARBOHYDRATES, ""));
    double mProteinGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_PROTEIN, ""));

    mPbCal.setMax(Integer.valueOf(dfW.format(mCalorieGoal)));
    mPbCal.setProgress(Integer.valueOf(dfW.format(mLogMeal.getCalorieCount()))
            + Integer.valueOf(dfW.format(mCalorieProgress)));

    mPbFat.setMax(Integer.valueOf(dfW.format(mFatGoal)));
    mPbFat.setProgress(
            Integer.valueOf(dfW.format(mLogMeal.getFatCount())) + Integer.valueOf(dfW.format(mFatProgress)));

    mPbCarb.setMax(Integer.valueOf(dfW.format(mCarbGoal)));
    mPbCarb.setProgress(
            Integer.valueOf(dfW.format(mLogMeal.getCarbCount())) + Integer.valueOf(dfW.format(mCarbProgress)));

    mPbPro.setMax(Integer.valueOf(dfW.format(mProteinGoal)));
    mPbPro.setProgress(Integer.valueOf(dfW.format(mLogMeal.getProteinCount()))
            + Integer.valueOf(dfW.format(mProteinProgress)));

    TextView cRem = (TextView) v.findViewById(R.id.cRem);
    cRem.setText(dfW.format(mLogMeal.getCalorieCount()) + " / " + dfW.format(mCalorieGoal));

    TextView fRem = (TextView) v.findViewById(R.id.fRem);
    fRem.setText(dfW.format(mLogMeal.getFatCount()) + " / " + dfW.format(mFatGoal));

    TextView carRem = (TextView) v.findViewById(R.id.carRem);
    carRem.setText(dfW.format(mLogMeal.getCarbCount()) + " / " + dfW.format(mCarbGoal));

    TextView proRem = (TextView) v.findViewById(R.id.proRem);
    proRem.setText(dfW.format(mLogMeal.getProteinCount()) + " / " + dfW.format(mProteinGoal));
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

public void FitBit(String s) {
    fbCaloriesBurned.setText(s);/*from w w  w .  jav  a2  s.c o m*/
    pbLoad.setVisibility(View.GONE);
    fbRefresh.setVisibility(View.VISIBLE);
    int caloriesBurned = Integer.valueOf(s);
    double mCalorieGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, ""))
            + caloriesBurned;
    fbCaloriesNew.setText("" + df.format(mCalorieGoal));
    fbCaloriesGoal = (TextView) v.findViewById(R.id.fbCaloriesGoalNew);
    fbCaloriesGoal.setText("" + df.format(mCalorieGoal));
    fbCaloriesConsumed = (TextView) v.findViewById(R.id.fbCaloriesConsumed);
    double mAllCaloriesConsumed = 0;
    for (LogMeal logMeal : mLogAdapterAll.getLogs()) {
        mAllCaloriesConsumed += logMeal.getCalorieCount();
    }
    fbCaloriesConsumed.setText(df.format(mAllCaloriesConsumed));
    ProgressBar progressFitbit = (ProgressBar) v.findViewById(R.id.progressFitbit);
    progressFitbit.setMax(Integer.valueOf(df.format(mCalorieGoal)));
    progressFitbit.setProgress(Integer.valueOf(df.format(mAllCaloriesConsumed)));
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

/**
 * Display the seasons list//from   www.  j ava  2s .co m
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(tvshowId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}

From source file:com.giovanniterlingen.windesheim.view.Adapters.NatschoolContentAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    final TextView contentName = holder.contentName;
    final ImageView icon = holder.icon;
    final FrameLayout menuButton = holder.menuButton;
    final ImageView menuButtonImage = holder.menuButtonImage;
    contentName.setText(content.get(position).name);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override//from   www.  jav a 2 s .  co m
        public void onClick(View v) {
            onContentClick(content.get(holder.getAdapterPosition()), holder.getAdapterPosition());
        }
    });
    if (content.get(position).type == -1) {
        icon.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                getDrawableByName(content.get(position).name), null));
        menuButton.setVisibility(View.VISIBLE);
        menuButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                menuButtonImage.setImageDrawable(
                        ResourcesCompat.getDrawable(activity.getResources(), R.drawable.overflow_open, null));
                PopupMenu popupMenu = new PopupMenu(activity, menuButton);
                popupMenu.inflate(R.menu.menu_file);
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        if (item.getItemId() == R.id.delete_file) {
                            showPromptDialog(holder.getAdapterPosition());
                            return true;
                        }
                        return true;
                    }
                });
                popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        menuButtonImage.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                                R.drawable.overflow_normal, null));
                    }
                });
                popupMenu.show();
            }
        });
    } else if (content.get(position).url == null || (content.get(position).url.length() == 0)) {
        if (content.get(position).imageUrl != null) {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_work, null));
        } else {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_folder, null));
        }
    } else {
        if (content.get(position).type == 1 || content.get(position).type == 3
                || content.get(position).type == 11) {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_link, null));
        } else if (content.get(position).type == 10) {
            icon.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                    getDrawableByName(content.get(position).url), null));

            final TextView progressTextView = holder.progressTextView;
            final ProgressBar progressBar = holder.progressBar;
            final FrameLayout cancelButton = holder.cancelButton;

            if (content.get(position).downloading) {
                contentName.setVisibility(View.GONE);
                progressTextView.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.VISIBLE);
                if (content.get(position).progress == -1 && content.get(position).progressString == null) {
                    progressTextView.setText(activity.getResources().getString(R.string.downloading));
                    progressBar.setIndeterminate(true);
                } else {
                    progressTextView.setText(content.get(position).progressString);
                    progressBar.setIndeterminate(false);
                    progressBar.setMax(100);
                    progressBar.setProgress(content.get(position).progress);
                }
                cancelButton.setVisibility(View.VISIBLE);
                cancelButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        NotificationCenter.getInstance().postNotificationName(
                                NotificationCenter.downloadCancelled,
                                content.get(holder.getAdapterPosition()).id);
                        contentName.setVisibility(View.VISIBLE);
                        progressTextView.setVisibility(View.GONE);
                        progressBar.setVisibility(View.GONE);
                        cancelButton.setVisibility(View.GONE);
                    }
                });
            } else {
                contentName.setVisibility(View.VISIBLE);
                progressTextView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                cancelButton.setVisibility(View.GONE);
            }
        }
    }
}