@Override public View getView(int position, View convertView, ViewGroup parent) { final View v; if (convertView == null) { v = ((Activity) mContext).getLayoutInflater().inflate( R.layout.presentation_list_item, null); } else { v = convertView; } final Display display = getItem(position); final int displayId = display.getDisplayId(); CheckBox cb = (CheckBox)v.findViewById(R.id.checkbox_presentation); cb.setTag(display); cb.setOnCheckedChangeListener(PresentationActivity.this); cb.setChecked(mActivePresentations.indexOfKey(displayId) >= 0 || mSavedPresentationContents.indexOfKey(displayId) >= 0); TextView tv = (TextView)v.findViewById(R.id.display_id); tv.setText(v.getContext().getResources().getString( R.string.presentation_display_id_text, displayId, display.getName())); Button b = (Button)v.findViewById(R.id.info); b.setTag(display); b.setOnClickListener(PresentationActivity.this); return v; }
@Override public void onDisplayRemoved(int displayId) { Log.d(TAG, "Display #" + displayId + " removed."); mDisplayListAdapter.updateContents(); } };
final Display display = getItem(position); final int displayId = display.getDisplayId();
/** * 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<>(); } // 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); }
/** * 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<PresentationContents>(); } // 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); }
/** * Called when the show all displays checkbox is toggled or when * an item in the list of displays is checked or unchecked. */ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView == mShowAllDisplaysCheckbox) { // Show all displays checkbox was toggled. mDisplayListAdapter.updateContents(); } else { // Display item checkbox was toggled. final Display display = (Display)buttonView.getTag(); if (isChecked) { DemoPresentationContents contents = new DemoPresentationContents(getNextPhoto()); showPresentation(display, contents); } else { hidePresentation(display); } mDisplayListAdapter.updateContents(); } }
@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); }
/** * Called when the show all displays checkbox is toggled or when * an item in the list of displays is checked or unchecked. */ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView == mShowAllDisplaysCheckbox) { // Show all displays checkbox was toggled. mDisplayListAdapter.updateContents(); } else { // Display item checkbox was toggled. final Display display = (Display)buttonView.getTag(); if (isChecked) { PresentationContents contents = new PresentationContents(getNextPhoto()); showPresentation(display, contents); } else { hidePresentation(display); } } }
@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 PresentationContents 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); }
/** * Update the contents of the display list adapter to show * information about all current displays. */ public void updateContents() { clear(); String displayCategory = getDisplayCategory(); Display[] displays = mDisplayManager.getDisplays(displayCategory); addAll(displays); Log.d(TAG, "There are currently " + displays.length + " displays connected."); for (Display display : displays) { Log.d(TAG, " " + display); } }
/** * Update the contents of the display list adapter to show * information about all current displays. */ public void updateContents() { clear(); String displayCategory = getDisplayCategory(); Display[] displays = mDisplayManager.getDisplays(displayCategory); addAll(displays); Log.d(TAG, "There are currently " + displays.length + " displays connected."); for (Display display : displays) { Log.d(TAG, " " + display); } }
@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(); } };
@Override public void onDisplayAdded(int displayId) { Log.d(TAG, "Display #" + displayId + " added."); mDisplayListAdapter.updateContents(); }
@Override public void onDisplayChanged(int displayId) { Log.d(TAG, "Display #" + displayId + " changed."); mDisplayListAdapter.updateContents(); }
@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(); } };
@Override public void onDisplayRemoved(int displayId) { Log.d(TAG, "Display #" + displayId + " removed."); mDisplayListAdapter.updateContents(); } };
@Override public void onDisplayChanged(int displayId) { Log.d(TAG, "Display #" + displayId + " changed."); mDisplayListAdapter.updateContents(); }
@Override public void onDisplayAdded(int displayId) { Log.d(TAG, "Display #" + displayId + " added."); mDisplayListAdapter.updateContents(); }