-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,008 additions
and
789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
.../io/treehouses/remote/Fragments/DialogFragments/BottomSheetDialogs/BridgeBottomSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.text.InputType; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
|
||
import io.treehouses.remote.Constants; | ||
import io.treehouses.remote.Fragments.DialogFragments.WifiDialogFragment; | ||
import io.treehouses.remote.R; | ||
import io.treehouses.remote.bases.BaseBottomSheetDialog; | ||
import io.treehouses.remote.callback.HomeInteractListener; | ||
import io.treehouses.remote.pojo.NetworkProfile; | ||
import io.treehouses.remote.utils.SaveUtils; | ||
|
||
import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG; | ||
import static io.treehouses.remote.Fragments.NewNetworkFragment.openWifiDialog; | ||
|
||
public class BridgeBottomSheet extends BaseBottomSheetDialog { | ||
|
||
private EditText essid, password, hotspotEssid, hotspotPassword; | ||
private Button startConfig, addProfile, btnWifiSearch; | ||
|
||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.dialog_bridge, container, false); | ||
|
||
essid = v.findViewById(R.id.et_essid); | ||
password = v.findViewById(R.id.et_password); | ||
hotspotEssid = v.findViewById(R.id.et_hotspot_essid); | ||
hotspotPassword = v.findViewById(R.id.et_hotspot_password); | ||
|
||
startConfig = v.findViewById(R.id.btn_start_config); | ||
addProfile = v.findViewById(R.id.add_bridge_profile); | ||
btnWifiSearch = v.findViewById(R.id.btnWifiSearch); | ||
|
||
try { | ||
essid.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); | ||
hotspotEssid.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
startConfigListener(); | ||
setAddProfileListener(); | ||
|
||
btnWifiSearch.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
openWifiDialog(BridgeBottomSheet.this, context); | ||
} | ||
}); | ||
|
||
return v; | ||
} | ||
|
||
private void startConfigListener() { | ||
startConfig.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String temp = "treehouses bridge \"" + essid.getText().toString() + "\" \"" + hotspotEssid.getText().toString() + "\" "; | ||
String overallMessage = TextUtils.isEmpty(password.getText().toString()) ? temp + "\"\"" : temp + "\"" + password.getText().toString() + "\""; | ||
overallMessage += " "; | ||
|
||
if (!TextUtils.isEmpty(hotspotPassword.getText().toString())) { | ||
overallMessage += "\"" + hotspotPassword.getText().toString() + "\""; | ||
} | ||
listener.sendMessage(overallMessage); | ||
|
||
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show(); | ||
Intent intent = new Intent(); | ||
intent.putExtra(CLICKED_START_CONFIG, true); | ||
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent); | ||
dismiss(); | ||
} | ||
}); | ||
} | ||
|
||
private void setAddProfileListener() { | ||
addProfile.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
NetworkProfile networkProfile = new NetworkProfile(essid.getText().toString(), password.getText().toString(), | ||
hotspotEssid.getText().toString(), hotspotPassword.getText().toString()); | ||
|
||
SaveUtils.addProfile(context, networkProfile); | ||
Toast.makeText(context, "Bridge Profile Added", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if( resultCode != Activity.RESULT_OK ) { | ||
return; | ||
} | ||
if( requestCode == Constants.REQUEST_DIALOG_WIFI ) { | ||
String ssid = data.getStringExtra(WifiDialogFragment.WIFI_SSID_KEY); | ||
essid.setText(ssid); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...o/treehouses/remote/Fragments/DialogFragments/BottomSheetDialogs/EthernetBottomSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
|
||
import io.treehouses.remote.R; | ||
import io.treehouses.remote.bases.BaseBottomSheetDialog; | ||
import io.treehouses.remote.callback.HomeInteractListener; | ||
|
||
import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG; | ||
|
||
public class EthernetBottomSheet extends BaseBottomSheetDialog { | ||
|
||
private EditText etIP, etMask, etGateway, DNSText; | ||
private Button startConfig; | ||
|
||
@Nullable | ||
@Override | ||
|
||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.dialog_ethernet, container, false); | ||
etIP = v.findViewById(R.id.ip); | ||
etMask = v.findViewById(R.id.mask); | ||
etGateway = v.findViewById(R.id.gateway); | ||
DNSText = v.findViewById(R.id.dns); | ||
|
||
startConfig = v.findViewById(R.id.btn_start_config); | ||
|
||
startConfig.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String ip = etIP.getText().toString(); | ||
String dns = DNSText.getText().toString(); | ||
String gateway = etGateway.getText().toString(); | ||
String mask = etMask.getText().toString(); | ||
listener.sendMessage(String.format("treehouses ethernet %s %s %s %s", ip, mask, gateway, dns)); | ||
Intent intent = new Intent(); | ||
intent.putExtra(CLICKED_START_CONFIG, true); | ||
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent); | ||
dismiss(); | ||
} | ||
}); | ||
return v; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...io/treehouses/remote/Fragments/DialogFragments/BottomSheetDialogs/HotspotBottomSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Spinner; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
|
||
import io.treehouses.remote.R; | ||
import io.treehouses.remote.bases.BaseBottomSheetDialog; | ||
import io.treehouses.remote.callback.HomeInteractListener; | ||
import io.treehouses.remote.pojo.NetworkProfile; | ||
import io.treehouses.remote.utils.SaveUtils; | ||
|
||
import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG; | ||
|
||
public class HotspotBottomSheet extends BaseBottomSheetDialog { | ||
private EditText essidText; | ||
private EditText passwordText; | ||
private Button startConfig, addProfile; | ||
private Spinner spinner; | ||
|
||
@Nullable | ||
@Override | ||
|
||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.dialog_hotspot, container, false); | ||
|
||
essidText = v.findViewById(R.id.et_hotspot_ssid); | ||
passwordText = v.findViewById(R.id.et_hotspot_password); | ||
startConfig = v.findViewById(R.id.btn_start_config); | ||
addProfile = v.findViewById(R.id.set_hotspot_profile); | ||
|
||
spinner = v.findViewById(R.id.spn_hotspot_type); | ||
|
||
startConfigListener(); | ||
|
||
setAddProfileListener(); | ||
return v; | ||
} | ||
|
||
private void startConfigListener() { | ||
startConfig.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (passwordText.getText().toString().isEmpty()) { | ||
listener.sendMessage("treehouses ap \"" + spinner.getSelectedItem().toString() + "\" \"" + essidText.getText().toString() + "\""); | ||
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show(); | ||
} else { | ||
listener.sendMessage("treehouses ap \"" + spinner.getSelectedItem().toString() + "\" \"" + essidText.getText().toString() + "\" \"" + passwordText.getText().toString() + "\""); | ||
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show(); | ||
} | ||
Intent intent = new Intent(); | ||
intent.putExtra(CLICKED_START_CONFIG, true); | ||
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent); | ||
dismiss(); | ||
} | ||
}); | ||
} | ||
|
||
private void setAddProfileListener() { | ||
addProfile.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
SaveUtils.addProfile(context, new NetworkProfile(essidText.getText().toString(), passwordText.getText().toString(), spinner.getSelectedItem().toString())); | ||
Toast.makeText(context, "Hotspot Profile Saved", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...va/io/treehouses/remote/Fragments/DialogFragments/BottomSheetDialogs/WifiBottomSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
|
||
import io.treehouses.remote.Constants; | ||
import io.treehouses.remote.Fragments.DialogFragments.WifiDialogFragment; | ||
import io.treehouses.remote.R; | ||
import io.treehouses.remote.bases.BaseBottomSheetDialog; | ||
import io.treehouses.remote.pojo.NetworkProfile; | ||
import io.treehouses.remote.utils.SaveUtils; | ||
|
||
import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG; | ||
import static io.treehouses.remote.Fragments.NewNetworkFragment.openWifiDialog; | ||
|
||
|
||
public class WifiBottomSheet extends BaseBottomSheetDialog { | ||
|
||
private EditText ssidText; | ||
private EditText passwordText; | ||
private Button startConfig, addProfile, searchWifi; | ||
|
||
@Nullable | ||
@Override | ||
|
||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.dialog_wifi, container, false); | ||
ssidText = v.findViewById(R.id.editTextSSID); | ||
passwordText = v.findViewById(R.id.wifipassword); | ||
startConfig = v.findViewById(R.id.btn_start_config); | ||
addProfile = v.findViewById(R.id.set_wifi_profile); | ||
searchWifi = v.findViewById(R.id.btnWifiSearch); | ||
|
||
setStartConfigListener(); | ||
|
||
setAddProfileListener(); | ||
|
||
searchWifi.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
openWifiDialog(WifiBottomSheet.this, context); | ||
|
||
} | ||
}); | ||
|
||
return v; | ||
} | ||
|
||
private void setStartConfigListener() { | ||
startConfig.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String ssid = ssidText.getText().toString(); | ||
String password = passwordText.getText().toString(); | ||
listener.sendMessage(String.format("treehouses wifi \"%s\" \"%s\"", ssid, password)); | ||
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show(); | ||
Intent intent = new Intent(); | ||
intent.putExtra(CLICKED_START_CONFIG, true); | ||
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent); | ||
dismiss(); | ||
} | ||
}); | ||
} | ||
|
||
private void setAddProfileListener() { | ||
addProfile.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
SaveUtils.addProfile(context, new NetworkProfile(ssidText.getText().toString(), passwordText.getText().toString())); | ||
Toast.makeText(context, "WiFi Profile Saved", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if((resultCode == Activity.RESULT_OK) && (requestCode == Constants.REQUEST_DIALOG_WIFI) ) { | ||
ssidText.setText(data.getStringExtra(WifiDialogFragment.WIFI_SSID_KEY)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDismiss(final DialogInterface dialogInterface) { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.