1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-08 14:18:08 +02:00

#46 make all strings localizable

This commit is contained in:
cpfeiffer 2015-05-01 01:26:12 +02:00
parent 75b9d0e833
commit 8b3b4d0882
13 changed files with 115 additions and 76 deletions

View File

@ -14,6 +14,7 @@
<application
android:allowBackup="true"
android:name="nodomain.freeyourgadget.gadgetbridge.GBApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GadgetbridgeTheme">

View File

@ -123,9 +123,9 @@ public class BluetoothCommunicationService extends Service {
//Check the system status
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBtAdapter == null) {
Toast.makeText(this, "Bluetooth is not supported.", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.bluetooth_is_not_supported_, Toast.LENGTH_SHORT).show();
} else if (!mBtAdapter.isEnabled()) {
Toast.makeText(this, "Bluetooth is disabled.", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.bluetooth_is_disabled_, Toast.LENGTH_SHORT).show();
} else {
String btDeviceAddress = intent.getStringExtra("device_address");
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -153,7 +153,7 @@ public class BluetoothCommunicationService extends Service {
}
}
} catch (Exception e) {
Toast.makeText(this, "Cannot connect. BT address invalid?", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.cannot_connect_bt_address_invalid_, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
@ -206,7 +206,7 @@ public class BluetoothCommunicationService extends Service {
((PebbleIoThread) mGBDeviceIoThread).installApp(Uri.parse(uriString));
}
} else if (action.equals(ACTION_START)) {
startForeground(GB.NOTIFICATION_ID, GB.createNotification("Gadgetbridge running", this));
startForeground(GB.NOTIFICATION_ID, GB.createNotification(getString(R.string.gadgetbridge_running), this));
mStarted = true;
}

View File

@ -18,11 +18,9 @@ import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
public class ControlCenter extends Activity {
@ -176,9 +174,9 @@ public class ControlCenter extends Activity {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
Toast.makeText(this, "Bluetooth is not supported.", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.bluetooth_is_not_supported_, Toast.LENGTH_SHORT).show();
} else if (!btAdapter.isEnabled()) {
Toast.makeText(this, "Bluetooth is disabled.", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.bluetooth_is_disabled_, Toast.LENGTH_SHORT).show();
} else {
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
for (BluetoothDevice pairedDevice : pairedDevices) {
@ -212,9 +210,9 @@ public class ControlCenter extends Activity {
}
if (connected) {
hintTextView.setText("tap connected device for App Mananger");
hintTextView.setText(R.string.tap_connected_device_for_app_mananger);
} else if (!deviceList.isEmpty()) {
hintTextView.setText("tap a device to connect");
hintTextView.setText(R.string.tap_a_device_to_connect);
}
}
mGBDeviceAdapter.notifyDataSetChanged();

View File

@ -51,7 +51,7 @@ public class DebugActivity extends Activity {
public void onClick(View v) {
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC);
startIntent.putExtra("notification_title", "Gadgetbridge");
startIntent.putExtra("notification_title", R.string.gadgetbridge);
startIntent.putExtra("notification_body", editContent.getText().toString());
startService(startIntent);
}
@ -62,8 +62,8 @@ public class DebugActivity extends Activity {
public void onClick(View v) {
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL);
startIntent.putExtra("notification_sender", "Gadgetbridge");
startIntent.putExtra("notification_subject", "Test");
startIntent.putExtra("notification_sender", R.string.gadgetbridge);
startIntent.putExtra("notification_subject", R.string.test);
startIntent.putExtra("notification_body", editContent.getText().toString());
startService(startIntent);
}
@ -148,9 +148,9 @@ public class DebugActivity extends Activity {
private void testNotification() {
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
ncomp.setContentTitle("Test Notification");
ncomp.setContentText("This is a Test Notification from Gadgetbridge");
ncomp.setTicker("This is a Test Notification from Gadgetbridge");
ncomp.setContentTitle(getString(R.string.test_notification));
ncomp.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
ncomp.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
ncomp.setSmallIcon(R.drawable.ic_notification);
ncomp.setAutoCancel(true);
nManager.notify((int) System.currentTimeMillis(), ncomp.build());

View File

@ -9,7 +9,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
@ -27,7 +26,7 @@ public class GB {
notificationIntent, 0);
return new NotificationCompat.Builder(context)
.setContentTitle("Gadgetbridge")
.setContentTitle(context.getString(R.string.gadgetbridge))
.setTicker(text)
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification)

View File

@ -115,24 +115,23 @@ public class GBDevice implements Parcelable {
String getStateString() {
switch (mState) {
case NOT_CONNECTED:
return "not connected"; // TODO: do not hardcode
return GBApplication.getContext().getString(R.string.not_connected);
case CONNECTING:
return "connecting";
return GBApplication.getContext().getString(R.string.connecting);
case CONNECTED:
return "connected";
return GBApplication.getContext().getString(R.string.connected);
case INITIALIZED:
return "initialized";
return GBApplication.getContext().getString(R.string.initialized);
}
return "unknown state";
return GBApplication.getContext().getString(R.string.unknown_state);
}
public String getInfoString() {
//FIXME: ugly
if (mFirmwareVersion != null) {
if (mHardwareVersion != null) {
return getStateString() + " (HW: " + mHardwareVersion + " FW: " + mFirmwareVersion + ")";
return GBApplication.getContext().getString(R.string.connectionstate_hw_fw, getStateString(), mHardwareVersion, mFirmwareVersion);
}
return getStateString() + " (FW: " + mFirmwareVersion + ")";
return GBApplication.getContext().getString(R.string.connectionstate_fw, getStateString(), mFirmwareVersion);
} else {
return getStateString();
}
@ -194,7 +193,7 @@ public class GBDevice implements Parcelable {
* Returns a string representation of the battery state.
*/
public String getBatteryState() {
return mBatteryState != null ? mBatteryState : "(unknown)";
return mBatteryState != null ? mBatteryState : GBApplication.getContext().getString(R.string._unknown_);
}
public void setBatteryState(String batteryState) {

View File

@ -1,5 +1,10 @@
package nodomain.freeyourgadget.gadgetbridge.adapter;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.R;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@ -8,11 +13,6 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.R;
public class GBDeviceAppAdapter extends ArrayAdapter<GBDeviceApp> {
private final Context context;
@ -39,7 +39,7 @@ public class GBDeviceAppAdapter extends ArrayAdapter<GBDeviceApp> {
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
deviceStatusLabel.setText(deviceApp.getVersion() + " by " + deviceApp.getCreator());
deviceStatusLabel.setText(getContext().getString(R.string.appversion_by_creator, deviceApp.getVersion(), deviceApp.getCreator()));
deviceNameLabel.setText(deviceApp.getName());
switch (deviceApp.getType()) {
case APP_ACTIVITYTRACKER:

View File

@ -1,5 +1,8 @@
package nodomain.freeyourgadget.gadgetbridge.miband;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
public class BatteryInfo extends AbstractInfo {
public BatteryInfo(byte[] data) {
super(data);
@ -12,21 +15,20 @@ public class BatteryInfo extends AbstractInfo {
return 50; // actually unknown
}
// TODO: localization
public String getStatus() {
if (mData.length >= 10) {
int value = mData[9];
switch (value) {
case 1:
return "low";
return GBApplication.getContext().getString(R.string.battery_low);
case 2:
return "medium";
return GBApplication.getContext().getString(R.string.battery_medium);
case 3:
return "full";
return GBApplication.getContext().getString(R.string.battery_full);
case 4:
return "not charging";
return GBApplication.getContext().getString(R.string.battery_not_charging);
}
}
return "(unknown)";
return GBApplication.getContext().getString(R.string._unknown_);
}
}

View File

@ -1,5 +1,8 @@
package nodomain.freeyourgadget.gadgetbridge.miband;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import java.util.Locale;
public class DeviceInfo extends AbstractInfo {
@ -12,6 +15,6 @@ public class DeviceInfo extends AbstractInfo {
int last = 15;
return String.format(Locale.US, "%d.%d.%d.%d", mData[last], mData[last - 1], mData[last - 2], mData[last - 3]);
}
return "(unknown)"; // TODO: localization
return GBApplication.getContext().getString(R.string._unknown_);
}
}

View File

@ -1,5 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.pebble;
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.R;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -14,12 +20,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.R;
public class PebbleAppInstallerActivity extends Activity {
@ -71,10 +71,10 @@ public class PebbleAppInstallerActivity extends Activity {
GBDeviceApp app = mPBWReader.getGBDeviceApp();
if (mPBWReader.isFirmware()) {
debugTextView.setText("YOUR ARE TRYING TO INSTALL A FIRMWARE, PROCEED AT YOUR OWN RISK.\n\n\n This firmware is for HW Revision: " + mPBWReader.getHWRevision());
debugTextView.setText(getString(R.string.firmware_install_warning, mPBWReader.getHWRevision()));
} else if (app != null) {
debugTextView.setText("You are about to install the following app:\n\n\n" + app.getName() + " Version " + app.getVersion() + " by " + app.getCreator() + "\n");
debugTextView.setText(getString(R.string.app_install_info, app.getName(), app.getVersion(), app.getCreator()));
}
installButton.setOnClickListener(new View.OnClickListener() {

View File

@ -1,5 +1,27 @@
package nodomain.freeyourgadget.gadgetbridge.pebble;
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.GB;
import nodomain.freeyourgadget.gadgetbridge.GBCallControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
import nodomain.freeyourgadget.gadgetbridge.GBMusicControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.ZipInputStream;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@ -16,28 +38,6 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.ZipInputStream;
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.GB;
import nodomain.freeyourgadget.gadgetbridge.GBCallControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
import nodomain.freeyourgadget.gadgetbridge.GBMusicControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
public class PebbleIoThread extends GBDeviceIoThread {
private static final String TAG = PebbleIoThread.class.getSimpleName();
private static final int NOTIFICATION_ID = 2;
@ -87,7 +87,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
notificationIntent, 0);
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
.setContentTitle("Gadgetbridge")
.setContentTitle(context.getString(R.string.gadgetbridge))
.setContentText(text)
.setTicker(text)
@ -115,6 +115,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
mBtAdapter = btAdapter;
}
@Override
protected boolean connect(String btDeviceAddress) {
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
ParcelUuid uuids[] = btDevice.getUuids();
@ -138,6 +139,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
return true;
}
@Override
public void run() {
mIsConnected = connect(gbDevice.getAddress());
mQuit = !mIsConnected; // quit if not connected
@ -192,7 +194,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
} while (bytes < 2000);
if (bytes > 0) {
updateInstallNotification("installing binary " + (mCurrentInstallableIndex + 1) + "/" + mPebbleInstallables.length, true, (int) (((float) mBytesWritten / mBinarySize) * 100), getContext());
updateInstallNotification(getContext().getString(
R.string.installing_binary_d_d, (mCurrentInstallableIndex + 1), mPebbleInstallables.length), true, (int) (((float) mBytesWritten / mBinarySize) * 100), getContext());
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
mBytesWritten += bytes;
mAppInstallToken = -1;
@ -323,6 +326,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
gbDevice.sendDeviceUpdateIntent(getContext());
}
@Override
synchronized public void write(byte[] bytes) {
// block writes if app installation in in progress
if (mIsConnected && !mIsInstalling) {
@ -460,9 +464,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
return;
}
if (hadError) {
updateInstallNotification("installation failed!", false, 0, getContext());
updateInstallNotification(getContext().getString(R.string.installation_failed_), false, 0, getContext());
} else {
updateInstallNotification("installation successful", false, 0, getContext());
updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext());
}
mInstallState = PebbleAppInstallState.UNKNOWN;
@ -477,6 +481,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
mInstallSlot = -2;
}
@Override
public void quit() {
mQuit = true;
if (mBtSocket != null) {

View File

@ -1,8 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
public class GBDeviceCommandVersionInfo extends GBDeviceCommand {
public String fwVersion = "N/A";
public String hwVersion = "N/A";
public String fwVersion = GBApplication.getContext().getString(R.string.n_a);
public String hwVersion = GBApplication.getContext().getString(R.string.n_a);
public GBDeviceCommandVersionInfo() {
commandClass = CommandClass.VERSION_INFO;

View File

@ -34,4 +34,33 @@
<string name="pref_header_development">Developer Options</string>
<string name="pref_title_development_miaddr">Miband address</string>
<string name="not_connected">not connected</string>
<string name="connecting">connecting</string>
<string name="connected">connected</string>
<string name="unknown_state">unknown state</string>
<string name="connectionstate_hw_fw">%1$s (HW: %2$s FW: %3$s)</string>
<string name="connectionstate_fw">%1$s (FW: %2$s)</string>
<string name="_unknown_">(unknown)</string>
<string name="gadgetbridge">Gadgetbridge</string>
<string name="test">Test</string>
<string name="test_notification">Test Notification</string>
<string name="this_is_a_test_notification_from_gadgetbridge">This is a Test Notification from Gadgetbridge</string>
<string name="bluetooth_is_not_supported_">Bluetooth is not supported.</string>
<string name="bluetooth_is_disabled_">Bluetooth is disabled.</string>
<string name="tap_connected_device_for_app_mananger">tap connected device for App Mananger</string>
<string name="tap_a_device_to_connect">tap a device to connect</string>
<string name="cannot_connect_bt_address_invalid_">Cannot connect. BT address invalid?</string>
<string name="gadgetbridge_running">Gadgetbridge running</string>
<string name="battery_low">low</string>
<string name="battery_medium">medium</string>
<string name="battery_full">full</string>
<string name="battery_not_charging">not charging</string>
<string name="installing_binary_d_d">installing binary %1$d/%2$d</string>
<string name="installation_failed_">installation failed!</string>
<string name="installation_successful">installation successful</string>
<string name="firmware_install_warning">YOUR ARE TRYING TO INSTALL A FIRMWARE, PROCEED AT YOUR OWN RISK.\n\n\n This firmware is for HW Revision: %s</string>
<string name="app_install_info">You are about to install the following app:\n\n\n%1$s Version %2$s by %3$s\n</string>
<string name="n_a">N/A</string>
<string name="initialized">initialized</string>
<string name="appversion_by_creator">%1$s by %1$s</string>
</resources>