下面列出了android.util.Log#isLoggable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void unregisterNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
enforceSystemOnly();
final long token = Binder.clearCallingIdentity();
try {
synchronized (mScoreCaches) {
RemoteCallbackList<INetworkScoreCache> callbackList = mScoreCaches.get(networkType);
if (callbackList == null || !callbackList.unregister(scoreCache)) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Unable to unregister NetworkScoreCache for type "
+ networkType);
}
} else if (callbackList.getRegisteredCallbackCount() == 0) {
mScoreCaches.remove(networkType);
}
}
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "Upgrade CE from version " + oldVersion + " to version " + newVersion);
if (oldVersion == 9) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "onUpgrade upgrading to v10");
}
db.execSQL("DROP TABLE IF EXISTS " + TABLE_META);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SHARED_ACCOUNTS);
// Recreate the trigger, since the old one references the table to be removed
db.execSQL("DROP TRIGGER IF EXISTS " + TABLE_ACCOUNTS + "Delete");
createAccountsDeletionTrigger(db);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_GRANTS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEBUG);
oldVersion++;
}
if (oldVersion != newVersion) {
Log.e(TAG, "failed to upgrade version " + oldVersion + " to version " + newVersion);
}
}
@Override
public void onAmbientModeChanged(boolean inAmbientMode) {
super.onAmbientModeChanged(inAmbientMode);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onAmbientModeChanged: " + inAmbientMode);
}
adjustPaintColorToCurrentMode(mBackgroundPaint, mInteractiveBackgroundColor,
DigitalWatchFaceUtil.COLOR_VALUE_DEFAULT_AND_AMBIENT_BACKGROUND);
adjustPaintColorToCurrentMode(mHourPaint, mInteractiveHourDigitsColor,
DigitalWatchFaceUtil.COLOR_VALUE_DEFAULT_AND_AMBIENT_HOUR_DIGITS);
adjustPaintColorToCurrentMode(mMinutePaint, mInteractiveMinuteDigitsColor,
DigitalWatchFaceUtil.COLOR_VALUE_DEFAULT_AND_AMBIENT_MINUTE_DIGITS);
// Actually, the seconds are not rendered in the ambient mode, so we could pass just any
// value as ambientColor here.
adjustPaintColorToCurrentMode(mSecondPaint, mInteractiveSecondDigitsColor,
DigitalWatchFaceUtil.COLOR_VALUE_DEFAULT_AND_AMBIENT_SECOND_DIGITS);
if (mLowBitAmbient) {
boolean antiAlias = !inAmbientMode;
mDatePaint.setAntiAlias(antiAlias);
mHourPaint.setAntiAlias(antiAlias);
mMinutePaint.setAntiAlias(antiAlias);
mSecondPaint.setAntiAlias(antiAlias);
mAmPmPaint.setAntiAlias(antiAlias);
mColonPaint.setAntiAlias(antiAlias);
}
invalidate();
// Whether the timer should be running depends on whether we're in ambient mode (as well
// as whether we're visible), so we may need to start or stop the timer.
updateTimer();
}
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "OkHttp failed to obtain result", e);
}
callback.onLoadFailed(e);
}
private void closeActiveSyncContext(ActiveSyncContext activeSyncContext) {
activeSyncContext.close();
mActiveSyncContexts.remove(activeSyncContext);
mSyncStorageEngine.removeActiveSync(activeSyncContext.mSyncInfo,
activeSyncContext.mSyncOperation.target.userId);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Slog.v(TAG, "removing all MESSAGE_MONITOR_SYNC & MESSAGE_SYNC_EXPIRED for "
+ activeSyncContext.toString());
}
mSyncHandler.removeMessages(SyncHandler.MESSAGE_MONITOR_SYNC, activeSyncContext);
mLogger.log("closeActiveSyncContext: ", activeSyncContext);
}
@Override
public boolean onStartJob(JobParameters params) {
mLogger.purgeOldLogs();
boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
synchronized (mLock) {
final int jobId = params.getJobId();
mJobParamsMap.put(jobId, params);
mStartedSyncs.delete(jobId);
mJobStartUptimes.put(jobId, SystemClock.uptimeMillis());
}
Message m = Message.obtain();
m.what = SyncManager.SyncHandler.MESSAGE_START_SYNC;
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(params.getExtras());
mLogger.log("onStartJob() jobid=", params.getJobId(), " op=", op);
if (op == null) {
Slog.e(TAG, "Got invalid job " + params.getJobId());
return false;
}
if (isLoggable) {
Slog.v(TAG, "Got start job message " + op.target);
}
m.obj = op;
sendMessage(m);
return true;
}
private void setResultAndFinish(final String type) {
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "ChooseAccountTypeActivity.setResultAndFinish: "
+ "selected account type " + type);
}
finish();
}
@Override
public void run() {
mCurrentScrollState = mNewState;
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG,
"new scroll state: " + mNewState + " old state: " + mPreviousScrollState);
}
// Fix the position after a scroll or a fling ends
if (mNewState == OnScrollListener.SCROLL_STATE_IDLE
&& mPreviousScrollState != OnScrollListener.SCROLL_STATE_IDLE
&& mPreviousScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
mPreviousScrollState = mNewState;
int i = 0;
View child = getChildAt(i);
while (child != null && child.getBottom() <= 0) {
child = getChildAt(++i);
}
if (child == null) {
// The view is no longer visible, just return
return;
}
int firstPosition = getFirstVisiblePosition();
int lastPosition = getLastVisiblePosition();
boolean scroll = firstPosition != 0 && lastPosition != getCount() - 1;
final int top = child.getTop();
final int bottom = child.getBottom();
final int midpoint = getHeight() / 2;
if (scroll && top < LIST_TOP_OFFSET) {
if (bottom > midpoint) {
smoothScrollBy(top, GOTO_SCROLL_DURATION);
} else {
smoothScrollBy(bottom, GOTO_SCROLL_DURATION);
}
}
} else {
mPreviousScrollState = mNewState;
}
}
/**
* Extracts image pixels into byte array "pixels"
*/
private void getImagePixels() {
int w = image.getWidth();
int h = image.getHeight();
if ((w != width) || (h != height)) {
// create new image with right size/format
Bitmap temp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(temp);
canvas.drawBitmap(temp, 0, 0, null);
image = temp;
}
int[] pixelsInt = new int[w * h];
image.getPixels(pixelsInt, 0, w, 0, 0, w, h);
// The algorithm requires 3 bytes per pixel as RGB.
pixels = new byte[pixelsInt.length * 3];
int pixelsIndex = 0;
hasTransparentPixels = false;
int totalTransparentPixels = 0;
for (final int pixel : pixelsInt) {
if (pixel == Color.TRANSPARENT) {
totalTransparentPixels++;
}
pixels[pixelsIndex++] = (byte) (pixel & 0xFF);
pixels[pixelsIndex++] = (byte) ((pixel >> 8) & 0xFF);
pixels[pixelsIndex++] = (byte) ((pixel >> 16) & 0xFF);
}
double transparentPercentage = 100 * totalTransparentPixels / (double) pixelsInt.length;
// Assume images with greater where more than n% of the pixels are transparent actually have transparency.
// See issue #214.
hasTransparentPixels = transparentPercentage > MIN_TRANSPARENT_PERCENTAGE;
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "got pixels for frame with " + transparentPercentage + "% transparent pixels");
}
}
public static PercentLayoutInfo getPercentLayoutInfo(Context context, AttributeSet attrs) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PercentLayout_Layout);
PercentLayoutInfo info = setPaddingRelatedVal(array, setMinMaxWidthHeightRelatedVal(array, setTextSizeSupportVal(array, setMarginRelatedVal(array, setWidthAndHeightVal(array, null)))));
Log.d(TAG, "constructed: " + info);
array.recycle();
if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "constructed: " + info);
}
return info;
}
public TimingMetric(String eventName, String tag) {
this.eventName = eventName;
this.tag = tag;
this.disabled = !Log.isLoggable(tag, 2);
}
@Override // GoogleApiClient.OnConnectionFailedListener
public void onConnectionFailed(ConnectionResult result) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onConnectionFailed: " + result);
}
}
@Override
protected void handle(Throwable t) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "Request threw uncaught throwable", t);
}
}
/** Log info messages normally but add a consistent TAG */
public static void logi(String message) {
if (Log.isLoggable(TAG, Log.INFO)) {
Log.i(TAG, message);
}
}
private void restart(int updateMode, boolean incrementalResources,
boolean toast) {
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun", "Finished loading changes; update mode ="
+ updateMode);
}
if ((updateMode == 0) || (updateMode == 1)) {
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun", "Applying incremental code without restart");
}
if (toast) {
Activity foreground = Restarter
.getForegroundActivity(this.mApplication);
if (foreground != null) {
Restarter.showToast(foreground,
"Applied code changes without activity restart");
} else if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun",
"Couldn't show toast: no activity found");
}
}
return;
}
List<Activity> activities = Restarter.getActivities(this.mApplication,
false);
if ((incrementalResources) && (updateMode == 2)) {
File file = FileManager.getExternalResourceFile();
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun", "About to update resource file=" + file
+ ", activities=" + activities);
}
if (file != null) {
String resources = file.getPath();
MonkeyPatcher.monkeyPatchApplication(this.mApplication, null,
null, resources);
MonkeyPatcher.monkeyPatchExistingResources(this.mApplication,
resources, activities);
} else {
Log.e("InstantRun", "No resource file found to apply");
updateMode = 3;
}
}
Activity activity = Restarter.getForegroundActivity(this.mApplication);
if (updateMode == 2) {
if (activity != null) {
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun", "Restarting activity only!");
}
boolean handledRestart = false;
try {
Method method = activity.getClass().getMethod(
"onHandleCodeChange", new Class[] { Long.TYPE });
Object result = method.invoke(activity,
new Object[] { Long.valueOf(0L) });
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun", "Activity " + activity
+ " provided manual restart method; return "
+ result);
}
if (Boolean.TRUE.equals(result)) {
handledRestart = true;
if (toast) {
Restarter.showToast(activity, "Applied changes");
}
}
} catch (Throwable ignore) {
}
if (!handledRestart) {
if (toast) {
Restarter.showToast(activity,
"Applied changes, restarted activity");
}
Restarter.restartActivityOnUiThread(activity);
}
return;
}
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun",
"No activity found, falling through to do a full app restart");
}
updateMode = 3;
}
if (updateMode != 3) {
if (Log.isLoggable("InstantRun", 6)) {
Log.e("InstantRun", "Unexpected update mode: " + updateMode);
}
return;
}
if (Log.isLoggable("InstantRun", 2)) {
Log.v("InstantRun",
"Waiting for app to be killed and restarted by the IDE...");
}
}
private void updateRunningAccountsH(EndPoint syncTargets) {
AccountAndUser[] oldAccounts = mRunningAccounts;
mRunningAccounts = AccountManagerService.getSingleton().getRunningAccounts();
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Slog.v(TAG, "Accounts list: ");
for (AccountAndUser acc : mRunningAccounts) {
Slog.v(TAG, acc.toString());
}
}
if (mLogger.enabled()) {
mLogger.log("updateRunningAccountsH: ", Arrays.toString(mRunningAccounts));
}
if (mBootCompleted) {
doDatabaseCleanup();
}
AccountAndUser[] accounts = mRunningAccounts;
for (ActiveSyncContext currentSyncContext : mActiveSyncContexts) {
if (!containsAccountAndUser(accounts,
currentSyncContext.mSyncOperation.target.account,
currentSyncContext.mSyncOperation.target.userId)) {
Log.d(TAG, "canceling sync since the account is no longer running");
sendSyncFinishedOrCanceledMessage(currentSyncContext,
null /* no result since this is a cancel */);
}
}
// On account add, check if there are any settings to be restored.
for (AccountAndUser aau : mRunningAccounts) {
if (!containsAccountAndUser(oldAccounts, aau.account, aau.userId)) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Account " + aau.account + " added, checking sync restore data");
}
AccountSyncSettingsBackupHelper.accountAdded(mContext);
break;
}
}
// Cancel all jobs from non-existent accounts.
AccountAndUser[] allAccounts = AccountManagerService.getSingleton().getAllAccounts();
List<SyncOperation> ops = getAllPendingSyncs();
for (SyncOperation op: ops) {
if (!containsAccountAndUser(allAccounts, op.target.account, op.target.userId)) {
mLogger.log("canceling: ", op);
cancelJob(op, "updateRunningAccountsH()");
}
}
if (syncTargets != null) {
scheduleSync(syncTargets.account, syncTargets.userId,
SyncOperation.REASON_ACCOUNTS_UPDATED, syncTargets.provider,
null, AuthorityInfo.NOT_INITIALIZED,
ContentResolver.SYNC_EXEMPTION_NONE);
}
}
public static void LOGD(final String tag, String message, Throwable cause) {
// noinspection PointlessBooleanExpression,ConstantConditions
if (BuildConfig.DEBUG || Log.isLoggable(tag, Log.DEBUG)) {
Log.d(tag, message, cause);
}
}
private static int parseExifSegment(RandomAccessReader segmentData) {
final int headerOffsetSize = JPEG_EXIF_SEGMENT_PREAMBLE.length();
short byteOrderIdentifier = segmentData.getInt16(headerOffsetSize);
final ByteOrder byteOrder;
if (byteOrderIdentifier == MOTOROLA_TIFF_MAGIC_NUMBER) {
byteOrder = ByteOrder.BIG_ENDIAN;
} else if (byteOrderIdentifier == INTEL_TIFF_MAGIC_NUMBER) {
byteOrder = ByteOrder.LITTLE_ENDIAN;
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
}
byteOrder = ByteOrder.BIG_ENDIAN;
}
segmentData.order(byteOrder);
int firstIfdOffset = segmentData.getInt32(headerOffsetSize + 4) + headerOffsetSize;
int tagCount = segmentData.getInt16(firstIfdOffset);
int tagOffset, tagType, formatCode, componentCount;
for (int i = 0; i < tagCount; i++) {
tagOffset = calcTagOffset(firstIfdOffset, i);
tagType = segmentData.getInt16(tagOffset);
// We only want orientation.
if (tagType != ORIENTATION_TAG_TYPE) {
continue;
}
formatCode = segmentData.getInt16(tagOffset + 2);
// 12 is max format code.
if (formatCode < 1 || formatCode > 12) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Got invalid format code = " + formatCode);
}
continue;
}
componentCount = segmentData.getInt32(tagOffset + 4);
if (componentCount < 0) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Negative tiff component count");
}
continue;
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Got tagIndex=" + i + " tagType=" + tagType + " formatCode=" + formatCode
+ " componentCount=" + componentCount);
}
final int byteCount = componentCount + BYTES_PER_FORMAT[formatCode];
if (byteCount > 4) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Got byte count > 4, not orientation, continuing, formatCode=" + formatCode);
}
continue;
}
final int tagValueOffset = tagOffset + 8;
if (tagValueOffset < 0 || tagValueOffset > segmentData.length()) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Illegal tagValueOffset=" + tagValueOffset + " tagType=" + tagType);
}
continue;
}
if (byteCount < 0 || tagValueOffset + byteCount > segmentData.length()) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Illegal number of bytes for TI tag data tagType=" + tagType);
}
continue;
}
//assume componentCount == 1 && fmtCode == 3
return segmentData.getInt16(tagValueOffset);
}
return -1;
}
public boolean isLoggable(final int logLevel) {
return logLevel >= minLogLevel || Log.isLoggable(tag, logLevel);
}
/**
* Customize the log tag for your application, so that other apps
* using Volley don't mix their logs with yours.
*
* Enable the log property for your tag before starting your app:
*
* {@code adb shell setprop log.tag.<tag>}
*/
public static void setTag(String tag) {
d("Changing log tag to %s", tag);
TAG = tag;
// Reinitialize the DEBUG "constant"
DEBUG = Log.isLoggable(TAG, Log.VERBOSE);
}