android.view.ViewGroup#setOnTouchListener ( )源码实例Demo

下面列出了android.view.ViewGroup#setOnTouchListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PLDroidShortVideo   文件: VideoDivideActivity.java
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());
}
 
@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;
}
 
@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;
}
 
源代码4 项目: MxVideoPlayer   文件: MxVideoPlayer.java
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();
}
 
源代码5 项目: YiBo   文件: Skeleton.java
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());
}
 
源代码6 项目: SwipeLayout   文件: SwipeLayout.java
/**
 * 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;
        }
    });
}
 
源代码7 项目: photo-viewer   文件: ImageViewerView.java
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;
        }
    });
}
 
源代码8 项目: DistroHopper   文件: WidgetContainer.java
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));
}
 
源代码9 项目: FastWaiMai   文件: DatePickerDialog.java
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;
        }
    }
 
@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;
}
 
源代码11 项目: GiraffePlayer2   文件: GiraffePlayer.java
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;
    }
 
源代码12 项目: Noyze   文件: WPVolumePanel.java
@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;
}
 
源代码13 项目: Noyze   文件: WPVolumePanel.java
@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;
}
 
 方法所在类