Java Code Examples for android.util.Log.isLoggable()

The following are Jave code examples for showing how to use isLoggable() of the android.util.Log class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Brevent   File: BreventActivity.java   Source Code and License Vote up 6 votes
public void showProgress(int message) {
    if (Log.isLoggable(UILog.TAG, Log.DEBUG)) {
        UILog.d("show " + FRAGMENT_PROGRESS + ", " + message + ": " + message
                + ", stopped: " + isStopped());
    }
    if (isStopped()) {
        return;
    }
    hideDisabled();
    hideAppProgress();
    ProgressFragment fragment = (ProgressFragment) getFragmentManager()
            .findFragmentByTag(FRAGMENT_PROGRESS);
    if (fragment == null || fragment.getMessage() != message) {
        if (fragment != null) {
            fragment.dismiss();
        }
        fragment = new ProgressFragment();
        fragment.setMessage(message);
        fragment.show(getFragmentManager(), FRAGMENT_PROGRESS);
    }
}
 
Example 2
Project: GitHub   File: DiskLruCacheWrapper.java   Source Code and License Vote up 6 votes
@Override
public File get(Key key) {
  String safeKey = safeKeyGenerator.getSafeKey(key);
  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    Log.v(TAG, "Get: Obtained: " + safeKey + " for for Key: " + key);
  }
  File result = null;
  try {
    // It is possible that the there will be a put in between these two gets. If so that shouldn't
    // be a problem because we will always put the same value at the same key so our input streams
    // will still represent the same data.
    final DiskLruCache.Value value = getDiskCache().get(safeKey);
    if (value != null) {
      result = value.getFile(0);
    }
  } catch (IOException e) {
    if (Log.isLoggable(TAG, Log.WARN)) {
      Log.w(TAG, "Unable to get from disk cache", e);
    }
  }
  return result;
}
 
Example 3
Project: GitHub   File: HttpUrlFetcher.java   Source Code and License Vote up 6 votes
@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
  long startTime = LogTime.getLogTime();
  final InputStream result;
  try {
    result = loadDataWithRedirects(glideUrl.toURL(), 0 /*redirects*/, null /*lastUrl*/,
        glideUrl.getHeaders());
  } catch (IOException e) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Failed to load data for url", e);
    }
    callback.onLoadFailed(e);
    return;
  }

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    Log.v(TAG, "Finished http url fetcher fetch in " + LogTime.getElapsedMillis(startTime)
        + " ms and loaded " + result);
  }
  callback.onDataReady(result);
}
 
Example 4
Project: GitHub   File: Glide.java   Source Code and License Vote up 6 votes
/**
 * Returns a directory with the given name in the private cache directory of the application to
 * use to store retrieved media and thumbnails.
 *
 * @param context   A context.
 * @param cacheName The name of the subdirectory in which to store the cache.
 * @see #getPhotoCacheDir(android.content.Context)
 */
@Nullable
public static File getPhotoCacheDir(Context context, String cacheName) {
  File cacheDir = context.getCacheDir();
  if (cacheDir != null) {
    File result = new File(cacheDir, cacheName);
    if (!result.mkdirs() && (!result.exists() || !result.isDirectory())) {
      // File wasn't able to create a directory, or the result exists but not a directory
      return null;
    }
    return result;
  }
  if (Log.isLoggable(TAG, Log.ERROR)) {
    Log.e(TAG, "default disk cache dir is null");
  }
  return null;
}
 
Example 5
Project: GitHub   File: StreamGifDecoder.java   Source Code and License Vote up 6 votes
private static byte[] inputStreamToBytes(InputStream is) {
  final int bufferSize = 16384;
  ByteArrayOutputStream buffer = new ByteArrayOutputStream(bufferSize);
  try {
    int nRead;
    byte[] data = new byte[bufferSize];
    while ((nRead = is.read(data)) != -1) {
      buffer.write(data, 0, nRead);
    }
    buffer.flush();
  } catch (IOException e) {
    if (Log.isLoggable(TAG, Log.WARN)) {
      Log.w(TAG, "Error reading data from stream", e);
    }
    return null;
  }
  return buffer.toByteArray();
}
 
Example 6
Project: chromium-net-for-android   File: CronetUrlRequestContext.java   Source Code and License Vote up 5 votes
/**
 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and
 *         {@link #LOG_VERBOSE}.
 */
private int getLoggingLevel() {
    int loggingLevel;
    if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
        loggingLevel = LOG_VERBOSE;
    } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
        loggingLevel = LOG_DEBUG;
    } else {
        loggingLevel = LOG_NONE;
    }
    return loggingLevel;
}
 
Example 7
Project: GitHub   File: VolleyStreamFetcher.java   Source Code and License Vote up 5 votes
@Override
protected VolleyError parseNetworkError(VolleyError volleyError) {
  if (Log.isLoggable(TAG, Log.DEBUG)) {
    Log.d(TAG, "Volley failed to retrieve response", volleyError);
  }
  callback.onLoadFailed(volleyError);
  return super.parseNetworkError(volleyError);
}
 
Example 8
Project: GitHub   File: LruArrayPool.java   Source Code and License Vote up 5 votes
@Override
public <T> T get(int size, Class<T> arrayClass) {
  ArrayAdapterInterface<T> arrayAdapter = getAdapterFromType(arrayClass);
  T result;
  synchronized (this) {
    Integer possibleSize = getSizesForAdapter(arrayClass).ceilingKey(size);
    final Key key;
    if (mayFillRequest(size, possibleSize)) {
      key = keyPool.get(possibleSize, arrayClass);
    } else {
      key = keyPool.get(size, arrayClass);
    }

    result = getArrayForKey(key);
    if (result != null) {
      currentSize -= arrayAdapter.getArrayLength(result) * arrayAdapter.getElementSizeInBytes();
      decrementArrayOfSize(arrayAdapter.getArrayLength(result), arrayClass);
    }
  }

  if (result == null) {
    if (Log.isLoggable(arrayAdapter.getTag(), Log.VERBOSE)) {
      Log.v(arrayAdapter.getTag(), "Allocated " + size + " bytes");
    }
    result = arrayAdapter.newArray(size);
  }
  return result;
}
 
Example 9
Project: GitHub   File: DecodePath.java   Source Code and License Vote up 5 votes
private Resource<ResourceType> decodeResourceWithList(DataRewinder<DataType> rewinder, int width,
    int height, Options options, List<Throwable> exceptions) throws GlideException {
  Resource<ResourceType> result = null;
  for (int i = 0, size = decoders.size(); i < size; i++) {
    ResourceDecoder<DataType, ResourceType> decoder = decoders.get(i);
    try {
      DataType data = rewinder.rewindAndGet();
      if (decoder.handles(data, options)) {
        data = rewinder.rewindAndGet();
        result = decoder.decode(data, width, height, options);
      }
      // Some decoders throw unexpectedly. If they do, we shouldn't fail the entire load path, but
      // instead log and continue. See #2406 for an example.
    } catch (IOException | RuntimeException | OutOfMemoryError e) {
      if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Failed to decode data for " + decoder, e);
      }
      exceptions.add(e);
    }

    if (result != null) {
      break;
    }
  }

  if (result == null) {
    throw new GlideException(failureMessage, new ArrayList<>(exceptions));
  }
  return result;
}
 
Example 10
Project: GitHub   File: ThumbFetcher.java   Source Code and License Vote up 5 votes
@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
  try {
    inputStream = openThumbInputStream();
  } catch (FileNotFoundException e) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Failed to find thumbnail file", e);
    }
    callback.onLoadFailed(e);
    return;
  }

  callback.onDataReady(inputStream);
}
 
Example 11
Project: GitHub   File: TransformationUtils.java   Source Code and License Vote up 5 votes
/**
 * If the Bitmap is smaller or equal to the Target it returns the original size, if not then
 * {@link #fitCenter(BitmapPool, Bitmap, int, int)} is called instead.
 *
 * @param pool   The BitmapPool obtain a bitmap from.
 * @param inBitmap  The Bitmap to center.
 * @param width  The width in pixels of the target.
 * @param height The height in pixels of the target.
 * @return returns input Bitmap if smaller or equal to target, or toFit if the Bitmap's width or
 * height is larger than the given dimensions
 */
public static Bitmap centerInside(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int width,
                               int height) {
  if (inBitmap.getWidth() <= width && inBitmap.getHeight() <= height) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
      Log.v(TAG, "requested target size larger or equal to input, returning input");
    }
    return inBitmap;
  } else {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
      Log.v(TAG, "requested target size too big for input, fit centering instead");
    }
    return fitCenter(pool, inBitmap, width, height);
  }
}
 
Example 12
Project: prebid-mobile-android   File: LogUtil.java   Source Code and License Vote up 5 votes
public static void v(final String tag, String message, Throwable cause) {
    if (BuildConfig.DEBUG) {
        if (TextUtils.isEmpty(tag)) {
            if (Log.isLoggable(BASE_TAG, Log.VERBOSE)) {
                Log.v(BASE_TAG, message, cause);
            }
        } else {
            if (Log.isLoggable(tag, Log.VERBOSE)) {
                Log.v(tag, message, cause);
            }
        }
    }
}
 
Example 13
Project: GitHub   File: Downsampler.java   Source Code and License Vote up 4 votes
static void calculateScaling(DownsampleStrategy downsampleStrategy, int degreesToRotate,
    int sourceWidth, int sourceHeight, int targetWidth, int targetHeight,
    BitmapFactory.Options options) {
  // We can't downsample source content if we can't determine its dimensions.
  if (sourceWidth <= 0 || sourceHeight <= 0) {
    return;
  }

  final float exactScaleFactor;
  if (degreesToRotate == 90 || degreesToRotate == 270) {
    // If we're rotating the image +-90 degrees, we need to downsample accordingly so the image
    // width is decreased to near our target's height and the image height is decreased to near
    // our target width.
    //noinspection SuspiciousNameCombination
    exactScaleFactor = downsampleStrategy.getScaleFactor(sourceHeight, sourceWidth,
        targetWidth, targetHeight);
  } else {
    exactScaleFactor =
        downsampleStrategy.getScaleFactor(sourceWidth, sourceHeight, targetWidth, targetHeight);
  }

  if (exactScaleFactor <= 0f) {
    throw new IllegalArgumentException("Cannot scale with factor: " + exactScaleFactor
        + " from: " + downsampleStrategy);
  }
  SampleSizeRounding rounding = downsampleStrategy.getSampleSizeRounding(sourceWidth,
      sourceHeight, targetWidth, targetHeight);
  if (rounding == null) {
    throw new IllegalArgumentException("Cannot round with null rounding");
  }

  int outWidth = (int) (exactScaleFactor * sourceWidth + 0.5f);
  int outHeight = (int) (exactScaleFactor * sourceHeight + 0.5f);

  int widthScaleFactor = sourceWidth / outWidth;
  int heightScaleFactor = sourceHeight / outHeight;

  int scaleFactor = rounding == SampleSizeRounding.MEMORY
      ? Math.max(widthScaleFactor, heightScaleFactor)
      : Math.min(widthScaleFactor, heightScaleFactor);

  int powerOfTwoSampleSize;
  // BitmapFactory does not support downsampling wbmp files on platforms <= M. See b/27305903.
  if (Build.VERSION.SDK_INT <= 23
      && NO_DOWNSAMPLE_PRE_N_MIME_TYPES.contains(options.outMimeType)) {
    powerOfTwoSampleSize = 1;
  } else {
    powerOfTwoSampleSize = Math.max(1, Integer.highestOneBit(scaleFactor));
    if (rounding == SampleSizeRounding.MEMORY
        && powerOfTwoSampleSize < (1.f / exactScaleFactor)) {
      powerOfTwoSampleSize = powerOfTwoSampleSize << 1;
    }
  }

  float adjustedScaleFactor = powerOfTwoSampleSize * exactScaleFactor;

  options.inSampleSize = powerOfTwoSampleSize;
  // Density scaling is only supported if inBitmap is null prior to KitKat. Avoid setting
  // densities here so we calculate the final Bitmap size correctly.
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    options.inTargetDensity = (int) (1000 * adjustedScaleFactor + 0.5f);
    options.inDensity = 1000;
  }
  if (isScaling(options)) {
    options.inScaled = true;
  } else {
    options.inDensity = options.inTargetDensity = 0;
  }

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    Log.v(TAG, "Calculate scaling"
        + ", source: [" + sourceWidth + "x" + sourceHeight + "]"
        + ", target: [" + targetWidth + "x" + targetHeight + "]"
        + ", exact scale factor: " + exactScaleFactor
        + ", power of 2 sample size: " + powerOfTwoSampleSize
        + ", adjusted scale factor: " + adjustedScaleFactor
        + ", target density: " + options.inTargetDensity
        + ", density: " + options.inDensity);
  }
}
 
Example 14
Project: GitHub   File: Downsampler.java   Source Code and License Vote up 4 votes
private Bitmap decodeFromWrappedStreams(InputStream is,
    BitmapFactory.Options options, DownsampleStrategy downsampleStrategy,
    DecodeFormat decodeFormat, int requestedWidth, int requestedHeight,
    boolean fixBitmapToRequestedDimensions, DecodeCallbacks callbacks) throws IOException {

  int[] sourceDimensions = getDimensions(is, options, callbacks);
  int sourceWidth = sourceDimensions[0];
  int sourceHeight = sourceDimensions[1];
  String sourceMimeType = options.outMimeType;

  int orientation = ImageHeaderParserUtils.getOrientation(parsers, is, byteArrayPool);
  int degreesToRotate = TransformationUtils.getExifOrientationDegrees(orientation);

  options.inPreferredConfig = getConfig(is, decodeFormat);
  if (options.inPreferredConfig != Bitmap.Config.ARGB_8888) {
    options.inDither = true;
  }

  int targetWidth = requestedWidth == Target.SIZE_ORIGINAL ? sourceWidth : requestedWidth;
  int targetHeight = requestedHeight == Target.SIZE_ORIGINAL ? sourceHeight : requestedHeight;

  calculateScaling(downsampleStrategy, degreesToRotate, sourceWidth, sourceHeight, targetWidth,
      targetHeight, options);

  boolean isKitKatOrGreater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
  // Prior to KitKat, the inBitmap size must exactly match the size of the bitmap we're decoding.
  if ((options.inSampleSize == 1 || isKitKatOrGreater)
      && shouldUsePool(is)) {
    int expectedWidth;
    int expectedHeight;
    if (fixBitmapToRequestedDimensions && isKitKatOrGreater) {
      expectedWidth = targetWidth;
      expectedHeight = targetHeight;
    } else {
      float densityMultiplier = isScaling(options)
          ? (float) options.inTargetDensity / options.inDensity : 1f;
      int sampleSize = options.inSampleSize;
      int downsampledWidth = (int) Math.ceil(sourceWidth / (float) sampleSize);
      int downsampledHeight = (int) Math.ceil(sourceHeight / (float) sampleSize);
      expectedWidth = Math.round(downsampledWidth * densityMultiplier);
      expectedHeight = Math.round(downsampledHeight * densityMultiplier);

      if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Calculated target [" + expectedWidth + "x" + expectedHeight + "] for source"
            + " [" + sourceWidth + "x" + sourceHeight + "]"
            + ", sampleSize: " + sampleSize
            + ", targetDensity: " + options.inTargetDensity
            + ", density: " + options.inDensity
            + ", density multiplier: " + densityMultiplier);
      }
    }
    // If this isn't an image, or BitmapFactory was unable to parse the size, width and height
    // will be -1 here.
    if (expectedWidth > 0 && expectedHeight > 0) {
      setInBitmap(options, bitmapPool, expectedWidth, expectedHeight);
    }
  }
  Bitmap downsampled = decodeStream(is, options, callbacks);
  callbacks.onDecodeComplete(bitmapPool, downsampled);

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    logDecode(sourceWidth, sourceHeight, sourceMimeType, options, downsampled,
        requestedWidth, requestedHeight);
  }

  Bitmap rotated = null;
  if (downsampled != null) {
    // If we scaled, the Bitmap density will be our inTargetDensity. Here we correct it back to
    // the expected density dpi.
    downsampled.setDensity(displayMetrics.densityDpi);

    rotated = TransformationUtils.rotateImageExif(bitmapPool, downsampled, orientation);
    if (!downsampled.equals(rotated)) {
      bitmapPool.put(downsampled);
    }
  }

  return rotated;
}
 
Example 15
Project: boohee_v5.6   File: NotificationManagerCompat.java   Source Code and License Vote up 4 votes
public void onServiceDisconnected(ComponentName componentName) {
    if (Log.isLoggable(NotificationManagerCompat.TAG, 3)) {
        Log.d(NotificationManagerCompat.TAG, "Disconnected from service " + componentName);
    }
    this.mHandler.obtainMessage(2, componentName).sendToTarget();
}
 
Example 16
Project: Pocket-Plays-for-Twitch   File: LogUtils.java   Source Code and License Vote up 4 votes
public static void LOGV(final String tag, String message) {
    if (sDebug && Log.isLoggable(tag, Log.VERBOSE)) {
        Log.v(tag, getVersionPrefix() + message);
    }
}
 
Example 17
Project: TakeoutService   File: AndroidLog.java   Source Code and License Vote up 4 votes
public void debug(String msg, Throwable th) {
    if (Log.isLoggable(__JETTY_TAG, Log.DEBUG)) {
        Log.d(__JETTY_TAG, msg, th);
    }
}
 
Example 18
Project: simple-share-android   File: InputStreamBuffer.java   Source Code and License Vote up 4 votes
/**
 * Attempts to advance the head of the buffer to the requested index. If the index is less
 * than the head of the buffer, the internal state will not be changed.
 *
 * <p/>
 * Advancing does not fill the internal buffer. The next {@link #get(int)} or
 * {@link #has(int)} call will fill the buffer.
 */
public void advanceTo(final int index) throws IllegalStateException, IndexOutOfBoundsException {
    final int i = index - mOffset;
    if (i <= 0) {
        // noop
        return;
    } else if (i < mFilled) {
        // Shift elements starting at i to position 0.
        shiftToBeginning(i);
        mOffset = index;
        mFilled = mFilled - i;
    } else if (mInputStream != null) {
        // Burn some bytes from the input stream to match the new index.
        int burn = i - mFilled;
        boolean empty = false;
        int fails = 0;
        try {
            while (burn > 0) {
                final long burned = mInputStream.skip(burn);
                if (burned <= 0) {
                    fails++;
                } else {
                    burn -= burned;
                }

                if (fails >= 5) {
                    empty = true;
                    break;
                }
            }
        } catch (IOException ignored) {
            empty = true;
        }

        if (empty) {
            //Mark input stream as consumed.
            mInputStream = null;
        }

        mOffset = index - burn;
        mFilled = 0;
    } else {
        // Advancing beyond the input stream.
        mOffset = index;
        mFilled = 0;
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, String.format("advanceTo %d buffer: %s", i, this));
    }
}
 
Example 19
Project: TakeoutService   File: AndroidLog.java   Source Code and License Vote up 4 votes
public void warn(String msg, Object... args) {
    if (Log.isLoggable(__JETTY_TAG, Log.WARN))
        Log.w(__JETTY_TAG, msg);
}
 
Example 20
Project: VirtualHook   File: VAccountManagerService.java   Source Code and License Vote up 3 votes
public void sendResult() {
	IAccountManagerResponse response = getResponseAndClose();
	if (response != null) {
		try {
			Account[] accounts = new Account[mAccountsWithFeatures.size()];
			for (int i = 0; i < accounts.length; i++) {
				accounts[i] = mAccountsWithFeatures.get(i);
			}
			if (Log.isLoggable(TAG, Log.VERBOSE)) {
				Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response "
						+ response);
			}
			Bundle result = new Bundle();
			result.putParcelableArray(AccountManager.KEY_ACCOUNTS, accounts);
			response.onResult(result);
		} catch (RemoteException e) {
			// if the caller is dead then there is no one to care about remote exceptions
			Log.v(TAG, "failure while notifying response", e);
		}
	}
}