2014-11-16 23:14:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Albert Vaca Cintora <albertvaka@gmail.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 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-09-05 01:37:59 +02:00
|
|
|
package org.kde.kdeconnect.UserInterface;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.CheckBoxPreference;
|
|
|
|
import android.preference.Preference;
|
2014-09-16 15:45:31 +02:00
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceScreen;
|
2013-09-03 17:58:59 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
2013-09-05 01:37:59 +02:00
|
|
|
import org.kde.kdeconnect.BackgroundService;
|
|
|
|
import org.kde.kdeconnect.Device;
|
2015-01-10 00:31:07 -08:00
|
|
|
import org.kde.kdeconnect.Plugins.Plugin;
|
2013-09-05 01:37:59 +02:00
|
|
|
import org.kde.kdeconnect.Plugins.PluginFactory;
|
2014-09-16 15:45:31 +02:00
|
|
|
import org.kde.kdeconnect_tp.R;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2014-09-16 15:45:31 +02:00
|
|
|
public class SettingsActivity extends PreferenceActivity {
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2014-10-20 01:13:41 -07:00
|
|
|
static private String deviceId; //Static because if we get here by using the back button in the action bar, the extra deviceId will not be set.
|
|
|
|
|
2013-09-03 17:58:59 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2014-09-16 15:45:31 +02:00
|
|
|
final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(this);
|
|
|
|
setPreferenceScreen(preferenceScreen);
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2014-10-20 01:13:41 -07:00
|
|
|
if (getIntent().hasExtra("deviceId")) {
|
|
|
|
deviceId = getIntent().getStringExtra("deviceId");
|
|
|
|
}
|
|
|
|
|
2013-09-03 17:58:59 +02:00
|
|
|
BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
|
|
|
|
|
|
|
final Device device = service.getDevice(deviceId);
|
|
|
|
Set<String> plugins = PluginFactory.getAvailablePlugins();
|
|
|
|
|
|
|
|
final ArrayList<Preference> preferences = new ArrayList<Preference>();
|
|
|
|
for (final String pluginName : plugins) {
|
2014-09-16 15:45:31 +02:00
|
|
|
final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext());
|
|
|
|
|
2013-09-03 17:58:59 +02:00
|
|
|
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName);
|
|
|
|
pref.setKey(pluginName);
|
|
|
|
pref.setTitle(info.getDisplayName());
|
|
|
|
pref.setSummary(info.getDescription());
|
|
|
|
pref.setChecked(device.isPluginEnabled(pluginName));
|
|
|
|
preferences.add(pref);
|
2014-09-16 15:45:31 +02:00
|
|
|
preferenceScreen.addPreference(pref);
|
|
|
|
|
|
|
|
if (info.hasSettings()) {
|
|
|
|
final Preference pluginPreference = new Preference(getBaseContext());
|
2015-01-10 00:31:07 -08:00
|
|
|
pluginPreference.setKey(pluginName + "_preferences");
|
2014-11-09 15:24:12 -08:00
|
|
|
pluginPreference.setSummary(getString(R.string.plugin_settings_with_name, info.getDisplayName()));
|
2014-09-16 15:45:31 +02:00
|
|
|
preferences.add(pluginPreference);
|
|
|
|
preferenceScreen.addPreference(pluginPreference);
|
|
|
|
pluginPreference.setDependency(pref.getKey());
|
|
|
|
}
|
2013-09-03 17:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2014-09-25 16:05:28 +02:00
|
|
|
Preference pref = preferences.get(i);
|
2015-01-10 00:31:07 -08:00
|
|
|
if (pref.getDependency() == null) { //Is a check to enable/disable a plugin
|
2014-09-25 16:05:28 +02:00
|
|
|
CheckBoxPreference check = (CheckBoxPreference)pref;
|
2014-09-16 15:45:31 +02:00
|
|
|
boolean enabled = device.isPluginEnabled(pref.getKey());
|
|
|
|
device.setPluginEnabled(pref.getKey(), !enabled);
|
2014-09-25 16:05:28 +02:00
|
|
|
check.setChecked(!enabled);
|
|
|
|
} else { //Is a plugin suboption
|
|
|
|
if (pref.isEnabled()) {
|
2015-01-10 00:31:07 -08:00
|
|
|
String pluginName = pref.getDependency(); //The parent pref will be named like the plugin
|
|
|
|
Plugin plugin = device.getPlugin(pluginName, true);
|
|
|
|
plugin.startPreferencesActivity(SettingsActivity.this);
|
2014-09-25 16:05:28 +02:00
|
|
|
}
|
2014-09-16 15:45:31 +02:00
|
|
|
}
|
2013-09-03 17:58:59 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2014-11-16 23:14:06 -08:00
|
|
|
}
|