Search in sources :

Example 46 with AsyncTask

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

the class AlarmClockFragment method asyncAddAlarm.

private void asyncAddAlarm(final Alarm alarm, final boolean expand) {
    final Context context = getActivity().getApplicationContext();
    final AsyncTask<Void, Void, AlarmInstance> updateTask = new AsyncTask<Void, Void, AlarmInstance>() {

        @Override
        protected AlarmInstance doInBackground(Void... parameters) {
            if (context != null && alarm != null) {
                ContentResolver cr = context.getContentResolver();
                // Add alarm to db
                Alarm newAlarm = Alarm.addAlarm(cr, alarm);
                mScrollToAlarmId = newAlarm.id;
                if (expand) {
                    mExpandedId = newAlarm.id;
                }
                // Create and add instance to db
                if (newAlarm.enabled) {
                    sDeskClockExtensions.addAlarm(context, newAlarm);
                    return setupAlarmInstance(context, newAlarm);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(AlarmInstance instance) {
            if (instance != null) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                boolean noAlarmSoundHintShown = prefs.getBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, false);
                boolean hintShown = prefs.getBoolean(PREF_KEY_ALARM_HINT_SHOWN, false);
                if (!instance.mRingtone.equals(Alarm.NO_RINGTONE_URI)) {
                    Uri defaultAlarm = Utils.getDefaultAlarmUri(getActivity());
                    if (defaultAlarm == null) {
                        if (!noAlarmSoundHintShown) {
                            // show hint that this alarm has been created with alarm tone choosen
                            AlarmUtils.popNoDefaultAlarmSoundToast(context);
                            prefs.edit().putBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, true).commit();
                            return;
                        }
                    }
                }
                if (!hintShown) {
                    AlarmUtils.popFirstAlarmCreatedToast(context);
                    prefs.edit().putBoolean(PREF_KEY_ALARM_HINT_SHOWN, true).commit();
                } else {
                    AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
                }
            }
        }
    };
    updateTask.execute();
}
Also used : Context(android.content.Context) AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) SharedPreferences(android.content.SharedPreferences) Alarm(org.omnirom.deskclock.provider.Alarm) AsyncTask(android.os.AsyncTask) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 47 with AsyncTask

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

the class AlarmClockFragment method asyncDeleteAlarm.

private void asyncDeleteAlarm(final Alarm alarm) {
    final Context context = getActivity().getApplicationContext();
    final AsyncTask<Void, Void, Void> deleteTask = new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... parameters) {
            // Activity may be closed at this point , make sure data is still valid
            if (context != null && alarm != null) {
                ContentResolver cr = context.getContentResolver();
                AlarmStateManager.deleteAllInstances(context, alarm.id);
                Alarm.deleteAlarm(cr, alarm.id);
                sDeskClockExtensions.deleteAlarm(context, alarm.id);
            }
            return null;
        }
    };
    mUndoShowing = true;
    deleteTask.execute();
}
Also used : Context(android.content.Context) AsyncTask(android.os.AsyncTask) ContentResolver(android.content.ContentResolver)

Example 48 with AsyncTask

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

the class AlarmClockFragment method asyncUpdateAlarm.

private void asyncUpdateAlarm(final Alarm alarm, final boolean popToast) {
    final Context context = getActivity().getApplicationContext();
    final AsyncTask<Void, Void, AlarmInstance> updateTask = new AsyncTask<Void, Void, AlarmInstance>() {

        @Override
        protected AlarmInstance doInBackground(Void... parameters) {
            ContentResolver cr = context.getContentResolver();
            // Dismiss all old instances
            AlarmStateManager.deleteAllInstances(context, alarm.id);
            // Update alarm
            Alarm.updateAlarm(cr, alarm);
            if (alarm.enabled) {
                return setupAlarmInstance(context, alarm);
            }
            return null;
        }

        @Override
        protected void onPostExecute(AlarmInstance instance) {
            if (popToast && instance != null) {
                AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
            }
        }
    };
    updateTask.execute();
}
Also used : Context(android.content.Context) AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) AsyncTask(android.os.AsyncTask) ContentResolver(android.content.ContentResolver)

Example 49 with AsyncTask

use of android.os.AsyncTask in project MTweaks-KernelAdiutorMOD by morogoku.

the class BackupFragment method reload.

private void reload() {
    if (mLoader == null) {
        getHandler().postDelayed(new Runnable() {

            @Override
            public void run() {
                clearItems();
                mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        showProgress();
                    }

                    @Override
                    protected List<RecyclerViewItem> doInBackground(Void... voids) {
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> items) {
                        super.onPostExecute(items);
                        for (RecyclerViewItem item : items) {
                            addItem(item);
                        }
                        hideProgress();
                        mLoader = null;
                    }
                };
                mLoader.execute();
            }
        }, 250);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 50 with AsyncTask

use of android.os.AsyncTask in project MTweaks-KernelAdiutorMOD by morogoku.

the class OnBootFragment method reload.

private void reload() {
    if (mLoader == null) {
        getHandler().postDelayed(new Runnable() {

            @Override
            public void run() {
                mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        clearItems();
                        showProgress();
                    }

                    @Override
                    protected List<RecyclerViewItem> doInBackground(Void... voids) {
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
                        super.onPostExecute(recyclerViewItems);
                        for (RecyclerViewItem item : recyclerViewItems) {
                            addItem(item);
                        }
                        hideProgress();
                        mLoader = null;
                    }
                };
                mLoader.execute();
            }
        }, 250);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

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