I have successfully enabled filtering for the add a feature dialog.
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -120,21 +120,39 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
|
|||||||
* update interval
|
* update interval
|
||||||
*/
|
*/
|
||||||
ArrayList<Fragment> what = new ArrayList<Fragment>();
|
ArrayList<Fragment> what = new ArrayList<Fragment>();
|
||||||
|
ArrayList<Integer> added = new ArrayList<Integer>();
|
||||||
|
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_VOLUME))
|
if(this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_VOLUME)){
|
||||||
what.add(new RingtoneFragment(this.mInfo, this, AudioManager.STREAM_RING));
|
what.add(new RingtoneFragment(this.mInfo, this, AudioManager.STREAM_RING));
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME))
|
added.add(0);
|
||||||
what.add(new RingtoneFragment(this.mInfo, this, AudioManager.STREAM_NOTIFICATION));
|
}
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_ALARM_VOLUME))
|
|
||||||
what.add(new VolumeFragment(this.mInfo, this, this, AudioManager.STREAM_ALARM));
|
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_MUSIC_VOLUME))
|
|
||||||
what.add(new VolumeFragment(this.mInfo, this, this, AudioManager.STREAM_MUSIC));
|
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_WIFI))
|
|
||||||
what.add(new ToggleButtonFragment(this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this));
|
|
||||||
if(this.mInfo.containsKey(RingerDatabase.KEY_BT))
|
|
||||||
what.add(new ToggleButtonFragment(this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this));
|
|
||||||
|
|
||||||
fragments.add(new FeatureListFragment(this.mInfo, this, what));
|
if(this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME)){
|
||||||
|
what.add(new RingtoneFragment(this.mInfo, this, AudioManager.STREAM_NOTIFICATION));
|
||||||
|
added.add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mInfo.containsKey(RingerDatabase.KEY_ALARM_VOLUME)){
|
||||||
|
what.add(new VolumeFragment(this.mInfo, this, this, AudioManager.STREAM_ALARM));
|
||||||
|
added.add(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mInfo.containsKey(RingerDatabase.KEY_MUSIC_VOLUME)){
|
||||||
|
what.add(new VolumeFragment(this.mInfo, this, this, AudioManager.STREAM_MUSIC));
|
||||||
|
added.add(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mInfo.containsKey(RingerDatabase.KEY_BT)){
|
||||||
|
what.add(new ToggleButtonFragment(this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this));
|
||||||
|
added.add(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mInfo.containsKey(RingerDatabase.KEY_WIFI)){
|
||||||
|
what.add(new ToggleButtonFragment(this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this));
|
||||||
|
added.add(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
fragments.add(new FeatureListFragment(this.mInfo, this, what, added));
|
||||||
|
|
||||||
//Populate the pager
|
//Populate the pager
|
||||||
this.mPager = (ViewPager)findViewById(R.id.pager);
|
this.mPager = (ViewPager)findViewById(R.id.pager);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
@@ -41,6 +42,7 @@ public class FeatureListFragment extends Fragment implements OnClickListener, an
|
|||||||
private final ArrayList<Fragment> mFragments;
|
private final ArrayList<Fragment> mFragments;
|
||||||
private final ContentValues mInfo;
|
private final ContentValues mInfo;
|
||||||
private final OnContentChangedListener mListener;
|
private final OnContentChangedListener mListener;
|
||||||
|
private final ArrayList<Integer> mAdded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new FeatureListFragment
|
* Creates a new FeatureListFragment
|
||||||
@@ -49,11 +51,12 @@ public class FeatureListFragment extends Fragment implements OnClickListener, an
|
|||||||
* @param fragments
|
* @param fragments
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public FeatureListFragment(ContentValues info, OnContentChangedListener listener, ArrayList<Fragment> fragments) {
|
public FeatureListFragment(ContentValues info, OnContentChangedListener listener, ArrayList<Fragment> fragments, ArrayList<Integer> added) {
|
||||||
super();
|
super();
|
||||||
mFragments = fragments;
|
mFragments = fragments;
|
||||||
mInfo = info;
|
mInfo = info;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
|
mAdded = added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +93,84 @@ public class FeatureListFragment extends Fragment implements OnClickListener, an
|
|||||||
super.onActivityResult(arg0, arg1, arg2);
|
super.onActivityResult(arg0, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an item is picked from the add featue list
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.content.DialogInterface.OnClickListener#onClick(android.content.DialogInterface, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Fragment f = null;
|
||||||
|
switch(which){
|
||||||
|
case 0:
|
||||||
|
f= new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_RING);
|
||||||
|
mAdded.add(0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
f = new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_NOTIFICATION);
|
||||||
|
mAdded.add(1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_ALARM);
|
||||||
|
mAdded.add(2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_MUSIC);
|
||||||
|
mAdded.add(3);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
f = new ToggleButtonFragment(this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener);
|
||||||
|
mAdded.add(4);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
f = new ToggleButtonFragment(this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener);
|
||||||
|
mAdded.add(5);
|
||||||
|
break;
|
||||||
|
// case 6:
|
||||||
|
// f =
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(f != null)
|
||||||
|
add(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the add feature button is clicked
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
new AlertDialog.Builder(this.getActivity())
|
||||||
|
.setTitle(R.string.add_a_feature)
|
||||||
|
// .setItems(R.array.features, this)
|
||||||
|
.setAdapter(
|
||||||
|
new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, this.getResources().getStringArray(R.array.features)){
|
||||||
|
/**
|
||||||
|
* we override this, because we want to filter which items are enabled
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.widget.BaseAdapter#areAllItemsEnabled()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean areAllItemsEnabled(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* here we can notify the adaptor if an item should be enabled or not
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.widget.BaseAdapter#isEnabled(int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int position){
|
||||||
|
return ! mAdded.contains(position);
|
||||||
|
}
|
||||||
|
}, this)
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.support.v4.app.ListFragment#onCreateView(android.view.LayoutInflater,
|
* @see android.support.v4.app.ListFragment#onCreateView(android.view.LayoutInflater,
|
||||||
@@ -154,54 +235,4 @@ public class FeatureListFragment extends Fragment implements OnClickListener, an
|
|||||||
}
|
}
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the add feature button is clicked
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
new AlertDialog.Builder(this.getActivity())
|
|
||||||
.setTitle(R.string.add_a_feature)
|
|
||||||
.setItems(R.array.features, this)
|
|
||||||
.create()
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an item is picked from the add featue list
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.content.DialogInterface.OnClickListener#onClick(android.content.DialogInterface, int)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
Fragment f = null;
|
|
||||||
switch(which){
|
|
||||||
case 0:
|
|
||||||
f= new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_RING);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
f = new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_NOTIFICATION);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_ALARM);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_MUSIC);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
f = new ToggleButtonFragment(this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
f = new ToggleButtonFragment(this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener);
|
|
||||||
break;
|
|
||||||
// case 6:
|
|
||||||
// f =
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(f != null)
|
|
||||||
add(f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user