From 7aebd3b60d8b95837ac7d8eaa739373709a39184 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 26 May 2012 13:22:27 -0400 Subject: [PATCH] I finished fixing the add feature list filtering Signed-off-by: Ricky Barrette --- .../FeatureRemovedListener.java | 22 +++++ .../ui/fragments/FeatureListFragment.java | 94 ++++++++++--------- .../ui/fragments/IdFragment.java | 30 ++++++ .../ui/fragments/RingtoneFragment.java | 6 +- .../ui/fragments/ToggleButtonFragment.java | 6 +- .../ui/fragments/VolumeFragment.java | 6 +- 6 files changed, 110 insertions(+), 54 deletions(-) create mode 100644 LocationRinger/src/com/TwentyCodes/android/LocationRinger/FeatureRemovedListener.java create mode 100644 LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/IdFragment.java diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/FeatureRemovedListener.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/FeatureRemovedListener.java new file mode 100644 index 0000000..48e9b0a --- /dev/null +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/FeatureRemovedListener.java @@ -0,0 +1,22 @@ +/** + * FeatureRemovedListener.java + * @date May 26, 2012 + * @author ricky barrette + * @author Twenty Codes, LLC + */ +package com.TwentyCodes.android.LocationRinger; + +import android.support.v4.app.Fragment; + +/** + * This interface will be used to notify + * @author ricky barrette + */ +public interface FeatureRemovedListener { + + /** + * Called when a feature is removed from the list + * @author ricky barrette + */ + public void onFeatureRemoved(Fragment fragment); +} \ No newline at end of file diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java index 4a5487e..220bea6 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java @@ -35,7 +35,13 @@ import com.TwentyCodes.android.LocationRinger.db.RingerDatabase; * @author ricky */ public class FeatureListFragment extends BaseFragmentListFragment implements OnClickListener, android.content.DialogInterface.OnClickListener, FeatureRemovedListener { - + + private static final int KEY_ADDED_RINGTONE = 0; + private static final int KEY_ADDED_NOTIFICATIONTONE = 1; + private static final int KEY_ADDED_ALARM_VOLUME = 2; + private static final int KEY_ADDED_MUSIC_VOLUME = 3; + private static final int KEY_ADDED_BT = 4; + private static final int KEY_ADDED_WIFI = 5; private static final String TAG = "FeatureListFragment"; private final ContentValues mInfo; private final OnContentChangedListener mListener; @@ -64,33 +70,27 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC ArrayList what = new ArrayList(); if(this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_VOLUME)){ - what.add(new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_RING)); - mAdded.add(0); + initFeatureFragment(KEY_ADDED_RINGTONE); } if(this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME)){ - what.add(new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_NOTIFICATION)); - mAdded.add(1); + initFeatureFragment(KEY_ADDED_NOTIFICATIONTONE); } if(this.mInfo.containsKey(RingerDatabase.KEY_ALARM_VOLUME)){ - what.add(new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_ALARM)); - mAdded.add(2); + initFeatureFragment(KEY_ADDED_ALARM_VOLUME); } if(this.mInfo.containsKey(RingerDatabase.KEY_MUSIC_VOLUME)){ - what.add(new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_MUSIC)); - mAdded.add(3); + initFeatureFragment(KEY_ADDED_MUSIC_VOLUME); } if(this.mInfo.containsKey(RingerDatabase.KEY_BT)){ - what.add(new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener, this)); - mAdded.add(4); + initFeatureFragment(KEY_ADDED_BT); } if(this.mInfo.containsKey(RingerDatabase.KEY_WIFI)){ - what.add(new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener, this)); - mAdded.add(5); + initFeatureFragment(KEY_ADDED_WIFI); } return what; } @@ -102,40 +102,42 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC */ @Override public void onClick(DialogInterface dialog, int which) { - Fragment f = null; - switch(which){ - case 0: - f= new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_RING); - mAdded.add(0); - break; - case 1: - f = new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_NOTIFICATION); - mAdded.add(1); - break; - case 2: - f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_ALARM); - mAdded.add(2); - break; - case 3: - f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_MUSIC); - mAdded.add(3); - break; - case 4: - f = new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener, this); - mAdded.add(4); - break; - case 5: - f = new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener, this); - mAdded.add(5); - break; -// case 6: -// f = -// break; - } - + final Fragment f = initFeatureFragment(which); if(f != null) add(f); } + + public Fragment initFeatureFragment(int fragmentCode){ + Fragment f = null; + switch(fragmentCode){ + case 0: + f= new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_RING, KEY_ADDED_RINGTONE); + mAdded.add(KEY_ADDED_RINGTONE); + break; + case 1: + f = new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_NOTIFICATION, KEY_ADDED_NOTIFICATIONTONE); + mAdded.add(KEY_ADDED_NOTIFICATIONTONE); + break; + case 2: + f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_ALARM, KEY_ADDED_ALARM_VOLUME); + mAdded.add(KEY_ADDED_ALARM_VOLUME); + break; + case 3: + f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_MUSIC, KEY_ADDED_MUSIC_VOLUME); + mAdded.add(KEY_ADDED_MUSIC_VOLUME); + break; + case 4: + f = new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener, this, KEY_ADDED_BT); + mAdded.add(KEY_ADDED_BT); + break; + case 5: + f = new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener, this, KEY_ADDED_WIFI); + mAdded.add(KEY_ADDED_WIFI); + break; + + } + return f; + } /** * Called when the add feature button is clicked @@ -209,6 +211,8 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC @Override public void onFeatureRemoved(Fragment f) { this.remove(f); - //TODO remove database entries + + if(f instanceof IdFragment) + mAdded.remove(new Integer(((IdFragment) f).getFragmentId())); } } \ No newline at end of file diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/IdFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/IdFragment.java new file mode 100644 index 0000000..c959ed7 --- /dev/null +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/IdFragment.java @@ -0,0 +1,30 @@ +/** + * IdFragment.java + * @date May 26, 2012 + * @author ricky barrette + * @author Twenty Codes, LLC + */ +package com.TwentyCodes.android.LocationRinger.ui.fragments; + +import android.support.v4.app.Fragment; + +/** + * This is a simple extention of a fragment that will allow for storage of an id + * @author ricky barrette + */ +public class IdFragment extends Fragment { + + private final int mId; + + public IdFragment(int id){ + super(); + mId = id; + } + + /** + * @return the id of this fragment + */ + public int getFragmentId() { + return mId; + } +} \ No newline at end of file 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 4a5ddc8..eee6c4a 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/RingtoneFragment.java @@ -39,7 +39,7 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug; * This fragment will be for ringtone settings * @author ricky */ -public class RingtoneFragment extends Fragment implements OnClickListener, OnSeekBarChangeListener { +public class RingtoneFragment extends IdFragment implements OnClickListener, OnSeekBarChangeListener { private static final String TAG = "RingtoneFragment"; private final int mStream; @@ -56,8 +56,8 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee private SeekBar mVolume; private ImageView mIcon; - public RingtoneFragment(ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream){ - super(); + public RingtoneFragment(ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream, int id){ + super(id); this.mChangedListener = changedListener; this.mStream = stream; this.mInfo = info; 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 b0bae2f..213bb9b 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/ToggleButtonFragment.java @@ -28,7 +28,7 @@ import android.widget.ToggleButton; * A simple fragment that displays a toggle button and a title label * @author ricky */ -public class ToggleButtonFragment extends Fragment implements OnCheckedChangeListener, OnClickListener { +public class ToggleButtonFragment extends IdFragment implements OnCheckedChangeListener, OnClickListener { private final String mTitle; private final String mKey; @@ -41,8 +41,8 @@ public class ToggleButtonFragment extends Fragment implements OnCheckedChangeLis * Creates a new ToggleButtonFtagment * @author ricky barrette */ - public ToggleButtonFragment(int icon, String title, String key, ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener) { - super(); + public ToggleButtonFragment(int icon, String title, String key, ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int id) { + super(id); this.mTitle = title; this.mKey = key; this.mInfo = info; 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 001bf3a..f24978c 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/VolumeFragment.java @@ -33,7 +33,7 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug; * This fragment will represent the volume fragments * @author ricky */ -public class VolumeFragment extends Fragment implements OnSeekBarChangeListener, OnClickListener { +public class VolumeFragment extends IdFragment implements OnSeekBarChangeListener, OnClickListener { private static final String TAG = "VolumeFragment"; private final AudioManager mAudioManager; @@ -53,8 +53,8 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener, * @param stream * @author ricky barrette */ - public VolumeFragment(ContentValues info, Context context, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream){ - super(); + public VolumeFragment(ContentValues info, Context context, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream, int id){ + super(id); this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); this.mStream = stream; this.mChangedListener = changedListener;