Skip to content

Commit

Permalink
Refactor, fix Allow ip bug, fix adding items to config list on larger…
Browse files Browse the repository at this point in the history
… screens. Add icon
  • Loading branch information
jp-bennett committed Jun 4, 2015
1 parent 3609782 commit e103f3b
Show file tree
Hide file tree
Showing 17 changed files with 415 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="dnsjava-2.1.7" level="project" />
<orderEntry type="library" exported="" name="commons-beanutils-1.8.3" level="project" />
<orderEntry type="library" exported="" name="commons-validator-1.4.1" level="project" />
<orderEntry type="library" exported="" name="core-3.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-19.0.0" level="project" />
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ dependencies {
compile('commons-validator:commons-validator:1.4.1') {
exclude group: 'commons-collections', module: 'commons-collections'
}
compile 'dnsjava:dnsjava:2.1.7'
compile 'com.google.zxing:core:3.2.0'
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/fwknop2"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/biz/incomsystems/fwknop2/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package biz.incomsystems.fwknop2;
public class Config {
public String NICK_NAME;
public String ACCESS_IP;
public String TCP_PORTS;
public String UDP_PORTS;
public String SERVER_IP;
public String SERVER_PORT;
public String SERVER_TIMEOUT;
public String KEY;
public Boolean KEY_BASE64;
public String HMAC;
public String NAT_IP;
public String NAT_PORT;
public String SERVER_CMD;
public Boolean HMAC_BASE64;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.view.View;


/**
Expand All @@ -36,6 +37,7 @@
* more than a {@link ConfigDetailFragment}.
*/
public class ConfigDetailActivity extends ActionBarActivity {
ConfigDetailFragment fragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -62,13 +64,27 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle arguments = new Bundle();
arguments.putString(ConfigDetailFragment.ARG_ITEM_ID,
getIntent().getStringExtra(ConfigDetailFragment.ARG_ITEM_ID));
ConfigDetailFragment fragment = new ConfigDetailFragment();
fragment = new ConfigDetailFragment();

fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.add(R.id.config_detail_container, fragment)
.commit();
}
}
public void onCheckboxClicked(View view) {
fragment.onCheckboxClicked(view);
}

public void onItemSaved() {
ConfigListFragment listFrag = new ConfigListFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.config_list, listFrag);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Expand Down
152 changes: 115 additions & 37 deletions app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,26 @@
* on handsets.
*/
public class ConfigDetailFragment extends Fragment {
DBHelper mydb ;
DBHelper mydb;
Config config;
TextView txt_NickName ; // objects representing the config options
Spinner spn_allowip ;
TextView txt_allowIP ;
LinearLayout lay_allowIP;
CheckBox chknataccess;
CheckBox chkservercmd;
LinearLayout lay_natIP;
LinearLayout lay_natport;
LinearLayout lay_serverCMD;

TextView txt_tcp_ports ;
TextView txt_udp_ports ;
TextView txt_server_ip ;
TextView txt_server_port ;
TextView txt_server_time ;
TextView txt_nat_ip;
TextView txt_nat_port;
TextView txt_server_cmd;
TextView txt_KEY ;
CheckBox chkb64key ;
TextView txt_HMAC ;
Expand All @@ -84,6 +94,7 @@ public ConfigDetailFragment() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
config = new Config();
mydb = new DBHelper(getActivity()); // grabbing a database instance
active_Nick = getArguments().getString(ARG_ITEM_ID); // This populates active_Nick with index of the selected config
}
Expand All @@ -101,6 +112,32 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.mainmenu, menu);
}

public void onCheckboxClicked(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();

// Check which checkbox was clicked
switch(view.getId()) {
case R.id.chknataccess:
if (checked) {
lay_natIP.setVisibility(View.VISIBLE);
lay_natport.setVisibility(View.VISIBLE);
} else {
lay_natIP.setVisibility(View.GONE);
lay_natport.setVisibility(View.GONE);
}
break;
case R.id.chkservercmd:
if (checked) {
lay_serverCMD.setVisibility(View.VISIBLE);
} else {
lay_serverCMD.setVisibility(View.GONE);
}
break;

}
}

public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.qr_code) {
Expand Down Expand Up @@ -153,33 +190,58 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else if (b64_hmac_error){ //if key is base64, check if is b64 compat
toast.setText("Not a valid Base 64 hmac");
toast.show();

//end input validation, actual saving below
} else {
toast.show();
String tmp_access;
if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Resolve IP") || spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Source IP")) {
tmp_access = spn_allowip.getSelectedItem().toString();
if (chknataccess.isChecked()) {
config.NAT_IP = txt_nat_ip.getText().toString();
config.NAT_PORT = txt_nat_port.getText().toString();
} else {
config.NAT_IP = "";
config.NAT_PORT = "";
}
if (chkservercmd.isChecked()) {
config.SERVER_CMD = txt_server_cmd.getText().toString();
} else {
tmp_access = txt_allowIP.getText().toString();
config.SERVER_CMD = "";
}
mydb.updateConfig(
txt_NickName.getText().toString(), //nickname
tmp_access, //overload this. possibilites are Resolve IP, Source IP, or the ip address
txt_tcp_ports.getText().toString(),
txt_udp_ports.getText().toString(),
txt_server_ip.getText().toString(),
txt_server_port.getText().toString(),
txt_server_time.getText().toString(),
txt_KEY.getText().toString(), //key
chkb64key.isChecked(), //is key b64
txt_HMAC.getText().toString(), // hmac key
chkb64hmac.isChecked() //is hmac base64
);
if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Resolve IP")) {
config.ACCESS_IP = spn_allowip.getSelectedItem().toString();
} else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Source IP")) {
config.ACCESS_IP = "0.0.0.0";
} else {
config.ACCESS_IP = txt_allowIP.getText().toString();
}
config.NICK_NAME = txt_NickName.getText().toString(); //nickname
config.TCP_PORTS = txt_tcp_ports.getText().toString();
config.UDP_PORTS = txt_udp_ports.getText().toString();
config.SERVER_IP = txt_server_ip.getText().toString();
config.SERVER_PORT = txt_server_port.getText().toString();
config.SERVER_TIMEOUT = txt_server_time.getText().toString();
config.KEY = txt_KEY.getText().toString(); //key
config.KEY_BASE64 = chkb64key.isChecked(); //is key b64
config.HMAC = txt_HMAC.getText().toString(); // hmac key
config.HMAC_BASE64 = chkb64hmac.isChecked(); //is hmac base64
mydb.updateConfig(context, config);
//Need to somehow call
Activity activity = getActivity();
//if(activity instanceof ConfigDetailActivity){
// ConfigDetailActivity myactivity = (ConfigDetailActivity) activity;
// myactivity.onItemSaved();
//} else
if(activity instanceof ConfigListActivity) {
ConfigListActivity myactivity = (ConfigListActivity) activity;
myactivity.onItemSaved();
}

}
}
return super.onOptionsItemSelected(item);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
Expand Down Expand Up @@ -230,18 +292,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
//spinner below
txt_allowIP = (TextView) rootView.findViewById(R.id.iptoallow);
lay_allowIP = (LinearLayout) rootView.findViewById(R.id.iptoallowsl);
lay_natIP = (LinearLayout) rootView.findViewById(R.id.natipsl);
lay_natport = (LinearLayout) rootView.findViewById(R.id.natportsl);
lay_serverCMD = (LinearLayout) rootView.findViewById(R.id.servercmdsl);
txt_tcp_ports = (TextView) rootView.findViewById(R.id.tcpAccessPorts);
txt_udp_ports = (TextView) rootView.findViewById(R.id.udpAccessPorts);
txt_server_ip = (TextView) rootView.findViewById(R.id.destIP);
txt_server_port = (TextView) rootView.findViewById(R.id.destPort);
txt_server_time = (TextView) rootView.findViewById(R.id.fwTimeout);
txt_server_cmd = (TextView) rootView.findViewById(R.id.servercmd);
txt_nat_ip = (TextView) rootView.findViewById(R.id.natip);
txt_nat_port = (TextView) rootView.findViewById(R.id.natport);


txt_KEY = (TextView) rootView.findViewById(R.id.passwd);
txt_HMAC = (TextView) rootView.findViewById(R.id.hmac);

chkb64hmac = (CheckBox) rootView.findViewById(R.id.chkb64hmac);
chkb64key = (CheckBox) rootView.findViewById(R.id.chkb64key);

chknataccess = (CheckBox) rootView.findViewById(R.id.chknataccess);
chkservercmd = (CheckBox) rootView.findViewById(R.id.chkservercmd);
spn_allowip = (Spinner) rootView.findViewById(R.id.allowip);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.spinner_options, android.R.layout.simple_spinner_item);
Expand Down Expand Up @@ -270,36 +340,44 @@ public void onNothingSelected(AdapterView<?> parent) {
if (active_Nick.equalsIgnoreCase("New Config")) {
txt_NickName.setText("");
} else {
Cursor CurrentIndex = mydb.getData(active_Nick);
CurrentIndex.moveToFirst();

txt_NickName.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_NICK_NAME)));
String tmp_access = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_ACCESS_IP));
if (tmp_access.equalsIgnoreCase( "Resolve IP")) {
config = mydb.getConfig(active_Nick);
txt_NickName.setText(active_Nick);
if (config.ACCESS_IP.equalsIgnoreCase( "Resolve IP")) {
spn_allowip.setSelection(0);
} else if (tmp_access.equalsIgnoreCase("Source IP")) {
} else if (config.ACCESS_IP.equalsIgnoreCase("0.0.0.0")) {
spn_allowip.setSelection(1);
} else {
spn_allowip.setSelection(2);
txt_allowIP.setText(tmp_access);
txt_allowIP.setText(config.ACCESS_IP);
}
txt_tcp_ports.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS)));
txt_udp_ports.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_UDP_PORTS)));
txt_server_ip.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_IP)));
txt_server_port.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_PORT)));
txt_server_time.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_TIMEOUT)));
txt_KEY.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_KEY)));
if (CurrentIndex.getInt(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_KEY_BASE64)) == 1) {

txt_tcp_ports.setText(config.TCP_PORTS);
txt_udp_ports.setText(config.UDP_PORTS);
txt_server_ip.setText(config.SERVER_IP);
txt_server_port.setText(config.SERVER_PORT);
txt_server_time.setText(config.SERVER_TIMEOUT);
txt_KEY.setText(config.KEY);
if (config.KEY_BASE64) {
chkb64key.setChecked(true);
} else { chkb64key.setChecked(false);}
txt_HMAC.setText(CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_HMAC)));
if (CurrentIndex.getInt(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_HMAC_BASE64)) == 1) {
txt_HMAC.setText(config.HMAC);
if (config.HMAC_BASE64) {
chkb64hmac.setChecked(true);
} else { chkb64hmac.setChecked(false);}
CurrentIndex.close();
if (!config.SERVER_CMD.equalsIgnoreCase("")) {
chkservercmd.setChecked(true);
txt_server_cmd.setText(config.SERVER_CMD);
lay_serverCMD.setVisibility(View.VISIBLE);
}
if (!config.NAT_IP.equalsIgnoreCase("")) {
chknataccess.setChecked(true);
txt_nat_ip.setText(config.NAT_IP);
txt_nat_port.setText(config.NAT_PORT);
lay_natIP.setVisibility(View.VISIBLE);
lay_natport.setVisibility(View.VISIBLE);
}
}
return rootView;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import java.util.List;

/**
* An activity representing a list of. This activity
Expand All @@ -39,6 +43,9 @@
*/
public class ConfigListActivity extends FragmentActivity
implements ConfigListFragment.Callbacks {
ConfigDetailFragment fragment;
ConfigListFragment fragment2;

/**
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
* device.
Expand Down Expand Up @@ -69,6 +76,18 @@ protected void onCreate(Bundle savedInstanceState) {


}


public void onItemSaved() {
List<Fragment> allFragments = getSupportFragmentManager().getFragments();
for (Fragment fragment : allFragments) {
if (fragment instanceof ConfigListFragment) {
((ConfigListFragment) fragment).onUpdate();
}
}
}


/**
* Callback method from {@link ConfigListFragment.Callbacks}
* indicating that the item with the given ID was selected.
Expand All @@ -81,7 +100,7 @@ public void onItemSelected(String nick) {
// fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(ConfigDetailFragment.ARG_ITEM_ID, nick);
ConfigDetailFragment fragment = new ConfigDetailFragment();
fragment = new ConfigDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.replace(R.id.config_detail_container, fragment)
Expand All @@ -95,6 +114,9 @@ public void onItemSelected(String nick) {
startActivity(detailIntent);
}
}
public void onCheckboxClicked(View view) {
fragment.onCheckboxClicked(view);
}

protected void onNewIntent(Intent intent) {
super. onNewIntent(intent);
Expand Down
Loading

0 comments on commit e103f3b

Please sign in to comment.