Skip to content

Commit

Permalink
Second Commit: Established a TCP connection with my linux device. The…
Browse files Browse the repository at this point in the history
… 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
dancanangwenyi committed Sep 2, 2018
1 parent a185e03 commit 72cd6fa
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 4 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dancan.serverclienttester">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -14,12 +17,15 @@
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ServerActivity" />
<activity android:name=".ClientActivity" />
<activity android:name=".ComposeActivity"></activity>
<activity android:name=".ComposeActivity" />
<activity android:name=".PlaylistActivity" />
<activity android:name=".RealtimeActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,41 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.dancan.serverclienttester.MESSAGE";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
Button buttonPlaylist = findViewById(R.id.playlist);
Button buttonCompose = findViewById(R.id.compose);
Button buttonRealTime = findViewById(R.id.realButton);
buttonPlaylist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, PlaylistActivity.class);
startActivity(intent);
}
});
buttonCompose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, ComposeActivity.class);
startActivity(intent);
}
});
buttonRealTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, RealtimeActivity.class);
startActivity(intent);
}
});



}

/**
Expand Down
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);
}
}
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());

}
}
});
}
}
41 changes: 41 additions & 0 deletions app/src/main/res/layout/activity_playlist.xml
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>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_realtime.xml
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>

0 comments on commit 72cd6fa

Please sign in to comment.