Java 类android.os.AsyncTask 实例源码
项目:QuranAndroid
文件:DownloadTafseerService.java
/**
* Function to start service
*
* @param intent Activity intent
* @param flags to start sticky or not
* @param startId Service id
* @return usually start or start once
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("TAFSEER_DOWN_TAG" , "tafseer service is start");
AppPreference.Downloading(true);
Bundle extras = intent.getExtras();
String downloadURL = extras.getString(AppConstants.Download.DOWNLOAD_URL);
String downloadLocation = extras.getString(AppConstants.Download.DOWNLOAD_LOCATION);
int type = extras.getInt(AppConstants.Download.TYPE , -1);
List<String> downloadLinks = extras.getStringArrayList(AppConstants.Download.DOWNLOAD_LINKS);
if(downloadLinks == null){
downloadManager = new DownloadManager(this, true ,type);
downloadManager.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadURL, downloadLocation);
} else{
downloadManager = new DownloadManager(this, true, downloadLinks ,type);
downloadManager.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "", downloadLocation);
}
return START_NOT_STICKY;
}
项目:Cable-Android
文件:ConversationActivity.java
@Override
public void onRecorderCanceled() {
Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(50);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {
@Override
public void onSuccess(final Pair<Uri, Long> result) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first);
return null;
}
}.execute();
}
@Override
public void onFailure(ExecutionException e) {}
});
}
项目:easyappointments-android-client
文件:ServiceModel.java
public ServiceModel(){
super();
categoryTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
CategoryService client = CategoryServiceFactory.getInstance();
try {
CategoryModel c = client.get(categoryId).execute().body();
categoryModel = c;
} catch (IOException e) {
Log.e("AppointmentsModel", "Error loading category");
}
return (Void)null;
}
@Override
protected void onPostExecute(Void aVoid) {
categoryTask = null;
}
};
}
项目:RoadLab-Pro
文件:SelectProjectDialog.java
private void initList() {
new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
if (currentPage == 0) {
Cursor foldersCursor = folderDao.getAllFolderCursor();
adapter = new FoldersAdapter(getContext(), foldersCursor, 0, folderDao);
} else if (currentPage == 1) {
Cursor roadsCursor = null;
if (selectedFolder < 0) {
roadsCursor = roadDao.getAllRoadCursor();
} else {
roadsCursor = roadDao.getAllRoadByFolderIdCursor(selectedFolder);
}
adapter = new RoadsAdapter(getContext(), roadsCursor, 0, roadDao, selectedFolder);
}
return null;
}
@Override
protected void onPostExecute(Object o) {
setupTitle();
valuesList.setAdapter(adapter);
}
}.execute();
}
项目:ubiquitous
文件:SunshineFirebaseJobService.java
/**
* The entry point to your Job. Implementations should offload work to another thread of
* execution as soon as possible.
*
* This is called by the Job Dispatcher to tell us we should start our job. Keep in mind this
* method is run on the application's main thread, so we need to offload work to a background
* thread.
*
* @return whether there is more work remaining.
*/
@Override
public boolean onStartJob(final JobParameters jobParameters) {
mFetchWeatherTask = new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... voids) {
Context context = getApplicationContext();
SunshineSyncTask.syncWeather(context);
jobFinished(jobParameters, false);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
jobFinished(jobParameters, false);
}
};
mFetchWeatherTask.execute();
return true;
}
项目:PlayStoreParallelDownload
文件:DownloadService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String url = " ";
int position = -1;
if (intent != null) {
url = intent.getStringExtra("url");
position = intent.getIntExtra("position", -1);
}
String[] params = new String[]{url, String.valueOf(position)};
new DownloadingTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
return START_NOT_STICKY;
}
项目:Cable-Android
文件:InviteReminder.java
public InviteReminder(final @NonNull Context context,
final @NonNull Recipients recipients)
{
super(context.getString(R.string.reminder_header_invite_title),
context.getString(R.string.reminder_header_invite_text, recipients.toShortString()));
setDismissListener(new OnClickListener() {
@Override public void onClick(View v) {
new AsyncTask<Void,Void,Void>() {
@Override protected Void doInBackground(Void... params) {
DatabaseFactory.getRecipientPreferenceDatabase(context).setSeenInviteReminder(recipients, true);
return null;
}
}.execute();
}
});
}
项目:VulcanOTA
文件:SlimOTAFragment.java
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
final String key = preference.getKey();
switch (key) {
case KEY_CHECK_UPDATE:
mTask = CheckUpdateTask.getInstance(false);
if (!mTask.getStatus().equals(AsyncTask.Status.RUNNING)) {
mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
}
return true;
case KEY_CHANGELOG:
ChangelogFragment changelogFrag = new ChangelogFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
transaction.replace(this.getId(), changelogFrag);
transaction.addToBackStack(this.getClass().getName());
transaction.commit();
return true;
default:
OTALink link = LinkConfig.getInstance().findLink(key, getActivity());
if (link != null) {
OTAUtils.launchUrl(link.getUrl(), getActivity());
}
break;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
项目:chromium-for-android-56-debug-video
文件:PrintShareActivity.java
private static void unregisterActivity(final Activity activity) {
ThreadUtils.assertOnUiThread();
sPendingShareActivities.remove(activity);
if (!sPendingShareActivities.isEmpty()) return;
ApplicationStatus.unregisterActivityStateListener(sStateListener);
waitForPendingStateChangeTask();
sStateChangeTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (!sPendingShareActivities.isEmpty()) return null;
activity.getPackageManager().setComponentEnabledSetting(
new ComponentName(activity, PrintShareActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
return null;
}
@Override
protected void onPostExecute(Void result) {
if (sStateChangeTask == this) sStateChangeTask = null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:android-titanium-imagecropper
文件:CropImageView.java
/**
* Sets a bitmap loaded from the given Android URI as the content of the CropImageView.<br>
* Can be used with URI from gallery or camera source.<br>
* Will rotate the image by exif data.<br>
*
* @param uri the URI to load the image from
*/
public void setImageUriAsync(Uri uri) {
if (uri != null) {
BitmapLoadingWorkerTask currentTask =
mBitmapLoadingWorkerTask != null ? mBitmapLoadingWorkerTask.get() : null;
if (currentTask != null) {
// cancel previous loading (no check if the same URI because camera URI can be the same for
// different images)
currentTask.cancel(true);
}
// either no existing task is working or we canceled it, need to load new URI
clearImageInt();
mRestoreCropWindowRect = null;
mRestoreDegreesRotated = 0;
mCropOverlayView.setInitialCropWindowRect(null);
mBitmapLoadingWorkerTask = new WeakReference<>(new BitmapLoadingWorkerTask(this, uri));
mBitmapLoadingWorkerTask.get().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
setProgressBarVisibility();
}
}
项目:Opal-Chat-AnalyticsDashboard
文件:BotStuff.java
public static void getResponse(String input, final BotCallback<String> callback) {
final CleverBotQuery bot = new CleverBotQuery(API_KEY, input);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
String response;
try {
bot.sendRequest();
response = bot.getResponse();
callback.onSuccess(response);
} catch (IOException e) {
response = e.getMessage();
callback.onFailure(response);
}
}
});
}
项目:GoUbiquitous
文件:SunshineFirebaseJobService.java
/**
* The entry point to your Job. Implementations should offload work to another thread of
* execution as soon as possible.
*
* This is called by the Job Dispatcher to tell us we should start our job. Keep in mind this
* method is run on the application's main thread, so we need to offload work to a background
* thread.
*
* @return whether there is more work remaining.
*/
@Override
public boolean onStartJob(final JobParameters jobParameters) {
mFetchWeatherTask = new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... voids) {
Context context = getApplicationContext();
SunshineSyncTask.syncWeather(context);
jobFinished(jobParameters, false);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
jobFinished(jobParameters, false);
}
};
mFetchWeatherTask.execute();
return true;
}
项目:GitHub
文件:ReadEPubActivity.java
@Override
public void configViews() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
loadBook();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
initPager();
initTocList();
}
}.execute();
}
项目:RoadLab-Pro
文件:SyncDataManager.java
public void uploadSingleRoad(final RoadModel road, final String dropboxPath,
final MeasurementsDataHelper.MeasurementsDataLoaderListener listener) {
initUpload();
//showProgress(true);
new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object[] params) {
checkValidToken();
long folderId = road.getFolderId();
FolderModel folder = folderDAO.getFolder(folderId);
checkDataDirs(dropboxPath, folder, road, DataSyncMode.ROAD);
uploadRoad(folder, road, dropboxPath);
return null;
}
@Override
protected void onPostExecute(Object o) {
showProgress(false);
if (listener != null) {
listener.onDataLoaded(true);
}
}
}.execute();
}
项目:iosched-reader
文件:ForceAppDataSyncNowAction.java
@Override
public void run(final Context context, final Callback callback) {
new AsyncTask<Context, Void, Void>() {
@Override
protected Void doInBackground(Context... params) {
final AbstractUserDataSyncHelper syncer = UserDataSyncHelperFactory.buildSyncHelper(
context, AccountUtils.getActiveAccountName(context));
syncer.sync();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
callback.done(true, "Sync done");
}
}.execute(context);
}
项目:RNLearn_Project1
文件:CameraRollManager.java
/**
* Get photos from {@link MediaStore.Images}, most recent first.
*
* @param params a map containing the following keys:
* <ul>
* <li>first (mandatory): a number representing the number of photos to fetch</li>
* <li>
* after (optional): a cursor that matches page_info[end_cursor] returned by a
* previous call to {@link #getPhotos}
* </li>
* <li>groupName (optional): an album name</li>
* <li>
* mimeType (optional): restrict returned images to a specific mimetype (e.g.
* image/jpeg)
* </li>
* </ul>
* @param promise the Promise to be resolved when the photos are loaded; for a format of the
* parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
*/
@ReactMethod
public void getPhotos(final ReadableMap params, final Promise promise) {
int first = params.getInt("first");
String after = params.hasKey("after") ? params.getString("after") : null;
String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
ReadableArray mimeTypes = params.hasKey("mimeTypes")
? params.getArray("mimeTypes")
: null;
if (params.hasKey("groupTypes")) {
throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android");
}
new GetPhotosTask(
getReactApplicationContext(),
first,
after,
groupName,
mimeTypes,
promise)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:MakiLite
文件:ImageGrabber.java
/**
* Reads the given file as Bitmap in the background. The appropriate callback
* of the provided <i>OnImageReadListener</i> will be triggered upon completion.
* @param imageFile the file to read
* @param listener the listener to notify the caller when the
* image read operation finishes
* @since 1.1
*/
public static void readFromDiskAsync(@NonNull File imageFile, @NonNull final OnImageReadListener listener) {
new AsyncTask<String, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(String... params) {
return BitmapFactory.decodeFile(params[0]);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null)
listener.onImageRead(bitmap);
else
listener.onReadFailed();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imageFile.getAbsolutePath());
}
项目:mapbox-plugins-android
文件:ClusterManagerPlugin.java
/**
* Force a re-cluster. You may want to call this after adding new item(s).
*/
public void cluster() {
mClusterTaskLock.writeLock().lock();
try {
// Attempt to cancel the in-flight request.
mClusterTask.cancel(true);
mClusterTask = new ClusterTask();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
mClusterTask.execute((float) mMap.getCameraPosition().zoom);
} else {
mClusterTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (float) mMap.getCameraPosition().zoom);
}
} finally {
mClusterTaskLock.writeLock().unlock();
}
}
项目:PhotoPickApp
文件:LoadImageUtil.java
public static void loadImage(final String path, final OnLoadImageListener listener) {
new AsyncTask<String, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(String... strings) {
String string = strings[0];
return decodeSampledBitmapFromResource(string);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (bitmap != null) {
listener.onFinish(bitmap, path);
} else {
listener.onError();
}
}
}.execute(path);
}
项目:AndroidPdfViewerV2
文件:PDFView.java
private void load(DocumentSource docSource, String password, OnLoadCompleteListener onLoadCompleteListener, OnErrorListener onErrorListener, int[] userPages) {
if (!recycled) {
throw new IllegalStateException("Don't call load on a PDF View without recycling it first.");
}
// Manage UserPages if not null
if (userPages != null) {
this.originalUserPages = userPages;
this.filteredUserPages = ArrayUtils.deleteDuplicatedPages(originalUserPages);
this.filteredUserPageIndexes = ArrayUtils.calculateIndexesInDuplicateArray(originalUserPages);
}
this.onLoadCompleteListener = onLoadCompleteListener;
this.onErrorListener = onErrorListener;
int firstPageIdx = 0;
if (originalUserPages != null) {
firstPageIdx = originalUserPages[0];
}
recycled = false;
// Start decoding document
decodingAsyncTask = new DecodingAsyncTask(docSource, password, this, pdfiumCore, firstPageIdx);
decodingAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:chromium-for-android-56-debug-video
文件:ShortcutHelper.java
/**
* Stores the specified bitmap as the splash screen for a web app.
* @param id ID of the web app which is storing data.
* @param splashImage Image which should be displayed on the splash screen of
* the web app. This can be null of there is no image to show.
*/
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
if (storage != null) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... args0) {
return encodeBitmapAsString(splashImage);
}
@Override
protected void onPostExecute(String encodedImage) {
storage.updateSplashScreenImage(encodedImage);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
项目:Mp3Player
文件:AlbumAdapter.java
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView==null)
convertView = layoutInflater.inflate(R.layout.album_gridview, parent, false);
this.imageView = (ImageView) convertView.findViewById(R.id.imageView);
this.nofsongs =(TextView) convertView.findViewById(R.id.textView);
this.albumname =(TextView) convertView.findViewById(R.id.albumname);
// this.imageView.setImageResource(R.mipmap.black);
this.imageView.setImageResource(R.drawable.default_album_small);
RelativeLayout.LayoutParams layoutParams =new RelativeLayout.LayoutParams(width/2,width/2);
this.imageView.setLayoutParams(layoutParams);
//below line of code genrating error on activtiy restart........
// if(bitmaps.get(position)!= null)
// this.imageView.setImageBitmap(bitmaps.get(position));
// else
// {
// this.imageView.setImageResource(R.drawable.default_album_small);
// }
// setCursor();
new get(this.nofsongs,this.albumname,position,this.imageView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return convertView;
}
项目:Pocket-Plays-for-Twitch
文件:LazyMainActivity.java
/**
* Refreshes the Activity's visual elements by clearing the adapter and setting the current offset to one.
* After the adapter is finished clearing, new elements will be loaded and added.
*/
@Override
public void refreshElements() {
int duration = mAdapter.clear();
// Fetch new elements after the adapter animations are done
// ToDo: These elements should be loaded while the animations are running. But not be added until the animations are done.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
setCurrentOffset(0);
getRecyclerView().scrollToPosition(0);
GetVisualElementsTask<Game> getTopGamesTask = new GetVisualElementsTask<>();
getTopGamesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, LazyMainActivity.this);
}
}, duration);
}
项目:PeSanKita-android
文件:AndroidAutoHeardReceiver.java
@Override
protected void onReceive(final Context context, Intent intent,
@Nullable final MasterSecret masterSecret)
{
if (!HEARD_ACTION.equals(intent.getAction()))
return;
final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);
if (threadIds != null) {
int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1);
NotificationManagerCompat.from(context).cancel(notificationId);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
for (long threadId : threadIds) {
Log.i(TAG, "Marking meassage as read: " + threadId);
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
messageIdsCollection.addAll(messageIds);
}
MessageNotifier.updateNotification(context, masterSecret);
MarkReadReceiver.process(context, messageIdsCollection);
return null;
}
}.execute();
}
}
项目:underlx
文件:UnconfirmedTripsFragment.java
@Override
public void onReceive(Context context, Intent intent) {
if (getActivity() == null) {
return;
}
switch (intent.getAction()) {
case MainActivity.ACTION_MAIN_SERVICE_BOUND:
case MainService.ACTION_UPDATE_TOPOLOGY_FINISHED:
case MainService.ACTION_TRIP_REALM_UPDATED:
new UpdateDataTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
}
}
项目:chromium-for-android-56-debug-video
文件:PhysicalWebUma.java
/**
* Uploads metrics that we have deferred for uploading.
*/
public static void uploadDeferredMetrics() {
// Read the metrics.
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
if (prefs.getBoolean(HAS_DEFERRED_METRICS_KEY, false)) {
AsyncTask.THREAD_POOL_EXECUTOR.execute(new UmaUploader(prefs));
}
}
项目:chromium-for-android-56-debug-video
文件:TabPersistentStore.java
private void startPrefetchActiveTabTask(Executor executor) {
final int activeTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID);
if (activeTabId == Tab.INVALID_TAB_ID) return;
mPrefetchActiveTabTask = new AsyncTask<Void, Void, TabState>() {
@Override
protected TabState doInBackground(Void... params) {
return TabState.restoreTabState(getStateDirectory(), activeTabId);
}
}.executeOnExecutor(executor);
}
项目:L-Assistant
文件:GuokrHandpickNewsLocalDataSource.java
@SuppressLint("StaticFieldLeak")
@Override
public void getFavorites(@NonNull LoadGuokrHandpickNewsCallback callback) {
if (mDb == null) {
mDb = DatabaseCreator.getInstance().getDatabase();
}
if (mDb != null) {
new AsyncTask<Void, Void, List<GuokrHandpickNewsResult>>() {
@Override
protected List<GuokrHandpickNewsResult> doInBackground(Void... voids) {
return mDb.guokrHandpickNewsDao().queryAllFavorites();
}
@Override
protected void onPostExecute(List<GuokrHandpickNewsResult> list) {
super.onPostExecute(list);
if (list == null) {
callback.onDataNotAvailable();
} else {
callback.onNewsLoaded(list);
}
}
}.execute();
}
}
项目:anitrend-app
文件:FragmentPresenter.java
@Override
public void beginAsync(Callback<List<Series>> callback, int viewPosition) {
new HomePageFetch(callback, new Search(KeyUtils.SeriesTypes[KeyUtils.ANIME], /*anime or manga*/
getApiPrefs().getYear(), /*year*/
SeasonTitles[viewPosition], /*season*/
getApiPrefs().getShowType(), /*Type e.g. TV or Movie e.t.c*/
getApiPrefs().getStatus(), /*status*/
getApiPrefs().getGenres(), /*genre */
getApiPrefs().getExcluded(), /*genre exclude*/
getApiPrefs().getSort(), /*sort*/
getApiPrefs().getOrder(), /*order*/
true, /*airing data*/
false, /*full page true: no pagination; false: paginate using the page variable*/
null)/*page*/, mContext).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:HiBangClient
文件:BaseFragment.java
protected void clearAsyncTask() {
Iterator<AsyncTask<Void, Void, Boolean>> iterator = mAsyncTasks
.iterator();
while (iterator.hasNext()) {
AsyncTask<Void, Void, Boolean> asyncTask = iterator.next();
if (asyncTask != null && !asyncTask.isCancelled()) {
asyncTask.cancel(true);
}
}
mAsyncTasks.clear();
}
项目:Android-skin-support
文件:SkinCompatManager.java
/**
* 加载记录的皮肤包,一般在Application中初始化换肤框架后调用.
*
* @return
*/
public AsyncTask loadSkin() {
String skin = SkinPreference.getInstance().getSkinName();
int strategy = SkinPreference.getInstance().getSkinStrategy();
if (TextUtils.isEmpty(skin) || strategy == SKIN_LOADER_STRATEGY_NONE) {
return null;
}
return loadSkin(skin, null, strategy);
}
项目:wallpaperboard
文件:FavoritesFragment.java
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ViewHelper.setupToolbar(mToolbar);
TextView textView = getActivity().findViewById(R.id.title);
textView.setText(getActivity().getResources().getString(
R.string.navigation_view_favorites));
mToolbar.setTitle("");
mToolbar.setNavigationIcon(ConfigurationHelper.getNavigationIcon(getActivity(),
WallpaperBoardApplication.getConfig().getNavigationIcon()));
mToolbar.setNavigationOnClickListener(view -> {
try {
NavigationListener listener = (NavigationListener) getActivity();
listener.onNavigationIconClick();
} catch (IllegalStateException e) {
LogUtil.e("Parent activity must implements NavigationListener");
}
});
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(),
getActivity().getResources().getInteger(R.integer.wallpapers_column_count)));
mRecyclerView.setHasFixedSize(false);
if (WallpaperBoardApplication.getConfig().getWallpapersGrid() ==
WallpaperBoardConfiguration.GridStyle.FLAT) {
int padding = getActivity().getResources().getDimensionPixelSize(R.dimen.card_margin);
mRecyclerView.setPadding(padding, padding, 0, 0);
}
resetViewBottomPadding(mRecyclerView, true);
mAsyncTask = new FavoritesLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:orgzly-android
文件:SyncFragment.java
@SuppressLint("StaticFieldLeak")
public void createFilter(final Filter filter) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mShelf.createFilter(filter);
return null;
}
}.execute();
}
项目:q-mail
文件:QMail.java
public static void saveSettingsAsync() {
new AsyncTask<Void,Void,Void>() {
@Override
protected Void doInBackground(Void... voids) {
Preferences prefs = Preferences.getPreferences(app);
StorageEditor editor = prefs.getStorage().edit();
save(editor);
editor.commit();
return null;
}
}.execute();
}
项目:orgzly-android
文件:SyncFragment.java
@SuppressLint("StaticFieldLeak")
public void moveFilterUp(final long id) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mShelf.moveFilterUp(id);
return null;
}
}.execute();
}
项目:react-native-cameraroll
文件:RNCameraRollModule.java
@ReactMethod
public void getAssets(final ReadableMap params, final Promise promise) {
String start = params.hasKey("start") ? params.getString("start") : null;
int limit = params.getInt("limit");
String assetType = params.getString("assetType");
new GetAssetsTask(
getReactApplicationContext(),
start,
limit,
assetType,
promise)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
项目:Android-Development
文件:EditPoiFragment.java
private void loadNodeData() {
if (DeviceUtils.isInternetConnected(getActivity()))
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
MapDataDao mapDao = new MapDataDao(osm);
editNode = mapDao.getNode(POI.getId());
// if (editNode != null)
// if (editNode.getTags() != null)
// for (Map.Entry<String, String> tag : editNode.getTags().entrySet()) {
// AppLog.log(tag.getKey() + " " + tag.getValue());
// }
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
hideLoadingScreen();
if (editNode != null) //load data to UI
loadNodeInfoToUI(editNode);
else {
//not a node
new AppToast(getActivity()).centerViewToast(getString(R.string.editing_is_not_possible) + " \n" + POI.getPoiName());
closeFragment();
}
}
}.execute();
else {
hideLoadingScreen();
new AppToast(getActivity()).centerViewToast(getString(R.string.offline));
closeFragment();
}
}
项目:MTweaks-KernelAdiutorMOD
文件:ProfileFragment.java
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);
}
}
项目:wallpaperboard
文件:WallpapersFragment.java
public void getWallpapers() {
if (mAsyncTask != null) {
mAsyncTask.cancel(true);
}
if (Database.get(getActivity()).getWallpapersCount() > 0) {
mAsyncTask = new WallpapersTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return;
}
mAsyncTask = new WallpapersTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
项目:orgzly-android
文件:SyncFragment.java
@SuppressLint("StaticFieldLeak")
public void shiftNoteState(final long id, final int direction) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mShelf.shiftState(id, direction);
return null;
}
}.execute();
}