diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java index b207117..252a4d3 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java @@ -33,18 +33,62 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug; public class VolumeFragment extends Fragment implements OnSeekBarChangeListener { private static final String TAG = "VolumeFragment"; - private AudioManager mAudioManager; - private int mStream; - private OnContentChangedListener mListener; - private String mKey; - private ContentValues mInfo; + private final AudioManager mAudioManager; + private final int mStream; + private final OnContentChangedListener mListener; + private final String mKey; + private final ContentValues mInfo; + private final int mLabel; + /** + * Creates a new Volume Fragment + * @param info + * @param context + * @param listener + * @param stream + * @author ricky barrette + */ public VolumeFragment(ContentValues info, Context context, OnContentChangedListener listener, int stream){ super(); this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); this.mStream = stream; this.mListener = listener; this.mInfo = info; + + switch(this.mStream){ + case AudioManager.STREAM_ALARM: + this.mLabel = R.string.alarm_volume; + this.mKey = RingerDatabase.KEY_ALARM_VOLUME; + break; + case AudioManager.STREAM_DTMF: + this.mLabel = R.string.dtmf_volume; + this.mKey = RingerDatabase.KEY_DTMF_VOLUME; + break; + case AudioManager.STREAM_MUSIC: + this.mLabel = R.string.music_volume; + this.mKey = RingerDatabase.KEY_MUSIC_VOLUME; + break; + case AudioManager.STREAM_NOTIFICATION: + this.mLabel = R.string.notification_volume; + this.mKey = RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME; + break; + case AudioManager.STREAM_RING: + this.mLabel = R.string.ringtone_volume; + this.mKey = RingerDatabase.KEY_RINGTONE_VOLUME; + break; + case AudioManager.STREAM_SYSTEM: + this.mLabel = R.string.system_volume; + this.mKey = RingerDatabase.KEY_SYSTEM_VOLUME; + break; + case AudioManager.STREAM_VOICE_CALL: + this.mLabel = R.string.call_volume; + this.mKey = RingerDatabase.KEY_CALL_VOLUME; + break; + default: + this.mLabel = R.string.volume; + this.mKey = RingerDatabase.KEY_RINGTONE_VOLUME; + break; + } } @Override @@ -61,63 +105,43 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener volume.setProgress(this.mAudioManager.getStreamVolume(mStream)); volume.setOnSeekBarChangeListener(this); - switch(this.mStream){ - case AudioManager.STREAM_ALARM: - label.setText(R.string.alarm_volume); - this.mKey = RingerDatabase.KEY_ALARM_VOLUME; - break; - case AudioManager.STREAM_DTMF: - label.setText(R.string.dtmf_volume); - this.mKey = RingerDatabase.KEY_DTMF_VOLUME; - break; - case AudioManager.STREAM_MUSIC: - label.setText(R.string.music_volume); - this.mKey = RingerDatabase.KEY_MUSIC_VOLUME; - break; - case AudioManager.STREAM_NOTIFICATION: - label.setText(R.string.notification_volume); - this.mKey = RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME; - break; - case AudioManager.STREAM_RING: - label.setText(R.string.ringtone_volume); - this.mKey = RingerDatabase.KEY_RINGTONE_VOLUME; - break; - case AudioManager.STREAM_SYSTEM: - label.setText(R.string.system_volume); - this.mKey = RingerDatabase.KEY_SYSTEM_VOLUME; - break; - case AudioManager.STREAM_VOICE_CALL: - label.setText(R.string.call_volume); - this.mKey = RingerDatabase.KEY_CALL_VOLUME; - break; - } + label.setText(mLabel); if(this.mInfo.containsKey(this.mKey)) volume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKey))); - + else + notifyListener(this.mAudioManager.getStreamVolume(mStream)); + return view; } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if(fromUser) - if(this.mListener != null){ - ContentValues info = new ContentValues(); - info.put(this.mKey, progress); - this.mListener.onInfoContentChanged(info); - } + notifyListener(progress); + } + + /** + * Notifys the listener of changes made to the volume + * @param progress + * @author ricky barrette + */ + private void notifyListener(final int progress) { + if(this.mListener != null){ + final ContentValues info = new ContentValues(); + info.put(this.mKey, progress); + this.mListener.onInfoContentChanged(info); + } } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub - } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub - } }