2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Moved string to xml for i18n

This commit is contained in:
Albert Vaca
2013-09-05 01:33:54 +02:00
parent 950f684a05
commit 093350a175
13 changed files with 126 additions and 56 deletions

View File

@@ -1,12 +1,12 @@
package org.kde.connect;
import android.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
@@ -19,6 +19,7 @@ import org.kde.connect.ComputerLinks.BaseComputerLink;
import org.kde.connect.Plugins.Plugin;
import org.kde.connect.Plugins.PluginFactory;
import org.kde.connect.UserInterface.PairActivity;
import org.kde.kdeconnect.R;
import java.security.KeyFactory;
import java.security.PrivateKey;
@@ -109,7 +110,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
}
public String getName() {
return name != null? name : "unknown device"; //TODO: i18n
return name != null? name : context.getString(R.string.unknown_device);
}
public String getDeviceId() {
@@ -145,16 +146,18 @@ public class Device implements BaseComputerLink.PackageReceiver {
public void requestPairing() {
Resources res = context.getResources();
if (pairStatus == PairStatus.Paired) {
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Device already paired"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(res.getString(R.string.error_already_paired));
return;
}
if (pairStatus == PairStatus.Requested) {
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Pairing already requested"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(res.getString(R.string.error_already_requested));
return;
}
if (!isReachable()) {
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Device not reachable"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(res.getString(R.string.error_not_reachable));
return;
}
@@ -163,7 +166,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
boolean success = sendPackage(np);
if (!success) {
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Could not send package");
for (PairingCallback cb : pairingCallback) cb.pairingFailed(res.getString(R.string.error_could_not_send_package));
return;
}
@@ -171,7 +174,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
pairingTimer.schedule(new TimerTask() {
@Override
public void run() {
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Timed out"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(context.getString(R.string.error_timed_out));
pairStatus = PairStatus.NotPaired;
}
}, 20*1000);
@@ -242,7 +245,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
np.set("pair", false);
sendPackage(np);
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Canceled by the user"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(context.getString(R.string.error_canceled_by_user));
}
@@ -299,7 +302,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
if (pairStatus == PairStatus.Requested) {
pairStatus = PairStatus.NotPaired;
pairingTimer.cancel();
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Canceled by other peer"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(context.getString(R.string.error_canceled_by_other_peer));
}
return;
}
@@ -310,12 +313,11 @@ public class Device implements BaseComputerLink.PackageReceiver {
try {
String publicKeyContent = np.getString("publicKey").replace("-----BEGIN PUBLIC KEY-----\n","").replace("-----END PUBLIC KEY-----\n","");
byte[] publicKeyBytes = Base64.decode(publicKeyContent, 0);
Log.e("asdasd","key bytes: " + publicKeyBytes);
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes));
} catch(Exception e) {
e.printStackTrace();
Log.e("Device","Pairing exception: Received incorrect key");
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Incorrect key received"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(context.getString(R.string.error_invalid_key));
return;
}
@@ -349,12 +351,14 @@ public class Device implements BaseComputerLink.PackageReceiver {
intent.putExtra("deviceId", deviceId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Resources res = context.getResources();
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle("Pairing request from" + getName()) //TODO: i18n
.setContentText("Tap to answer") //TODO: i18n
.setContentTitle(res.getString(R.string.pairing_request_from, getName()))
.setContentText(res.getString(R.string.tap_to_answer))
.setContentIntent(pendingIntent)
.setTicker("Pair requested") //TODO: i18n
.setSmallIcon(R.drawable.ic_menu_help)
.setTicker(res.getString(R.string.pair_requested))
.setSmallIcon(android.R.drawable.ic_menu_help)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.build();
@@ -382,7 +386,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
if (pairStatus == PairStatus.Requested) {
pairingTimer.cancel();
for (PairingCallback cb : pairingCallback) cb.pairingFailed("Canceled by other peer"); //TODO: i18n
for (PairingCallback cb : pairingCallback) cb.pairingFailed(context.getString(R.string.error_canceled_by_other_peer));
} else if (pairStatus == PairStatus.Paired) {
SharedPreferences preferences = context.getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
preferences.edit().remove(deviceId).commit();

View File

@@ -106,8 +106,8 @@ public class ClipboardPlugin extends Plugin {
@Override
public AlertDialog getErrorDialog(Context baseContext) {
return new AlertDialog.Builder(baseContext)
.setTitle("ClipBoard Plugin")
.setMessage("This plugin is not compatible with Android 4.3")
.setTitle(R.string.pref_plugin_clipboard)
.setMessage(R.string.plugin_not_available)
.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

View File

@@ -203,7 +203,7 @@ public class MprisPlugin extends Plugin {
@Override
public Button getInterfaceButton(final Activity activity) {
Button b = new Button(activity);
b.setText("Open remote control"); //TODO: i18n
b.setText(R.string.open_mpris_controls);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@@ -281,9 +281,9 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
if (Build.VERSION.SDK_INT < 18) {
return new AlertDialog.Builder(baseContext)
.setTitle("Notifications Plugin") //TODO: i18n
.setMessage("This plugin is not compatible with Android prior 4.3") //TODO: i18n
.setPositiveButton("Ok",new DialogInterface.OnClickListener() { //TODO: i18n
.setTitle(R.string.pref_plugin_notifications)
.setMessage(R.string.plugin_not_available)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
@@ -292,18 +292,18 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
.create();
} else {
return new AlertDialog.Builder(baseContext)
.setTitle("Notifications Plugin") //TODO: i18n
.setMessage("You need to grant permission to access notifications") //TODO: i18n
.setPositiveButton("Open settings",new DialogInterface.OnClickListener() {
.setTitle(R.string.pref_plugin_notifications)
.setMessage(R.string.no_permissions)
.setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) { //TODO: i18n
Intent intent=new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
baseContext.startActivity(intent);
}
})
.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) { //TODO: i18n
public void onClick(DialogInterface dialogInterface, int i) {
//Do nothing
}
})

View File

@@ -28,17 +28,17 @@ public class PingPlugin extends Plugin {
@Override
public String getDisplayName() {
return context.getResources().getString(org.kde.kdeconnect.R.string.pref_plugin_ping);
return context.getResources().getString(R.string.pref_plugin_ping);
}
@Override
public String getDescription() {
return context.getResources().getString(org.kde.kdeconnect.R.string.pref_plugin_ping_desc);
return context.getResources().getString(R.string.pref_plugin_ping_desc);
}
@Override
public Drawable getIcon() {
return context.getResources().getDrawable(org.kde.kdeconnect.R.drawable.icon);
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
@@ -67,7 +67,7 @@ public class PingPlugin extends Plugin {
.setContentTitle(device.getName())
.setContentText("Ping!")
.setTicker("Ping!")
.setSmallIcon(R.drawable.ic_dialog_alert)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.build();
@@ -88,7 +88,7 @@ public class PingPlugin extends Plugin {
@Override
public Button getInterfaceButton(Activity activity) {
Button b = new Button(activity);
b.setText("Send ping"); //TODO: i18n
b.setText(R.string.send_ping);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@@ -52,7 +52,7 @@ public class DeviceActivity extends ActionBarActivity {
if (!failedPlugins.isEmpty() && errorList.getHeaderViewsCount() == 0) {
TextView header = new TextView(DeviceActivity.this);
header.setPadding(0,24,0,0);
header.setText("Plugins failed to load (tap for more info):"); //TODO: i18n
header.setText(getResources().getString(R.string.plugins_failed_to_load));
errorList.addHeaderView(header);
}
errorList.setAdapter(new ArrayAdapter<String>(DeviceActivity.this, android.R.layout.simple_list_item_1, names));
@@ -123,8 +123,7 @@ public class DeviceActivity extends ActionBarActivity {
super.onPrepareOptionsMenu(menu);
menu.clear();
if (device.isPaired()) {
//TODO: i18n
menu.add("Select plugins").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
menu.add(R.string.device_menu_plugins).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Intent intent = new Intent(DeviceActivity.this, SettingsActivity.class);
@@ -133,8 +132,7 @@ public class DeviceActivity extends ActionBarActivity {
return true;
}
});
//TODO: i18n
menu.add("Unpair").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
menu.add(R.string.device_menu_unpair).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
device.unpair();

View File

@@ -98,7 +98,9 @@ public class MainActivity extends ActionBarActivity {
SectionItem section;
section = new SectionItem("Connected devices"); //TODO: i18n
Resources res = getResources();
section = new SectionItem(res.getString(R.string.category_connected_devices));
section.isEmpty = true;
items.add(section);
for(Device d : devices) {
@@ -108,7 +110,7 @@ public class MainActivity extends ActionBarActivity {
}
}
section = new SectionItem("Not paired devices"); //TODO: i18n
section = new SectionItem(res.getString(R.string.category_not_paired_devices));
section.isEmpty = true;
items.add(section);
for(Device d : devices) {
@@ -118,7 +120,7 @@ public class MainActivity extends ActionBarActivity {
}
}
section = new SectionItem("Remembered devices"); //TODO: i18n
section = new SectionItem(res.getString(R.string.category_remembered_devices));
section.isEmpty = true;
items.add(section);
for(Device d : devices) {
@@ -128,7 +130,7 @@ public class MainActivity extends ActionBarActivity {
}
}
if (section.isEmpty) {
items.remove(items.size()-1); //Remove this section
items.remove(items.size()-1); //Remove section
}
runOnUiThread(new Runnable() {

View File

@@ -25,7 +25,7 @@ public class PairActivity extends ActionBarActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
((TextView) findViewById(R.id.pair_message)).setText("Pairing requested"); //TODO: i18n
((TextView) findViewById(R.id.pair_message)).setText(R.string.pair_requested);
findViewById(R.id.pair_progress).setVisibility(View.GONE);
findViewById(R.id.pair_button).setVisibility(View.GONE);
findViewById(R.id.pair_request).setVisibility(View.VISIBLE);

View File

@@ -16,7 +16,6 @@
android:layout_weight="1"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"

View File

@@ -20,11 +20,17 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Device not paired"
android:text="@string/device_not_paired"
android:id="@+id/pair_message"
android:layout_gravity="left|center_vertical" />
android:layout_gravity="left|center_vertical"
/>
<Button android:id="@+id/pair_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Request pairing"/>
<Button
android:id="@+id/pair_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/request_pairing"
/>
<LinearLayout
android:layout_width="match_parent"
@@ -33,9 +39,19 @@
android:id="@+id/pair_request"
android:layout_gravity="center">
<Button android:id="@+id/accept_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Accept"
android:layout_weight="1" />
<Button android:id="@+id/reject_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Reject"
<Button
android:id="@+id/accept_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/pairing_accept"
android:layout_weight="1"
/>
<Button
android:id="@+id/reject_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/pairing_reject"
android:layout_weight="1" />
</LinearLayout>

View File

@@ -2,9 +2,31 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="12px"
android:paddingBottom="12px"
android:paddingTop="12dip"
android:paddingBottom="12dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_marginLeft="6px" android:layout_marginRight="8px" android:layout_height="wrap_content" android:maxHeight="32px" android:minHeight="32px" android:maxWidth="32px" android:minWidth="32px" android:src="@drawable/icon" android:layout_width="wrap_content" android:id="@+id/img" android:layout_gravity="center_vertical"></ImageView>
<TextView android:gravity="left" android:id="@+id/txt" android:layout_width="wrap_content" android:textSize="8pt" android:textColor="#000000" android:layout_height="wrap_content" android:layout_gravity="center_vertical" ></TextView>
<ImageView
android:layout_marginLeft="6dip"
android:layout_marginRight="8dip"
android:layout_height="wrap_content"
android:maxHeight="32dip"
android:minHeight="32dip"
android:maxWidth="32dip"
android:minWidth="32dip"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:id="@+id/img"
android:layout_gravity="center_vertical"
/>
<TextView
android:gravity="left"
android:id="@+id/txt"
android:layout_width="wrap_content"
android:textSize="8pt"
android:textColor="#000000"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
</LinearLayout>

View File

@@ -6,7 +6,7 @@
android:icon="@drawable/navigation_refresh"
android:orderInCategory="200"
kdeconnect:showAsAction="always"
android:title="Reconnect"
android:title="@string/reconnect"
/>
<item

View File

@@ -16,5 +16,34 @@
<string name="pref_plugin_notifications_desc">Access your notifications from other devices</string>
<string name="plugin_not_available">This feature is not available in your Android version</string>
<string name="device_list_empty">No devices</string>
<string name="ok">Ok</string>
<string name="cancel">Cancel</string>
<string name="open_settings">Open settings</string>
<string name="no_permissions">You need to grant permission to access notifications</string>
<string name="send_ping">Send ping</string>
<string name="open_mpris_controls">Open remote control</string>
<string name="category_connected_devices">Connected devices</string>
<string name="category_not_paired_devices">Not paired devices</string>
<string name="category_remembered_devices">Remembered devices</string>
<string name="plugins_failed_to_load">Plugins failed to load (tap for more info):</string>
<string name="device_menu_plugins">Select plugins</string>
<string name="device_menu_unpair">Unpair</string>
<string name="unknown_device">Unknown device</string>
<string name="error_not_reachable">Device not reachable</string>
<string name="error_already_requested">Pairing already requested</string>
<string name="error_already_paired">Device already paired</string>
<string name="error_could_not_send_package">Could not send package</string>
<string name="error_timed_out">Timed out</string>
<string name="error_canceled_by_user">Canceled by user</string>
<string name="error_canceled_by_other_peer">Canceled by other peer</string>
<string name="error_invalid_key">Invalid key received</string>
<string name="pair_requested">Pair requested</string>
<string name="pairing_request_from">Pairing request from %1s</string>
<string name="tap_to_answer">Tap to answer</string>
<string name="reconnect">Reconnect</string>
<string name="device_not_paired">Device not paired</string>
<string name="request_pairing">Request pairing</string>
<string name="pairing_accept">Accept</string>
<string name="pairing_reject">Reject</string>
</resources>