Skip to content
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

info page #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

10 changes: 3 additions & 7 deletions DarkChatter/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions DarkChatter/.idea/vcs.xml

This file was deleted.

17 changes: 17 additions & 0 deletions DarkChatter/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="comdarkchatter.github.darkchatter">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -12,13 +16,26 @@
<activity
android:name=".GroupActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".ChatActivity"
android:label="@string/title_activity_chat"
android:parentActivityName=".GroupActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="comdarkchatter.github.darkchatter.GroupActivity" />
</activity>
<activity
android:name=".InfoPage"
android:label="@string/title_activity_info_page"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package comdarkchatter.github.darkchatter;

import android.app.Activity;
import android.content.Intent;
import android.net.nsd.NsdServiceInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.support.design.widget.Snackbar;
import comdarkchatter.github.darkchatter.NsdHelper;

public class ChatActivity extends Activity {

NsdHelper mNsdHelper;

private TextView mStatusView;
private Handler mUpdateHandler;

public static final String TAG = "NsdChat";

ChatConnection mConnection;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "Creating chat activity");
setContentView(R.layout.main);
mStatusView = (TextView) findViewById(R.id.status);

mUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
String chatLine = msg.getData().getString("msg");
addChatLine(chatLine);
}
};

}

public void clickAdvertise(View v) {
// Register service
if(mConnection.getLocalPort() > -1) {
mNsdHelper.registerService(mConnection.getLocalPort());
} else {
//User-side warning when register fails
Snackbar registerError = Snackbar.make(v, "Unable to register!", Snackbar.LENGTH_SHORT);
registerError.show();
Log.d(TAG, "ServerSocket isn't bound.");
}
}

public void clickDiscover(View v) {
mNsdHelper.discoverServices();
}

public void clickConnect(View v) {
NsdServiceInfo service = mNsdHelper.getChosenServiceInfo();
if (service != null) {
Log.d(TAG, "Connecting.");
mConnection.connectToServer(service.getHost(),
service.getPort());
} else {
//User-side warning when connect fails
Snackbar connectError = Snackbar.make(v, "Unable to connect! There is a problem with the service.", Snackbar.LENGTH_SHORT);
connectError.show();
Log.d(TAG, "No service to connect to!");
}
}

public void clickSend(View v) {
EditText messageView = (EditText) this.findViewById(R.id.chatInput);
if (messageView != null) {
String messageString = messageView.getText().toString();
if (!messageString.isEmpty()) {
boolean messageSent = mConnection.sendMessage(messageString);
if (!messageSent){
//User-side warning when connect fails
Snackbar messageSentError = Snackbar.make(v, "Message was not sent. There is a problem with the service.", Snackbar.LENGTH_SHORT);
messageSentError.show();
}
}
messageView.setText("");
}
}

/** Called when the user taps the info button*/
public void infoPage(View v) {
Button info = (Button) findViewById(R.id.info);
info.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
Intent infoPage = new Intent(ChatActivity.this, InfoPage.class);
//GroupActivity.this.startActivity(chat);
startActivity(infoPage);

}
});
}

public void addChatLine(String line) {
mStatusView.append("\n" + line);
}

@Override
protected void onStart() {
Log.d(TAG, "Starting.");
mConnection = new ChatConnection(mUpdateHandler);

mNsdHelper = new NsdHelper(this);
mNsdHelper.initializeNsd();
super.onStart();
}


@Override
protected void onPause() {
Log.d(TAG, "Pausing.");
if (mNsdHelper != null) {
mNsdHelper.stopDiscovery();
}
super.onPause();
}

@Override
protected void onResume() {
Log.d(TAG, "Resuming.");
super.onResume();
if (mNsdHelper != null) {
mNsdHelper.discoverServices();
}
}


// For KitKat and earlier releases, it is necessary to remove the
// service registration when the application is stopped. There's
// no guarantee that the onDestroy() method will be called (we're
// killable after onStop() returns) and the NSD service won't remove
// the registration for us if we're killed.

// In L and later, NsdService will automatically unregister us when
// our connection goes away when we're killed, so this step is
// optional (but recommended).

@Override
protected void onStop() {
Log.d(TAG, "Being stopped.");
mNsdHelper.tearDown();
mConnection.tearDown();
mNsdHelper = null;
mConnection = null;
super.onStop();
}

@Override
protected void onDestroy() {
Log.d(TAG, "Being destroyed.");
super.onDestroy();
}
}
Loading