public class Globals {
// TODO IMPORTANT CONFIG CHANGES
// ** IMPORTANT CONFIGURATION
private static String serverRealUrl = "http://www.myserver.com/api"; //Real Server configuration
private static String serverLocalUrl = "http://localhost:80/api"; //local configuration
/**
* Substitute you own sender ID here. This is the project number you got
* from the API Console, as described in "Getting Started."
*/
public static String SENDER_ID = "000000";
public static String base64EncodedPublicKey = "xxxxx";
//DEBUG MODO
public static boolean debugModeBoolean = true; //USE in DEBUG MODE
//public static boolean debugModeBoolean = false; //USE in REAL MODE
//PRINT FROM WEB ENABLES
//public static boolean printFronWebEnabled = true; //USE to activate print fron web
public static boolean printFronWebEnabled = false; //USE to deactivate print fron web
//GCM Register
//public static boolean gcmRegisterEnabled = true; //USE to register device in GCM
public static boolean gcmRegisterEnabled = false; // not use gcm services
//IN APP BILLING
//public static boolean inAppBillingModeON = true; //USE in pay app modo on
public static boolean inAppBillingModeON = false; //USE in pay app modo off
private static String internalClassName = "Globals"; // * Tag used on log messages.
public static int deviceType = 0; // * Device type
//0 Pending config (Default as start)
//1 NET Print
//2 RS232 ->Pending
//3 USB
//4 BT
//Google subscriptions
public static boolean mSubscribedToYearlyUsed = false;
// Bluetooth variable Config
public static BluetoothAdapter mBluetoothAdapter;
public static BluetoothSocket mmSocket;
public static BluetoothDevice mmDevice;
public static String logoProcesed = "";
public static OutputStream mmOutputStream;
public static InputStream mmInputStream;
// NET Printer Config
public static String deviceIP = "";
public static int devicePort = 0;
public static int usbDeviceID = 0;
public static int usbVendorID = 0;
public static int usbProductID = 0;
public static String blueToothDeviceAdress = "";
public static int blueToothSpinnerSelected = -1;
public static String tmpDeviceIP = "";
public static int tmpDevicePort = 0;
public static int tmpUsbDeviceID = 0;
public static int tmpUsbVendorID = 0;
public static int tmpUsbProductID = 0;
public static String link_code = "";
public static String tmpBlueToothDeviceAdress = "";
public static String getServerUrl() {
String actualServer = "";
if (debugModeBoolean) {
actualServer = serverLocalUrl;
} else {
actualServer = serverRealUrl;
}
return actualServer;
}
public static String server_registerPrinter = "registerPrinter";
public static String server_getData = "getData";
public static String regid = "";
public static String picturePath = "";
public static void savePreferences(SharedPreferences sharedPrefs) {
Log.i(internalClassName, "savePreferences");
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString("usbDeviceID", String.valueOf(usbDeviceID));
editor.putString("usbVendorID", String.valueOf(usbVendorID));
editor.putString("usbProductID", String.valueOf(usbProductID));
editor.putString("blueToothDeviceAdress", String.valueOf(blueToothDeviceAdress));
editor.putString("deviceType", String.valueOf(deviceType));
//Ethernet
editor.putString("deviceIP", String.valueOf(deviceIP));
editor.putString("devicePort", String.valueOf(devicePort));
editor.putString("link_code", String.valueOf(link_code));
editor.putString("picturePath", String.valueOf(picturePath));
editor.putString("logoProcesed", logoProcesed);
Log.i(internalClassName, " deviceType=" + String.valueOf(deviceType));
Log.i(internalClassName, " deviceIP=" + String.valueOf(deviceIP));
Log.i(internalClassName, " devicePort=" + String.valueOf(devicePort));
Log.i(internalClassName, " usbDeviceID=" + String.valueOf(usbDeviceID));
Log.i(internalClassName, " blueToothDeviceAdress=" + String.valueOf(blueToothDeviceAdress));
editor.commit();
}
public static void savePreferenceskitchen(SharedPreferences sharedPrefs) {
Log.i(internalClassName, "savePreferences");
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString("usbDeviceID", String.valueOf(usbDeviceID));
editor.putString("usbVendorID", String.valueOf(usbVendorID));
editor.putString("usbProductID", String.valueOf(usbProductID));
editor.putString("blueToothDeviceAdress", String.valueOf(blueToothDeviceAdress));
editor.putString("deviceType", String.valueOf(deviceType));
//Ethernet
editor.putString("deviceIP", String.valueOf(deviceIP));
editor.putString("devicePort", String.valueOf(devicePort));
editor.putString("link_code", String.valueOf(link_code));
editor.putString("picturePath", String.valueOf(picturePath));
editor.putString("logoProcesed", logoProcesed);
Log.i(internalClassName, " deviceType=" + String.valueOf(deviceType));
Log.i(internalClassName, " deviceIP=" + String.valueOf(deviceIP));
Log.i(internalClassName, " devicePort=" + String.valueOf(devicePort));
Log.i(internalClassName, " usbDeviceID=" + String.valueOf(usbDeviceID));
Log.i(internalClassName, " blueToothDeviceAdress=" + String.valueOf(blueToothDeviceAdress));
editor.commit();
}
public static void loadPreferences(SharedPreferences sharedPrefs) {
Log.i(internalClassName, "loadPreferences");
usbDeviceID = mathIntegerFromString(sharedPrefs.getString("usbDeviceID", "0"), 0);
usbVendorID = mathIntegerFromString(sharedPrefs.getString("usbVendorID", "0"), 0);
usbProductID = mathIntegerFromString(sharedPrefs.getString("usbProductID", "0"), 0);
link_code = sharedPrefs.getString("link_code", "");
picturePath = sharedPrefs.getString("picturePath", "");
blueToothDeviceAdress = sharedPrefs.getString("blueToothDeviceAdress", "x:x:x:x");
deviceType = mathIntegerFromString(sharedPrefs.getString("deviceType", "0"), 0);
//Ethernet
deviceIP = sharedPrefs.getString("deviceIP", "192.168.0.98");
devicePort = mathIntegerFromString(sharedPrefs.getString("devicePort", "9100"), 9100);
logoProcesed = sharedPrefs.getString("logoProcesed", "");
Log.i(internalClassName, " deviceType=" + String.valueOf(deviceType));
Log.i(internalClassName, " deviceIP=" + String.valueOf(deviceIP));
Log.i(internalClassName, " devicePort=" + String.valueOf(devicePort));
Log.i(internalClassName, " usbDeviceID=" + String.valueOf(usbDeviceID));
Log.i(internalClassName, " blueToothDeviceAdress=" + String.valueOf(blueToothDeviceAdress));
}
public static void loadPreferenceskitchen(SharedPreferences sharedPrefs) {
Log.i(internalClassName, "loadPreferences");
usbDeviceID = mathIntegerFromString(sharedPrefs.getString("usbDeviceID", "0"), 0);
usbVendorID = mathIntegerFromString(sharedPrefs.getString("usbVendorID", "0"), 0);
usbProductID = mathIntegerFromString(sharedPrefs.getString("usbProductID", "0"), 0);
link_code = sharedPrefs.getString("link_code", "");
picturePath = sharedPrefs.getString("picturePath", "");
blueToothDeviceAdress = sharedPrefs.getString("blueToothDeviceAdress", "x:x:x:x");
deviceType = mathIntegerFromString(sharedPrefs.getString("deviceType", "0"), 0);
//Ethernet
deviceIP = sharedPrefs.getString("deviceIP", "192.168.0.98");
devicePort = mathIntegerFromString(sharedPrefs.getString("devicePort", "9100"), 9100);
logoProcesed = sharedPrefs.getString("logoProcesed", "");
Log.i(internalClassName, " deviceType=" + String.valueOf(deviceType));
Log.i(internalClassName, " deviceIP=" + String.valueOf(deviceIP));
Log.i(internalClassName, " devicePort=" + String.valueOf(devicePort));
Log.i(internalClassName, " usbDeviceID=" + String.valueOf(usbDeviceID));
Log.i(internalClassName, " blueToothDeviceAdress=" + String.valueOf(blueToothDeviceAdress));
}
public static Integer mathIntegerFromString(String inti, Integer defi) {
//used for preferences
Integer returi = defi;
if (!inti.equals("")) {
try {
returi = Integer.valueOf(inti);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
return returi;
}
public static String prepareDataToPrint(String data) {
//ESC POS Comamnds convertions
data = data.replace("$bold$", "·27·E·1·");
data = data.replace("$unbold$", "·27·E·0·");
data = data.replace("$intro$", "·13··10·");
data = data.replace("$cut$", "·27·m");
data = data.replace("$cutt$", "·27·i");
data = data.replace("$al_left$", "·27·a·0·");
data = data.replace("$al_center$", "·27·a·1·");
data = data.replace("$al_right$", "·27·a·2·");
data = data.replace("$small$", "·27·!·1·");
data = data.replace("$smallh$", "·27·!·17·");
data = data.replace("$smallw$", "·27·!·33·");
data = data.replace("$smallhw$", "·27·!·49·");
data = data.replace("$smallu$", "·27·!·129·");
data = data.replace("$smalluh$", "·27·!·145·");
data = data.replace("$smalluw$", "·27·!·161·");
data = data.replace("$smalluhw$", "·27·!·177·");
data = data.replace("$big$", "·27·!·0·");
data = data.replace("$bigh$", "·27·!·16·");
data = data.replace("$bigw$", "·27·!·32·");
data = data.replace("$bighw$", "·27·!·48·");
data = data.replace("$bigu$", "·27·!·128·");
data = data.replace("$biguh$", "·27·!·144·");
data = data.replace("$biguw$", "·27·!·160·");
data = data.replace("$biguhw$", "·27·!·176·");
data = data.replace("$drawer$", "·27··112··48··200··100·");
data = data.replace("$drawer2$", "·27··112··49··200··100·");
data = data.replace("$enter$", "·13··10·");
data = data.replace("$letrap$", "·27·!·1·");
data = data.replace("$letraph$", "·27·!·17·");
data = data.replace("$letrapw$", "·27·!·33·");
data = data.replace("$letraphw$", "·27·!·49·");
data = data.replace("$letrapu$", "·27·!·129·");
data = data.replace("$letrapuh$", "·27·!·145·");
data = data.replace("$letrapuw$", "·27·!·161·");
data = data.replace("$letrapuhw$", "·27·!·177·");
data = data.replace("$letrag$", "·27·!·0·");
data = data.replace("$letragh$", "·27·!·16·");
data = data.replace("$letragw$", "·27·!·32·");
data = data.replace("$letraghw$", "·27·!·48·");
data = data.replace("$letragu$", "·27·!·128·");
data = data.replace("$letraguh$", "·27·!·144·");
data = data.replace("$letraguw$", "·