android.support.annotation.UiThread Java Examples

The following examples show how to use android.support.annotation.UiThread. 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: GamePlayActivity.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
/** {@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();
  }
}
 
Example #3
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
/** 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();
  }
}
 
Example #4
Source File: PushControllerWizardActivity.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
@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();
    });
}
 
Example #5
Source File: AsyncListUtil.java    From letv with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: TaskDispatcher.java    From android-performance with MIT License 6 votes vote down vote up
@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));
}
 
Example #7
Source File: PictureCompressor.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #8
Source File: NotificationCenter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #9
Source File: NotificationCenter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #10
Source File: TapTargetSequence.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: GamePlayActivity.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #12
Source File: ConsoleEditText.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@UiThread
private void appendStdout(final CharSequence spannableString) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            append(spannableString);
        }
    });
}
 
Example #13
Source File: ConsoleEditText.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@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);
        }
    });
}
 
Example #14
Source File: GamePlayActivity.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #15
Source File: Operater.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@UiThread
public void start(TransferModel model) {
    List<TransferModel> list = mPipe.mDownloadingQueue;
    if (list.size() - 1 > 0) {
        pause(list.get(list.size() - 1));
    }
    startImpl(model);
}
 
Example #16
Source File: GamePlayActivity.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #17
Source File: Operater.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@UiThread
public void pauseAll() {
    List<TransferModel> list = mPipe.mDownloadingQueue;
    for (int i = list.size() - 1; i >= 0; i = list.size() - 1) {
        pause(list.get(i));
    }
    notifyDataSetChanged();
}
 
Example #18
Source File: ChameleonMiniRevERebootedDevice.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
@UiThread
public void createReadCardDataOperation(AppCompatActivity activity,
        Class<? extends CardData> cardDataClass, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);
    throw new UnsupportedOperationException("Device does not support ReadCardDataOperation");
}
 
Example #19
Source File: ChameleonMiniRevGDevice.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
@UiThread
public void createReadCardDataOperation(AppCompatActivity activity,
        Class<? extends CardData> cardDataClass, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);

    ((OnOperationCreatedCallback) activity).onOperationCreated(new ReadMifareOperation(this),
            callbackId);
}
 
Example #20
Source File: AnimHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example #21
Source File: BaseDialog.java    From dependency-injection-in-android-course with Apache License 2.0 5 votes vote down vote up
@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()));

}
 
Example #22
Source File: TuSDKEditorBarFragment.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
/********************** 微整形 ***********************

     /**
     * 初始化微整形视图
     */
    @UiThread
    public void prepareBeautyPlasticViews() {
        mBeautyPlasticRecyclerAdapter = new BeautyPlasticRecyclerAdapter(getContext(), mBeautyPlastics);
        mBeautyPlasticRecyclerAdapter.setOnBeautyPlasticItemClickListener(beautyPlasticItemClickListener);

        // 美型Bar
        mBeautyConfigView.setSeekBarDelegate(mBeautyConfigDelegate);
        mBeautyConfigView.setVisibility(View.GONE);
        mBeautyPlasticRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
    }
 
Example #23
Source File: AbstractBus.java    From Common with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters the given subscriber from all event classes.
 */
@UiThread
public synchronized void unregister(Callback subscriber) {
    if (subscriber != null) {
        mCallbacks.remove(subscriber);
    }
}
 
Example #24
Source File: AbstractBus.java    From Common with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example #25
Source File: Proxmark3Device.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
@UiThread
public void createWriteOrEmulateDataOperation(AppCompatActivity activity, CardData cardData,
        boolean write, int callbackId) {
    ensureOperationCreatedCallbackSupported(activity);

    ((OnOperationCreatedCallback) activity).onOperationCreated(
            new WriteOrEmulateHIDOperation(this, cardData, write), callbackId);
}
 
Example #26
Source File: FrameCache.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@UiThread
public static void release(Context context) {
    if (context == null) {
        return;
    }
    FrameCacheManager.getIns(context.getApplicationContext()).release();
}
 
Example #27
Source File: TypingIndicatorView.java    From widgetlab with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #28
Source File: AbstractProgressBus.java    From Common with Apache License 2.0 5 votes vote down vote up
@UiThread
@Override
public void onCancel() {
    for (int i = 0; i < mCallbacks.size(); i++) {
        Callback l = mCallbacks.get(i);
        if (l != null) {
            l.onCancel();
        }
    }
}
 
Example #29
Source File: Pipe.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #30
Source File: FrameCache.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@UiThread
public static void clear(View view) {
    if (view == null) {
        return;
    }
    view.setTag(getTag(), "");
}