Common add button for tunnel views
This commit is contained in:
@ -6,25 +6,19 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.i2p.android.help.HelpActivity;
|
import net.i2p.android.help.HelpActivity;
|
||||||
import net.i2p.android.i2ptunnel.util.TunnelUtil;
|
|
||||||
import net.i2p.android.router.I2PFragmentBase;
|
import net.i2p.android.router.I2PFragmentBase;
|
||||||
import net.i2p.android.router.I2PFragmentBase.RouterContextProvider;
|
import net.i2p.android.router.I2PFragmentBase.RouterContextProvider;
|
||||||
import net.i2p.android.router.R;
|
import net.i2p.android.router.R;
|
||||||
import net.i2p.android.util.FragmentUtils;
|
import net.i2p.android.util.FragmentUtils;
|
||||||
import net.i2p.i2ptunnel.TunnelControllerGroup;
|
import net.i2p.i2ptunnel.TunnelControllerGroup;
|
||||||
import net.i2p.i2ptunnel.ui.TunnelConfig;
|
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,9 +27,6 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
I2PFragmentBase.RouterContextUser,
|
I2PFragmentBase.RouterContextUser,
|
||||||
LoaderManager.LoaderCallbacks<List<TunnelEntry>> {
|
LoaderManager.LoaderCallbacks<List<TunnelEntry>> {
|
||||||
public static final String SHOW_CLIENT_TUNNELS = "show_client_tunnels";
|
public static final String SHOW_CLIENT_TUNNELS = "show_client_tunnels";
|
||||||
public static final String TUNNEL_WIZARD_DATA = "tunnel_wizard_data";
|
|
||||||
|
|
||||||
static final int TUNNEL_WIZARD_REQUEST = 1;
|
|
||||||
|
|
||||||
private static final int CLIENT_LOADER_ID = 1;
|
private static final int CLIENT_LOADER_ID = 1;
|
||||||
private static final int SERVER_LOADER_ID = 2;
|
private static final int SERVER_LOADER_ID = 2;
|
||||||
@ -57,8 +48,6 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||||
private boolean mActivateOnItemClick = false;
|
private boolean mActivateOnItemClick = false;
|
||||||
|
|
||||||
private ImageButton mNewTunnel;
|
|
||||||
|
|
||||||
// Container Activity must implement this interface
|
// Container Activity must implement this interface
|
||||||
public interface OnTunnelSelectedListener {
|
public interface OnTunnelSelectedListener {
|
||||||
public void onTunnelSelected(int tunnelId);
|
public void onTunnelSelected(int tunnelId);
|
||||||
@ -97,27 +86,6 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
// Create the list fragment's content view by calling the super method
|
|
||||||
final View listFragmentView = super.onCreateView(inflater, container, savedInstanceState);
|
|
||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_list_with_add, container, false);
|
|
||||||
FrameLayout listContainer = (FrameLayout) v.findViewById(R.id.list_container);
|
|
||||||
listContainer.addView(listFragmentView);
|
|
||||||
|
|
||||||
mNewTunnel = (ImageButton) v.findViewById(R.id.promoted_action);
|
|
||||||
mNewTunnel.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
Intent wi = new Intent(getActivity(), TunnelWizardActivity.class);
|
|
||||||
startActivityForResult(wi, TUNNEL_WIZARD_REQUEST);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
@ -195,7 +163,6 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.fragment_i2ptunnel_list_actions, menu);
|
inflater.inflate(R.menu.fragment_i2ptunnel_list_actions, menu);
|
||||||
if (getRouterContext() == null) {
|
if (getRouterContext() == null) {
|
||||||
mNewTunnel.setVisibility(View.GONE);
|
|
||||||
menu.findItem(R.id.action_start_all_tunnels).setVisible(false);
|
menu.findItem(R.id.action_start_all_tunnels).setVisible(false);
|
||||||
menu.findItem(R.id.action_stop_all_tunnels).setVisible(false);
|
menu.findItem(R.id.action_stop_all_tunnels).setVisible(false);
|
||||||
menu.findItem(R.id.action_restart_all_tunnels).setVisible(false);
|
menu.findItem(R.id.action_restart_all_tunnels).setVisible(false);
|
||||||
@ -231,18 +198,6 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
if (requestCode == TUNNEL_WIZARD_REQUEST) {
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
|
||||||
Bundle tunnelData = data.getExtras().getBundle(TUNNEL_WIZARD_DATA);
|
|
||||||
TunnelConfig cfg = TunnelUtil.createConfigFromWizard(getActivity(), mGroup, tunnelData);
|
|
||||||
TunnelEntry tunnel = TunnelEntry.createNewTunnel(getActivity(), mGroup, cfg);
|
|
||||||
mAdapter.add(tunnel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns on activate-on-click mode. When this mode is on, list items will be
|
* Turns on activate-on-click mode. When this mode is on, list items will be
|
||||||
* given the 'activated' state when touched.
|
* given the 'activated' state when touched.
|
||||||
@ -261,6 +216,10 @@ public class TunnelListFragment extends ListFragment implements
|
|||||||
mActivatedPosition = position;
|
mActivatedPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addTunnel(TunnelEntry tunnelEntry) {
|
||||||
|
mAdapter.add(tunnelEntry);
|
||||||
|
}
|
||||||
|
|
||||||
// Duplicated from I2PFragmentBase because this extends ListFragment
|
// Duplicated from I2PFragmentBase because this extends ListFragment
|
||||||
private RouterContext getRouterContext() {
|
private RouterContext getRouterContext() {
|
||||||
return mRouterContextProvider.getRouterContext();
|
return mRouterContextProvider.getRouterContext();
|
||||||
|
@ -32,7 +32,7 @@ public class TunnelWizardActivity extends AbstractWizardActivity {
|
|||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Intent result = new Intent();
|
Intent result = new Intent();
|
||||||
result.putExtra(TunnelListFragment.TUNNEL_WIZARD_DATA, mWizardModel.save());
|
result.putExtra(TunnelsContainer.TUNNEL_WIZARD_DATA, mWizardModel.save());
|
||||||
setResult(Activity.RESULT_OK, result);
|
setResult(Activity.RESULT_OK, result);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
finish();
|
finish();
|
||||||
|
@ -1,28 +1,42 @@
|
|||||||
package net.i2p.android.i2ptunnel;
|
package net.i2p.android.i2ptunnel;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
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.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
|
import net.i2p.android.i2ptunnel.util.TunnelUtil;
|
||||||
import net.i2p.android.router.R;
|
import net.i2p.android.router.R;
|
||||||
|
import net.i2p.android.router.util.Util;
|
||||||
|
import net.i2p.android.util.MemoryFragmentPagerAdapter;
|
||||||
|
import net.i2p.i2ptunnel.TunnelControllerGroup;
|
||||||
|
import net.i2p.i2ptunnel.ui.TunnelConfig;
|
||||||
|
|
||||||
public class TunnelsContainer extends Fragment implements
|
public class TunnelsContainer extends Fragment implements
|
||||||
TunnelListFragment.OnTunnelSelectedListener,
|
TunnelListFragment.OnTunnelSelectedListener,
|
||||||
TunnelDetailFragment.TunnelDetailListener {
|
TunnelDetailFragment.TunnelDetailListener {
|
||||||
|
static final int TUNNEL_WIZARD_REQUEST = 1;
|
||||||
|
public static final String TUNNEL_WIZARD_DATA = "tunnel_wizard_data";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
||||||
* device.
|
* device.
|
||||||
*/
|
*/
|
||||||
private boolean mTwoPane;
|
private boolean mTwoPane;
|
||||||
|
|
||||||
FragmentPagerAdapter mFragPagerAdapter;
|
ViewPager mViewPager;
|
||||||
|
MemoryFragmentPagerAdapter mFragPagerAdapter;
|
||||||
|
|
||||||
|
private ImageButton mNewTunnel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -34,6 +48,9 @@ public class TunnelsContainer extends Fragment implements
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.container_tunnels, container, false);
|
View v = inflater.inflate(R.layout.container_tunnels, container, false);
|
||||||
|
|
||||||
|
mViewPager = (ViewPager) v.findViewById(R.id.pager);
|
||||||
|
mNewTunnel = (ImageButton) v.findViewById(R.id.promoted_action);
|
||||||
|
|
||||||
if (v.findViewById(R.id.detail_fragment) != null) {
|
if (v.findViewById(R.id.detail_fragment) != null) {
|
||||||
// The detail container view will be present only in the
|
// The detail container view will be present only in the
|
||||||
// large-screen layouts (res/values-large and
|
// large-screen layouts (res/values-large and
|
||||||
@ -42,14 +59,26 @@ public class TunnelsContainer extends Fragment implements
|
|||||||
mTwoPane = true;
|
mTwoPane = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewPager viewPager = (ViewPager) v.findViewById(R.id.container_pager);
|
|
||||||
mFragPagerAdapter = new TunnelsPagerAdapter(getActivity(), getChildFragmentManager(), mTwoPane);
|
|
||||||
viewPager.setAdapter(mFragPagerAdapter);
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TunnelsPagerAdapter extends FragmentPagerAdapter {
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
mFragPagerAdapter = new TunnelsPagerAdapter(getActivity(), getChildFragmentManager(), mTwoPane);
|
||||||
|
mViewPager.setAdapter(mFragPagerAdapter);
|
||||||
|
|
||||||
|
mNewTunnel.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Intent wi = new Intent(getActivity(), TunnelWizardActivity.class);
|
||||||
|
startActivityForResult(wi, TUNNEL_WIZARD_REQUEST);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TunnelsPagerAdapter extends MemoryFragmentPagerAdapter {
|
||||||
private static final int NUM_ITEMS = 2;
|
private static final int NUM_ITEMS = 2;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@ -97,6 +126,30 @@ public class TunnelsContainer extends Fragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.fragment_i2ptunnel_list_actions, menu);
|
||||||
|
if (Util.getRouterContext() == null) {
|
||||||
|
mNewTunnel.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == TUNNEL_WIZARD_REQUEST) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
Bundle tunnelData = data.getExtras().getBundle(TUNNEL_WIZARD_DATA);
|
||||||
|
// TODO fetch earlier
|
||||||
|
TunnelControllerGroup tcg = TunnelControllerGroup.getInstance();
|
||||||
|
TunnelConfig cfg = TunnelUtil.createConfigFromWizard(getActivity(), tcg, tunnelData);
|
||||||
|
TunnelEntry tunnel = TunnelEntry.createNewTunnel(getActivity(), tcg, cfg);
|
||||||
|
|
||||||
|
TunnelListFragment f = (TunnelListFragment) mFragPagerAdapter.getFragment(tunnel.isClient() ? 0 : 1);
|
||||||
|
f.addTunnel(tunnel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TunnelListFragment.OnTunnelSelectedListener
|
// TunnelListFragment.OnTunnelSelectedListener
|
||||||
|
|
||||||
public void onTunnelSelected(int tunnelId) {
|
public void onTunnelSelected(int tunnelId) {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<android.support.v4.view.ViewPager
|
|
||||||
android:id="@+id/container_pager"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<android.support.v4.view.PagerTitleStrip
|
|
||||||
android:id="@+id/container_pager_header"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="top" />
|
|
||||||
</android.support.v4.view.ViewPager>
|
|
||||||
</LinearLayout>
|
|
@ -22,13 +22,13 @@
|
|||||||
|
|
||||||
<!-- The main fragment view -->
|
<!-- The main fragment view -->
|
||||||
<android.support.v4.view.ViewPager
|
<android.support.v4.view.ViewPager
|
||||||
android:id="@+id/container_pager"
|
android:id="@+id/pager"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<android.support.v4.view.PagerTitleStrip
|
<android.support.v4.view.PagerTitleStrip
|
||||||
android:id="@+id/container_pager_header"
|
android:id="@+id/pager_title_strip"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="top" />
|
android:layout_gravity="top" />
|
||||||
|
33
app/src/main/res/layout/container_with_add_onepane.xml
Normal file
33
app/src/main/res/layout/container_with_add_onepane.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<!-- The main content view -->
|
||||||
|
<android.support.v4.view.ViewPager
|
||||||
|
android:id="@+id/pager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<android.support.v4.view.PagerTitleStrip
|
||||||
|
android:id="@+id/pager_title_strip"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top" />
|
||||||
|
</android.support.v4.view.ViewPager>
|
||||||
|
|
||||||
|
<net.i2p.android.ext.floatingactionbutton.AddFloatingActionButton
|
||||||
|
android:id="@+id/promoted_action"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginBottom="@dimen/listitem_horizontal_margin"
|
||||||
|
android:layout_marginEnd="@dimen/listitem_horizontal_margin"
|
||||||
|
android:layout_marginRight="@dimen/listitem_horizontal_margin"
|
||||||
|
app:fab_colorNormal="@color/accent"
|
||||||
|
app:fab_colorPressed="@color/accent_dark" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -2,6 +2,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<item name="activity_multipane" type="layout">@layout/activity_onepane</item>
|
<item name="activity_multipane" type="layout">@layout/activity_onepane</item>
|
||||||
<item name="container_addressbook" type="layout">@layout/container_addressbook_onepane</item>
|
<item name="container_addressbook" type="layout">@layout/container_addressbook_onepane</item>
|
||||||
<item name="container_tunnels" type="layout">@layout/container_tunnels_onepane</item>
|
<item name="container_tunnels" type="layout">@layout/container_with_add_onepane</item>
|
||||||
<item name="activity_help" type="layout">@layout/activity_help_onepane</item>
|
<item name="activity_help" type="layout">@layout/activity_help_onepane</item>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user