Skip to content

Commit

Permalink
passwordless treehouses bridge (fixes #155) (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcouture27 authored and dogi committed Feb 7, 2019
1 parent 97f47a5 commit 80251ff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected AlertDialog getAlertDialog(View mView) {
.setPositiveButton(R.string.start_configuration,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// getActivity().getIntent().putExtra("isValidInput", mSSIDEditText.getText().toString().length() > 0? Boolean.TRUE: Boolean.FALSE);
String essid = ESSIDEditText.getText().toString();
String hotspotessid = HotspotESSIDEditText.getText().toString();
String password = PasswordEditText.getText().toString();
Expand All @@ -70,6 +69,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
Intent intent = new Intent();
intent.putExtra("essid", essid);
intent.putExtra("hssid", hotspotessid);
intent.putExtra("type","bridge");
intent.putExtra("password",password);
intent.putExtra("hpassword",hotspotpassword);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package io.treehouses.remote.Fragments;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;

import androidx.fragment.app.FragmentActivity;
import io.treehouses.remote.InitialActivity;
import io.treehouses.remote.MiscOld.Constants;
import io.treehouses.remote.Network.BluetoothChatService;
import io.treehouses.remote.R;

import static android.content.Context.WIFI_SERVICE;
Expand All @@ -28,14 +36,20 @@ public class NetworkFragment extends androidx.fragment.app.Fragment {

InitialActivity initialActivity;

// EditText HotspotPasswordEditText;
// EditText PasswordEditText;

public NetworkFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

view = inflater.inflate(R.layout.activity_network_fragment, container, false);

initialActivity = new InitialActivity();
BluetoothChatService chatService = initialActivity.getChatService();
chatService.updateHandler(mHandler);

ArrayList<String> list = new ArrayList<String>();
list.add("Ethernet");
Expand Down Expand Up @@ -164,7 +178,7 @@ private void wifiOn(Bundle bundle){
// boolean b = wifi.enableNetwork(res, true);
// Log.d("WifiPreference", "enableNetwork returned " + b );
}
private void hotspotOn(Bundle bundle){
private void hotspotOn (Bundle bundle){
if(bundle.getString("HPWD").equals("")){
initialActivity.sendMessage("treehouses ap "+bundle.getString("hotspotType")+" "+bundle.getString("HSSID"));
}else{
Expand All @@ -174,7 +188,48 @@ private void hotspotOn(Bundle bundle){
private void ethernetOn(Bundle bundle){
initialActivity.sendMessage("treehouses ethernet "+bundle.getString("ip")+" "+bundle.getString("mask")+" "+bundle.getString("gateway")+" "+bundle.getString("dns"));
}

private void bridgeOn(Bundle bundle){
initialActivity.sendMessage("treehouses bridge "+bundle.getString("essid")+" "+bundle.getString("hssid")+" "+bundle.getString("password")+" "+bundle.getString("hpassword"));
String overallMessage = "treehouses bridge "+(bundle.getString("essid"))+" "+bundle.getString("hssid")+" ";

if(TextUtils.isEmpty(bundle.getString("password"))){
overallMessage+="\"\"";
}else{
overallMessage+=bundle.getString("password");
}
overallMessage+=" ";
if(!TextUtils.isEmpty(bundle.getString("hpassword"))){
overallMessage+=bundle.getString("hpassword");
}
Log.e("NetworkFragment","Bridge RPI Message = "+overallMessage);
initialActivity.sendMessage(overallMessage);
}
}

private AlertDialog showAlertDialog(String message){
return new AlertDialog.Builder(getContext())
.setTitle("OUTPUT:")
.setMessage(message)
.setIcon(R.drawable.wificon)
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) { dialog.cancel(); }
})
.show();
}

/**
* The Handler that gets information back from the BluetoothChatService
*/
public final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
FragmentActivity activity = getActivity();
switch (msg.what) {
case Constants.MESSAGE_READ:
String readMessage = (String)msg.obj;
showAlertDialog(readMessage);
break;
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void getListFragment(int position){
switch (position){
case 0:
// showEthernetDialog();

break;
case 1:
initialActivity.sendMessage("treehouses expandfs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ private void validateETHERNET(final Context context) {
*
*/
private void validateBridge(final Context context) {
if (ESSIDEditText.length() == 0 || HotspotESSIDEditText.length() == 0 || PasswordEditText.length() == 0 || HotspotPasswordEditText.length() == 0) {
if (ESSIDEditText.length() == 0 || HotspotESSIDEditText.length() == 0) {

dialogButtonTrueOrFalse(mDialog, false);
PasswordEditText.setError(context.getString(R.string.error_pwd_length));
HotspotPasswordEditText.setError(context.getString(R.string.error_pwd_length));
//PasswordEditText.setError(context.getString(R.string.error_pwd_length));
//HotspotPasswordEditText.setError(context.getString(R.string.error_pwd_length));
}else {
dialogButtonTrueOrFalse(mDialog,true);
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ buildscript {

allprojects {
repositories {
jcenter()
google()
jcenter()
}
}

Expand Down

0 comments on commit 80251ff

Please sign in to comment.