类android.support.annotation.UiThread源码实例Demo

下面列出了怎么用android.support.annotation.UiThread的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: play-billing-codelab   文件: GamePlayActivity.java
/**
 * Show an alert dialog to the user
 * @param messageId String id to display inside the alert dialog
 * @param optionalParam Optional attribute for the string
 */
@UiThread
void alert(@StringRes int messageId, @Nullable Object optionalParam) {
    if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
        throw new RuntimeException("Dialog could be shown only from the main thread");
    }

    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    bld.setNeutralButton("OK", null);

    if (optionalParam == null) {
        bld.setMessage(messageId);
    } else {
        bld.setMessage(getResources().getString(messageId, optionalParam));
    }

    bld.create().show();
}
 
源代码2 项目: connectivity-samples   文件: MainActivity.java
/** {@see ConnectionsActivity#onReceive(Endpoint, Payload)} */
@Override
protected void onReceive(Endpoint endpoint, Payload payload) {
  if (payload.getType() == Payload.Type.STREAM) {
    AudioPlayer player =
        new AudioPlayer(payload.asStream().asInputStream()) {
          @WorkerThread
          @Override
          protected void onFinish() {
            final AudioPlayer audioPlayer = this;
            post(
                new Runnable() {
                  @UiThread
                  @Override
                  public void run() {
                    mAudioPlayers.remove(audioPlayer);
                  }
                });
          }
        };
    mAudioPlayers.add(player);
    player.start();
  }
}
 
源代码3 项目: connectivity-samples   文件: MainActivity.java
/** Transitions from the old state to the new state with an animation implying moving backward. */
@UiThread
private void transitionBackward(State oldState, final State newState) {
  mPreviousStateView.setVisibility(View.VISIBLE);
  mCurrentStateView.setVisibility(View.VISIBLE);

  updateTextView(mCurrentStateView, oldState);
  updateTextView(mPreviousStateView, newState);

  if (ViewCompat.isLaidOut(mCurrentStateView)) {
    mCurrentAnimator = createAnimator(true /* reverse */);
    mCurrentAnimator.addListener(
        new AnimatorListener() {
          @Override
          public void onAnimationEnd(Animator animator) {
            updateTextView(mCurrentStateView, newState);
          }
        });
    mCurrentAnimator.start();
  }
}
 
@UiThread
private void checkAndConnect() {
    log("checkAndConnect");
    if (!Utils.isServiceInstalled()) {
        showConnectFail(FAIL_REASON_NOT_INSTALLED);
        return;
    }

    layout.setHeaderText(R.string.wizard_connect);
    checkPermissionAndRun(() -> {
        log("Checking pass");
        if (mConnectTask != null && !mConnectTask.isCancelled()) {
            mConnectTask.cancel(true);
            mConnectTask = null;
        }
        mConnectTask = new ConnectTask();
        mConnectTask.execute();
    });
}
 
源代码5 项目: android-performance   文件: TaskDispatcher.java
@UiThread
public void start() {
    mStartTime = System.currentTimeMillis();
    if (Looper.getMainLooper() != Looper.myLooper()) {
        throw new RuntimeException("must be called from UiThread");
    }
    if (mAllTasks.size() > 0) {
        mAnalyseCount.getAndIncrement();
        printDependedMsg();
        mAllTasks = TaskSortUtil.getSortResult(mAllTasks, mClsAllTasks);
        mCountDownLatch = new CountDownLatch(mNeedWaitCount.get());

        sendAndExecuteAsyncTasks();

        DispatcherLog.i("task analyse cost " + (System.currentTimeMillis() - mStartTime) + "  begin main ");
        executeTaskMain();
    }
    DispatcherLog.i("task analyse cost startTime cost " + (System.currentTimeMillis() - mStartTime));
}
 
源代码6 项目: letv   文件: AsyncListUtil.java
@UiThread
public void extendRangeInto(int[] range, int[] outRange, int scrollHint) {
    int i;
    int fullRange = (range[1] - range[0]) + 1;
    int halfRange = fullRange / 2;
    int i2 = range[0];
    if (scrollHint == 1) {
        i = fullRange;
    } else {
        i = halfRange;
    }
    outRange[0] = i2 - i;
    i = range[1];
    if (scrollHint != 2) {
        fullRange = halfRange;
    }
    outRange[1] = i + fullRange;
}
 
源代码7 项目: phoenix   文件: PictureCompressor.java
/**
 * start asynchronous compress thread
 */
@UiThread
private void launch(final Context context) {
    if (mFile == null && onCompressListener != null) {
        onCompressListener.onError(new NullPointerException("image mFile cannot be null"));
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_START));

                File result = new Engine(mFile, getImageCacheFile(context), mFilterSize).compress();
                mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_SUCCESS, result));
            } catch (IOException e) {
                mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, e));
            }
        }
    }).start();
}
 
源代码8 项目: styT   文件: TapTargetSequence.java
/**
 * Cancels the sequence, if the current target is cancelable.
 * When the sequence is canceled, the current target is dismissed and the remaining targets are
 * removed from the sequence.
 * @return whether the sequence was canceled or not
 */
@UiThread
public boolean cancel() {
  if (targets.isEmpty() || !active) {
    return false;
  }
  if (currentView == null || !currentView.cancelable) {
    return false;
  }
  currentView.dismiss(false);
  active = false;
  targets.clear();
  if (listener != null) {
    listener.onSequenceCanceled(currentView.target);
  }
  return true;
}
 
源代码9 项目: play-billing-codelab   文件: GamePlayActivity.java
/**
 * Show an alert dialog to the user
 * @param messageId String id to display inside the alert dialog
 * @param optionalParam Optional attribute for the string
 */
@UiThread
void alert(@StringRes int messageId, @Nullable Object optionalParam) {
    if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
        throw new RuntimeException("Dialog could be shown only from the main thread");
    }

    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    bld.setNeutralButton("OK", null);

    if (optionalParam == null) {
        bld.setMessage(messageId);
    } else {
        bld.setMessage(getResources().getString(messageId, optionalParam));
    }

    bld.create().show();
}
 
源代码10 项目: TelePlus-Android   文件: NotificationCenter.java
@UiThread
public static NotificationCenter getInstance(int num)
{
    NotificationCenter localInstance = Instance[num];
    if (localInstance == null)
    {
        synchronized (NotificationCenter.class)
        {
            localInstance = Instance[num];
            if (localInstance == null)
            {
                Instance[num] = localInstance = new NotificationCenter(num);
            }
        }
    }
    return localInstance;
}
 
源代码11 项目: TelePlus-Android   文件: NotificationCenter.java
@UiThread
public static NotificationCenter getGlobalInstance()
{
    NotificationCenter localInstance = globalInstance;
    if (localInstance == null)
    {
        synchronized (NotificationCenter.class)
        {
            localInstance = globalInstance;
            if (localInstance == null)
            {
                globalInstance = localInstance = new NotificationCenter(-1);
            }
        }
    }
    return localInstance;
}
 
源代码12 项目: Walrus   文件: Proxmark3Device.java
@Override
@UiThread
public void createWriteOrEmulateDataOperation(AppCompatActivity activity, CardData cardData,
        boolean write, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);

    ((OnOperationCreatedCallback) activity).onOperationCreated(
            new WriteOrEmulateHIDOperation(this, cardData, write), callbackId);
}
 
源代码13 项目: connectivity-samples   文件: MainActivity.java
/** {@see ConnectionsActivity#onReceive(Endpoint, Payload)} */
@Override
protected void onReceive(Endpoint endpoint, Payload payload) {
  if (payload.getType() == Payload.Type.STREAM) {
    if (mAudioPlayer != null) {
      mAudioPlayer.stop();
      mAudioPlayer = null;
    }

    AudioPlayer player =
        new AudioPlayer(payload.asStream().asInputStream()) {
          @WorkerThread
          @Override
          protected void onFinish() {
            runOnUiThread(
                new Runnable() {
                  @UiThread
                  @Override
                  public void run() {
                    mAudioPlayer = null;
                  }
                });
          }
        };
    mAudioPlayer = player;
    player.start();
  }
}
 
源代码14 项目: Walrus   文件: ChameleonMiniRevERebootedDevice.java
@Override
@UiThread
public void createReadCardDataOperation(AppCompatActivity activity,
        Class<? extends CardData> cardDataClass, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);
    throw new UnsupportedOperationException("Device does not support ReadCardDataOperation");
}
 
源代码15 项目: Walrus   文件: DebugDevice.java
@Override
@UiThread
public void createReadCardDataOperation(AppCompatActivity activity,
        Class<? extends CardData> cardDataClass, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);

    ((OnOperationCreatedCallback) activity).onOperationCreated(
            new ReadAnyOperation(this, cardDataClass), callbackId);
}
 
源代码16 项目: Walrus   文件: ChameleonMiniRevGDevice.java
@Override
@UiThread
public void createReadCardDataOperation(AppCompatActivity activity,
        Class<? extends CardData> cardDataClass, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);

    ((OnOperationCreatedCallback) activity).onOperationCreated(new ReadMifareOperation(this),
            callbackId);
}
 
源代码17 项目: DMusic   文件: Operater.java
@UiThread
public void start(TransferModel model) {
    List<TransferModel> list = mPipe.mDownloadingQueue;
    if (list.size() - 1 > 0) {
        pause(list.get(list.size() - 1));
    }
    startImpl(model);
}
 
源代码18 项目: play-billing-codelab   文件: GamePlayActivity.java
/**
 * Update UI to reflect model
 */
@UiThread
private void updateUi() {
    Log.d(TAG, "Updating the UI. Thread: " + Thread.currentThread().getName());

    // Update gas gauge to reflect tank status
    mGasImageView.setImageResource(mViewController.getTankResId());
}
 
源代码19 项目: mvvm-template   文件: AnimHelper.java
@UiThread public static void startBeatsAnimation(@NonNull View view) {
    view.clearAnimation();
    if (view.getAnimation() != null) {
        view.getAnimation().cancel();
    }
    List<ObjectAnimator> animators = getBeats(view);
    for (ObjectAnimator anim : animators) {
        anim.setDuration(300).start();
        anim.setInterpolator(interpolator);
    }
}
 
源代码20 项目: Common   文件: AbstractBus.java
/**
 * Unregisters the given subscriber from all event classes.
 */
@UiThread
public synchronized void unregister(Callback subscriber) {
    if (subscriber != null) {
        mCallbacks.remove(subscriber);
    }
}
 
源代码21 项目: Common   文件: AbstractBus.java
@UiThread
@Override
public void onError(Throwable e) {
    for (int i = 0; i < mCallbacks.size(); i++) {
        Callback l = mCallbacks.get(i);
        if (l != null) {
            l.onError(e);
        }
    }
}
 
源代码22 项目: DMusic   文件: FrameCache.java
@SuppressWarnings("unused")
@UiThread
public static void release(Context context) {
    if (context == null) {
        return;
    }
    FrameCacheManager.getIns(context.getApplicationContext()).release();
}
 
源代码23 项目: widgetlab   文件: TypingIndicatorView.java
@UiThread
public void stopDotAnimation() {
    isAnimationStarted = false;

    // There is a report saying NPE here.  Not sure how is it possible.
    try {
        handler.removeCallbacks(dotAnimationRunnable);
    } catch (Exception ex) {
        Log.e(TAG, "stopDotAnimation: weird crash", ex);
    }
}
 
源代码24 项目: Common   文件: AbstractProgressBus.java
@UiThread
@Override
public void onCancel() {
    for (int i = 0; i < mCallbacks.size(); i++) {
        Callback l = mCallbacks.get(i);
        if (l != null) {
            l.onCancel();
        }
    }
}
 
源代码25 项目: DMusic   文件: Pipe.java
@UiThread
public void add(TransferModel item) {
    for (int i = 0; i < mList.size(); i++) {
        TransferModel transfer = mList.get(i);
        if (transfer.type.equals(item.type)
                && TextUtils.equals(transfer.songId, item.songId)) {
            return;
        }
    }
    mDownloading.add(item);
    mList.add(item);
    notifyItemInserted(item);
}
 
源代码26 项目: DMusic   文件: FrameCache.java
@SuppressWarnings("unused")
@UiThread
public static void clear(View view) {
    if (view == null) {
        return;
    }
    view.setTag(getTag(), "");
}
 
源代码27 项目: play-billing-codelab   文件: GamePlayActivity.java
/**
 * Update UI to reflect model
 */
@UiThread
private void updateUi() {
    Log.d(TAG, "Updating the UI. Thread: " + Thread.currentThread().getName());

    // Update gas gauge to reflect tank status
    mGasImageView.setImageResource(mViewController.getTankResId());
}
 
@UiThread
protected PresentationComponent getPresentationComponent() {
    if (mIsInjectorUsed) {
        throw new RuntimeException("there is no need to use injector more than once");
    }
    mIsInjectorUsed = true;
    return getApplicationComponent()
            .newPresentationComponent(new PresentationModule(getActivity()));

}
 
源代码29 项目: javaide   文件: ConsoleEditText.java
@UiThread
private void appendStderr(final CharSequence str) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            SpannableString spannableString = new SpannableString(str);
            spannableString.setSpan(new ForegroundColorSpan(Color.RED), 0, str.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            append(spannableString);
        }
    });
}
 
源代码30 项目: FriendBook   文件: MvpBasePresenter.java
@UiThread
@Override
public void destroy() {
    if (isViewAttached()) {
        detachView();
    }
}
 
 类方法
 同包方法