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
|
||||
* update interval
|
||||
*/
|
||||
ArrayList<Fragment> what = new ArrayList<Fragment>();
|
||||
ArrayList<Integer> added = new ArrayList<Integer>();
|
||||
|
||||
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));
|
||||
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));
|
||||
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);
|
||||
}
|
||||
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));
|
||||
// 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));
|
||||
// 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(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(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));
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
||||
private final int mLayout;
|
||||
|
||||
/**
|
||||
* Creates a new BaseFragmentListFragment
|
||||
* Creates a new Populated BaseFragmentListFragment
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public BaseFragmentListFragment(ArrayList<Fragment> fragments, int layout, int container) {
|
||||
@@ -42,6 +42,18 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
||||
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
|
||||
* @param fragment
|
||||
@@ -54,6 +66,31 @@ public abstract class BaseFragmentListFragment extends Fragment {
|
||||
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
|
||||
* @author ricky barrette
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.R;
|
||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
@@ -33,7 +34,7 @@ import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
*
|
||||
* @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 final ContentValues mInfo;
|
||||
@@ -48,10 +49,50 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
|
||||
* @author ricky barrette
|
||||
*/
|
||||
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;
|
||||
mListener = listener;
|
||||
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;
|
||||
switch(which){
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
// case 6:
|
||||
@@ -159,4 +200,15 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
|
||||
v.findViewById(R.id.add_feature_button).setOnClickListener(this);
|
||||
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.TextView;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.R;
|
||||
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 final int mStream;
|
||||
private final int mType;
|
||||
private final OnContentChangedListener mListener;
|
||||
private final OnContentChangedListener mChangedListener;
|
||||
private final String mKeyEnabled;
|
||||
private final String mKeyUri;
|
||||
private final String mKeyVolume;
|
||||
private final ContentValues mInfo;
|
||||
private final FeatureRemovedListener mRemovedListener;
|
||||
private final int mLabel;
|
||||
private EditText mRingtone;
|
||||
private Uri mRingtoneURI;
|
||||
private SeekBar mVolume;
|
||||
private ImageView mIcon;
|
||||
|
||||
public RingtoneFragment(ContentValues info, OnContentChangedListener listener, int stream){
|
||||
public RingtoneFragment(ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream){
|
||||
super();
|
||||
this.mListener = listener;
|
||||
this.mChangedListener = changedListener;
|
||||
this.mStream = stream;
|
||||
this.mInfo = info;
|
||||
this.mRemovedListener = removedListener;
|
||||
|
||||
switch(stream){
|
||||
case AudioManager.STREAM_NOTIFICATION:
|
||||
@@ -102,11 +105,11 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void notifyRingtoneChanged(Uri tone) {
|
||||
if(this.mListener != null){
|
||||
if(this.mChangedListener != null){
|
||||
ContentValues info = new ContentValues();
|
||||
info.put(this.mKeyUri, tone != null ? tone.toString() : 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) {
|
||||
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();
|
||||
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
|
||||
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
|
||||
@@ -180,6 +192,8 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
|
||||
this.mRingtone.setOnClickListener(this);
|
||||
mVolume.setMax(audioManager.getStreamMaxVolume(mStream));
|
||||
|
||||
view.findViewById(R.id.close).setOnClickListener(this);
|
||||
|
||||
/*
|
||||
* volume
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.FeatureRemovedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.R;
|
||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
@@ -15,6 +16,7 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
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
|
||||
* @author ricky
|
||||
*/
|
||||
public class ToggleButtonFragment extends Fragment implements OnCheckedChangeListener {
|
||||
public class ToggleButtonFragment extends Fragment implements OnCheckedChangeListener, OnClickListener {
|
||||
|
||||
private String mTitle;
|
||||
private String mKey;
|
||||
private ContentValues mInfo;
|
||||
private OnContentChangedListener mListener;
|
||||
private final String mTitle;
|
||||
private final String mKey;
|
||||
private final ContentValues mInfo;
|
||||
private final OnContentChangedListener mChangedListener;
|
||||
private final int mIcon;
|
||||
private final FeatureRemovedListener mRemovedListener;
|
||||
|
||||
/**
|
||||
* Creates a new ToggleButtonFtagment
|
||||
* @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();
|
||||
this.mTitle = title;
|
||||
this.mKey = key;
|
||||
this.mInfo = info;
|
||||
this.mListener = listener;
|
||||
this.mChangedListener = changedListener;
|
||||
this.mIcon = icon;
|
||||
this.mRemovedListener = removedListener;
|
||||
}
|
||||
|
||||
@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.title);
|
||||
final View view = inflater.inflate(R.layout.toggle_button_fragment, container, false);
|
||||
final 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));
|
||||
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))
|
||||
b.setChecked(RingerDatabase.parseBoolean(this.mInfo.getAsString(this.mKey)));
|
||||
b.setOnCheckedChangeListener(this);
|
||||
@@ -63,11 +71,21 @@ public class ToggleButtonFragment extends Fragment implements OnCheckedChangeLis
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(this.mListener != null){
|
||||
if(this.mChangedListener != null){
|
||||
ContentValues info = new ContentValues();
|
||||
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.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
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.FeatureRemovedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||
import com.TwentyCodes.android.LocationRinger.R;
|
||||
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
|
||||
* @author ricky
|
||||
*/
|
||||
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener {
|
||||
public class VolumeFragment extends Fragment implements OnSeekBarChangeListener, OnClickListener {
|
||||
|
||||
private static final String TAG = "VolumeFragment";
|
||||
private final AudioManager mAudioManager;
|
||||
private final int mStream;
|
||||
private final OnContentChangedListener mListener;
|
||||
private final OnContentChangedListener mChangedListener;
|
||||
private final String mKey;
|
||||
private final ContentValues mInfo;
|
||||
private final int mLabel;
|
||||
private final FeatureRemovedListener mRemovedListener;
|
||||
private ImageView mIcon;
|
||||
|
||||
/**
|
||||
* Creates a new Volume Fragment
|
||||
* @param info
|
||||
* @param context
|
||||
* @param listener
|
||||
* @param changedListener
|
||||
* @param stream
|
||||
* @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();
|
||||
this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
this.mStream = stream;
|
||||
this.mListener = listener;
|
||||
this.mChangedListener = changedListener;
|
||||
this.mInfo = info;
|
||||
this.mRemovedListener = removedListener;
|
||||
|
||||
switch(this.mStream){
|
||||
case AudioManager.STREAM_ALARM:
|
||||
@@ -111,6 +115,8 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
||||
|
||||
mIcon = (ImageView) view.findViewById(R.id.icon);
|
||||
|
||||
view.findViewById(R.id.close).setOnClickListener(this);
|
||||
|
||||
if(this.mInfo.containsKey(this.mKey))
|
||||
volume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKey)));
|
||||
else
|
||||
@@ -134,10 +140,10 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void notifyListener(final int progress) {
|
||||
if(this.mListener != null){
|
||||
if(this.mChangedListener != null){
|
||||
final ContentValues info = new ContentValues();
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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