My question is about the Android facility for utilizing the secondary screen of device, i.e. android.app.Presentation
I'm using this wrapper: https://github.com/commonsguy/cwac-presentation
Unfortunately I cannot force the second screen layout to be in fullscreen mode: although its width fully matches the screen, its height is always restricted to a stripe in the center of screen, approximately 1/4 of screen height
Correspondingly, all its content is displayed within this narrow boundary, while the remaining parts of the screen keep staying black and useless
For those who don't have an idea about this API,
android.app.Presentation
is a special type of Dialog
which is shown on secondary screen of device,
The wrapper I've mentioned above, is based on PresentationFragment
which extends DialogFragment
. User creates a class extending PresentationFragment
, and in its overridden onCreateView()
he creates the layout he wishes to be displayed on second screen. Example:
public class CustomPresentationFragment extends PresentationFragment {
public static CustomPresentationFragment newInstance(Context ctxt,
Display display) {
CustomPresentationFragment frag=new CustomPresentationFragment();
frag.setDisplay(ctxt, display);
//we may prepare bundle to pass, if necessary
//Bundle b=new Bundle();
//b.putString("key1", value1);
//b.putString("key2", value2);
//frag.setArguments(b);
return(frag);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View myView = new View(getContext());
//here we create layout that we want to be displayed on second screen, and return it
return(myView);
}
}
This is the implementation of PresentationFragment
. As we see, it contains Presentation
variable:
package com.commonsware.cwac.preso;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
public abstract class PresentationFragment extends DialogFragment
{
private Display display = null;
private Presentation preso = null;
public Dialog onCreateDialog(Bundle savedInstanceState)
{
if (this.preso == null) {
return super.onCreateDialog(savedInstanceState);
//instead of simply returning super value, I have tried the following here,
//with no success:
//
//Dialog dlg = super.onCreateDialog(savedInstanceState);
//dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//dlg.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//dlg.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//return dlg;
}
return this.preso;
}
public void setDisplay(Context ctxt, Display display) {
if (display == null) {
this.preso = null;
}
else {
this.preso = new Presentation(ctxt, display, getTheme());
//since Presentation is Dialog, I have tried the same here as well,
//no success:
//this.preso.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//this.preso.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this.preso.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
this.display = display;
}
public Display getDisplay() {
return this.display;
}
protected Context getContext() {
if (this.preso != null) {
return this.preso.getContext();
}
return getActivity();
}
}
EDIT.
This is onCreateView()
from one of my PresentationFragments:
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
String uri = "somefilepath";
File imgFile = new File(uri);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView view = new ImageView(getContext());
view.setImageBitmap(myBitmap);
view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
RelativeLayout pRelative = new RelativeLayout(getContext());
pRelative.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
pRelative.setGravity(Gravity.CENTER);
pRelative.addView(view);
return pRelative;
}