|
@@ -1,21 +1,29 @@
|
|
|
package com.example.david.myapplication;
|
|
package com.example.david.myapplication;
|
|
|
|
|
|
|
|
import android.content.pm.ActivityInfo;
|
|
import android.content.pm.ActivityInfo;
|
|
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
+import android.text.Layout;
|
|
|
|
|
+import android.text.method.ScrollingMovementMethod;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
import android.view.GestureDetector;
|
|
import android.view.GestureDetector;
|
|
|
import android.view.GestureDetector.OnGestureListener;
|
|
import android.view.GestureDetector.OnGestureListener;
|
|
|
import android.view.MotionEvent;
|
|
import android.view.MotionEvent;
|
|
|
|
|
+import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
import android.view.Window;
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
import android.widget.ViewSwitcher;
|
|
import android.widget.ViewSwitcher;
|
|
|
|
|
|
|
|
|
|
+import com.google.android.gms.appindexing.Action;
|
|
|
|
|
+import com.google.android.gms.appindexing.AppIndex;
|
|
|
|
|
+import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
import com.neovisionaries.ws.client.WebSocket;
|
|
import com.neovisionaries.ws.client.WebSocket;
|
|
|
import com.neovisionaries.ws.client.WebSocketAdapter;
|
|
import com.neovisionaries.ws.client.WebSocketAdapter;
|
|
|
import com.neovisionaries.ws.client.WebSocketException;
|
|
import com.neovisionaries.ws.client.WebSocketException;
|
|
@@ -25,6 +33,8 @@ import com.neovisionaries.ws.client.WebSocketListener;
|
|
|
import com.squareup.picasso.Picasso;
|
|
import com.squareup.picasso.Picasso;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
@@ -37,45 +47,108 @@ import io.vov.vitamio.LibsChecker;
|
|
|
import io.vov.vitamio.MediaPlayer;
|
|
import io.vov.vitamio.MediaPlayer;
|
|
|
import io.vov.vitamio.widget.VideoView;
|
|
import io.vov.vitamio.widget.VideoView;
|
|
|
|
|
|
|
|
-public class MainActivity extends AppCompatActivity implements OnGestureListener{
|
|
|
|
|
|
|
+public class MainActivity extends AppCompatActivity implements OnGestureListener {
|
|
|
private static final String TAG = "MainActivity";
|
|
private static final String TAG = "MainActivity";
|
|
|
private static final String path = "rtmp://plataforma.especificosba.com.ar:1935/src/movie";
|
|
private static final String path = "rtmp://plataforma.especificosba.com.ar:1935/src/movie";
|
|
|
private ViewSwitcher viewSwitcher;
|
|
private ViewSwitcher viewSwitcher;
|
|
|
private VideoView mVideoView;
|
|
private VideoView mVideoView;
|
|
|
private GestureDetector myDetector;
|
|
private GestureDetector myDetector;
|
|
|
private ViewGroup.LayoutParams lparams;
|
|
private ViewGroup.LayoutParams lparams;
|
|
|
- private float x1,x2;
|
|
|
|
|
|
|
+ private TextView chat;
|
|
|
|
|
+ private float x1, x2;
|
|
|
private int MIN_DISTANCE = 100;
|
|
private int MIN_DISTANCE = 100;
|
|
|
private WebSocket ws;
|
|
private WebSocket ws;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
|
|
+ * See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
|
|
+ */
|
|
|
|
|
+ private GoogleApiClient client;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onStart() {
|
|
|
|
|
+ super.onStart();
|
|
|
|
|
+
|
|
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
|
|
+ client.connect();
|
|
|
|
|
+ Action viewAction = Action.newAction(
|
|
|
|
|
+ Action.TYPE_VIEW, // TODO: choose an action type.
|
|
|
|
|
+ "Main Page", // TODO: Define a title for the content shown.
|
|
|
|
|
+ // TODO: If you have web page content that matches this app activity's content,
|
|
|
|
|
+ // make sure this auto-generated web page URL is correct.
|
|
|
|
|
+ // Otherwise, set the URL to null.
|
|
|
|
|
+ Uri.parse("http://host/path"),
|
|
|
|
|
+ // TODO: Make sure this auto-generated app URL is correct.
|
|
|
|
|
+ Uri.parse("android-app://com.example.david.myapplication/http/host/path")
|
|
|
|
|
+ );
|
|
|
|
|
+ AppIndex.AppIndexApi.start(client, viewAction);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onStop() {
|
|
|
|
|
+ super.onStop();
|
|
|
|
|
+
|
|
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
|
|
+ Action viewAction = Action.newAction(
|
|
|
|
|
+ Action.TYPE_VIEW, // TODO: choose an action type.
|
|
|
|
|
+ "Main Page", // TODO: Define a title for the content shown.
|
|
|
|
|
+ // TODO: If you have web page content that matches this app activity's content,
|
|
|
|
|
+ // make sure this auto-generated web page URL is correct.
|
|
|
|
|
+ // Otherwise, set the URL to null.
|
|
|
|
|
+ Uri.parse("http://host/path"),
|
|
|
|
|
+ // TODO: Make sure this auto-generated app URL is correct.
|
|
|
|
|
+ Uri.parse("android-app://com.example.david.myapplication/http/host/path")
|
|
|
|
|
+ );
|
|
|
|
|
+ AppIndex.AppIndexApi.end(client, viewAction);
|
|
|
|
|
+ client.disconnect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private enum WS_STATUS {
|
|
|
|
|
+ CONNECTED,
|
|
|
|
|
+ DISCONNECTED
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ;
|
|
|
|
|
+ private WS_STATUS status = WS_STATUS.DISCONNECTED;
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
|
|
+ @Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
//requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
//requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
|
|
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
- if (!LibsChecker.checkVitamioLibs(this))
|
|
|
|
|
|
|
+ if (!LibsChecker.checkVitamioLibs(this)) {
|
|
|
return;
|
|
return;
|
|
|
|
|
+ }
|
|
|
setContentView(R.layout.activity_main);
|
|
setContentView(R.layout.activity_main);
|
|
|
connectWebSocket();
|
|
connectWebSocket();
|
|
|
|
|
|
|
|
|
|
+ Button b = (Button) findViewById(R.id.button);
|
|
|
|
|
+ b.setOnClickListener(new Button.OnClickListener(){
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View b){
|
|
|
|
|
+ sendMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
|
|
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
|
|
|
viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
|
|
viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
|
|
|
-
|
|
|
|
|
- lparams=mVideoView.getLayoutParams();
|
|
|
|
|
|
|
+ chat = (TextView) findViewById(R.id.chat);
|
|
|
|
|
+ lparams = mVideoView.getLayoutParams();
|
|
|
//lparams.width=mVideoView.getWidth();
|
|
//lparams.width=mVideoView.getWidth();
|
|
|
- lparams.width=200;
|
|
|
|
|
|
|
+ lparams.width = 200;
|
|
|
mVideoView.setLayoutParams(lparams);
|
|
mVideoView.setLayoutParams(lparams);
|
|
|
-
|
|
|
|
|
|
|
+ chat.setMovementMethod(new ScrollingMovementMethod());
|
|
|
|
|
+ chat.append("\n");
|
|
|
myDetector = new GestureDetector(this, this);
|
|
myDetector = new GestureDetector(this, this);
|
|
|
|
|
|
|
|
- Picasso.with(this.getApplicationContext()).load("https://plataforma.especificosba.com.ar/diapo/EBA/1.png").into((ImageView)findViewById(R.id.imageView));
|
|
|
|
|
|
|
+ Picasso.with(this.getApplicationContext()).load("https://plataforma.especificosba.com.ar/diapo/EBA/1.png").into((ImageView) findViewById(R.id.imageView));
|
|
|
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
mediaPlayer.setPlaybackSpeed(1.0f);
|
|
mediaPlayer.setPlaybackSpeed(1.0f);
|
|
|
- // mediaPlayer.start();
|
|
|
|
|
|
|
+ // mediaPlayer.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -86,6 +159,9 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
mVideoView.start();
|
|
mVideoView.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
|
|
+ client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void connectWebSocket() {
|
|
private void connectWebSocket() {
|
|
@@ -103,37 +179,67 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
ws.addListener(new WebSocketAdapter() {
|
|
ws.addListener(new WebSocketAdapter() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onTextMessage(WebSocket websocket, String message) throws Exception {
|
|
public void onTextMessage(WebSocket websocket, String message) throws Exception {
|
|
|
- // Received a text message.
|
|
|
|
|
- TextView textView = (TextView)findViewById(R.id.chat);
|
|
|
|
|
- textView.setText(textView.getText() + "\n" + message);
|
|
|
|
|
|
|
+ //Log.i("Websocket", "msg:" + message);
|
|
|
|
|
+ JSONObject obj = new JSONObject(message);
|
|
|
|
|
+ switch (obj.getString("type")) {
|
|
|
|
|
+ case "chat":
|
|
|
|
|
+
|
|
|
|
|
+ String formattedMessage = String.format("\n[HORA] %s: %s", obj.getString("user"), obj.getString("text"));
|
|
|
|
|
+ chat.append(formattedMessage);
|
|
|
|
|
+ final Layout layout = chat.getLayout();
|
|
|
|
|
+ if(layout != null){
|
|
|
|
|
+ int scrollDelta = layout.getLineBottom(chat.getLineCount() - 1)
|
|
|
|
|
+ - chat.getScrollY() - chat.getHeight();
|
|
|
|
|
+ Log.i("Websocket", Integer.toString(scrollDelta));
|
|
|
|
|
+ if(scrollDelta > 0)
|
|
|
|
|
+ chat.scrollBy(0, scrollDelta);
|
|
|
|
|
+ }
|
|
|
|
|
+ chat.invalidate();
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ ;
|
|
|
}
|
|
}
|
|
|
- @Override
|
|
|
|
|
- public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception{
|
|
|
|
|
- Log.i("Websocket", "connecterd");
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void onDisconnected(WebSocket websocket,WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame,
|
|
|
|
|
- boolean closedByServer){
|
|
|
|
|
- Log.i("Websocket", "discon");
|
|
|
|
|
|
|
+ public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
|
|
|
|
+ Log.i("Websocket", "Connected");
|
|
|
|
|
+ status = WS_STATUS.CONNECTED;
|
|
|
|
|
+ chat.append("\nConectado al sistema");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame,
|
|
|
|
|
+ boolean closedByServer) {
|
|
|
|
|
+ Log.i("Websocket", "Disconnected");
|
|
|
|
|
+ status = WS_STATUS.DISCONNECTED;
|
|
|
|
|
+ websocket.connectAsynchronously();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
- public void onConnectError(WebSocket websocket, WebSocketException cause){
|
|
|
|
|
- Log.i("Websocket", "didnt even connect"+ cause.getMessage() );
|
|
|
|
|
|
|
+ public void onConnectError(WebSocket websocket, WebSocketException cause) {
|
|
|
|
|
+ Log.i("Websocket", "Didn't connect" + cause.getMessage());
|
|
|
|
|
+ status = WS_STATUS.DISCONNECTED;
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- ws.connectAsynchronously();
|
|
|
|
|
|
|
+ }).connectAsynchronously();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
public void sendMessage() {
|
|
public void sendMessage() {
|
|
|
- EditText editText = (EditText)findViewById(R.id.send_text);
|
|
|
|
|
- ws.sendText(editText.getText().toString());
|
|
|
|
|
|
|
+ EditText editText = (EditText) findViewById(R.id.send_text);
|
|
|
|
|
+ String text=editText.getText().toString();
|
|
|
|
|
+ if(text.length() < 3) return;
|
|
|
|
|
+
|
|
|
|
|
+ String formatted=String.format("{ \"type\":\"chat\", \"user\": \"%s %s (%s)\", \"text\":\"%s\" }", "nombre","Apellido","pais", text);
|
|
|
|
|
+ Log.i("Websocket", "sending" + formatted);
|
|
|
|
|
+
|
|
|
|
|
+ ws.sendText(formatted);
|
|
|
editText.setText("");
|
|
editText.setText("");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
- switch(event.getAction())
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ switch (event.getAction()) {
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
x1 = event.getX();
|
|
x1 = event.getX();
|
|
|
break;
|
|
break;
|
|
@@ -141,29 +247,24 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
x2 = event.getX();
|
|
x2 = event.getX();
|
|
|
float deltaX = x2 - x1;
|
|
float deltaX = x2 - x1;
|
|
|
|
|
|
|
|
- if (Math.abs(deltaX) > MIN_DISTANCE)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Math.abs(deltaX) > MIN_DISTANCE) {
|
|
|
// Left to Right swipe action
|
|
// Left to Right swipe action
|
|
|
- if (x2 > x1)
|
|
|
|
|
- {
|
|
|
|
|
- if(viewSwitcher.getCurrentView() != findViewById(R.id.llayout)) { //animation: OK
|
|
|
|
|
|
|
+ if (x2 > x1) {
|
|
|
|
|
+ if (viewSwitcher.getCurrentView() != findViewById(R.id.llayout)) { //animation: OK
|
|
|
viewSwitcher.showNext();
|
|
viewSwitcher.showNext();
|
|
|
Toast.makeText(this, "Left to Right swipe [Next]", Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(this, "Left to Right swipe [Next]", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Right to left swipe action
|
|
// Right to left swipe action
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- if(viewSwitcher.getCurrentView() != findViewById(R.id.secondLayout)) { //animation:notok
|
|
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (viewSwitcher.getCurrentView() != findViewById(R.id.secondLayout)) { //animation:notok
|
|
|
viewSwitcher.showPrevious();
|
|
viewSwitcher.showPrevious();
|
|
|
Toast.makeText(this, "Right to Left swipe [Previous]", Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(this, "Right to Left swipe [Previous]", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
// consider as something else - a screen tap for example
|
|
// consider as something else - a screen tap for example
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -173,7 +274,7 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onDown(MotionEvent motionEvent) {
|
|
public boolean onDown(MotionEvent motionEvent) {
|
|
|
- return false;
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|