Example usage for android.app ProgressDialog STYLE_HORIZONTAL

List of usage examples for android.app ProgressDialog STYLE_HORIZONTAL

Introduction

In this page you can find the example usage for android.app ProgressDialog STYLE_HORIZONTAL.

Prototype

int STYLE_HORIZONTAL

To view the source code for android.app ProgressDialog STYLE_HORIZONTAL.

Click Source Link

Document

Creates a ProgressDialog with a horizontal progress bar.

Usage

From source file:org.thialfihar.android.apg.ui.EditKeyActivity.java

private void finallySaveClicked() {
    try {//from ww  w  .j av a  2s . c  o m
        // Send all information needed to service to edit key in other thread
        Intent intent = new Intent(this, ApgIntentService.class);

        intent.setAction(ApgIntentService.ACTION_SAVE_KEYRING);

        SaveKeyringParcel saveParams = new SaveKeyringParcel();
        saveParams.userIds = getUserIds(mUserIdsView);
        saveParams.originalIDs = mUserIdsView.getOriginalIDs();
        saveParams.deletedIDs = mUserIdsView.getDeletedIDs();
        saveParams.newIDs = toPrimitiveArray(mUserIdsView.getNewIDFlags());
        saveParams.primaryIDChanged = mUserIdsView.primaryChanged();
        saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray());
        saveParams.deletedKeys = mKeysView.getDeletedKeys();
        saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView);
        saveParams.keysUsages = getKeysUsages(mKeysView);
        saveParams.newPassphrase = mNewPassphrase;
        saveParams.oldPassphrase = mCurrentPassphrase;
        saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray());
        saveParams.keys = getKeys(mKeysView);
        saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID();

        // fill values for this action
        Bundle data = new Bundle();
        data.putBoolean(ApgIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign);
        data.putParcelable(ApgIntentService.SAVE_KEYRING_PARCEL, saveParams);

        intent.putExtra(ApgIntentService.EXTRA_DATA, data);

        // Message is received after saving is done in ApgIntentService
        ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this,
                getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL) {
            public void handleMessage(Message message) {
                // handle messages by standard ApgIntentServiceHandler first
                super.handleMessage(message);

                if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
                    Intent data = new Intent();

                    // return uri pointing to new created key
                    Uri uri = ApgContract.KeyRings.buildGenericKeyRingUri(String.valueOf(getMasterKeyId()));
                    data.setData(uri);

                    setResult(RESULT_OK, data);
                    finish();
                }
            }
        };

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(saveHandler);
        intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

        saveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } catch (PgpGeneralException e) {
        Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage()));
        AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), AppMsg.STYLE_ALERT).show();
    }
}

From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java

private void finallySaveClicked() {
    try {//from  w ww .j  a  v  a2s .  c o  m
        // Send all information needed to service to edit key in other thread
        Intent intent = new Intent(this, KeychainIntentService.class);

        intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);

        OldSaveKeyringParcel saveParams = new OldSaveKeyringParcel();
        saveParams.userIds = getUserIds(mUserIdsView);
        saveParams.originalIDs = mUserIdsView.getOriginalIDs();
        saveParams.deletedIDs = mUserIdsView.getDeletedIDs();
        saveParams.newIDs = toPrimitiveArray(mUserIdsView.getNewIDFlags());
        saveParams.primaryIDChanged = mUserIdsView.primaryChanged();
        saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray());
        saveParams.deletedKeys = mKeysView.getDeletedKeys();
        saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView);
        saveParams.keysUsages = getKeysUsages(mKeysView);
        saveParams.newPassphrase = mNewPassphrase;
        saveParams.oldPassphrase = mCurrentPassphrase;
        saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray());
        saveParams.keys = getKeys(mKeysView);
        saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID();

        // fill values for this action
        Bundle data = new Bundle();
        data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign);
        data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams);

        intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

        // Message is received after saving is done in KeychainIntentService
        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
                getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL) {
            public void handleMessage(Message message) {
                // handle messages by standard KeychainIntentServiceHandler first
                super.handleMessage(message);

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    Intent data = new Intent();

                    // return uri pointing to new created key
                    Uri uri = KeyRings.buildGenericKeyRingUri(getMasterKeyId());
                    data.setData(uri);

                    setResult(RESULT_OK, data);
                    finish();
                }
            }
        };

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(saveHandler);
        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

        saveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } catch (PgpGeneralException e) {
        Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage()));
        AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), AppMsg.STYLE_ALERT).show();
    }
}

From source file:com.BeatYourRecord.SubmitActivity.java

public void upload(Uri videoUri) {
    this.dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("uploading ...");
    dialog.setCancelable(false);/*  ww  w . j  a v a 2s.co m*/
    dialog.show();

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            dialog.dismiss();
            String videoId = msg.getData().getString("videoId");
            Log.v("Video", videoId);
            String youtubelink = "http://www.youtube.com/watch?v=" + videoId;
            SharedPreferences pref = getApplicationContext().getSharedPreferences("TourPref", 0); // 0 - for private mode
            Editor editor = pref.edit();

            editor.putString("myyoutubelink", youtubelink);
            editor.commit();
            DefaultHttpClient client = new DefaultHttpClient();
            Log.v("here1233", "here");
            Log.v("authtoke", auth);
            HttpPost post = new HttpPost(
                    "http://ec2-54-212-221-3.us-west-2.compute.amazonaws.com/api/v3/entries?auth_token="
                            + auth);
            JSONObject holder = new JSONObject();
            JSONObject userObj = new JSONObject();
            JSONObject userObj1 = new JSONObject();
            JSONObject userObj2 = new JSONObject();
            String response = null;
            JSONObject json = new JSONObject();

            try {
                try {
                    // setup the returned values in case
                    // something goes wrong
                    json.put("success", false);
                    json.put("info", "Something went wrong. Retry!");
                    // add the user email and password to
                    // the params

                    String k = "";
                    String k1 = "";
                    String k2 = "";

                    //log.v("auth",auth);
                    userObj.put("score", getTitleText());
                    SharedPreferences pref11 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
                    Editor editor11 = pref11.edit();
                    editor11.putString("score", getTitleText());
                    editor11.commit();
                    ////////////////////////
                    holder.put("entry", userObj);
                    k = holder.toString();
                    k = k.substring(0, k.length() - 2);
                    k += ",";
                    userObj1.put("tournament_id", tourid);
                    k1 += userObj1.toString();
                    k1 = k1.substring(1, k1.length() - 1);

                    k += k1;
                    k += ",";
                    userObj2.put("yt_video", youtubelink);
                    k1 = userObj2.toString();
                    k1 = k1.substring(1, k1.length());
                    k += k1;
                    /*    double arr[] = new double[2];
                        arr[0]=lat;
                        arr[1]=lng;
                      JSONObject Array1 = new JSONObject();
                    Array1.put("geoloc", arr);
                    k1=Array1.toString();
                    k1=k1.substring(1, k1.length());
                            
                    k+=k1;
                            
                      userObj2.put("geoloc", String.valueOf(lat) +","+ String.valueOf(lng));
                      k1 += userObj2.toString();
                      k1=k1.substring(1, k1.length());
                              
                      k+=k1;*/
                    k += "}";

                    //log.v("holder",k);
                    StringEntity se = new StringEntity(k);
                    post.setEntity(se);

                    // setup the request headers
                    post.setHeader("Content-Type", "application/json");
                    post.setHeader("Accept", "application/json");
                    //  post.setHeader("Content-Type", "application/json");
                    //log.v("test1","wearegere");
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                    response = client.execute(post, responseHandler);
                    json = new JSONObject(response);
                    // test = json.getJSONObject("data").getString("auth_token");
                    //  //log.v("test1",test);

                } catch (HttpResponseException e) {
                    e.printStackTrace();
                    Log.e("ClientProtocol", "" + e);
                    json.put("info", "Email and/or password are invalid. Retry!");
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e("IO", "" + e);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                Log.e("JSON", "" + e);
            }

            if (!Util.isNullOrEmpty(videoId)) {
                currentFileSize = 0;
                totalBytesUploaded = 0;
                Intent result = new Intent();
                result.putExtra("videoId", videoId);
                Log.v("tired", videoId);
                setResult(RESULT_OK, result);
                finish();
            } else {
                String error = msg.getData().getString("error");
                if (!Util.isNullOrEmpty(error)) {
                    Toast.makeText(SubmitActivity.this, error, Toast.LENGTH_LONG).show();
                }
            }
        }
    };

    asyncUpload(videoUri, handler);
}

From source file:com.dsi.ant.antplus.pluginsampler.weightscale.Activity_WeightScaleSampler.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.e("WeightScale", "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_weightscale);

    layoutControllerList = new ArrayList<Closeable>();

    button_requestBasicMeasurement = (Button) findViewById(R.id.button_requestBasicMeasurement);
    button_requestAdvancedMeasurement = (Button) findViewById(R.id.button_requestAdvancedMeasurement);
    button_requestCapabilities = (Button) findViewById(R.id.button_requestCapabilities);
    button_configUserProfile = (Button) findViewById(R.id.button_configUserProfile);
    button_requestDownloadAllHistory = (Button) findViewById(R.id.button_requestDownloadAllHistory);

    linearLayout_FitDataView = (LinearLayout) findViewById(R.id.linearLayout_WeightScaleCards);

    tv_status = (TextView) findViewById(R.id.textView_Status);
    tv_estTimestamp = (TextView) findViewById(R.id.textView_EstTimestamp);
    tv_bodyWeightResult = (TextView) findViewById(R.id.textView_BodyWeightResult);
    tv_bodyWeightBroadcast = (TextView) findViewById(R.id.textView_BodyWeightBroadcast);
    tv_bodyFatPercentage = (TextView) findViewById(R.id.textView_BodyFatPercentage);
    tv_hydrationPercentage = (TextView) findViewById(R.id.textView_HydrationPercentage);
    tv_muscleMass = (TextView) findViewById(R.id.textView_MuscleMass);
    tv_boneMass = (TextView) findViewById(R.id.textView_BoneMass);
    tv_activeMetabolicRate = (TextView) findViewById(R.id.textView_ActiveMetabolicRate);
    tv_basalMetabolicRate = (TextView) findViewById(R.id.textView_BasalMetabolicRate);

    tv_userProfileExchangeSupport = (TextView) findViewById(R.id.textView_UserProfileExchangeSupport);
    tv_userProfileSelected = (TextView) findViewById(R.id.textView_UserProfileSelected);
    tv_userProfileID = (TextView) findViewById(R.id.textView_UserProfileID);
    tv_historySupport = (TextView) findViewById(R.id.textView_HistorySupport);

    tv_hardwareRevision = (TextView) findViewById(R.id.textView_HardwareRevision);
    tv_manufacturerID = (TextView) findViewById(R.id.textView_ManufacturerID);
    tv_modelNumber = (TextView) findViewById(R.id.textView_ModelNumber);

    tv_mainSoftwareRevision = (TextView) findViewById(R.id.textView_MainSoftwareRevision);
    tv_supplementalSoftwareRevision = (TextView) findViewById(R.id.textView_SupplementalSoftwareRevision);
    tv_serialNumber = (TextView) findViewById(R.id.textView_SerialNumber);

    userProfile.age = 32;/*  w  w w.  j a  v a2s  . c om*/
    userProfile.height = 160;
    userProfile.gender = Gender.FEMALE;
    userProfile.lifetimeAthlete = false;
    userProfile.activityLevel = 4;

    button_requestBasicMeasurement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            boolean submitted = wgtPcc.requestBasicMeasurement(new IBasicMeasurementFinishedReceiver() {

                @Override
                public void onBasicMeasurementFinished(long estTimestamp, EnumSet<EventFlag> eventFlags,
                        final WeightScaleRequestStatus status, final BigDecimal bodyWeight) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            setRequestButtonsEnabled(true);
                            if (checkRequestResult(status)) {
                                if (bodyWeight.intValue() == -1)
                                    tv_bodyWeightResult.setText("Invalid");
                                else
                                    tv_bodyWeightResult.setText(String.valueOf(bodyWeight) + "kg");
                            }
                        }
                    });
                }
            });

            if (submitted) {
                setRequestButtonsEnabled(false);
                resetWeightRequestedDataDisplay("Computing");
            }
        }
    });

    button_requestAdvancedMeasurement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            boolean submitted = wgtPcc.requestAdvancedMeasurement(new IAdvancedMeasurementFinishedReceiver() {
                @Override
                public void onAdvancedMeasurementFinished(long estTimestamp, EnumSet<EventFlag> eventFlags,
                        final WeightScaleRequestStatus status, final AdvancedMeasurement measurement) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            setRequestButtonsEnabled(true);
                            if (checkRequestResult(status)) {
                                if (measurement.bodyWeight.intValue() == -1)
                                    tv_bodyWeightResult.setText("Invalid");
                                else
                                    tv_bodyWeightResult.setText(String.valueOf(measurement.bodyWeight) + "kg");
                                if (measurement.hydrationPercentage.intValue() == -1)
                                    tv_hydrationPercentage.setText("Invalid");
                                else
                                    tv_hydrationPercentage
                                            .setText(String.valueOf(measurement.hydrationPercentage) + "%");
                                if (measurement.bodyFatPercentage.intValue() == -1)
                                    tv_bodyFatPercentage.setText("Invalid");
                                else
                                    tv_bodyFatPercentage
                                            .setText(String.valueOf(measurement.bodyFatPercentage) + "%");
                                if (measurement.muscleMass.intValue() == -1)
                                    tv_muscleMass.setText("Invalid");
                                else
                                    tv_muscleMass.setText(String.valueOf(measurement.muscleMass) + "kg");
                                if (measurement.boneMass.intValue() == -1)
                                    tv_boneMass.setText("Invalid");
                                else
                                    tv_boneMass.setText(String.valueOf(measurement.boneMass) + "kg");
                                if (measurement.activeMetabolicRate.intValue() == -1)
                                    tv_activeMetabolicRate.setText("Invalid");
                                else
                                    tv_activeMetabolicRate
                                            .setText(String.valueOf(measurement.activeMetabolicRate) + "kcal");
                                if (measurement.basalMetabolicRate.intValue() == -1)
                                    tv_basalMetabolicRate.setText("Invalid");
                                else
                                    tv_basalMetabolicRate
                                            .setText(String.valueOf(measurement.basalMetabolicRate) + "kcal");
                            }
                        }
                    });
                }
            }, userProfile);

            if (submitted) {
                setRequestButtonsEnabled(false);
                resetWeightRequestedDataDisplay("Computing");
            }
        }
    });

    button_requestCapabilities.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean submitted = wgtPcc.requestCapabilities(new ICapabilitiesRequestFinishedReceiver() {
                @Override
                public void onCapabilitiesRequestFinished(long estTimestamp, EnumSet<EventFlag> eventFlags,
                        final WeightScaleRequestStatus status, final int userProfileID,
                        final boolean historySupport, final boolean userProfileExchangeSupport,
                        final boolean userProfileSelected) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            setRequestButtonsEnabled(true);

                            if (checkRequestResult(status)) {
                                tv_bodyWeightResult.setText("Req Capab Success");
                                tv_userProfileExchangeSupport
                                        .setText(String.valueOf(userProfileExchangeSupport));
                                tv_userProfileSelected.setText(String.valueOf(userProfileSelected));
                                tv_historySupport.setText(String.valueOf(historySupport));
                                if (userProfileID == -1)
                                    tv_userProfileID.setText("UNASSIGNED");
                                else
                                    tv_userProfileID.setText(String.valueOf(userProfileID));
                            }
                        }
                    });
                }
            });

            if (submitted) {
                setRequestButtonsEnabled(false);
                resetWeightRequestedDataDisplay("Req Capab");
            }
        }
    });

    button_configUserProfile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog_ConfigUserProfile dialog = new Dialog_ConfigUserProfile(userProfile);
            dialog.show(getSupportFragmentManager(), "Configure User Profile");
        }
    });

    button_requestDownloadAllHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            antFsProgressDialog = new ProgressDialog(Activity_WeightScaleSampler.this);
            antFsProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            antFsProgressDialog.setMessage("Sending Request...");
            antFsProgressDialog.setCancelable(false);
            antFsProgressDialog.setIndeterminate(false);

            boolean submitted = wgtPcc.requestDownloadAllHistory(new IDownloadAllHistoryFinishedReceiver() {
                //Process the final result of the download
                @Override
                public void onDownloadAllHistoryFinished(final AntFsRequestStatus status) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            setRequestButtonsEnabled(true);
                            antFsProgressDialog.dismiss();

                            switch (status) {
                            case SUCCESS:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory finished successfully.", Toast.LENGTH_SHORT).show();
                                break;
                            case FAIL_ALREADY_BUSY_EXTERNAL:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, device busy.", Toast.LENGTH_SHORT).show();
                                break;
                            case FAIL_DEVICE_COMMUNICATION_FAILURE:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, communication error.", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                            case FAIL_NOT_SUPPORTED:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, feature not supported in weight scale.",
                                        Toast.LENGTH_LONG).show();
                                break;
                            case FAIL_AUTHENTICATION_REJECTED:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, authentication rejected.",
                                        Toast.LENGTH_LONG).show();
                                break;
                            case FAIL_DEVICE_TRANSMISSION_LOST:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, transmission lost.", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                            case FAIL_PLUGINS_SERVICE_VERSION:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "Failed: Plugin Service Upgrade Required?", Toast.LENGTH_SHORT).show();
                                break;
                            case UNRECOGNIZED:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "Failed: UNRECOGNIZED. PluginLib Upgrade Required?", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                            default:
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "DownloadAllHistory failed, unrecognized code: " + status,
                                        Toast.LENGTH_SHORT).show();
                                break;
                            }
                        }
                    });
                }
            },
                    //Written using FIT SDK 7.10 Library (fit.jar)
                    new IFitFileDownloadedReceiver() {
                        //Process incoming FIT file(s)
                        @Override
                        public void onNewFitFileDownloaded(FitFile downloadedFitFile) {

                            InputStream fitFile = downloadedFitFile.getInputStream();

                            if (!Decode.checkIntegrity(fitFile)) {
                                Toast.makeText(Activity_WeightScaleSampler.this,
                                        "FIT file integrity check failed.", Toast.LENGTH_SHORT).show();
                                return;
                            }

                            //Must reset InputStream after reading it for integrity check
                            try {
                                fitFile.reset();
                            } catch (IOException e) {
                                //No IOExceptions thrown from ByteArrayInputStream
                            }

                            FileIdMesgListener fileIdMesgListener = new FileIdMesgListener() {
                                @Override
                                public void onMesg(final FileIdMesg mesg) {
                                    //Add File ID Layout to the list of layouts displayed to the user
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            layoutControllerList.add(new LayoutController_FileId(
                                                    getLayoutInflater(), linearLayout_FitDataView, mesg));
                                        }
                                    });
                                }
                            };

                            UserProfileMesgListener userProfileMesgListener = new UserProfileMesgListener() {
                                @Override
                                public void onMesg(final UserProfileMesg mesg) {
                                    //Add User Profile Layout to the list of layouts displayed to the user
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            layoutControllerList
                                                    .add(new LayoutController_WeightScaleUserProfile(
                                                            getLayoutInflater(), linearLayout_FitDataView,
                                                            mesg));
                                        }
                                    });
                                }
                            };

                            WeightScaleMesgListener weightScaleMesgListener = new WeightScaleMesgListener() {
                                @Override
                                public void onMesg(final WeightScaleMesg mesg) {
                                    //Add Weight Scale Layout to the list of layouts displayed to the user
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            layoutControllerList.add(new LayoutController_WeightScale(
                                                    getLayoutInflater(), linearLayout_FitDataView, mesg));
                                        }
                                    });
                                }
                            };

                            DeviceInfoMesgListener deviceInfoMesgListener = new DeviceInfoMesgListener() {
                                @Override
                                public void onMesg(final DeviceInfoMesg mesg) {
                                    //Add Device Information Layout to the list of layouts displayed to the user
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            layoutControllerList.add(new LayoutController_WeightScaleDeviceInfo(
                                                    getLayoutInflater(), linearLayout_FitDataView, mesg));
                                        }
                                    });
                                }
                            };

                            MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();
                            mesgBroadcaster.addListener(fileIdMesgListener);
                            mesgBroadcaster.addListener(userProfileMesgListener);
                            mesgBroadcaster.addListener(weightScaleMesgListener);
                            mesgBroadcaster.addListener(deviceInfoMesgListener);

                            try {
                                mesgBroadcaster.run(fitFile);
                            } catch (FitRuntimeException e) {
                                Log.e("WeightScaleSampler", "Error decoding FIT file: " + e.toString());
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(Activity_WeightScaleSampler.this,
                                                "Error decoding FIT file", Toast.LENGTH_LONG).show();
                                    }
                                });
                            }
                        }

                    }, new IAntFsProgressUpdateReceiver() {
                        @Override
                        public void onNewAntFsProgressUpdate(final AntFsState state,
                                final long transferredBytes, final long totalBytes) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    switch (state) {
                                    //In Link state and requesting to link with the device in order to pass to Auth state
                                    case LINK_REQUESTING_LINK:
                                        antFsProgressDialog.setMax(4);
                                        antFsProgressDialog.setProgress(1);
                                        antFsProgressDialog.setMessage("In Link State: Requesting Link.");
                                        break;

                                    //In Authentication state, processing authentication commands
                                    case AUTHENTICATION:
                                        antFsProgressDialog.setMax(4);
                                        antFsProgressDialog.setProgress(2);
                                        antFsProgressDialog.setMessage("In Authentication State.");
                                        break;

                                    //In Authentication state, currently attempting to pair with the device
                                    //NOTE: Feedback SHOULD be given to the user here as pairing typically requires user interaction with the device
                                    case AUTHENTICATION_REQUESTING_PAIRING:
                                        antFsProgressDialog.setMax(4);
                                        antFsProgressDialog.setProgress(2);
                                        antFsProgressDialog
                                                .setMessage("In Authentication State: User Pairing Requested.");
                                        break;

                                    //In Transport state, no requests are currently being processed
                                    case TRANSPORT_IDLE:
                                        antFsProgressDialog.setMax(4);
                                        antFsProgressDialog.setProgress(3);
                                        antFsProgressDialog.setMessage(
                                                "Requesting download (In Transport State: Idle)...");
                                        break;

                                    //In Transport state, files are currently being downloaded
                                    case TRANSPORT_DOWNLOADING:
                                        antFsProgressDialog.setMessage("In Transport State: Downloading.");
                                        antFsProgressDialog.setMax(100);

                                        if (transferredBytes >= 0 && totalBytes > 0) {
                                            int progress = (int) (transferredBytes * 100 / totalBytes);
                                            antFsProgressDialog.setProgress(progress);
                                        }
                                        break;

                                    case UNRECOGNIZED:
                                        Toast.makeText(Activity_WeightScaleSampler.this,
                                                "Failed: UNRECOGNIZED. PluginLib Upgrade Required?",
                                                Toast.LENGTH_SHORT).show();
                                        break;

                                    default:
                                        Log.w("WeightScaleSampler",
                                                "Unknown ANT-FS State Code Received: " + state);
                                        break;
                                    }
                                }
                            });
                        }
                    });

            if (submitted) {
                clearLayoutList();

                setRequestButtonsEnabled(false);
                antFsProgressDialog.show();
            }
        }
    });

    resetPcc();
}

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
    Dialog dialog = null;/*w ww.j  a va 2 s  .  c  o  m*/
    switch (id) {
    case DIALOG_DOWNLOAD_ID: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.")
                .setPositiveButton("OK", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this);
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setMessage("Downloading...");
                        progressDialog.setCancelable(true);
                        progressDialog.show();

                        String fileId = bundle.getString(JsonKeys.ID);
                        String name = bundle.getString(JsonKeys.NAME);

                        File file = new File(Environment.getExternalStorageDirectory(), name);

                        final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file,
                                new LiveDownloadOperationListener() {
                                    @Override
                                    public void onDownloadProgress(int totalBytes, int bytesRemaining,
                                            LiveDownloadOperation operation) {
                                        int percentCompleted = computePrecentCompleted(totalBytes,
                                                bytesRemaining);

                                        progressDialog.setProgress(percentCompleted);
                                    }

                                    @Override
                                    public void onDownloadFailed(LiveOperationException exception,
                                            LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast(exception.getMessage());
                                    }

                                    @Override
                                    public void onDownloadCompleted(LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast("File downloaded.");
                                    }
                                });

                        progressDialog.setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                operation.cancel();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

        dialog = builder.create();
        break;
    }
    }

    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }

    return dialog;
}

From source file:babybear.akbquiz.ConfigActivity.java

/**
 * ???/*w  w w.jav  a 2 s.  co m*/
 */
private void doNewVersionUpdate() {
    StringBuffer sb = new StringBuffer();
    Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.update_title)
            .setMessage(getString(R.string.update_have_update, verName, verCode, newVerName, newVerCode))
            // 
            .setPositiveButton(R.string.update_do_update, // 
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            pBar = new ProgressDialog(ConfigActivity.this);
                            pBar.setTitle(R.string.update_downloading);
                            pBar.setMessage(getString(R.string.update_waiting));
                            pBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                            pBar.setMax(100);
                            downFile(updateURL);
                        }
                    })
            .setNegativeButton(R.string.update_later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            }).create();
    dialog.show();
}

From source file:com.Beat.RingdroidEditActivity.java

private void loadFromFile() {
    mFile = new File(mFilename);
    mExtension = getExtensionFromFilename(mFilename);

    /* SongMetadataReader metadataReader = new SongMetadataReader(
    this, mFilename);/*from   w  ww . j  av  a2 s. c om*/
     mTitle = metadataReader.mTitle;
     mArtist = metadataReader.mArtist;
     mAlbum = metadataReader.mAlbum;
     mYear = metadataReader.mYear;
     mGenre = metadataReader.mGenre;*/

    String titleLabel = mTitle;
    if (mArtist != null && mArtist.length() > 0) {
        titleLabel += " - " + mArtist;
    }
    setTitle(titleLabel);

    mLoadingStartTime = System.currentTimeMillis();
    mLoadingLastUpdateTime = System.currentTimeMillis();
    mLoadingKeepGoing = true;
    mProgressDialog = new ProgressDialog(RingdroidEditActivity.this);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mProgressDialog.setTitle(R.string.progress_dialog_loading);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            mLoadingKeepGoing = false;
        }
    });
    mProgressDialog.show();

    final CheapSoundFile.ProgressListener listener = new CheapSoundFile.ProgressListener() {
        public boolean reportProgress(double fractionComplete) {
            long now = System.currentTimeMillis();
            if (now - mLoadingLastUpdateTime > 100) {
                mProgressDialog.setProgress((int) (mProgressDialog.getMax() * fractionComplete));
                mLoadingLastUpdateTime = now;
            }
            return mLoadingKeepGoing;
        }
    };

    // Create the MediaPlayer in a background thread
    mCanSeekAccurately = false;
    new Thread() {
        public void run() {
            mCanSeekAccurately = SeekTest.CanSeekAccurately(getPreferences(Context.MODE_PRIVATE));
            System.out.println("Seek test done, creating media player.");
            try {
                MediaPlayer player = new MediaPlayer();
                player.setDataSource(mFile.getAbsolutePath());
                player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                player.prepare();
                mPlayer = player;
            } catch (final java.io.IOException e) {
                Runnable runnable = new Runnable() {
                    public void run() {
                        handleFatalError("ReadError", getResources().getText(R.string.read_error), e);
                    }
                };
                mHandler.post(runnable);
            }
            ;
        }
    }.start();

    // Load the sound file in a background thread
    new Thread() {
        public void run() {
            try {
                mSoundFile = CheapSoundFile.create(mFile.getAbsolutePath(), listener);

                if (mSoundFile == null) {
                    mProgressDialog.dismiss();
                    String name = mFile.getName().toLowerCase();
                    String[] components = name.split("\\.");
                    String err;
                    if (components.length < 2) {
                        err = getResources().getString(R.string.no_extension_error);
                    } else {
                        err = getResources().getString(R.string.bad_extension_error) + " "
                                + components[components.length - 1];
                    }
                    final String finalErr = err;
                    Runnable runnable = new Runnable() {
                        public void run() {
                            handleFatalError("UnsupportedExtension", finalErr, new Exception());
                        }
                    };
                    mHandler.post(runnable);
                    return;
                }
            } catch (final Exception e) {
                mProgressDialog.dismiss();
                e.printStackTrace();
                mInfo.setText(e.toString());

                Runnable runnable = new Runnable() {
                    public void run() {
                        handleFatalError("ReadError", getResources().getText(R.string.read_error), e);
                    }
                };
                mHandler.post(runnable);
                return;
            }
            mProgressDialog.dismiss();
            if (mLoadingKeepGoing) {
                Runnable runnable = new Runnable() {
                    public void run() {
                        finishOpeningSoundFile();
                    }
                };
                mHandler.post(runnable);
            } else {
                RingdroidEditActivity.this.finish();
            }
        }
    }.start();
}

From source file:org.uguess.android.sysinfo.ApplicationManager.java

void export(final List<AppInfoHolder> apps) {
    if (apps == null || apps.isEmpty()) {
        Util.shortToast(getActivity(), R.string.no_app_selected);
        return;//  ww w .  j  a  v a 2s  .  com
    }

    if (progress != null) {
        progress.dismiss();
    }
    progress = new ProgressDialog(getActivity());
    progress.setMessage(getResources().getString(R.string.start_exporting));
    progress.setIndeterminate(false);
    progress.setCancelable(false);
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progress.setMax(apps.size());

    progress.show();

    new Thread(new Runnable() {

        public void run() {
            String exportFolder = Util.getStringOption(getActivity(), PSTORE_APPMANAGER,
                    PREF_KEY_APP_EXPORT_DIR, DEFAULT_EXPORT_FOLDER);

            File output = new File(exportFolder);

            if (!output.exists()) {
                if (!output.mkdirs()) {
                    handler.sendMessage(Message.obtain(handler, MSG_COPING_ERROR, 0, 0,
                            getString(R.string.error_create_folder, output.getAbsolutePath())));

                    return;
                }
            }

            File sysoutput = new File(output, SYS_APP);

            if (!sysoutput.exists()) {
                if (!sysoutput.mkdirs()) {
                    handler.sendMessage(Message.obtain(handler, MSG_COPING_ERROR, 0, 0,
                            getString(R.string.error_create_folder, sysoutput.getAbsolutePath())));

                    return;
                }
            }

            File useroutput = new File(output, USER_APP);

            if (!useroutput.exists()) {
                if (!useroutput.mkdirs()) {
                    handler.sendMessage(Message.obtain(handler, MSG_COPING_ERROR, 0, 0,
                            getString(R.string.error_create_folder, useroutput.getAbsolutePath())));

                    return;
                }
            }

            int skipped = 0;
            int succeed = 0;

            for (int i = 0, size = apps.size(); i < size; i++) {
                ApplicationInfo app = apps.get(i).appInfo;

                String src = app.sourceDir;

                if (src != null) {
                    File srcFile = new File(src);

                    if (src.contains("/data/app-private") //$NON-NLS-1$
                            || !srcFile.canRead()) {
                        skipped++;

                        continue;
                    }

                    String appName = getFileName(src);

                    if (appName != null && app.packageName != null) {
                        // always use package name as the file name for
                        // versatile match
                        appName = app.packageName + ".apk"; //$NON-NLS-1$

                        File targetOutput = useroutput;

                        if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                            targetOutput = sysoutput;
                        }

                        File destFile = new File(targetOutput, appName);

                        handler.sendMessage(Message.obtain(handler, MSG_COPING, appName));

                        try {
                            copyFile(srcFile, destFile);

                            succeed++;
                        } catch (Exception e) {
                            Log.e(ApplicationManager.class.getName(), e.getLocalizedMessage(), e);

                            handler.sendMessage(
                                    Message.obtain(handler, MSG_COPING_ERROR, 1, 0, e.getLocalizedMessage()));

                            continue;
                        }
                    }
                }
            }

            handler.sendMessage(Message.obtain(handler, MSG_COPING_FINISHED, succeed, skipped, apps));
        }
    }).start();
}

From source file:com.yeldi.yeldibazaar.AppDetails.java

private ProgressDialog createProgressDialog(String file, int p, int max) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    pd.setMessage(getString(R.string.download_server) + ":\n " + file);
    pd.setMax(max);//from  w  w w  . j av a  2s. c  o  m
    pd.setProgress(p);
    pd.setCancelable(true);
    pd.setCanceledOnTouchOutside(false);
    pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            downloadHandler.cancel();
        }
    });
    pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    pd.cancel();
                }
            });
    pd.show();
    return pd;
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final BaseApplication application = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = application.getOneDriveClient();

    if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD && data != null && data.getData() != null
            && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) {

        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setTitle(R.string.upload_in_progress_title);
        dialog.setMessage(getString(R.string.upload_in_progress_message));
        dialog.setIndeterminate(false);// www .  ja va 2 s .c  o m
        dialog.setCancelable(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format));
        dialog.show();
        final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                try {
                    final ContentResolver contentResolver = getActivity().getContentResolver();
                    final ContentProviderClient contentProvider = contentResolver
                            .acquireContentProviderClient(data.getData());
                    final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData());
                    contentProvider.release();

                    // Fix up the file name (needed for camera roll photos, etc)
                    final String filename = FileContent.getValidFileName(contentResolver, data.getData());
                    final Option option = new QueryOption("@name.conflictBehavior", "fail");
                    oneDriveClient.getDrive().getItems(mItemId).getChildren().byId(filename).getContent()
                            .buildRequest(Collections.singletonList(option))
                            .put(fileInMemory, new IProgressCallback<Item>() {
                                @Override
                                public void success(final Item item) {
                                    dialog.dismiss();
                                    Toast.makeText(getActivity(),
                                            application.getString(R.string.upload_complete, item.name),
                                            Toast.LENGTH_LONG).show();
                                    refresh();
                                }

                                @Override
                                public void failure(final ClientException error) {
                                    dialog.dismiss();
                                    if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {
                                        Toast.makeText(getActivity(), R.string.upload_failed_name_conflict,
                                                Toast.LENGTH_LONG).show();
                                    } else {
                                        Toast.makeText(getActivity(),
                                                application.getString(R.string.upload_failed, filename),
                                                Toast.LENGTH_LONG).show();
                                    }
                                }

                                @Override
                                public void progress(final long current, final long max) {
                                    dialog.setProgress((int) current);
                                    dialog.setMax((int) max);
                                }
                            });
                } catch (final Exception e) {
                    Log.e(getClass().getSimpleName(), e.getMessage());
                    Log.e(getClass().getSimpleName(), e.toString());
                }
                return null;
            }
        };
        uploadFile.execute();
    }
}