Moved strings to res
This commit is contained in:
@@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
TextView lblPrinterName;
|
TextView lblPrinterName;
|
||||||
EditText textBox;
|
EditText textBox;
|
||||||
|
|
||||||
|
Button btnFind;
|
||||||
Button btnConnect;
|
Button btnConnect;
|
||||||
Button btnDisconnect;
|
Button btnDisconnect;
|
||||||
Button btnPrint;
|
Button btnPrint;
|
||||||
@@ -59,8 +60,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
// Create object of controls
|
// Create object of controls
|
||||||
Button btnFind = findViewById(R.id.btnFind);
|
btnFind = findViewById(R.id.btnFind);
|
||||||
|
|
||||||
btnConnect = findViewById(R.id.btnConnect);
|
btnConnect = findViewById(R.id.btnConnect);
|
||||||
btnDisconnect = findViewById(R.id.btnDisconnect);
|
btnDisconnect = findViewById(R.id.btnDisconnect);
|
||||||
btnPrint = findViewById(R.id.btnPrint);
|
btnPrint = findViewById(R.id.btnPrint);
|
||||||
@@ -137,6 +137,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setButtonsDisconnect() {
|
void setButtonsDisconnect() {
|
||||||
|
btnFind.setEnabled(true);
|
||||||
btnConnect.setEnabled(true);
|
btnConnect.setEnabled(true);
|
||||||
btnDisconnect.setEnabled(false);
|
btnDisconnect.setEnabled(false);
|
||||||
btnPrint.setEnabled(false);
|
btnPrint.setEnabled(false);
|
||||||
@@ -145,6 +146,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setButtonsConnect() {
|
void setButtonsConnect() {
|
||||||
|
btnFind.setEnabled(false);
|
||||||
btnConnect.setEnabled(false);
|
btnConnect.setEnabled(false);
|
||||||
btnDisconnect.setEnabled(true);
|
btnDisconnect.setEnabled(true);
|
||||||
btnPrint.setEnabled(true);
|
btnPrint.setEnabled(true);
|
||||||
@@ -158,13 +160,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
if (bluetoothAdapter == null) {
|
if (bluetoothAdapter == null) {
|
||||||
Log.w(TAG, "Bluetooth adapter not found");
|
Log.w(TAG, "Bluetooth adapter not found");
|
||||||
lblStatus.setText("No Bluetooth Adapter found");
|
lblStatus.setText(getResources().getText(R.string.stateNoBTAdapter));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bluetoothAdapter.isEnabled()) {
|
if (!bluetoothAdapter.isEnabled()) {
|
||||||
Log.w(TAG, "Bluetooth adapter not enabled.");
|
Log.w(TAG, "Bluetooth adapter not enabled.");
|
||||||
lblStatus.setText("Bluetooth is disabled");
|
lblStatus.setText(getResources().getText(R.string.stateBTDisabled));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +177,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (pairedDevices.size() == 0) {
|
if (pairedDevices.size() == 0) {
|
||||||
Log.d(TAG, "No paired bluetooth devices");
|
Log.d(TAG, "No paired bluetooth devices");
|
||||||
|
lblStatus.setText(getResources().getText(R.string.stateBTnoPaired));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +214,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void openBluetoothPrinter() {
|
void openBluetoothPrinter() {
|
||||||
lblStatus.setText("Connecting...");
|
lblStatus.setText(getResources().getText(R.string.stateConnecting));
|
||||||
|
btnConnect.setEnabled(false);
|
||||||
|
|
||||||
// Open Bluetooth Printer
|
// Open Bluetooth Printer
|
||||||
thread = new Thread(new Runnable() {
|
thread = new Thread(new Runnable() {
|
||||||
@@ -229,7 +233,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
refresh.post(new Runnable() {
|
refresh.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lblStatus.setText("Connected to bluetooth");
|
lblStatus.setText(getResources().getText(R.string.statePrinterConnected));
|
||||||
setButtonsConnect();
|
setButtonsConnect();
|
||||||
beginListenData();
|
beginListenData();
|
||||||
}
|
}
|
||||||
@@ -239,7 +243,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
refresh.post(new Runnable() {
|
refresh.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lblStatus.setText("Error while connecting");
|
lblStatus.setText(getResources().getText(R.string.stateConnError));
|
||||||
|
btnConnect.setEnabled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -312,7 +317,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
outputStream.close();
|
outputStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
bluetoothSocket.close();
|
bluetoothSocket.close();
|
||||||
lblStatus.setText("Printer Disconnected.");
|
lblStatus.setText(getResources().getText(R.string.statePrinterDisconnected));
|
||||||
setButtonsDisconnect();
|
setButtonsDisconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -325,17 +330,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
String msg = textBox.getText().toString();
|
String msg = textBox.getText().toString();
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
outputStream.write(msg.getBytes());
|
outputStream.write(msg.getBytes());
|
||||||
lblStatus.setText("Printing Text...");
|
lblStatus.setText(getResources().getText(R.string.statePrinterPrintText));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
setButtonsDisconnect();
|
setButtonsDisconnect();
|
||||||
lblStatus.setText("Error communication...");
|
lblStatus.setText(getResources().getText(R.string.stateCommError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printCharsetTable() {
|
void printCharsetTable() {
|
||||||
try {
|
try {
|
||||||
lblStatus.setText("Printing table...");
|
lblStatus.setText(getResources().getText(R.string.statePrinterPrintTable));
|
||||||
|
|
||||||
byte[] array = new byte[237];
|
byte[] array = new byte[237];
|
||||||
int index=0;
|
int index=0;
|
||||||
@@ -348,13 +353,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
setButtonsDisconnect();
|
setButtonsDisconnect();
|
||||||
lblStatus.setText("Error communication...");
|
lblStatus.setText(getResources().getText(R.string.stateCommError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCharset() {
|
void setCharset() {
|
||||||
try {
|
try {
|
||||||
lblStatus.setText("Setting codepage");
|
lblStatus.setText(getResources().getText(R.string.statePrinterSetCodepage));
|
||||||
|
|
||||||
outputStream.write(setCharsetCode);
|
outputStream.write(setCharsetCode);
|
||||||
outputStream.write((byte)0x12);
|
outputStream.write((byte)0x12);
|
||||||
@@ -362,7 +367,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
setButtonsDisconnect();
|
setButtonsDisconnect();
|
||||||
lblStatus.setText("Error communication...");
|
lblStatus.setText(getResources().getText(R.string.stateConnError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,19 @@
|
|||||||
|
|
||||||
<string name="lblStatus">Idle</string>
|
<string name="lblStatus">Idle</string>
|
||||||
<string name="lblPrinterName">Not selected</string>
|
<string name="lblPrinterName">Not selected</string>
|
||||||
|
|
||||||
|
<string name="statePrinterConnected">Printer connected</string>
|
||||||
|
<string name="statePrinterDisconnected">Printer disconnected</string>
|
||||||
|
<string name="statePrinterPrintText">Printing text</string>
|
||||||
|
<string name="statePrinterPrintTable">Printing character table</string>
|
||||||
|
<string name="statePrinterSetCodepage">Setting codepage</string>
|
||||||
|
|
||||||
|
|
||||||
|
<string name="stateConnecting">Connecting...</string>
|
||||||
|
<string name="stateConnError">Connection error</string>
|
||||||
|
<string name="stateCommError">Comunication error</string>
|
||||||
|
|
||||||
|
<string name="stateNoBTAdapter">No bluetooth adapter found</string>
|
||||||
|
<string name="stateBTDisabled">Bluetooth is disabled</string>
|
||||||
|
<string name="stateBTnoPaired">No paired Bluetooth devices</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user