Java Code Examples for android.view.ViewGroup#setOnTouchListener()

The following examples show how to use android.view.ViewGroup#setOnTouchListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoDivideActivity.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
private void initView() {
    setContentView(R.layout.activity_video_divide);

    mPreview = (VideoView) findViewById(R.id.preview);
    mPlaybackButton = (ImageButton) findViewById(R.id.pause_playback);
    mFrameListParent = (ViewGroup) findViewById(R.id.recycler_parent);
    mFrameList = (RecyclerView) findViewById(R.id.recycler_frame_list);
    mScrollViewParent = (FrameLayout) findViewById(R.id.scroll_view_parent);
    mScrollView = (ObservableHorizontalScrollView) findViewById(R.id.scroll_view);

    ImageView middleLineImage = (ImageView) findViewById(R.id.middle_line_image);
    ViewGroup topGroup = (ViewGroup) findViewById(R.id.top_group);

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    mFrameWidth = mFrameHeight = wm.getDefaultDisplay().getWidth() / 6;
    middleLineImage.getLayoutParams().height = mFrameHeight;

    mScrollView.setOnScrollListener(new OnViewScrollListener());
    topGroup.setOnTouchListener(new OnTopViewTouchListener());
}
 
Example 2
Source File: RepeatingChainedAnimationsDemoFragment.java    From android_additive_animations with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.fragment_tap_to_move_demo, container, false);
    animatedView = rootView.findViewById(R.id.animated_view);

    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_DOWN) {
                AdditiveAnimator.cancelAnimation(animatedView, View.ROTATION);
            }
            return true;
        }
    });

    animate();
    return rootView;
}
 
Example 3
Source File: MarginsDemoFragment.java    From android_additive_animations with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.fragment_margins_demo, container, false);
    animatedView = rootView.findViewById(R.id.animated_view_with_margins);

    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN) {
                if(AdditiveAnimationsShowcaseActivity.ADDITIVE_ANIMATIONS_ENABLED) {
                    AdditiveAnimator.animate(animatedView).leftMargin((int) event.getX()).topMargin((int) event.getY()).start();
                } else {
                    ViewPropertyObjectAnimator.animate(animatedView).leftMargin((int) event.getX()).topMargin((int) event.getY()).setInterpolator(EaseInOutPathInterpolator.create()).setDuration(1000).start();
                }
            }
            return true;
        }
    });
    return rootView;
}
 
Example 4
Source File: MxVideoPlayer.java    From MxVideoPlayer with Apache License 2.0 6 votes vote down vote up
public void initView(Context context) {
    View.inflate(context, getLayoutId(), this);
    mPlayControllerButton = (ImageView) findViewById(R.id.mx_start);
    mFullscreenButton = (ImageView) findViewById(R.id.mx_fullscreen);
    mProgressBar = (SeekBar) findViewById(R.id.mx_progress);
    mCurrentTimeTextView = (TextView) findViewById(R.id.mx_current_time);
    mTotalTimeTextView = (TextView) findViewById(R.id.mx_total_time);
    mBottomContainer = (ViewGroup) findViewById(R.id.mx_layout_bottom);
    mTextureViewContainer = (ViewGroup) findViewById(R.id.mx_surface_container);
    mTopContainer = (ViewGroup) findViewById(R.id.mx_layout_top);
    mCacheImageView = (MxImageView) findViewById(R.id.mx_cache);

    mPlayControllerButton.setOnClickListener(this);
    if (mFullscreenButton != null) {
        mFullscreenButton.setOnClickListener(this);
    }
    mProgressBar.setOnSeekBarChangeListener(this);
    mBottomContainer.setOnClickListener(this);
    mTextureViewContainer.setOnClickListener(this);

    mTextureViewContainer.setOnTouchListener(this);
    mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
    mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    mHandler = new Handler();
}
 
Example 5
Source File: Skeleton.java    From YiBo with Apache License 2.0 6 votes vote down vote up
private void initEvent() {
	btnMyHome.setEnabled(false);

	btnMyHome.setOnClickListener(buttonListener);
	btnMessage.setOnClickListener(buttonListener);
	btnProfile.setOnClickListener(buttonListener);
	btnApp.setOnClickListener(buttonListener);
	btnMore.setOnClickListener(buttonListener);

	ImageButton ibGroup = (ImageButton)this.findViewById(R.id.ibGroup);
	groupClickListener = new HomePageGroupClickListener(this);
	ibGroup.setOnClickListener(groupClickListener);

	//双击头部快速回到第一行;
	ViewGroup llHeader = (ViewGroup)this.findViewById(R.id.llHeader);
	llHeader.setOnTouchListener(new HomePageHeaderDoubleClickListener());
}
 
Example 6
Source File: SwipeLayout.java    From SwipeLayout with MIT License 5 votes vote down vote up
/**
 * Enable touch for ViewGroup
 */
public void enableTouchForViewGroup(@NonNull final ViewGroup viewGroup) {
    viewGroup.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
}
 
Example 7
Source File: ImageViewerView.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
private void init() {
    inflate(getContext(), R.layout.image_viewer, this);

    backgroundView = findViewById(R.id.backgroundView);
    pager = (MultiTouchViewPager) findViewById(R.id.pager);

    dismissContainer = (ViewGroup) findViewById(R.id.container);
    swipeDismissListener = new SwipeToDismissListener(findViewById(R.id.dismissView), this, this);
    dismissContainer.setOnTouchListener(swipeDismissListener);

    directionDetector = new SwipeDirectionDetector(getContext()) {
        @Override
        public void onDirectionDetected(Direction direction) {
            ImageViewerView.this.direction = direction;
        }
    };

    scaleDetector = new ScaleGestureDetector(getContext(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener());

    gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (pager.isScrolled()) {
                onClick(e, isOverlayWasClicked);
            }
            return false;
        }
    });
}
 
Example 8
Source File: WidgetContainer.java    From DistroHopper with GNU General Public License v3.0 5 votes vote down vote up
protected WidgetContainer (Context context, AttributeSet attrs, WidgetHostView widget)
{
	super (context, attrs);

	widget.setWidgetContainer (this);
	this.widget = widget;

	LayoutInflater inflater = (LayoutInflater) context.getSystemService (Service.LAYOUT_INFLATER_SERVICE);
	this.view = inflater.inflate (R.layout.widget_container, this, true);

	FrameLayout widgetContainer = (FrameLayout) this.findViewById (R.id.widgetContainer);
	widgetContainer.addView (widget);
	this.container = widgetContainer;
	this.overlay = (ViewGroup) this.findViewById (R.id.widgetOverlayCenter);
	ImageButton ibRemove = (ImageButton) this.findViewById (R.id.ibRemove);

	ViewGroup llEdgeTop = (ViewGroup) this.findViewById (R.id.llEdgeTop);
	ViewGroup llEdgeRight = (ViewGroup) this.findViewById (R.id.llEdgeRight);
	ViewGroup llEdgeBottom = (ViewGroup) this.findViewById (R.id.llEdgeBottom);
	ViewGroup llEdgeLeft = (ViewGroup) this.findViewById (R.id.llEdgeLeft);

	llEdgeTop.setOnTouchListener (this);
	llEdgeRight.setOnTouchListener (this);
	llEdgeBottom.setOnTouchListener (this);
	llEdgeLeft.setOnTouchListener (this);
	ibRemove.setOnClickListener (new WidgetContainerRemove_ClickListener (this));
}
 
Example 9
Source File: DatePickerDialog.java    From FastWaiMai with MIT License 4 votes vote down vote up
protected void initViews() {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        decorView = (ViewGroup) ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
        rootView = (ViewGroup) layoutInflater.inflate(R.layout.layout_alertview, decorView, false);
        rootView.setLayoutParams(new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
        ));
//        rootView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View view, MotionEvent motionEvent) {
//                if () {
//                    dismiss();
//                }
//                return false;
//            }
//        });
        contentContainer = (ViewGroup) rootView.findViewById(R.id.content_container);
        contentContainer.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });
        int margin_alert_left_right = 0;
        switch (style) {
            case ActionSheet:
                params.gravity = Gravity.BOTTOM;
                margin_alert_left_right = context.getResources().getDimensionPixelSize(R.dimen.margin_actionsheet_left_right);
                params.setMargins(margin_alert_left_right, 0, margin_alert_left_right, margin_alert_left_right);
                contentContainer.setLayoutParams(params);
                gravity = Gravity.BOTTOM;
                initActionSheetViews(layoutInflater);
                break;
            case Alert:
                params.gravity = Gravity.CENTER;
                margin_alert_left_right = context.getResources().getDimensionPixelSize(R.dimen.margin_alert_left_right);
                params.setMargins(margin_alert_left_right, 0, margin_alert_left_right, 0);
                contentContainer.setLayoutParams(params);
                gravity = Gravity.CENTER;
                initAlertViews(layoutInflater);
                break;
        }
    }
 
Example 10
Source File: CustomPlaybackOverlayFragment.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.vlc_player_interface, container, false);

    // inject the RowsSupportFragment in the popup container
    if (getChildFragmentManager().findFragmentById(R.id.rows_area) == null) {
        mPopupRowsFragment = new RowsSupportFragment();
        getChildFragmentManager().beginTransaction()
                .replace(R.id.rows_area, mPopupRowsFragment).commit();
    } else {
        mPopupRowsFragment = (RowsSupportFragment) getChildFragmentManager()
                .findFragmentById(R.id.rows_area);
    }

    mPopupRowPresenter = new PositionableListRowPresenter();
    mPopupRowAdapter = new ArrayObjectAdapter(mPopupRowPresenter);
    mPopupRowsFragment.setAdapter(mPopupRowAdapter);
    mPopupRowsFragment.setOnItemViewClickedListener(itemViewClickedListener);

    // And the Live Guide element
    mTvGuide = (RelativeLayout) inflater.inflate(R.layout.overlay_tv_guide, null);
    root.addView(mTvGuide);
    mTvGuide.setVisibility(View.GONE);

    root.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //if we're not visible, show us
            if (!mIsVisible) show();

            //and then manage our fade timer
            if (mFadeEnabled) startFadeTimer();

            Timber.d("Got touch event.");
            return false;
        }
    });

    return root;
}
 
Example 11
Source File: GiraffePlayer.java    From GiraffePlayer2 with Apache License 2.0 4 votes vote down vote up
private ViewGroup createFloatBox() {
        removeFloatContainer();
        Activity topActivity = PlayerManager.getInstance().getTopActivity();
        ViewGroup topActivityBox = (ViewGroup) topActivity.findViewById(android.R.id.content);
        ViewGroup floatBox = (ViewGroup) LayoutInflater.from(topActivity.getApplication()).inflate(R.layout.giraffe_float_box, null);
        floatBox.setBackgroundColor(videoInfo.getBgColor());

        FrameLayout.LayoutParams floatBoxParams = new FrameLayout.LayoutParams(VideoInfo.floatView_width, VideoInfo.floatView_height);
        if (VideoInfo.floatView_x == Integer.MAX_VALUE || VideoInfo.floatView_y == Integer.MAX_VALUE) {
            floatBoxParams.gravity = Gravity.BOTTOM | Gravity.END;
            floatBoxParams.bottomMargin = 20;
            floatBoxParams.rightMargin = 20;
        } else {
            floatBoxParams.gravity = Gravity.TOP | Gravity.START;
            floatBoxParams.leftMargin = (int) VideoInfo.floatView_x;
            floatBoxParams.topMargin = (int) VideoInfo.floatView_y;
        }
        topActivityBox.addView(floatBox, floatBoxParams);

        floatBox.setOnTouchListener(new View.OnTouchListener() {
            float ry;
            float oy;

            float rx;
            float ox;

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // 获取相对屏幕的坐标,即以屏幕左上角为原点
//                System.out.println("MotionEvent:action:"+event.getAction()+",raw:["+event.getRawX()+","+event.getRawY()+"],xy["+event.getX()+","+event.getY()+"]");

                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        ry = event.getRawY();
                        oy = v.getTranslationY();

                        rx = event.getRawX();
                        ox = v.getTranslationX();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        float y = oy + event.getRawY() - ry;
                        if (y > 0) {
//                            y = 0;
                        }
                        v.setTranslationY(y);

                        float x = ox + event.getRawX() - rx;
                        if (x > 0) {
//                            x = 0;
                        }
                        v.setTranslationX(x);
                        break;
                }
                return true;
            }
        });
        return floatBox;
    }
 
Example 12
Source File: WPVolumePanel.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@Override public void onCreate() {
    super.onCreate();
    Context context = getContext();

    transition = TransitionCompat.get();

    // Get all relevant layouts/ views.
    LayoutInflater inflater = LayoutInflater.from(context);
    root = (ViewGroup) inflater.inflate(R.layout.wp_volume_adjust, null);
    musicPanel = (ViewGroup) root.findViewById(R.id.music_panel);
    trackInfo = (ViewGroup) musicPanel.findViewById(R.id.track_info);
    musicPanel.setVisibility(View.VISIBLE);
    playPause = (ImageButton) musicPanel.findViewById(R.id.media_play_pause);
    mBtnNext = (ImageButton) musicPanel.findViewById(R.id.media_next);
    mBtnPrev = (ImageButton) musicPanel.findViewById(R.id.media_previous);
    volText = (TextView) root.findViewById(R.id.volume_text);
    streamText = (TextView) root.findViewById(R.id.streamName);
    icon = (ImageView) root.findViewById(R.id.stream_icon);
    ringerText = (TextView) root.findViewById(R.id.ringer_mode);
    artist = ((TextView) trackInfo.findViewById(R.id.track_artist));
    title  = ((TextView) trackInfo.findViewById(R.id.track_song));

    // Launch the music app when the track information is clicked.
    trackInfo.setOnTouchListener(new OnTouchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hide();
            launchMusicApp();
        }
    }));

    // Handle toggling the vibrate/ ringer mode when clicked.
    icon.setOnTouchListener(new OnTouchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleRinger();
            onUserInteraction();
        }
    }));

    // Set Segoe UI as the default font for all text.
    Typeface segoe = Typeface.createFromAsset(context.getAssets(), "fonts/Segoe-Regular.ttf");
    Typeface segoeBold = Typeface.createFromAsset(context.getAssets(), "fonts/Segoe-Bold.ttf");
    volText.setTypeface(segoe);
    ringerText.setTypeface(segoe);
    streamText.setTypeface(segoe);
    artist.setTypeface(segoe);
    title.setTypeface(segoeBold);
    volText.setPaintFlags(volText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    artist.setPaintFlags(artist.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    title.setPaintFlags(title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    streamText.setPaintFlags(streamText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    ringerText.setPaintFlags(ringerText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);

    attachPlaybackListeners(musicPanel, new MediaButtonClickListener());
    onRingerModeChange(mRingerMode);

    mLayout = root;
}
 
Example 13
Source File: WPVolumePanel.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@Override public void onCreate() {
    super.onCreate();
    Context context = getContext();

    transition = TransitionCompat.get();

    // Get all relevant layouts/ views.
    LayoutInflater inflater = LayoutInflater.from(context);
    root = (ViewGroup) inflater.inflate(R.layout.wp_volume_adjust, null);
    musicPanel = (ViewGroup) root.findViewById(R.id.music_panel);
    trackInfo = (ViewGroup) musicPanel.findViewById(R.id.track_info);
    musicPanel.setVisibility(View.VISIBLE);
    playPause = (ImageButton) musicPanel.findViewById(R.id.media_play_pause);
    mBtnNext = (ImageButton) musicPanel.findViewById(R.id.media_next);
    mBtnPrev = (ImageButton) musicPanel.findViewById(R.id.media_previous);
    volText = (TextView) root.findViewById(R.id.volume_text);
    streamText = (TextView) root.findViewById(R.id.streamName);
    icon = (ImageView) root.findViewById(R.id.stream_icon);
    ringerText = (TextView) root.findViewById(R.id.ringer_mode);
    artist = ((TextView) trackInfo.findViewById(R.id.track_artist));
    title  = ((TextView) trackInfo.findViewById(R.id.track_song));

    // Launch the music app when the track information is clicked.
    trackInfo.setOnTouchListener(new OnTouchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hide();
            launchMusicApp();
        }
    }));

    // Handle toggling the vibrate/ ringer mode when clicked.
    icon.setOnTouchListener(new OnTouchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleRinger();
            onUserInteraction();
        }
    }));

    // Set Segoe UI as the default font for all text.
    Typeface segoe = Typeface.createFromAsset(context.getAssets(), "fonts/Segoe-Regular.ttf");
    Typeface segoeBold = Typeface.createFromAsset(context.getAssets(), "fonts/Segoe-Bold.ttf");
    volText.setTypeface(segoe);
    ringerText.setTypeface(segoe);
    streamText.setTypeface(segoe);
    artist.setTypeface(segoe);
    title.setTypeface(segoeBold);
    volText.setPaintFlags(volText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    artist.setPaintFlags(artist.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    title.setPaintFlags(title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    streamText.setPaintFlags(streamText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    ringerText.setPaintFlags(ringerText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);

    attachPlaybackListeners(musicPanel, new MediaButtonClickListener());
    onRingerModeChange(mRingerMode);

    mLayout = root;
}