android.support.annotation.AnyThread Java Examples

The following examples show how to use android.support.annotation.AnyThread. 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: Hook12306Impl2.java    From 12306XposedPlugin with GNU General Public License v3.0 6 votes vote down vote up
@AnyThread
private void playMusic() {
    if (messageClient != null) {
        bindService();
        messageClient.sendToTarget(EventCode.CODE_PLAY_MUSIC);
        messageClient.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (vibrator != null) {
                    vibrator.cancel();
                }
                vibrator = (Vibrator) messageClient.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
                long[] patter = {500, 3000, 500, 3000};
                assert vibrator != null;
                vibrator.vibrate(patter, 0);
            }
        });
    }
}
 
Example #2
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 6 votes vote down vote up
/**
 * Set the color stops used for the heat map's gradient. There needs to be at least 2 stops
 * and there should be one at a position of 0 and one at a position of 1.
 * @param stops A map from stop positions (as fractions of the width in [0,1]) to ARGB colors.
 */
@AnyThread
public void setColorStops(Map<Float, Integer> stops) {
    if (stops.size() < 2)
        throw new IllegalArgumentException("There must be at least 2 color stops");
    colors = new int[stops.size()];
    positions = new float[stops.size()];
    int i = 0;
    for (Float key : stops.keySet()) {
        colors[i] = stops.get(key);
        positions[i] = key;
        i++;
    }
    if (!mTransparentBackground)
        mBackground.setColor(colors[0]);
}
 
Example #3
Source File: OktaAppAuth.java    From okta-sdk-appauth-android with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the OktaAppAuth object. This will fetch an OpenID Connect discovery document
 * from the issuer in the configuration to configure this instance for use.
 *
 * @param context        The application context
 * @param listener       An OktaAuthListener that will be called once the initialization is
 *                       complete
 * @param customTabColor The color that will be passed to
 *                       {@link CustomTabsIntent.Builder#setToolbarColor(int)}
 * @param oktaConnectionBuilder        Implementation of {@link OktaConnectionBuilder}
 */
@AnyThread
public void init(
        final Context context,
        final OktaAuthListener listener,
        @ColorInt int customTabColor,
        final OktaConnectionBuilder oktaConnectionBuilder) {
    mCustomTabColor = customTabColor;
    mConnectionBuilder = new ConnectionBuilder() {
        @NonNull
        @Override
        public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException {
            return oktaConnectionBuilder.openConnection(uri);
        }
    };
    mExecutor.submit(new Runnable() {
        @Override
        public void run() {
            doInit(context, mConnectionBuilder, listener);
        }
    });
}
 
Example #4
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 6 votes vote down vote up
@AnyThread
@SuppressWarnings("WrongThread")
private float getScale() {
    if (mMaxWidth == null || mMaxHeight == null)
        return 1.0f;
    float sourceRatio = getWidth() / getHeight();
    float targetRatio = mMaxWidth / mMaxHeight;
    float scale;
    if (sourceRatio < targetRatio) {
        scale = getWidth() / ((float)mMaxWidth);
    }
    else {
        scale = getHeight() / ((float)mMaxHeight);
    }
    return scale;
}
 
Example #5
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 6 votes vote down vote up
@AnyThread
@SuppressLint("WrongThread")
private void redrawShadow(int width, int height) {
    mRenderBoundaries[0] = 10000;
    mRenderBoundaries[1] = 10000;
    mRenderBoundaries[2] = 0;
    mRenderBoundaries[3] = 0;

    if (mUseDrawingCache)
        mShadow = getDrawingCache();
    else
        mShadow = Bitmap.createBitmap(getDrawingWidth(), getDrawingHeight(), Bitmap.Config.ARGB_8888);
    Canvas shadowCanvas = new Canvas(mShadow);

    drawTransparent(shadowCanvas, width, height);
}
 
Example #6
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 6 votes vote down vote up
@AnyThread
@VisibleForTesting
void writeState(@Nullable AuthState state) {
    mPrefsLock.lock();
    try {
        SharedPreferences.Editor editor = mPrefs.edit();
        if (state == null) {
            editor.remove(KEY_STATE);
        } else {
            editor.putString(KEY_STATE, state.jsonSerializeString());
        }

        if (!editor.commit()) {
            throw new IllegalStateException("Failed to write state to shared prefs");
        }
    } finally {
        mPrefsLock.unlock();
    }
}
 
Example #7
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 6 votes vote down vote up
@AnyThread
@NonNull
@VisibleForTesting
AuthState readState() {
    mPrefsLock.lock();
    try {
        String currentState = mPrefs.getString(KEY_STATE, null);
        if (currentState == null) {
            return new AuthState();
        }

        try {
            return AuthState.jsonDeserialize(currentState);
        } catch (JSONException ex) {
            Log.w(TAG, "Failed to deserialize stored auth state - discarding");
            return new AuthState();
        }
    } finally {
        mPrefsLock.unlock();
    }
}
 
Example #8
Source File: SecKill.java    From 12306XposedPlugin with GNU General Public License v3.0 6 votes vote down vote up
@AnyThread
private void createTimer() {
    if (currentTask == null) {
        return;
    }
    long nowTime = System.currentTimeMillis();
    long interval = currentTask.getKillTime() - nowTime;
    // 任务结束
    if (interval <= -1000) {
        currentTask = null;
        if (timerPair != null) {
            timerPair.first.cancel();
        }
        Log.i(TAG, "任务结束");
        return;
    }
    if (interval > 5 * 60 * 1000) {
        createTimeTask(60_000);
    } else if (interval > 60 * 1000) {
        createTimeTask(30_000);
    } else if (interval > 5 * 1000) {
        createTimeTask(3000);
    } else {
        createTimeTask(MIN_INTERVAL);
    }
}
 
Example #9
Source File: MainActivity.java    From 12306XposedPlugin with GNU General Public License v3.0 6 votes vote down vote up
@AnyThread
public void update() {
    executorService.execute(new Runnable() {
        @Override
        public void run() {
            LitePal.where("status=?", "0").findAsync(TaskDao.class)
                    .listen(new FindMultiCallback<TaskDao>() {
                        @Override
                        public void onFinish(final List<TaskDao> list) {
                            recyclerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    update(list);
                                }
                            });
                        }
                    });
        }
    });
}
 
Example #10
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 5 votes vote down vote up
@AnyThread
@SuppressLint("WrongThread")
private int getDrawingHeight() {
    if (mMaxHeight == null)
        return getHeight();
    return Math.min(calcMaxHeight(), getHeight());
}
 
Example #11
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 5 votes vote down vote up
@AnyThread
@SuppressLint("WrongThread")
private int getDrawingWidth() {
    if (mMaxWidth == null)
        return getWidth();
    return Math.min(calcMaxWidth(), getWidth());
}
 
Example #12
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 5 votes vote down vote up
/**
 * Set the blur factor for the heat map. Must be between 0 and 1.
 * @param blur The blur factor
 */
@AnyThread
public void setBlur(double blur) {
    if (blur > 1.0 || blur < 0.0)
        throw new IllegalArgumentException("Blur must be between 0 and 1.");
    mBlur = blur;
}
 
Example #13
Source File: HeatMap.java    From AndroidHeatMap with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a radial gradient at a given location. Only draws in black with the gradient being only
 * in transparency.
 *
 * @param canvas Canvas to draw into.
 * @param x The x location to draw the point.
 * @param y The y location to draw the point.
 * @param radius The radius (in pixels) of the point.
 * @param blurFactor A factor to scale the circles width by.
 * @param alpha The transparency of the gradient.
 */
@AnyThread
private void drawDataPoint(Canvas canvas, float x, float y, double radius, double blurFactor, double alpha) {
    if (blurFactor == 1) {
        canvas.drawCircle(x, y, (float)radius, mBlack);
    }
    else {
        //create a radial gradient at the requested position with the requested size
        RadialGradient gradient = new RadialGradient(x, y, (float)(radius * blurFactor),
                new int[] { Color.argb((int)(alpha * 255), 0, 0, 0), Color.argb(0, 0, 0, 0) },
                null, Shader.TileMode.CLAMP);
        mFill.setShader(gradient);
        canvas.drawCircle(x, y, (float)(2 * radius), mFill);
    }
}
 
Example #14
Source File: SubsamplingScaleImageView.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Debug logger
 */
@AnyThread
private void debug(String message, Object... args) {
    if (debug) {
        Log.d(TAG, String.format(message, args));
    }
}
 
Example #15
Source File: MainActivity.java    From AndroidHeatMap with Apache License 2.0 5 votes vote down vote up
@AnyThread
private void drawNewMap() {
    map.clearData();
    Random rand = new Random();
    //add 20 random points of random intensity
    for (int i = 0; i < 20; i++) {
        HeatMap.DataPoint point = new HeatMap.DataPoint(clamp(rand.nextFloat(), 0.0f, 1.0f),
                clamp(rand.nextFloat(), 0.0f, 1.0f), clamp(rand.nextDouble(), 0.0, 100.0));
        map.addData(point);
    }
}
 
Example #16
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the manager object via the static {@link WeakReference} or construct a new instance.
 * Stores the state in the {@link SharedPreferences} that we get from the
 * {@link Context#getSharedPreferences(String, int)} in {@link Context#MODE_PRIVATE}.
 *
 * @param context The Context from which to get the application's environment
 * @return an AuthStateManager object
 */
@AnyThread
public static AuthStateManager getInstance(@NonNull Context context) {
    AuthStateManager manager = INSTANCE_REF.get().get();
    if (manager == null) {
        manager = new AuthStateManager(
                context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE),
                new ReentrantLock()
        );
    }

    return manager;
}
 
Example #17
Source File: JobService.java    From firebase-jobdispatcher-android with Apache License 2.0 5 votes vote down vote up
/**
 * Callback to inform the scheduling driver that you've finished executing. Can be called from any
 * thread. When the system receives this message, it will release the wakelock being held.
 *
 * @param job
 * @param needsReschedule whether the job should be rescheduled
 * @see com.firebase.jobdispatcher.JobInvocation.Builder#setRetryStrategy(RetryStrategy)
 */
@AnyThread
public final void jobFinished(@NonNull JobParameters job, boolean needsReschedule) {
  if (job == null) {
    Log.e(TAG, "jobFinished called with a null JobParameters");
    return;
  }

  this.backgroundExecutor.execute(
      UnitOfWork.removeAndFinishJobWithResult(
          this, job, /* result= */ needsReschedule ? RESULT_FAIL_RETRY : RESULT_SUCCESS));
}
 
Example #18
Source File: SubsamplingScaleImageView.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Converts source rectangle from tile, which treats the image file as if it were in the correct orientation already,
 * to the rectangle of the image that needs to be loaded.
 */
@SuppressWarnings("SuspiciousNameCombination")
@AnyThread
private void fileSRect(Rect sRect, Rect target) {
    if (getRequiredRotation() == 0) {
        target.set(sRect);
    } else if (getRequiredRotation() == 90) {
        target.set(sRect.top, sHeight - sRect.right, sRect.bottom, sHeight - sRect.left);
    } else if (getRequiredRotation() == 180) {
        target.set(sWidth - sRect.right, sHeight - sRect.bottom, sWidth - sRect.left, sHeight - sRect.top);
    } else {
        target.set(sWidth - sRect.bottom, sRect.left, sWidth - sRect.top, sRect.right);
    }
}
 
Example #19
Source File: SubsamplingScaleImageView.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Converts source rectangle from tile, which treats the image file as if it were in the correct orientation already,
 * to the rectangle of the image that needs to be loaded.
 */
@SuppressWarnings("SuspiciousNameCombination")
@AnyThread
private void fileSRect(Rect sRect, Rect target) {
    if (getRequiredRotation() == 0) {
        target.set(sRect);
    } else if (getRequiredRotation() == 90) {
        target.set(sRect.top, sHeight - sRect.right, sRect.bottom, sHeight - sRect.left);
    } else if (getRequiredRotation() == 180) {
        target.set(sWidth - sRect.right, sHeight - sRect.bottom, sWidth - sRect.left, sHeight - sRect.top);
    } else {
        target.set(sWidth - sRect.bottom, sRect.left, sWidth - sRect.top, sRect.right);
    }
}
 
Example #20
Source File: SubsamplingScaleImageView.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the rotation to be applied to tiles, based on EXIF orientation or chosen setting.
 */
@AnyThread
private int getRequiredRotation() {
    if (orientation == ORIENTATION_USE_EXIF) {
        return sOrientation;
    } else {
        return orientation;
    }
}
 
Example #21
Source File: SubsamplingScaleImageView.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Debug logger
 */
@AnyThread
private void debug(String message, Object... args) {
    if (debug) {
        Log.d(TAG, String.format(message, args));
    }
}
 
Example #22
Source File: SubsamplingScaleImageView.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the rotation to be applied to tiles, based on EXIF orientation or chosen setting.
 */
@AnyThread
private int getRequiredRotation() {
    if (orientation == ORIENTATION_USE_EXIF) {
        return sOrientation;
    } else {
        return orientation;
    }
}
 
Example #23
Source File: OktaAppAuth.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an OktaAppAuth object. Provided the Context to initialize any other components.
 *
 * @param context The application Context
 */
@AnyThread
protected OktaAppAuth(Context context) {
    mContext = new WeakReference<>(context);
    mExecutor = Executors.newSingleThreadExecutor();
    mAuthStateManager = AuthStateManager.getInstance(context.getApplicationContext());
    mConfiguration = OAuthClientConfiguration.getInstance(context);
}
 
Example #24
Source File: OktaAppAuth.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the manager object via the static {@link WeakReference} or construct a new instance.
 *
 * @param context The Context from which to get the application's environment
 * @return am OktaAppAuth object
 */
@AnyThread
public static OktaAppAuth getInstance(@NonNull Context context) {
    OktaAppAuth oktaAppAuth = INSTANCE_REF.get().get();
    if (oktaAppAuth == null) {
        oktaAppAuth = new OktaAppAuth(context);
        INSTANCE_REF.set(new WeakReference<>(oktaAppAuth));
    } else if (oktaAppAuth.mContext.get() == null) {
        oktaAppAuth.mContext = new WeakReference<>(context);
    }

    return oktaAppAuth;
}
 
Example #25
Source File: Hook12306Impl2.java    From 12306XposedPlugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 抢票成功
 */
@AnyThread
private void ticketSuccess(@NonNull Trains trains) {
    isStarted.set(false);
    playMusic();
    messageClient.sendToTarget(EventCode.CODE_TICKET_SUCCESS);
    MessageUtil.sendToHi(trains);
}
 
Example #26
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Called after the token exchange is complete or a refresh token is used to acquire a new
 * access token.
 *
 * @param response The TokenResponse from the Authorization Server
 * @param ex Any AuthorizationException that occurred during the token exchange
 * @return The updated AuthState
 */
@AnyThread
@NonNull
public AuthState updateAfterTokenResponse(
        @Nullable TokenResponse response,
        @Nullable AuthorizationException ex) {
    AuthState current = getCurrent();
    current.update(response, ex);
    return replace(current);
}
 
Example #27
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Called after the app receives the callback from the authorization code flow. This updates
 * the state to prepare for the token exchange.
 *
 * @param response The AuthorizationResponse from the Authorization Server
 * @param ex Any AuthorizationException that occurred during the authorization code flow
 * @return The updated AuthState
 */
@AnyThread
@NonNull
public AuthState updateAfterAuthorization(
        @Nullable AuthorizationResponse response,
        @Nullable AuthorizationException ex) {
    AuthState current = getCurrent();
    current.update(response, ex);
    return replace(current);
}
 
Example #28
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the current AuthState in {@link SharedPreferences} with the provided once.
 *
 * @param state The updated AuthState
 * @return The AuthState which was stored in the SharedPreferences
 */
@AnyThread
@NonNull
public AuthState replace(@NonNull AuthState state) {
    writeState(state);
    mCurrentAuthState.set(state);
    return state;
}
 
Example #29
Source File: AuthStateManager.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current AuthState stored in the {@link SharedPreferences}.
 *
 * @return the stored AuthState
 */
@AnyThread
@NonNull
public AuthState getCurrent() {
    if (mCurrentAuthState.get() != null) {
        return mCurrentAuthState.get();
    }

    AuthState state = readState();
    if (mCurrentAuthState.compareAndSet(null, state)) {
        return state;
    } else {
        return mCurrentAuthState.get();
    }
}
 
Example #30
Source File: OAuthClientConfiguration.java    From okta-sdk-appauth-android with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Retrieve the configuration object via the static {@link WeakReference} or construct a new
 * instance using the configuration provided via a resource file.
 * </p>
 * <p>
 * NOTE: The OAuthClientConfiguration may have an error after constructing. Call
 * {@link #isValid()} to ensure its validity.
 * </p>
 *
 * @param context The Context from which to get the application's resources
 * @return an OAuthClientConfiguration object
 */
@AnyThread
public static OAuthClientConfiguration getInstance(final Context context) {
    OAuthClientConfiguration config = INSTANCE_REF.get().get();
    if (config == null) {
        config = new OAuthClientConfiguration(
                context.getApplicationContext(),
                context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE),
                context.getResources().openRawResource(R.raw.okta_app_auth_config)
        );
    }

    return config;
}