Example #1
0
  public Window(final StandOutWindow context, final int id) {
    super(context);
    context.setTheme(context.getThemeStyle());

    mContext = context;
    mLayoutInflater = LayoutInflater.from(context);

    this.cls = context.getClass();
    this.id = id;
    this.originalParams = context.getParams(id, this);
    this.flags = context.getFlags(id);
    this.touchInfo = new TouchInfo();
    touchInfo.ratio = (float) originalParams.width / originalParams.height;
    this.data = new Bundle();
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    displayWidth = metrics.widthPixels;
    displayHeight = (int) (metrics.heightPixels - 25 * metrics.density);

    // create the window contents
    View content;
    FrameLayout body;

    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
      // requested system window decorations
      content = getSystemDecorations();
      body = (FrameLayout) content.findViewById(R.id.body);
    } else {
      // did not request decorations. will provide own implementation
      content = new FrameLayout(context);
      content.setId(R.id.content);
      body = (FrameLayout) content;
    }

    addView(content);

    body.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // pass all touch events to the implementation
            boolean consumed = false;

            // handle move and bring to front
            consumed = context.onTouchHandleMove(id, Window.this, v, event) || consumed;

            // alert implementation
            consumed = context.onTouchBody(id, Window.this, v, event) || consumed;

            return consumed;
          }
        });

    // attach the view corresponding to the id from the
    // implementation
    context.createAndAttachView(id, body);

    // make sure the implementation attached the view
    if (body.getChildCount() == 0) {
      throw new RuntimeException(
          "You must attach your view to the given frame in createAndAttachView()");
    }

    // implement StandOut specific workarounds
    if (!Utils.isSet(flags, StandOutFlags.FLAG_FIX_COMPATIBILITY_ALL_DISABLE)) {
      fixCompatibility(body);
    }
    // implement StandOut specific additional functionality
    if (!Utils.isSet(flags, StandOutFlags.FLAG_ADD_FUNCTIONALITY_ALL_DISABLE)) {
      addFunctionality(body);
    }

    // attach the existing tag from the frame to the window
    setTag(body.getTag());
  }