Merge branch 'Support/#46'
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical"
|
android:layout_height="wrap_content" >
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/fragment_list_contianer"
|
|
||||||
>
|
|
||||||
|
|
||||||
</LinearLayout>
|
<LinearLayout
|
||||||
|
android:id="@+id/fragment_list_contianer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
@@ -7,19 +7,17 @@
|
|||||||
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
@@ -27,66 +25,122 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display a list of fragments
|
* This fragment will be used to display a list of fragments
|
||||||
*
|
* TODO
|
||||||
* TODO + create button bar that had a plus button and a hint + add/remove
|
* + create button bar that had a plus button and a hint + add/remove features
|
||||||
* features
|
|
||||||
*
|
*
|
||||||
* @author ricky
|
* @author ricky
|
||||||
*/
|
*/
|
||||||
public class FeatureListFragment extends ListFragment {
|
public class FeatureListFragment extends Fragment {
|
||||||
|
|
||||||
|
private static final String TAG = "FeatureListFragment";
|
||||||
|
private final ArrayList<Fragment> mFragments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new FeatureListFragment
|
||||||
|
* @param info
|
||||||
|
* @param listener
|
||||||
|
* @param fragments
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public FeatureListFragment(ContentValues info, OnContentChangedListener listener, ArrayList<Fragment> fragments) {
|
||||||
|
super();
|
||||||
|
mFragments = fragments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the fragment to the list
|
||||||
|
* @param fragment
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void add(final Fragment fragment){
|
||||||
|
this.mFragments.add(fragment);
|
||||||
|
final FragmentTransaction transaction = this.getFragmentManager().beginTransaction();
|
||||||
|
transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag());
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all the fragments
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private void loadFragments() {
|
||||||
|
final FragmentTransaction transaction = this.getFragmentManager().beginTransaction();
|
||||||
|
for(Fragment fragment : this.mFragments)
|
||||||
|
transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag());
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.Fragment#onActivityResult(int, int, android.content.Intent)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int arg0, int arg1, Intent arg2) {
|
||||||
|
removeFragments();
|
||||||
|
loadFragments();
|
||||||
|
super.onActivityResult(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
|
||||||
* @see android.support.v4.app.ListFragment#onCreateView(android.view.LayoutInflater,
|
* @see android.support.v4.app.ListFragment#onCreateView(android.view.LayoutInflater,
|
||||||
* android.view.ViewGroup, android.os.Bundle)
|
* android.view.ViewGroup, android.os.Bundle)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflator, ViewGroup container,
|
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle bundle) {
|
||||||
Bundle bundle) {
|
return inflator.inflate(R.layout.fragment_list_contianer, null);
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return super.onCreateView(inflator, container, bundle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = "FeatureListFragment";
|
/**
|
||||||
private static final int DELETE_ID = 0;
|
* (non-Javadoc)
|
||||||
private ArrayList<Fragment> mFeatures;
|
* @see android.support.v4.app.Fragment#onPause()
|
||||||
|
*/
|
||||||
// private OnContentChangedListener mListener;
|
@Override
|
||||||
// private ContentValues mInfo;
|
public void onPause() {
|
||||||
// private int mIndex;
|
try{
|
||||||
|
removeFragments();
|
||||||
public FeatureListFragment(ContentValues info,
|
} catch(IllegalStateException e){
|
||||||
OnContentChangedListener listener, ArrayList<Fragment> fragments) {
|
e.printStackTrace();
|
||||||
super();
|
//do nothing
|
||||||
this.mFeatures = fragments;
|
}
|
||||||
// this.mInfo = info;
|
Collections.reverse(this.mFragments);
|
||||||
// this.mListener = listener;
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.support.v4.app.Fragment#onResume()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
this.setListAdapter(new FragmentListAdaptor(this, mFeatures));
|
|
||||||
this.getListView().setOnCreateContextMenuListener(this);
|
|
||||||
if (Debug.DEBUG)
|
if (Debug.DEBUG)
|
||||||
Log.v(TAG, "onResume()");
|
Log.v(TAG, "onResume()");
|
||||||
|
loadFragments();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
/**
|
||||||
ContextMenuInfo menuInfo) {
|
* Removes a fragment from the list
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
* @param fragment
|
||||||
menu.add(0, DELETE_ID, 0, R.string.delete).setIcon(
|
* @author ricky barrette
|
||||||
android.R.drawable.ic_menu_delete);
|
*/
|
||||||
|
public void remove(final Fragment fragment){
|
||||||
|
this.mFragments.remove(fragment);
|
||||||
|
final FragmentTransaction transaction = this.getFragmentManager().beginTransaction();
|
||||||
|
transaction.remove(fragment);
|
||||||
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
/**
|
||||||
switch (item.getItemId()) {
|
* Removes all fragments from the the view
|
||||||
case DELETE_ID:
|
* @throws IllegalStateException
|
||||||
Toast.makeText(this.getActivity(), "deleted! (note really)",
|
* @author ricky barrette
|
||||||
Toast.LENGTH_LONG).show();
|
*/
|
||||||
return true;
|
private void removeFragments() throws IllegalStateException {
|
||||||
|
final FragmentTransaction transaction = this.getFragmentManager().beginTransaction();
|
||||||
|
for(Fragment fragment : this.mFragments){
|
||||||
|
transaction.remove(fragment);
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
transaction.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
/**
|
|
||||||
* FragmentListAdaptor.java
|
|
||||||
* @date Dec 24, 2011
|
|
||||||
* @author ricky barrette
|
|
||||||
* @author Twenty Codes, LLC
|
|
||||||
*/
|
|
||||||
package com.TwentyCodes.android.LocationRinger.ui.fragments;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.FragmentManager;
|
|
||||||
import android.support.v4.app.FragmentTransaction;
|
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
|
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
|
||||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This Adaptor Class will be used to display fragments in a ListFragment.
|
|
||||||
* TODO
|
|
||||||
* + Get this code working
|
|
||||||
* + Add/Remove fragments on the fly
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public class FragmentListAdaptor extends BaseAdapter {
|
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
|
||||||
private ArrayList<Fragment> mFragments;
|
|
||||||
private FragmentManager mFragmentManager;
|
|
||||||
private final String TAG = "FragmentListAdaptor";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new FragmentListAdaptor
|
|
||||||
* @param listFragment
|
|
||||||
* @param fragments
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public FragmentListAdaptor(ListFragment listFragment, ArrayList<Fragment> fragments) {
|
|
||||||
if(Debug.DEBUG)
|
|
||||||
Log.v(TAG, "FragmentListAdaptor()");
|
|
||||||
mInflater = LayoutInflater.from(listFragment.getActivity());
|
|
||||||
mFragments = fragments;
|
|
||||||
mFragmentManager = listFragment.getFragmentManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of Fragments to display
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.widget.Adapter#getCount()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
if(Debug.DEBUG)
|
|
||||||
Log.v(TAG, "getCount() :"+ mFragments.size());
|
|
||||||
return mFragments.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the fragment to display
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.widget.Adapter#getItem(int)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
if(Debug.DEBUG)
|
|
||||||
Log.v(TAG, "getItem("+position+")");
|
|
||||||
return mFragments.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the id of the fragment being displayed
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.widget.Adapter#getItemId(int)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
if(Debug.DEBUG)
|
|
||||||
Log.v(TAG, "getView("+position+")");
|
|
||||||
FragmentTransaction transaction = mFragmentManager.beginTransaction();
|
|
||||||
|
|
||||||
// A Holder keeps references to children views to avoid unnecessary calls to findViewById() on each row.
|
|
||||||
Holder holder;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When convertView is not null, we can reuse it directly, there is no need
|
|
||||||
* to reinflate it. We only inflate a new View when the convertView supplied
|
|
||||||
* by ListView is null.
|
|
||||||
*/
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = mInflater.inflate(R.layout.fragment_container, null);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Creates a ViewHolder and store references
|
|
||||||
* that we want to bind data to.
|
|
||||||
*/
|
|
||||||
holder = new Holder();
|
|
||||||
holder.view = (View) convertView.findViewById(R.id.fragment_container);
|
|
||||||
holder.view.setId(position+1);
|
|
||||||
holder.tag = createTag(position);
|
|
||||||
convertView.setTag(holder);
|
|
||||||
|
|
||||||
//add the fragment to the new view
|
|
||||||
// transaction.add(holder.view.getId(), getItem(position), holder.tag);
|
|
||||||
transaction.replace(holder.view.getId(), getItem(position),holder.tag);
|
|
||||||
} else {
|
|
||||||
// Get the ViewHolder back to get fast access to the Old Views
|
|
||||||
holder = (Holder) convertView.getTag();
|
|
||||||
Fragment shown = mFragmentManager.findFragmentByTag(holder.tag);
|
|
||||||
|
|
||||||
//replace the old fragment with a new one
|
|
||||||
transaction.addToBackStack(holder.tag);
|
|
||||||
holder.tag = createTag(position);
|
|
||||||
if(shown != null)
|
|
||||||
transaction.remove(shown);
|
|
||||||
// transaction.add(holder.view.getId(), getItem(position), holder.tag);
|
|
||||||
transaction.replace(holder.view.getId(), getItem(position),holder.tag);
|
|
||||||
}
|
|
||||||
transaction.commit();
|
|
||||||
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param position
|
|
||||||
* @return a unique tag to be used for identifying fragments
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
private String createTag(int position){
|
|
||||||
return "andorid:FragmentList:tag:"+position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple Holder class
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
class Holder{
|
|
||||||
public String tag;
|
|
||||||
public View view;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user