package com.telpo.presentation;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Presentation;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
//BEGIN_INCLUDE(activity)
/**
* <h3>Presentation Activity</h3>
*
* <p>
* This demonstrates how to create an activity that shows some content
* on a secondary display using a {@link Presentation}.
* </p><p>
* The activity uses the {@link DisplayManager} API to enumerate displays.
* When the user selects a display, the activity opens a {@link Presentation}
* on that display. We show a different photograph in each presentation
* on a unique background along with a label describing the display.
* We also write information about displays and display-related events to
* the Android log which you can read using <code>adb logcat</code>.
* </p><p>
* You can try this out using an HDMI or Wifi display or by using the
* "Simulate secondary displays" feature in Development Settings to create a few
* simulated secondary displays. Each display will appear in the list along with a
* checkbox to show a presentation on that display.
* </p><p>
* uses the media router to automatically select a secondary display
* on which to show content based on the currently selected route.
* </p>
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public class PresentationActivity extends Activity
implements OnCheckedChangeListener, OnClickListener, OnItemSelectedListener {
private final String TAG = "PresentationActivity";
// Key for storing saved instance state.
private static final String PRESENTATION_KEY = "presentation";
// The content that we want to show on the presentation.
private static final int[] PHOTOS = new int[] {
R.drawable.frantic,
R.drawable.photo1, R.drawable.photo2, R.drawable.photo3,
R.drawable.photo4, R.drawable.photo5, R.drawable.photo6,
R.drawable.sample_4,
};
private DisplayManager mDisplayManager;
private DisplayListAdapter mDisplayListAdapter;
private CheckBox mShowAllDisplaysCheckbox;
private ListView mListView;
private int mNextImageNumber;
// List of presentation contents indexed by displayId.
// This state persists so that we can restore the old presentation
// contents when the activity is paused or resumed.
private SparseArray<DemoPresentationContents> mSavedPresentationContents;
// List of all currently visible presentations indexed by display id.
private final SparseArray<DemoPresentation> mActivePresentations =
new SparseArray<DemoPresentation>();
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// Restore saved instance state.
if (savedInstanceState != null) {
mSavedPresentationContents =
savedInstanceState.getSparseParcelableArray(PRESENTATION_KEY);
} else {
mSavedPresentationContents = new SparseArray<DemoPresentationContents>();
}
// Get the display manager service.
mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);
// See assets/res/any/layout/presentation_activity.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.presentation_activity);
// Set up checkbox to toggle between showing all displays or only presentation displays.
mShowAllDisplaysCheckbox = (CheckBox)findViewById(R.id.show_all_displays);
mShowAllDisplaysCheckbox.setOnCheckedChangeListener(this);
// Set up the list of displays.
mDisplayListAdapter = new DisplayListAdapter(this);
mListView = (ListView)findViewById(R.id.display_list);
mListView.setAdapter(mDisplayListAdapter);
}
@Override
protected void onResume() {
// Be sure to call the super class.
super.onResume();
// Update our list of displays on resume.
mDisplayListAdapter.updateContents();
// Restore presentations from before the activity was paused.
final int numDisplays = mDisplayListAdapter.getCount();
for (int i = 0; i < numDisplays; i++) {
final Display display = mDisplayListAdapter.getItem(i);
final DemoPresentationContents contents =
mSavedPresentationContents.get(display.getDisplayId());
if (contents != null) {
showPresentation(display, contents);
}
}
mSavedPresentationContents.clear();
// Register to receive events from the display manager.
mDisplayManager.registerDisplayListener(mDisplayListener, null);
}
@Override
protected void onPause() {
// Be sure to call the super class.
super.onPause();
// Unregister from the display manager.
mDisplayManager.unregisterDisplayListener(mDisplayListener);
// Dismiss all of our presentations but remember their contents.
Log.d(TAG, "Activity is being paused. Dismissing all active presentation.");
for (int i = 0; i < mActivePresentations.size(); i++) {
DemoPresentation presentation = mActivePresentations.valueAt(i);
int displayId = mActivePresentations.keyAt(i);
mSavedPresentationContents.put(displayId, presentation.mContents);
presentation.dismiss();
}
mActivePresentations.clear();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// Be sure to call the super class.
super.onSaveInstanceState(outState);
outState.putSparseParcelableArray(PRESENTATION_KEY, mSavedPresentationContents);
}
/**
* Shows a {@link Presentation} on the specified display.
*/
private void showPresentation(Display display, DemoPresentationContents contents) {
final int displayId = display.getDisplayId();
if (mActivePresentations.get(displayId) != null) {
return;
}
Log.d(TAG, "Showing presentation photo #" + contents.photo
+ " on display #" + displayId + ".");
DemoPresentation presentation = new DemoPresentation(this, display, contents);
presentation.show();
presentation.setOnDismissListener(mOnDismissListener);
mActivePresentations.put(displayId, presentation);
}
/**
* Hides a {@link Presentation} on the specified display.
*/
private void hidePresentation(Display display) {
final int displayId = display.getDisplayId();
DemoPresentation presentation = mActivePresentations.get(displayId);
if (presentation == null) {
return;
}
Log.d(TAG, "Dismissing presentation on display #" + displayId + ".");
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
presentation-dev.zip (57个子文件)
presentation-dev
gradlew.bat 2KB
gradlew 5KB
gradle.properties 726B
app
proguard-rules.pro 751B
src
test
java
com
telpo
presentation
ExampleUnitTest.java 383B
androidTest
java
com
telpo
presentation
ExampleInstrumentedTest.java 728B
main
res
mipmap-xxxhdpi
ic_launcher.png 9KB
ic_launcher_round.png 15KB
drawable
photo5.jpg 54KB
photo2.jpg 16KB
sample_4.jpg 50KB
photo1.jpg 41KB
photo6.jpg 43KB
photo3.jpg 53KB
photo4.jpg 47KB
ic_launcher_background.xml 5KB
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 5KB
drawable-v24
ic_launcher_foreground.xml 2KB
values
colors.xml 208B
strings.xml 855B
styles.xml 383B
drawable-nodpi
frantic.jpg 188KB
mipmap-xxhdpi
ic_launcher.png 6KB
ic_launcher_round.png 10KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 3KB
mipmap-xhdpi
ic_launcher.png 4KB
ic_launcher_round.png 7KB
mipmap-anydpi-v26
ic_launcher_round.xml 272B
ic_launcher.xml 272B
layout
presentation_activity.xml 2KB
presentation_list_item.xml 2KB
presentation_content.xml 3KB
java
com
telpo
presentation
DemoPresentationContents.java 2KB
PresentationActivity.java 17KB
DemoPresentation.java 4KB
AndroidManifest.xml 1KB
.gitignore 7B
release
output.json 234B
build.gradle 927B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 230B
screenshot.png 75KB
.idea
dbnavigator.xml 22KB
caches
build_file_checksums.ser 545B
codeStyles
Project.xml 5KB
gradle.xml 748B
runConfigurations.xml 564B
misc.xml 3KB
jarRepositories.xml 2KB
inspectionProfiles
Project_Default.xml 2KB
.gitignore 137B
settings.gradle 15B
release
app-release.apk 1.87MB
output.json 234B
build.gradle 546B
共 57 条
- 1
Mr.码农
- 粉丝: 173
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5