Example usage for android.app ProgressDialog hide

List of usage examples for android.app ProgressDialog hide

Introduction

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

Prototype

public void hide() 

Source Link

Document

Hide the dialog, but do not dismiss it.

Usage

From source file:net.kourlas.voipms_sms.gcm.Gcm.java

/**
 * Registers for Google Cloud Messaging. Sends the registration token to the application servers.
 *
 * @param activity     The activity that initiated the registration.
 * @param showFeedback If true, shows a dialog at the end of the registration process indicating the success or
 *                     failure of the process.
 * @param force        If true, retrieves a new registration token even if one is already stored.
 *///from   w ww .jav  a2 s  .c  o  m
public void registerForGcm(final Activity activity, final boolean showFeedback, boolean force) {
    if (!preferences.getNotificationsEnabled()) {
        return;
    }
    if (preferences.getDid().equals("")) {
        // Do not show an error; this method should never be called unless a DID is set
        return;
    }
    if (!checkPlayServices(activity, showFeedback)) {
        return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    if (showFeedback) {
        progressDialog.setMessage(applicationContext.getString(R.string.notifications_gcm_progress));
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    final InstanceID instanceIdObj = InstanceID.getInstance(applicationContext);
    final String instanceId = instanceIdObj.getId();
    if (preferences.getGcmToken().equals("") || !instanceId.equals(preferences.getGcmInstanceId()) || force) {
        new AsyncTask<Boolean, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(Boolean... params) {
                try {
                    String token = instanceIdObj.getToken(
                            applicationContext.getString(R.string.notifications_gcm_sender_id),
                            GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

                    String registrationBackendUrl = "https://voipmssms-kourlas.rhcloud.com/register?" + "did="
                            + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "reg_id="
                            + URLEncoder.encode(token, "UTF-8");
                    JSONObject result = Utils.getJson(registrationBackendUrl);
                    String status = result.optString("status");
                    if (status == null || !status.equals("success")) {
                        return false;
                    }

                    preferences.setGcmInstanceId(instanceId);
                    preferences.setGcmToken(token);

                    return true;
                } catch (Exception ex) {
                    return false;
                }
            }

            @Override
            protected void onPostExecute(Boolean success) {
                if (showFeedback) {
                    progressDialog.hide();
                    if (!success) {
                        Utils.showInfoDialog(activity,
                                applicationContext.getResources().getString(R.string.notifications_gcm_fail));
                    } else {
                        Utils.showInfoDialog(activity, applicationContext.getResources()
                                .getString(R.string.notifications_gcm_success));
                    }
                }
            }
        }.execute();
    } else if (showFeedback) {
        Utils.showInfoDialog(activity,
                applicationContext.getResources().getString(R.string.notifications_gcm_success));
    }
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

private void installFiles(final SharedPreferences preferences) {
    final ProgressDialog dialog = new ProgressDialog(this);
    final UnzipTask unzipTask = new UnzipTask(app.configuration.getCthPath() + "/scripts/", this) {

        @Override/*from w  w w  .  ja v a  2s .co m*/
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setMessage(getString(R.string.preparing_game_files_dialog));
            dialog.setIndeterminate(false);
            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            dialog.setProgress(values[0]);
            dialog.setMax(values[1]);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<String> result) {
            super.onPostExecute(result);
            Exception error;
            if ((error = result.getError()) != null) {
                Log.d(LOG_TAG, "Error copying files.");
                BugSenseHandler.sendException(error);
            }

            Editor edit = preferences.edit();
            edit.putBoolean("scripts_copied", true);
            edit.putInt("last_version", currentVersion);
            edit.commit();
            dialog.hide();
            loadApplication();
        }

    };

    AsyncTask<String, Void, AsyncTaskResult<File>> copyTask = new

    AsyncTask<String, Void, AsyncTaskResult<File>>() {

        @Override
        protected AsyncTaskResult<File> doInBackground(String... params) {

            try {
                Files.copyAsset(SDLActivity.this, params[0], params[1]);
            } catch (IOException e) {

                return new AsyncTaskResult<File>(e);
            }
            return new AsyncTaskResult<File>(new File(params[1] + "/" + params[0]));
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<File> result) {
            super.onPostExecute(result);
            File f;
            if ((f = result.getResult()) != null) {
                unzipTask.execute(f);
            } else {
                BugSenseHandler.sendException(result.getError());

            }
        }

    };

    if (Files.canAccessExternalStorage()) {

        copyTask.execute(ENGINE_ZIP_FILE, getExternalCacheDir().getAbsolutePath());
    } else {
        DialogFactory.createExternalStorageWarningDialog(this, true).show();
    }
}

From source file:com.example.android.camera2basic.fragments.Camera2BasicFragment.java

public void upload() {

    //Crea y muestra barra de progreso
    final ProgressDialog mProgressDialog = new ProgressDialog(getActivity());

    mProgressDialog.setIndeterminate(false);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setMessage("Subiendo foto...");

    mProgressDialog.show();/*  w ww  .j  ava  2s .  c o m*/

    //Retrofit
    Retrofit retrofit = new Retrofit.Builder().baseUrl(FileUploadService.ENDPOINT)
            .addConverterFactory(GsonConverterFactory.create()).build();

    // create upload service client
    FileUploadService service = retrofit.create(FileUploadService.class);

    // create RequestBody instance from file
    RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), mFile);

    // MultipartBody.Part is used to send also the actual file name
    MultipartBody.Part body = MultipartBody.Part.createFormData("fichero", mFile.getName(), requestFile);

    // finally, execute the request
    Call<ResponseBody> call = service.upload(body);
    call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

            if (response.isSuccessful()) {
                mProgressDialog.hide();//Oculta progressDialog

                showToast("Upload picture success");

                Log.v(TAG, "success");
            } else {
                mProgressDialog.hide();//Oculta progressDialog

                showToast("Upload error:" + response.code());

                Log.e(TAG, "Code: " + response.code());
            }

        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            mProgressDialog.hide();//Oculta progressDialog

            showToast("Upload error:" + t.getMessage());

            Log.e(TAG, "onfailure: " + t.getMessage());
        }
    });

}

From source file:me.kartikarora.transfersh.activities.TransferActivity.java

private void uploadFile(Uri uri) throws IOException {
    final ProgressDialog dialog = new ProgressDialog(TransferActivity.this);
    dialog.setMessage(getString(R.string.uploading_file));
    dialog.setCancelable(false);//from w w w  .j a va2s  .com
    dialog.show();
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
        final String name = cursor.getString(nameIndex);
        final String mimeType = getContentResolver().getType(uri);
        Log.d(this.getClass().getSimpleName(), cursor.getString(0));
        Log.d(this.getClass().getSimpleName(), name);
        Log.d(this.getClass().getSimpleName(), mimeType);
        InputStream inputStream = getContentResolver().openInputStream(uri);
        OutputStream outputStream = openFileOutput(name, MODE_PRIVATE);
        if (inputStream != null) {
            IOUtils.copy(inputStream, outputStream);
            final File file = new File(getFilesDir(), name);
            TypedFile typedFile = new TypedFile(mimeType, file);
            TransferClient.getInterface().uploadFile(typedFile, name, new ResponseCallback() {
                @Override
                public void success(Response response) {
                    BufferedReader reader;
                    StringBuilder sb = new StringBuilder();
                    try {
                        reader = new BufferedReader(new InputStreamReader(response.getBody().in()));
                        String line;
                        try {
                            while ((line = reader.readLine()) != null) {
                                sb.append(line);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    String result = sb.toString();
                    Snackbar.make(mCoordinatorLayout, name + " " + getString(R.string.uploaded),
                            Snackbar.LENGTH_SHORT).show();

                    ContentValues values = new ContentValues();
                    values.put(FilesContract.FilesEntry.COLUMN_NAME, name);
                    values.put(FilesContract.FilesEntry.COLUMN_TYPE, mimeType);
                    values.put(FilesContract.FilesEntry.COLUMN_URL, result);
                    values.put(FilesContract.FilesEntry.COLUMN_SIZE, String.valueOf(file.getTotalSpace()));
                    getContentResolver().insert(FilesContract.BASE_CONTENT_URI, values);
                    getSupportLoaderManager().restartLoader(BuildConfig.VERSION_CODE, null,
                            TransferActivity.this);
                    FileUtils.deleteQuietly(file);
                    if (dialog.isShowing())
                        dialog.hide();
                }

                @Override
                public void failure(RetrofitError error) {
                    error.printStackTrace();
                    if (dialog.isShowing())
                        dialog.hide();
                    Snackbar.make(mCoordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.report, new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    // TODO add feedback code
                                }
                            }).show();
                }
            });
        } else
            Snackbar.make(mCoordinatorLayout, R.string.unable_to_read, Snackbar.LENGTH_SHORT).show();
    }
}

From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java

private void addNotification() {
    // Error checking
    if (mSensorValue.getText().length() == 0) {
        mSensorValue.setError(getString(R.string.error_empty_value));
        return;//from ww  w  .j  av a2  s .c o  m
    }

    final ProgressDialog progress = ProgressDialog.show(this, "",
            getResources().getString(R.string.adding_notification), false);

    NotificationInfo notificationInfo = null;
    String condition = "";
    switch (mConditionSpinner.getSelectedItemPosition()) {
    case 0:
        condition = ">=";
        break;
    case 1:
        condition = "=<";
        break;
    }

    Boolean ringOnce = mRingOnceCheckbox.isChecked();

    switch (mDeviceSpinner.getSelectedItemPosition()) {
    case 0: // System
        switch (mTypeSpinner.getSelectedItemPosition()) {
        case 0: // Temperature
            notificationInfo = new NotificationInfo(
                    mSystemTempSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 1: // Fan
            notificationInfo = new NotificationInfo(
                    mSystemFanSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 2: // Voltage
            notificationInfo = new NotificationInfo(
                    mSystemVoltSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        }
        break;
    case 1: // CPU
        switch (mTypeSpinner.getSelectedItemPosition()) {
        case 0: // Temp
            notificationInfo = new NotificationInfo(
                    mCPUTempSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 1: // Power
            notificationInfo = new NotificationInfo(
                    mCPUPowerSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 2: // Load
            notificationInfo = new NotificationInfo(
                    mCPULoadSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 3: // Clock
            notificationInfo = new NotificationInfo(
                    mCPUClockSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        }
        break;
    case 2: // GPU
        switch (mTypeSpinner.getSelectedItemPosition()) {
        case 0: // Temp
            notificationInfo = new NotificationInfo(
                    mGPUTempSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 1: // Fan
            notificationInfo = new NotificationInfo(
                    mGPUFanSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 2: // Load
            notificationInfo = new NotificationInfo(
                    mGPULoadSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        case 3: // Clock
            notificationInfo = new NotificationInfo(
                    mGPUClockSensors[mSensorSpinner.getSelectedItemPosition()].getName(), "Temperature",
                    condition, mSensorValue.getText().toString(), ringOnce);
            break;
        }
    }

    // Add notification
    RequestParams params = new RequestParams();
    params.put("type", "addnotif");
    params.put("id", String.valueOf(mSettings.getLong("device_id", -2)));

    params.put("name", notificationInfo.getNotificationName());
    params.put("ntype", notificationInfo.getNotificationType());
    params.put("condition", notificationInfo.getCondition());
    params.put("value", notificationInfo.getNotificationValue());
    params.put("ringonce", notificationInfo.getRingOnce().toString());

    final Activity context = this;

    mClient.get(mURL, params, new TextHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, String responseBody) {
            progress.hide();
            Toast.makeText(context, "Notification added", Toast.LENGTH_SHORT).show();
            finish();
        }

        @Override
        public void onFailure(String responseBody, Throwable error) {
            progress.hide();
            Toast.makeText(context, "Could not add notification: " + error.getMessage(), Toast.LENGTH_LONG)
                    .show();
        }
    });
}

From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_add_notification);
    mSettings = getSharedPreferences(MainViewActivity.SHAREDPREFS_FILE, 0);

    // Prepare buttons
    findViewById(R.id.button_add).setOnClickListener(this);
    findViewById(R.id.button_cancel).setOnClickListener(this);
    findViewById(R.id.button_notification_help).setOnClickListener(this);

    // Prepare spinners
    mDeviceSpinner = (Spinner) findViewById(R.id.spinner_device);
    mTypeSpinner = (Spinner) findViewById(R.id.spinner_type);
    mSensorSpinner = (Spinner) findViewById(R.id.spinner_sensor);
    mConditionSpinner = (Spinner) findViewById(R.id.spinner_condition);

    // Edittext/*from  w  ww .  j  a  v  a 2s  .c  om*/
    mSensorValue = (EditText) findViewById(R.id.editText_value);

    // Checkbox
    mRingOnceCheckbox = (CheckBox) findViewById(R.id.checkbox_notif_ringonce);

    // URL
    mURL = getIntent().getExtras().getString(MainViewActivity.EXTRA_ADDRESS);

    // Client
    mClient.setMaxRetriesAndTimeout(2, 2000);

    // Retrieve sensors
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("type", "listdev");
    params.put("id", String.valueOf(mSettings.getLong("device_id", -2)));

    final Activity context = this;
    final ProgressDialog progress = ProgressDialog.show(this, "",
            getResources().getString(R.string.retrieving_devices), false);

    mClient.get(mURL, params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            try {
                // System
                JSONArray systemResponse = response.getJSONArray("System");

                int len = systemResponse.length();
                int lenTemp = 0;
                int lenFan = 0;
                int lenVolt = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(systemResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        lenTemp++;
                    } else if (sensor.getType().equals("Fan")) {
                        lenFan++;
                    } else if (sensor.getType().equals("Voltage")) {
                        lenVolt++;
                    }
                }

                mSystemTempSensors = new Sensor[lenTemp];
                mSystemFanSensors = new Sensor[lenFan];
                mSystemVoltSensors = new Sensor[lenVolt];

                int iTemp = 0;
                int iFan = 0;
                int iVolt = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(systemResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        mSystemTempSensors[iTemp] = sensor;
                        iTemp++;
                    } else if (sensor.getType().equals("Fan")) {
                        mSystemFanSensors[iFan] = sensor;
                        iFan++;
                    } else if (sensor.getType().equals("Voltage")) {
                        mSystemVoltSensors[iVolt] = sensor;
                        iVolt++;
                    }
                }

                // CPU
                JSONArray cpuResponse = response.getJSONArray("CPU");

                len = cpuResponse.length();
                lenTemp = 0;
                int lenLoad = 0;
                int lenClock = 0;
                int lenPower = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(cpuResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        lenTemp++;
                    } else if (sensor.getType().equals("Load")) {
                        lenLoad++;
                    } else if (sensor.getType().equals("Clock")) {
                        lenClock++;
                    } else if (sensor.getType().equals("Power")) {
                        lenPower++;
                    }
                }

                mCPUTempSensors = new Sensor[lenTemp];
                mCPULoadSensors = new Sensor[lenLoad];
                mCPUPowerSensors = new Sensor[lenPower];
                mCPUClockSensors = new Sensor[lenClock];

                iTemp = 0;
                int iLoad = 0;
                int iPower = 0;
                int iClock = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(cpuResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        mCPUTempSensors[iTemp] = sensor;
                        iTemp++;
                    } else if (sensor.getType().equals("Power")) {
                        mCPUPowerSensors[iPower] = sensor;
                        iPower++;
                    } else if (sensor.getType().equals("Clock")) {
                        mCPUClockSensors[iClock] = sensor;
                        iClock++;
                    } else if (sensor.getType().equals("Load")) {
                        mCPULoadSensors[iLoad] = sensor;
                        iLoad++;
                    }
                }

                // GPU
                JSONArray gpuResponse = response.getJSONArray("GPU");

                len = gpuResponse.length();
                lenTemp = 0;
                lenLoad = 0;
                lenClock = 0;
                lenFan = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(gpuResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        lenTemp++;
                    } else if (sensor.getType().equals("Load")) {
                        lenLoad++;
                    } else if (sensor.getType().equals("Clock")) {
                        lenClock++;
                    } else if (sensor.getType().equals("Fan")) {
                        lenFan++;
                    }
                }

                mGPUTempSensors = new Sensor[lenTemp];
                mGPULoadSensors = new Sensor[lenLoad];
                mGPUFanSensors = new Sensor[lenFan];
                mGPUClockSensors = new Sensor[lenClock];

                iTemp = 0;
                iLoad = 0;
                iClock = 0;
                iFan = 0;

                for (int i = 0; i < len; i++) {
                    Sensor sensor = new Sensor(gpuResponse.getJSONObject(i));

                    if (sensor.getType().equals("Temperature")) {
                        mGPUTempSensors[iTemp] = sensor;
                        iTemp++;
                    } else if (sensor.getType().equals("Fan")) {
                        mGPUFanSensors[iFan] = sensor;
                        iFan++;
                    } else if (sensor.getType().equals("Clock")) {
                        mGPUClockSensors[iClock] = sensor;
                        iClock++;
                    } else if (sensor.getType().equals("Load")) {
                        mGPULoadSensors[iLoad] = sensor;
                        iLoad++;
                    }
                }

                // Prepare spinners
                setAdapter(mSensorSpinner, mSystemTempSensors);

                mTypeSpinner.setOnItemSelectedListener(new TypeOnItemSelectedListener());
                mDeviceSpinner.setOnItemSelectedListener(new DeviceOnItemSelectedListener());

                // Close window
                progress.hide();
            } catch (JSONException e) {
                Toast.makeText(context, getString(R.string.error_could_not_reach_host), Toast.LENGTH_LONG)
                        .show();
                progress.hide();
            }
        }

        @Override
        public void onFailure(Throwable error, String content) {
            Toast.makeText(context, getString(R.string.error_could_not_reach_host) + ":" + error.getMessage(),
                    Toast.LENGTH_LONG).show();
            finish();
            progress.hide();
            Log.e("Notif", error.getMessage());
        }
    });
}