-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: interface for ESP wifi module added #1911
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,99 @@ | ||
package io.pslab.fragment; | ||
|
||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.DialogFragment; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ProgressBar; | ||
import android.widget.Toast; | ||
|
||
import java.io.IOException; | ||
|
||
import io.pslab.R; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class ESPFragment extends DialogFragment { | ||
private String espIPAddress = ""; | ||
private ProgressBar espConnectProgressBar; | ||
private Button espConnectBtn; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View rootView = inflater.inflate(R.layout.fragment_esp, container, false); | ||
EditText espIPEditText = rootView.findViewById(R.id.esp_ip_edit_text); | ||
espConnectBtn = rootView.findViewById(R.id.esp_connect_btn); | ||
espConnectProgressBar = rootView.findViewById(R.id.esp_connect_progressbar); | ||
espConnectBtn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
espIPAddress = espIPEditText.getText().toString(); | ||
if (espIPAddress.length() == 0) { | ||
Toast.makeText(getContext(), getResources().getString(R.string.incorrect_IP_address_message), Toast.LENGTH_SHORT).show(); | ||
} else { | ||
new ESPTask().execute(); | ||
} | ||
} | ||
}); | ||
return rootView; | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes(); | ||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT; | ||
params.width = ViewGroup.LayoutParams.MATCH_PARENT; | ||
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); | ||
} | ||
|
||
private class ESPTask extends AsyncTask<Void, Void, String> { | ||
|
||
@Override | ||
protected void onPreExecute() { | ||
espConnectBtn.setVisibility(View.GONE); | ||
espConnectProgressBar.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
protected String doInBackground(Void... voids) { | ||
String result = ""; | ||
try { | ||
OkHttpClient client = new OkHttpClient(); | ||
Request request = new Request.Builder() | ||
.url("http://" + espIPAddress) | ||
.build(); | ||
Response response = client.newCall(request).execute(); | ||
result = response.body().string(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(String result) { | ||
espConnectProgressBar.setVisibility(View.GONE); | ||
espConnectBtn.setVisibility(View.VISIBLE); | ||
if (result.length() == 0) { | ||
Toast.makeText(getContext(), getResources().getString(R.string.incorrect_IP_address_message), Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Log.v("Response", result); | ||
} | ||
} | ||
} | ||
} |
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,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24.0" android:viewportWidth="24.0" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#FF000000" android:pathData="M17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88z"/> | ||
</vector> |
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,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24.0" android:viewportWidth="24.0" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#FF000000" android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/> | ||
</vector> |
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,74 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_margin="@dimen/dialog_space_width"> | ||
|
||
<io.pslab.items.SquareLinearLayout | ||
android:id="@+id/bluetooth_btn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/dialog_space_width" | ||
android:layout_weight="1" | ||
android:background="@drawable/btn_back_rounded" | ||
android:orientation="vertical" | ||
android:paddingTop="@dimen/btn_padding" | ||
android:stateListAnimator="@animator/selector_animator"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:maxLines="1" | ||
android:paddingLeft="@dimen/btn_title_side_padding" | ||
android:paddingRight="@dimen/btn_title_side_padding" | ||
android:text="@string/bluetooth" | ||
android:textColor="@color/white" | ||
android:textStyle="bold" /> | ||
|
||
<ImageView | ||
android:layout_width="@dimen/bluetooth_wifi_icon_dimen" | ||
android:layout_height="@dimen/bluetooth_wifi_icon_dimen" | ||
android:layout_gravity="center" | ||
android:layout_margin="@dimen/btn_margin" | ||
android:src="@drawable/ic_bluetooth" /> | ||
|
||
</io.pslab.items.SquareLinearLayout> | ||
|
||
<View | ||
android:layout_width="@dimen/separator_width" | ||
android:layout_height="match_parent" | ||
android:layout_marginTop="@dimen/dialog_sep_margin_top" | ||
android:layout_marginBottom="@dimen/dialog_sep_margin_top" | ||
android:background="@color/grey_light" /> | ||
|
||
<io.pslab.items.SquareLinearLayout | ||
android:id="@+id/wifi_btn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/dialog_space_width" | ||
android:layout_weight="1" | ||
android:background="@drawable/btn_back_rounded" | ||
android:orientation="vertical" | ||
android:paddingTop="@dimen/btn_padding" | ||
android:stateListAnimator="@animator/selector_animator"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:maxLines="1" | ||
android:text="@string/wifi" | ||
android:textColor="@color/white" | ||
android:textStyle="bold" /> | ||
|
||
<ImageView | ||
android:layout_width="@dimen/bluetooth_wifi_icon_dimen" | ||
android:layout_height="@dimen/bluetooth_wifi_icon_dimen" | ||
android:layout_gravity="center" | ||
android:layout_margin="@dimen/btn_margin" | ||
android:src="@drawable/ic_wifi" /> | ||
</io.pslab.items.SquareLinearLayout> | ||
|
||
</LinearLayout> |
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,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/esp_fragment_padding"> | ||
|
||
<EditText | ||
android:id="@+id/esp_ip_edit_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:hint="@string/enter_IP_hint" /> | ||
|
||
<Button | ||
android:id="@+id/esp_connect_btn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/esp_ip_edit_text" | ||
android:layout_centerHorizontal="true" | ||
android:background="@color/colorPrimary" | ||
android:text="@string/esp_connect_text" | ||
android:textColor="@color/white" /> | ||
|
||
<ProgressBar | ||
android:id="@+id/esp_connect_progressbar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/esp_ip_edit_text" | ||
android:layout_centerHorizontal="true" | ||
android:visibility="gone" /> | ||
</RelativeLayout> |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reformat the whole code to add proper indents and spaces. Should be quiet obvious by now.