private void startCameraSource() {
   try {
     mPreview.start(mCameraSource, mGraphicOverlay);
     boolean startAsyncTask = sp.getBoolean("vision_continuous_test", false);
     if (!startAsyncTask) {
       if (asyncTask != null) {
         // Check if there is an Async Task running. If so, cancel it
         switch (asyncTask.getStatus()) {
           case RUNNING:
             asyncTask.cancel(true);
             asyncTask = null;
             break;
           case PENDING:
             asyncTask.cancel(true);
             asyncTask = null;
             break;
           case FINISHED:
             asyncTask = null;
             break;
         }
       }
       asyncTask =
           new AsyncTaskWaitForBarcode(
                   this, Integer.parseInt(sp.getString("vision_sleep", "1500")))
               .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     }
   } catch (IOException e) {
     mCameraSource.release();
     mCameraSource = null;
   }
 }
 @Override
 protected void onPause() {
   super.onPause();
   if (followInvoiceTask != null) {
     followInvoiceTask.cancel(true);
   }
   if (updateTimerTask != null) {
     updateTimerTask.cancel(true);
   }
 }
Example #3
0
 public void cleanup() {
   serverWorking = false;
   if (clientPoll != null)
     for (int i = 0; i < clientPoll.size(); i++) {
       AsyncTask<Integer, Object, Void> async = clientPoll.get(i);
       if (async != null) async.cancel(true);
     }
   if (serverStart != null) serverStart.cancel(true);
   serverStart = null;
   clientPoll = null;
   asyncClean();
 }
  protected void generateAsyncListMetadata() {
    synchronized (mObjectList) {
      if (mCurrentMetadataTask != null) {
        mCurrentMetadataTask.cancel(true);
      }

      final StickyHeaderListViewArrayAdapterBase<T, D> that = this;

      this.mCurrentMetadataTask =
          new AsyncTask<Void, Void, Void>() {
            private MetadataDTO metadata;

            @Override
            protected Void doInBackground(Void... params) {
              this.metadata = generateListMetadata();
              return null;
            }

            protected void onPostExecute(Void result) {
              mNotifiyng = true;
              that.mPrevHeadersPositionByIndex = metadata.getPrevHeadersPositionByIndex();
              that.mNextHeadersPositionByIndex = metadata.getNextHeadersPositionByIndex();
              that.mViewTypesByPosition = metadata.getViewTypesByPosition();
              that.mTotalItems = metadata.getTotalItems();

              StickyHeaderListViewArrayAdapterBase.super.notifyDataSetChanged();
            };
          };
      mCurrentMetadataTask.execute();
    }
  }
  /**
   * start or stop recording
   *
   * @param start true start recording, false stop recording
   */
  private void onRecord(boolean start) {
    if (start) {
      onPlay(STOP_PLAYING);
      mPlayPause.setImageResource(R.drawable.ic_play);

      startRecordingAsync();

      startAnimate();

    } else {

      if (!mIsRecording) {
        recordingAsync.cancel(true);
      }

      stopRecording();

      stopAnimating();

      try {
        long size = 0;
        File forSize = new File(mFilePath);
        if (forSize.exists()) {
          size = forSize.length();
          String text = getString(R.string.OK) + ", " + Tools.readableFileSize(size);
          okButton.setText(text);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      ;
    }
  }
 @Override
 public void onDestroy() {
   super.onDestroy();
   if (mLicenseLoader != null) {
     mLicenseLoader.cancel(true);
   }
 }
 @Override
 public void onDismiss(DialogInterface dialog) {
   if (loadApps != null && loadApps.getStatus() == AsyncTask.Status.RUNNING) {
     loadApps.cancel(true);
     loadApps = null;
   }
 }
 @Override
 public Object onRetainNonConfigurationInstance() {
   if (mSignupTask != null) {
     mSignupTask.cancel(true);
   }
   return mSignupTask;
 }
 /** Gently killing AsyncTask */
 public static void stopTaskGracefully(AsyncTask<?, ?, ?> t) {
   if (t != null) {
     if (t.getStatus() == Status.RUNNING) {
       t.cancel(true);
     }
   }
 }
    void calculateProgress(
        final String name,
        final long fileBytes,
        final int id,
        final long size,
        final boolean move) {
      if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
        asyncTask.cancel(true);
      asyncTask =
          new AsyncTask<Void, Void, Void>() {
            int p1, p2;

            @Override
            protected Void doInBackground(Void... voids) {
              p1 = (int) ((copiedBytes / (float) totalBytes) * 100);
              p2 = (int) ((fileBytes / (float) size) * 100);
              lastpercent = (int) copiedBytes;
              return null;
            }

            @Override
            public void onPostExecute(Void v) {
              publishResults(name, p1, p2, id, totalBytes, copiedBytes, false, move);
            }
          }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
 private synchronized void cancel() {
   AsyncTask<?, ?, ?> task = inactivityTask;
   if (task != null) {
     task.cancel(true);
     inactivityTask = null;
   }
 }
Example #12
0
  public void atualizarDados(final int position) {
    if (mTask != null) {
      mTask.cancel(true);
    }
    if (!mGoogleApiClient.isConnected()) return; // Se não estiver conectado, saia...
    mTask =
        new AsyncTask<Void, Void, PutDataMapRequest>() {
          @Override
          protected PutDataMapRequest doInBackground(Void... voids) {
            PutDataMapRequest putDataMapRequest =
                PutDataMapRequest.create(Constantes.CAMINHO_DADOS);
            mUriDados = putDataMapRequest.getUri();
            DataMap map = putDataMapRequest.getDataMap();
            map.putInt(Constantes.EXTRA_POSICAO_ATUAL, position);
            map.putInt(Constantes.EXTRA_TOTAL_IMAGENS, Constantes.TOTAL_IMAGENS);
            Bitmap miniatura =
                ImagemUtil.imagem(mContext, "foto" + (position + 1) + ".jpg", 160, 160);
            if (miniatura != null) {
              final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
              miniatura.compress(Bitmap.CompressFormat.JPEG, 80, byteStream);
              Asset asset = Asset.createFromBytes(byteStream.toByteArray());
              map.putAsset(Constantes.EXTRA_IMAGEM, asset);
            }
            return putDataMapRequest;
          }

          @Override
          protected void onPostExecute(PutDataMapRequest dataMapRequest) {
            super.onPostExecute(dataMapRequest);
            Wearable.DataApi.putDataItem(mGoogleApiClient, dataMapRequest.asPutDataRequest());
          }
        }.execute();
  }
Example #13
0
 @Override
 protected void onDestroy() {
   if (getUsersTask != null) {
     getUsersTask.cancel(true);
   }
   super.onDestroy();
 }
 @Override
 protected void onPause() {
   super.onPause();
   if (operationTask != null) {
     operationTask.cancel(true);
   }
 }
 @Override
 public void onDestroyView() {
   if (mCurrentTask != null) {
     mCurrentTask.cancel(true);
   }
   mCurrentTask = null;
   super.onDestroyView();
 }
Example #16
0
  public void stop() {

    Log.d("SyncTask", "Requested stop");
    this.stopped = true;
    if (task != null) {
      task.cancel(true);
    }
  }
 @Override
 public void onDestroy() {
   super.onDestroy();
   OpenHelperManager.releaseHelper();
   if (mAsyncTask != null) {
     mAsyncTask.cancel(true);
   }
 }
Example #18
0
 private void unInit() {
   if (null != mInitTask) {
     if (!mInitTask.isCancelled()) {
       mInitTask.cancel(true);
     }
     mInitTask = null;
   }
 }
 @Override
 public void onBackPressed() {
   super.onBackPressed();
   if (asyncTask != null) {
     asyncTask.cancel(true);
     asyncTask = null;
   }
 }
Example #20
0
 @Override
 public void onDestroy() {
   if (mTask != null) {
     mTask.cancel(true);
     mTask = null;
   }
   super.onDestroy();
 }
 private synchronized void cancelOutstandingTask() {
   if (outstandingTask != null) {
     if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) {
       outstandingTask.cancel(true);
     }
     outstandingTask = null;
   }
 }
 private void cancelPrevRegisterTask() {
   synchronized (mSyncObj) {
     if (null != mRegistrationAsyncTask) {
       mRegistrationAsyncTask.cancel(true);
     }
     mRegistrationAsyncTask = null;
   }
 }
Example #23
0
 @JavascriptInterface
 public void cancel() {
   Log.d(TAG, "cancel");
   super.cancel(false);
   if (currentUsbRequest != null) {
     currentUsbRequest.cancel();
   }
   errorMessage = "cancel";
 }
Example #24
0
 @Override
 public void onStopWithNative() {
   super.onStopWithNative();
   mCleanupTask.cancel(true);
   if (getActivityTab() != null) getActivityTab().saveState(getActivityDirectory());
   if (getFullscreenManager() != null) {
     getFullscreenManager().setPersistentFullscreenMode(false);
   }
 }
 @Override
 protected void onPause() {
   AsyncTask<?, ?, ?> oldTask = networkTask;
   if (oldTask != null) {
     oldTask.cancel(true);
     networkTask = null;
   }
   super.onPause();
 }
 @Override
 protected void onDestroy() {
   if (mRegisterTask != null) {
     mRegisterTask.cancel(true);
   }
   unregisterReceiver(mHandleMessageReceiver);
   GCMRegistrar.onDestroy(this);
   super.onDestroy();
 }
Example #27
0
 // GCM
 @Override
 protected void onDestroy() {
   // TODO Auto-generated method stub
   if (mRegisterTask != null) {
     mRegisterTask.cancel(true);
   }
   unregisterReceiver(mHandleMessageReceiver);
   GCMRegistrar.onDestroy(getApplicationContext());
   super.onDestroy();
 }
  @Override
  protected void onStop() {
    Log.d(TAG, "onStop");
    super.onStop();

    if (mLoadPictureTask != null && mLoadPictureTask.getStatus() != AsyncTask.Status.FINISHED) {
      mLoadPictureTask.cancel(false);
    }

    unregisterReceiver(mReceiver);
  }
Example #29
0
 public void cancel() {
   super.cancel(true);
   isCanceled = true;
   if (mAjax != null) {
     HttpRequest mHttpRequest = mAjax.getHttpRequest();
     if (mHttpRequest != null) {
       mHttpRequest.cancel();
       mHttpRequest = null;
     }
   }
 }
  @Override
  protected void onPause() {
    active = false;
    rescanWifiTask.cancel(true);

    if (nfcAvailable) {
      nfcAdapter.disableForegroundDispatch(this);
    }

    super.onPause();
  }