mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Add detection of Android TV devices with a proper icon
KDE app : https://phabricator.kde.org/D12802 Test Plan: Tested with an Android TV device (Nvidia Shield) Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: tfella, nicolasfella, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D12803
This commit is contained in:
BIN
res/drawable-hdpi/ic_device_tv.png
Normal file
BIN
res/drawable-hdpi/ic_device_tv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 327 B |
BIN
res/drawable-mdpi/ic_device_tv.png
Normal file
BIN
res/drawable-mdpi/ic_device_tv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 347 B |
BIN
res/drawable-xhdpi/ic_device_tv.png
Normal file
BIN
res/drawable-xhdpi/ic_device_tv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 439 B |
BIN
res/drawable-xxhdpi/ic_device_tv.png
Normal file
BIN
res/drawable-xxhdpi/ic_device_tv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 433 B |
@@ -209,6 +209,7 @@
|
||||
<string name="plugin_not_supported">This plugin is not supported by the device</string>
|
||||
<string name="findmyphone_title">Find my phone</string>
|
||||
<string name="findmyphone_title_tablet">Find my tablet</string>
|
||||
<string name="findmyphone_title_tv">Find my TV</string>
|
||||
<string name="findmyphone_description">Rings this device so you can find it</string>
|
||||
<string name="findmyphone_found">Found</string>
|
||||
|
||||
|
@@ -103,11 +103,13 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
public enum DeviceType {
|
||||
Phone,
|
||||
Tablet,
|
||||
Computer;
|
||||
Computer,
|
||||
Tv;
|
||||
|
||||
public static DeviceType FromString(String s) {
|
||||
if ("tablet".equals(s)) return Tablet;
|
||||
if ("phone".equals(s)) return Phone;
|
||||
if ("tv".equals(s)) return Tv;
|
||||
return Computer; //Default
|
||||
}
|
||||
|
||||
@@ -117,6 +119,8 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
return "tablet";
|
||||
case Phone:
|
||||
return "phone";
|
||||
case Tv:
|
||||
return "tv";
|
||||
default:
|
||||
return "desktop";
|
||||
}
|
||||
@@ -195,6 +199,9 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
case Tablet:
|
||||
drawableId = R.drawable.ic_device_tablet;
|
||||
break;
|
||||
case Tv:
|
||||
drawableId = R.drawable.ic_device_tv;
|
||||
break;
|
||||
default:
|
||||
drawableId = R.drawable.ic_device_laptop;
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.kdeconnect.Device;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DeviceHelper {
|
||||
@@ -504,12 +506,27 @@ public class DeviceHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTablet() {
|
||||
private static boolean isTablet() {
|
||||
Configuration config = Resources.getSystem().getConfiguration();
|
||||
//This assumes that the values for the screen sizes are consecutive, so XXLARGE > XLARGE > LARGE
|
||||
return ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
|
||||
}
|
||||
|
||||
private static boolean isTv(Context context) {
|
||||
int uiMode = context.getResources().getConfiguration().uiMode;
|
||||
return (uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION;
|
||||
}
|
||||
|
||||
public static Device.DeviceType getDeviceType(Context context) {
|
||||
if (isTv(context)) {
|
||||
return Device.DeviceType.Tv;
|
||||
} else if (isTablet()) {
|
||||
return Device.DeviceType.Tablet;
|
||||
} else {
|
||||
return Device.DeviceType.Phone;
|
||||
}
|
||||
}
|
||||
|
||||
//It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName().
|
||||
public static String getDeviceName(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
@@ -275,7 +275,7 @@ public class NetworkPacket {
|
||||
np.mBody.put("deviceId", deviceId);
|
||||
np.mBody.put("deviceName", DeviceHelper.getDeviceName(context));
|
||||
np.mBody.put("protocolVersion", NetworkPacket.ProtocolVersion);
|
||||
np.mBody.put("deviceType", DeviceHelper.isTablet() ? "tablet" : "phone");
|
||||
np.mBody.put("deviceType", DeviceHelper.getDeviceType(context).toString());
|
||||
np.mBody.put("incomingCapabilities", new JSONArray(PluginFactory.getIncomingCapabilities(context)));
|
||||
np.mBody.put("outgoingCapabilities", new JSONArray(PluginFactory.getOutgoingCapabilities(context)));
|
||||
} catch (Exception e) {
|
||||
|
@@ -22,6 +22,7 @@ package org.kde.kdeconnect.Plugins.FindMyPhonePlugin;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||
import org.kde.kdeconnect.NetworkPacket;
|
||||
import org.kde.kdeconnect.Plugins.Plugin;
|
||||
@@ -33,7 +34,16 @@ public class FindMyPhonePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return DeviceHelper.isTablet() ? context.getString(R.string.findmyphone_title_tablet) : context.getString(R.string.findmyphone_title);
|
||||
switch (DeviceHelper.getDeviceType(context)) {
|
||||
case Tv:
|
||||
return context.getString(R.string.findmyphone_title_tv);
|
||||
case Tablet:
|
||||
return context.getString(R.string.findmyphone_title_tablet);
|
||||
case Phone:
|
||||
return context.getString(R.string.findmyphone_title);
|
||||
default:
|
||||
return context.getString(R.string.findmyphone_title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user