diff options
Diffstat (limited to 'app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java')
-rw-r--r-- | app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java | 341 |
1 files changed, 172 insertions, 169 deletions
diff --git a/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java b/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java index 9b07246..341fb68 100644 --- a/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java +++ b/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java @@ -20,6 +20,7 @@ package fil.libre.repwifiapp.activities; +import fil.libre.repwifiapp.ActivityLauncher; import fil.libre.repwifiapp.Commons; import fil.libre.repwifiapp.R; import fil.libre.repwifiapp.helpers.AccessPointInfo; @@ -40,178 +41,180 @@ import android.widget.TextView; public class SelectNetworkActivity extends Activity implements OnClickListener { - private AccessPointInfo[] aps; - - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_select_network); - - setTitle("Select network"); - - getNetworks(); - - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - //Suppress menu button - return true; - } - - private void writeOut(String msg) { - - TextView v = (TextView)findViewById(R.id.txt_selnets); - v.setText(msg); - - } - - private void getNetworks(){ - - Intent intent = getIntent(); - if(! intent.hasExtra(Commons.EXTRA_APINFO_ARR)){ - this.setResult(RESULT_CANCELED); - finish(); - return; - } - AccessPointInfo[] nets = (AccessPointInfo[])intent.getExtras().getSerializable(Commons.EXTRA_APINFO_ARR); - if (nets == null){ - this.setResult(RESULT_CANCELED); - finish(); - return; - } - - int reqCode = intent.getExtras().getInt(Commons.EXTRA_REQCODE); - - this.aps = nets; - - if (reqCode == Commons.RequestCode.SELECT_CONN){ - showNetworksForConnection(nets); - } - else{ - showNetworksForManagement(nets); - } - - } - - public void btnScanClick(View v){ - returnResults(null, true); - } - - @Override + private AccessPointInfo[] aps; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_select_network); + + setTitle("Select network"); + + getNetworks(); + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Suppress menu button + return true; + } + + private void writeOut(String msg) { + + TextView v = (TextView) findViewById(R.id.txt_selnets); + v.setText(msg); + + } + + private void getNetworks() { + + Intent intent = getIntent(); + if (!intent.hasExtra(ActivityLauncher.EXTRA_APINFO_ARR)) { + this.setResult(RESULT_CANCELED); + finish(); + return; + } + AccessPointInfo[] nets = (AccessPointInfo[]) intent.getExtras().getSerializable( + ActivityLauncher.EXTRA_APINFO_ARR); + if (nets == null) { + this.setResult(RESULT_CANCELED); + finish(); + return; + } + + int reqCode = intent.getExtras().getInt(ActivityLauncher.EXTRA_REQCODE); + + this.aps = nets; + + if (reqCode == ActivityLauncher.RequestCode.SELECT_CONN) { + showNetworksForConnection(nets); + } else { + showNetworksForManagement(nets); + } + + } + + public void btnScanClick(View v) { + returnResults(null, true); + } + + @Override public void onClick(View v) { - if (v instanceof NetworkButton){ - networkNameClick((NetworkButton)v); - } + if (v instanceof NetworkButton) { + networkNameClick((NetworkButton) v); + } + + } + + public void networkNameClick(NetworkButton b) { + + for (AccessPointInfo i : this.aps) { + + if (i.getBssid().equals(b.getNetworkBSSID())) { + + returnResults(i, false); + + } + + } + } + + private void returnResults(AccessPointInfo i, boolean rescan) { + + Intent intent = new Intent(); + intent.putExtra(ActivityLauncher.EXTRA_APINFO, i); + intent.putExtra(ActivityLauncher.EXTRA_RESCAN, rescan); + setResult(RESULT_OK, intent); + finish(); + + } + + private void showNetworksForConnection(AccessPointInfo[] info) { + + if (info == null) { + Utils.logError("Unable to retrieve network list!"); + writeOut("Unable to retrieve network list!"); + return; + } + + if (info.length == 0) { + writeOut("No network found."); + toggleBtnRescan(true); + return; + } + + writeOut("Select the network you want to connect to:"); + toggleBtnRescan(false); + + for (AccessPointInfo i : info) { + + addButtonForNetwork(i); + + } + + } + + private void showNetworksForManagement(AccessPointInfo[] info) { + + if (info == null || info.length == 0) { + return; + } + + writeOut("Select network info to manage:"); + toggleBtnRescan(false); + + for (AccessPointInfo i : info) { + + addButtonForNetwork(i); + + } + + } + + private void toggleBtnRescan(boolean enable) { + + Button b = (Button) findViewById(R.id.btn_rescan); + if (enable) { + b.setVisibility(View.VISIBLE); + } else { + b.setVisibility(View.INVISIBLE); + } + } + + private void addButtonForNetwork(AccessPointInfo info) { + + TableLayout s = (TableLayout) findViewById(R.id.table_networks); + TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + TableRow row = new TableRow(this); + TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.WRAP_CONTENT); + rowParams.gravity = Gravity.FILL_HORIZONTAL; + row.setPadding(10, 10, 10, 10); + row.setLayoutParams(rowParams); + row.setGravity(Gravity.FILL_HORIZONTAL); + row.setLayoutParams(rowParams); + + NetworkButton button = new NetworkButton(this, info.getBssid()); + + TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.WRAP_CONTENT); + button.setLayoutParams(params); + button.setBackground(getResources().getDrawable(R.drawable.repwifi_button)); + button.setTextColor(Commons.colorThemeLight); + button.setTextSize(20); + button.setPadding(25, 10, 25, 10); + button.setGravity(Gravity.CENTER_HORIZONTAL); + button.setText(info.getSsid(20)); + button.setOnClickListener(this); + + row.addView(button, params); + row.setGravity(Gravity.CENTER_HORIZONTAL); + s.addView(row, tableParams); + s.setGravity(Gravity.FILL_HORIZONTAL); } - - public void networkNameClick(NetworkButton b){ - - for(AccessPointInfo i : this.aps){ - - if (i.getBSSID().equals(b.getNetworkBSSID())){ - - returnResults(i,false); - - } - - } - } - - private void returnResults(AccessPointInfo i, boolean rescan){ - - Intent intent = new Intent(); - intent.putExtra(Commons.EXTRA_APINFO, i); - intent.putExtra(Commons.EXTRA_RESCAN, rescan); - setResult(RESULT_OK, intent); - finish(); - - } - - private void showNetworksForConnection(AccessPointInfo[] info) { - - if (info == null){ - Utils.logError("Unable to retrieve network list!"); - writeOut("Unable to retrieve network list!"); - return; - } - - if (info.length == 0){ - writeOut("No network found."); - toggleBtnRescan(true); - return; - } - - writeOut("Select the network you want to connect to:"); - toggleBtnRescan(false); - - for (AccessPointInfo i : info){ - - addButtonForNetwork(i); - - } - - } - - private void showNetworksForManagement(AccessPointInfo[] info){ - - if (info == null || info.length == 0){ - return; - } - - writeOut("Select network info to manage:"); - toggleBtnRescan(false); - - for (AccessPointInfo i : info){ - - addButtonForNetwork(i); - - } - - } - - private void toggleBtnRescan(boolean enable) { - - Button b = (Button)findViewById(R.id.btn_rescan); - if (enable){ - b.setVisibility(View.VISIBLE); - } - else{ - b.setVisibility(View.INVISIBLE); - } - } - - private void addButtonForNetwork(AccessPointInfo info){ - - TableLayout s = (TableLayout)findViewById(R.id.table_networks); - TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - TableRow row = new TableRow(this); - TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - rowParams.gravity = Gravity.FILL_HORIZONTAL; - row.setPadding(10, 10, 10, 10); - row.setLayoutParams(rowParams); - row.setGravity(Gravity.FILL_HORIZONTAL); - row.setLayoutParams(rowParams); - - NetworkButton button = new NetworkButton(this, info.getBSSID()); - - TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - button.setLayoutParams(params); - button.setBackgroundColor(Commons.colorThemeDark); - button.setTextColor(Commons.colorThemeLight); - button.setTextSize(20); - button.setPadding(10, 10, 10, 10); - button.setGravity(Gravity.CENTER_HORIZONTAL); - button.setText(info.getSSID()); - button.setOnClickListener(this); - - row.addView(button,params); - s.addView(row,tableParams); - s.setGravity(Gravity.FILL_HORIZONTAL); - - } } |