Home | History | Annotate | Download | only in sound
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 package com.android.car.settings.sound;
     17 
     18 import android.car.Car;
     19 import android.content.ComponentName;
     20 import android.content.ServiceConnection;
     21 import android.media.AudioManager;
     22 import android.os.Bundle;
     23 import android.os.IBinder;
     24 import android.view.View;
     25 
     26 import com.android.car.settings.common.CarSettingActivity;
     27 import com.android.car.settings.R;
     28 
     29 /**
     30  * Activity hosts sound related settings.
     31  */
     32 public class SoundSettingsActivity extends CarSettingActivity {
     33     private static final String TAG = "SoundSettingsActivity";
     34     private Car mCar;
     35 
     36     private VolumeControllerPresenter mMediaVolumeControllerPresenter;
     37     private VolumeControllerPresenter mRingVolumeControllerPresenter;
     38 
     39     @Override
     40     protected void onCreate(Bundle savedInstanceState) {
     41         super.onCreate(savedInstanceState);
     42         setContentView(R.layout.volume_list);
     43 
     44         View mediaVolumeControllerView = findViewById(
     45                 R.id.media_volume);
     46         View ringVolumeControllerView = findViewById(
     47                 R.id.ring_volume);
     48         mMediaVolumeControllerPresenter = new VolumeControllerPresenter(
     49                 this /* context*/,
     50                 mediaVolumeControllerView,
     51                 AudioManager.STREAM_MUSIC,
     52                 null /* Uri sampleUri */,
     53                 R.string.media_volume_title,
     54                 com.android.internal.R.drawable.ic_audio_media);
     55         mRingVolumeControllerPresenter = new VolumeControllerPresenter(
     56                 this /* context*/,
     57                 ringVolumeControllerView,
     58                 AudioManager.STREAM_RING,
     59                 null /* Uri sampleUri */,
     60                 R.string.ring_volume_title,
     61                 com.android.internal.R.drawable.ic_audio_ring_notif);
     62         mCar = Car.createCar(this /* context */, mServiceConnection);
     63     }
     64 
     65     ServiceConnection mServiceConnection = new ServiceConnection() {
     66         @Override
     67         public void onServiceConnected(ComponentName name, IBinder service) {
     68             mMediaVolumeControllerPresenter.onServiceConnected(mCar);
     69             mRingVolumeControllerPresenter.onServiceConnected(mCar);
     70         }
     71 
     72         @Override
     73         public void onServiceDisconnected(ComponentName name) {
     74             mMediaVolumeControllerPresenter.onServiceDisconnected();
     75             mRingVolumeControllerPresenter.onServiceDisconnected();
     76         }
     77     };
     78 
     79     @Override
     80     public void onStart() {
     81         super.onStart();
     82         mCar.connect();
     83     }
     84 
     85     @Override
     86     public void onStop() {
     87         super.onStop();
     88         mMediaVolumeControllerPresenter.stop();
     89         mRingVolumeControllerPresenter.stop();
     90         mCar.disconnect();
     91     }
     92 }
     93