/*
* *************************************************************************
* Developer.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* 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) 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.gui.preferences;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.DebugLogActivity;
import org.videolan.vlc.util.VLCInstance;
public class Developer extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected int getXml() {
return R.xml.preferences_dev;
}
@Override
protected int getTitleId() {
return R.string.developer_prefs_category;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findPreference("debug_logs").setVisible(BuildConfig.DEBUG && (AndroidUtil.isJellyBeanMR1OrLater() ||
getActivity().checkCallingOrSelfPermission(Manifest.permission.READ_LOGS) == PackageManager.PERMISSION_GRANTED));
}
@Override
public void onStart() {
super.onStart();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onStop() {
super.onStop();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
switch (preference.getKey()){
case "debug_logs":
Intent intent = new Intent(VLCApplication.getAppContext(), DebugLogActivity.class);
startActivity(intent);
return true;
}
return super.onPreferenceTreeClick(preference);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key){
case "dev_hardware_decoder":
case "enable_verbose_mode":
VLCInstance.restart(getActivity());
((PreferencesActivity)getActivity()).restartMediaPlayer();
}
}
}