import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
public class MainActivity extends Activity {
int music_max;
int alarm_max;
int ring_max;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
music_max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
alarm_max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
ring_max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
SeekBar seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
SeekBar seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
SeekBar seekBar3 = (SeekBar) findViewById(R.id.seekBar3);
seekBar1.setMax(music_max);
seekBar2.setMax(alarm_max);
seekBar3.setMax(ring_max);
// Button "button1"
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// To-Do
SeekBar seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
SeekBar seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
SeekBar seekBar3 = (SeekBar) findViewById(R.id.seekBar3);
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, seekBar1.getProgress(), AudioManager.FLAG_SHOW_UI);
mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, seekBar2.getProgress(), AudioManager.FLAG_SHOW_UI);
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, seekBar3.getProgress(), AudioManager.FLAG_SHOW_UI);
}
});
// End of Button "button1"
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
沒有留言:
張貼留言