Skip to content
Snippets Groups Projects
Commit ef6ecb96 authored by riska's avatar riska
Browse files

wassalam

parent aa2a5828
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="LOCAL" /> <option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="E:\Program Files\Android\Android Studio\gradle\gradle-2.2.1" /> <option name="gradleHome" value="C:\Program Files\Android\Android Studio1\gradle\gradle-2.2.1" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
......
...@@ -5,58 +5,36 @@ import android.content.Intent; ...@@ -5,58 +5,36 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableRow;
import android.widget.TextView;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
<<<<<<< HEAD
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
=======
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
>>>>>>> 2655f8eae877e785f39925089bc68057dbd70346
import java.net.Socket; import java.net.Socket;
public class FindItemActivity extends Activity { public class FindItemActivity extends Activity {
JSONObject request, response; JSONObject request, response;
<<<<<<< HEAD private String ip;
String ip; private int port;
int port; private Socket socket;
=======
Socket socket;
String ip, port;
PrintWriter printWriter; PrintWriter printWriter;
DataInputStream is; DataInputStream is;
DataOutputStream os; DataOutputStream os;
BufferedReader buffer; BufferedReader buffer;
String token = "123adsfja3sd0";
int item = 1;
>>>>>>> 2655f8eae877e785f39925089bc68057dbd70346
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_item); setContentView(R.layout.activity_find_item);
try {
onFindItemResult(token, item);
} catch (JSONException e) {
e.printStackTrace();
}
} }
public void onFindItemResult(String token, int item) throws JSONException, IOException { public void onFindItemResult(String token, int item) throws JSONException, IOException {
Socket socket = new Socket(ip,port); Socket socket = new Socket(ip,port);
socket.setSoTimeout(100); socket.setSoTimeout(100);
...@@ -65,68 +43,11 @@ public class FindItemActivity extends Activity { ...@@ -65,68 +43,11 @@ public class FindItemActivity extends Activity {
request.put("token",token); request.put("token",token);
request.put("item",item); request.put("item",item);
<<<<<<< HEAD
BufferedWriter out = new BufferedWriter(new OutputStreamWriter( BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream() socket.getOutputStream()
)); ));
out.write(request.toString()); out.write(request.toString());
out.flush(); out.flush();
socket.close(); socket.close();
=======
new ItemFinder().execute(request);
}
public class ItemFinder extends AsyncTask<JSONObject, Void, String>{
@Override
protected String doInBackground(JSONObject... req) {
String respons = null;
try{
respons = sendRequest();
}
catch(IOException e){
e.printStackTrace();
}
return respons;
}
public String sendRequest() throws IOException {
String resp = null;
try {
socket = new Socket(ip, Integer.parseInt(port));
socket.setSoTimeout(30);
is = new DataInputStream(socket.getInputStream());
os = new DataOutputStream(socket.getOutputStream());
printWriter = new PrintWriter(os);
buffer = new BufferedReader(new InputStreamReader(is));
resp = getResponse();
}
catch(IOException e){
e.printStackTrace();
}
return resp;
}
public String getResponse() throws IOException {
printWriter.println(request.toString());
printWriter.flush();
String inputLine;
String respons = null;
while((inputLine=buffer.readLine())!= null){
respons += inputLine;
}
is.close();
os.close();
return respons;
}
@Override
protected void onPostExecute(String response){
}
>>>>>>> 2655f8eae877e785f39925089bc68057dbd70346
} }
} }
...@@ -82,15 +82,12 @@ public class MainActivity extends Activity { ...@@ -82,15 +82,12 @@ public class MainActivity extends Activity {
response = in.readLine(); response = in.readLine();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
response = "UnknownHostException: " + e.toString(); response = "UnknownHostException: " + e.toString();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
response = "IOException: " + e.toString(); response = "IOException: " + e.toString();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
response = "Exception: " + e.toString(); response = "Exception: " + e.toString();
} finally{ } finally{
...@@ -98,7 +95,6 @@ public class MainActivity extends Activity { ...@@ -98,7 +95,6 @@ public class MainActivity extends Activity {
try { try {
socket.close(); socket.close();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -29,7 +29,8 @@ public class RegisterActivity extends Activity { ...@@ -29,7 +29,8 @@ public class RegisterActivity extends Activity {
private DataOutputStream os ; private DataOutputStream os ;
private BufferedReader buffer; private BufferedReader buffer;
EditText username, password; EditText username, password;
String ip, port; private String ip;
private int port;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -43,7 +44,7 @@ public class RegisterActivity extends Activity { ...@@ -43,7 +44,7 @@ public class RegisterActivity extends Activity {
password = (EditText)findViewById(R.id.editText2); password = (EditText)findViewById(R.id.editText2);
String pass = password.getText().toString(); String pass = password.getText().toString();
socket = new Socket(ip,port); socket = new Socket(ip, port);
socket.setSoTimeout(100); socket.setSoTimeout(100);
request = new JSONObject(); request = new JSONObject();
request.put("method", "signup"); request.put("method", "signup");
......
...@@ -226,33 +226,71 @@ ...@@ -226,33 +226,71 @@
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:id="@+id/Button11" android:id="@+id/Button11"
android:layout_marginTop="73dp" android:layout_below="@+id/textView11"
android:layout_below="@+id/textView6" android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/button2" android:layout_alignParentStart="true" />
android:layout_toStartOf="@+id/button2" />
<Button <Button
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:id="@+id/button12" android:id="@+id/button12"
android:layout_below="@+id/Button11" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> android:layout_alignParentStart="true"
android:layout_marginBottom="62dp" />
<Button <Button
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="40dp" android:layout_height="40dp"
android:text="OK" android:text="OK"
android:id="@+id/button13" android:id="@+id/button13"
android:layout_above="@+id/button12" android:layout_alignTop="@+id/editText5"
android:layout_alignLeft="@+id/button14" android:layout_alignLeft="@+id/textView9"
android:layout_alignStart="@+id/button14" /> android:layout_alignStart="@+id/textView9" />
<Button <Button
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="40dp" android:layout_height="40dp"
android:id="@+id/button14" android:id="@+id/button14"
android:text="Back" android:text="Back"
android:layout_above="@+id/editText6"
android:layout_alignLeft="@+id/button13"
android:layout_alignStart="@+id/button13" />
<EditText
android:layout_width="40dp"
android:layout_height="40dp"
android:inputType="number"
android:ems="10"
android:id="@+id/editText5"
android:layout_alignBottom="@+id/Button11"
android:layout_toLeftOf="@+id/button8"
android:layout_toStartOf="@+id/button8" />
<EditText
android:layout_width="40dp"
android:layout_height="40dp"
android:inputType="number"
android:ems="10"
android:id="@+id/editText6"
android:layout_alignBottom="@+id/button12" android:layout_alignBottom="@+id/button12"
android:layout_alignLeft="@+id/textView9" android:layout_toRightOf="@+id/textView7"
android:layout_alignStart="@+id/textView9" /> android:layout_toEndOf="@+id/textView7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offered Item"
android:id="@+id/textView11"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Demanded Item"
android:id="@+id/textView12"
android:layout_above="@+id/button12"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout> </RelativeLayout>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment