Skip to content

Commit

Permalink
Added kaltura player to small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalRadwantzor committed Jan 12, 2014
1 parent 32af1f1 commit 21514e6
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 165 deletions.
9 changes: 7 additions & 2 deletions DemoApplication/res/layout-land/info.xml
Expand Up @@ -26,7 +26,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!--
<ImageView
android:id="@+id/iv_thumbnail"
android:layout_width="match_parent"
Expand All @@ -41,7 +41,12 @@
android:layout_centerInParent="true"
android:background="@drawable/button_play_selector"
android:onClick="onClick" />
-->

<com.kaltura.playersdk.CustomPlayerView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/custom_player"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -66,7 +71,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/iv_thumbnail">
android:layout_below="@id/custom_player">

<TextView
android:id="@+id/tv_episode"
Expand Down
32 changes: 9 additions & 23 deletions DemoApplication/res/layout/info.xml
Expand Up @@ -20,34 +20,20 @@
android:id="@+id/ll_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:isScrollContainer="true" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/iv_thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#b9bdc0"
android:background="@color/black"/>

<ImageView
android:id="@+id/iv_button_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/button_play_selector"
android:onClick="onClick" />
</RelativeLayout>
android:orientation="vertical">


<com.kaltura.playersdk.CustomPlayerView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/custom_player"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="15dp">
android:layout_margin="15dp"
android:id="@+id/ll_data">

<TextView
android:id="@+id/tv_name"
Expand Down
214 changes: 78 additions & 136 deletions DemoApplication/src/com/kaltura/activity/Info.java
@@ -1,17 +1,22 @@
package com.kaltura.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.hardware.SensorManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.View;
import android.widget.ImageView;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -21,44 +26,72 @@
import com.kaltura.client.types.KalturaMediaEntry;
import com.kaltura.enums.States;
import com.kaltura.mediatorActivity.TemplateActivity;
import com.kaltura.playersdk.CustomPlayerView;
import com.kaltura.services.Media;
import com.kaltura.sharing.Sharing;
import com.kaltura.utils.Utils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
//import com.nostra13.universalimageloader.core.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;

public class Info extends TemplateActivity {

private String entryId;
private KalturaMediaEntry entry;
private LinearLayout ll_info;
private DownloadEntryTask downloadTask;
private ImageView iv_thumbnail;
private boolean isDownload;
private String nameCategory;
private int orientation;
private Activity activity;
private Sharing sharing;
private String partnerId;
private PlayerHelper mPlayerHelper;

public Info() {
downloadTask = new DownloadEntryTask();
}

@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

OrientationEventListener orientationListener = new OrientationEventListener( this, SensorManager.SENSOR_DELAY_NORMAL) {
int lastPos = 0;
@Override
public void onOrientationChanged(int i) {
int diff = Math.abs(lastPos - i);
if ( diff >= 45 && diff <= 270 ) {
int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
if ( isInRange(i, 90) ) {
if (Build.VERSION.SDK_INT >= 9)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
else
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if ( isInRange(i, 180) ) {
if (Build.VERSION.SDK_INT >= 9)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
} else if ( isInRange(i, 270) ) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
lastPos = i;
setRequestedOrientation( requestedOrientation );
}
}
/**
*
* @param current
* @param pos
* @return true if current is in the range (max difference of 45) of pos value
*/
private boolean isInRange( int current, int pos ) {
return ( Math.abs( pos - current ) <= 45 );
}
};

if ( orientationListener.canDetectOrientation() )
orientationListener.enable();

init();
setContentView(R.layout.info);

activity = this;
Configuration c = getResources().getConfiguration();
orientation = c.orientation;
setView();

extractBundle();

if (bar != null) {
Expand All @@ -69,63 +102,24 @@ public void onCreate(Bundle savedInstanceState) {
}
ll_info.setVisibility(View.INVISIBLE);
sharing = new Sharing(this);

switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
case Configuration.ORIENTATION_UNDEFINED:
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
iv_thumbnail.getLayoutParams().height = display.getHeight() / 2;
iv_thumbnail.getLayoutParams().width = display.getWidth();
downloadTask.execute();
break;
case Configuration.ORIENTATION_LANDSCAPE:
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
iv_thumbnail.getLayoutParams().height = display.getHeight() - display.getHeight() / 3;
iv_thumbnail.getLayoutParams().width = display.getWidth();
downloadTask.execute();
break;
default:
break;
}
downloadTask.execute();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.info);
this.orientation = newConfig.orientation;
setView();
if (bar != null) {
bar.setTitle(getText(R.string.info));
bar.setVisibleNameCategory(View.VISIBLE);
bar.setTextNameCategory(nameCategory);
}
if (isDownload) {
updateData();
}


Log.w(TAG, "oreientation: " + newConfig.orientation);
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
case Configuration.ORIENTATION_UNDEFINED:
iv_thumbnail.getLayoutParams().height = display.getHeight() / 2;
iv_thumbnail.getLayoutParams().width = display.getWidth();
break;
case Configuration.ORIENTATION_LANDSCAPE:
iv_thumbnail.getLayoutParams().height = display.getHeight() - display.getHeight() / 3;
iv_thumbnail.getLayoutParams().width = display.getWidth();
break;
default:
break;
if ( mPlayerHelper != null ) {
if ( newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ) {
mPlayerHelper.openFullscreen();
} else {
mPlayerHelper.closeFullscreen();
}
}

}

private void setView() {
bar = new ActionBar(this, TAG);
ll_info = (LinearLayout) findViewById(R.id.ll_info);
iv_thumbnail = ((ImageView) findViewById(R.id.iv_thumbnail));
setFont();

}
Expand Down Expand Up @@ -153,11 +147,13 @@ private void extractBundle() {
try {
Bundle extras = getIntent().getExtras();
entryId = extras.getString("entryId");
partnerId = extras.getString("partnerId");
nameCategory = extras.getString("nameCategory");

} catch (Exception e) {
e.printStackTrace();
entryId = "";
partnerId = "";
nameCategory = "";
}
}
Expand All @@ -183,11 +179,6 @@ public boolean dispatchTouchEvent(MotionEvent ev) {

public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_button_play:
Log.w(TAG, "test play button");
String url = entry.thumbnailUrl + "/width/" + new Integer(display.getWidth()).toString() + "/height/" + new Integer(display.getHeight() / 2).toString();
getActivityMediator().showPlayer(entry.id, entry.downloadUrl, entry.duration, url, entry.partnerId);
break;
case R.id.iv_button_facebook:
Log.w(TAG, "test facebook button");
sharing.sendToFacebook(entry);
Expand All @@ -212,11 +203,26 @@ public void onClick(View v) {
}

private void updateData() {
String url = entry.thumbnailUrl + "/width/" + new Integer(display.getWidth()).toString() + "/height/" + new Integer(display.getHeight() / 2).toString();
ImageLoader(url);
((TextView) findViewById(R.id.tv_name)).setText(entry.name);
((TextView) findViewById(R.id.tv_episode)).setText("");
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
((TextView) findViewById(R.id.tv_duration)).setText(sdf.format(new Date(entry.duration * 1000)));
((TextView) findViewById(R.id.tv_description)).setText(entry.description);
ll_info.setVisibility(View.VISIBLE);
CustomPlayerView playerView = (CustomPlayerView) findViewById( R.id.custom_player );
mPlayerHelper = new PlayerHelper( playerView, this );
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
size.y = size.y / 2;
playerView.getLayoutParams().height = size.y;
playerView.getLayoutParams().width = size.x;
List<View> comps = new ArrayList<View>();
comps.add(findViewById(R.id.ll_data));
comps.add(findViewById(R.id.bar));
mPlayerHelper.showPlayer(entryId, partnerId, size.x, size.y, comps);

}


private class DownloadEntryTask extends AsyncTask<Void, States, Void> {

private String message;
Expand Down Expand Up @@ -252,7 +258,6 @@ protected Void doInBackground(Void... params) {
@Override
protected void onPostExecute(Void param) {
progressDialog.hide();
isDownload = true;
updateData();
}

Expand All @@ -270,67 +275,4 @@ protected void onProgressUpdate(States... progress) {
}
}
}

private void ImageLoader(String url) {
Log.w(TAG, "Start image loader");

DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();

// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(activity).threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2).memoryCacheSize(150000000) // 150 Mb
.discCacheSize(50000000) // 50 Mb
.denyCacheImageMultipleSizesInMemory().build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
imageLoader.init(config);


iv_thumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);
((TextView) findViewById(R.id.tv_name)).setText(entry.name);
((TextView) findViewById(R.id.tv_episode)).setText("");
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
((TextView) findViewById(R.id.tv_duration)).setText(sdf.format(new Date(entry.duration * 1000)));
((TextView) findViewById(R.id.tv_description)).setText(entry.description);
ll_info.setVisibility(View.VISIBLE);


imageLoader.displayImage(url, iv_thumbnail, options, new ImageLoadingListener() {

@Override
public void onLoadingStarted(String imageUri, View view) {
// do nothing
Log.w(TAG, "onLoadingStarted");

}

@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
Log.w(TAG, "onLoadingFailed");
imageLoader.clearMemoryCache();
imageLoader.clearDiscCache();

}

@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
// do nothing
Log.w(TAG, "onLoadingComplete: ");

}

@Override
public void onLoadingCancelled(String imageUri, View view) {
// TODO Auto-generated method stub

}
});



}
}

0 comments on commit 21514e6

Please sign in to comment.