Search in sources :

Example 61 with AsyncTask

use of android.os.AsyncTask in project xDrip by NightscoutFoundation.

the class Home method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_resend_last_bg:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND));
            break;
        case R.id.action_open_watch_settings:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
            break;
        case R.id.action_sync_watch_db:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESET_DB));
            break;
    }
    if (item.getItemId() == R.id.action_export_database) {
        new AsyncTask<Void, Void, String>() {

            @Override
            protected String doInBackground(Void... params) {
                int permissionCheck = ContextCompat.checkSelfPermission(Home.this, Manifest.permission.READ_EXTERNAL_STORAGE);
                if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(Home.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 0);
                    return null;
                } else {
                    return DatabaseUtil.saveSql(getBaseContext());
                }
            }

            @Override
            protected void onPostExecute(String filename) {
                super.onPostExecute(filename);
                if (filename != null) {
                    snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), "Share database..."), Home.this);
                    startActivity(new Intent(xdrip.getAppContext(), SdcardImportExport.class).putExtra("backup", "now").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                /*    SnackbarManager.show(
                                Snackbar.with(Home.this)
                                        .type(SnackbarType.MULTI_LINE)
                                        .duration(4000)
                                        .text(getString(R.string.exported_to) + filename) // text to display
                                        .actionLabel("Share") // action button label
                                        .actionListener(new SnackbarUriListener(Uri.fromFile(new File(filename)))),
                                Home.this);*/
                } else {
                    Toast.makeText(Home.this, R.string.could_not_export_database, Toast.LENGTH_LONG).show();
                }
            }
        }.execute();
        return true;
    }
    if (item.getItemId() == R.id.action_import_db) {
        startActivity(new Intent(this, ImportDatabaseActivity.class));
        return true;
    }
    if (item.getItemId() == R.id.action_export_csv_sidiary) {
        long from = Pref.getLong("sidiary_last_exportdate", 0);
        final GregorianCalendar date = new GregorianCalendar();
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        if (from > 0)
            datePickerFragment.setInitiallySelectedDate(from);
        datePickerFragment.setAllowFuture(false);
        datePickerFragment.setTitle(getString(R.string.sidiary_date_title));
        datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

            @Override
            public void onDateSet(int year, int month, int day) {
                date.set(year, month, day);
                date.set(Calendar.HOUR_OF_DAY, 0);
                date.set(Calendar.MINUTE, 0);
                date.set(Calendar.SECOND, 0);
                date.set(Calendar.MILLISECOND, 0);
                new AsyncTask<Void, Void, String>() {

                    @Override
                    protected String doInBackground(Void... params) {
                        return DatabaseUtil.saveCSV(getBaseContext(), date.getTimeInMillis());
                    }

                    @Override
                    protected void onPostExecute(String filename) {
                        super.onPostExecute(filename);
                        if (filename != null) {
                            Pref.setLong("sidiary_last_exportdate", System.currentTimeMillis());
                            snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), "Share database..."), Home.this);
                        } else {
                            Toast.makeText(Home.this, "Could not export CSV :(", Toast.LENGTH_LONG).show();
                        }
                    }
                }.execute();
            }
        });
        datePickerFragment.show(getFragmentManager(), "DatePicker");
        return true;
    }
    if (item.getItemId() == R.id.action_toggle_speakreadings) {
        Pref.toggleBoolean("bg_to_speech");
        invalidateOptionsMenu();
        if (Pref.getBooleanDefaultFalse("bg_to_speech")) {
            BgToSpeech.testSpeech();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter) GregorianCalendar(java.util.GregorianCalendar) AsyncTask(android.os.AsyncTask) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) Paint(android.graphics.Paint) Point(android.graphics.Point) File(java.io.File)

Example 62 with AsyncTask

use of android.os.AsyncTask in project xDrip-plus by jamorham.

the class ShareRest method getSessionId.

private String getSessionId() {
    AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() {

        @Override
        protected String doInBackground(String... params) {
            try {
                Boolean isActive = null;
                if (params[0] != null)
                    isActive = dexcomShareApi.checkSessionActive(params[0]).execute().body();
                if (isActive == null || !isActive) {
                    return updateAuthenticationParams();
                } else
                    return params[0];
            } catch (IOException e) {
                return null;
            } catch (RuntimeException e) {
                UserError.Log.wtf(TAG, "Painful exception processing response in updateAuthenticationParams " + e);
                return null;
            }
        }

        private String updateAuthenticationParams() throws IOException {
            sessionId = dexcomShareApi.getSessionId(new ShareAuthenticationBody(password, username).toMap()).execute().body();
            dexcomShareApi.authenticatePublisherAccount(sessionId, serialNumber, new ShareAuthenticationBody(password, username).toMap()).execute().body();
            dexcomShareApi.StartRemoteMonitoringSession(sessionId, serialNumber).execute();
            String assignment = dexcomShareApi.checkMonitorAssignment(sessionId, serialNumber).execute().body();
            if ((assignment != null) && (!assignment.equals("AssignedToYou"))) {
                dexcomShareApi.updateMonitorAssignment(sessionId, serialNumber).execute();
            }
            return sessionId;
        }
    };
    if (sessionId == null || sessionId.equals(""))
        try {
            sessionId = task.executeOnExecutor(xdrip.executor, sessionId).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    return sessionId;
}
Also used : ShareAuthenticationBody(com.eveningoutpost.dexdrip.ShareModels.Models.ShareAuthenticationBody) AsyncTask(android.os.AsyncTask) IOException(java.io.IOException)

Example 63 with AsyncTask

use of android.os.AsyncTask in project android_packages_apps_Settings by omnirom.

the class CryptKeeper method setupUi.

/**
 * Initializes the UI based on the current state of encryption.
 * This is idempotent - calling repeatedly will simply re-initialize the UI.
 */
private void setupUi() {
    if (mEncryptionGoneBad || isDebugView(FORCE_VIEW_ERROR)) {
        setContentView(R.layout.crypt_keeper_progress);
        showFactoryReset(mCorrupt);
        return;
    }
    final String progress = SystemProperties.get("vold.encrypt_progress");
    if (!"".equals(progress) || isDebugView(FORCE_VIEW_PROGRESS)) {
        setContentView(R.layout.crypt_keeper_progress);
        encryptionProgressInit();
    } else if (mValidationComplete || isDebugView(FORCE_VIEW_PASSWORD)) {
        new AsyncTask<Void, Void, Void>() {

            int passwordType = StorageManager.CRYPT_TYPE_PASSWORD;

            String owner_info;

            boolean pattern_visible;

            boolean password_visible;

            @Override
            public Void doInBackground(Void... v) {
                try {
                    final IStorageManager service = getStorageManager();
                    passwordType = service.getPasswordType();
                    owner_info = service.getField(StorageManager.OWNER_INFO_KEY);
                    pattern_visible = !("0".equals(service.getField(StorageManager.PATTERN_VISIBLE_KEY)));
                    password_visible = !("0".equals(service.getField(StorageManager.PASSWORD_VISIBLE_KEY)));
                } catch (Exception e) {
                    Log.e(TAG, "Error calling mount service " + e);
                }
                return null;
            }

            @Override
            public void onPostExecute(java.lang.Void v) {
                Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, password_visible ? 1 : 0);
                if (passwordType == StorageManager.CRYPT_TYPE_PIN) {
                    setContentView(R.layout.crypt_keeper_pin_entry);
                    mStatusString = R.string.enter_pin;
                } else if (passwordType == StorageManager.CRYPT_TYPE_PATTERN) {
                    setContentView(R.layout.crypt_keeper_pattern_entry);
                    setBackFunctionality(false);
                    mStatusString = R.string.enter_pattern;
                } else {
                    setContentView(R.layout.crypt_keeper_password_entry);
                    mStatusString = R.string.enter_password;
                }
                final TextView status = (TextView) findViewById(R.id.status);
                status.setText(mStatusString);
                final TextView ownerInfo = (TextView) findViewById(R.id.owner_info);
                ownerInfo.setText(owner_info);
                // Required for marquee'ing to work
                ownerInfo.setSelected(true);
                passwordEntryInit();
                findViewById(android.R.id.content).setSystemUiVisibility(View.STATUS_BAR_DISABLE_BACK);
                if (mLockPatternView != null) {
                    mLockPatternView.setInStealthMode(!pattern_visible);
                }
                if (mCooldown) {
                    // in case we are cooling down and coming back from emergency dialler
                    setBackFunctionality(false);
                    cooldown();
                }
            }
        }.execute();
    } else if (!mValidationRequested) {
        // We're supposed to be encrypted, but no validation has been done.
        new ValidationTask().execute((Void[]) null);
        mValidationRequested = true;
    }
}
Also used : IStorageManager(android.os.storage.IStorageManager) AsyncTask(android.os.AsyncTask) TextView(android.widget.TextView) NotFoundException(android.content.res.Resources.NotFoundException) RemoteException(android.os.RemoteException)

Example 64 with AsyncTask

use of android.os.AsyncTask in project android_packages_apps_Settings by omnirom.

the class NotificationSoundPreference method updateRingtoneName.

private void updateRingtoneName(final Uri uri) {
    AsyncTask ringtoneNameTask = new AsyncTask<Object, Void, CharSequence>() {

        @Override
        protected CharSequence doInBackground(Object... params) {
            if (uri == null) {
                return getContext().getString(com.android.internal.R.string.ringtone_silent);
            } else if (RingtoneManager.isDefault(uri)) {
                return getContext().getString(R.string.notification_sound_default);
            } else if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())) {
                return getContext().getString(R.string.notification_unknown_sound_title);
            } else {
                return Ringtone.getTitle(getContext(), uri, false, /* followSettingsUri */
                true);
            }
        }

        @Override
        protected void onPostExecute(CharSequence name) {
            setSummary(name);
        }
    };
    ringtoneNameTask.execute();
}
Also used : AsyncTask(android.os.AsyncTask)

Example 65 with AsyncTask

use of android.os.AsyncTask in project android_packages_apps_Settings by omnirom.

the class DefaultNotificationTonePreference method updateRingtoneName.

private void updateRingtoneName(final Uri uri) {
    AsyncTask ringtoneNameTask = new AsyncTask<Object, Void, CharSequence>() {

        @Override
        protected CharSequence doInBackground(Object... params) {
            return Ringtone.getTitle(mUserContext, uri, false, /* followSettingsUri */
            true);
        }

        @Override
        protected void onPostExecute(CharSequence name) {
            setSummary(name);
        }
    };
    ringtoneNameTask.execute();
}
Also used : AsyncTask(android.os.AsyncTask)

Aggregations

AsyncTask (android.os.AsyncTask)394 IOException (java.io.IOException)188 InputStream (java.io.InputStream)159 URL (java.net.URL)159 HttpURLConnection (java.net.HttpURLConnection)158 ExecutionException (java.util.concurrent.ExecutionException)158 Gson (com.google.gson.Gson)155 Message (com.remswork.project.alice.model.support.Message)153 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)102 ArrayList (java.util.ArrayList)93 View (android.view.View)54 Intent (android.content.Intent)52 TextView (android.widget.TextView)52 JSONException (org.json.JSONException)51 JSONArray (org.json.JSONArray)50 DialogInterface (android.content.DialogInterface)40 OutputStream (java.io.OutputStream)37 BufferedWriter (java.io.BufferedWriter)35 OutputStreamWriter (java.io.OutputStreamWriter)35 ImageView (android.widget.ImageView)33