Browse Source

limpio un poco

David 10 years atrás
parent
commit
f3411138c4

+ 1 - 0
app/build.gradle

@@ -27,4 +27,5 @@ dependencies {
     compile project(':picasso-2.5.2')
     compile 'com.android.support:appcompat-v7:22.2.1'
     compile 'com.android.support:design:22.2.1'
+    compile "org.java-websocket:Java-WebSocket:1.3.0"
 }

+ 3 - 8
app/src/main/AndroidManifest.xml

@@ -1,25 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.david.myapplication">
-
-    <!-- To auto-complete the email text field in the login form with the user's emails -->
-    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
-    <uses-permission android:name="android.permission.READ_PROFILE" />
-    <uses-permission android:name="android.permission.READ_CONTACTS" />
-
+    <uses-permission android:name="android.permission.INTERNET" />
     <application
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
-        <activity android:name=".MainActivity" />
+        <!--android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"> -->
+        <activity android:name=".MainActivity"/>
         <activity
             android:name=".LoginActivity"
             android:label="@string/title_activity_login">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>

+ 2 - 57
app/src/main/java/com/example/david/myapplication/LoginActivity.java

@@ -37,13 +37,7 @@ import java.util.List;
  */
 public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
 
-    /**
-     * A dummy authentication store containing known user names and passwords.
-     * TODO: remove after connecting to a real authentication system.
-     */
-    private static final String[] DUMMY_CREDENTIALS = new String[]{
-            "foo@example.com:hello", "bar@example.com:world"
-    };
+
     /**
      * Keep track of the login task to ensure we can cancel it if requested.
      */
@@ -61,8 +55,6 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
         setContentView(R.layout.activity_login);
         // Set up the login form.
         mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
-        populateAutoComplete();
-
         mPasswordView = (EditText) findViewById(R.id.password);
         mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
             @Override
@@ -192,31 +184,12 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
 
     @Override
     public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
-        return new CursorLoader(this,
-                // Retrieve data rows for the device user's 'profile' contact.
-                Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
-                        ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
-
-                // Select only email addresses.
-                ContactsContract.Contacts.Data.MIMETYPE +
-                        " = ?", new String[]{ContactsContract.CommonDataKinds.Email
-                .CONTENT_ITEM_TYPE},
-
-                // Show primary email addresses first. Note that there won't be
-                // a primary email address if the user hasn't specified one.
-                ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
+        return new CursorLoader(this);
     }
 
     @Override
     public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
-        List<String> emails = new ArrayList<>();
-        cursor.moveToFirst();
-        while (!cursor.isAfterLast()) {
-            emails.add(cursor.getString(ProfileQuery.ADDRESS));
-            cursor.moveToNext();
-        }
 
-        addEmailsToAutoComplete(emails);
     }
 
     @Override
@@ -224,26 +197,6 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
 
     }
 
-    private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
-        //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
-        ArrayAdapter<String> adapter =
-                new ArrayAdapter<>(LoginActivity.this,
-                        android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
-
-        mEmailView.setAdapter(adapter);
-    }
-
-
-    private interface ProfileQuery {
-        String[] PROJECTION = {
-                ContactsContract.CommonDataKinds.Email.ADDRESS,
-                ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
-        };
-
-        int ADDRESS = 0;
-        int IS_PRIMARY = 1;
-    }
-
     /**
      * Represents an asynchronous login/registration task used to authenticate
      * the user.
@@ -270,14 +223,6 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
                 return false;
             }
 
-            for (String credential : DUMMY_CREDENTIALS) {
-                String[] pieces = credential.split(":");
-                if (pieces[0].equals(mEmail)) {
-                    // Account exists, return true if the password matches.
-                    return pieces[1].equals(mPassword);
-                }
-            }
-
             // TODO: register the new account here.
             return true;
         }

+ 66 - 6
app/src/main/java/com/example/david/myapplication/MainActivity.java

@@ -1,22 +1,33 @@
 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.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.squareup.picasso.Picasso;
 
+import org.java_websocket.client.WebSocketClient;
+import org.java_websocket.handshake.ServerHandshake;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import io.vov.vitamio.LibsChecker;
 import io.vov.vitamio.MediaPlayer;
 import io.vov.vitamio.widget.CenterLayout;
@@ -27,18 +38,19 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
     private static final String TAG = "MainActivity";
     private static final String path = "rtmp://plataforma.especificosba.com.ar:1935/src/movie";
     private ViewSwitcher viewSwitcher;
-    //private HashMap<String, String> options;
     private VideoView mVideoView;
     private GestureDetector myDetector;
     private ViewGroup.LayoutParams lparams;
     private float x1,x2;
     private int MIN_DISTANCE = 100;
-    @Override
+    private WebSocketClient mWebSocketClient;
+
+        @Override
     protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
         //requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
-        setContentView(R.layout.activity_main);
+        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        super.onCreate(savedInstanceState);
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
         if (!LibsChecker.checkVitamioLibs(this))
             return;
@@ -65,12 +77,60 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
         });
 
 //        mVideoView.setLayoutParams(lparams);
-
+        connectWebSocket();
         mVideoView.setVideoPath(path);
         mVideoView.start();
 
 
     }
+
+    private void connectWebSocket() {
+        URI uri;
+        try {
+            uri = new URI("wss://plataforma.especificosba.com.ar/ws/");
+        } catch (URISyntaxException e) {
+            e.printStackTrace();
+            return;
+        }
+
+        mWebSocketClient = new WebSocketClient(uri) {
+            @Override
+            public void onOpen(ServerHandshake serverHandshake) {
+                Log.i("Websocket", "Opened");
+                Toast.makeText(getApplicationContext(), "opened", Toast.LENGTH_SHORT).show();
+            }
+
+            @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);
+                    }
+                });
+            }
+
+            @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 onError(Exception e) {
+//                Toast.makeText(getApplicationContext(), "Error"+ e.getMessage(), Toast.LENGTH_SHORT).show();
+                Log.i("Websocket", "Error " + e.getMessage());
+            }
+        };
+        mWebSocketClient.connect();
+    }
+    public void sendMessage() {
+        EditText editText = (EditText)findViewById(R.id.send_text);
+        mWebSocketClient.send(editText.getText().toString());
+        editText.setText("");
+    }
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         switch(event.getAction())
@@ -96,7 +156,7 @@ public class MainActivity extends AppCompatActivity implements OnGestureListener
                     // Right to left swipe action
                     else
                     {
-                        if(viewSwitcher.getCurrentView() != findViewById(R.id.dummylayout)) { //animation:notok
+                        if(viewSwitcher.getCurrentView() != findViewById(R.id.secondLayout)) { //animation:notok
                             viewSwitcher.showPrevious();
                             Toast.makeText(this, "Right to Left swipe [Previous]", Toast.LENGTH_SHORT).show();
                         }

+ 19 - 8
app/src/main/res/layout/activity_main.xml

@@ -21,9 +21,9 @@
             android:orientation="horizontal"
             android:id="@+id/llayout">
             <LinearLayout
-                android:layout_width="match_parent"
+                android:layout_width="0dp"
                 android:layout_height="match_parent"
-                android:layout_weight=".40">
+                android:layout_weight=".50">
                 <io.vov.vitamio.widget.VideoView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -32,14 +32,25 @@
             <ImageView
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
-                android:layout_weight=".60"
+                android:layout_weight=".50"
                 android:id="@+id/imageView" />
         </LinearLayout>
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="LinearLayout 2"
-            android:id="@+id/dummylayout" />
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:id="@+id/secondLayout">
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="chattext 2"
+                android:id="@+id/chat" />
+            <EditText
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="intext"
+                android:id="@+id/send_text" />
+        </LinearLayout>
+
     </ViewSwitcher>
 
 </LinearLayout>

+ 6 - 1
app/src/main/res/values/styles.xml

@@ -7,5 +7,10 @@
         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
         <item name="colorAccent">@color/colorAccent</item>
     </style>
-
+    <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
+        <item name="windowNoTitle">true</item>
+        <item name="windowActionBar">false</item>
+        <item name="android:windowFullscreen">true</item>
+        <item name="android:windowContentOverlay">@null</item>
+    </style>
 </resources>