I notify the listener in VolumeFragment.onCreateView
only if it is popluated with system settings closes #58 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -33,18 +33,62 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
|||||||
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener {
|
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener {
|
||||||
|
|
||||||
private static final String TAG = "VolumeFragment";
|
private static final String TAG = "VolumeFragment";
|
||||||
private AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
private int mStream;
|
private final int mStream;
|
||||||
private OnContentChangedListener mListener;
|
private final OnContentChangedListener mListener;
|
||||||
private String mKey;
|
private final String mKey;
|
||||||
private ContentValues mInfo;
|
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){
|
public VolumeFragment(ContentValues info, Context context, OnContentChangedListener listener, int stream){
|
||||||
super();
|
super();
|
||||||
this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
this.mStream = stream;
|
this.mStream = stream;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
this.mInfo = info;
|
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
|
@Override
|
||||||
@@ -61,63 +105,43 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
|||||||
volume.setProgress(this.mAudioManager.getStreamVolume(mStream));
|
volume.setProgress(this.mAudioManager.getStreamVolume(mStream));
|
||||||
volume.setOnSeekBarChangeListener(this);
|
volume.setOnSeekBarChangeListener(this);
|
||||||
|
|
||||||
switch(this.mStream){
|
label.setText(mLabel);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.mInfo.containsKey(this.mKey))
|
if(this.mInfo.containsKey(this.mKey))
|
||||||
volume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKey)));
|
volume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKey)));
|
||||||
|
else
|
||||||
|
notifyListener(this.mAudioManager.getStreamVolume(mStream));
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
if(fromUser)
|
if(fromUser)
|
||||||
if(this.mListener != null){
|
notifyListener(progress);
|
||||||
ContentValues info = new ContentValues();
|
}
|
||||||
info.put(this.mKey, progress);
|
|
||||||
this.mListener.onInfoContentChanged(info);
|
/**
|
||||||
}
|
* 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
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user