-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Second Commit: Established a TCP connection with my linux device. The…
… connection is working but can't still send a message to the computer. New activities that have been added include realtimeActivity and playlistActivity. Signed-off-by: Dancan <dancangwe@gmail.com>
- Loading branch information
1 parent
a185e03
commit 72cd6fa
Showing
7 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/example/dancan/serverclienttester/PlaylistActivity.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,13 @@ | ||
package com.example.dancan.serverclienttester; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
public class PlaylistActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_playlist); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/example/dancan/serverclienttester/RealtimeActivity.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,54 @@ | ||
package com.example.dancan.serverclienttester; | ||
|
||
import android.os.Bundle; | ||
import android.os.StrictMode; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PrintWriter; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
|
||
public class RealtimeActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_realtime); | ||
|
||
final TextView tView = findViewById(R.id.textView); | ||
final Button button = findViewById(R.id.buttonSend); | ||
//To ensure better performance this line must be removed | ||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | ||
StrictMode.setThreadPolicy(policy); | ||
|
||
button.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
try { | ||
Log.v("Tcp", "Clicked the button"); | ||
Socket s = new Socket("197.239.161.75", 4447); | ||
Log.v("Tcp", "Got the Socket and host address"); | ||
OutputStream out = s.getOutputStream(); | ||
PrintWriter output = new PrintWriter(out); | ||
output.println("Hello Mr Pi!!"); | ||
out.close(); | ||
|
||
} catch (UnknownHostException e) { | ||
tView.setText(e.toString()); | ||
Log.v("Tcp", e.toString()); | ||
} catch (IOException e) { | ||
tView.setText(e.toString()); | ||
Log.v("Tcp", e.toString()); | ||
} catch (Exception e) { | ||
tView.setText(e.toString()); | ||
|
||
} | ||
} | ||
}); | ||
} | ||
} |
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,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".PlaylistActivity"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" | ||
android:text="@string/playlist" | ||
android:textColor="@color/colorPrimary" | ||
android:textSize="30sp" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="2" | ||
android:orientation="vertical"> | ||
|
||
<ListView | ||
android:id="@+id/playlist" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
</LinearLayout> | ||
|
||
<!--<RelativeLayout--> | ||
<!--android:layout_width="match_parent"--> | ||
<!--android:layout_height="0dp"--> | ||
<!--android:layout_weight="1">--> | ||
<!--<TextView--> | ||
<!--android:layout_width="wrap_content"--> | ||
<!--android:layout_height="wrap_content" --> | ||
<!--android:id="@+id/playingTune"--> | ||
<!--android:background="@color/colorBrown"/>--> | ||
<!----> | ||
<!--</RelativeLayout>--> | ||
|
||
</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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".RealtimeActivity"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="@color/colorPrimaryDark" /> | ||
|
||
<Button | ||
android:id="@+id/buttonSend" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_gravity="center" | ||
android:layout_margin="8dp" | ||
android:background="@drawable/music" /> | ||
|
||
</LinearLayout> |