Skip to content

Commit

Permalink
Merge pull request #41 from nus-mtp/android-streams-implementation
Browse files Browse the repository at this point in the history
Android streams implementation
  • Loading branch information
kylelwm committed Feb 16, 2016
2 parents 03baa3c + 11b722c commit 9995522
Show file tree
Hide file tree
Showing 57 changed files with 2,247 additions and 595 deletions.
37 changes: 24 additions & 13 deletions client/android/WorldScope/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -19,27 +20,37 @@ android {
}
}




dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

//Instrumented Tests
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'org.mockito:mockito-core:1.+'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
//JavaCV
compile group: 'org.bytedeco', name: 'javacv', version: '1.0'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.9-0.9', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.3-0.9', classifier: 'android-arm'
compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-arm'
//Exoplayer
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.exoplayer:exoplayer:r1.5.1'
compile 'com.facebook.android:facebook-android-sdk:4.+'
//Facebook
compile 'com.android.support:appcompat-v7:23.1.1'
//Retrofit - RESTful client
//Gson
//Picasso - Android Image Loader
compile 'com.google.android.exoplayer:exoplayer:r1.5.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.9.0'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
//Gson
compile 'com.google.code.gson:gson:2.4'
//Picasso - Android Image Loader
compile 'com.squareup.picasso:picasso:2.5.2'
//Android GIF Drawable
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
}
compile 'com.ocpsoft:ocpsoft-pretty-time:1.0.6'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.litmus.worldscope;

import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.litmus.worldscope.model.WorldScopeUser;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class FacebookLoginActivityTest extends TestCase{

private FacebookLoginActivity facebookLoginActivity;


@Rule
public ActivityTestRule<FacebookLoginActivity> activityRule = new ActivityTestRule<>(
FacebookLoginActivity.class);

@Before
public void setUp() {
facebookLoginActivity = activityRule.getActivity();
}

@Test
public void testTrue() {
assertEquals(true, true);
}

@Test
public void testRedirectToMainActivity() {
String testUserName = "testUserName";
WorldScopeUser mockUser = new WorldScopeUser();
Instrumentation.ActivityMonitor am = InstrumentationRegistry.getInstrumentation().addMonitor(MainActivity.class.getName(), null, true);
facebookLoginActivity.redirectToMainActivity(mockUser);
assertEquals(1, am.getHits());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.litmus.worldscope;

import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MainActivityTest extends TestCase{

private static final Boolean IS_LOGOUT_ATTEMPT = true;
private MainActivity mainActivity;


@Rule
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(
MainActivity.class);

@Before
public void setUp() {
mainActivity = activityRule.getActivity();
}

@Test
public void testTrue() {
assertEquals(true, true);
}

@Test
public void testRedirectToStreamActivity() {
Instrumentation.ActivityMonitor am = InstrumentationRegistry.getInstrumentation()
.addMonitor(StreamActivity.class.getName(), null, true);
mainActivity.redirectToStreamActivity();
assertEquals(1, am.getHits());
}

@Test
public void testRedirectToViewActivity() {
Instrumentation.ActivityMonitor am = InstrumentationRegistry.getInstrumentation()
.addMonitor(ViewActivity.class.getName(), null, true);
mainActivity.redirectToViewActivity();
assertEquals(1, am.getHits());
}

@Test
public void testRedirectToFacebookLoginActivity() {
Instrumentation.ActivityMonitor am = InstrumentationRegistry.getInstrumentation()
.addMonitor(FacebookLoginActivity.class.getName(), null, true);
mainActivity.redirectToFacebookLoginActivity(IS_LOGOUT_ATTEMPT);
assertEquals(1, am.getHits());
}
}
18 changes: 12 additions & 6 deletions client/android/WorldScope/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.VIBRATE" />

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Expand All @@ -29,28 +30,33 @@

<activity
android:name=".FacebookLoginActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StreamActivity" />
<activity android:name=".StreamActivity"
android:windowSoftInputMode="adjustResize"
android:theme="@style/FullscreenTheme"/>
<activity
android:name=".ViewActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_view"
android:theme="@style/FullscreenTheme" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main2"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar"/>
</application>

<instrumentation
android:targetPackage="com.litmus.worldscope.FacebookLoginActivityTest"
android:name="android.test.InstrumentationTestRunner" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<head>
</head>
<body style="background-color: #000000; margin:0px; padding: 0px; height: 100%; width: 100%;">
<img style="height: auto; width: 100%; max-height: 100%" alt="Welcome GIF" src="welcome.gif">
</body>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class DashRendererBuilder implements ManifestFetcher.ManifestCallback<Med


public DashRendererBuilder(LitmusPlayer player, Context context, String mpdLink, String userAgent, MediaDrmCallback drmCallback) {

Log.d(TAG, "DashRendererBuilder created");
Log.d(TAG, "mpdLink: " + mpdLink);
this.player = player;
this.context = context;
this.userAgent = userAgent;
Expand Down Expand Up @@ -106,6 +109,8 @@ private void buildAudioRenderer(Context context) {
// Function to build both renderers
private void buildRenderers() {

Log.d(TAG, "Building renderers");

Period period = manifest.getPeriod(0);

boolean hasContentProtection = false;
Expand Down Expand Up @@ -139,6 +144,7 @@ private void buildRenderers() {
renderers[LitmusPlayer.TYPE_VIDEO] = videoRenderer;
renderers[LitmusPlayer.TYPE_AUDIO] = audioRenderer;
this.player.onRenderers(renderers);
Log.d(TAG, "Renderer ready to push");
player.readyToPushSurface(LitmusPlayer.RENDERER_READY);
}

Expand All @@ -153,6 +159,8 @@ public MediaCodecAudioTrackRenderer getAudioRenderer() {
// Implement for ManifestCallback
@Override
public void onSingleManifest(MediaPresentationDescription manifest) {
Log.d(TAG, "Received manifest");

this.manifest = manifest;
if (manifest.dynamic && manifest.utcTiming != null) {
UtcTimingElementResolver.resolveTimingElement(manifestDataSource, manifest.utcTiming,
Expand All @@ -164,6 +172,7 @@ public void onSingleManifest(MediaPresentationDescription manifest) {

@Override
public void onSingleManifestError(IOException e) {
e.printStackTrace();
}

// Implement for UTCTimingCallBack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;

import com.facebook.AccessToken;
import com.litmus.worldscope.model.WorldScopeUser;

import layout.FacebookLoginFragment;

Expand All @@ -18,6 +20,7 @@
public class FacebookLoginActivity extends AppCompatActivity implements FacebookLoginFragment.OnFragmentInteractionListener {

private static final String TAG = "FacebookLoginActivity";
private static final String WELCOME_GIF_LINK = "file:///android_asset/welcomeGifAssets/welcome.html";
private static final String APP_SERVER_AUTH_FAILED_MSG = "Authentication with WorldScope's server has failed, please check that you have internet connections and try again.";
private static Context context;
private FacebookLoginFragment facebookLoginFragment;
Expand All @@ -28,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_facebook_login);
context = this;

loadGifIntoWebView();
}

@Override
Expand All @@ -37,7 +41,7 @@ public void onFacebookLoginSuccess(AccessToken accessToken) {
Log.d(TAG, "AccessToken: " + accessToken.getToken());

// Instantiate and make a call to login user into WorldScope servers
Call<WorldScopeUser> call = WorldScopeRestAPI.buildWorldScopeAPIService().loginUser(new WorldScopeAPIService.LoginUserRequest(accessToken.getToken()));
Call<WorldScopeUser> call = new WorldScopeRestAPI(context).buildWorldScopeAPIService().loginUser(new WorldScopeAPIService.LoginUserRequest(accessToken.getToken()));
call.enqueue(new Callback<WorldScopeUser>() {
@Override
public void onResponse(Response<WorldScopeUser> response) {
Expand All @@ -46,11 +50,10 @@ public void onResponse(Response<WorldScopeUser> response) {
Log.d(TAG, "" + response.body().toString());

// Redirect to MainActivty if successful
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("loginUser", response.body());
startActivity(intent);
redirectToMainActivity(response.body());

} else {
Log.d(TAG, "Failure" + response.code() + ": " + response.body().toString());
Log.d(TAG, "Failure" + response.code() + ": " + response.message().toString());
// Logout of Facebook
logoutOfFacebook();
}
Expand All @@ -66,6 +69,13 @@ public void onFailure(Throwable t) {

}

//Redirects to MainActivity
protected void redirectToMainActivity(WorldScopeUser user) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("loginUser", user);
startActivity(intent);
}

// Called to logout of Facebook when attempt to authenticate with App server fails
private void logoutOfFacebook() {
if(facebookLoginFragment == null) {
Expand All @@ -79,4 +89,10 @@ private void logoutOfFacebook() {
facebookLoginFragment.logoutFromFacebook();

}

// Method to load Gif's html data into WebView
private void loadGifIntoWebView() {
WebView welcomeGifWebView = (WebView) findViewById(R.id.welcomeGifWebView);
welcomeGifWebView.loadUrl(WELCOME_GIF_LINK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.android.exoplayer.audio.AudioTrack;
import com.google.android.exoplayer.drm.MediaDrmCallback;
import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
import com.google.android.exoplayer.upstream.BandwidthMeter;
import com.google.android.exoplayer.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer.util.PlayerControl;
import com.google.android.exoplayer.util.Util;
Expand Down
Loading

0 comments on commit 9995522

Please sign in to comment.