Skip to content

Commit

Permalink
ServerConnectionCriado
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jun 28, 2020
1 parent 0314509 commit 127d9f6
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 4 deletions.
17 changes: 17 additions & 0 deletions App/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>App</name>
<comment>Project App created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions App/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/Java/jdk1.8.0_181
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
3 changes: 2 additions & 1 deletion App/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gazeboindustries.sextafeiramobile">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class HomeFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home, container, false);
View view = inflater.inflate(R.layout.fragment_home, container, false);


return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ protected void onCreate(Bundle savedInstanceState) {
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setSelectedItemId(R.id.navigation_home);
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

new ServerConnection("getProjects");

}


public void changeFrame(Fragment fragment){
getSupportFragmentManager().beginTransaction().replace(R.id.frame, fragment).commit();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.gazeboindustries.sextafeiramobile;

import android.os.AsyncTask;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

public class ServerConnection extends AsyncTask<String, Integer, String> {
private String IP = "192.168.0.5";
private int port = 5000;
private Socket socket;
private PrintWriter out;
private BufferedReader in;
private JSONObject jsonRequest;
private JSONObject jsonResponse;
private String data;
private ArrayList<JSONArray> list;
private JSONArray arrayResponse;
private char[] buffer = new char[5800];

public ServerConnection(String request){
execute(request);
}

@Override
protected String doInBackground(String... params) {
try {
this.socket = new Socket(IP, port);
this.out = new PrintWriter(this.socket.getOutputStream(), true);
this.in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));

jsonRequest = new JSONObject();
jsonRequest.put("header", "gazeboindustries09082004");
jsonRequest.put("request", params[0]);

this.out.println(jsonRequest);

this.in.read(buffer);

data = new String(buffer);

this.jsonResponse = new JSONObject(data.trim());

System.out.println(this.jsonResponse);

list = new ArrayList<>();

for (int c = 0; c < jsonResponse.length(); c++){
arrayResponse = (JSONArray) jsonResponse.get(Integer.toString(c));
list.add(arrayResponse);
System.out.println(list);
}

} catch (IOException | JSONException e) {
System.out.println("DEU ERRO");
e.printStackTrace();
}
return null;
}
}
3 changes: 2 additions & 1 deletion App/app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="wrap_content"
android:text="@string/boa_tarde_chefe"
android:textColor="@android:color/white"
android:textSize="50sp"
android:textSize="45sp"
android:fontFamily="sans-serif-black"
android:layout_gravity="center"
android:layout_marginTop="120dp"/>
Expand Down Expand Up @@ -113,6 +113,7 @@
android:textColor="@android:color/white"
android:textSize="30sp"
android:drawableStart="@drawable/ic_play_circle_filled_white_24dp"
android:id="@+id/btnStartFriday"
/>


Expand Down
2 changes: 1 addition & 1 deletion Configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"ServerConfigs": {
"ID": "Server",
"Host": "192.168.0.4",
"Host": "192.168.0.5",
"Port": 5000
},
"InterfaceConfigs": {
Expand Down

0 comments on commit 127d9f6

Please sign in to comment.