1

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;       

      }
mangusta
  • 3,470
  • 5
  • 24
  • 47
  • Since you have elected to not show the code that is giving you trouble (i.e., the real implementation of `onCreateView()`), I cannot help you much. Try running the supplied demo app, which does not exhibit the behavior that you describe. If you get the same behavior, something must be awry with your specific environment. If the demo app behaves properly, compare and contrast your implementation versus the demo's. – CommonsWare Dec 16 '14 at 12:04
  • @CommonsWare Thanks for a quick reply. Basically, it doesn't matter which view I return from `onCreateView()`, one fragment returns RelativeLayout with ImageView inside, second fragment returns RelativeLayout with WebView inside, third fragment returns RelativeLayout with VideoView inside. All do comply with the way you described how to use `onCreateView()` – mangusta Dec 16 '14 at 14:28
  • and all are restricted to the narrow strip in the middle of screen. regarding demo, should I use the one labeled "demo" or the one called "presentation" ? – mangusta Dec 16 '14 at 14:30
  • "Basically, it doesn't matter which view I return from onCreateView()" -- yes, it does, because **we cannot see this code** and therefore cannot help you with it or use it to try to reproduce your problem. "regarding demo, should I use the one labeled "demo" or the one called "presentation" ?" -- quoting [the documentation](https://github.com/commonsguy/cwac-presentation#demo), "In the demo/ sub-project you will find a sample project demonstrating the use of the aforementioned classes, with the exception of PresentationService." – CommonsWare Dec 16 '14 at 14:32
  • @CommonsWare all right, I've included the one with ImageView. – mangusta Dec 16 '14 at 14:40

1 Answers1

1

First, the parent of your RelativeLayout is probably not another RelativeLayout, and therefore you should not be trying to set the RelativeLayout's LayoutParams to be an instance of RelativeLayout.LayoutParams.

Second, rewrite this as an XML layout and inflate it. Your RelativeLayout has a better chance of working then, as it will know its parent at inflation time. RelativeLayout is a finicky beast. Another option would be to switch away from RelativeLayout to something else that can do your centering, such as a FrameLayout.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • unfortunately your demo app shows the same behaviour. http://s50.radikal.ru/i130/1412/c6/4af7de26f918.jpg (the second screen size is identical to the master screen). the mirror shows up normally though, i.e. the behaviour is presentation-related only – mangusta Dec 17 '14 at 09:19
  • the link above depicts the screen on app launch. this is Mirror Presentation, selected from menu: http://s017.radikal.ru/i427/1412/80/c838f6c886de.jpg, and this is Mirror Fragment, selected from menu: http://i067.radikal.ru/1412/b5/44af1068614b.jpg – mangusta Dec 17 '14 at 09:25
  • @mangusta: It must somehow be tied to your external display. I have used this code on several projectors and televisions, including using it for a few conference presentations, without issue. What exactly are you using for your external display? – CommonsWare Dec 17 '14 at 11:44
  • seems that it was somehow related to inability of second screen to show full-screen layout in portrait mode, so we switched it to landscape and turned the views 270 degree clockwise. This seemed to solve the full-screen issue, although introducing some other issues : ) we're unable to scale views inside of presentation fragment. although it seems to be a bit out of topic, maybe you know how to overcome this ? : ) – mangusta Dec 17 '14 at 20:03
  • @mangusta: I am not sure what you mean by "scale views". Do you mean `setScaleX()` and such? I have never tried that in a `Presentation`, but I would be somewhat surprised if it didn't work. – CommonsWare Dec 17 '14 at 20:05
  • yes, `setScaleX()` & `setScaleY()`. thanks for assistance, in any case : ) – mangusta Dec 17 '14 at 20:07
  • @mangusta: If you come up with a reproducible test case demonstrating your scale problem, I'd be interested to see it. – CommonsWare Dec 17 '14 at 20:15