Untitled

mail@pastecode.io avatar
unknown
java
4 years ago
43 kB
6
Indexable
Never
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
        boolean z;
        int i2;
        boolean z2;
        long j;
        long currentTimeMillis;
        long j2;
        String str;
        StringBuilder sb;
        byte[] bArr2 = bArr;
        if (!this.isDestroy && bluetoothDevice.getName() != null && bluetoothDevice.getName().equals(Const.DEVICE_NAME)) {
            String address = bluetoothDevice.getAddress();
            final Device device = null;
            final int i3 = -1;
            for (int i4 = 0; i4 < this.deviceList.size(); i4++) {
                if (((Device) this.deviceList.get(i4)).getDeviceMac().toLowerCase().equals(address.toLowerCase())) {
                    device = (Device) this.deviceList.get(i4);
                    i3 = i4;
                }
            }
            if (device != null) {
                ObjectAnimator objectAnimator = this.animator;
                if (objectAnimator != null) {
                    objectAnimator.cancel();
                }
                String str2 = "";
                for (byte b : bArr2) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append(str2);
                    byte b2 = b & 255;
                    if (Integer.toHexString(b2).length() == 2) {
                        sb = new StringBuilder();
                        str = " ";
                    } else {
                        sb = new StringBuilder();
                        str = " 0";
                    }
                    sb.append(str);
                    sb.append(Integer.toHexString(b2));
                    sb2.append(sb.toString());
                    str2 = sb2.toString();
                }
                String str3 = this.TAG;
                StringBuilder sb3 = new StringBuilder();
                sb3.append("onLeScan: scanRecord: ");
                sb3.append(str2);
                Log.d(str3, sb3.toString());
                int customDataStartIndex = Utils.getCustomDataStartIndex(bArr);
                if (customDataStartIndex == -1) {
                    String str4 = this.TAG;
                    StringBuilder sb4 = new StringBuilder();
                    sb4.append("unavailable device: ");
                    sb4.append(bluetoothDevice.getName());
                    sb4.append(": ");
                    sb4.append(address);
                    Log.e(str4, "onLeScan: ", new Exception(sb4.toString()));
                    return;
                }
                boolean z3 = true;
                if (bArr2[customDataStartIndex] == 21 || bArr2[customDataStartIndex] == 19) {
                    int littleEndianDataParse = Utils.littleEndianDataParse(bArr2, customDataStartIndex + 12, 2);
                    float littleEndianDataParseHaveSign = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 14, 2)) / 16.0f;
                    int i5 = customDataStartIndex + 2;
                    if (bArr2[i5] == 16 || bArr2[i5] == 17 || bArr2[i5] == 18) {
                        float littleEndianDataParseHaveSign2 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 16, 2)) / 16.0f;
                        j = (long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 18, 4);
                        if (((device.getHumidityType() & 1) == 1 && littleEndianDataParseHaveSign2 <= device.getPresetLowestHumidity() && device.getRecentHumidity() > device.getPresetLowestHumidity()) || ((device.getHumidityType() & 2) == 2 && littleEndianDataParseHaveSign2 >= device.getPresetHighestHumidity() && device.getRecentHumidity() < device.getPresetHighestHumidity())) {
                            NotificationSender.getInstance().notify(this, 2, device, littleEndianDataParseHaveSign2);
                        }
                        if (device.getRecentHumidity() != littleEndianDataParseHaveSign2) {
                            device.setRecentHumidity(littleEndianDataParseHaveSign2);
                            z2 = true;
                            long j3 = 1000 * j;
                            currentTimeMillis = System.currentTimeMillis() - j3;
                            long j4 = j3 + currentTimeMillis;
                            if (!Utils.isNew(currentTimeMillis, device.getStartTime(), j)) {
                                String str5 = this.TAG;
                                StringBuilder sb5 = new StringBuilder();
                                sb5.append("onLeScan: start change: ");
                                j2 = j4;
                                sb5.append(Math.abs(device.getStartTime() - currentTimeMillis));
                                sb5.append(", ");
                                sb5.append(Math.ceil((double) Math.abs(((float) (device.getStartTime() - currentTimeMillis)) / 1000.0f)));
                                Log.e(str5, sb5.toString());
                                device.setStartTime(currentTimeMillis);
                                try {
                                    MyApplication myApplication = this.myApplication;
                                    Session session = new Session(currentTimeMillis, device.getHighestTemp(), device.getHighestTempTime(), device.getLowestTemp(), device.getLowestTempTime(), device.getTempType(), device.getName(), device.getLocation(), device.getPresetHighest(), device.getPresetLowest(), device.getImgName(), device.getDeviceType());
                                    device.setSessionID(myApplication.addSession(session));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                z2 = true;
                            } else {
                                j2 = j4;
                            }
                            if (((device.getTempType() & 1) == 1 && littleEndianDataParseHaveSign <= device.getPresetLowest() && device.getRecentTemp() > device.getPresetLowest()) || ((device.getTempType() & 2) == 2 && littleEndianDataParseHaveSign >= device.getPresetHighest() && device.getRecentTemp() < device.getPresetHighest())) {
                                NotificationSender.getInstance().notify(this, 1, device, littleEndianDataParseHaveSign);
                            }
                            if (device.getRecentTempTime() != j2) {
                                long j5 = j2;
                                device.setRecentTempTime(j5);
                                device.setRecentTemp(littleEndianDataParseHaveSign);
                                if (littleEndianDataParseHaveSign > device.getHighestTemp()) {
                                    device.setHighestTemp(littleEndianDataParseHaveSign);
                                    device.setHighestTempTime(j5);
                                }
                                if (littleEndianDataParseHaveSign < device.getLowestTemp()) {
                                    device.setLowestTemp(littleEndianDataParseHaveSign);
                                    device.setLowestTempTime(j5);
                                }
                                z2 = true;
                            }
                            if (device.getBattery() == littleEndianDataParse) {
                                device.setBattery(littleEndianDataParse);
                            } else {
                                z3 = z2;
                            }
                            String str6 = this.TAG;
                            StringBuilder sb6 = new StringBuilder();
                            sb6.append("onLeScan: battery: ");
                            sb6.append(littleEndianDataParse);
                            sb6.append(", currentTemperature: ");
                            sb6.append(littleEndianDataParseHaveSign);
                            sb6.append(", currentTempDeviceRuntime: ");
                            sb6.append(j);
                            Log.i(str6, sb6.toString());
                            i2 = i;
                            z = z3;
                        }
                    } else {
                        j = (long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 16, 4);
                    }
                    z2 = false;
                    long j32 = 1000 * j;
                    currentTimeMillis = System.currentTimeMillis() - j32;
                    long j42 = j32 + currentTimeMillis;
                    if (!Utils.isNew(currentTimeMillis, device.getStartTime(), j)) {
                    }
                    NotificationSender.getInstance().notify(this, 1, device, littleEndianDataParseHaveSign);
                    if (device.getRecentTempTime() != j2) {
                    }
                    if (device.getBattery() == littleEndianDataParse) {
                    }
                    String str62 = this.TAG;
                    StringBuilder sb62 = new StringBuilder();
                    sb62.append("onLeScan: battery: ");
                    sb62.append(littleEndianDataParse);
                    sb62.append(", currentTemperature: ");
                    sb62.append(littleEndianDataParseHaveSign);
                    sb62.append(", currentTempDeviceRuntime: ");
                    sb62.append(j);
                    Log.i(str62, sb62.toString());
                    i2 = i;
                    z = z3;
                } else if (bArr2[customDataStartIndex] != 23 || device.getStartTime() == 0) {
                    i2 = i;
                    z = false;
                } else {
                    float littleEndianDataParseHaveSign3 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 12, 2)) / 16.0f;
                    float littleEndianDataParseHaveSign4 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 18, 2)) / 16.0f;
                    long startTime = device.getStartTime() + (((long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 14, 4)) * 1000);
                    long startTime2 = device.getStartTime() + (((long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 20, 4)) * 1000);
                    String str7 = this.TAG;
                    StringBuilder sb7 = new StringBuilder();
                    sb7.append("onLeScan: highest: ");
                    sb7.append(littleEndianDataParseHaveSign3);
                    sb7.append(", lowest: ");
                    sb7.append(littleEndianDataParseHaveSign4);
                    Log.i(str7, sb7.toString());
                    if (device.getHighestTempTime() == startTime && device.getHighestTemp() == littleEndianDataParseHaveSign3) {
                        z = false;
                    } else {
                        device.setHighestTempTime(startTime);
                        device.setHighestTemp(littleEndianDataParseHaveSign3);
                        z = true;
                    }
                    if (!(device.getLowestTempTime() == startTime2 && device.getLowestTemp() == littleEndianDataParseHaveSign4)) {
                        device.setLowestTempTime(startTime2);
                        device.setLowestTemp(littleEndianDataParseHaveSign4);
                        z = true;
                    }
                    if (z) {
                        Session sessionBySessionID = this.myApplication.getSessionBySessionID(device.getSessionID());
                        sessionBySessionID.setHighest(littleEndianDataParseHaveSign3);
                        sessionBySessionID.setHighestTime(startTime);
                        sessionBySessionID.setLowest(littleEndianDataParseHaveSign4);
                        sessionBySessionID.setLowestTime(startTime2);
                        String str8 = this.TAG;
                        StringBuilder sb8 = new StringBuilder();
                        sb8.append("getShowData3 lowestValue: ");
                        sb8.append(littleEndianDataParseHaveSign4);
                        sb8.append(", time: ");
                        sb8.append(startTime2);
                        Log.i(str8, sb8.toString());
                        this.myApplication.updateSession(sessionBySessionID);
                    }
                    i2 = i;
                }
                device.setSignal(i2);
                if (z) {
                    this.handler.post(new Runnable() {
                        public void run() {
                            CurrentActivity.this.deviceAdapter.notifyItemChanged(i3);
                            CurrentActivity.this.myApplication.updateDevice(device);
                        }
                    });
                }
            }
        }
    }

package com.beyondtel.thermoplus.utils;

import java.util.UUID;

public class Const {
    public static final UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    public static final String DB_NAME = "thermo_plus.db";
    public static final float DEFAULT_PRESET_HIGHEST = 27.0f;
    public static final float DEFAULT_PRESET_LOWEST = 20.0f;
    public static final float DEFAULT_TEMP_TYPE = 0.0f;
    public static final String DEVICE_IMAGE_NAME_DEFAULT = "device_default.png";
    public static final String DEVICE_NAME = "ThermoBeacon";
    public static final String EXTRA_NAME_DATA_TYPE = "extra_name_data_type";
    public static final String EXTRA_NAME_DEVICE_MAC = "extra_name_device_mac";
    public static final String EXTRA_NAME_DEVICE_POSITION = "extra_is_device_position";
    public static final String EXTRA_NAME_DEVICE_TYPE = "extra_name_device_type";
    public static final String EXTRA_NAME_HISTORY_ID = "extra_name_history_id";
    public static final String EXTRA_NAME_HISTORY_POSITION = "extra_name_history_position";
    public static final String EXTRA_NAME_IS_DEVICE_DELETED = "extra_is_device_deleted";
    public static final String EXTRA_NAME_IS_FROM_STORY = "extra_name_is_from_story";
    public static final String EXTRA_NAME_IS_UNIT_CHANGED = "extra_name_is_unit_changed";
    public static final String EXTRA_NAME_LOCATION_ID = "extra_name_location_id";
    public static final String EXTRA_NAME_PICTURE_ID = "extra_name_picture_id";
    public static final String EXTRA_NAME_REMARK_IMAGE_POSITION = "extra_name_remark_image_position";
    public static final String EXTRA_NAME_REMARK_IMG_PATH = "extra_name_remark_img_path";
    public static final String EXTRA_NAME_SESSION_ID = "extra_name_session_id";
    public static final String EXTRA_NAME_START_TIME = "extra_name_start_time";
    public static final UUID FFF_3 = UUID.fromString("0000fff3-0000-1000-8000-00805f9b34fb");
    public static final UUID FFF_5 = UUID.fromString("0000fff5-0000-1000-8000-00805f9b34fb");
    public static final UUID FFF_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
    public static final String FLAVOR_HUMIPAD = "Humipad";
    public static final String IS_FIRST_SHOW_HISTORY = "is_first_show_history";
    public static final String LANGUAGE = "language";
    public static final int LANGUAGE_AUTO = 0;
    public static final int LANGUAGE_DANISH = 2;
    public static final int LANGUAGE_DUTCH = 6;
    public static final int LANGUAGE_ENGLISH = 1;
    public static final int LANGUAGE_FRENCH = 4;
    public static final int LANGUAGE_GERMAN = 3;
    public static final int LANGUAGE_ITALIAN = 7;
    public static final int LANGUAGE_JAPANESE = 8;
    public static final int LANGUAGE_SPANISH = 5;
    public static final long LOGGER_INTERVAL = 600000;
    public static final String NEED_SHOW_LOCATION_ALERT = "need_show_location_alert";
    public static final int REQUEST_CODE_BLE_PERMISSION = 931;
    public static final int REQUEST_CODE_CAMERA = 631;
    public static final int REQUEST_CODE_CAMERA_PERMISSION = 933;
    public static final int REQUEST_CODE_CROP = 634;
    public static final int REQUEST_CODE_DEVICE_SETTING = 635;
    public static final int REQUEST_CODE_GALLERY = 632;
    public static final int REQUEST_CODE_HISTORY_REMARK = 637;
    public static final int REQUEST_CODE_HISTORY_REMARK_IMG = 638;
    public static final int REQUEST_CODE_LOCATION = 639;
    public static final int REQUEST_CODE_SETTING = 636;
    public static final int REQUEST_CODE_STORAGE_PERMISSION = 932;
    public static final int REQUEST_CODE_SYSTEM = 633;
    public static final String SETTING_NAME_ALERTRINGTONE = "alertRingtone";
    public static final String SETTING_NAME_ALERTVIBRATION = "alertVibration";
    public static final String SETTING_NAME_ISUNITCELSIUS = "isUnitCelsius";
    public static final int UPDATE_INTERVAL = 5000;
}

package com.beyondtel.thermoplus.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.net.Uri;
import android.provider.Settings.System;
import android.text.format.DateFormat;
import android.util.Log;
import android.util.TypedValue;
import com.beyondtel.sensorblue.R;
import com.beyondtel.thermoplus.MyApplication;
import com.beyondtel.thermoplus.entity.History;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Utils {
    private static final String TAG = "Utils";

    public static float c2f(float f) {
        return (f * 1.8f) + 32.0f;
    }

    public static float f2c(float f) {
        return (f - 32.0f) / 1.8f;
    }

    private void scanDataParse(byte[] bArr) {
    }

    public static int bigEndianDataParse(byte[] bArr, int i, int i2) throws Exception {
        if (i2 == 2) {
            return (short) (bArr[i + 1] | (bArr[i] << 8));
        } else if (i2 == 4) {
            return bArr[i + 3] | (bArr[i] << 24) | (bArr[i + 1] << 16) | (bArr[i + 2] << 8);
        } else {
            throw new Exception("length value can only be 2 or 4");
        }
    }

    public static int littleEndianDataParse(byte[] bArr, int i, int i2) {
        short s;
        short s2;
        if (i2 == 2) {
            s = (short) (bArr[i] & 255);
            s2 = (bArr[i + 1] << 8) & 65280;
        } else if (i2 != 4) {
            return -1;
        } else {
            s = (bArr[i] & 255) | (65280 & (bArr[i + 1] << 8)) | ((bArr[i + 2] << 16) & 16711680);
            s2 = (bArr[i + 3] << 24) & -16777216;
        }
        return s2 | s;
    }

    public static int littleEndianDataParseHaveSign(byte[] bArr, int i, int i2) {
        short s;
        int i3;
        if (i2 == 2) {
            s = (short) (bArr[i] & 255);
            i3 = bArr[i + 1] << 8;
        } else if (i2 != 4) {
            return -1;
        } else {
            s = bArr[i] | (bArr[i + 1] << 8) | (bArr[i + 2] << 16);
            i3 = bArr[i + 3] << 24;
        }
        return i3 | s;
    }

    public static String deviceMacAddressParse(byte[] bArr, int i) {
        StringBuilder sb = new StringBuilder();
        sb.append(Integer.toHexString(bArr[i + 6] & 255));
        String str = ":";
        sb.append(str);
        sb.append(Integer.toHexString(bArr[i + 7] & 255));
        sb.append(str);
        sb.append(Integer.toHexString(bArr[i + 8] & 255));
        sb.append(str);
        sb.append(Integer.toHexString(bArr[i + 9] & 255));
        sb.append(str);
        sb.append(Integer.toHexString(bArr[i + 10] & 255));
        sb.append(str);
        sb.append(Integer.toHexString(bArr[i + 11] & 255));
        return sb.toString();
    }

    public static boolean isConfirmPkg(byte[] bArr, int i) {
        return bArr[i + 5] == Byte.MIN_VALUE;
    }

    public static int getCustomDataStartIndex(byte[] bArr) {
        int i = 0;
        while (i < bArr.length - 1) {
            if (bArr[i + 1] == -1) {
                return i;
            }
            i += bArr[i] + 1;
        }
        return -1;
    }

    public static String dateFormat(long j) {
        String str;
        Date date = new Date(j);
        int intValue = Integer.valueOf((String) DateFormat.format("dd", date)).intValue();
        if (intValue != 1) {
            if (intValue != 2) {
                if (intValue != 3) {
                    switch (intValue) {
                        case 21:
                            break;
                        case 22:
                            break;
                        case 23:
                            break;
                        default:
                            StringBuilder sb = new StringBuilder();
                            sb.append(intValue);
                            sb.append("th");
                            str = sb.toString();
                            break;
                    }
                }
                StringBuilder sb2 = new StringBuilder();
                sb2.append(intValue);
                sb2.append("rd");
                str = sb2.toString();
                StringBuilder sb3 = new StringBuilder();
                sb3.append(str);
                sb3.append(".");
                sb3.append(DateFormat.format("MMM", date));
                return sb3.toString();
            }
            StringBuilder sb4 = new StringBuilder();
            sb4.append(intValue);
            sb4.append("nd");
            str = sb4.toString();
            StringBuilder sb32 = new StringBuilder();
            sb32.append(str);
            sb32.append(".");
            sb32.append(DateFormat.format("MMM", date));
            return sb32.toString();
        }
        StringBuilder sb5 = new StringBuilder();
        sb5.append(intValue);
        sb5.append("st");
        str = sb5.toString();
        StringBuilder sb322 = new StringBuilder();
        sb322.append(str);
        sb322.append(".");
        sb322.append(DateFormat.format("MMM", date));
        return sb322.toString();
    }

    public static String time2PeriodDHM(long j) {
        int i = (int) (j / 86400000);
        long j2 = j % 86400000;
        int i2 = (int) (j2 / 3600000);
        int i3 = (int) ((j2 % 3600000) / 60000);
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        sb.append("D");
        sb.append(i2);
        sb.append("H");
        sb.append(i3);
        sb.append("M");
        return sb.toString();
    }

    public static String time2PeriodDH(long j) {
        int i = (int) (j / 86400000);
        int i2 = (int) ((j % 86400000) / 3600000);
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        sb.append("D");
        sb.append(i2);
        sb.append("H");
        return sb.toString();
    }

    public static CharSequence time2HistoryTime(long j) {
        String str = "yyyy-MM-dd";
        if (!DateFormat.format(str, new Date()).equals(DateFormat.format(str, new Date(j)))) {
            return time2TimePointStr(j);
        }
        return DateFormat.format("HH:mm", new Date(j));
    }

    public static CharSequence time2TimePointStr(long j) {
        StringBuilder sb = new StringBuilder();
        sb.append(getMonth(j).toString());
        sb.append(DateFormat.format(".dd", new Date(j)).toString());
        return sb.toString();
    }

    public static CharSequence getMonth(long j) {
        Calendar instance = Calendar.getInstance();
        instance.setTimeInMillis(j);
        switch (instance.get(2)) {
            case 1:
                return "Feb";
            case 2:
                return "Mar";
            case 3:
                return "Apr";
            case 4:
                return "May";
            case 5:
                return "Jun";
            case 6:
                return "Jul";
            case 7:
                return "Aug";
            case 8:
                return "Sep";
            case 9:
                return "Oct";
            case 10:
                return "Nov";
            case 11:
                return "Dec";
            default:
                return "Jan";
        }
    }

    public static String getTempStr(float f) {
        String str = "%.2f";
        if (!MyApplication.getInstance().isUnitCelsius()) {
            return String.format(str, new Object[]{Float.valueOf(c2f(f))});
        }
        return String.format(str, new Object[]{Float.valueOf(f)});
    }

    public static String getIntegerPart(float f) {
        if (!MyApplication.getInstance().isUnitCelsius()) {
            f = c2f(f);
        }
        StringBuilder sb = new StringBuilder();
        sb.append((int) f);
        sb.append("");
        return sb.toString();
    }

    public static String getDecimalPart(float f) {
        if (!MyApplication.getInstance().isUnitCelsius()) {
            f = c2f(f);
        }
        int abs = Math.abs(Math.round(((f * 1000.0f) % 1000.0f) / 10.0f));
        if (abs < 10) {
            StringBuilder sb = new StringBuilder();
            sb.append(".0");
            sb.append(abs);
            return sb.toString();
        }
        StringBuilder sb2 = new StringBuilder();
        sb2.append(".");
        sb2.append(abs);
        return sb2.toString();
    }

    public static String getHumidityStr(float f) {
        return String.format("%.1f", new Object[]{Float.valueOf(f)});
    }

    public static String getHumidityIntegerPart(float f) {
        StringBuilder sb = new StringBuilder();
        sb.append((int) f);
        sb.append("");
        return sb.toString();
    }

    public static String getHumidityDecimalPart(float f) {
        int abs = Math.abs(Math.round(((f * 100.0f) % 100.0f) / 10.0f));
        StringBuilder sb = new StringBuilder();
        sb.append(".");
        sb.append(abs);
        return sb.toString();
    }

    public static String showTemp(float f) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        if (MyApplication.getInstance().isUnitCelsius()) {
            return decimalFormat.format((double) f);
        }
        return decimalFormat.format((double) c2f(f));
    }

    public static String showHumidity(float f) {
        DecimalFormat decimalFormat = new DecimalFormat("0.0");
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        return decimalFormat.format((double) f);
    }

    public static String showTempWithUnit(float f) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00°");
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        if (MyApplication.getInstance().isUnitCelsius()) {
            return decimalFormat.format((double) f);
        }
        return decimalFormat.format((double) c2f(f));
    }

    public static String showHumidityWithUnit(float f) {
        DecimalFormat decimalFormat = new DecimalFormat("0.0");
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        StringBuilder sb = new StringBuilder();
        sb.append(decimalFormat.format((double) f));
        sb.append("%");
        return sb.toString();
    }

    public static String showTempIntegerStr(float f) {
        String str = "°";
        if (MyApplication.getInstance().isUnitCelsius()) {
            StringBuilder sb = new StringBuilder();
            sb.append(Math.round(f));
            sb.append(str);
            return sb.toString();
        }
        StringBuilder sb2 = new StringBuilder();
        sb2.append(Math.round(c2f(f)));
        sb2.append(str);
        return sb2.toString();
    }

    public static String showExpiredStr(int i) {
        if (i == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        sb.append(" days");
        return sb.toString();
    }

    public static String showHumidityIntegerStr(float f) {
        StringBuilder sb = new StringBuilder();
        sb.append(Math.round(f));
        sb.append("%");
        return sb.toString();
    }

    public static int showTempInteger(float f) {
        if (MyApplication.getInstance().isUnitCelsius()) {
            return Math.round(f);
        }
        return Math.round(c2f(f));
    }

    public static String getDevicePresetValueStr(Context context, int i, float f, float f2, int i2, float f3, float f4) {
        if (i == 0 && i2 == 0) {
            return "";
        }
        String string = context.getResources().getString(R.string.current_desired);
        String str = "~";
        if ((i & 1) == 1) {
            if ((i & 2) == 2) {
                StringBuilder sb = new StringBuilder();
                sb.append(string);
                sb.append(context.getResources().getString(R.string.current_desired_temp));
                sb.append(showTempIntegerStr(f2));
                sb.append(str);
                sb.append(showTempIntegerStr(f));
                string = sb.toString();
            } else {
                StringBuilder sb2 = new StringBuilder();
                sb2.append(string);
                sb2.append(context.getResources().getString(R.string.current_desired_temp));
                sb2.append(showTempIntegerStr(f2));
                sb2.append("~∞");
                string = sb2.toString();
            }
        } else if ((i & 2) == 2) {
            StringBuilder sb3 = new StringBuilder();
            sb3.append(string);
            sb3.append(context.getResources().getString(R.string.current_desired_temp));
            sb3.append("-∞~");
            sb3.append(showTempIntegerStr(f));
            string = sb3.toString();
        }
        if (!(i == 0 || i2 == 0)) {
            StringBuilder sb4 = new StringBuilder();
            sb4.append(string);
            sb4.append(" · ");
            string = sb4.toString();
        }
        if ((i2 & 1) == 1) {
            if ((i2 & 2) == 2) {
                StringBuilder sb5 = new StringBuilder();
                sb5.append(string);
                sb5.append(context.getResources().getString(R.string.current_desired_humidity));
                sb5.append(showHumidityIntegerStr(f4));
                sb5.append(str);
                sb5.append(showHumidityIntegerStr(f3));
                string = sb5.toString();
            } else {
                StringBuilder sb6 = new StringBuilder();
                sb6.append(string);
                sb6.append(context.getResources().getString(R.string.current_desired_humidity));
                sb6.append(showHumidityIntegerStr(f4));
                sb6.append("~100%");
                string = sb6.toString();
            }
        } else if ((i2 & 2) == 2) {
            StringBuilder sb7 = new StringBuilder();
            sb7.append(string);
            sb7.append(context.getResources().getString(R.string.current_desired_humidity));
            sb7.append("0%~");
            sb7.append(showHumidityIntegerStr(f3));
            string = sb7.toString();
        }
        return string;
    }

    public static boolean isNew(long j, long j2, long j3) {
        return ((float) Math.abs((j - j2) / 1000)) > ((float) (j3 * 4)) / 10000.0f;
    }

    public static int c2fInterger(float f) {
        return Math.round((f * 1.8f) + 32.0f);
    }

    public static String time2Interval(long j) {
        int i = (int) (j / 86400000);
        long j2 = j % 86400000;
        int i2 = (int) (j2 / 3600000);
        int i3 = (int) ((j2 % 3600000) / 60000);
        if (i != 0) {
            if (i == 1) {
                StringBuilder sb = new StringBuilder();
                sb.append(i);
                sb.append(" day ago");
                return sb.toString();
            }
            StringBuilder sb2 = new StringBuilder();
            sb2.append(i);
            sb2.append(" days ago");
            return sb2.toString();
        } else if (i2 != 0) {
            if (i2 == 1) {
                StringBuilder sb3 = new StringBuilder();
                sb3.append(i2);
                sb3.append(" hour ago");
                return sb3.toString();
            }
            StringBuilder sb4 = new StringBuilder();
            sb4.append(i2);
            sb4.append(" hours ago");
            return sb4.toString();
        } else if (i3 > 30) {
            return "30 minutes ago";
        } else {
            if (i3 > 20) {
                return "20 minutes ago";
            }
            if (i3 > 10) {
                return "10 minutes ago";
            }
            return i3 > 5 ? "5 minutes ago" : MyApplication.getInstance().getString(R.string.now);
        }
    }

    public static float dp2px(float f) {
        return TypedValue.applyDimension(1, f, Resources.getSystem().getDisplayMetrics());
    }

    public static float sp2px(int i) {
        return TypedValue.applyDimension(2, (float) i, Resources.getSystem().getDisplayMetrics());
    }

    public static String byte2HexStr(byte[] bArr) {
        String str = "";
        for (byte b : bArr) {
            String hexString = Integer.toHexString(b & 255);
            if (hexString.length() == 1) {
                StringBuilder sb = new StringBuilder();
                sb.append("0");
                sb.append(hexString);
                hexString = sb.toString();
            }
            StringBuilder sb2 = new StringBuilder();
            sb2.append(str);
            sb2.append(hexString);
            sb2.append(" ");
            str = sb2.toString();
        }
        return str;
    }

    public static String getVersion(Context context) {
        try {
            return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return "Can not find version name";
        }
    }

    public static Bitmap getAvatar(Resources resources, int i) {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(resources, R.drawable.ic_triangle, options);
        options.inJustDecodeBounds = false;
        options.inDensity = options.outWidth;
        options.inTargetDensity = i;
        return BitmapFactory.decodeResource(resources, R.drawable.ic_triangle, options);
    }

    public static List<History> getShowData(int i, List<History> list, long j, float f, long j2, float f2) {
        float f3;
        int i2;
        int i3;
        int i4;
        String str;
        String str2;
        String str3;
        int i5;
        String str4;
        int i6;
        int i7;
        List<History> list2 = list;
        long j3 = j;
        float f4 = f;
        long j4 = j2;
        float f5 = f2;
        int size = list.size() < 100 ? list.size() : 100;
        float size2 = ((float) list.size()) / ((float) size);
        ArrayList arrayList = new ArrayList(size + 2);
        int i8 = 0;
        while (i8 < size) {
            float f6 = ((float) i8) * size2;
            int size3 = Math.round(f6) > list.size() - 1 ? list.size() - 1 : Math.round(f6);
            arrayList.add(list2.get(size3));
            if (i == 1) {
                float f7 = ((float) (i8 + 1)) * size2;
                int size4 = Math.round(f7) > list.size() + -1 ? list.size() - 1 : Math.round(f7);
                String str5 = "getShowData: add lowest position: ";
                String str6 = "getShowData add lowest: ";
                i2 = size;
                f3 = size2;
                String str7 = "getShowData: add highest position: ";
                String str8 = ", ";
                String str9 = "HH:mm";
                String str10 = "getShowData add highest: ";
                String str11 = TAG;
                if (j3 < j4) {
                    if (((History) list2.get(size3)).getTime() >= j3 || ((History) list2.get(size4)).getTime() <= j3) {
                        i6 = size4;
                        i7 = size3;
                        i4 = i8;
                        str4 = str8;
                    } else {
                        StringBuilder sb = new StringBuilder();
                        sb.append(str6);
                        sb.append(DateFormat.format(str9, j3));
                        sb.append(str8);
                        sb.append(f4);
                        Log.d(str11, sb.toString());
                        i6 = size4;
                        String str12 = str5;
                        i7 = size3;
                        i4 = i8;
                        str4 = str8;
                        History history = r1;
                        History history2 = new History(((History) list2.get(i8)).getSessionID().longValue(), f, j);
                        arrayList.add(history);
                        StringBuilder sb2 = new StringBuilder();
                        sb2.append(str12);
                        sb2.append(arrayList.size() - 1);
                        Log.d(str11, sb2.toString());
                    }
                    if (((History) list2.get(i7)).getTime() >= j4 || ((History) list2.get(i6)).getTime() <= j4) {
                        float f8 = f2;
                        j3 = j;
                    } else {
                        StringBuilder sb3 = new StringBuilder();
                        sb3.append(str10);
                        sb3.append(DateFormat.format(str9, j4));
                        sb3.append(str4);
                        sb3.append(f2);
                        Log.d(str11, sb3.toString());
                        int i9 = i4;
                        History history3 = new History(((History) list2.get(i9)).getSessionID().longValue(), f2, j2);
                        arrayList.add(history3);
                        StringBuilder sb4 = new StringBuilder();
                        sb4.append(str7);
                        sb4.append(arrayList.size() - 1);
                        Log.d(str11, sb4.toString());
                        f4 = f;
                        i3 = i9;
                        j3 = j;
                    }
                } else {
                    int i10 = size4;
                    String str13 = str5;
                    int i11 = size3;
                    int i12 = i8;
                    String str14 = str9;
                    String str15 = str8;
                    String str16 = str7;
                    String str17 = str10;
                    float f9 = f2;
                    if (((History) list2.get(i11)).getTime() >= j4 || ((History) list2.get(i10)).getTime() <= j4) {
                        str3 = str6;
                        str2 = str14;
                        i5 = i12;
                        str = str13;
                    } else {
                        StringBuilder sb5 = new StringBuilder();
                        sb5.append(str17);
                        sb5.append(DateFormat.format(str14, j4));
                        sb5.append(str15);
                        sb5.append(f9);
                        Log.d(str11, sb5.toString());
                        str3 = str6;
                        str = str13;
                        History history4 = r1;
                        str2 = str14;
                        String str18 = str16;
                        i5 = i12;
                        History history5 = new History(((History) list2.get(i12)).getSessionID().longValue(), f2, j2);
                        arrayList.add(history4);
                        StringBuilder sb6 = new StringBuilder();
                        sb6.append(str18);
                        sb6.append(arrayList.size() - 1);
                        Log.d(str11, sb6.toString());
                    }
                    j3 = j;
                    String str19 = str;
                    if (((History) list2.get(i11)).getTime() < j3 && ((History) list2.get(i10)).getTime() > j3) {
                        StringBuilder sb7 = new StringBuilder();
                        sb7.append(str3);
                        sb7.append(DateFormat.format(str2, j3));
                        sb7.append(str15);
                        f4 = f;
                        sb7.append(f4);
                        Log.d(str11, sb7.toString());
                        i3 = i4;
                        History history6 = new History(((History) list2.get(i3)).getSessionID().longValue(), f, j);
                        arrayList.add(history6);
                        StringBuilder sb8 = new StringBuilder();
                        sb8.append(str19);
                        sb8.append(arrayList.size() - 1);
                        Log.d(str11, sb8.toString());
                    }
                }
                f4 = f;
                i3 = i4;
            } else {
                i3 = i8;
                i2 = size;
                f3 = size2;
            }
            i8 = i3 + 1;
            j4 = j2;
            float f10 = f2;
            size = i2;
            size2 = f3;
        }
        return arrayList;
    }

    public static Uri saveBitmap(Bitmap bitmap, Uri uri) {
        StringBuilder sb = new StringBuilder();
        sb.append("saveBitmap: ");
        sb.append(uri.getPath());
        Log.i(TAG, sb.toString());
        if (bitmap != null) {
            try {
                File file = new File(uri.getPath());
                if (file.exists()) {
                    file.delete();
                }
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.PNG, 100, fileOutputStream);
                fileOutputStream.flush();
                fileOutputStream.close();
                return uri;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e2) {
                e2.printStackTrace();
                return null;
            }
        }
        return null;
    }

    public static String getBatteryRemainTime(int i) {
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        sb.append("");
        return sb.toString();
    }

    public static boolean isTimeFormat24(ContentResolver contentResolver) {
        String string = System.getString(contentResolver, "time_12_24");
        if (string == null) {
            return false;
        }
        return "24".equals(string);
    }
}