179 lines
6.0 KiB
Java
179 lines
6.0 KiB
Java
package com.ds.remote;
|
|
|
|
import android.app.AlertDialog;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.util.Log;
|
|
|
|
import java.util.Calendar;
|
|
|
|
public class Public {
|
|
//串口服务
|
|
public static SerialPortService serial_port_service;
|
|
//串口名称
|
|
//public static final String ComDefaultName = "/dev/s3c2410_serial3"; //Android 开发板靠边第一个串口
|
|
public static final String ComDefaultName = "/dev/ttyS1"; //Android 开发板靠边第一个串口
|
|
private static String ComName;
|
|
//串口波特率
|
|
public static final int ComBaudrate = 19200;
|
|
|
|
//数据库
|
|
public static final String db_name = "remote.sqlite";
|
|
public static final String table_name_favorite = "favorite";
|
|
public static final String table_name_learn_code = "learn_code";
|
|
|
|
//Message
|
|
public static final int MESSAGE_LEARN_BUTTON = 1; //更新学习的按钮
|
|
public static final int MESSAGE_UPDATE_ARC_DISPLAY = 2; //更新arc显示
|
|
public static final int MESSAGE_START_LEARN = 3; //开始学习
|
|
public static final int MESSAGE_LEARN_TIMEOUT = 4; //学习超时
|
|
public static final int MESSAGE_CHANGE_GROUP = 5; //变换码组
|
|
public static final int MESSAGE_LEARN_SUCCEEDED = 6; //学习成功
|
|
public static final int MESSAGE_LEARN_FAILED = 7; //学习失败
|
|
public static final int MESSAGE_ON_RECEIVED = 8; //串口接收数据
|
|
public static final int MESSAGE_SHOW_SIGNAL_FALG = 9; //显示发码标志
|
|
public static final int MESSAGE_HIDE_SIGNAL_FALG = 10; //隐藏发码标志
|
|
public static final int MESSAGE_AUTO_RECOGNITION = 11; //空调学习
|
|
public static final int MESSAGE_RECOGNITION_TIMEOUT = 12; //识别超时
|
|
public static final int MESSAGE_RECOGNITION_SUCCEEDED = 13; //识别超时
|
|
public static final int MESSAGE_RECOGNITION_FAILED = 14; //学习失败
|
|
|
|
//常量
|
|
public static final int REQUEST_LEARN = 0x01;
|
|
public static final int REQUEST_RECOGNITION = 0x02;
|
|
public static final int REQUEST_GROUP = 0x03;
|
|
|
|
//码库
|
|
public static enum GROUP_LIBRARY {
|
|
asia, //亚洲
|
|
america //美洲/欧洲
|
|
}
|
|
|
|
//语言
|
|
public static enum LANGUAGE {
|
|
simple_chinese, //中文
|
|
english //英文
|
|
}
|
|
|
|
public static GROUP_LIBRARY group_library;
|
|
public static LANGUAGE language;
|
|
|
|
|
|
//设置
|
|
public static final String PREFS_NAME = "HbgRemote.Prefs";
|
|
public static final String SETTING_GROUP_LIBRARY = "SETTING_GROUP_LIBRARY";
|
|
public static final String SETTING_LANGUAGE = "SETTING_LANGUAGE";
|
|
|
|
//默认:亚洲码库,中文界面
|
|
public static final GROUP_LIBRARY DEFAULT_GROUP_LIBRARY = GROUP_LIBRARY.asia;
|
|
public static final LANGUAGE DEFAULT_LANGUAGE = LANGUAGE.simple_chinese;
|
|
|
|
public static final String SETTING_FAVORITE_ID = "SETTING_FAVORITE_ID";
|
|
public static final String SETTING_LAST_DEVICE = "SETTING_DEVICE";
|
|
public static final String SETTING_LAST_GROUP = "SETTING_LAST_DEIVCE";
|
|
public static final String SETTING_IS_FIRST = "SETTING_IS_FIRST";
|
|
|
|
//默认设备
|
|
public static final Device.DEVICE_TYPE DEFAULT_DEVICE_TYPE_ASIA = Device.DEVICE_TYPE.C_ATV_DEVICE;
|
|
public static final Device.DEVICE_TYPE DEFAULT_DEVICE_TYPE_AMERICA = Device.DEVICE_TYPE.C_CTV_DEVICE;
|
|
|
|
public static boolean b_require_reload; //是否需要重新加载页面
|
|
|
|
|
|
//////////////////////////
|
|
public static void ShowAlert(String title, String msg, Context context) {
|
|
new AlertDialog.Builder(context)
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
.setTitle(title)
|
|
.setMessage(msg)
|
|
.setCancelable(false)
|
|
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
dialog.cancel();
|
|
}
|
|
})
|
|
.show();
|
|
}
|
|
|
|
public static void ShowInfo(String title, String msg, Context context) {
|
|
new AlertDialog.Builder(context)
|
|
.setIcon(android.R.drawable.ic_dialog_info)
|
|
.setTitle(title)
|
|
.setMessage(msg)
|
|
.setCancelable(false)
|
|
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
dialog.cancel();
|
|
}
|
|
})
|
|
.show();
|
|
}
|
|
|
|
public static String get_date() {
|
|
int mYear;
|
|
int mMonth;
|
|
int mDay;
|
|
|
|
final Calendar c = Calendar.getInstance();
|
|
|
|
mYear = c.get(Calendar.YEAR);
|
|
mMonth = c.get(Calendar.MONTH) + 1;
|
|
mDay = c.get(Calendar.DAY_OF_MONTH);
|
|
|
|
String result = String.format("%04d-%02d-%02d", mYear, mMonth, mDay);
|
|
return result;
|
|
}
|
|
|
|
public static String get_date_time() {
|
|
int mYear;
|
|
int mMonth;
|
|
int mDay;
|
|
int mHour;
|
|
int mMinute;
|
|
int mSecond;
|
|
|
|
final Calendar c = Calendar.getInstance();
|
|
|
|
mYear = c.get(Calendar.YEAR);
|
|
mMonth = c.get(Calendar.MONTH) + 1;
|
|
mDay = c.get(Calendar.DAY_OF_MONTH);
|
|
mHour = c.get(Calendar.HOUR_OF_DAY);
|
|
mMinute = c.get(Calendar.MINUTE);
|
|
mSecond = c.get(Calendar.SECOND);
|
|
|
|
String result = String.format("%04d-%02d-%02d %02d:%02d:%02d",
|
|
mYear, mMonth, mDay, mHour, mMinute, mSecond);
|
|
return result;
|
|
}
|
|
|
|
public static int get_current_hour() {
|
|
final Calendar c = Calendar.getInstance();
|
|
return c.get(Calendar.HOUR_OF_DAY);
|
|
}
|
|
|
|
public static int get_current_minute() {
|
|
final Calendar c = Calendar.getInstance();
|
|
return c.get(Calendar.MINUTE);
|
|
}
|
|
|
|
public static void debug(byte[] buf, int len) {
|
|
StringBuilder str = new StringBuilder();
|
|
for (int i=0; i<len; i++) {
|
|
str.append(String.format("%02X ", buf[i]));
|
|
}
|
|
Log.e("----", "DEBUG_BUF: " + str.toString());
|
|
}
|
|
|
|
public static void setCommName(String com){
|
|
ComName = com;
|
|
}
|
|
|
|
public static String getCommName(){
|
|
if(ComName == null)
|
|
return ComDefaultName;
|
|
else
|
|
return ComName;
|
|
}
|
|
|
|
}
|