Example usage for android.widget ProgressBar setProgress

List of usage examples for android.widget ProgressBar setProgress

Introduction

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

Prototype

@android.view.RemotableViewMethod
public synchronized void setProgress(int progress) 

Source Link

Document

Sets the current progress to the specified value.

Usage

From source file:org.trakhound.www.trakhound.DeviceDetails.java

private void updateDevicePercentages(DeviceStatus status) {

    // Percentages
    if (status.timersInfo != null && status.timersInfo.total > 0) {

        TimersInfo info = status.timersInfo;

        double active = (info.active / info.total) * 100;
        double idle = (info.idle / info.total) * 100;
        double alert = (info.alert / info.total) * 100;

        // Progress Bars

        // Active
        ProgressBar pb = (ProgressBar) findViewById(R.id.ActiveProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(active));

        // Idle// www . ja v  a 2 s .c  om
        pb = (ProgressBar) findViewById(R.id.IdleProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(idle));

        // Alert
        pb = (ProgressBar) findViewById(R.id.AlertProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(alert));

        // Percentage TextViews

        // Active
        TextView txt = (TextView) findViewById(R.id.ActivePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", active));

        // Idle
        txt = (TextView) findViewById(R.id.IdlePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", idle));

        // Alert
        txt = (TextView) findViewById(R.id.AlertPercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", alert));

        // Time Elapsed TextViews

        // Active
        Integer seconds = Integer.valueOf((int) Math.round(info.active));
        Period period = new Period(seconds * 1000);
        String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.ActiveTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Idle
        seconds = Integer.valueOf((int) Math.round(info.idle));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.IdleTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Alert
        seconds = Integer.valueOf((int) Math.round(info.alert));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.AlertTime);
        if (txt != null)
            txt.setText(statusPeriod);

    } else
        clearDevicePercentages();
}

From source file:android.kostalms.fragment.WebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/* w  w  w.j  a  v a 2 s  .  c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // xml   .
    final View v = inflater.inflate(R.layout.webview, container, false);

    // viewContentProgress has a
    final ProgressBar viewContentProgress = (ProgressBar) v.findViewById(R.id.progress);

    // viewContentWebView has a
    viewContentWebView = (WebView) v.findViewById(R.id.webview);
    viewContentWebView.getSettings().setJavaScriptEnabled(true);
    viewContentWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    // WebChromeClient    .
    viewContentWebView.setWebChromeClient(new WebChromeClient() {

        //    
        @Override
        public void onProgressChanged(WebView view, int newProgress) {

            // viewContentProgress set
            viewContentProgress.setProgress(newProgress);

            // 100   .    .
            viewContentProgress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);

            //      url   ?
            //     .
            if (newProgress == 100 && resetHistory) {
                viewContentWebView.clearHistory();
                resetHistory = false;
            }
        }
    });
    return v;
}

From source file:com.amaze.filemanager.fragments.ProcessViewer.java

public void processExtractResults(DataPackage dataPackage) {
    if (!running)
        return;//from   w ww. ja v a  2  s  . com
    if (getResources() == null)
        return;
    final int id = dataPackage.getId();

    if (!CancelledExtractIds.contains(id)) {
        if (ExtractIds.contains(id)) {

            boolean completed = dataPackage.isCompleted();
            View process = rootView.findViewWithTag("extract" + id);
            if (completed) {
                rootView.removeViewInLayout(process);
                ExtractIds.remove(ExtractIds.indexOf(id));
            } else {
                String name = dataPackage.getName();
                int p1 = dataPackage.getP1();
                long p3 = dataPackage.getTotal();
                long p2 = dataPackage.getDone();
                ProgressBar p = (ProgressBar) process.findViewById(R.id.progressBar1);
                if (p1 <= 100) {
                    ((TextView) process.findViewById(R.id.progressText)).setText(
                            utils.getString(getActivity(), R.string.extracting) + "\n" + name + "\n" + p1 + "%"
                                    + "\n" + utils.readableFileSize(p2) + "/" + utils.readableFileSize(p3));

                    p.setProgress(p1);
                }
            }
        } else {
            CardView root = (CardView) getActivity().getLayoutInflater().inflate(R.layout.processrow, null);
            root.setTag("extract" + id);

            ImageView progressImage = ((ImageView) root.findViewById(R.id.progressImage));
            ImageButton cancel = (ImageButton) root.findViewById(R.id.delete_button);
            TextView progressText = (TextView) root.findViewById(R.id.progressText);

            if (mainActivity.theme1 == 1) {

                root.setCardBackgroundColor(R.color.cardView_foreground);
                root.setCardElevation(0f);
                cancel.setImageResource(R.drawable.ic_action_cancel);
                progressText.setTextColor(Color.WHITE);
                progressImage.setImageResource(R.drawable.ic_doc_compressed);
            } else {

                // cancel has default src set for light theme
                progressText.setTextColor(Color.BLACK);
                progressImage.setImageResource(R.drawable.ic_doc_compressed_black);
            }

            cancel.setOnClickListener(new View.OnClickListener() {

                public void onClick(View p1) {
                    Toast.makeText(getActivity(), utils.getString(getActivity(), R.string.stopping),
                            Toast.LENGTH_LONG).show();
                    Intent i = new Intent("excancel");
                    i.putExtra("id", id);
                    getActivity().sendBroadcast(i);
                    rootView.removeView(rootView.findViewWithTag("extract" + id));

                    ExtractIds.remove(ExtractIds.indexOf(id));
                    CancelledExtractIds.add(id);
                    // TODO: Implement this method
                }
            });

            String name = dataPackage.getName();
            int p1 = dataPackage.getP1();

            ((TextView) root.findViewById(R.id.progressText))
                    .setText(utils.getString(getActivity(), R.string.extracting) + "\n" + name);
            ProgressBar p = (ProgressBar) root.findViewById(R.id.progressBar1);
            p.setProgress(p1);
            ExtractIds.add(id);
            rootView.addView(root);
        }
    }
}

From source file:com.kdao.cmpe235_project.UploadActivity.java

private void initUI() {
    /**//from w w w  .  j ava2 s  .  c o m
     * This adapter takes the data in transferRecordMaps and displays it,
     * with the keys of the map being related to the columns in the adapter
     */
    simpleAdapter = new SimpleAdapter(this, transferRecordMaps, R.layout.record_item,
            new String[] { "checked", "fileName", "progress", "bytes", "state", "percentage" },
            new int[] { R.id.radioButton1, R.id.textFileName, R.id.progressBar1, R.id.textBytes, R.id.textState,
                    R.id.textPercentage });
    simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            switch (view.getId()) {
            case R.id.radioButton1:
                RadioButton radio = (RadioButton) view;
                radio.setChecked((Boolean) data);
                return true;
            case R.id.textFileName:
                TextView fileName = (TextView) view;
                fileName.setText((String) data);
                return true;
            case R.id.progressBar1:
                ProgressBar progress = (ProgressBar) view;
                progress.setProgress((Integer) data);
                return true;
            case R.id.textBytes:
                TextView bytes = (TextView) view;
                bytes.setText((String) data);
                return true;
            case R.id.textState:
                TextView state = (TextView) view;
                state.setText(((TransferState) data).toString());
                return true;
            case R.id.textPercentage:
                TextView percentage = (TextView) view;
                percentage.setText((String) data);
                return true;
            }
            return false;
        }
    });
    setListAdapter(simpleAdapter);

    // Updates checked index when an item is clicked
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {

            if (checkedIndex != pos) {
                transferRecordMaps.get(pos).put("checked", true);
                if (checkedIndex >= 0) {
                    transferRecordMaps.get(checkedIndex).put("checked", false);
                }
                checkedIndex = pos;
                updateButtonAvailability();
                simpleAdapter.notifyDataSetChanged();
            }
        }
    });

    //btnUploadFile = (Button) findViewById(R.id.buttonUploadFile);
    btnUploadImage = (Button) findViewById(R.id.buttonUploadImage);
    btnUploadAudio = (Button) findViewById(R.id.buttonUploadAudio);
    btnUploadVideo = (Button) findViewById(R.id.buttonUploadVideo);
    btnPause = (Button) findViewById(R.id.buttonPause);
    btnResume = (Button) findViewById(R.id.buttonResume);
    btnCancel = (Button) findViewById(R.id.buttonCancel);
    btnDelete = (Button) findViewById(R.id.buttonDelete);
    btnPauseAll = (Button) findViewById(R.id.buttonPauseAll);
    btnCancelAll = (Button) findViewById(R.id.buttonCancelAll);

    btnUploadImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                System.out.println(">>>>> Start uploading photos... <<<<<<<");
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/photo";
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnUploadAudio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/audio";
                intent.setType("audio/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }

    });

    btnUploadVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/video";
                intent.setType("video/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean paused = transferUtility.pause(observers.get(checkedIndex).getId());
                /**
                 * If paused does not return true, it is likely because the
                 * user is trying to pause an upload that is not in a
                 * pausable state (For instance it is already paused, or
                 * canceled).
                 */
                if (!paused) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_PAUSE_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnResume.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                TransferObserver resumed = transferUtility.resume(observers.get(checkedIndex).getId());
                // Sets a new transfer listener to the original observer.
                // This will overwrite existing listener.
                observers.get(checkedIndex).setTransferListener(new UploadListener());
                /**
                 * If resume returns null, it is likely because the transfer
                 * is not in a resumable state (For instance it is already
                 * running).
                 */
                if (resumed == null) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_RESUME_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean canceled = transferUtility.cancel(observers.get(checkedIndex).getId());
                /**
                 * If cancel returns false, it is likely because the
                 * transfer is already canceled
                 */
                if (!canceled) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_TRANSFER_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                transferUtility.deleteTransferRecord(observers.get(checkedIndex).getId());
                observers.remove(checkedIndex);
                transferRecordMaps.remove(checkedIndex);
                checkedIndex = INDEX_NOT_CHECKED;
                updateButtonAvailability();
                updateList();
            }
        }
    });

    btnPauseAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.pauseAllWithType(TransferType.UPLOAD);
        }
    });

    btnCancelAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.cancelAllWithType(TransferType.UPLOAD);
        }
    });

    updateButtonAvailability();
}

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 {/*from w w  w .j  a va2s . c om*/
        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.alibaba.akita.io.HttpInvoker.java

private static byte[] retrieveImageData(InputStream inputStream, int fileSize, ProgressBar progressBar)
        throws IOException {

    // determine the remoteimageview size and allocate a buffer
    //Log.d(TAG, "fetching remoteimageview " + imgUrl + " (" +
    //        (fileSize <= 0 ? "size unknown" : Long.toString(fileSize)) + ")");
    BufferedInputStream istream = new BufferedInputStream(inputStream);

    try {//from  w  ww .j  ava  2s  .com
        if (fileSize <= 0) {
            Log.w(TAG, "Server did not set a Content-Length header, will default to buffer size of "
                    + DEFAULT_BUFFER_SIZE + " bytes");
            ByteArrayOutputStream buf = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            int bytesRead = 0;
            while (bytesRead != -1) {
                bytesRead = istream.read(buffer, 0, DEFAULT_BUFFER_SIZE);
                if (bytesRead > 0)
                    buf.write(buffer, 0, bytesRead);
            }
            return buf.toByteArray();
        } else {
            byte[] imageData = new byte[fileSize];

            int bytesRead = 0;
            int offset = 0;
            while (bytesRead != -1 && offset < fileSize) {
                bytesRead = istream.read(imageData, offset, fileSize - offset);
                offset += bytesRead;
                // process reporting
                try {
                    if (progressBar != null) {
                        progressBar.setProgress(offset * 100 / fileSize);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return imageData;
        }
    } finally {
        // clean up
        try {
            istream.close();
            inputStream.close();
        } catch (Exception ignore) {
        }
    }
}

From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java

private void loadGameDetails() {
    View view = getView();/*from w ww  .j  av a  2s . co m*/
    if (view == null)
        return;

    if (mTitleId < 0) {
        view.findViewById(R.id.unselected).setVisibility(View.VISIBLE);
        view.findViewById(R.id.achievement_contents).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.unselected).setVisibility(View.GONE);
        view.findViewById(R.id.achievement_contents).setVisibility(View.VISIBLE);
    }

    if (!mShowGameTotals)
        return;

    Context context = getActivity();
    ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(Games.CONTENT_URI, GamesFragment.PROJ, Games._ID + "=" + mTitleId, null, null);

    if (c != null) {
        try {
            if (c.moveToFirst()) {
                int platinum = c.getInt(GamesFragment.COLUMN_UNLOCKED_PLATINUM);
                int gold = c.getInt(GamesFragment.COLUMN_UNLOCKED_GOLD);
                int silver = c.getInt(GamesFragment.COLUMN_UNLOCKED_SILVER);
                int bronze = c.getInt(GamesFragment.COLUMN_UNLOCKED_BRONZE);
                int progress = c.getInt(GamesFragment.COLUMN_PROGRESS);

                TextView tv;
                ImageView iv;
                ProgressBar pb;

                if ((tv = (TextView) view.findViewById(R.id.game_title)) != null)
                    tv.setText(c.getString(GamesFragment.COLUMN_TITLE));
                if ((tv = (TextView) view.findViewById(R.id.game_progress_ind)) != null)
                    tv.setText(progress + "");
                if ((pb = (ProgressBar) view.findViewById(R.id.game_progress_bar)) != null)
                    pb.setProgress(progress);

                if ((tv = (TextView) view.findViewById(R.id.game_trophies_platinum)) != null)
                    tv.setText(platinum + "");
                if ((tv = (TextView) view.findViewById(R.id.game_trophies_gold)) != null)
                    tv.setText(gold + "");
                if ((tv = (TextView) view.findViewById(R.id.game_trophies_silver)) != null)
                    tv.setText(silver + "");
                if ((tv = (TextView) view.findViewById(R.id.game_trophies_bronze)) != null)
                    tv.setText(bronze + "");
                if ((tv = (TextView) view.findViewById(R.id.game_trophies_all)) != null)
                    tv.setText((platinum + gold + silver + bronze) + "");

                ImageCache ic = ImageCache.getInstance();
                String iconUrl = c.getString(GamesFragment.COLUMN_ICON_URL);
                Bitmap bmp;

                if ((bmp = ic.getCachedBitmap(iconUrl, mCp)) != null) {
                    iv = (ImageView) view.findViewById(R.id.game_icon);
                    iv.setImageBitmap(bmp);
                } else {
                    if (iconUrl != null) {
                        ic.requestImage(iconUrl, new OnImageReadyListener() {
                            @Override
                            public void onImageReady(long id, Object param, Bitmap bmp) {
                                mHandler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        loadGameDetails();
                                    }
                                });
                            }
                        }, 0, null, true, mCp);
                    }
                }
            }
        } finally {
            c.close();
        }
    }
}

From source file:com.owncloud.android.ui.activity.DrawerActivity.java

/**
 * Updates the quota in the drawer//ww w .  j a v  a2s  .  c  o m
 */
private void updateQuota() {
    Account account = AccountUtils.getCurrentOwnCloudAccount(this);

    if (account == null)
        return;

    UserProfile.UserQuota userQuota = UserProfilesRepository.getUserProfilesRepository().getQuota(account.name);

    if (userQuota == null)
        return;

    ProgressBar accountQuotaBar = findViewById(R.id.account_quota_bar);

    TextView accountQuotaText = findViewById(R.id.account_quota_text);

    if (accountQuotaBar != null && accountQuotaText != null) {

        if (userQuota.getFree() < 0) { // Pending, unknown or unlimited free storage

            accountQuotaBar.setVisibility(View.VISIBLE);

            accountQuotaBar.setProgress(0);

            accountQuotaText.setText(String.format(getString(R.string.drawer_unavailable_free_storage),
                    DisplayUtils.bytesToHumanReadable(userQuota.getUsed(), this)));

        } else if (userQuota.getFree() == 0) { // Quota 0, guest users

            accountQuotaBar.setVisibility(View.GONE);

            accountQuotaText.setText(getString(R.string.drawer_unavailable_used_storage));

        } else { // Limited quota

            accountQuotaBar.setVisibility(View.VISIBLE);

            // Update progress bar rounding up to next int. Example: quota is 0.54 => 1
            accountQuotaBar.setProgress((int) Math.ceil(userQuota.getRelative()));

            accountQuotaText.setText(String.format(getString(R.string.drawer_quota),
                    DisplayUtils.bytesToHumanReadable(userQuota.getUsed(), this),
                    DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), this), userQuota.getRelative()));

        }
    }
}

From source file:com.bt.download.android.gui.adapters.TransferListAdapter.java

private void populateBittorrentDownloadItem(View view, TransferItem item) {
    ImageView icon = findView(view, R.id.view_transfer_item_list_item_icon);
    TextView title = findView(view, R.id.view_transfer_item_list_item_title);
    ProgressBar progress = findView(view, R.id.view_transfer_item_list_item_progress);
    TextView size = findView(view, R.id.view_transfer_item_list_item_size);
    ImageButton buttonPlay = findView(view, R.id.view_transfer_item_list_item_button_play);

    icon.setImageResource(getFileTypeIconId(FilenameUtils.getExtension(item.getFile().getAbsolutePath())));
    title.setText(item.getDisplayName());
    progress.setProgress(item.getProgress());
    size.setText(UIUtils.getBytesInHuman(item.getSize()));

    buttonPlay.setTag(item);/*from w  w  w. j  av  a2 s .  c o m*/
    buttonPlay.setVisibility(item.isComplete() ? View.VISIBLE : View.GONE);
    buttonPlay.setOnClickListener(playOnClickListener);
}

From source file:com.esri.arcgisruntime.sample.generategeodatabase.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // define permission to request
    String[] reqPermission = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE };
    int requestCode = 2;
    // For API level 23+ request permission at runtime
    if (ContextCompat.checkSelfPermission(MainActivity.this,
            reqPermission[0]) != PackageManager.PERMISSION_GRANTED) {
        // request permission
        ActivityCompat.requestPermissions(MainActivity.this, reqPermission, requestCode);
    }//from   w w w .  j a v  a 2 s  .c o  m

    // use local tile package for the base map
    TileCache sanFrancisco = new TileCache(
            Environment.getExternalStorageDirectory() + getString(R.string.san_francisco_tpk));
    ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(sanFrancisco);

    // create a map view and add a map
    mMapView = (MapView) findViewById(R.id.mapView);
    final ArcGISMap map = new ArcGISMap(new Basemap(tiledLayer));
    mMapView.setMap(map);

    // create a graphics overlay and symbol to mark the extent
    final GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
    mMapView.getGraphicsOverlays().add(graphicsOverlay);
    final SimpleLineSymbol boundarySymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 5);

    // inflate button and progress layout
    final Button genGeodatabaseButton = (Button) findViewById(R.id.genGeodatabaseButton);
    mProgressLayout = (RelativeLayout) findViewById(R.id.progressLayout);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.taskProgressBar);
    mProgressTextView = (TextView) findViewById(R.id.progressTextView);

    // create a geodatabase sync task
    final GeodatabaseSyncTask geodatabaseSyncTask = new GeodatabaseSyncTask(getString(R.string.wildfire_sync));
    geodatabaseSyncTask.loadAsync();
    geodatabaseSyncTask.addDoneLoadingListener(new Runnable() {
        @Override
        public void run() {

            // generate the geodatabase sync task
            genGeodatabaseButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    // show the progress layout
                    progressBar.setProgress(0);
                    mProgressLayout.setVisibility(View.VISIBLE);

                    // clear any previous operational layers and graphics if button clicked more than once
                    map.getOperationalLayers().clear();
                    graphicsOverlay.getGraphics().clear();

                    // show the extent used as a graphic
                    Envelope extent = mMapView.getVisibleArea().getExtent();
                    Graphic boundary = new Graphic(extent, boundarySymbol);
                    graphicsOverlay.getGraphics().add(boundary);

                    // create generate geodatabase parameters for the current extent
                    final ListenableFuture<GenerateGeodatabaseParameters> defaultParameters = geodatabaseSyncTask
                            .createDefaultGenerateGeodatabaseParametersAsync(extent);
                    defaultParameters.addDoneListener(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                // set parameters and don't include attachments
                                GenerateGeodatabaseParameters parameters = defaultParameters.get();
                                parameters.setReturnAttachments(false);

                                // define the local path where the geodatabase will be stored
                                final String localGeodatabasePath = getCacheDir().toString() + File.separator
                                        + getString(R.string.wildfire_geodatabase);

                                // create and start the job
                                final GenerateGeodatabaseJob generateGeodatabaseJob = geodatabaseSyncTask
                                        .generateGeodatabaseAsync(parameters, localGeodatabasePath);
                                generateGeodatabaseJob.start();
                                mProgressTextView.setText(getString(R.string.progress_started));

                                // update progress
                                generateGeodatabaseJob.addProgressChangedListener(new Runnable() {
                                    @Override
                                    public void run() {
                                        progressBar.setProgress(generateGeodatabaseJob.getProgress());
                                        mProgressTextView.setText(getString(R.string.progress_fetching));
                                    }
                                });

                                // get geodatabase when done
                                generateGeodatabaseJob.addJobDoneListener(new Runnable() {
                                    @Override
                                    public void run() {
                                        mProgressLayout.setVisibility(View.INVISIBLE);
                                        if (generateGeodatabaseJob.getStatus() == Job.Status.SUCCEEDED) {
                                            final Geodatabase geodatabase = generateGeodatabaseJob.getResult();
                                            geodatabase.loadAsync();
                                            geodatabase.addDoneLoadingListener(new Runnable() {
                                                @Override
                                                public void run() {
                                                    if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {
                                                        mProgressTextView
                                                                .setText(getString(R.string.progress_done));
                                                        for (GeodatabaseFeatureTable geodatabaseFeatureTable : geodatabase
                                                                .getGeodatabaseFeatureTables()) {
                                                            geodatabaseFeatureTable.loadAsync();
                                                            map.getOperationalLayers().add(
                                                                    new FeatureLayer(geodatabaseFeatureTable));
                                                        }
                                                        genGeodatabaseButton.setVisibility(View.GONE);
                                                        Log.i(TAG, "Local geodatabase stored at: "
                                                                + localGeodatabasePath);
                                                    } else {
                                                        Log.e(TAG, "Error loading geodatabase: "
                                                                + geodatabase.getLoadError().getMessage());
                                                    }
                                                }
                                            });
                                            // unregister since we're not syncing
                                            ListenableFuture unregisterGeodatabase = geodatabaseSyncTask
                                                    .unregisterGeodatabaseAsync(geodatabase);
                                            unregisterGeodatabase.addDoneListener(new Runnable() {
                                                @Override
                                                public void run() {
                                                    Log.i(TAG,
                                                            "Geodatabase unregistered since we wont be editing it in this sample.");
                                                    Toast.makeText(MainActivity.this,
                                                            "Geodatabase unregistered since we wont be editing it in this sample.",
                                                            Toast.LENGTH_LONG).show();
                                                }
                                            });
                                        } else if (generateGeodatabaseJob.getError() != null) {
                                            Log.e(TAG, "Error generating geodatabase: "
                                                    + generateGeodatabaseJob.getError().getMessage());
                                        } else {
                                            Log.e(TAG, "Unknown Error generating geodatabase");
                                        }
                                    }
                                });
                            } catch (InterruptedException | ExecutionException e) {
                                Log.e(TAG, "Error generating geodatabase parameters : " + e.getMessage());
                            }
                        }
                    });
                }
            });
        }
    });
}