Exemplo n.º 1
0
        /// <summary>
        /// Unregisters a change event callback for given key.
        /// </summary>
        /// <param name="key">The runtime information key which wants to unregister callback.</param>
        /// <param name="callback">The callback function to unsubscribe.</param>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
        internal static void UnsetCallback(RuntimeInfoKey key, EventHandler <RuntimeFeatureStatusChangedEventArgs> callback)
        {
            RuntimeInfoEventHandler handler = null;

            FindEventHandler(key, ref handler);
            if (handler == null)
            {
                Log.Error(InformationErrorFactory.LogTag, "Invalid key");
                InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            }

            handler.EventHandler -= callback;
        }
Exemplo n.º 2
0
        private static void FindEventHandler(RuntimeInfoKey key, ref RuntimeInfoEventHandler handler)
        {
            switch (key)
            {
            case RuntimeInfoKey.Bluetooth:
                handler = BluetoothEnabled;
                break;

            case RuntimeInfoKey.WifiHotspot:
                handler = WifiHotspotEnabled;
                break;

            case RuntimeInfoKey.BluetoothTethering:
                handler = BluetoothTetheringEnabled;
                break;

            case RuntimeInfoKey.UsbTethering:
                handler = UsbTetheringEnabled;
                break;

            case RuntimeInfoKey.PacketData:
                handler = PacketDataEnabled;
                break;

            case RuntimeInfoKey.DataRoaming:
                handler = DataRoamingEnabled;
                break;

            case RuntimeInfoKey.Vibration:
                handler = VibrationEnabled;
                break;

            case RuntimeInfoKey.AudioJack:
                handler = AudioJackConnected;
                break;

            case RuntimeInfoKey.Gps:
                handler = GpsStatusChanged;
                break;

            case RuntimeInfoKey.BatteryIsCharging:
                handler = BatteryIsCharging;
                break;

            case RuntimeInfoKey.TvOut:
                handler = TvOutConnected;
                break;

            case RuntimeInfoKey.AudioJackConnector:
                handler = AudioJackConnectorChanged;
                break;

            case RuntimeInfoKey.Charger:
                handler = ChargerConnected;
                break;

            case RuntimeInfoKey.AutoRotation:
                handler = AutoRotationEnabled;
                break;

            default:
                handler = null;
                break;
            }
        }