Home | History | Annotate | Download | only in android
      1 package org.robolectric.res.android;
      2 
      3 import java.nio.ByteOrder;
      4 
      5 public class Util {
      6 
      7   static final int SIZEOF_SHORT = 2;
      8   public static final int SIZEOF_INT = 4;
      9   private static boolean littleEndian = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
     10 
     11   private static final boolean DEBUG = false;
     12 
     13   static short dtohs(short v) {
     14     return littleEndian
     15         ? v
     16         : (short) ((v << 8) | (v >> 8));
     17   }
     18 
     19   static int dtohl(int v) {
     20     return littleEndian
     21         ? v
     22         : (v << 24) | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00) | (v >> 24);
     23   }
     24 
     25   static short htods(short v) {
     26     return littleEndian
     27         ? v
     28         : (short) ((v << 8) | (v >> 8));
     29   }
     30 
     31   static int htodl(int v) {
     32     return littleEndian
     33         ? v
     34         : (v << 24) | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00) | (v >> 24);
     35   }
     36 
     37   public static boolean isTruthy(int i) {
     38     return i != 0;
     39   }
     40 
     41   public static boolean isTruthy(Object o) {
     42     return o != null;
     43   }
     44 
     45   static void ALOGD(String message, Object... args) {
     46     if (DEBUG) {
     47       System.out.println("DEBUG: " + String.format(message, args));
     48     }
     49   }
     50 
     51   static void ALOGW(String message, Object... args) {
     52     System.out.println("WARN: " + String.format(message, args));
     53   }
     54 
     55   public static void ALOGV(String message, Object... args) {
     56     if (DEBUG) {
     57       System.out.println("VERBOSE: " + String.format(message, args));
     58     }
     59   }
     60 
     61   public static void ALOGI(String message, Object... args) {
     62     if (DEBUG) {
     63       System.out.println("INFO: " + String.format(message, args));
     64     }
     65   }
     66 
     67   static void ALOGE(String message, Object... args) {
     68     System.out.println("ERROR: " + String.format(message, args));
     69   }
     70 
     71   static void LOG_FATAL_IF(boolean assertion, String message, Object... args) {
     72     assert !assertion : String.format(message, args);
     73   }
     74 
     75   static void ATRACE_CALL() {
     76   }
     77 }
     78