I finished fixing the add feature list filtering

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-05-26 13:22:27 -04:00
parent 36ecfc3507
commit 7aebd3b60d
6 changed files with 110 additions and 54 deletions

View File

@@ -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);
}

View File

@@ -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<Fragment> what = new ArrayList<Fragment>();
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()));
}
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;