Merge branch 'Feature/#73'

This commit is contained in:
2012-05-26 19:19:31 -04:00
15 changed files with 557 additions and 215 deletions

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/title_bar"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@android:drawable/ic_menu_close_clear_cancel" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="test"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@android:drawable/stat_sys_data_bluetooth" />
</RelativeLayout>

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -4,14 +4,12 @@
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/label"
<include
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@android:drawable/title_bar"
android:text="@string/ringtone_options"
android:textColor="#FFFFFF" />
layout="@layout/feature_title_bar" />
<EditText
android:id="@+id/ringtone"

View File

@@ -4,14 +4,12 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/label"
<include
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@android:drawable/title_bar"
android:text="@string/ringtone_options"
android:textColor="#FFFFFF" />
layout="@layout/feature_title_bar" />
<ToggleButton
android:id="@+id/toggle"

View File

@@ -4,14 +4,12 @@
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/volume_label"
<include
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@android:drawable/title_bar"
android:text="@string/volume"
android:textColor="#FFFFFF" />
layout="@layout/feature_title_bar" />
<SeekBar
android:id="@+id/volume"

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

@@ -19,4 +19,5 @@ public interface OnContentChangedListener {
void onInfoContentChanged(ContentValues info);
void onInfoContentRemoved(String... keys);
}

View File

@@ -38,10 +38,10 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
public class RingerDatabase {
private static final String TAG = "RingerDatabase";
private Context mContext;
private final Context mContext;
private SQLiteDatabase mDb;
private final DatabaseListener mListener;
public boolean isUpgrading = false;
private DatabaseListener mListener;
/*
* database information values
@@ -109,7 +109,7 @@ public class RingerDatabase {
*/
private void convert2to3(SQLiteDatabase db){
//get all the ringer information from the old table
Cursor cursor = db.query("two", new String[] { KEY_RINGER_NAME, KEY_RINGTONE,
final Cursor cursor = db.query("two", new String[] { KEY_RINGER_NAME, KEY_RINGTONE,
KEY_NOTIFICATION_RINGTONE, KEY_RINGTONE_IS_SILENT,
KEY_NOTIFICATION_IS_SILENT, KEY_IS_ENABLED,
KEY_RADIUS, KEY_LOCATION_LAT, KEY_LOCATION_LON,
@@ -124,7 +124,7 @@ public class RingerDatabase {
int count = cursor.getColumnCount();
if (cursor.moveToFirst()) {
do {
ContentValues ringer = new ContentValues();
final ContentValues ringer = new ContentValues();
if(Debug.DEBUG)
Log.v(TAG, "Converting: " + cursor.getString(0));
for(int i = 0; i < count; i++){
@@ -278,10 +278,15 @@ public class RingerDatabase {
* @author ricky barrette
*/
public RingerDatabase(Context context){
this.mContext = context;
this.mDb = new OpenHelper(this.mContext).getWritableDatabase();
this(context, null);
}
/**
* Creates a new RingerDatabase
* @param context
* @param listener
* @author ricky barrette
*/
public RingerDatabase(Context context, DatabaseListener listener){
this.mListener = listener;
this.mContext = context;
@@ -308,13 +313,14 @@ public class RingerDatabase {
* @author ricky barrette
*/
public boolean backup(){
File dbFile = new File(Environment.getDataDirectory() + "/data/"+mContext.getPackageName()+"/databases/"+DATABASE_NAME);
final File dbFile = new File(Environment.getDataDirectory() + "/data/"+mContext.getPackageName()+"/databases/"+DATABASE_NAME);
File exportDir = new File(Environment.getExternalStorageDirectory(), "/"+this.mContext.getString(R.string.app_name));
final File exportDir = new File(Environment.getExternalStorageDirectory(), "/"+this.mContext.getString(R.string.app_name));
if (!exportDir.exists()) {
exportDir.mkdirs();
}
File file = new File(exportDir, dbFile.getName());
final File file = new File(exportDir, dbFile.getName());
try {
file.createNewFile();
@@ -331,9 +337,9 @@ public class RingerDatabase {
* @param name
* @return
*/
private String checkRingerName(String name){
private String checkRingerName(final String name){
List<String> names = this.getAllRingerTitles();
final List<String> names = this.getAllRingerTitles();
String ringerName = name;
int count = 1;
@@ -344,8 +350,6 @@ public class RingerDatabase {
}
}
return ringerName;
// return checkRingerName(name, 0);
}
/**
@@ -355,9 +359,9 @@ public class RingerDatabase {
* @throws IOException
* @author ricky barrette
*/
private void copyFile(File src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
private void copyFile(final File src, final File dst) throws IOException {
final FileChannel inChannel = new FileInputStream(src).getChannel();
final FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
@@ -421,8 +425,8 @@ public class RingerDatabase {
* @author ricky barrette
*/
public List<String> getAllRingerTitles() {
List<String> list = new ArrayList<String>();
Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { KEY_RINGER_NAME }, null, null, null, null, null);
final List<String> list = new ArrayList<String>();
final Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { KEY_RINGER_NAME }, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
list.add(cursor.getString(0));
@@ -440,8 +444,8 @@ public class RingerDatabase {
* @author ricky barrette
*/
public List<String> getAllRingerDescriptions() {
List<String> list = new ArrayList<String>();
List<String> ringers = getAllRingerTitles();
final List<String> list = new ArrayList<String>();
final List<String> ringers = getAllRingerTitles();
for(String ringer: ringers){
list.add(getRingerInfo(ringer).getAsString(KEY_RINGER_DESCRIPTION));
}
@@ -464,9 +468,9 @@ public class RingerDatabase {
* @return
* @author ricky barrette
*/
public ContentValues getRingerInfo(String ringerName){
ContentValues values = new ContentValues();
Cursor info = this.mDb.query(RINGER_INFO_TABLE, new String[]{ KEY, KEY_VALUE }, KEY_RINGER_NAME +" = "+ DatabaseUtils.sqlEscapeString(ringerName), null, null, null, null);
public ContentValues getRingerInfo(final String ringerName){
final ContentValues values = new ContentValues();
final Cursor info = this.mDb.query(RINGER_INFO_TABLE, new String[]{ KEY, KEY_VALUE }, KEY_RINGER_NAME +" = "+ DatabaseUtils.sqlEscapeString(ringerName), null, null, null, null);
if (info.moveToFirst()) {
do {
values.put(info.getString(0), info.getString(1));
@@ -484,9 +488,9 @@ public class RingerDatabase {
* @return ringer's name
* @author ricky barrette
*/
public String getRingerName(long id) {
public String getRingerName(final long id) {
String name = null;
Cursor cursor = this.mDb.query(RINGER_TABLE, new String[]{ KEY_RINGER_NAME }, "id = "+id, null, null, null, null);;
final Cursor cursor = this.mDb.query(RINGER_TABLE, new String[]{ KEY_RINGER_NAME }, "id = "+id, null, null, null, null);;
if (cursor.moveToFirst()) {
name = cursor.getString(0);
}
@@ -502,14 +506,14 @@ public class RingerDatabase {
* @param ringerInfo values
* @author ricky barrette
*/
public void insertRinger(ContentValues ringer, ContentValues ringerInfo){
public void insertRinger(final ContentValues ringer, final ContentValues ringerInfo){
ringer.put(RingerDatabase.KEY_RINGER_NAME, checkRingerName(ringer.getAsString(RingerDatabase.KEY_RINGER_NAME)));
mDb.insert(RINGER_TABLE, null, ringer);
String ringerName = ringer.getAsString(RingerDatabase.KEY_RINGER_NAME);
final String ringerName = ringer.getAsString(RingerDatabase.KEY_RINGER_NAME);
//insert the information values
for(Entry<String, Object> item : ringerInfo.valueSet()){
ContentValues values = new ContentValues();
for(final Entry<String, Object> item : ringerInfo.valueSet()){
final ContentValues values = new ContentValues();
values.put(KEY_RINGER_NAME, ringerName);
values.put(KEY, item.getKey());
/*
@@ -540,8 +544,8 @@ public class RingerDatabase {
* @return true if the ringer is enabled
* @author ricky barrette
*/
public boolean isRingerEnabled(long id) {
Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { KEY_IS_ENABLED }, "id = "+id, null, null, null, null);
public boolean isRingerEnabled(final long id) {
final Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { KEY_IS_ENABLED }, "id = "+id, null, null, null, null);
if (cursor.moveToFirst()) {
if(Debug.DEBUG)
Log.d(TAG, "isRingerEnabled("+id+") = "+ cursor.getString(0));
@@ -556,13 +560,14 @@ public class RingerDatabase {
* @author ricky barrette
*/
public void restore(){
File dbFile = new File(Environment.getDataDirectory() + "/data/"+mContext.getPackageName()+"/databases/"+DATABASE_NAME);
final File dbFile = new File(Environment.getDataDirectory() + "/data/"+mContext.getPackageName()+"/databases/"+DATABASE_NAME);
File exportDir = new File(Environment.getExternalStorageDirectory(), "/"+this.mContext.getString(R.string.app_name));
final File exportDir = new File(Environment.getExternalStorageDirectory(), "/"+this.mContext.getString(R.string.app_name));
if (!exportDir.exists()) {
exportDir.mkdirs();
}
File file = new File(exportDir, dbFile.getName());
final File file = new File(exportDir, dbFile.getName());
try {
file.createNewFile();
@@ -580,10 +585,10 @@ public class RingerDatabase {
this.mListener.onRestoreComplete();
}
public int setRingerEnabled(long id, boolean enabled) {
public int setRingerEnabled(final long id, final boolean enabled) {
if(Debug.DEBUG)
Log.d(TAG, "setRingerEnabled("+id+") = "+ enabled);
ContentValues values = new ContentValues();
final ContentValues values = new ContentValues();
values.put(KEY_IS_ENABLED, enabled);
return mDb.update(RINGER_TABLE, values, "id" + "= "+ id, null);
}
@@ -595,19 +600,38 @@ public class RingerDatabase {
* @param info values
* @author ricky barrette
*/
public void updateRinger(long id, ContentValues ringer, ContentValues info) throws NullPointerException{
public void updateRinger(final long id, final ContentValues ringer, final ContentValues info) throws NullPointerException{
if(ringer == null || info == null)
throw new NullPointerException("ringer content was null");
String ringer_name = getRingerName(id);
final String ringer_name = getRingerName(id);
/*
* here we retrive the old values.
* we will compare the old value against the new values.
* we will delete all values that are NOT included in the new values.
*/
final ContentValues old = getRingerInfo(ringer_name);
for(final Entry<String, Object> item : info.valueSet()){
if(old.containsKey(item.getKey()))
old.remove(item.getKey());
}
for(final Entry<String, Object> item : old.valueSet()){
RingerDatabase.this.mDb.delete(RINGER_INFO_TABLE, KEY +" = "+ DatabaseUtils.sqlEscapeString(item.getKey()) +" and "+ KEY_RINGER_NAME +" = "+DatabaseUtils.sqlEscapeString(ringer_name), null);
}
/*
* here we want to update the ringer name if needed
*/
if(!ringer_name.equals(ringer.getAsString(RingerDatabase.KEY_RINGER_NAME)))
ringer.put(RingerDatabase.KEY_RINGER_NAME, checkRingerName(ringer.getAsString(RingerDatabase.KEY_RINGER_NAME)));
//update the information values in the info table
for(Entry<String, Object> item : info.valueSet()){
ContentValues values = new ContentValues();
/*
* here we wanr to update the information values in the info table
*/
for(final Entry<String, Object> item : info.valueSet()){
final ContentValues values = new ContentValues();
values.put(KEY_RINGER_NAME, ringer.getAsString(KEY_RINGER_NAME));
values.put(KEY, item.getKey());
try {
@@ -619,7 +643,11 @@ public class RingerDatabase {
values.put(KEY_VALUE, (Integer) item.getValue());
}
}
//try to update, if update fails insert
/*
* here we are going to try to update a row,
* if that fails we will insert a row insead
*/
if(!(mDb.update(RINGER_INFO_TABLE, values, KEY_RINGER_NAME + "="+ DatabaseUtils.sqlEscapeString(ringer_name) +" AND " + KEY +"='"+ item.getKey()+"'", null) > 0))
mDb.insert(RINGER_INFO_TABLE, null, values);
}
@@ -636,7 +664,7 @@ public class RingerDatabase {
private void updateRowIds(long id) {
long currentRow;
ContentValues values = new ContentValues();
Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { "id" },null, null, null, null, null);
final Cursor cursor = this.mDb.query(RINGER_TABLE, new String[] { "id" },null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
currentRow = cursor.getLong(0);

View File

@@ -14,7 +14,6 @@ import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Looper;
import android.support.v4.app.Fragment;
@@ -35,9 +34,6 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
import com.TwentyCodes.android.LocationRinger.ui.fragments.AboutRingerFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.FeatureListFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.LocationInfomationFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.RingtoneFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.ToggleButtonFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.VolumeFragment;
import com.jakewharton.android.viewpagerindicator.TitlePageIndicator;
import com.jakewharton.android.viewpagerindicator.TitledFragmentAdapter;
@@ -63,12 +59,16 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
Log.d(TAG, item.getKey() +" = "+ item.getValue());
}
/**
* Called when the activity is first created
* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.ringer_information_activity);
/*
* Set up the action bar if required
*/
@@ -112,47 +112,7 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
if(!isDefault)
fragments.add(new LocationInfomationFragment(this.mInfo, this, this));
/*
* What page
* ONLY Dynamically add the required fragments that have already been added.
*
* 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);
}
fragments.add(new FeatureListFragment(this.mInfo, this, what, added));
fragments.add(new FeatureListFragment(this.mInfo, this));
//Populate the pager
this.mPager = (ViewPager)findViewById(R.id.pager);
@@ -165,11 +125,6 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
indicator.setViewPager(this.mPager);
indicator.setOnPageChangeListener(this);
/*
* TODO
* button bar
*/
}
/**
@@ -182,6 +137,11 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
return super.onCreateOptionsMenu(menu);
}
/**
* Called when the ringer info has changed
* (non-Javadoc)
* @see com.TwentyCodes.android.LocationRinger.OnContentChangedListener#onInfoContentChanged(android.content.ContentValues)
*/
@Override
public void onInfoContentChanged(ContentValues values) {
if(Debug.DEBUG){
@@ -229,10 +189,13 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
/**
* Called when the ringer content has been changed
* (non-Javadoc)
* @see com.TwentyCodes.android.LocationRinger.OnContentChangedListener#onRingerContentChanged(android.content.ContentValues)
*/
@Override
public void onRingerContentChanged(ContentValues values) {
if(Debug.DEBUG){
@@ -262,9 +225,26 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
}).start();
}
/**
* Called when the scrolling state of the view pager is changed
* (non-Javadoc)
* @see com.TwentyCodes.android.LocationRinger.EnableScrollingListener#setScrollEnabled(boolean)
*/
@Override
public void setScrollEnabled(boolean enabled) {
this.mPager.setScrollEnabled(enabled);
}
/**
* Called when a feature is removed
* (non-Javadoc)
* @see com.TwentyCodes.android.LocationRinger.OnContentChangedListener#onInfoContentRemoved(java.lang.String[])
*/
@Override
public void onInfoContentRemoved(String... keys) {
for(String key : keys)
if(this.mInfo.containsKey(key))
this.mInfo.remove(key);
}
}

View File

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

View File

@@ -22,38 +22,132 @@ 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;
/**
* This fragment will be used to display a list of features
* TODO
* + create button bar that had a plus button and a hint + add/remove features
*
* @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 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 final ContentValues mInfo;
private final OnContentChangedListener mListener;
private final ArrayList<Integer> mAdded;
/**
* Creates a new FeatureListFragment
* Creates a new populated FeatureListFragment
* @param info
* @param listener
* @param fragments
* @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);
if ( info == null )
throw new NullPointerException();
if ( listener == null )
throw new NullPointerException();
if ( fragments == null )
throw new NullPointerException();
if ( added == null )
throw new NullPointerException();
mInfo = info;
mListener = listener;
mAdded = added;
}
/**
* Creates a new empty feature list fragment
* @param info
* @param listener
* @author ricky barrette
*/
public FeatureListFragment(ContentValues info, OnContentChangedListener listener){
this(info, listener, new ArrayList<Fragment>(), new ArrayList<Integer>());
}
/**
* Initializes a feature fragment
* @param fragmentCode
* @return
* @author ricky barrette
*/
public Fragment initFeatureFragment(int fragmentCode){
Fragment f = null;
switch(fragmentCode){
case KEY_ADDED_RINGTONE:
f= new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_RING, KEY_ADDED_RINGTONE);
mAdded.add(KEY_ADDED_RINGTONE);
break;
case KEY_ADDED_NOTIFICATIONTONE:
f = new RingtoneFragment(this.mInfo, this.mListener, this, AudioManager.STREAM_NOTIFICATION, KEY_ADDED_NOTIFICATIONTONE);
mAdded.add(KEY_ADDED_NOTIFICATIONTONE);
break;
case KEY_ADDED_ALARM_VOLUME:
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 KEY_ADDED_MUSIC_VOLUME:
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 KEY_ADDED_BT:
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 KEY_ADDED_WIFI:
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;
}
/**
* Initializes feature fragments based upon current records
* @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(initFeatureFragment(KEY_ADDED_RINGTONE));
}
if(this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_IS_SILENT) || this.mInfo.containsKey(RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME)){
what.add(initFeatureFragment(KEY_ADDED_NOTIFICATIONTONE));
}
if(this.mInfo.containsKey(RingerDatabase.KEY_ALARM_VOLUME)){
what.add(initFeatureFragment(KEY_ADDED_ALARM_VOLUME));
}
if(this.mInfo.containsKey(RingerDatabase.KEY_MUSIC_VOLUME)){
what.add(initFeatureFragment(KEY_ADDED_MUSIC_VOLUME));
}
if(this.mInfo.containsKey(RingerDatabase.KEY_BT)){
what.add(initFeatureFragment(KEY_ADDED_BT));
}
if(this.mInfo.containsKey(RingerDatabase.KEY_WIFI)){
what.add(initFeatureFragment(KEY_ADDED_WIFI));
}
return what;
}
/**
* Called when an item is picked from the add featue list
* (non-Javadoc)
@@ -61,37 +155,7 @@ 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, 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;
}
final Fragment f = initFeatureFragment(which);
if(f != null)
add(f);
}
@@ -150,6 +214,18 @@ public class FeatureListFragment extends BaseFragmentListFragment implements OnC
}
/**
* Called when the activity is first created
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle arg0) {
addAllInit(initList());
super.onCreate(arg0);
}
/**
* Called when the view needs to be created
* (non-Javadoc)
* @see com.TwentyCodes.android.LocationRinger.ui.fragments.BaseFragmentListFragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@@ -159,4 +235,43 @@ 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);
if(f instanceof IdFragment){
final int id = ((IdFragment) f).getFragmentId();
mAdded.remove(new Integer(id));
/*
* we need to notify our parent activity that the feature have been removed.
*/
switch(id){
case KEY_ADDED_RINGTONE:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_RINGTONE_URI, RingerDatabase.KEY_RINGTONE_IS_SILENT, RingerDatabase.KEY_RINGTONE_VOLUME);
break;
case KEY_ADDED_NOTIFICATIONTONE:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_NOTIFICATION_RINGTONE_URI, RingerDatabase.KEY_NOTIFICATION_IS_SILENT, RingerDatabase.KEY_NOTIFICATION_RINGTONE_VOLUME);
break;
case KEY_ADDED_ALARM_VOLUME:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_ALARM_VOLUME);
break;
case KEY_ADDED_MUSIC_VOLUME:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_MUSIC_VOLUME);
break;
case KEY_ADDED_BT:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_BT);
break;
case KEY_ADDED_WIFI:
this.mListener.onInfoContentRemoved(RingerDatabase.KEY_WIFI);
break;
}
}
}
}

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

@@ -17,17 +17,18 @@ import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
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.EditText;
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;
@@ -37,26 +38,37 @@ 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;
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){
super();
this.mListener = listener;
public RingtoneFragment(ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream, int id){
super(id);
if ( info == null )
throw new NullPointerException();
if ( changedListener == null )
throw new NullPointerException();
if ( removedListener == null )
throw new NullPointerException();
this.mChangedListener = changedListener;
this.mStream = stream;
this.mInfo = info;
this.mRemovedListener = removedListener;
switch(stream){
case AudioManager.STREAM_NOTIFICATION:
@@ -100,11 +112,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);
}
}
@@ -114,10 +126,11 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
* @author ricky barrette
*/
private void notifyVolumeChanged(int progress) {
if(this.mListener != null){
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.mChangedListener != null){
final ContentValues info = new ContentValues();
info.put(this.mKeyVolume, progress);
this.mListener.onInfoContentChanged(info);
this.mChangedListener.onInfoContentChanged(info);
}
}
@@ -133,6 +146,7 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
this.mRingtone.setText(R.string.silent);
mVolume.setEnabled(false);
mVolume.setProgress(0);
notifyVolumeChanged(0);
} else {
mVolume.setEnabled(true);
Ringtone ringtone = RingtoneManager.getRingtone(this.getActivity(), Uri.parse(tone.toString()));
@@ -149,7 +163,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
@@ -164,15 +187,30 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
/*
* initialize the views
*/
final TextView label = (TextView) view.findViewById(R.id.label);
final TextView label = (TextView) view.findViewById(R.id.title);
label.setText(mLabel);
mIcon = (ImageView) view.findViewById(R.id.icon);
mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(android.R.drawable.ic_lock_silent_mode_off));
this.mRingtone = (EditText) view.findViewById(R.id.ringtone);
mVolume = (SeekBar) view.findViewById(R.id.ringtone_volume);
this.mRingtone.setOnClickListener(this);
mVolume.setMax(audioManager.getStreamMaxVolume(mStream));
view.findViewById(R.id.close).setOnClickListener(this);
/*
* volume
*/
if(this.mInfo.containsKey(this.mKeyVolume))
mVolume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKeyVolume)));
else {
mVolume.setProgress(audioManager.getStreamVolume(mStream));
notifyVolumeChanged(audioManager.getStreamVolume(mStream));
}
/*
* ringtone & uri
*/
@@ -196,15 +234,7 @@ public class RingtoneFragment extends Fragment implements OnClickListener, OnSee
mVolume.setProgress(0);
}
/*
* volume
*/
if(this.mInfo.containsKey(this.mKeyVolume))
mVolume.setProgress(Integer.parseInt(this.mInfo.getAsString(this.mKeyVolume)));
else {
mVolume.setProgress(audioManager.getStreamVolume(mStream));
notifyVolumeChanged(audioManager.getStreamVolume(mStream));
}
mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(mVolume.getProgress() == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off));
mVolume.setOnSeekBarChangeListener(this);
return view;

View File

@@ -6,64 +6,107 @@
*/
package com.TwentyCodes.android.LocationRinger.ui.fragments;
import com.TwentyCodes.android.LocationRinger.R;
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
import android.content.ContentValues;
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;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
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;
/**
* 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 IdFragment 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) {
super();
public ToggleButtonFragment(int icon, String title, String key, ContentValues info, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int id) {
super(id);
if ( info == null )
throw new NullPointerException();
if (title == null )
throw new NullPointerException();
if ( key == null )
throw new NullPointerException();
if ( changedListener == null )
throw new NullPointerException();
if ( removedListener == null )
throw new NullPointerException();
this.mTitle = title;
this.mKey = key;
this.mInfo = info;
this.mListener = listener;
this.mChangedListener = changedListener;
this.mIcon = icon;
this.mRemovedListener = removedListener;
}
/**
* Called when the fragment's view needs to be created
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@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.label);
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);
ToggleButton b = (ToggleButton) view.findViewById(R.id.toggle);
final ImageView icon = (ImageView) view.findViewById(R.id.icon);
icon.setImageDrawable(this.getActivity().getResources().getDrawable(mIcon));
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);
return view;
}
/**
* Called when the toggle button is clicked
* (non-Javadoc)
* @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
*/
@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);
}
}

View File

@@ -12,17 +12,19 @@ import android.content.ContentValues;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
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.R;
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;
import com.TwentyCodes.android.LocationRinger.debug.Debug;
@@ -30,30 +32,43 @@ 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 IdFragment 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){
super();
public VolumeFragment(ContentValues info, Context context, OnContentChangedListener changedListener, FeatureRemovedListener removedListener, int stream, int id){
super(id);
if ( info == null )
throw new NullPointerException();
if ( context == null )
throw new NullPointerException();
if ( changedListener == null )
throw new NullPointerException();
if ( removedListener == null )
throw new NullPointerException();
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:
@@ -91,6 +106,11 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
}
}
/**
* Called when the fragment's view needs to be created
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -98,27 +118,34 @@ public class VolumeFragment extends Fragment implements OnSeekBarChangeListener
for(Entry<String,Object> item : this.mInfo.valueSet())
Log.d(TAG, item.getKey() +" = "+ item.getValue());
View view = inflater.inflate(R.layout.volume_fragment, container, false);
TextView label = (TextView) view.findViewById(R.id.volume_label);
SeekBar volume = (SeekBar) view.findViewById(R.id.volume);
final View view = inflater.inflate(R.layout.volume_fragment, container, false);
final TextView label = (TextView) view.findViewById(R.id.title);
final SeekBar volume = (SeekBar) view.findViewById(R.id.volume);
volume.setMax(this.mAudioManager.getStreamMaxVolume(mStream));
volume.setProgress(this.mAudioManager.getStreamVolume(mStream));
volume.setOnSeekBarChangeListener(this);
label.setText(mLabel);
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
notifyListener(this.mAudioManager.getStreamVolume(mStream));
mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(volume.getProgress() == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off));
return view;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser)
if(fromUser){
notifyListener(progress);
mIcon.setImageDrawable(this.getActivity().getResources().getDrawable(progress == 0 ? android.R.drawable.ic_lock_silent_mode : android.R.drawable.ic_lock_silent_mode_off));
}
}
/**
@@ -127,21 +154,29 @@ 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);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// 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);
}
}