From 8570fff4e452c45c91e67a767ba4c0bdd15aae20 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 26 May 2012 12:09:20 -0400 Subject: [PATCH] Started intergrating the new fragment title bar into the following fragments: ringtone fragment, toggle button fragment, volume fragment Signed-off-by: Ricky Barrette --- .../ui/fragments/RingtoneFragment.java | 31 ++++++++++++------- .../ui/fragments/ToggleButtonFragment.java | 6 +++- .../ui/fragments/VolumeFragment.java | 19 ++++++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java index f519fba..3795d5c 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java @@ -24,6 +24,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.EditText; +import android.widget.ImageView; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; @@ -51,6 +52,7 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee private EditText mRingtone; private Uri mRingtoneURI; private SeekBar mVolume; + private ImageView mIcon; public RingtoneFragment(ContentValues info, OnContentChangedListener listener, int stream){ super(); @@ -114,6 +116,7 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee * @author ricky barrette */ private void notifyVolumeChanged(int progress) { + mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(progress == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off)); if(this.mListener != null){ final ContentValues info = new ContentValues(); info.put(this.mKeyVolume, progress); @@ -133,6 +136,7 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee this.mRingtone.setText(R.string.silent); mVolume.setEnabled(false); mVolume.setProgress(0); + notifyVolumeChanged(0); } else { mVolume.setEnabled(true); Ringtone ringtone = RingtoneManager.getRingtone(this.getActivity(), Uri.parse(tone.toString())); @@ -164,15 +168,28 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee /* * initialize the views */ - final TextView label = (TextView) view.findViewById(R.id.label); + final TextView label = (TextView) view.findViewById(R.id.title); label.setText(mLabel); + mIcon = (ImageView) view.findViewById(R.id.icon); + mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(android.R.drawable.ic_lock_silent_mode_off)); + this.mRingtone = (EditText) view.findViewById(R.id.ringtone); mVolume = (SeekBar) view.findViewById(R.id.ringtone_volume); this.mRingtone.setOnClickListener(this); mVolume.setMax(audioManager.getStreamMaxVolume(mStream)); + /* + * volume + */ + if(this.mInfo.containsKey(this.mKeyVolume)) + mVolume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKeyVolume))); + else { + mVolume.setProgress(audioManager.getStreamVolume(mStream)); + notifyVolumeChanged(audioManager.getStreamVolume(mStream)); + } + /* * ringtone & uri */ @@ -195,16 +212,8 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee mRingtone.setText(R.string.silent); mVolume.setProgress(0); } - - /* - * volume - */ - if(this.mInfo.containsKey(this.mKeyVolume)) - mVolume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKeyVolume))); - else { - mVolume.setProgress(audioManager.getStreamVolume(mStream)); - notifyVolumeChanged(audioManager.getStreamVolume(mStream)); - } + + mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(mVolume.getProgress() == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off)); mVolume.setOnSeekBarChangeListener(this); return view; diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java index 2b1f449..e082b3b 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java @@ -18,6 +18,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.ImageView; import android.widget.TextView; import android.widget.ToggleButton; @@ -47,9 +48,12 @@ public class ToggleButtonFragment extends Fragment implements OnCheckedChangeLis @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) { View view = inflater.inflate(R.layout.toggle_button_fragment, container, false); - TextView t = (TextView) view.findViewById(R.id.label); + TextView t = (TextView) view.findViewById(R.id.title); t.setText(this.mTitle); + final ImageView icon = (ImageView) view.findViewById(R.id.icon); + icon.setImageDrawable(this.getActivity().getResources().getDrawable(android.R.drawable.ic_lock_silent_mode_off)); + ToggleButton b = (ToggleButton) view.findViewById(R.id.toggle); if(this.mInfo.containsKey(this.mKey)) b.setChecked(RingerDatabase.parseBoolean(this.mInfo.getAsString(this.mKey))); 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 252a4d3..99ee79f 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java @@ -17,12 +17,13 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; -import com.TwentyCodes.android.LocationRinger.R; import com.TwentyCodes.android.LocationRinger.OnContentChangedListener; +import com.TwentyCodes.android.LocationRinger.R; import com.TwentyCodes.android.LocationRinger.db.RingerDatabase; import com.TwentyCodes.android.LocationRinger.debug.Debug; @@ -39,6 +40,7 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener private final String mKey; private final ContentValues mInfo; private final int mLabel; + private ImageView mIcon; /** * Creates a new Volume Fragment @@ -98,27 +100,32 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener for(Entry item : this.mInfo.valueSet()) Log.d(TAG, item.getKey() +" = "+ item.getValue()); - View view = inflater.inflate(R.layout.volume_fragment, container, false); - TextView label = (TextView) view.findViewById(R.id.volume_label); - SeekBar volume = (SeekBar) view.findViewById(R.id.volume); + final View view = inflater.inflate(R.layout.volume_fragment, container, false); + final TextView label = (TextView) view.findViewById(R.id.title); + final SeekBar volume = (SeekBar) view.findViewById(R.id.volume); volume.setMax(this.mAudioManager.getStreamMaxVolume(mStream)); volume.setProgress(this.mAudioManager.getStreamVolume(mStream)); volume.setOnSeekBarChangeListener(this); label.setText(mLabel); + mIcon = (ImageView) view.findViewById(R.id.icon); + if(this.mInfo.containsKey(this.mKey)) volume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKey))); else notifyListener(this.mAudioManager.getStreamVolume(mStream)); - + + mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(volume.getProgress() == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off)); return view; } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - if(fromUser) + if(fromUser){ notifyListener(progress); + mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(progress == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off)); + } } /**