android.os.AsyncTask.Status Java Examples

The following examples show how to use android.os.AsyncTask.Status. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloadCartridgeActivity.java    From WhereYouGo with GNU General Public License v3.0 6 votes vote down vote up
public DownloadTask(final Context context, String username, String password) {
    super(context, username, password);
    progressDialog = new ProgressDialog(context);
    progressDialog.setMessage("");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMax(1);
    progressDialog.setIndeterminate(true);
    progressDialog.setCanceledOnTouchOutside(false);

    progressDialog.setCancelable(true);
    progressDialog.setOnCancelListener(arg0 -> {
        if (downloadTask != null && downloadTask.getStatus() != Status.FINISHED) {
            downloadTask.cancel(false);
            downloadTask = null;
            Log.i("down", "cancel");
            ManagerNotify.toastShortMessage(context, getString(R.string.cancelled));
        }
    });
}
 
Example #2
Source File: BootloaderActivity.java    From crazyflie-android-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (mFlashFirmwareTask != null && mFlashFirmwareTask.getStatus().equals(Status.RUNNING)) {
        if (mDoubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }
        this.mDoubleBackToExitPressedOnce = true;
        Toast.makeText(this, "Please click BACK again to cancel flashing and exit", Toast.LENGTH_SHORT).show();
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                mDoubleBackToExitPressedOnce = false;

            }
        }, 2000);
    } else {
        super.onBackPressed();
    }
}
 
Example #3
Source File: PluginDownloader.java    From geoar-app with Apache License 2.0 6 votes vote down vote up
public static void getDataSources(OnDataSourceResultListener listener,
		boolean force) {
	if (mDownloadTask == null
			|| mDownloadTask.getStatus() != Status.FINISHED || force) {
		mCurrentListeners.add(listener);

		if (mDownloadTask == null
				|| mDownloadTask.getStatus() == Status.FINISHED) {
			mDownloadTask = new DownloadTask();
			mDownloadTask.execute((Void) null);
		}
	} else {
		listener.onDataSourceResult(new ArrayList<PluginDownloadHolder>(
				mDownloadableDataSources));
	}
}
 
Example #4
Source File: MainActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void markTaskStatusInProgress(Uri task) {
    Log.i(TAG, "markStatusInProgress(): " + task);
    org.sana.api.task.Status status = org.sana.api.task.Status.IN_PROGRESS;
    String now = timeStamp();
    ContentValues values = new ContentValues();
    values.put(Tasks.Contract.STATUS, "In Progress");
    values.put(Tasks.Contract.MODIFIED, now);
    values.put(Tasks.Contract.STARTED, now);
    getContentResolver().update(task, values, null, null);

    Bundle form = new Bundle();
    form.putString(Tasks.Contract.STATUS, "In Progress");
    form.putString(Tasks.Contract.MODIFIED, now);
    form.putString(Tasks.Contract.STARTED, now);

    // send to sync
    Intent intent = new Intent(Intents.ACTION_UPDATE, task);
    intent.putExtra("form", form);
    startService(intent);
}
 
Example #5
Source File: MainActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void markTaskStatusCompleted(Uri task, Uri encounter) {
    Log.i(TAG, "markStatusCompleted(): " + task);
    org.sana.api.task.Status status = org.sana.api.task.Status.COMPLETED;
    String now = timeStamp();
    String uuid = ModelWrapper.getUuid(encounter, getContentResolver());
    ContentValues values = new ContentValues();
    values.put(Tasks.Contract.STATUS, status.toString());
    values.put(Tasks.Contract.COMPLETED, now);
    values.put(EncounterTasks.Contract.ENCOUNTER, uuid);
    values.put(Tasks.Contract.MODIFIED, now);

    Bundle form = new Bundle();
    form.putString(Tasks.Contract.STATUS, status.toString());
    form.putString(Tasks.Contract.MODIFIED, now);
    form.putString(Tasks.Contract.COMPLETED, now);
    form.putString(EncounterTasks.Contract.ENCOUNTER, uuid);

    // send to sync
    Intent intent = new Intent(Intents.ACTION_UPDATE, task);
    intent.putExtra("form", form);
    startService(intent);
}
 
Example #6
Source File: NaviEngine.java    From PocketMaps with MIT License 6 votes vote down vote up
@UiThread
private void calculatePositionAsync(Activity activity, GeoPoint curPos)
{
  if (naviEngineTask == null) { createNaviEngineTask(activity); }
  updateDirectTargetDir(curPos);
  if (naviEngineTask.getStatus() == Status.RUNNING)
  {
    log("Error, NaviEngineTask is still running! Drop job ...");
  }
  else if (naviEngineTask.hasError())
  {
    naviEngineTask.getError().printStackTrace();
  }
  else
  {
    createNaviEngineTask(activity); //TODO: Recreation of Asynctask seems necessary?!
    naviEngineTask.execute(curPos);
  }
}
 
Example #7
Source File: TaskFragment.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
private void initCallbacks()
{
	_callbacks = getTaskCallbacks(getActivity());
	if (_callbacks != null)
	{
		if(_task.getStatus() != Status.FINISHED)
			_callbacks.onPrepare(getArguments());
		else
			try
			{
				_callbacks.onCompleted(getArguments(), _task.get());
			}
			catch (Exception ignored)
			{
			}
	}
}
 
Example #8
Source File: NavigationActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void saveLocalTaskState(Bundle outState) {
    final MDSSyncTask mTask = mSyncTask;
    if (mTask != null && mTask.getStatus() != Status.FINISHED) {
        mTask.cancel(true);
        outState.putBoolean(STATE_MDS_SYNC, true);
    }
    final ResetDatabaseTask rTask = mResetDatabaseTask;
    if (rTask != null && rTask.getStatus() != Status.FINISHED) {
        rTask.cancel(true);
        outState.putBoolean(STATE_RESET_DB, true);
    }
}
 
Example #9
Source File: NavigationActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Executes a task to clear out the database
 */
private void doClearDatabase() {
    // TODO: context leak
    if (mResetDatabaseTask != null && mResetDatabaseTask.getStatus() != Status.FINISHED)
        return;
    mResetDatabaseTask =
            (ResetDatabaseTask) new ResetDatabaseTask(this).execute(this);
}
 
Example #10
Source File: LNReaderApplication.java    From coolreader with MIT License 5 votes vote down vote up
public boolean addTask(String key, AsyncTask<?, ?, ?> task) {
	synchronized (lock) {
		if (runningTasks.containsKey(key)) {
			AsyncTask<?, ?, ?> tempTask = runningTasks.get(key);
			if (tempTask != null && tempTask.getStatus() != Status.FINISHED)
				return false;
		}
		runningTasks.put(key, task);
		return true;
	}
}
 
Example #11
Source File: Sana.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void saveLocalTaskState(Bundle outState) {
    final MDSSyncTask mTask = mSyncTask;
    if (mTask != null && mTask.getStatus() != Status.FINISHED) {
        mTask.cancel(true);
        outState.putBoolean(STATE_MDS_SYNC, true);
    }
    final ResetDatabaseTask rTask = mResetDatabaseTask;
    if (rTask != null && rTask.getStatus() != Status.FINISHED) {
        rTask.cancel(true);
        outState.putBoolean(STATE_RESET_DB, true);
    }
}
 
Example #12
Source File: Sana.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Executes a task to clear out the database
 */
private void doClearDatabase() {
    // TODO: context leak
    if (mResetDatabaseTask != null && mResetDatabaseTask.getStatus() != Status.FINISHED)
        return;
    mResetDatabaseTask =
            (ResetDatabaseTask) new ResetDatabaseTask(this).execute(this);
}
 
Example #13
Source File: StatusScrollListener.java    From YiBo with Apache License 2.0 5 votes vote down vote up
private void displayImage(AbsListView listView) {
	int firstPos = listView.getFirstVisiblePosition();
	int lastPos = listView.getLastVisiblePosition();
	int totalCount = lastPos - firstPos + 1;
	
	Log.v(TAG, "滚动停止加载图片..");
	for (int i = 0; i < totalCount; i++) {
		View view = listView.getChildAt(i);
		Object tag = view.getTag();
	    if (!(tag instanceof StatusHolder)) {
	    	continue;
	    }
	    
	    StatusHolder holder = (StatusHolder)view.getTag();
	    ImageLoad4ThumbnailTask thumbnailTask = holder.thumbnailTask;
	    if (thumbnailTask != null 
	    	&& thumbnailTask.isCancelled() == false
	    	&& thumbnailTask.getStatus() == Status.PENDING) {
	    	thumbnailTask.execute();
	    }
	    
	    QueryResponseCountTask responseCountTask  = holder.responseCountTask;
	    if (responseCountTask != null
	    	&& responseCountTask.isCancelled() == false
	    	&& responseCountTask.getStatus() == Status.PENDING) {
	    	responseCountTask.execute();
	    }
	}
}
 
Example #14
Source File: DownloadCartridgeActivity.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    if (downloadTask != null && downloadTask.getStatus() != Status.FINISHED) {
        downloadTask.cancel(true);
        downloadTask = null;
    }
}
 
Example #15
Source File: MainActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void saveLocalTaskState(Bundle outState) {
    final ResetDatabaseTask rTask = mResetDatabaseTask;
    if (rTask != null && rTask.getStatus() != Status.FINISHED) {
        rTask.cancel(true);
        outState.putBoolean("_resetdb", true);
    }
}
 
Example #16
Source File: MainActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void doClearDatabase(Uri[] uris) {
    // TODO: context leak
    if (mResetDatabaseTask != null && mResetDatabaseTask.getStatus() != Status.FINISHED)
        return;
    mResetDatabaseTask =
            (ResetDatabaseTask) new ResetDatabaseTask(this, true, uris).execute(this);
}
 
Example #17
Source File: MainActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Executes a task to clear out the database
 */
private void doClearDatabase() {
    // TODO: context leak
    if (mResetDatabaseTask != null && mResetDatabaseTask.getStatus() != Status.FINISHED)
        return;
    mResetDatabaseTask =
            (ResetDatabaseTask) new ResetDatabaseTask(this, true).execute(this);
}
 
Example #18
Source File: BaseRunnerFragment.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void lookupPatient(String patientId) {
    logEvent(EventType.ENCOUNTER_LOOKUP_PATIENT_START, patientId);

    // Display progress dialog
    String message = String.format(getString(R.string.dialog_look_up_patient), patientId);
    showProgressDialogFragment(message);

    if (patientLookupTask == null || patientLookupTask.getStatus() == Status.FINISHED) {
        patientLookupTask = new PatientLookupTask(getActivity());
        patientLookupTask.setPatientLookupListener(this);
        patientLookupTask.execute(patientId);
    }
}
 
Example #19
Source File: DilbertFragment.java    From Simple-Dilbert with Apache License 2.0 5 votes vote down vote up
private void refreshAction() {
    Glide.get(getContext()).clearMemory();
    preferences.removeCache(getDateFromArguments());
    if (this.loadTask == null
            || this.loadTask.getStatus() != Status.PENDING) {
        this.loadTask = new GetStripUrl(getContext(), getStripURIlListener, preferences,
                getDateFromArguments(), progress);
    }
    this.loadTask.execute();
}
 
Example #20
Source File: BootloaderActivity.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPause() {
    //TODO: improve
    //TODO: why does resetToFirmware not work?
    if (mFlashFirmwareTask != null && mFlashFirmwareTask.getStatus().equals(Status.RUNNING)) {
        Log.d(LOG_TAG, "OnPause: stop bootloader.");
        mFlashFirmwareTask.cancel(true);
    }
    super.onPause();
}
 
Example #21
Source File: LivePlayerController.java    From letv with Apache License 2.0 5 votes vote down vote up
private void fullScreenClickShowAndHide(boolean show) {
    LogInfo.log(RxBus.TAG, "全屏控制栏显示:" + show);
    if (show) {
        this.mTopBar.setVisibility(0);
        this.mBottomBar.setVisibility(0);
        if (LiveLunboUtils.isLunBoWeiShiType(this.pageIndex)) {
            this.mChannelBtn.setVisibility(0);
        }
        if (this.mLiveBarrageController == null || !this.mLiveBarrageController.getBarrageControl().isOpenBarrage()) {
            this.mBarrageInputBtn.setVisibility(4);
        } else {
            this.mBarrageInputBtn.setVisibility(0);
        }
        if (this.mCanWatchAndBuy) {
            this.mCartLayout.setVisibility(0);
            if (this.mCartShowingSubscription != null) {
                LogInfo.log(RxBus.TAG, "取消监听购物车按钮消失的通知");
                this.mCartShowingSubscription.unsubscribe();
            }
        }
        if (!(LiveLunboUtils.isLunBoWeiShiType(this.pageIndex) || this.mBaseBean == null || this.mBaseBean.branchType <= 0 || this.mBaseBean.isBranch != 1 || BaseTypeUtils.isListEmpty(this.mBaseBean.branches))) {
            this.mBtnMultiProgram.setVisibility(0);
        }
    } else {
        this.mTopBar.setVisibility(8);
        this.mBottomBar.setVisibility(8);
        if (LiveLunboUtils.isLunBoWeiShiType(this.pageIndex)) {
            this.mChannelBtn.setVisibility(8);
        }
        this.mBarrageInputBtn.setVisibility(4);
        hideFloatView();
        setLevelTipVisible(false);
        if (this.mCartLayout.getVisibility() == 0 && !this.mWacthAndBuyFloatView.isShowing() && this.mWatchAndBuyCartListView.getVisibility() != 0 && ((this.mCartTask == null || this.mCartTask.getStatus() != Status.RUNNING) && this.mWatchAndBuyCartListView.getVisibility() != 0)) {
            this.mCartLayout.setVisibility(8);
        }
        this.mBtnMultiProgram.setVisibility(8);
    }
    RxBus.getInstance().send("rx_bus_live_home_action_update_system_ui");
}
 
Example #22
Source File: MainActivity.java    From ImageChooser with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片
 */
private void loadImages() {
    mLoadingLayout.showLoading(true);
    if (!SDcardUtil.hasExternalStorage()) {
        mLoadingLayout.showEmpty(getString(R.string.donot_has_sdcard));
        return;
    }

    // 线程正在执行
    if (mLoadTask != null && mLoadTask.getStatus() == Status.RUNNING) {
        return;
    }

    mLoadTask = new ImageLoadTask(this, new OnTaskResultListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void onResult(boolean success, String error, Object result) {
            mLoadingLayout.showLoading(false);
            // 如果加载成功
            if (success && result != null && result instanceof ArrayList) {
                setImageAdapter((ArrayList<ImageGroup>)result);
            } else {
                // 加载失败,显示错误提示
                mLoadingLayout.showFailed(getString(R.string.loaded_fail));
            }
        }
    });
    TaskUtil.execute(mLoadTask);
}
 
Example #23
Source File: DocumentCursor.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void close() {
  super.close();
  if (mLoadingTask != null && mLoadingTask.getStatus() != Status.FINISHED) {
    if(BuildConfig.DEBUG) Log.d(TAG, "Cursor is closed. Cancel the loading task " + mLoadingTask);
    // Interrupting the task is not a good choice as it's waiting for the Samba client thread
    // returning the result. Interrupting the task only frees the task from waiting for the
    // result, rather than freeing the Samba client thread doing the hard work.
    mLoadingTask.cancel(false);
  }
}
 
Example #24
Source File: TaskManager.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
public <T> void runTask(Uri uri, AsyncTask<T, ?, ?> task, T... args) {
  synchronized (mTasks) {
    if (!mTasks.containsKey(uri) || mTasks.get(uri).getStatus() == Status.FINISHED) {
      mTasks.put(uri, task);
      // TODO: Use different executor for different servers.
      task.executeOnExecutor(mExecutor, args);
    } else {
      Log.i(TAG,
          "Ignore this task for " + uri + " to avoid running multiple updates at the same time.");
    }
  }
}
 
Example #25
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onQueryTextSubmit(String query) {
    if ((mTask != null) && (mTask.getStatus() == Status.RUNNING)) {
        return false;
    }

    mQuery = query;


    mTask = new SearchTask(getActivity());
    mTask.execute(query);
    return false;
}
 
Example #26
Source File: NetworkFragment.java    From upcKeygen with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onActivityCreated(Bundle savedInstanceState) {
	super.onActivityCreated(savedInstanceState);
	if (passwordList == null) {
		if (thread.getStatus() == Status.FINISHED
				|| thread.getStatus() == Status.RUNNING)
			thread = new KeygenThread(wifiNetwork);
		if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
			thread.execute();
		} else {
			thread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		}
	}
}
 
Example #27
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onQueryTextSubmit(String query) {
    if ((mTask != null) && (mTask.getStatus() == Status.RUNNING)) {
        return false;
    }

    mQuery = query;


    mTask = new SearchTask(getActivity());
    mTask.execute(query);
    return false;
}
 
Example #28
Source File: IncompleteFormListAdapter.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public void release() {
    if (loader.getStatus() == Status.RUNNING) {
        loader.cancel(false);
    }
}
 
Example #29
Source File: ChatService.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
/**
 * Connects to the Chat Service
 */
private void connectChatService() {

    //If there already is a pending connect task, remove it since we have a newer one
    if (mConnectRunnable != null) {
        mHandler.removeCallbacks(mConnectRunnable);
    }
    if (isLoggedIn() && !mMessageConsumer.isRunning()) {

        mConnectRunnable = new Runnable() {

            @Override
            public void run() {

                if (!isLoggedIn()
                        || !DeviceInfo.INSTANCE
                        .isNetworkConnected()) {

                    //If there is no internet connection or we are not logged in, we need not attempt to connect
                    mConnectRunnable = null;
                    return;
                }

                mQueueName = generateQueueNameFromUserEmailAndDeviceId(UserInfo.INSTANCE
                                                                               .getEmail(),
                                                                       UserInfo.INSTANCE
                                                                               .getDeviceId()
                );

                if (mConnectTask == null) {
                    mConnectTask = new ConnectToChatAsyncTask();
                    mConnectTask.execute(USERNAME, PASSWORD, mQueueName, UserInfo.INSTANCE
                            .getId());
                } else {
                    final Status connectingStatus = mConnectTask
                            .getStatus();

                    if (connectingStatus != Status.RUNNING) {

                        // We are not already attempting to connect, let's try connecting
                        if (connectingStatus == Status.PENDING) {
                            //Cancel a pending task
                            mConnectTask.cancel(false);
                        }

                        mConnectTask = new ConnectToChatAsyncTask();
                        mConnectTask.execute(USERNAME, PASSWORD, mQueueName, UserInfo.INSTANCE
                                .getId());
                    }
                }
                mConnectRunnable = null;

            }

        };

        mHandler.postDelayed(mConnectRunnable, mCurrentConnectMultiplier
                * CONNECT_BACKOFF_INTERVAL * 1000);
        mCurrentConnectMultiplier = (++mCurrentConnectMultiplier > MAX_CONNECT_MULTIPLIER) ? MAX_CONNECT_MULTIPLIER
                : mCurrentConnectMultiplier;
    }

}
 
Example #30
Source File: NavigationActivity.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Syncs the Patient database with MDS
 */
private void doUpdatePatientDatabase() {
    if (mSyncTask != null && mSyncTask.getStatus() != Status.FINISHED)
        return;
    mSyncTask = (MDSSyncTask) new MDSSyncTask(this).execute(this);
}