|
|
@@ -1,37 +1,40 @@
|
|
|
package com.example.david.myapplication;
|
|
|
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
-import android.os.Build;
|
|
|
-import android.support.v7.app.AppCompatActivity;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
import android.util.Log;
|
|
|
import android.view.GestureDetector;
|
|
|
import android.view.GestureDetector.OnGestureListener;
|
|
|
import android.view.MotionEvent;
|
|
|
-import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
-import android.view.animation.Animation;
|
|
|
-import android.view.animation.AnimationUtils;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
import android.widget.ViewSwitcher;
|
|
|
|
|
|
+import com.neovisionaries.ws.client.WebSocket;
|
|
|
+import com.neovisionaries.ws.client.WebSocketAdapter;
|
|
|
+import com.neovisionaries.ws.client.WebSocketException;
|
|
|
+import com.neovisionaries.ws.client.WebSocketFactory;
|
|
|
+import com.neovisionaries.ws.client.WebSocketFrame;
|
|
|
+import com.neovisionaries.ws.client.WebSocketListener;
|
|
|
import com.squareup.picasso.Picasso;
|
|
|
|
|
|
-import org.java_websocket.client.WebSocketClient;
|
|
|
-import org.java_websocket.handshake.ServerHandshake;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.net.ssl.SSLContext;
|
|
|
|
|
|
import io.vov.vitamio.LibsChecker;
|
|
|
import io.vov.vitamio.MediaPlayer;
|
|
|
-import io.vov.vitamio.widget.CenterLayout;
|
|
|
-import io.vov.vitamio.widget.MediaController;
|
|
|
import io.vov.vitamio.widget.VideoView;
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements OnGestureListener{
|
|
|
@@ -43,7 +46,7 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
private ViewGroup.LayoutParams lparams;
|
|
|
private float x1,x2;
|
|
|
private int MIN_DISTANCE = 100;
|
|
|
- private WebSocketClient mWebSocketClient;
|
|
|
+ private WebSocket ws;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -55,6 +58,8 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
if (!LibsChecker.checkVitamioLibs(this))
|
|
|
return;
|
|
|
setContentView(R.layout.activity_main);
|
|
|
+ connectWebSocket();
|
|
|
+
|
|
|
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
|
|
|
viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
|
|
|
|
|
|
@@ -77,7 +82,6 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
});
|
|
|
|
|
|
// mVideoView.setLayoutParams(lparams);
|
|
|
- connectWebSocket();
|
|
|
mVideoView.setVideoPath(path);
|
|
|
mVideoView.start();
|
|
|
|
|
|
@@ -85,50 +89,45 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
}
|
|
|
|
|
|
private void connectWebSocket() {
|
|
|
- URI uri;
|
|
|
try {
|
|
|
- uri = new URI("wss://plataforma.especificosba.com.ar/ws/");
|
|
|
- } catch (URISyntaxException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ WebSocketFactory factory = new WebSocketFactory();
|
|
|
+ SSLContext context = NaiveSSLContext.getInstance("TLS");
|
|
|
+
|
|
|
+ // Set the custom SSL context.
|
|
|
+ factory.setSSLContext(context);
|
|
|
+ ws = factory.createSocket("wss://ws.especificosba.com.ar/");
|
|
|
+ } catch (Exception e) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- mWebSocketClient = new WebSocketClient(uri) {
|
|
|
+ ws.addListener(new WebSocketAdapter() {
|
|
|
@Override
|
|
|
- public void onOpen(ServerHandshake serverHandshake) {
|
|
|
- Log.i("Websocket", "Opened");
|
|
|
- Toast.makeText(getApplicationContext(), "opened", Toast.LENGTH_SHORT).show();
|
|
|
+ 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);
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
- public void onMessage(String s) {
|
|
|
- final String message = s;
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- TextView textView = (TextView)findViewById(R.id.chat);
|
|
|
- textView.setText(textView.getText() + "\n" + message);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception{
|
|
|
+ Log.i("Websocket", "connecterd");
|
|
|
|
|
|
- @Override
|
|
|
- public void onClose(int i, String s, boolean b) {
|
|
|
- // Log.i("Websocket", "Closed " + s);
|
|
|
- Toast.makeText(getApplicationContext(), "closed", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public void onDisconnected(WebSocket websocket,WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame,
|
|
|
+ boolean closedByServer){
|
|
|
+ Log.i("Websocket", "discon");
|
|
|
|
|
|
+ }
|
|
|
@Override
|
|
|
- public void onError(Exception e) {
|
|
|
-// Toast.makeText(getApplicationContext(), "Error"+ e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
- Log.i("Websocket", "Error " + e.getMessage());
|
|
|
+ public void onConnectError(WebSocket websocket, WebSocketException cause){
|
|
|
+ Log.i("Websocket", "didnt even connect"+ cause.getMessage() );
|
|
|
}
|
|
|
- };
|
|
|
- mWebSocketClient.connect();
|
|
|
+ });
|
|
|
+ ws.connectAsynchronously();
|
|
|
}
|
|
|
public void sendMessage() {
|
|
|
EditText editText = (EditText)findViewById(R.id.send_text);
|
|
|
- mWebSocketClient.send(editText.getText().toString());
|
|
|
+ ws.sendText(editText.getText().toString());
|
|
|
editText.setText("");
|
|
|
}
|
|
|
@Override
|