1 /* 2 * Copyright 2019 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 17 package com.google.sample.oboe.manualtest; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.LayoutInflater; 22 import android.widget.LinearLayout; 23 import android.widget.SeekBar; 24 import android.widget.TextView; 25 26 public class WorkloadView extends LinearLayout { 27 28 private AudioStreamTester mAudioStreamTester; 29 30 protected static final int FADER_PROGRESS_MAX = 1000; // must match layout 31 protected TextView mTextView; 32 protected SeekBar mSeekBar; 33 protected ExponentialTaper mExponentialTaper; 34 35 private SeekBar.OnSeekBarChangeListener mChangeListener = new SeekBar.OnSeekBarChangeListener() { 36 @Override 37 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 38 setValueByPosition(progress); 39 } 40 41 @Override 42 public void onStartTrackingTouch(SeekBar seekBar) { 43 } 44 45 @Override 46 public void onStopTrackingTouch(SeekBar seekBar) { 47 } 48 }; 49 WorkloadView(Context context)50 public WorkloadView(Context context) { 51 super(context); 52 initializeViews(context); 53 } 54 WorkloadView(Context context, AttributeSet attrs)55 public WorkloadView(Context context, AttributeSet attrs) { 56 super(context, attrs); 57 initializeViews(context); 58 } 59 WorkloadView(Context context, AttributeSet attrs, int defStyle)60 public WorkloadView(Context context, 61 AttributeSet attrs, 62 int defStyle) { 63 super(context, attrs, defStyle); 64 initializeViews(context); 65 } 66 getAudioStreamTester()67 public AudioStreamTester getAudioStreamTester() { 68 return mAudioStreamTester; 69 } 70 setAudioStreamTester(AudioStreamTester audioStreamTester)71 public void setAudioStreamTester(AudioStreamTester audioStreamTester) { 72 mAudioStreamTester = audioStreamTester; 73 } 74 setFaderNormalizedProgress(double fraction)75 void setFaderNormalizedProgress(double fraction) { 76 mSeekBar.setProgress((int)(fraction * FADER_PROGRESS_MAX)); 77 } 78 79 /** 80 * Inflates the views in the layout. 81 * 82 * @param context 83 * the current context for the view. 84 */ initializeViews(Context context)85 private void initializeViews(Context context) { 86 LayoutInflater inflater = (LayoutInflater) context 87 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 88 inflater.inflate(R.layout.workload_view, this); 89 90 mTextView = (TextView) findViewById(R.id.textWorkload); 91 mSeekBar = (SeekBar) findViewById(R.id.faderWorkload); 92 mSeekBar.setOnSeekBarChangeListener(mChangeListener); 93 mExponentialTaper = new ExponentialTaper(0.0, 100.0, 10.0); 94 //mSeekBar.setProgress(0); 95 } 96 setValueByPosition(int progress)97 private void setValueByPosition(int progress) { 98 double workload = mExponentialTaper.linearToExponential( 99 ((double)progress) / FADER_PROGRESS_MAX); 100 mAudioStreamTester.setWorkload(workload); 101 mTextView.setText("Workload = " + String.format("%6.2f", workload)); 102 } 103 104 @Override setEnabled(boolean enabled)105 public void setEnabled(boolean enabled) { 106 super.setEnabled(enabled); 107 mSeekBar.setEnabled(enabled); 108 } 109 } 110