// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java
// public class SharedPreferencesKeys {
// 
//     public final static String SP_FIRST_CALL = "first_call";
// 
//     public final static String SP_KEY_IP = "save_clementine_ip";
// 
//     public final static String SP_KEY_AC = "pref_autoconnect";
// 
//     public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey";
// 
//     public final static String SP_KEY_PORT = "pref_port";
// 
//     public final static String SP_LAST_AUTH_CODE = "last_auth_code";
// 
//     public final static String SP_SHOW_TRACKNO = "pref_show_trackno";
// 
//     public final static String SP_LASTFM = "pref_show_lastfm";
// 
//     public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on";
// 
//     public final static String SP_WAKE_LOCK = "pref_wake_lock";
// 
//     public final static String SP_LOWER_VOLUME = "pref_lower_volume";
// 
//     public final static String SP_CALL_VOLUME = "pref_call_volume";
// 
//     public final static String SP_VOLUME_INC = "pref_volume_inc";
// 
//     public final static String SP_LIBRARY_GROUPING = "pref_library_grouping";
// 
//     public final static String SP_LIBRARY_SORTING = "pref_library_sorting";
// 
//     public final static String SP_WIFI_ONLY = "pref_dl_wifi_only";
// 
//     public final static String SP_DOWNLOAD_DIR = "pref_dl_dir";
// 
//     public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override";
// 
//     public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir";
// 
//     public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir";
// 
//     public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir";
// 
//     public final static String SP_LAST_STACKTRACE = "last_stacktrace";
// 
//     public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace";
// 
//     public final static String SP_LIBRARY_IP = "library_ip";
// 
//     public final static String SP_KNOWN_IP = "known_ips";
// }


import de.qspool.clementineremote.backend.Clementine;
import de.qspool.clementineremote.backend.pb.ClementineMessage;
import de.qspool.clementineremote.backend.pb.ClementineMessageFactory;
import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;
import de.qspool.clementineremote.App;
import de.qspool.clementineremote.SharedPreferencesKeys;
/* This file is part of the Android Clementine Remote.
 * Copyright (C) 2013, Andreas Muttscheller <asfa194@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 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 de.qspool.clementineremote.backend.receivers;



public class ClementinePhoneStateCheck extends BroadcastReceiver {

    private static String lastPhoneState = TelephonyManager.EXTRA_STATE_IDLE;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (App.getApp() == null
                || App.ClementineConnection == null
                || App.Clementine == null
                || !App.ClementineConnection.isConnected()) {
            return;
        }

        if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) {
            return;
        }

        if (ContextCompat.checkSelfPermission(context,
                Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            return;
        }

        // Check if we need to change the volume
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
        String volumeString = prefs
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java
// public class SharedPreferencesKeys {
// 
//     public final static String SP_FIRST_CALL = "first_call";
// 
//     public final static String SP_KEY_IP = "save_clementine_ip";
// 
//     public final static String SP_KEY_AC = "pref_autoconnect";
// 
//     public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey";
// 
//     public final static String SP_KEY_PORT = "pref_port";
// 
//     public final static String SP_LAST_AUTH_CODE = "last_auth_code";
// 
//     public final static String SP_SHOW_TRACKNO = "pref_show_trackno";
// 
//     public final static String SP_LASTFM = "pref_show_lastfm";
// 
//     public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on";
// 
//     public final static String SP_WAKE_LOCK = "pref_wake_lock";
// 
//     public final static String SP_LOWER_VOLUME = "pref_lower_volume";
// 
//     public final static String SP_CALL_VOLUME = "pref_call_volume";
// 
//     public final static String SP_VOLUME_INC = "pref_volume_inc";
// 
//     public final static String SP_LIBRARY_GROUPING = "pref_library_grouping";
// 
//     public final static String SP_LIBRARY_SORTING = "pref_library_sorting";
// 
//     public final static String SP_WIFI_ONLY = "pref_dl_wifi_only";
// 
//     public final static String SP_DOWNLOAD_DIR = "pref_dl_dir";
// 
//     public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override";
// 
//     public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir";
// 
//     public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir";
// 
//     public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir";
// 
//     public final static String SP_LAST_STACKTRACE = "last_stacktrace";
// 
//     public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace";
// 
//     public final static String SP_LIBRARY_IP = "library_ip";
// 
//     public final static String SP_KNOWN_IP = "known_ips";
// }


// Path: app/src/main/java/de/qspool/clementineremote/backend/receivers/ClementinePhoneStateCheck.java
import de.qspool.clementineremote.backend.Clementine;
import de.qspool.clementineremote.backend.pb.ClementineMessage;
import de.qspool.clementineremote.backend.pb.ClementineMessageFactory;
import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;
import de.qspool.clementineremote.App;
import de.qspool.clementineremote.SharedPreferencesKeys;

/* This file is part of the Android Clementine Remote.
 * Copyright (C) 2013, Andreas Muttscheller <asfa194@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 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 de.qspool.clementineremote.backend.receivers;



public class ClementinePhoneStateCheck extends BroadcastReceiver {

    private static String lastPhoneState = TelephonyManager.EXTRA_STATE_IDLE;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (App.getApp() == null
                || App.ClementineConnection == null
                || App.Clementine == null
                || !App.ClementineConnection.isConnected()) {
            return;
        }

        if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) {
            return;
        }

        if (ContextCompat.checkSelfPermission(context,
                Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            return;
        }

        // Check if we need to change the volume
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
        String volumeString = prefs
                .getString(SharedPreferencesKeys.SP_CALL_VOLUME,