Skip to content
Snippets Groups Projects
Commit 6a76371b authored by Adrien Béraud's avatar Adrien Béraud
Browse files

preferences: add start on boot setting

Tuleap: #423
Tuleap: #102
Change-Id: Idfc2bbc19d6b40cd817b907b0bceb4691023694e
parent 4423b10e
No related branches found
No related tags found
No related merge requests found
Showing
with 121 additions and 26 deletions
......@@ -252,7 +252,7 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
break;
case Manifest.permission.READ_CONTACTS:
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
sharedPref.edit().putBoolean(SettingsFragment.KEY_PREF_CONTACTS, grantResults[i] == PackageManager.PERMISSION_GRANTED).apply();
sharedPref.edit().putBoolean(getString(R.string.pref_systemContacts_key), grantResults[i] == PackageManager.PERMISSION_GRANTED).apply();
break;
}
}
......
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package cx.ring.fragments;
import android.Manifest;
......@@ -15,13 +33,16 @@ import cx.ring.service.LocalService;
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener
{
public static final String KEY_PREF_MOBILE = "pref_mobileData";
public static final String KEY_PREF_CONTACTS = "pref_systemContacts";
public static final String KEY_PREF_DIALER = "pref_systemDialer";
private static final String TAG = SettingsFragment.class.getSimpleName();
private String KEY_PREF_CONTACTS = null;
private String KEY_PREF_DIALER = null;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
KEY_PREF_CONTACTS = getString(R.string.pref_systemContacts_key);
KEY_PREF_DIALER = getString(R.string.pref_systemDialer_key);
}
public void onResume() {
......@@ -45,6 +66,11 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
if (val && !LocalService.checkPermission(getActivity(), Manifest.permission.READ_CONTACTS)) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_CONTACTS}, LocalService.PERMISSIONS_REQUEST);
}
} else if (key.equals(KEY_PREF_DIALER)) {
boolean val = sharedPreferences.getBoolean(KEY_PREF_DIALER, false);
if (val && !LocalService.checkPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG)) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_CALL_LOG}, LocalService.PERMISSIONS_REQUEST);
}
}
}
......
......@@ -23,6 +23,7 @@ package cx.ring.loaders;
import java.util.ArrayList;
import cx.ring.R;
import cx.ring.fragments.SettingsFragment;
import cx.ring.model.CallContact;
import cx.ring.model.SipUri;
......@@ -117,7 +118,7 @@ public class ContactsLoader extends AsyncTaskLoader<ContactsLoader.Result>
{
final Result res = new Result();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean canUseContacts = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_CONTACTS, true);
boolean canUseContacts = sharedPreferences.getBoolean(getContext().getString(R.string.pref_systemContacts_key), true);
if (!canUseContacts || !LocalService.checkPermission(getContext(), Manifest.permission.READ_CONTACTS))
return res;
......
package cx.ring.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import cx.ring.R;
import cx.ring.fragments.SettingsFragment;
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = BootReceiver.class.getSimpleName();
public BootReceiver() {
}
@Override
public void onReceive(Context c, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
boolean startOnBoot = sharedPreferences.getBoolean(c.getString(R.string.pref_startOnBoot_key), false);
if (startOnBoot) {
Log.w(TAG, "Starting Ring on boot");
Intent serviceIntent = new Intent(c, LocalService.class);
c.startService(serviceIntent);
}
}
}
}
......@@ -14,8 +14,7 @@
* 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cx.ring.service;
......@@ -326,8 +325,8 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
isMobileConn = ni != null && ni.isConnected();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
canUseContacts = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_CONTACTS, true);
canUseMobile = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_MOBILE, true);
canUseContacts = sharedPreferences.getBoolean(getString(R.string.pref_systemContacts_key), true);
canUseMobile = sharedPreferences.getBoolean(getString(R.string.pref_mobileData_key), false);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
......@@ -395,16 +394,13 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case SettingsFragment.KEY_PREF_CONTACTS:
canUseContacts = sharedPreferences.getBoolean(key, true);
mSystemContactLoader.onContentChanged();
mSystemContactLoader.startLoading();
break;
case SettingsFragment.KEY_PREF_MOBILE:
canUseMobile = sharedPreferences.getBoolean(key, true);
updateConnectivityState();
break;
if (key.equals(getString(R.string.pref_systemContacts_key))) {
canUseContacts = sharedPreferences.getBoolean(key, true);
mSystemContactLoader.onContentChanged();
mSystemContactLoader.startLoading();
} else if (key.equals(getString(R.string.pref_mobileData_key))) {
canUseMobile = sharedPreferences.getBoolean(key, true);
updateConnectivityState();
}
}
......@@ -494,9 +490,12 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
perms.add(p);
}
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
boolean contact_perm = sharedPref.getBoolean(SettingsFragment.KEY_PREF_CONTACTS, true);
boolean contact_perm = sharedPref.getBoolean(c.getString(R.string.pref_systemContacts_key), true);
if (contact_perm && !checkPermission(c, Manifest.permission.READ_CONTACTS))
perms.add(Manifest.permission.READ_CONTACTS);
boolean sys_dialer = sharedPref.getBoolean(c.getString(R.string.pref_systemDialer_key), false);
if (sys_dialer && !checkPermission(c, Manifest.permission.WRITE_CALL_LOG))
perms.add(Manifest.permission.WRITE_CALL_LOG);
return perms.toArray(new String[perms.size()]);
}
......
......@@ -28,6 +28,7 @@ import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import cx.ring.R;
import cx.ring.client.CallActivity;
import cx.ring.fragments.SettingsFragment;
import cx.ring.model.SipUri;
......@@ -46,7 +47,7 @@ public class OutgoingCallHandler extends BroadcastReceiver
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean systemDialer = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_DIALER, false);
boolean systemDialer = sharedPreferences.getBoolean(context.getString(R.string.pref_systemDialer_key), false);
if (systemDialer) {
boolean systemDialerSip = sharedPreferences.getBoolean(KEY_CACHE_HAVE_SIPACCOUNT, false);
boolean systemDialerRing = sharedPreferences.getBoolean(KEY_CACHE_HAVE_RINGACCOUNT, false);
......
ring-android/app/src/main/res/drawable-hdpi/ic_android_black_24dp.png

341 B

ring-android/app/src/main/res/drawable-mdpi/ic_android_black_24dp.png

213 B

ring-android/app/src/main/res/drawable-xhdpi/ic_android_black_24dp.png

343 B

ring-android/app/src/main/res/drawable-xxhdpi/ic_android_black_24dp.png

519 B

ring-android/app/src/main/res/drawable-xxxhdpi/ic_android_black_24dp.png

641 B

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_category_network">Network</string>
<string name="pref_category_contacts">Contacts</string>
<string name="pref_category_system">System</string>
<string name="pref_mobileData_key" translatable="false">pref_mobileData</string>
<string name="pref_mobileData_title">Mobile data</string>
<string name="pref_mobileData_summary">Allow Ring on 3G/LTE networks additionally to Wi-Fi</string>
<string name="pref_category_contacts">Contacts</string>
<string name="pref_systemContacts_key" translatable="false">pref_systemContacts</string>
<string name="pref_systemContacts_title">Use system contacts</string>
<string name="pref_systemContacts_summary">Use system contacts to show caller details.</string>
<string name="pref_systemDialer_key" translatable="false">pref_systemDialer</string>
<string name="pref_systemDialer_title">Place system calls using Ring</string>
<string name="pref_systemDialer_summary">Use Ring to place system calls when possible.</string>
<string name="pref_startOnBoot_key" translatable="false">pref_startOnBoot</string>
<string name="pref_startOnBoot_title">Start Ring on startup</string>
<string name="pref_startOnBoot_summary">Run Ring in the background when the system starts.</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (c) 2016 Savoir-faire Linux Inc.
Author: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
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 3 of the License, or
(at your option) any later version.
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 <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_category_network">
<android.support.v14.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_perm_data_setting_black_24dp"
android:key="pref_mobileData"
android:key="@string/pref_mobileData_key"
android:summary="@string/pref_mobileData_summary"
android:title="@string/pref_mobileData_title" />
</PreferenceCategory>
......@@ -14,17 +31,28 @@
<android.support.v14.preference.SwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_group_black_24dp"
android:key="pref_systemContacts"
android:key="@string/pref_systemContacts_key"
android:summary="@string/pref_systemContacts_summary"
android:title="@string/pref_systemContacts_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_system">
<android.support.v14.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_dialpad_black_24dp"
android:key="pref_systemDialer"
android:key="@string/pref_systemDialer_key"
android:summary="@string/pref_systemDialer_summary"
android:title="@string/pref_systemDialer_title" />
<android.support.v14.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_android_black_24dp"
android:key="@string/pref_startOnBoot_key"
android:summary="@string/pref_startOnBoot_summary"
android:title="@string/pref_startOnBoot_title" />
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment