当前位置: 首页>>代码示例>>Java>>正文


Java AnyThread类代码示例

本文整理汇总了Java中android.support.annotation.AnyThread的典型用法代码示例。如果您正苦于以下问题:Java AnyThread类的具体用法?Java AnyThread怎么用?Java AnyThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnyThread类属于android.support.annotation包,在下文中一共展示了AnyThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refreshProgress

import android.support.annotation.AnyThread; //导入依赖的package包/类
/**
 * Refreshes the current progress value displayed by this progress bar with respect to UI thread,
 * so this can be also called from the background thread.
 * <p>
 * If called from the UI thread, {@link #onRefreshProgress(int, int, boolean)} will be called
 * immediately, otherwise to refresh progress will be posted runnable.
 *
 * @param id       One of {@link android.R.id#progress} or {@link android.R.id#secondaryProgress}.
 * @param progress The progress value to be refreshed.
 */
@AnyThread
@SuppressWarnings("WrongThread")
final synchronized void refreshProgress(int id, int progress) {
	if (mUiThreadId == Thread.currentThread().getId()) {
		onRefreshProgress(id, progress, true);
		return;
	}
	if (mRefreshProgressRunnable == null) {
		this.mRefreshProgressRunnable = new RefreshProgressRunnable();
	}
	final RefreshData refreshData = RefreshData.obtain(id, progress);
	mRefreshProgressRunnable.refreshData.add(refreshData);
	if ((mPrivateFlags & PrivateFlags.PFLAG_ATTACHED_TO_WINDOW) != 0 && (mPrivateFlags & PFLAG_REFRESH_PROGRESS_POSTED) == 0) {
		post(mRefreshProgressRunnable);
		this.updatePrivateFlags(PFLAG_REFRESH_PROGRESS_POSTED, true);
	}
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:28,代码来源:BaseProgressBar.java

示例2: notifyComponents

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread
public static HandlerType notifyComponents(@NonNull Context context, @NonNull Intent intent) {
  boolean handled = LocalBroadcastManager.getInstance(context).sendBroadcast(intent);

  if (handled) {
    return HandlerType.COMPONENT;
  }

  final PackageManager packageManager = context.getPackageManager();
  if (intent.resolveActivity(packageManager) != null) {
    context.startActivity(intent);
    return HandlerType.ACTIVITY;
  }

  return HandlerType.NONE;
}
 
开发者ID:azmedien,项目名称:kolibri-android,代码行数:17,代码来源:Kolibri.java

示例3: shutdown

import android.support.annotation.AnyThread; //导入依赖的package包/类
/**
 * Shut down the renderer when you're finished.
 */
@Override
@AnyThread
public void shutdown() {
    synchronized (this) {
        if (!isRunning()) {
            Log.d(TAG, "requesting shutdown...");
            renderHandler.removeCallbacks(this);
            renderHandler.postAtFrontOfQueue(() -> {
                Log.i(TAG, "shutting down");
                synchronized (this) {
                    droppedFrameLogger = null;
                    yuvInAlloc.destroy();
                    rgbInAlloc.destroy();
                    rgbOutAlloc.destroy();
                    yuvToRGBScript.destroy();
                    if (renderThread != null) {
                        renderThread.quitSafely();
                    }
                }
            });
            renderHandler = null;
        }
    }
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:28,代码来源:RsCameraPreviewRenderer.java

示例4: saveSession

import android.support.annotation.AnyThread; //导入依赖的package包/类
/** Saves a {@link FirefoxAccountSession} to be restored with {@link #loadSession()}. */
@AnyThread
void saveSession(@NonNull final FirefoxAccountSession session) {
    final FirefoxAccount account = session.firefoxAccount;
    sharedPrefs.edit()
            .putInt(KEY_VERSION, STORE_VERSION)
            .putString(KEY_EMAIL, account.email)
            .putString(KEY_UID, account.uid)
            .putString(KEY_STATE_LABEL, account.accountState.getStateLabel().name())
            .putString(KEY_STATE_JSON, account.accountState.toJSONObject().toJSONString())

            // Future builds can change the endpoints in their config so we only store the label
            // so we can pull in the latest endpoints.
            .putString(KEY_ENDPOINT_CONFIG_LABEL, account.endpointConfig.label)
            .putString(KEY_APPLICATION_NAME, session.applicationName)
            .apply();
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:FirefoxAccountSessionSharedPrefsStore.java

示例5: runIfNotRunning

import android.support.annotation.AnyThread; //导入依赖的package包/类
/**
 * Runs the given {@link Request} if no other requests in the given request type is already
 * running.
 * <p>
 * If run, the request will be run in the current thread.
 *
 * @param type    The type of the request.
 * @param request The request to run.
 * @return True if the request is run, false otherwise.
 */
@SuppressWarnings("WeakerAccess")
@AnyThread
public boolean runIfNotRunning(@NonNull RequestType type, @NonNull Request request) {
    boolean hasListeners = !mListeners.isEmpty();
    StatusReport report = null;
    synchronized (mLock) {
        RequestQueue queue = mRequestQueues[type.ordinal()];
        if (queue.mRunning != null) {
            return false;
        }
        queue.mRunning = request;
        queue.mStatus = Status.RUNNING;
        queue.mFailed = null;
        queue.mLastError = null;
        if (hasListeners) {
            report = prepareStatusReportLocked();
        }
    }
    if (report != null) {
        dispatchReport(report);
    }
    final RequestWrapper wrapper = new RequestWrapper(request, this, type);
    wrapper.run();
    return true;
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:36,代码来源:PagingRequestHelper.java

示例6: recordResult

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread
@VisibleForTesting
void recordResult(@NonNull RequestWrapper wrapper, @Nullable Throwable throwable) {
    StatusReport report = null;
    final boolean success = throwable == null;
    boolean hasListeners = !mListeners.isEmpty();
    synchronized (mLock) {
        RequestQueue queue = mRequestQueues[wrapper.mType.ordinal()];
        queue.mRunning = null;
        queue.mLastError = throwable;
        if (success) {
            queue.mFailed = null;
            queue.mStatus = Status.SUCCESS;
        } else {
            queue.mFailed = wrapper;
            queue.mStatus = Status.FAILED;
        }
        if (hasListeners) {
            report = prepareStatusReportLocked();
        }
    }
    if (report != null) {
        dispatchReport(report);
    }
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:26,代码来源:PagingRequestHelper.java

示例7: loadData

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread
public static void loadData(final int page, final Object param, final LoadDataCallback cb) {
    sExecutor.execute(new Runnable() {
        @Override
        public void run() {
            final BaseResult<Item> result = loadDataSync(page, param);
            sUiHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (cb != null) {
                        if (result != null) {
                            cb.onLoadSuccess(page, result.getData(), result.isPageMore());
                        } else {
                            cb.onLoadFailed(page);
                        }
                    }
                }
            });
        }
    });
}
 
开发者ID:liyuanhust,项目名称:LoadMoreHelper,代码行数:22,代码来源:DataLoader.java

示例8: getDvrStorageStatus

import android.support.annotation.AnyThread; //导入依赖的package包/类
/**
 * Returns the current storage status for DVR recordings.
 *
 * @return {@link StorageStatus}
 */
@AnyThread
public @StorageStatus int getDvrStorageStatus() {
    MountedStorageStatus status = mMountedStorageStatus;
    if (status.mStorageMountedDir == null) {
        return STORAGE_STATUS_MISSING;
    }
    if (CommonFeatures.FORCE_RECORDING_UNTIL_NO_SPACE.isEnabled(mContext)) {
        return STORAGE_STATUS_OK;
    }
    if (status.mStorageMountedCapacity < MIN_STORAGE_SIZE_FOR_DVR_IN_BYTES) {
        return STORAGE_STATUS_TOTAL_CAPACITY_TOO_SMALL;
    }
    try {
        StatFs statFs = new StatFs(status.mStorageMountedDir.toString());
        if (statFs.getAvailableBytes() < MIN_FREE_STORAGE_SIZE_FOR_DVR_IN_BYTES) {
            return STORAGE_STATUS_FREE_SPACE_INSUFFICIENT;
        }
    } catch (IllegalArgumentException e) {
        // In rare cases, storage status change was not notified yet.
        SoftPreconditions.checkState(false);
        return STORAGE_STATUS_FREE_SPACE_INSUFFICIENT;
    }
    return STORAGE_STATUS_OK;
}
 
开发者ID:trevd,项目名称:android_packages_apps_tv,代码行数:30,代码来源:DvrStorageStatusManager.java

示例9: setColorStops

import android.support.annotation.AnyThread; //导入依赖的package包/类
/**
 * 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]);
}
 
开发者ID:HeartlandSoftware,项目名称:AndroidHeatMap,代码行数:21,代码来源:HeatMap.java

示例10: getScale

import android.support.annotation.AnyThread; //导入依赖的package包/类
@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;
}
 
开发者ID:HeartlandSoftware,项目名称:AndroidHeatMap,代码行数:17,代码来源:HeatMap.java

示例11: redrawShadow

import android.support.annotation.AnyThread; //导入依赖的package包/类
@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);
}
 
开发者ID:HeartlandSoftware,项目名称:AndroidHeatMap,代码行数:17,代码来源:HeatMap.java

示例12: readState

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread
@NonNull
private 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();
    }
}
 
开发者ID:openid,项目名称:AppAuth-Android,代码行数:21,代码来源:AuthStateManager.java

示例13: writeState

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread
private 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();
    }
}
 
开发者ID:openid,项目名称:AppAuth-Android,代码行数:19,代码来源:AuthStateManager.java

示例14: onError

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread @Override public void onError(final Exception e)
{
	runOnUiThread(() ->
	{
		// a 5xx error is not the fault of this app. Nothing we can do about it, so it does not
		// make sense to send an error report. Just notify the user
		// Also, we treat an invalid response the same as a (temporary) connection error
		if (e instanceof OsmConnectionException || e instanceof OsmApiReadResponseException)
		{
			Toast.makeText(MainActivity.this,R.string.download_server_error, Toast.LENGTH_LONG).show();
		}
		else
		{
			crashReportExceptionHandler.askUserToSendErrorReport(MainActivity.this, R.string.download_error, e);
		}
	});
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:18,代码来源:MainActivity.java

示例15: onQuestsCreated

import android.support.annotation.AnyThread; //导入依赖的package包/类
@AnyThread @Override
public void onQuestsCreated(final Collection<? extends Quest> quests, final QuestGroup group)
{
	runOnUiThread(() -> mapFragment.addQuests(quests, group));
	// to recreate element geometry of selected quest (if any) after recreation of activity
	if(getQuestDetailsFragment() != null)
	{
		for (Quest q : quests)
		{
			if (isQuestDetailsCurrentlyDisplayedFor(q.getId(), group))
			{
				questController.retrieve(group, q.getId());
				return;
			}
		}
	}
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:18,代码来源:MainActivity.java


注:本文中的android.support.annotation.AnyThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。