From 4d5d7449200a240ebc05aa71a60e7f53f03bde7b Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Thu, 22 Feb 2018 00:50:11 +0100 Subject: [PATCH] Allow choosing a ringtone for FindMyPhone Summary: BUG: 379023 Let users choose a ring tone in the settings. Test Plan: Open settings, choose a ringtone, search for device. Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: mtijink, andyholmes, albertvaka, apol, #kde_connect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D10332 --- res/values/strings.xml | 1 + res/xml/findmyphoneplugin_preferences.xml | 10 ++++++ .../FindMyPhoneActivity.java | 29 +++++++++++++--- .../FindMyPhonePlugin/FindMyPhonePlugin.java | 34 +++++++++++++++---- 4 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 res/xml/findmyphoneplugin_preferences.xml diff --git a/res/values/strings.xml b/res/values/strings.xml index 100bce6e..0e1faa49 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -216,5 +216,6 @@ To read and write SMS from your desktop you need to give permission to SMS To see phone calls and SMS from the desktop you need to give permission to phone calls and SMS To see a contact name instead of a phone number you need to give access to the phone\'s contacts + Select a ringtone diff --git a/res/xml/findmyphoneplugin_preferences.xml b/res/xml/findmyphoneplugin_preferences.xml new file mode 100644 index 00000000..2a040c6e --- /dev/null +++ b/res/xml/findmyphoneplugin_preferences.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java index 3d1c7fcc..8383d1d1 100644 --- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java +++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java @@ -1,13 +1,34 @@ +/* Copyright 2018 Nicolas Fella + * Copyright 2015 David Edmundson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ package org.kde.kdeconnect.Plugins.FindMyPhonePlugin; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.view.Window; @@ -61,13 +82,11 @@ public class FindMyPhoneActivity extends Activity { previousVolume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0); - Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); - if (alert == null) { - alert = RingtoneManager.getValidRingtoneUri(getApplicationContext()); - } + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + String ringtone = prefs.getString("select_ringtone", ""); mediaPlayer = new MediaPlayer(); - mediaPlayer.setDataSource(this, alert); + mediaPlayer.setDataSource(this, Uri.parse(ringtone)); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(true); mediaPlayer.prepare(); diff --git a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java index 0ea140c8..e88cae73 100644 --- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhonePlugin.java @@ -1,3 +1,23 @@ +/* + * Copyright 2015 David Edmundson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + package org.kde.kdeconnect.Plugins.FindMyPhonePlugin; import android.content.Intent; @@ -7,14 +27,8 @@ 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 { - public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone"; public final static String PACKAGE_TYPE_FINDMYPHONE_REQUEST = "kdeconnect.findmyphone.request"; @Override @@ -30,7 +44,7 @@ public class FindMyPhonePlugin extends Plugin { @Override public boolean onPackageReceived(NetworkPackage np) { - Intent intent = new Intent(context,FindMyPhoneActivity.class); + Intent intent = new Intent(context, FindMyPhoneActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; @@ -46,4 +60,10 @@ public class FindMyPhonePlugin extends Plugin { public String[] getOutgoingPackageTypes() { return new String[0]; } + + @Override + public boolean hasSettings() { + return true; + } + }