diff --git a/src/net/i2p/android/router/activity/AddressbookActivity.java b/src/net/i2p/android/router/activity/AddressbookActivity.java index 9e25dcd538664093a54aa2bcbb906e69d0bca202..5c8cb3984028ba20a0d758d30a705af58a900d37 100644 --- a/src/net/i2p/android/router/activity/AddressbookActivity.java +++ b/src/net/i2p/android/router/activity/AddressbookActivity.java @@ -2,6 +2,7 @@ package net.i2p.android.router.activity; import net.i2p.android.router.R; import net.i2p.android.router.fragment.AddressbookFragment; +import net.i2p.android.router.fragment.WebFragment; import android.app.SearchManager; import android.content.Context; import android.os.Bundle; @@ -12,7 +13,8 @@ import android.view.Menu; import android.view.MenuItem; public class AddressbookActivity extends I2PActivityBase - implements SearchView.OnQueryTextListener { + implements AddressbookFragment.OnAddressSelectedListener, + SearchView.OnQueryTextListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -36,6 +38,22 @@ public class AddressbookActivity extends I2PActivityBase return super.onCreateOptionsMenu(menu); } + // AddressbookFragment.OnAddressSelectedListener + + public void onAddressSelected(CharSequence host) { + WebFragment f = new WebFragment(); + Bundle args = new Bundle(); + args.putString(WebFragment.HTML_URI, "http://" + host + '/'); + f.setArguments(args); + getSupportFragmentManager().beginTransaction() + .replace(R.id.main_content, f) + .addToBackStack(null) + .commit(); + + } + + // SearchView.OnQueryTextListener + public boolean onQueryTextChange(String newText) { filterAddresses(newText); return true; diff --git a/src/net/i2p/android/router/fragment/AddressbookFragment.java b/src/net/i2p/android/router/fragment/AddressbookFragment.java index 257ae2e34b8de7c92975c0f8db9043171cc6e4c2..c6327b9e0fb8f65de9bc60be2d4813d7b794617b 100644 --- a/src/net/i2p/android/router/fragment/AddressbookFragment.java +++ b/src/net/i2p/android/router/fragment/AddressbookFragment.java @@ -1,16 +1,14 @@ package net.i2p.android.router.fragment; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.ListFragment; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; @@ -27,8 +25,29 @@ import net.i2p.android.router.activity.AddressbookSettingsActivity; import net.i2p.client.naming.NamingService; public class AddressbookFragment extends ListFragment { + OnAddressSelectedListener mCallback; private ArrayAdapter<String> mAdapter; + // Container Activity must implement this interface + public interface OnAddressSelectedListener { + public void onAddressSelected(CharSequence host); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + // This makes sure that the container activity has implemented + // the callback interface. If not, it throws an exception + try { + mCallback = (OnAddressSelectedListener) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement OnAddressSelectedListener"); + } + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -76,15 +95,7 @@ public class AddressbookFragment extends ListFragment { @Override public void onListItemClick(ListView parent, View view, int pos, long id) { CharSequence host = ((TextView) view).getText(); - WebFragment f = new WebFragment(); - Bundle args = new Bundle(); - args.putString(WebFragment.HTML_URI, "http://" + host + '/'); - f.setArguments(args); - getActivity().getSupportFragmentManager() - .beginTransaction() - .replace(R.id.main_content, f) - .addToBackStack(null) - .commit(); + mCallback.onAddressSelected(host); } @Override diff --git a/src/net/i2p/android/router/fragment/WebFragment.java b/src/net/i2p/android/router/fragment/WebFragment.java index 5fcfaf030ad0d8bcdbff2fedf6e138d59d837e84..e05f4d488ed1d07546e5ced7e4426b25d40dfd61 100644 --- a/src/net/i2p/android/router/fragment/WebFragment.java +++ b/src/net/i2p/android/router/fragment/WebFragment.java @@ -19,7 +19,7 @@ public class WebFragment extends I2PFragmentBase { private I2PWebViewClient _wvClient; - final static String HTML_URI = "html_url"; + public final static String HTML_URI = "html_url"; final static String HTML_RESOURCE_ID = "html_resource_id"; private static final String WARNING = "Warning - " + "any non-I2P links visited in this window are fetched over the regular internet and are " +