List of usage examples for java.lang Integer MAX_VALUE
int MAX_VALUE
To view the source code for java.lang Integer MAX_VALUE.
Click Source Link
From source file:Main.java
public static int[] findBoundsOfVisibleBitmap(Bitmap bitmap) { // Sanity check if (bitmap == null) return null; // Init data// w ww. j a v a 2 s. co m int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); // Color int backgroundColor = Color.TRANSPARENT; // Bounds int xMin = Integer.MAX_VALUE; int xMax = Integer.MIN_VALUE; int yMin = Integer.MAX_VALUE; int yMax = Integer.MIN_VALUE; // Get pixel array int[][] bitmapArray = new int[bitmapHeight][bitmapWidth]; for (int y = 0; y < bitmapHeight; y++) { bitmap.getPixels(bitmapArray[y], 0, bitmapWidth, 0, y, bitmapWidth, 1); } // Find bitmap bound boolean foundPixel = false; // Find xMin for (int x = 0; x < bitmapWidth; x += SCAN_INTERVAL) { boolean stop = false; for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) { if (bitmapArray[y][x] != backgroundColor) { xMin = x; stop = true; foundPixel = true; break; } } if (stop) break; } // Image is empty... if (!foundPixel) return null; // Find yMin for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) { boolean stop = false; for (int x = xMin; x < bitmapWidth; x += SCAN_INTERVAL) { if (bitmapArray[y][x] != backgroundColor) { yMin = y; stop = true; break; } } if (stop) break; } // Find xMax for (int x = bitmapWidth - 1; x >= xMin; x -= SCAN_INTERVAL) { boolean stop = false; for (int y = yMin; y < bitmapHeight; y += SCAN_INTERVAL) { if (bitmapArray[y][x] != backgroundColor) { xMax = x; stop = true; break; } } if (stop) break; } // Find yMax for (int y = bitmapHeight - 1; y >= yMin; y -= SCAN_INTERVAL) { boolean stop = false; for (int x = xMin; x <= xMax; x += SCAN_INTERVAL) { if (bitmapArray[y][x] != backgroundColor) { yMax = y; stop = true; break; } } if (stop) break; } // Expand bitmap with offset int offset = SCAN_INTERVAL; int left = Math.max(xMin - offset, 0); int top = Math.max(yMin - offset, 0); int right = Math.min(xMax + offset, bitmapWidth); int bottom = Math.min(yMax + offset, bitmapHeight); int[] bound = { left, top, right, bottom }; return bound; }
From source file:Main.java
public static boolean isServiceRunning(Context context, String className) { if (context == null) return false; if (TextUtils.isEmpty(className)) return false; boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> servicesList = activityManager .getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo si : servicesList) { if (className.equals(si.service.getClassName())) { isRunning = true;//from ww w . j a v a 2 s . c o m } } return isRunning; }
From source file:Main.java
/** * To check if the specified service is running. * This util needs `android.permission.GET_TASKS` permission. * * @param context the context/*from w ww .j a va 2s . c o m*/ * @param className class name of service * @return true if the service is running */ public static boolean isServiceRunning(Context context, String className) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo info : manager.getRunningServices(Integer.MAX_VALUE)) { if (info.service.getClassName().equals(className)) { return true; } } return false; }
From source file:Main.java
public static int toInt(long l) { if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) throw new ArithmeticException("Value (" + l + ") cannot fit into int"); return (int) l; }
From source file:Main.java
public static Camera.Size getOptimalCameraPreviewSize(Camera camera, int width, int height) { if (camera == null) { return null; }/*from ww w . ja va 2 s . com*/ double targetRatio = (double) height / width; Camera.Parameters params = camera.getParameters(); List<Camera.Size> sizes = params.getSupportedPreviewSizes(); Camera.Size optimalSize = null; // selecting optimal camera preview size int minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { double ratio = (double) size.height / size.width; if (Math.abs(ratio - targetRatio) > RATIO_TOLERANCE) continue; if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } if (optimalSize == null) { minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } } return optimalSize; }
From source file:Main.java
public static Camera.Size findClosetPreviewSize(Camera camera, Point preferSize) { int preferX = preferSize.x; int preferY = preferSize.y; Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> allSupportSizes = parameters.getSupportedPreviewSizes(); Log.d(TAG, "all support preview size: " + dumpPreviewSizeList(allSupportSizes)); int minDiff = Integer.MAX_VALUE; int index = 0; for (int i = 0; i < allSupportSizes.size(); i++) { Camera.Size size = allSupportSizes.get(i); int x = size.width; int y = size.height; int diff = Math.abs(x - preferX) + Math.abs(y - preferY); if (diff < minDiff) { minDiff = diff;//from w w w.j a v a 2 s .c om index = i; } } Camera.Size size = allSupportSizes.get(index); return size; }
From source file:Main.java
static int computeListCapacity(int arraySize) { return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE); }
From source file:Main.java
public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager .getRunningServices(Integer.MAX_VALUE); if (serviceList.size() <= 0) { return false; }//from w w w . j av a 2s. c om for (int i = 0; i < serviceList.size(); i++) { if (serviceList.get(i).service.getClassName().equals(className) == true) { isRunning = true; break; } } return isRunning; }
From source file:Main.java
public static boolean setOptimalCameraPreviewSize(Camera camera, int width, int height) { if (camera == null) { return false; }/*from w w w .j a v a 2 s . co m*/ double targetRatio = (double) height / width; Camera.Parameters params = camera.getParameters(); List<Camera.Size> sizes = params.getSupportedPreviewSizes(); Camera.Size optimalSize = null; // selecting optimal camera preview size int minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { double ratio = (double) size.height / size.width; if (Math.abs(ratio - targetRatio) > RATIO_TOLERANCE) continue; if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } if (optimalSize == null) { minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } } params.setPreviewSize(optimalSize.width, optimalSize.height); List<String> focusModes = params.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } // for Mi3, only support ImageFormat.NV21 // for most cameras, ImageFormat.NV21 are support worldwide // so use default preview format // params.setPreviewFormat(ImageFormat.JPEG); camera.setParameters(params); return true; }
From source file:Main.java
public static BufferedImage int2image(int[][] scene) { int maxValue = -1; int minValue = Integer.MAX_VALUE; for (int y = 0; y < scene.length; y++) { for (int x = 0; x < scene[y].length; x++) { maxValue = Math.max(maxValue, scene[y][x]); minValue = Math.min(minValue, scene[y][x]); }//from w w w . j av a2s. c o m } if (maxValue == minValue) maxValue = minValue + 1; final double scale = 255.0 / (maxValue - minValue); BufferedImage image = new BufferedImage(scene[0].length, scene.length, BufferedImage.TYPE_INT_RGB); for (int y = 0; y < scene.length; y++) { for (int x = 0; x < scene[y].length; x++) { final int c = (int) (scale * (scene[y][x] - minValue)); image.setRGB(x, y, c << 16 | c << 8 | c); } } return image; }