|
|
@@ -3,6 +3,9 @@ package com.example.david.myapplication;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v4.app.FragmentStatePagerAdapter;
|
|
|
+import android.support.v4.view.PagerAdapter;
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.text.Layout;
|
|
|
import android.text.method.ScrollingMovementMethod;
|
|
|
@@ -14,10 +17,7 @@ import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
-import android.widget.Button;
|
|
|
-import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
-import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
import android.widget.ViewSwitcher;
|
|
|
|
|
|
@@ -32,6 +32,10 @@ import com.neovisionaries.ws.client.WebSocketFrame;
|
|
|
import com.neovisionaries.ws.client.WebSocketListener;
|
|
|
import com.squareup.picasso.Picasso;
|
|
|
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
+import android.support.v4.app.FragmentActivity;
|
|
|
+import android.support.v4.app.FragmentManager;
|
|
|
+
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
@@ -47,74 +51,15 @@ import io.vov.vitamio.LibsChecker;
|
|
|
import io.vov.vitamio.MediaPlayer;
|
|
|
import io.vov.vitamio.widget.VideoView;
|
|
|
|
|
|
-public class MainActivity extends AppCompatActivity implements OnGestureListener {
|
|
|
+public class MainActivity extends FragmentActivity {
|
|
|
private static final String TAG = "MainActivity";
|
|
|
- private static final String path = "rtmp://plataforma.especificosba.com.ar:1935/src/movie";
|
|
|
- private ViewSwitcher viewSwitcher;
|
|
|
- private VideoView mVideoView;
|
|
|
- private GestureDetector myDetector;
|
|
|
- private ViewGroup.LayoutParams lparams;
|
|
|
- private TextView chat;
|
|
|
- private float x1, x2;
|
|
|
- private int MIN_DISTANCE = 100;
|
|
|
- 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();
|
|
|
+ private static final int NUM_PAGES = 2;
|
|
|
+ private ViewPager mPager;
|
|
|
+ private PagerAdapter mPagerAdapter;
|
|
|
|
|
|
- // 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
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
- //requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -123,183 +68,31 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
|
|
|
return;
|
|
|
}
|
|
|
setContentView(R.layout.activity_main);
|
|
|
- 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);
|
|
|
- viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
|
|
|
- chat = (TextView) findViewById(R.id.chat);
|
|
|
- lparams = mVideoView.getLayoutParams();
|
|
|
- //lparams.width=mVideoView.getWidth();
|
|
|
- lparams.width = 200;
|
|
|
- mVideoView.setLayoutParams(lparams);
|
|
|
- chat.setMovementMethod(new ScrollingMovementMethod());
|
|
|
- chat.append("\n");
|
|
|
- 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));
|
|
|
- mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
- @Override
|
|
|
- public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
- mediaPlayer.setPlaybackSpeed(1.0f);
|
|
|
- // mediaPlayer.start();
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-// mVideoView.setLayoutParams(lparams);
|
|
|
- mVideoView.setVideoPath(path);
|
|
|
- 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();
|
|
|
+ mPager = (ViewPager) findViewById(R.id.pager);
|
|
|
+ mPagerAdapter = new chatFragmentPagerAdapter(getSupportFragmentManager());
|
|
|
+ mPager.setAdapter(mPagerAdapter);
|
|
|
}
|
|
|
|
|
|
- private void connectWebSocket() {
|
|
|
- try {
|
|
|
- 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;
|
|
|
+ private class chatFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
|
|
+ public chatFragmentPagerAdapter(FragmentManager fm) {
|
|
|
+ super(fm);
|
|
|
}
|
|
|
|
|
|
- ws.addListener(new WebSocketAdapter() {
|
|
|
- @Override
|
|
|
- public void onTextMessage(WebSocket websocket, String message) throws Exception {
|
|
|
- //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 Fragment getItem(int position) {
|
|
|
+ switch (position) {
|
|
|
+ case 0:
|
|
|
+ return new videoFragment();
|
|
|
+ default:
|
|
|
+ return new chatFragment();
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- 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
|
|
|
- public void onConnectError(WebSocket websocket, WebSocketException cause) {
|
|
|
- Log.i("Websocket", "Didn't connect" + cause.getMessage());
|
|
|
- status = WS_STATUS.DISCONNECTED;
|
|
|
- }
|
|
|
- }).connectAsynchronously();
|
|
|
- }
|
|
|
-
|
|
|
- public void sendMessage() {
|
|
|
- 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("");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onTouchEvent(MotionEvent event) {
|
|
|
- switch (event.getAction()) {
|
|
|
- case MotionEvent.ACTION_DOWN:
|
|
|
- x1 = event.getX();
|
|
|
- break;
|
|
|
- case MotionEvent.ACTION_UP:
|
|
|
- x2 = event.getX();
|
|
|
- float deltaX = x2 - x1;
|
|
|
-
|
|
|
- if (Math.abs(deltaX) > MIN_DISTANCE) {
|
|
|
- // Left to Right swipe action
|
|
|
- if (x2 > x1) {
|
|
|
- if (viewSwitcher.getCurrentView() != findViewById(R.id.llayout)) { //animation: OK
|
|
|
- viewSwitcher.showNext();
|
|
|
- Toast.makeText(this, "Left to Right swipe [Next]", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Right to left swipe action
|
|
|
- else {
|
|
|
- if (viewSwitcher.getCurrentView() != findViewById(R.id.secondLayout)) { //animation:notok
|
|
|
- viewSwitcher.showPrevious();
|
|
|
- Toast.makeText(this, "Right to Left swipe [Previous]", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- // consider as something else - a screen tap for example
|
|
|
- }
|
|
|
- break;
|
|
|
}
|
|
|
- return super.onTouchEvent(event);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onDown(MotionEvent motionEvent) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onShowPress(MotionEvent motionEvent) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onSingleTapUp(MotionEvent motionEvent) {
|
|
|
- myDetector.onTouchEvent(motionEvent);
|
|
|
- return super.onTouchEvent(motionEvent);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float v, float v1) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLongPress(MotionEvent motionEvent) {
|
|
|
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return NUM_PAGES;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) {
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|