FloatingActionButton for I2PTunnel and addressbook

This commit is contained in:
str4d
2014-12-01 03:57:21 +00:00
parent c59103eb76
commit 23eab8a90a
7 changed files with 136 additions and 73 deletions

View File

@ -43,6 +43,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:21.0.2' compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2' compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:cardview-v7:21.0.2'
compile 'net.i2p.android.ext:floatingactionbutton:1.1.0'
compile files('libs/androidplot-core-0.6.1.jar') compile files('libs/androidplot-core-0.6.1.jar')
} }
@ -52,6 +53,7 @@ dependencyVerification {
'com.android.support:appcompat-v7:b760fd3d0b0b0547a1bcef9031b40939f31049ba955f04c8fdc5aa09a25d19e9', 'com.android.support:appcompat-v7:b760fd3d0b0b0547a1bcef9031b40939f31049ba955f04c8fdc5aa09a25d19e9',
'com.android.support:recyclerview-v7:71ef0f5659b3019dc33c5ffb346ea01df1f66735506f38d43fd783fbcb0370ce', 'com.android.support:recyclerview-v7:71ef0f5659b3019dc33c5ffb346ea01df1f66735506f38d43fd783fbcb0370ce',
'com.android.support:cardview-v7:cb4d7ee9ebb6edffa7203eff0d207b4e88425599a8ed37d94b650bc84390c4eb', 'com.android.support:cardview-v7:cb4d7ee9ebb6edffa7203eff0d207b4e88425599a8ed37d94b650bc84390c4eb',
'net.i2p.android.ext:floatingactionbutton:84cf5b67a66337bef59b46f57468c730387ca766b5a5f06ca852ba46cabbc0fb',
] ]
} }

View File

@ -1,27 +1,32 @@
package net.i2p.android.i2ptunnel; package net.i2p.android.i2ptunnel;
import java.util.List;
import net.i2p.android.help.HelpActivity;
import net.i2p.android.i2ptunnel.util.TunnelConfig;
import net.i2p.android.router.I2PFragmentBase;
import net.i2p.android.router.R;
import net.i2p.android.router.I2PFragmentBase.RouterContextProvider;
import net.i2p.i2ptunnel.TunnelControllerGroup;
import net.i2p.router.RouterContext;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; 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.i2ptunnel.util.TunnelConfig;
import net.i2p.android.router.I2PFragmentBase;
import net.i2p.android.router.I2PFragmentBase.RouterContextProvider;
import net.i2p.android.router.R;
import net.i2p.i2ptunnel.TunnelControllerGroup;
import net.i2p.router.RouterContext;
import java.util.List;
public class TunnelListFragment extends ListFragment implements public class TunnelListFragment extends ListFragment implements
I2PFragmentBase.RouterContextUser, I2PFragmentBase.RouterContextUser,
LoaderManager.LoaderCallbacks<List<TunnelEntry>> { LoaderManager.LoaderCallbacks<List<TunnelEntry>> {
@ -50,6 +55,8 @@ 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);
@ -85,6 +92,27 @@ 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);
@ -162,7 +190,7 @@ 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) {
menu.findItem(R.id.action_add_tunnel).setVisible(false); 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);
@ -174,26 +202,22 @@ public class TunnelListFragment extends ListFragment implements
// Handle presses on the action bar items // Handle presses on the action bar items
List<String> msgs; List<String> msgs;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_add_tunnel: case R.id.action_start_all_tunnels:
Intent wi = new Intent(getActivity(), TunnelWizardActivity.class); msgs = mGroup.startAllControllers();
startActivityForResult(wi, TUNNEL_WIZARD_REQUEST); break;
return true; case R.id.action_stop_all_tunnels:
case R.id.action_start_all_tunnels: msgs = mGroup.stopAllControllers();
msgs = mGroup.startAllControllers(); break;
break; case R.id.action_restart_all_tunnels:
case R.id.action_stop_all_tunnels: msgs = mGroup.restartAllControllers();
msgs = mGroup.stopAllControllers(); break;
break; case R.id.action_i2ptunnel_help:
case R.id.action_restart_all_tunnels: Intent hi = new Intent(getActivity(), HelpActivity.class);
msgs = mGroup.restartAllControllers(); hi.putExtra(HelpActivity.CATEGORY, HelpActivity.CAT_I2PTUNNEL);
break; startActivity(hi);
case R.id.action_i2ptunnel_help: return true;
Intent hi = new Intent(getActivity(), HelpActivity.class); default:
hi.putExtra(HelpActivity.CATEGORY, HelpActivity.CAT_I2PTUNNEL); return super.onOptionsItemSelected(item);
startActivity(hi);
return true;
default:
return super.onOptionsItemSelected(item);
} }
// TODO: Do something with the other messages // TODO: Do something with the other messages
if (msgs.size() > 0) if (msgs.size() > 0)
@ -251,7 +275,7 @@ public class TunnelListFragment extends ListFragment implements
} }
public void onLoadFinished(Loader<List<TunnelEntry>> loader, public void onLoadFinished(Loader<List<TunnelEntry>> loader,
List<TunnelEntry> data) { List<TunnelEntry> data) {
if (loader.getId() == (mClientTunnels ? if (loader.getId() == (mClientTunnels ?
CLIENT_LOADER_ID : SERVER_LOADER_ID)) { CLIENT_LOADER_ID : SERVER_LOADER_ID)) {
mAdapter.setData(data); mAdapter.setData(data);

View File

@ -7,25 +7,29 @@ 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.text.TextUtils; import android.text.TextUtils;
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.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.List;
import net.i2p.addressbook.Daemon; import net.i2p.addressbook.Daemon;
import net.i2p.android.help.HelpActivity; import net.i2p.android.help.HelpActivity;
import net.i2p.android.router.I2PFragmentBase; import net.i2p.android.router.I2PFragmentBase;
import net.i2p.android.router.R;
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.util.NamingServiceUtil; import net.i2p.android.router.util.NamingServiceUtil;
import net.i2p.client.naming.NamingService; import net.i2p.client.naming.NamingService;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import java.util.List;
public class AddressbookFragment extends ListFragment implements public class AddressbookFragment extends ListFragment implements
I2PFragmentBase.RouterContextUser, I2PFragmentBase.RouterContextUser,
LoaderManager.LoaderCallbacks<List<AddressEntry>> { LoaderManager.LoaderCallbacks<List<AddressEntry>> {
@ -46,6 +50,8 @@ public class AddressbookFragment extends ListFragment implements
private String mBook; private String mBook;
private String mCurFilter; private String mCurFilter;
private ImageButton mAddToAddressbook;
// Set in onActivityResult() // Set in onActivityResult()
private Intent mAddWizardData; private Intent mAddWizardData;
@ -84,6 +90,27 @@ public class AddressbookFragment 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);
mAddToAddressbook = (ImageButton) v.findViewById(R.id.promoted_action);
mAddToAddressbook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent wi = new Intent(getActivity(), AddressbookAddWizardActivity.class);
startActivityForResult(wi, ADD_WIZARD_REQUEST);
}
});
return v;
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -111,8 +138,8 @@ public class AddressbookFragment extends ListFragment implements
// Show actions // Show actions
if (mSearchAddressbook != null) if (mSearchAddressbook != null)
mSearchAddressbook.setVisible(true); mSearchAddressbook.setVisible(true);
if (mAddToAddressbook != null) if (mAddToAddressbook != null && mAddToAddressbook.getVisibility() != View.VISIBLE)
mAddToAddressbook.setVisible(false); mAddToAddressbook.setVisibility(View.VISIBLE);
if (mAddWizardData != null) { if (mAddWizardData != null) {
// Save the new entry // Save the new entry
@ -140,24 +167,22 @@ public class AddressbookFragment extends ListFragment implements
} }
private MenuItem mSearchAddressbook; private MenuItem mSearchAddressbook;
private MenuItem mAddToAddressbook;
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_addressbook_actions, menu); inflater.inflate(R.menu.fragment_addressbook_actions, menu);
mSearchAddressbook = menu.findItem(R.id.action_search_addressbook); mSearchAddressbook = menu.findItem(R.id.action_search_addressbook);
mAddToAddressbook = menu.findItem(R.id.action_add_to_addressbook);
// Hide until needed // Hide until needed
if (getRouterContext() == null) { if (getRouterContext() == null) {
mSearchAddressbook.setVisible(false); mSearchAddressbook.setVisible(false);
mAddToAddressbook.setVisible(false); mAddToAddressbook.setVisibility(View.GONE);
} }
// Only allow adding to private book // Only allow adding to private book
if (!PRIVATE_BOOK.equals(mBook)) { if (!PRIVATE_BOOK.equals(mBook)) {
mAddToAddressbook.setVisible(false); mAddToAddressbook.setVisibility(View.GONE);
mAddToAddressbook = null; mAddToAddressbook = null;
} }
} }
@ -167,26 +192,22 @@ public class AddressbookFragment extends ListFragment implements
// Handle presses on the action bar items // Handle presses on the action bar items
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_add_to_addressbook: case R.id.action_reload_subscriptions:
Intent wi = new Intent(getActivity(), AddressbookAddWizardActivity.class); Daemon.wakeup();
startActivityForResult(wi, ADD_WIZARD_REQUEST); Toast.makeText(getActivity(), "Reloading subscriptions...",
return true; Toast.LENGTH_SHORT).show();
case R.id.action_reload_subscriptions: return true;
Daemon.wakeup(); case R.id.action_addressbook_settings:
Toast.makeText(getActivity(), "Reloading subscriptions...", Intent si = new Intent(getActivity(), AddressbookSettingsActivity.class);
Toast.LENGTH_SHORT).show(); startActivity(si);
return true; return true;
case R.id.action_addressbook_settings: case R.id.action_addressbook_help:
Intent si = new Intent(getActivity(), AddressbookSettingsActivity.class); Intent hi = new Intent(getActivity(), HelpActivity.class);
startActivity(si); hi.putExtra(HelpActivity.CATEGORY, HelpActivity.CAT_ADDRESSBOOK);
return true; startActivity(hi);
case R.id.action_addressbook_help: return true;
Intent hi = new Intent(getActivity(), HelpActivity.class); default:
hi.putExtra(HelpActivity.CATEGORY, HelpActivity.CAT_ADDRESSBOOK); return super.onOptionsItemSelected(item);
startActivity(hi);
return true;
default:
return super.onOptionsItemSelected(item);
} }
} }
@ -228,7 +249,7 @@ public class AddressbookFragment extends ListFragment implements
} }
public void onLoadFinished(Loader<List<AddressEntry>> loader, public void onLoadFinished(Loader<List<AddressEntry>> loader,
List<AddressEntry> data) { List<AddressEntry> data) {
if (loader.getId() == (PRIVATE_BOOK.equals(mBook) ? if (loader.getId() == (PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID)) { PRIVATE_LOADER_ID : ROUTER_LOADER_ID)) {
mAdapter.setData(data); mAdapter.setData(data);

View File

@ -0,0 +1,24 @@
<?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">
<FrameLayout
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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>

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" > xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
<!-- Add, should appear as action buttons -->
<item android:id="@+id/action_add_to_addressbook"
android:title="@string/action_add"
android:icon="@drawable/ic_add_white_24dp"
i2pandroid:showAsAction="ifRoom" />
<!-- Settings, Help, should always be in the overflow --> <!-- Settings, Help, should always be in the overflow -->
<item android:id="@+id/action_reload_subscriptions" <item android:id="@+id/action_reload_subscriptions"
android:title="@string/action_reload_subscriptions" android:title="@string/action_reload_subscriptions"

View File

@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" > xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_add_tunnel"
android:title="@string/action_add"
android:icon="@drawable/ic_add_white_24dp"
i2pandroid:showAsAction="ifRoom" />
<item android:id="@+id/action_start_all_tunnels" <item android:id="@+id/action_start_all_tunnels"
android:title="@string/action_i2ptunnel_start_all" android:title="@string/action_i2ptunnel_start_all"
i2pandroid:showAsAction="never" /> i2pandroid:showAsAction="never" />

View File

@ -1,7 +1,8 @@
<resources> <resources>
<color name="primary">#673ab7</color> <color name="primary">#673ab7</color><!-- Deep Purple 500 -->
<color name="primary_dark">#512da8</color> <color name="primary_dark">#512da8</color><!-- Deep Purple 700 -->
<color name="accent">#ff6e40</color> <color name="accent">#ff6e40</color><!-- Deep Orange A200 -->
<color name="accent_dark">#ff3d00</color><!-- Deep Orange A400 -->
<color name="indicator_red">#ffff0000</color> <color name="indicator_red">#ffff0000</color>
<color name="indicator_yellow">#ffffff00</color> <color name="indicator_yellow">#ffffff00</color>