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