<pre class="html" name="code">public class ByteUtil {
public static byte[] intToByteArray(int num, int size) {
byte[] temp = new byte[size];
for (int i = 0; i < size; i++) {
temp[i] = (byte) ((num >> 8 * i) & 0xFF);
}
return temp;
}
public static byte[] intToByte(int i) {
byte[] abyte0 = new byte[4];
abyte0[0] = (byte) (0xff & i);
abyte0[1] = (byte) ((0xff00 & i) >> 8);
abyte0[2] = (byte) ((0xff0000 & i) >> 16);
abyte0[3] = (byte) ((0xff000000 & i) >> 24);
return abyte0;
}
public static int bytesToInt(byte[] bytes) {
int addr = 0;
try {
addr = bytes[0] & 0xFF;
addr |= ((bytes[1] << 8) & 0xFF00);
addr |= ((bytes[2] << 16) & 0xFF0000);
addr |= ((bytes[3] << 24) & 0xFF000000);
} catch (Exception e) {
}
return addr;
}
/**
* 1 + 2 + 4 + 8 + 16 + 32 + 64
*
* @param cycle
*/
public static String convertToDay(int cycle) {
String[] days = { "周日", "周六", "周五", "周四", "周三", "周二", "周一" };
cycle = cycle < 128 ? cycle + 128 : cycle;
if (cycle == 128) {
return "永不";
}
if (cycle == 255) {
return "每天(周一 周二 周三 周四 周五 周六 周日)";
}
char[] c = Integer.toBinaryString(cycle).toCharArray();
StringBuilder builder = new StringBuilder();
for (int i = c.length - 1; i > 0; i--) {
if (String.valueOf(c[i]).equals("1")) {
builder.append(days[i - 1] + " ");
}
}
return builder.toString();
}
}
byte[] time = ByteUtil.intToByte(bean.Time);String hour = time[1] < 10 ? "0" + time[1] : "" + time[1];String minute = time[0] < 10 ? "0" + time[0] : "" + time[0];tvAlarmTime.setText(getString(R.string.vibrate_time, hour, minute));
public static byte[] intToByte(int i) {
byte[] abyte0 = new byte[4];
abyte0[0] = (byte) (0xff & i);
abyte0[1] = (byte) ((0xff00 & i) >> 8);
abyte0[2] = (byte) ((0xff0000 & i) >> 16);
abyte0[3] = (byte) ((0xff000000 & i) >> 24);
return abyte0;
}
int cycle = bean.Cycle;
cycle = cycle < 128 ? cycle + 128 : cycle;
char[] c = Integer.toBinaryString(cycle).toCharArray();
cbMonday.setChecked(String.valueOf(c[7]).equals("1"));
cbTuesday.setChecked(String.valueOf(c[6]).equals("1"));
cbWednesday.setChecked(String.valueOf(c[5]).equals("1"));
cbThursday.setChecked(String.valueOf(c[4]).equals("1"));
cbFriday.setChecked(String.valueOf(c[3]).equals("1"));
cbSaturday.setChecked(String.valueOf(c[2]).equals("1"));
cbSunday.setChecked(String.valueOf(c[1]).equals("1"));