I got the initial funtionality of removing fragmens from the List.
the next step is to better handle the added array Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -119,38 +119,38 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
|
|||||||
* TODO
|
* TODO
|
||||||
* update interval
|
* update interval
|
||||||
*/
|
*/
|
||||||
ArrayList<Fragment> what = new ArrayList<Fragment>();
|
|
||||||
ArrayList<Integer> added = new ArrayList<Integer>();
|
ArrayList<Integer> added = new ArrayList<Integer>();
|
||||||
|
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, AudioManager.STREAM_RING));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_RINGTONE_VOLUME)){
|
||||||
added.add(0);
|
// what.add(new RingtoneFragment(this.mInfo, this, AudioManager.STREAM_RING));
|
||||||
}
|
// added.add(0);
|
||||||
|
// }
|
||||||
if(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));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME)){
|
||||||
added.add(1);
|
// 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));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_ALARM_VOLUME)){
|
||||||
added.add(2);
|
// 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));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_MUSIC_VOLUME)){
|
||||||
added.add(3);
|
// 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));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_BT)){
|
||||||
added.add(4);
|
// what.add(new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, 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));
|
// if(this.mInfo.containsKey(RingerDatabase.KEY_WIFI)){
|
||||||
added.add(5);
|
// what.add(new ToggleButtonFragment(android.R.drawable.stat_sys_data_bluetooth, this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this));
|
||||||
}
|
// added.add(5);
|
||||||
|
// }
|
||||||
|
|
||||||
fragments.add(new FeatureListFragment(this.mInfo, this, what, added));
|
fragments.add(new FeatureListFragment(this.mInfo, this, what, added));
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
|||||||
private final int mLayout;
|
private final int mLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new BaseFragmentListFragment
|
* Creates a new Populated BaseFragmentListFragment
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public BaseFragmentListFragment(ArrayList<Fragment> fragments, int layout, int container) {
|
public BaseFragmentListFragment(ArrayList<Fragment> fragments, int layout, int container) {
|
||||||
@@ -42,6 +42,18 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
|||||||
mContainer = container;
|
mContainer = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Empty Base Fragment List
|
||||||
|
* @param layout
|
||||||
|
* @param container
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public BaseFragmentListFragment(int layout, int container) {
|
||||||
|
mLayout = layout;
|
||||||
|
mContainer = container;
|
||||||
|
mFragments = new ArrayList<Fragment>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the fragment to the list
|
* Adds the fragment to the list
|
||||||
* @param fragment
|
* @param fragment
|
||||||
@@ -54,6 +66,31 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
|||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a collection ofs fragments to the list
|
||||||
|
* @param fragments
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void addAll(final ArrayList<Fragment> fragments){
|
||||||
|
final FragmentTransaction transaction = this.getFragmentManager().beginTransaction();
|
||||||
|
for(Fragment f : fragments){
|
||||||
|
this.mFragments.add(f);
|
||||||
|
transaction.add(mContainer, f, f.getTag());
|
||||||
|
}
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a collection ofs fragments to the list, but doesn't preform any transactions
|
||||||
|
* @param fragment
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
protected void addAllInit(final ArrayList<Fragment> fragments){
|
||||||
|
for(Fragment f : fragments){
|
||||||
|
this.mFragments.add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the fragments
|
* Loads all the fragments
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||||
@@ -33,7 +34,7 @@ import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
|||||||
*
|
*
|
||||||
* @author ricky
|
* @author ricky
|
||||||
*/
|
*/
|
||||||
public class FeatureListFragment extends BaseFragmentListFragment implements OnClickListener, android.content.DialogInterface.OnClickListener {
|
public class FeatureListFragment extends BaseFragmentListFragment implements OnClickListener, android.content.DialogInterface.OnClickListener, FeatureRemovedListener {
|
||||||
|
|
||||||
private static final String TAG = "FeatureListFragment";
|
private static final String TAG = "FeatureListFragment";
|
||||||
private final ContentValues mInfo;
|
private final ContentValues mInfo;
|
||||||
@@ -48,10 +49,50 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public FeatureListFragment(ContentValues info, OnContentChangedListener listener, ArrayList<Fragment> fragments, ArrayList<Integer> added) {
|
public FeatureListFragment(ContentValues info, OnContentChangedListener listener, ArrayList<Fragment> fragments, ArrayList<Integer> added) {
|
||||||
super(fragments, R.layout.fragment_list_contianer, R.id.fragment_list_contianer);
|
super(R.layout.fragment_list_contianer, R.id.fragment_list_contianer);
|
||||||
mInfo = info;
|
mInfo = info;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
mAdded = added;
|
mAdded = added;
|
||||||
|
addAllInit(initList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initali
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private ArrayList<Fragment> initList() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return what;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,27 +105,27 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
|
|||||||
Fragment f = null;
|
Fragment f = null;
|
||||||
switch(which){
|
switch(which){
|
||||||
case 0:
|
case 0:
|
||||||
f= new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_RING);
|
f= new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_RING);
|
||||||
mAdded.add(0);
|
mAdded.add(0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
f = new RingtoneFragment(this.mInfo, this.mListener, AudioManager.STREAM_NOTIFICATION);
|
f = new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_NOTIFICATION);
|
||||||
mAdded.add(1);
|
mAdded.add(1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_ALARM);
|
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_ALARM);
|
||||||
mAdded.add(2);
|
mAdded.add(2);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, AudioManager.STREAM_MUSIC);
|
f = new VolumeFragment(this.mInfo, this.getActivity(), this.mListener, this, AudioManager.STREAM_MUSIC);
|
||||||
mAdded.add(3);
|
mAdded.add(3);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
f = new ToggleButtonFragment(this.getString(R.string.bluetooth), RingerDatabase.KEY_BT, this.mInfo, this.mListener);
|
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);
|
mAdded.add(4);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
f = new ToggleButtonFragment(this.getString(R.string.wifi), RingerDatabase.KEY_WIFI, this.mInfo, this.mListener);
|
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);
|
mAdded.add(5);
|
||||||
break;
|
break;
|
||||||
// case 6:
|
// case 6:
|
||||||
@@ -159,4 +200,15 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
|
|||||||
v.findViewById(R.id.add_feature_button).setOnClickListener(this);
|
v.findViewById(R.id.add_feature_button).setOnClickListener(this);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a fragment needs to be removed
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see com.TwentyCodes.android.LocationRinger.FeatureRemovedListener#onFeatureRemoved(android.support.v4.app.Fragment)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onFeatureRemoved(Fragment f) {
|
||||||
|
this.remove(f);
|
||||||
|
//TODO remove database entries
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,7 @@ import android.widget.SeekBar;
|
|||||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||||
@@ -43,22 +44,24 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
|||||||
private static final String TAG = "RingtoneFragment";
|
private static final String TAG = "RingtoneFragment";
|
||||||
private final int mStream;
|
private final int mStream;
|
||||||
private final int mType;
|
private final int mType;
|
||||||
private final OnContentChangedListener mListener;
|
private final OnContentChangedListener mChangedListener;
|
||||||
private final String mKeyEnabled;
|
private final String mKeyEnabled;
|
||||||
private final String mKeyUri;
|
private final String mKeyUri;
|
||||||
private final String mKeyVolume;
|
private final String mKeyVolume;
|
||||||
private final ContentValues mInfo;
|
private final ContentValues mInfo;
|
||||||
|
private final FeatureRemovedListener mRemovedListener;
|
||||||
private final int mLabel;
|
private final int mLabel;
|
||||||
private EditText mRingtone;
|
private EditText mRingtone;
|
||||||
private Uri mRingtoneURI;
|
private Uri mRingtoneURI;
|
||||||
private SeekBar mVolume;
|
private SeekBar mVolume;
|
||||||
private ImageView mIcon;
|
private ImageView mIcon;
|
||||||
|
|
||||||
public RingtoneFragment(ContentValues info, OnContentChangedListener listener, int stream){
|
public RingtoneFragment(ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream){
|
||||||
super();
|
super();
|
||||||
this.mListener = listener;
|
this.mChangedListener = changedListener;
|
||||||
this.mStream = stream;
|
this.mStream = stream;
|
||||||
this.mInfo = info;
|
this.mInfo = info;
|
||||||
|
this.mRemovedListener = removedListener;
|
||||||
|
|
||||||
switch(stream){
|
switch(stream){
|
||||||
case AudioManager.STREAM_NOTIFICATION:
|
case AudioManager.STREAM_NOTIFICATION:
|
||||||
@@ -102,11 +105,11 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void notifyRingtoneChanged(Uri tone) {
|
private void notifyRingtoneChanged(Uri tone) {
|
||||||
if(this.mListener != null){
|
if(this.mChangedListener != null){
|
||||||
ContentValues info = new ContentValues();
|
ContentValues info = new ContentValues();
|
||||||
info.put(this.mKeyUri, tone != null ? tone.toString() : null);
|
info.put(this.mKeyUri, tone != null ? tone.toString() : null);
|
||||||
info.put(mKeyEnabled, tone == null);
|
info.put(mKeyEnabled, tone == null);
|
||||||
this.mListener.onInfoContentChanged(info);
|
this.mChangedListener.onInfoContentChanged(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,10 +120,10 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
|||||||
*/
|
*/
|
||||||
private void notifyVolumeChanged(int progress) {
|
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));
|
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){
|
if(this.mChangedListener != null){
|
||||||
final ContentValues info = new ContentValues();
|
final ContentValues info = new ContentValues();
|
||||||
info.put(this.mKeyVolume, progress);
|
info.put(this.mKeyVolume, progress);
|
||||||
this.mListener.onInfoContentChanged(info);
|
this.mChangedListener.onInfoContentChanged(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +156,16 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getRingtoneURI(this.mType, mRingtoneURI);
|
switch(v.getId()){
|
||||||
|
case R.id.ringtone:
|
||||||
|
getRingtoneURI(this.mType, mRingtoneURI);
|
||||||
|
break;
|
||||||
|
case R.id.close:
|
||||||
|
if(this.mRemovedListener != null)
|
||||||
|
this.mRemovedListener.onFeatureRemoved(this);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -180,6 +192,8 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
|||||||
this.mRingtone.setOnClickListener(this);
|
this.mRingtone.setOnClickListener(this);
|
||||||
mVolume.setMax(audioManager.getStreamMaxVolume(mStream));
|
mVolume.setMax(audioManager.getStreamMaxVolume(mStream));
|
||||||
|
|
||||||
|
view.findViewById(R.id.close).setOnClickListener(this);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* volume
|
* volume
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||||
@@ -15,6 +16,7 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
@@ -26,35 +28,41 @@ import android.widget.ToggleButton;
|
|||||||
* A simple fragment that displays a toggle button and a title label
|
* A simple fragment that displays a toggle button and a title label
|
||||||
* @author ricky
|
* @author ricky
|
||||||
*/
|
*/
|
||||||
public class ToggleButtonFragment extends Fragment implements OnCheckedChangeListener {
|
public class ToggleButtonFragment extends Fragment implements OnCheckedChangeListener, OnClickListener {
|
||||||
|
|
||||||
private String mTitle;
|
private final String mTitle;
|
||||||
private String mKey;
|
private final String mKey;
|
||||||
private ContentValues mInfo;
|
private final ContentValues mInfo;
|
||||||
private OnContentChangedListener mListener;
|
private final OnContentChangedListener mChangedListener;
|
||||||
|
private final int mIcon;
|
||||||
|
private final FeatureRemovedListener mRemovedListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ToggleButtonFtagment
|
* Creates a new ToggleButtonFtagment
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public ToggleButtonFragment(String title, String key, ContentValues info, OnContentChangedListener listener) {
|
public ToggleButtonFragment(int icon, String title, String key, ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener) {
|
||||||
super();
|
super();
|
||||||
this.mTitle = title;
|
this.mTitle = title;
|
||||||
this.mKey = key;
|
this.mKey = key;
|
||||||
this.mInfo = info;
|
this.mInfo = info;
|
||||||
this.mListener = listener;
|
this.mChangedListener = changedListener;
|
||||||
|
this.mIcon = icon;
|
||||||
|
this.mRemovedListener = removedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
|
||||||
View view = inflater.inflate(R.layout.toggle_button_fragment, container, false);
|
final View view = inflater.inflate(R.layout.toggle_button_fragment, container, false);
|
||||||
TextView t = (TextView) view.findViewById(R.id.title);
|
final TextView t = (TextView) view.findViewById(R.id.title);
|
||||||
t.setText(this.mTitle);
|
t.setText(this.mTitle);
|
||||||
|
|
||||||
final ImageView icon = (ImageView) view.findViewById(R.id.icon);
|
final ImageView icon = (ImageView) view.findViewById(R.id.icon);
|
||||||
icon.setImageDrawable(this.getActivity().getResources().getDrawable(android.R.drawable.ic_lock_silent_mode_off));
|
icon.setImageDrawable(this.getActivity().getResources().getDrawable(mIcon));
|
||||||
|
|
||||||
ToggleButton b = (ToggleButton) view.findViewById(R.id.toggle);
|
view.findViewById(R.id.close).setOnClickListener(this);
|
||||||
|
|
||||||
|
final ToggleButton b = (ToggleButton) view.findViewById(R.id.toggle);
|
||||||
if(this.mInfo.containsKey(this.mKey))
|
if(this.mInfo.containsKey(this.mKey))
|
||||||
b.setChecked(RingerDatabase.parseBoolean(this.mInfo.getAsString(this.mKey)));
|
b.setChecked(RingerDatabase.parseBoolean(this.mInfo.getAsString(this.mKey)));
|
||||||
b.setOnCheckedChangeListener(this);
|
b.setOnCheckedChangeListener(this);
|
||||||
@@ -63,11 +71,21 @@ public class ToggleButtonFragment extends Fragment implements OnCheckedChangeLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if(this.mListener != null){
|
if(this.mChangedListener != null){
|
||||||
ContentValues info = new ContentValues();
|
ContentValues info = new ContentValues();
|
||||||
info.put(this.mKey, isChecked);
|
info.put(this.mKey, isChecked);
|
||||||
this.mListener.onInfoContentChanged(info);
|
this.mChangedListener.onInfoContentChanged(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the user clicks the remove button
|
||||||
|
* @param v
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if(this.mRemovedListener != null)
|
||||||
|
this.mRemovedListener.onFeatureRemoved(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,12 +16,14 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||||
@@ -31,31 +33,33 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
|||||||
* This fragment will represent the volume fragments
|
* This fragment will represent the volume fragments
|
||||||
* @author ricky
|
* @author ricky
|
||||||
*/
|
*/
|
||||||
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener {
|
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener, OnClickListener {
|
||||||
|
|
||||||
private static final String TAG = "VolumeFragment";
|
private static final String TAG = "VolumeFragment";
|
||||||
private final AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
private final int mStream;
|
private final int mStream;
|
||||||
private final OnContentChangedListener mListener;
|
private final OnContentChangedListener mChangedListener;
|
||||||
private final String mKey;
|
private final String mKey;
|
||||||
private final ContentValues mInfo;
|
private final ContentValues mInfo;
|
||||||
private final int mLabel;
|
private final int mLabel;
|
||||||
|
private final FeatureRemovedListener mRemovedListener;
|
||||||
private ImageView mIcon;
|
private ImageView mIcon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Volume Fragment
|
* Creates a new Volume Fragment
|
||||||
* @param info
|
* @param info
|
||||||
* @param context
|
* @param context
|
||||||
* @param listener
|
* @param changedListener
|
||||||
* @param stream
|
* @param stream
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public VolumeFragment(ContentValues info, Context context, OnContentChangedListener listener, int stream){
|
public VolumeFragment(ContentValues info, Context context, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, 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.mChangedListener = changedListener;
|
||||||
this.mInfo = info;
|
this.mInfo = info;
|
||||||
|
this.mRemovedListener = removedListener;
|
||||||
|
|
||||||
switch(this.mStream){
|
switch(this.mStream){
|
||||||
case AudioManager.STREAM_ALARM:
|
case AudioManager.STREAM_ALARM:
|
||||||
@@ -111,6 +115,8 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
|||||||
|
|
||||||
mIcon = (ImageView) view.findViewById(R.id.icon);
|
mIcon = (ImageView) view.findViewById(R.id.icon);
|
||||||
|
|
||||||
|
view.findViewById(R.id.close).setOnClickListener(this);
|
||||||
|
|
||||||
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
|
else
|
||||||
@@ -134,10 +140,10 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void notifyListener(final int progress) {
|
private void notifyListener(final int progress) {
|
||||||
if(this.mListener != null){
|
if(this.mChangedListener != null){
|
||||||
final ContentValues info = new ContentValues();
|
final ContentValues info = new ContentValues();
|
||||||
info.put(this.mKey, progress);
|
info.put(this.mKey, progress);
|
||||||
this.mListener.onInfoContentChanged(info);
|
this.mChangedListener.onInfoContentChanged(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,4 +157,14 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the user clicks on the remove button
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if(this.mRemovedListener != null)
|
||||||
|
this.mRemovedListener.onFeatureRemoved(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user