mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +00:00
Implement a "Find my phone" plugin
This makes the phone sound an alarm sound until dismissed. Even when silent. Reviewed-by: Albert Vaca
This commit is contained in:
parent
291abddeba
commit
8aebaaea2f
@ -114,6 +114,13 @@
|
|||||||
-->
|
-->
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhoneActivity"
|
||||||
|
android:label="@string/findmyphone_title"
|
||||||
|
android:theme="@style/Theme.AppCompat"
|
||||||
|
android:launchMode="singleInstance">
|
||||||
|
</activity>
|
||||||
|
|
||||||
<!-- Plugin-related activities and services -->
|
<!-- Plugin-related activities and services -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
26
activity_find_my_phone.xml
Normal file
26
activity_find_my_phone.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
tools:context="org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhoneActivity">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:text="@string/findmyphone_found"
|
||||||
|
android:textSize="50dp"
|
||||||
|
android:id="@+id/bFindMyPhone"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -156,5 +156,7 @@
|
|||||||
<string name="pref_plugin_telepathy">Send SMS</string>
|
<string name="pref_plugin_telepathy">Send SMS</string>
|
||||||
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
|
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
|
||||||
<string name="plugin_not_supported">This plugin is not supported by the device</string>
|
<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_description">Rings this phone so you can find it.</string>
|
||||||
|
<string name="findmyphone_found">Found</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -60,6 +60,7 @@ public class NetworkPackage {
|
|||||||
public final static String PACKAGE_TYPE_MOUSEPAD = "kdeconnect.mousepad";
|
public final static String PACKAGE_TYPE_MOUSEPAD = "kdeconnect.mousepad";
|
||||||
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
|
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
|
||||||
public static final String PACKAGE_TYPE_CAPABILITIES = "kdeconnect.capabilities";
|
public static final String PACKAGE_TYPE_CAPABILITIES = "kdeconnect.capabilities";
|
||||||
|
public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone" ;
|
||||||
|
|
||||||
private long mId;
|
private long mId;
|
||||||
private String mType;
|
private String mType;
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
package org.kde.kdeconnect.Plugins.FindMyPhonePlugin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.media.AudioAttributes;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.Ringtone;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
public class FindMyPhoneActivity extends Activity {
|
||||||
|
Ringtone ringtone;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_find_my_phone);
|
||||||
|
|
||||||
|
Window window = this.getWindow();
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
|
||||||
|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
||||||
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||||
|
|
||||||
|
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||||
|
ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);
|
||||||
|
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||||
|
AudioAttributes.Builder b = new AudioAttributes.Builder();
|
||||||
|
b.setUsage(AudioAttributes.USAGE_ALARM);
|
||||||
|
ringtone.setAudioAttributes(b.build());
|
||||||
|
} else {
|
||||||
|
ringtone.setStreamType(AudioManager.STREAM_ALARM);
|
||||||
|
}
|
||||||
|
|
||||||
|
ringtone.play();
|
||||||
|
|
||||||
|
findViewById(R.id.bFindMyPhone).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
|
ringtone.stop();
|
||||||
|
super.finish();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package org.kde.kdeconnect.Plugins.FindMyPhonePlugin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vineet on 1/11/14.
|
||||||
|
* and David Edmundson 2015
|
||||||
|
*/
|
||||||
|
public class FindMyPhonePlugin extends Plugin {
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return context.getString(R.string.findmyphone_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return context.getString(R.string.findmyphone_description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPackageReceived(NetworkPackage np) {
|
||||||
|
Log.e("FindMyPhonePR", "onPackageReceived");
|
||||||
|
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_FINDMYPHONE)) {
|
||||||
|
//Log.e("PingPackageReceiver", "was a find my phone!");
|
||||||
|
|
||||||
|
Intent intent = new Intent(context,FindMyPhoneActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(intent);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSupportedPackageTypes() {
|
||||||
|
return new String[]{NetworkPackage.PACKAGE_TYPE_FINDMYPHONE};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getOutgoingPackageTypes() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin;
|
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin;
|
||||||
|
import org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhonePlugin;
|
||||||
import org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadPlugin;
|
import org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadPlugin;
|
||||||
import org.kde.kdeconnect.Plugins.SftpPlugin.SftpPlugin;
|
import org.kde.kdeconnect.Plugins.SftpPlugin.SftpPlugin;
|
||||||
import org.kde.kdeconnect.Plugins.ClibpoardPlugin.ClipboardPlugin;
|
import org.kde.kdeconnect.Plugins.ClibpoardPlugin.ClipboardPlugin;
|
||||||
@ -121,6 +122,7 @@ public class PluginFactory {
|
|||||||
PluginFactory.registerPlugin(MousePadPlugin.class);
|
PluginFactory.registerPlugin(MousePadPlugin.class);
|
||||||
PluginFactory.registerPlugin(SharePlugin.class);
|
PluginFactory.registerPlugin(SharePlugin.class);
|
||||||
PluginFactory.registerPlugin(TelepathyPlugin.class);
|
PluginFactory.registerPlugin(TelepathyPlugin.class);
|
||||||
|
PluginFactory.registerPlugin(FindMyPhonePlugin.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginInfo getPluginInfo(Context context, String pluginKey) {
|
public static PluginInfo getPluginInfo(Context context, String pluginKey) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user