diff options
author | Kyle Horimoto <khorimoto@gmail.com> | 2015-09-25 16:24:26 -0700 |
---|---|---|
committer | Kyle Horimoto <khorimoto@gmail.com> | 2015-09-28 14:20:56 -0700 |
commit | 19be66987c2014ff38ff0b051a86319b354eff16 (patch) | |
tree | 6c0f602f568e6d3d9d844d93696b5bd48299f86f /app | |
parent | 5f4f6074c257d4bf4ebbdfa41fc2842baa4d5ddf (diff) | |
download | connectbot-19be66987c2014ff38ff0b051a86319b354eff16.tar.gz connectbot-19be66987c2014ff38ff0b051a86319b354eff16.tar.bz2 connectbot-19be66987c2014ff38ff0b051a86319b354eff16.zip |
Add FAB to port forward activity.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/org/connectbot/PortForwardListActivity.java | 98 | ||||
-rw-r--r-- | app/src/main/res/layout/act_portforwardlist.xml | 32 |
2 files changed, 67 insertions, 63 deletions
diff --git a/app/src/main/java/org/connectbot/PortForwardListActivity.java b/app/src/main/java/org/connectbot/PortForwardListActivity.java index 28b4331..ecab4e0 100644 --- a/app/src/main/java/org/connectbot/PortForwardListActivity.java +++ b/app/src/main/java/org/connectbot/PortForwardListActivity.java @@ -39,6 +39,8 @@ import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.support.annotation.VisibleForTesting; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.DialogFragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -143,16 +145,12 @@ public class PortForwardListActivity extends AppCompatListActivity { this.registerForContextMenu(mListView); this.inflater = LayoutInflater.from(this); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuItem add = menu.add(R.string.portforward_menu_add); - add.setIcon(android.R.drawable.ic_menu_add); - add.setOnMenuItemClickListener(new OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { + FloatingActionButton addPortForwardButton = + (FloatingActionButton) findViewById(R.id.add_port_forward_button); + addPortForwardButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { // build dialog to prompt user about updating final View portForwardView = inflater.inflate(R.layout.dia_portforward, null, false); final EditText destEdit = (EditText) portForwardView.findViewById(R.id.portforward_destination); @@ -168,55 +166,53 @@ public class PortForwardListActivity extends AppCompatListActivity { }); new AlertDialog.Builder(PortForwardListActivity.this) - .setView(portForwardView) - .setPositiveButton(R.string.portforward_pos, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - try { - final EditText nicknameEdit = (EditText) portForwardView.findViewById(R.id.nickname); - final EditText sourcePortEdit = (EditText) portForwardView.findViewById(R.id.portforward_source); - - String type = HostDatabase.PORTFORWARD_LOCAL; - switch (typeSpinner.getSelectedItemPosition()) { - case 0: - type = HostDatabase.PORTFORWARD_LOCAL; - break; - case 1: - type = HostDatabase.PORTFORWARD_REMOTE; - break; - case 2: - type = HostDatabase.PORTFORWARD_DYNAMIC5; - break; - } + .setView(portForwardView) + .setPositiveButton(R.string.portforward_pos, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + try { + final EditText nicknameEdit = (EditText) portForwardView.findViewById(R.id.nickname); + final EditText sourcePortEdit = (EditText) portForwardView.findViewById(R.id.portforward_source); + + String type = HostDatabase.PORTFORWARD_LOCAL; + switch (typeSpinner.getSelectedItemPosition()) { + case 0: + type = HostDatabase.PORTFORWARD_LOCAL; + break; + case 1: + type = HostDatabase.PORTFORWARD_REMOTE; + break; + case 2: + type = HostDatabase.PORTFORWARD_DYNAMIC5; + break; + } - PortForwardBean portForward = new PortForwardBean( - host != null ? host.getId() : -1, - nicknameEdit.getText().toString(), type, - sourcePortEdit.getText().toString(), - destEdit.getText().toString()); + PortForwardBean portForward = new PortForwardBean( + host != null ? host.getId() : -1, + nicknameEdit.getText().toString(), type, + sourcePortEdit.getText().toString(), + destEdit.getText().toString()); - if (hostBridge != null) { - hostBridge.addPortForward(portForward); - hostBridge.enablePortForward(portForward); - } + if (hostBridge != null) { + hostBridge.addPortForward(portForward); + hostBridge.enablePortForward(portForward); + } - if (host != null && !hostdb.savePortForward(portForward)) { - throw new SQLException("Could not save port forward"); - } + if (host != null && !hostdb.savePortForward(portForward)) { + throw new SQLException("Could not save port forward"); + } - updateHandler.sendEmptyMessage(-1); - } catch (Exception e) { - Log.e(TAG, "Could not update port forward", e); - // TODO Show failure dialog. + updateHandler.sendEmptyMessage(-1); + } catch (Exception e) { + Log.e(TAG, "Could not update port forward", e); + // TODO Show failure dialog. + } } - } - }) - .setNegativeButton(R.string.delete_neg, null).create().show(); - - return true; + }) + .setNegativeButton(R.string.delete_neg, null).create().show(); } - }); - return true; + public void onNothingSelected(AdapterView<?> arg0) {} + }); } protected Handler updateHandler = new Handler() { diff --git a/app/src/main/res/layout/act_portforwardlist.xml b/app/src/main/res/layout/act_portforwardlist.xml index a11bb1b..b1655e0 100644 --- a/app/src/main/res/layout/act_portforwardlist.xml +++ b/app/src/main/res/layout/act_portforwardlist.xml @@ -18,25 +18,33 @@ */ --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > + <!-- paddingBottom is calculated with FloatingActionButton's height (56dp) and + margins (16dp): 56dp + (2 x 16dp) = 88dp. --> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="fill_parent" - android:layout_height="0dip" - android:layout_weight="1" - /> - - <TextView - android:id="@+id/empty" - android:layout_width="fill_parent" android:layout_height="fill_parent" - android:gravity="center" - android:text="@string/portforward_list_empty" - android:textAppearance="?android:attr/textAppearanceMedium" + android:paddingBottom="88dp" + android:clipToPadding="false" /> -</LinearLayout> + + <android.support.design.widget.FloatingActionButton + android:id="@+id/add_port_forward_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_alignParentEnd="true" + android:layout_alignParentRight="true" + android:layout_margin="16dp" + android:src="@drawable/ic_add" + app:backgroundTint="@color/accent" + app:rippleColor="@color/dark_accent" /> + +</RelativeLayout> |