/** * 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); }
@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 onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // Get the resources for the context of the presentation. // Notice that we are getting the resources from the context of the presentation. Resources r = getContext().getResources(); // Inflate the layout. setContentView(R.layout.presentation_content); final Display display = getDisplay(); final int displayId = display.getDisplayId(); final int photo = mContents.photo; // Show a caption to describe what's going on. TextView text = (TextView)findViewById(R.id.text); text.setText(r.getString(R.string.presentation_photo_text, photo, displayId, display.getName())); // Show a n image for visual interest. ImageView image = (ImageView)findViewById(R.id.image); image.setImageDrawable(r.getDrawable(PHOTOS[photo])); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT); // Set the background to a random gradient. Point p = new Point(); getDisplay().getSize(p); drawable.setGradientRadius(Math.max(p.x, p.y) / 2); drawable.setColors(mContents.colors); findViewById(android.R.id.content).setBackground(drawable); } }
@Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // Get the resources for the context of the presentation. // Notice that we are getting the resources from the context of the presentation. Resources r = getContext().getResources(); // Inflate the layout. setContentView(R.layout.presentation_content); final Display display = getDisplay(); final int displayId = display.getDisplayId(); final int photo = mContents.photo; // Show a caption to describe what's going on. TextView text = (TextView)findViewById(R.id.text); text.setText(r.getString(R.string.presentation_photo_text, photo, displayId, display.getName())); // Show a n image for visual interest. ImageView image = (ImageView)findViewById(R.id.image); image.setImageDrawable(r.getDrawable(PHOTOS[photo])); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT); // Set the background to a random gradient. Point p = new Point(); getDisplay().getSize(p); drawable.setGradientRadius(Math.max(p.x, p.y) / 2); drawable.setColors(mContents.colors); findViewById(android.R.id.content).setBackground(drawable); } }
@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(); }
/** * 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.dismiss(); mActivePresentations.delete(displayId); }
/** * 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.dismiss(); mActivePresentations.delete(displayId); }
/** * Shows a {@link Presentation} on the specified display. */ private void showPresentation(Display display, PresentationContents 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); }
@Override public void onDismiss(DialogInterface dialog) { DemoPresentation presentation = (DemoPresentation)dialog; int displayId = presentation.getDisplay().getDisplayId(); Log.d(TAG, "Presentation on display #" + displayId + " was dismissed."); mActivePresentations.delete(displayId); mDisplayListAdapter.notifyDataSetChanged(); } };
/** * Sets the display mode of the {@link Presentation} on the specified display * if it is already shown. */ private void setPresentationDisplayMode(Display display, int displayModeId) { final int displayId = display.getDisplayId(); DemoPresentation presentation = mActivePresentations.get(displayId); if (presentation == null) { return; } presentation.setPreferredDisplayMode(displayModeId); }
@Override public void onDismiss(DialogInterface dialog) { DemoPresentation presentation = (DemoPresentation)dialog; int displayId = presentation.getDisplay().getDisplayId(); Log.d(TAG, "Presentation on display #" + displayId + " was dismissed."); mActivePresentations.delete(displayId); mDisplayListAdapter.notifyDataSetChanged(); } };