Android Open Source - Media-Pack Popup






From Project

Back to project page Media-Pack.

License

The source code is released under:

Apache License

If you think the Android project Media-Pack listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//
//               INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 2013-2014 Intel Corporation. All Rights Reserved.
///* ww w  .  ja  v a 2  s . c o  m*/

package com.intel.inde.mp.samples.controls;

import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.PopupWindow;
import com.intel.inde.mp.samples.R;

public class Popup extends PopupWindow implements OnTouchListener, PopupWindow.OnDismissListener {
    protected Context context;
    protected View contentView;

    public Popup(Context context) {
        super(context);

        this.context = context;

        init();
    }

    public void show(View anchor, boolean center) {
        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

        int contentWidth = contentView.getMeasuredWidth();
        int contentHeight = contentView.getMeasuredHeight();

        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        int screenWidth = metrics.widthPixels;
        int screenHeight = metrics.heightPixels;

        int xPos = 0;
        int yPos = 0;

        boolean onTop = true;
        boolean onLeft = true;

        int gravity = Gravity.NO_GRAVITY;

        if (center) {
            xPos = 0;
            yPos = 0;

            gravity = Gravity.CENTER;
        } else {
            int[] location = new int[2];

            anchor.getLocationOnScreen(location);

            Rect anchorRect = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1] + anchor.getHeight());

            if ((anchorRect.left + contentWidth) > screenWidth) {
                if (anchorRect.right - contentWidth < 0) {
                    xPos = screenWidth - contentWidth - 4;
                } else {
                    xPos = anchorRect.right - contentWidth;
                }

                onLeft = false;
            } else {
                xPos = anchorRect.left;
                onLeft = true;
            }

            if (anchorRect.top < screenHeight / 2) {
                yPos = anchorRect.bottom + 4;
                onTop = true;
            } else {
                yPos = anchorRect.top - contentHeight - 4;
                onTop = false;
            }

            if (onTop) {
                if (onLeft) {
                    setAnimationStyle(R.style.Popups_Down_Left);
                } else {
                    setAnimationStyle(R.style.Popups_Down_Right);
                }
            } else {
                if (onLeft) {
                    setAnimationStyle(R.style.Popups_Up_Left);
                } else {
                    setAnimationStyle(R.style.Popups_Up_Right);
                }
            }
        }

        setOnDismissListener(this);

        onShow();

        showAtLocation(anchor, gravity, xPos, yPos);
    }

    public void hide() {
        dismiss();
    }

    private void init() {
        setTouchInterceptor(this);

        setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        setTouchable(true);
        setFocusable(true);
        setOutsideTouchable(true);

        setBackgroundDrawable(context.getResources().getDrawable(R.drawable.background_popup));
    }

    public void setContentView(View view) {
        super.setContentView(view);

        contentView = view;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
            dismiss();

            return true;
        }

        return false;
    }

    public void onShow() {
    }

    @Override
    public void onDismiss() {

    }
}




Java Source Code List

com.intel.inde.mp.android.graphics.EglUtil.java
com.intel.inde.mp.android.graphics.FrameBuffer.java
com.intel.inde.mp.android.graphics.FullFrameTexture.java
com.intel.inde.mp.android.graphics.ShaderProgram.java
com.intel.inde.mp.android.graphics.VideoEffect.java
com.intel.inde.mp.effects.AudioEffect.java
com.intel.inde.mp.effects.AudioReader.java
com.intel.inde.mp.effects.GrayScaleEffect.java
com.intel.inde.mp.effects.InverseEffect.java
com.intel.inde.mp.effects.JpegSubstituteEffect.java
com.intel.inde.mp.effects.OverlayEffect.java
com.intel.inde.mp.effects.RotateEffect.java
com.intel.inde.mp.effects.SepiaEffect.java
com.intel.inde.mp.effects.SubstituteAudioEffect.java
com.intel.inde.mp.effects.TextOverlayEffect.java
com.intel.inde.mp.samples.ActivityWithTimeline.java
com.intel.inde.mp.samples.CameraCapturerActivity.java
com.intel.inde.mp.samples.CameraStreamerActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectCoreActivity.java
com.intel.inde.mp.samples.ComposerCutActivity.java
com.intel.inde.mp.samples.ComposerCutCoreActivity.java
com.intel.inde.mp.samples.ComposerJoinActivity.java
com.intel.inde.mp.samples.ComposerJoinCoreActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoCoreActivity.java
com.intel.inde.mp.samples.ComposerTranscodeActivity.java
com.intel.inde.mp.samples.ComposerTranscodeCoreActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectCoreActivity.java
com.intel.inde.mp.samples.DemoListAdapter.java
com.intel.inde.mp.samples.DemoListItem.java
com.intel.inde.mp.samples.ExpandableSamplesListAdapter.java
com.intel.inde.mp.samples.FPSCounter.java
com.intel.inde.mp.samples.Format.java
com.intel.inde.mp.samples.GameCapturing.java
com.intel.inde.mp.samples.GameRenderer.java
com.intel.inde.mp.samples.GameStreaming.java
com.intel.inde.mp.samples.MediaStreamerActivity.java
com.intel.inde.mp.samples.MediaStreamerCoreActivity.java
com.intel.inde.mp.samples.RecognitionActivity.java
com.intel.inde.mp.samples.SamplesMainActivity.java
com.intel.inde.mp.samples.VideoCapture.java
com.intel.inde.mp.samples.VideoPlayerActivity.java
com.intel.inde.mp.samples.VideoStreamPlayerActivity.java
com.intel.inde.mp.samples.controls.CameraCaptureSettingsPopup.java
com.intel.inde.mp.samples.controls.GameGLSurfaceView.java
com.intel.inde.mp.samples.controls.PlaybackToolbar.java
com.intel.inde.mp.samples.controls.PopupMessage.java
com.intel.inde.mp.samples.controls.Popup.java
com.intel.inde.mp.samples.controls.RangeSelector.java
com.intel.inde.mp.samples.controls.TimelineItem.java
com.intel.inde.mp.samples.controls.TranscodeSurfaceView.java
com.intel.inde.mp.samples.controls.VideoPlayer.java