Rework WidevineSamplePlayer to use fragments
Previously it used TabActivity which has been deprecated and no longer works. bug: 29045104 Change-Id: I207f0208b6dba47adfa0ffe7485800d1561af617
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
@@ -9,56 +9,63 @@ import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Button;
|
||||
|
||||
public abstract class AssetActivity extends Activity {
|
||||
|
||||
public abstract class AssetFragment extends Fragment {
|
||||
|
||||
public static final String TAG = "WVM Sample Player";
|
||||
|
||||
private int currentPage;
|
||||
protected ArrayList<AssetsPage> pages;
|
||||
private Context context;
|
||||
private View mView;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
/** Called when the fragment is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
context = this;
|
||||
mView = inflater.inflate(R.layout.empty, container, false);
|
||||
|
||||
initialize();
|
||||
currentPage = 0;
|
||||
pages = new ArrayList<AssetsPage>();
|
||||
return mView;
|
||||
}
|
||||
|
||||
protected void initialize() {
|
||||
currentPage = 0;
|
||||
|
||||
pages = new ArrayList<AssetsPage>();
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle bundle) {
|
||||
super.onActivityCreated(bundle);
|
||||
if (setUpAssetPages()) {
|
||||
setContentView(createView(this));
|
||||
} else {
|
||||
setContentView(R.layout.empty);
|
||||
createView();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean setUpAssetPages();
|
||||
|
||||
private View createView(Context ctxt) {
|
||||
ImageView empty = new ImageView(this);
|
||||
empty.setBackground(getResources().getDrawable(R.drawable.empty, context.getTheme()));
|
||||
private void createView() {
|
||||
|
||||
ViewGroup viewGroup = (ViewGroup)mView;
|
||||
viewGroup.removeAllViews();
|
||||
|
||||
LinearLayout mainLayout = new LinearLayout(getActivity());
|
||||
|
||||
ImageView empty = new ImageView(getActivity());
|
||||
empty.setBackground(getResources().getDrawable(R.drawable.empty,
|
||||
getActivity().getTheme()));
|
||||
|
||||
View[] clips = new View[6];
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
@@ -69,22 +76,22 @@ public abstract class AssetActivity extends Activity {
|
||||
for (int i = 0; i < page.getPageCount(); i++) {
|
||||
|
||||
AssetItem assetItem = page.getPage(i);
|
||||
clips[i] = createViewItem(getBitmapFromAssetItem(assetItem), assetItem.getAssetPath(),
|
||||
assetItem.getTitle());
|
||||
clips[i] = createViewItem(getBitmapFromAssetItem(assetItem),
|
||||
assetItem.getAssetPath(), assetItem.getTitle());
|
||||
|
||||
}
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, 1);
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
|
||||
|
||||
LinearLayout.LayoutParams paramsMain = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, 1);
|
||||
paramsMain.gravity = Gravity.CENTER;
|
||||
|
||||
LinearLayout left = new LinearLayout(ctxt);
|
||||
LinearLayout left = new LinearLayout(getActivity());
|
||||
left.setOrientation(LinearLayout.VERTICAL);
|
||||
if (clips[0] != null) {
|
||||
left.addView(clips[0], params);
|
||||
@@ -95,7 +102,7 @@ public abstract class AssetActivity extends Activity {
|
||||
left.addView(createEmptyView(), params);
|
||||
}
|
||||
|
||||
LinearLayout middle = new LinearLayout(ctxt);
|
||||
LinearLayout middle = new LinearLayout(getActivity());
|
||||
middle.setOrientation(LinearLayout.VERTICAL);
|
||||
if (clips[1] != null) {
|
||||
middle.addView(clips[1], params);
|
||||
@@ -106,7 +113,7 @@ public abstract class AssetActivity extends Activity {
|
||||
middle.addView(createEmptyView(), params);
|
||||
}
|
||||
|
||||
LinearLayout right = new LinearLayout(ctxt);
|
||||
LinearLayout right = new LinearLayout(getActivity());
|
||||
right.setOrientation(LinearLayout.VERTICAL);
|
||||
if (clips[2] != null) {
|
||||
right.addView(clips[2], params);
|
||||
@@ -119,7 +126,7 @@ public abstract class AssetActivity extends Activity {
|
||||
}
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
|
||||
|
||||
LinearLayout body = new LinearLayout(ctxt);
|
||||
LinearLayout body = new LinearLayout(getActivity());
|
||||
|
||||
body.addView(left, paramsMain);
|
||||
body.addView(middle, paramsMain);
|
||||
@@ -129,18 +136,17 @@ public abstract class AssetActivity extends Activity {
|
||||
View.OnClickListener nextButtonListener = new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
currentPage++;
|
||||
Log.d(TAG, "Click next page: " + currentPage);
|
||||
if (currentPage >= pages.size()) {
|
||||
currentPage = 0;
|
||||
if (currentPage < pages.size() - 1) {
|
||||
currentPage++;
|
||||
createView();
|
||||
}
|
||||
setContentView(createView(context));
|
||||
}
|
||||
};
|
||||
|
||||
Button next = new Button(this);
|
||||
next.setText(">>");
|
||||
next.setTextSize(10);
|
||||
Button next = new Button(getActivity());
|
||||
next.setText(R.string.next_page);
|
||||
next.setTextSize(14);
|
||||
next.setOnClickListener(nextButtonListener);
|
||||
|
||||
// Previous button listener
|
||||
@@ -148,53 +154,48 @@ public abstract class AssetActivity extends Activity {
|
||||
|
||||
public void onClick(View v) {
|
||||
|
||||
currentPage--;
|
||||
Log.d(TAG, "Click prev page: " + currentPage);
|
||||
if (currentPage < 0) {
|
||||
currentPage = pages.size() - 1;
|
||||
if (currentPage > 0) {
|
||||
currentPage--;
|
||||
createView();
|
||||
}
|
||||
setContentView(createView(context));
|
||||
|
||||
}
|
||||
};
|
||||
Button prev = new Button(this);
|
||||
prev.setText("<<");
|
||||
prev.setTextSize(10);
|
||||
Button prev = new Button(getActivity());
|
||||
prev.setText(R.string.previous_page);
|
||||
prev.setTextSize(14);
|
||||
prev.setOnClickListener(prevButtonListener);
|
||||
|
||||
LinearLayout buttons = new LinearLayout(this);
|
||||
LinearLayout buttons = new LinearLayout(getActivity());
|
||||
buttons.addView(prev, params);
|
||||
buttons.addView(next, params);
|
||||
|
||||
body.setBackground(this.getResources().getDrawable(R.drawable.background3,
|
||||
context.getTheme()));
|
||||
body.setBackground(getActivity().getResources().getDrawable(R.drawable.background3,
|
||||
getActivity().getTheme()));
|
||||
|
||||
SwipeLinearLayout main = new SwipeLinearLayout(this);
|
||||
main.setNext(nextButtonListener);
|
||||
main.setPrev(prevButtonListener);
|
||||
main.setOrientation(LinearLayout.VERTICAL);
|
||||
main.addView(body, params);
|
||||
mainLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
mainLayout.addView(body, params);
|
||||
|
||||
LinearLayout.LayoutParams paramButtons = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
paramButtons.gravity = Gravity.CENTER;
|
||||
|
||||
main.addView(buttons, paramButtons);
|
||||
return main;
|
||||
mainLayout.addView(buttons, paramButtons);
|
||||
viewGroup.addView(mainLayout, paramsMain);
|
||||
}
|
||||
|
||||
private View createEmptyView() {
|
||||
ImageView empty = new ImageView(this);
|
||||
empty.setBackground(getResources().getDrawable(R.drawable.empty, context.getTheme()));
|
||||
ImageView empty = new ImageView(getActivity());
|
||||
empty.setBackground(getResources().getDrawable(R.drawable.empty, getActivity().getTheme()));
|
||||
|
||||
TextView emptyText = new TextView(this);
|
||||
TextView emptyText = new TextView(getActivity());
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
|
||||
LinearLayout body = new LinearLayout(this);
|
||||
LinearLayout body = new LinearLayout(getActivity());
|
||||
|
||||
body.setOrientation(LinearLayout.VERTICAL);
|
||||
body.addView(empty, params);
|
||||
@@ -208,30 +209,31 @@ public abstract class AssetActivity extends Activity {
|
||||
|
||||
final String assetPath = path;
|
||||
|
||||
ClipImageView clip = new ClipImageView(this);
|
||||
ClipImageView clip = new ClipImageView(getActivity());
|
||||
|
||||
clip.setImageBitmap(image);
|
||||
clip.setBackgroundColor(0);
|
||||
|
||||
// Set the onClick listener for each image
|
||||
clip.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
Log.d(TAG, "Click Asset path: " + assetPath);
|
||||
Intent intent = new Intent(context, VideoPlayerView.class);
|
||||
Intent intent = new Intent(getActivity(), VideoPlayerView.class);
|
||||
intent.putExtra("com.widevine.demo.Path", assetPath);
|
||||
context.startActivity(intent);
|
||||
getActivity().startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
TextView text = new TextView(this);
|
||||
TextView text = new TextView(getActivity());
|
||||
text.setText((title == null) ? path : title);
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
|
||||
params.gravity = Gravity.CENTER;
|
||||
LinearLayout body = new LinearLayout(this);
|
||||
LinearLayout body = new LinearLayout(getActivity());
|
||||
|
||||
body.setOrientation(LinearLayout.VERTICAL);
|
||||
body.addView(clip, params);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
@@ -7,8 +7,11 @@ package com.widevine.demo;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class DownloadActivity extends AssetActivity {
|
||||
public class DownloadFragment extends AssetFragment {
|
||||
private static String TAG = "DownloadActivity";
|
||||
|
||||
protected boolean setUpAssetPages() {
|
||||
pages = new ArrayList<AssetsPage>();
|
||||
@@ -32,6 +35,23 @@ public class DownloadActivity extends AssetActivity {
|
||||
private File[] getDownloadedClips() {
|
||||
|
||||
File file = new File("/sdcard/Widevine");
|
||||
String message = null;
|
||||
|
||||
if (!file.exists()) {
|
||||
message = "Warning: /sdcard/Widevine does not exist, create it for downloads";
|
||||
} else if (!file.isDirectory()) {
|
||||
message = "Warning: /sdcard/Widevine is not a directory";
|
||||
} else if (!file.canRead()) {
|
||||
message = "Warning: unable to read /sdcard/Widevine, check settings->app->permissions->storage";
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
Context context = getActivity().getApplicationContext();
|
||||
int duration = Toast.LENGTH_LONG;
|
||||
|
||||
Toast toast = Toast.makeText(context, message, duration);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
@@ -47,7 +67,5 @@ public class DownloadActivity extends AssetActivity {
|
||||
};
|
||||
|
||||
return file.listFiles(filter);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,41 +1,38 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google Inc.
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.util.Log;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class SettingsActivity extends Activity {
|
||||
public class SettingsFragment extends Fragment {
|
||||
// public static String CONTENT_PAGE = "/sdcard/Widevine/config.xml";
|
||||
public static String CONTENT_PAGE = "http://storage.googleapis.com/wvmedia/html/oem.html";
|
||||
|
||||
private Context context;
|
||||
private Button updateButton;
|
||||
private EditText drmServer, portalName, deviceId, contentPage;
|
||||
|
||||
public static final String TAG = "WVM Player Settings";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
context = this;
|
||||
View rootView = inflater.inflate(R.layout.settings, container, false);
|
||||
|
||||
setContentView(R.layout.settings);
|
||||
|
||||
updateButton = (Button) findViewById(R.id.update_button);
|
||||
updateButton = (Button)rootView.findViewById(R.id.save_settings);
|
||||
|
||||
View.OnClickListener clickListener = new View.OnClickListener() {
|
||||
|
||||
@@ -44,9 +41,9 @@ public class SettingsActivity extends Activity {
|
||||
WidevineDrm.Settings.DRM_SERVER_URI = drmServer.getText().toString();
|
||||
WidevineDrm.Settings.DEVICE_ID = deviceId.getText().toString();
|
||||
WidevineDrm.Settings.PORTAL_NAME = portalName.getText().toString();
|
||||
SettingsActivity.CONTENT_PAGE = contentPage.getText().toString();
|
||||
SettingsFragment.CONTENT_PAGE = contentPage.getText().toString();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
||||
builder.setMessage("DRM Settings Updated").setCancelable(false)
|
||||
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
@@ -61,18 +58,18 @@ public class SettingsActivity extends Activity {
|
||||
|
||||
updateButton.setOnClickListener(clickListener);
|
||||
|
||||
drmServer = (EditText) findViewById(R.id.drm_server);
|
||||
drmServer = (EditText)rootView.findViewById(R.id.drm_server);
|
||||
drmServer.setText(WidevineDrm.Settings.DRM_SERVER_URI);
|
||||
|
||||
deviceId = (EditText) findViewById(R.id.device_id);
|
||||
deviceId = (EditText)rootView.findViewById(R.id.device_id);
|
||||
deviceId.setText(WidevineDrm.Settings.DEVICE_ID);
|
||||
|
||||
portalName = (EditText) findViewById(R.id.portal_id);
|
||||
portalName = (EditText)rootView.findViewById(R.id.portal_id);
|
||||
portalName.setText(WidevineDrm.Settings.PORTAL_NAME);
|
||||
|
||||
contentPage = (EditText) findViewById(R.id.content_page);
|
||||
contentPage.setText(SettingsActivity.CONTENT_PAGE);
|
||||
contentPage = (EditText)rootView.findViewById(R.id.content_page);
|
||||
contentPage.setText(SettingsFragment.CONTENT_PAGE);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google Inc.
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
@@ -10,24 +10,13 @@ import java.util.ArrayList;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class StreamingActivity extends AssetActivity {
|
||||
public class StreamingFragment extends AssetFragment {
|
||||
private String contentPage;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
contentPage = SettingsActivity.CONTENT_PAGE;
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!contentPage.equals(SettingsActivity.CONTENT_PAGE)) {
|
||||
contentPage = SettingsActivity.CONTENT_PAGE;
|
||||
initialize();
|
||||
}
|
||||
contentPage = SettingsFragment.CONTENT_PAGE;
|
||||
}
|
||||
|
||||
protected boolean setUpAssetPages() {
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class SwipeLinearLayout extends LinearLayout {
|
||||
private View.OnClickListener prev;
|
||||
private View.OnClickListener next;
|
||||
|
||||
float startX, startY, endX, endY;
|
||||
|
||||
public SwipeLinearLayout(Context c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
public void setNext(View.OnClickListener next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public void setPrev(View.OnClickListener prev) {
|
||||
this.prev = prev;
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
if (e.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
startX = e.getX();
|
||||
startY = e.getY();
|
||||
return true;
|
||||
} else if (e.getAction() == MotionEvent.ACTION_UP) {
|
||||
endX = e.getX();
|
||||
endY = e.getY();
|
||||
|
||||
if (Math.abs(startY - endY) < 75) {
|
||||
if ((startX - endX) > 200.0) {
|
||||
// go forward
|
||||
if (next != null) {
|
||||
next.onClick(null);
|
||||
}
|
||||
} else if ((startX - endX) < -200.0) {
|
||||
// go back
|
||||
if (prev != null) {
|
||||
prev.onClick(null);
|
||||
}
|
||||
}
|
||||
startX = startY = endX = endY = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -33,7 +33,7 @@ import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class VideoPlayerView extends Activity {
|
||||
public class VideoPlayerView extends AppCompatActivity {
|
||||
private final static String TAG = "VideoPlayerView";
|
||||
|
||||
private final static float BUTTON_FONT_SIZE = 10;
|
||||
@@ -44,13 +44,11 @@ public class VideoPlayerView extends Activity {
|
||||
|
||||
private WidevineDrm drm;
|
||||
private FullScreenVideoView videoView;
|
||||
private MediaCodecView mediaCodecView;
|
||||
private String assetUri;
|
||||
private TextView logs;
|
||||
private ScrollView scrollView;
|
||||
private Context context;
|
||||
private ClipImageView bgImage;
|
||||
private Button mediaCodecModeButton;
|
||||
private Button playButton;
|
||||
private Button fullScreen;
|
||||
private Handler hRefresh;
|
||||
@@ -58,7 +56,6 @@ public class VideoPlayerView extends Activity {
|
||||
private LinearLayout main;
|
||||
private LinearLayout sidePanel;
|
||||
private boolean enteringFullScreen;
|
||||
private boolean useMediaCodec;
|
||||
private int width, height;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -69,7 +66,6 @@ public class VideoPlayerView extends Activity {
|
||||
height = display.getHeight();
|
||||
width = display.getWidth();
|
||||
context = this;
|
||||
useMediaCodec = false;
|
||||
contentView = createView();
|
||||
if (drm.isProvisionedDevice()) {
|
||||
setContentView(contentView);
|
||||
@@ -87,11 +83,6 @@ public class VideoPlayerView extends Activity {
|
||||
stopPlayback();
|
||||
}
|
||||
}
|
||||
if (mediaCodecView != null) {
|
||||
if (mediaCodecView.isPlaying()) {
|
||||
stopPlayback();
|
||||
}
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@@ -153,16 +144,10 @@ public class VideoPlayerView extends Activity {
|
||||
|
||||
FrameLayout playerFrame = new FrameLayout(this);
|
||||
|
||||
View view;
|
||||
if (useMediaCodec) {
|
||||
mediaCodecView = new MediaCodecView(this);
|
||||
view = mediaCodecView;
|
||||
} else {
|
||||
videoView = new FullScreenVideoView(this);
|
||||
view = videoView;
|
||||
}
|
||||
videoView = new FullScreenVideoView(this);
|
||||
|
||||
playerFrame.addView(view, new FrameLayout.LayoutParams(
|
||||
videoView.setVisibility(View.INVISIBLE);
|
||||
playerFrame.addView(videoView, new FrameLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
@@ -174,7 +159,6 @@ public class VideoPlayerView extends Activity {
|
||||
public void onClick(View v) {
|
||||
Log.d(TAG, "Click play (start playback).");
|
||||
startPlayback();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -211,8 +195,8 @@ public class VideoPlayerView extends Activity {
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT));
|
||||
fullScreen.setVisibility(View.INVISIBLE);
|
||||
playerFrame.addView(bgImage, new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT));
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
main = new LinearLayout(this);
|
||||
main.addView(playerFrame, new LinearLayout.LayoutParams((int)(width * 0.65),
|
||||
@@ -227,23 +211,14 @@ public class VideoPlayerView extends Activity {
|
||||
private void startPlayback() {
|
||||
logMessage("Playback start.");
|
||||
playButton.setText(R.string.stop);
|
||||
|
||||
bgImage.setVisibility(View.GONE);
|
||||
videoView.setVisibility(View.VISIBLE);
|
||||
|
||||
if (useMediaCodec) {
|
||||
mediaCodecView.setDataSource(
|
||||
this,
|
||||
Uri.parse(assetUri),
|
||||
null /* headers */,
|
||||
true /* encrypted */);
|
||||
videoView.setVideoPath(assetUri);
|
||||
videoView.setMediaController(new MediaController(context));
|
||||
|
||||
mediaCodecView.setMediaController(new MediaController(context));
|
||||
mediaCodecView.requestFocus();
|
||||
mediaCodecView.start();
|
||||
} else {
|
||||
videoView.setVideoPath(assetUri);
|
||||
videoView.setMediaController(new MediaController(context));
|
||||
|
||||
videoView.setOnErrorListener(new OnErrorListener() {
|
||||
videoView.setOnErrorListener(new OnErrorListener() {
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
String message = "Unknown error: " + what;
|
||||
switch (what) {
|
||||
@@ -261,18 +236,19 @@ public class VideoPlayerView extends Activity {
|
||||
|
||||
updateLogs();
|
||||
bgImage.setVisibility(View.VISIBLE);
|
||||
videoView.setVisibility(View.INVISIBLE);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
videoView.setOnCompletionListener(new OnCompletionListener() {
|
||||
videoView.setOnCompletionListener(new OnCompletionListener() {
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
Log.d(TAG, "onCompletion.");
|
||||
stopPlayback();
|
||||
}
|
||||
});
|
||||
|
||||
videoView.setOnInfoListener(new OnInfoListener() {
|
||||
videoView.setOnInfoListener(new OnInfoListener() {
|
||||
public boolean onInfo(MediaPlayer mp, int what, int extra) {
|
||||
|
||||
String message = "Unknown info message";
|
||||
@@ -315,68 +291,40 @@ public class VideoPlayerView extends Activity {
|
||||
}
|
||||
});
|
||||
|
||||
videoView.requestFocus();
|
||||
videoView.requestFocus();
|
||||
|
||||
videoView.start();
|
||||
videoView.start();
|
||||
|
||||
if (videoView.getFullScreen()) {
|
||||
sidePanel.setVisibility(View.GONE);
|
||||
} else {
|
||||
sidePanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
fullScreen.setVisibility(View.VISIBLE);
|
||||
videoView.setFullScreenDimensions(contentView.getRight() - contentView.getLeft(),
|
||||
contentView.getBottom() - contentView.getTop());
|
||||
if (videoView.getFullScreen()) {
|
||||
sidePanel.setVisibility(View.GONE);
|
||||
} else {
|
||||
sidePanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
fullScreen.setVisibility(View.VISIBLE);
|
||||
videoView.setFullScreenDimensions(contentView.getRight() - contentView.getLeft(),
|
||||
contentView.getBottom() - contentView.getTop());
|
||||
}
|
||||
|
||||
private void stopPlayback() {
|
||||
logMessage("Stop Playback.");
|
||||
playButton.setText(R.string.play);
|
||||
bgImage.setVisibility(View.VISIBLE);
|
||||
videoView.setVisibility(View.INVISIBLE);
|
||||
|
||||
if (useMediaCodec) {
|
||||
mediaCodecView.reset();
|
||||
} else {
|
||||
videoView.stopPlayback();
|
||||
videoView.stopPlayback();
|
||||
|
||||
fullScreen.setVisibility(View.INVISIBLE);
|
||||
if (videoView.getFullScreen() && !enteringFullScreen) {
|
||||
videoView.setVisibility(View.INVISIBLE);
|
||||
videoView.setFullScreen(false);
|
||||
videoView.setVisibility(View.VISIBLE);
|
||||
sidePanel.setVisibility(View.VISIBLE);
|
||||
fullScreen.setText(FULLSCREEN);
|
||||
}
|
||||
fullScreen.setVisibility(View.INVISIBLE);
|
||||
if (videoView.getFullScreen() && !enteringFullScreen) {
|
||||
videoView.setVisibility(View.INVISIBLE);
|
||||
videoView.setFullScreen(false);
|
||||
sidePanel.setVisibility(View.VISIBLE);
|
||||
fullScreen.setText(FULLSCREEN);
|
||||
}
|
||||
enteringFullScreen = false;
|
||||
}
|
||||
|
||||
private View createButtons() {
|
||||
mediaCodecModeButton = new Button(this);
|
||||
if (useMediaCodec) {
|
||||
mediaCodecModeButton.setText(R.string.normal_mode);
|
||||
} else {
|
||||
mediaCodecModeButton.setText(R.string.mediacodec_mode);
|
||||
}
|
||||
mediaCodecModeButton.setTextSize(BUTTON_FONT_SIZE);
|
||||
|
||||
mediaCodecModeButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
onStop();
|
||||
|
||||
useMediaCodec = (useMediaCodec) ? false : true;
|
||||
Log.d(TAG, "Click media codec mode. useMediaCodec = "+useMediaCodec);
|
||||
contentView = createView();
|
||||
if (drm.isProvisionedDevice()) {
|
||||
setContentView(contentView);
|
||||
} else {
|
||||
setContentView(R.layout.notprovisioned);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
playButton = new Button(this);
|
||||
playButton.setText(R.string.play);
|
||||
playButton.setTextSize(BUTTON_FONT_SIZE);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
@@ -1,85 +1,95 @@
|
||||
/*
|
||||
* (c)Copyright 2011 Widevine Technologies, Inc
|
||||
* (c)Copyright 2011 Google, Inc
|
||||
*/
|
||||
|
||||
package com.widevine.demo;
|
||||
|
||||
import android.app.TabActivity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TabHost;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
public class WidevineSamplePlayer extends TabActivity {
|
||||
public class WidevineSamplePlayer extends AppCompatActivity {
|
||||
|
||||
public static final String PREFS_NAME = "DrmPrefs";
|
||||
private static final String TAG = "WidevineSamplePlayer";
|
||||
|
||||
DemoPagerAdapter mPagerAdapter;
|
||||
ViewPager mViewPager;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||
WidevineDrm.Settings.DRM_SERVER_URI = settings.getString("drmServer",
|
||||
WidevineDrm.Settings.DRM_SERVER_URI);
|
||||
WidevineDrm.Settings.DEVICE_ID = settings.getString("deviceId",
|
||||
WidevineDrm.Settings.DEVICE_ID);
|
||||
WidevineDrm.Settings.PORTAL_NAME = settings.getString("portalId",
|
||||
WidevineDrm.Settings.PORTAL_NAME);
|
||||
SettingsActivity.CONTENT_PAGE = settings.getString("contentPage",
|
||||
SettingsActivity.CONTENT_PAGE);
|
||||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
TabHost tab = getTabHost();
|
||||
// ViewPager and its adapters use support library
|
||||
// fragments, so use getSupportFragmentManager.
|
||||
mPagerAdapter = new DemoPagerAdapter(getSupportFragmentManager(), this);
|
||||
mViewPager = (ViewPager)findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
|
||||
tabs.setupWithViewPager(mViewPager);
|
||||
}
|
||||
|
||||
// Setup Streaming tab
|
||||
TabHost.TabSpec streamingTab = tab.newTabSpec("Streaming");
|
||||
|
||||
streamingTab.setIndicator("Streaming");
|
||||
|
||||
Intent streamingIntent = new Intent(this, StreamingActivity.class);
|
||||
streamingTab.setContent(streamingIntent);
|
||||
|
||||
tab.addTab(streamingTab);
|
||||
|
||||
// Setup Down load tab
|
||||
TabHost.TabSpec downloadTab = tab.newTabSpec("Downloads");
|
||||
|
||||
downloadTab.setIndicator("Downloads");
|
||||
|
||||
Intent downloadIntent = new Intent(this, DownloadActivity.class);
|
||||
downloadTab.setContent(downloadIntent);
|
||||
|
||||
tab.addTab(downloadTab);
|
||||
|
||||
// Setup Settings tab
|
||||
TabHost.TabSpec settingsTab = tab.newTabSpec("Settings");
|
||||
|
||||
settingsTab.setIndicator("Settings");
|
||||
|
||||
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
||||
settingsTab.setContent(settingsIntent);
|
||||
|
||||
tab.addTab(settingsTab);
|
||||
}
|
||||
|
||||
class DemoPagerAdapter extends FragmentPagerAdapter {
|
||||
private Context context;
|
||||
public DemoPagerAdapter(FragmentManager fm, Context c) {
|
||||
super(fm);
|
||||
context = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
public Fragment getItem(int i) {
|
||||
Fragment fragment = null;
|
||||
switch (i) {
|
||||
case 0: fragment = new StreamingFragment();
|
||||
break;
|
||||
case 1: fragment = new DownloadFragment();
|
||||
break;
|
||||
case 2: fragment = new SettingsFragment();
|
||||
break;
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
// We need an Editor object to make preference changes.
|
||||
// All objects are from android.context.Context
|
||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putString("drmServer", WidevineDrm.Settings.DRM_SERVER_URI);
|
||||
editor.putString("deviceId", WidevineDrm.Settings.DEVICE_ID);
|
||||
editor.putString("portalId", WidevineDrm.Settings.PORTAL_NAME);
|
||||
editor.putString("contentPage", SettingsActivity.CONTENT_PAGE);
|
||||
// Commit the edits!
|
||||
editor.commit();
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
int tabNameIds[] = {R.string.streaming, R.string.downloads, R.string.settings};
|
||||
return context.getResources().getText(tabNameIds[position]);
|
||||
}
|
||||
}
|
||||
|
||||
// Instances of this class are fragments representing a single
|
||||
// object in our collection.
|
||||
class DemoObjectFragment extends Fragment {
|
||||
public static final String ARG_OBJECT = "object";
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
// The last two arguments ensure LayoutParams are inflated
|
||||
// properly.
|
||||
View rootView = inflater.inflate(R.layout.empty, container, false);
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user