From 21514e6ec58bcfd93757b9a50dd9b4c66fe77d38 Mon Sep 17 00:00:00 2001 From: MichalRadwantzor Date: Sun, 12 Jan 2014 21:38:06 +0200 Subject: [PATCH] Added kaltura player to small screens --- DemoApplication/res/layout-land/info.xml | 9 +- DemoApplication/res/layout/info.xml | 32 +-- .../src/com/kaltura/activity/Info.java | 214 +++++++----------- .../com/kaltura/activity/PlayerHelper.java | 117 ++++++++++ .../src/com/kaltura/bar/ActionBar.java | 4 +- .../TemplateActivityMediator.java | 3 +- KalturaClient/.classpath | 2 +- .../gen/com/kaltura/client/test/R.java | 27 +++ 8 files changed, 243 insertions(+), 165 deletions(-) create mode 100644 DemoApplication/src/com/kaltura/activity/PlayerHelper.java create mode 100644 KalturaClientTester/gen/com/kaltura/client/test/R.java diff --git a/DemoApplication/res/layout-land/info.xml b/DemoApplication/res/layout-land/info.xml index dbbe12d..00b1d4f 100644 --- a/DemoApplication/res/layout-land/info.xml +++ b/DemoApplication/res/layout-land/info.xml @@ -26,7 +26,7 @@ - + + + android:layout_below="@id/custom_player"> - - - - - - - + android:orientation="vertical"> + + + + android:layout_margin="15dp" + android:id="@+id/ll_data"> = 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) { @@ -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(); } @@ -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 = ""; } } @@ -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); @@ -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 comps = new ArrayList(); + 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 { private String message; @@ -252,7 +258,6 @@ protected Void doInBackground(Void... params) { @Override protected void onPostExecute(Void param) { progressDialog.hide(); - isDownload = true; updateData(); } @@ -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 - - } - }); - - - - } } diff --git a/DemoApplication/src/com/kaltura/activity/PlayerHelper.java b/DemoApplication/src/com/kaltura/activity/PlayerHelper.java new file mode 100644 index 0000000..9abea02 --- /dev/null +++ b/DemoApplication/src/com/kaltura/activity/PlayerHelper.java @@ -0,0 +1,117 @@ +package com.kaltura.activity; + +import java.util.Iterator; +import java.util.List; + +import android.app.Activity; +import android.content.pm.ActivityInfo; +import android.graphics.Color; +import android.graphics.Point; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; + +import com.kaltura.playersdk.CustomPlayerView; +import com.kaltura.playersdk.events.OnToggleFullScreenListener; +import com.kaltura.services.AdminUser; + +/** + * This Helper class will perform kaltura-player related actions + * @author michalradwantzor + * + */ +public class PlayerHelper implements OnToggleFullScreenListener { + + private CustomPlayerView mPlayerView; + private Boolean mInFS = false; + private Activity mActivity; + private int mWidth; + private int mHeight; + private List mComponents; + + /** + * Creates a new PlayerHelper + * @param player instance to control + * @param activity that holds the player + */ + public PlayerHelper( CustomPlayerView player, Activity activity ) { + mPlayerView = player; + mActivity = activity; + mPlayerView.setOnFullScreenListener(this); + } + + /** + * Build Iframe URL and display the player + * @param activity + * @param entryId + * @param partnerId + * @param uiconfId + * @param width + * @param height + * @param components to hide when opening fullscreen + */ + public void showPlayer( String entryId, String partnerId, int width, int height, List components) { + mComponents = components; + String iframeUrl = AdminUser.cdnHost + AdminUser.html5Url + "?wid=_" + partnerId + "&uiconf_id=" + AdminUser.uiconfId + "&entry_id=" + entryId; + LayoutParams params = (LayoutParams) mPlayerView.getLayoutParams(); + mWidth = params.width; + mHeight = params.height; + //override params with given arguments + if ( width != 0 ) { + mWidth = width; + } + if ( height != 0 ) { + mHeight = height; + } + mPlayerView.addComponents(iframeUrl, mWidth, mHeight, mActivity); + mPlayerView.setBackgroundColor(Color.BLACK); + } + + @Override + public void onToggleFullScreen() { + if ( !mInFS) { + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + openFullscreen(); + } else { + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + closeFullscreen(); + } + + } + + public void openFullscreen() { + mInFS = true; + if ( mComponents!=null ){ + for(Iterator i = mComponents.iterator(); i.hasNext(); ) { + i.next().setVisibility(View.GONE); + } + } + + Point size = new Point(); + mActivity.getWindowManager().getDefaultDisplay().getSize(size); + updateVideoDimensions( size.x, size.y ); + + } + + private void updateVideoDimensions( int width, int height ) { + ViewGroup.LayoutParams lp = mPlayerView.getLayoutParams(); + lp.width = width; + lp.height = height; + + mPlayerView.setLayoutParams( lp ); + + mPlayerView.setPlayerViewDimensions(width, height); + mPlayerView.invalidate(); + } + + public void closeFullscreen() { + mInFS = false; + if ( mComponents!=null ){ + for(Iterator i = mComponents.iterator(); i.hasNext(); ) { + i.next().setVisibility(View.VISIBLE); + } + } + updateVideoDimensions( mWidth, mHeight); + } + +} diff --git a/DemoApplication/src/com/kaltura/bar/ActionBar.java b/DemoApplication/src/com/kaltura/bar/ActionBar.java index 9b94b0d..60866d5 100644 --- a/DemoApplication/src/com/kaltura/bar/ActionBar.java +++ b/DemoApplication/src/com/kaltura/bar/ActionBar.java @@ -49,11 +49,11 @@ public ViewHolder getViewHolder() { } public int getBarWidth() { - return viewHolder.rl_bar.getWidth(); + return viewHolder.bar.getWidth(); } public int getBarHeight() { - return viewHolder.rl_bar.getHeight(); + return viewHolder.bar.getHeight(); } public void setTitle(CharSequence title) { diff --git a/DemoApplication/src/com/kaltura/mediatorActivity/TemplateActivityMediator.java b/DemoApplication/src/com/kaltura/mediatorActivity/TemplateActivityMediator.java index 701701b..099426b 100644 --- a/DemoApplication/src/com/kaltura/mediatorActivity/TemplateActivityMediator.java +++ b/DemoApplication/src/com/kaltura/mediatorActivity/TemplateActivityMediator.java @@ -111,9 +111,10 @@ public void showInfo() { startActivity(Info.class); } - public void showInfo(String entryId, String nameCategory) { + public void showInfo(String entryId, String nameCategory, int partnerId) { Bundle bundle = new Bundle(); bundle.putString("entryId", entryId); + bundle.putString("partnerId",Integer.toString(partnerId)); bundle.putString("nameCategory", nameCategory); startActivity(Info.class, bundle); } diff --git a/KalturaClient/.classpath b/KalturaClient/.classpath index 0b08408..d57ec02 100644 --- a/KalturaClient/.classpath +++ b/KalturaClient/.classpath @@ -1,7 +1,7 @@ - + diff --git a/KalturaClientTester/gen/com/kaltura/client/test/R.java b/KalturaClientTester/gen/com/kaltura/client/test/R.java new file mode 100644 index 0000000..366cb5f --- /dev/null +++ b/KalturaClientTester/gen/com/kaltura/client/test/R.java @@ -0,0 +1,27 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package com.kaltura.client.test; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int ic_action_search=0x7f020000; + public static final int ic_launcher=0x7f020001; + } + public static final class raw { + public static final int demo_image=0x7f030000; + public static final int demo_video=0x7f030001; + } + public static final class string { + public static final int app_name=0x7f040000; + } + public static final class style { + public static final int AppTheme=0x7f050000; + } +}