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
|
||||
|
@@ -158,13 +158,27 @@
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar"
|
||||
android:layout_width="match_parent"
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tblButtons"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginVertical="@dimen/activity_vertical_margin"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
android:layout_alignParentBottom="true">
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="@dimen/activity_vertical_margin"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminate="false"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSeekbar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/seekBar"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="@string/tvSeekBar"
|
||||
android:textSize="14sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@@ -35,4 +35,6 @@
|
||||
<string name="action_millis">Enable Millisecs</string>
|
||||
<string name="action_enable_ads">Enable Ads</string>
|
||||
<string name="action_exit">Exit</string>
|
||||
|
||||
<string name="tvSeekBar">Media Volume: </string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user