// Path: app/src/main/java/net/hyx/app/volumenotification/controller/TileServiceController.java
// public class TileServiceController {
// 
//     private final Context context;
//     private final VolumeControlModel volumeControlModel;
// 
//     public TileServiceController(Context context) {
//         this.context = context;
//         volumeControlModel = new VolumeControlModel(context);
//     }
// 
//     public static TileServiceController newInstance(Context context) {
//         return new TileServiceController(context);
//     }
// 
//     public void requestListening() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//             requestListeningTiles();
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     private void requestListeningTiles() {
//         String[] tileServices = {
//                 TileServiceMediaVolume.class.getName(),
//                 TileServiceCallVolume.class.getName(),
//                 TileServiceRingVolume.class.getName(),
//                 TileServiceAlarmVolume.class.getName(),
//                 TileServiceNotificationVolume.class.getName(),
//                 TileServiceSystemVolume.class.getName(),
//                 TileServiceDialVolume.class.getName(),
//                 TileServiceAccessibilityVolume.class.getName(),
//                 //TileServiceDefaultVolume.class.getName(),
//         };
//         for (String service : tileServices) {
//             TileService.requestListeningState(context, new ComponentName(context, service));
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     public void updateTile(Tile tile, int streamType) {
//         VolumeControl item = volumeControlModel.getItemByType(streamType);
//         if (item == null) {
//             item = volumeControlModel.getDefaultControls().get(streamType);
//         }
//         tile.setIcon(Icon.createWithResource(context, volumeControlModel.getIconId(item.icon)));
//         tile.setLabel(item.label);
//         tile.setState(Tile.STATE_ACTIVE);
//         tile.updateTile();
//     }
// 
// }
// 
// Path: app/src/main/java/net/hyx/app/volumenotification/model/AudioManagerModel.java
// public class AudioManagerModel {
// 
//     private final AudioManager audio;
//     private final SettingsModel settings;
// 
//     public AudioManagerModel(Context context) {
//         audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//         settings = new SettingsModel(context);
//     }
// 
//     public void adjustVolume(int streamType) {
//         audio.adjustStreamVolume(streamType, getStreamFlag(streamType), AudioManager.FLAG_SHOW_UI);
//     }
// 
//     private int getStreamFlag(int streamType) {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             if ((streamType == AudioManager.STREAM_MUSIC && settings.getToggleMute()) || (streamType == AudioManager.STREAM_RING && settings.getToggleSilent())) {
//                 return AudioManager.ADJUST_TOGGLE_MUTE;
//             }
//         }
//         return AudioManager.ADJUST_SAME;
//     }
// 
// }


import android.annotation.TargetApi;
import android.os.Build;
import android.service.quicksettings.TileService;
import net.hyx.app.volumenotification.controller.TileServiceController;
import net.hyx.app.volumenotification.model.AudioManagerModel;
/*
 * Copyright 2017 https://github.com/seht
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hyx.app.volumenotification.service;



@TargetApi(Build.VERSION_CODES.N)
abstract public class VolumeTileService extends TileService {

    protected void updateTile(int streamType) {
        TileServiceController tileServiceController = TileServiceController.newInstance(getApplicationContext());
        tileServiceController.updateTile(getQsTile(), streamType);
    }

    protected void adjustVolume(int streamType) {
        AudioManagerModel audioManagerModel = new AudioManagerModel(getApplicationContext());
// Path: app/src/main/java/net/hyx/app/volumenotification/controller/TileServiceController.java
// public class TileServiceController {
// 
//     private final Context context;
//     private final VolumeControlModel volumeControlModel;
// 
//     public TileServiceController(Context context) {
//         this.context = context;
//         volumeControlModel = new VolumeControlModel(context);
//     }
// 
//     public static TileServiceController newInstance(Context context) {
//         return new TileServiceController(context);
//     }
// 
//     public void requestListening() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//             requestListeningTiles();
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     private void requestListeningTiles() {
//         String[] tileServices = {
//                 TileServiceMediaVolume.class.getName(),
//                 TileServiceCallVolume.class.getName(),
//                 TileServiceRingVolume.class.getName(),
//                 TileServiceAlarmVolume.class.getName(),
//                 TileServiceNotificationVolume.class.getName(),
//                 TileServiceSystemVolume.class.getName(),
//                 TileServiceDialVolume.class.getName(),
//                 TileServiceAccessibilityVolume.class.getName(),
//                 //TileServiceDefaultVolume.class.getName(),
//         };
//         for (String service : tileServices) {
//             TileService.requestListeningState(context, new ComponentName(context, service));
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     public void updateTile(Tile tile, int streamType) {
//         VolumeControl item = volumeControlModel.getItemByType(streamType);
//         if (item == null) {
//             item = volumeControlModel.getDefaultControls().get(streamType);
//         }
//         tile.setIcon(Icon.createWithResource(context, volumeControlModel.getIconId(item.icon)));
//         tile.setLabel(item.label);
//         tile.setState(Tile.STATE_ACTIVE);
//         tile.updateTile();
//     }
// 
// }
// 
// Path: app/src/main/java/net/hyx/app/volumenotification/model/AudioManagerModel.java
// public class AudioManagerModel {
// 
//     private final AudioManager audio;
//     private final SettingsModel settings;
// 
//     public AudioManagerModel(Context context) {
//         audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//         settings = new SettingsModel(context);
//     }
// 
//     public void adjustVolume(int streamType) {
//         audio.adjustStreamVolume(streamType, getStreamFlag(streamType), AudioManager.FLAG_SHOW_UI);
//     }
// 
//     private int getStreamFlag(int streamType) {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             if ((streamType == AudioManager.STREAM_MUSIC && settings.getToggleMute()) || (streamType == AudioManager.STREAM_RING && settings.getToggleSilent())) {
//                 return AudioManager.ADJUST_TOGGLE_MUTE;
//             }
//         }
//         return AudioManager.ADJUST_SAME;
//     }
// 
// }


// Path: app/src/main/java/net/hyx/app/volumenotification/service/VolumeTileService.java
import android.annotation.TargetApi;
import android.os.Build;
import android.service.quicksettings.TileService;
import net.hyx.app.volumenotification.controller.TileServiceController;
import net.hyx.app.volumenotification.model.AudioManagerModel;

/*
 * Copyright 2017 https://github.com/seht
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hyx.app.volumenotification.service;



@TargetApi(Build.VERSION_CODES.N)
abstract public class VolumeTileService extends TileService {

    protected void updateTile(int streamType) {
        TileServiceController tileServiceController = TileServiceController.newInstance(getApplicationContext());
        tileServiceController.updateTile(getQsTile(), streamType);
    }

    protected void adjustVolume(int streamType) {
        AudioManagerModel audioManagerModel = new AudioManagerModel(getApplicationContext());
        audioManagerModel.adjustVolume(streamType);