Add textview for volume control.
This commit is contained in:
@@ -56,6 +56,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
SeekBar seekBar;
|
||||
AudioManager audioManager;
|
||||
TextView tvSeekBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -210,7 +211,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
//(ViewManager) etMillis.getParent().remove
|
||||
|
||||
seekBar = findViewById(R.id.seekBar);
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
|
||||
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
seekBar.setMax(maxVolume);
|
||||
|
||||
tvSeekBar = findViewById(R.id.tvSeekbar);
|
||||
|
||||
syncVolume();
|
||||
|
||||
@@ -218,19 +225,20 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, AudioManager.FLAG_SHOW_UI);
|
||||
syncVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// Do Nothing
|
||||
syncVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// Do Nothing
|
||||
syncVolume();
|
||||
}
|
||||
});
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
|
||||
recoverScreen();
|
||||
|
||||
@@ -685,11 +693,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void syncVolume() {
|
||||
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
seekBar.setMax(maxVolume);
|
||||
String tag = TAG + "syncVolume";
|
||||
if (DEBUG) Log.d(tag, "Starting");
|
||||
|
||||
int currVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
seekBar.setProgress(currVolume);
|
||||
|
||||
String volume = getString(R.string.tvSeekBar) + seekBar.getProgress() + "/" + seekBar.getMax();
|
||||
tvSeekBar.setText(volume);
|
||||
|
||||
if (DEBUG) Log.d(tag, "Finished");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user