Example usage for java.lang Integer MAX_VALUE

List of usage examples for java.lang Integer MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MAX_VALUE.

Prototype

int MAX_VALUE

To view the source code for java.lang Integer MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value an int can have, 231-1.

Usage

From source file:Main.java

public static boolean isServiceExisted(Context context, String className) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    if (!(serviceList.size() > 0)) {
        return false;
    }//from   www .  j av a  2s.c  o m

    for (int i = 0; i < serviceList.size(); i++) {
        RunningServiceInfo serviceInfo = serviceList.get(i);
        ComponentName serviceName = serviceInfo.service;
        Log.d("services", serviceName.getClassName());
        if (serviceName.getClassName().equals(className)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

private static int getImageViewFieldValue(Object object, String fieldName) {
    int value = 0;
    if (object instanceof ImageView) {
        try {//from   w  w w .  j  a  v  a  2  s . c  o m
            Field field = ImageView.class.getDeclaredField(fieldName);
            field.setAccessible(true);
            int fieldValue = (Integer) field.get(object);
            if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
                value = fieldValue;
            }
        } catch (Throwable e) {
        }
    }
    return value;
}

From source file:Main.java

/**
 * Return true if the string starting at offset in sb matches with xmlTag.
 * @param sb StringBuffer//ww  w. j a  v a2s. co m
 * @param offset int
 * @param xmlTag String The XML tag name to check without '&lt;' and '&gt;'
 * @return
 */
private static boolean matchXMLTag(StringBuffer sb, int offset, String xmlTag) {
    if (offset >= sb.length()) {
        return false;
    }
    if (sb.charAt(offset) != '<') {
        return false;
    }
    int indexOfSpace = sb.indexOf(" ", offset);
    int indexOfGt = sb.indexOf(">", offset);
    int indexOfEndTag = Integer.MAX_VALUE;
    if (indexOfSpace >= 0) {
        indexOfEndTag = indexOfSpace;
    }
    if (indexOfGt >= 0 && indexOfGt < indexOfEndTag) {
        indexOfEndTag = indexOfGt;
    }
    if (indexOfEndTag == Integer.MAX_VALUE) {
        return false;
    }
    String potentialTag = sb.substring(offset + 1, indexOfEndTag);
    return potentialTag.equals(xmlTag);
}

From source file:Main.java

private static Point findBestPreviewSizeValue(CharSequence previewSizeString, Point screenResolution) {
    int bestX = 0;
    int bestY = 0;
    int diff = Integer.MAX_VALUE;
    for (String previewSize : COMMA_PATTERN.split(previewSizeString)) {

        previewSize = previewSize.trim();
        int dimPosition = previewSize.indexOf('x');
        if (dimPosition < 0) {
            continue;
        }//from w w  w . ja  va2s.  co m

        int newX;
        int newY;
        try {
            newX = Integer.parseInt(previewSize.substring(0, dimPosition));
            newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
        } catch (NumberFormatException nfe) {
            continue;
        }

        int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
        if (newDiff == 0) {
            bestX = newX;
            bestY = newY;
            break;
        } else if (newDiff < diff) {
            bestX = newX;
            bestY = newY;
            diff = newDiff;
        }

    }
    if (bestX > 0 && bestY > 0) {
        return new Point(bestX, bestY);
    }
    return null;
}

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<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;/* w  w  w. j  a  v a 2  s.c o  m*/
        }
    }
    return isRunning;
}

From source file:Main.java

public static boolean isServiceRunning(Context ctx, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;//  www.j  a va  2 s  .  c  o m
        }
    }
    return isRunning;
}

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<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;//from  w  w  w  .  j a v a2s.co  m
        }
    }
    return isRunning;
}

From source file:Main.java

/**
 * Checks if the specified service is currently running or not.
 * @param context/*  w w w  .  j a  va  2  s .  com*/
 * @param service
 * @return
 */
public static final boolean isServiceRunning(Context context, Class<? extends Service> service) {
    return isServiceRunning(context, service, Integer.MAX_VALUE);
}

From source file:Main.java

public static boolean isServiceRunning(Context ctx, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        String serName = si.service.getClassName();
        Log.d("isServiceRunning", serName);
        if (className.equals(serName)) {
            isRunning = true;//from   w w w  .  j a  v a2 s . c  om
        }
    }
    return isRunning;
}

From source file:Main.java

/**
 * Aligns the first <code>rows</code> <code>cols</code> components of <code>parent</code> in a grid. Each component in
 * a column is as wide as the maximum preferred width of the components in that column; height is similarly determined
 * for each row. The parent is made just big enough to fit them all.
 * //from  www.j  av  a 2 s .co m
 * @param rows
 *          number of rows
 * @param cols
 *          number of columns
 * @param initialX
 *          x location to start the grid at
 * @param initialY
 *          y location to start the grid at
 * @param xPad
 *          x padding between cells
 * @param yPad
 *          y padding between cells
 */
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad,
        int yPad) {

    parent.setMaximumSize(new Dimension(Integer.MAX_VALUE, parent.getPreferredSize().height));
    SpringLayout layout;
    try {
        layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
        System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
        return;
    }

    // Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }

    // Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < cols; c++) {
            height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
        }
        for (int c = 0; c < cols; c++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }

    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);

}