Search in sources :

Example 6 with OnTouchListener

use of android.view.View.OnTouchListener in project GT by Tencent.

the class GTFloatView method createView.

private void createView() {
    wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    wmParams = new WindowManager.LayoutParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | 8;
    // 调整悬浮窗口至左上角
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    try {
        wm.addView(view_floatview, wmParams);
    } catch (Exception e) {
        /*
			 * 有的Android6会报permission denied for this window type问题
			 * https://github.com/intercom/intercom-android/issues/116
			 * 在这种系统上直接屏蔽悬浮窗
			 */
        stopSelf();
        return;
    }
    final int sbar_height = DeviceUtils.getStatusBarHeight(getApplicationContext());
    view_floatview.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - sbar_height;
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    move_event = false;
                    up_event = false;
                    state = MotionEvent.ACTION_DOWN;
                    StartX = x;
                    StartY = y;
                    mTouchStartX = event.getX();
                    mTouchStartY = event.getY();
                    touchX = mTouchStartX;
                    touchY = mTouchStartY;
                    ProX = event.getRawX();
                    ProY = event.getRawY();
                    clickHandler.sendEmptyMessage(0);
                    break;
                case MotionEvent.ACTION_MOVE:
                    state = MotionEvent.ACTION_MOVE;
                    moveX = event.getRawX();
                    moveY = event.getRawY();
                    final ViewConfiguration configuration = ViewConfiguration.get(getApplicationContext());
                    int mTouchSlop = configuration.getScaledTouchSlop();
                    // 第一次move
                    if (move_oldX == -1000 && move_oldY == -1000) {
                        move_oldX = moveX;
                        move_oldY = moveY;
                        if (Math.abs(moveX - ProX) < mTouchSlop * 2 && Math.abs(moveY - ProY) < mTouchSlop * 2) {
                            move_event = false;
                        } else {
                            move_event = true;
                            updateViewPosition();
                        }
                    } else {
                        if (move_event == false) {
                            if (Math.abs(moveX - move_oldX) < mTouchSlop * 2 && Math.abs(moveY - move_oldY) < mTouchSlop * 2) {
                                move_event = false;
                            } else {
                                move_event = true;
                                updateViewPosition();
                            }
                        } else {
                            updateViewPosition();
                        }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    state = MotionEvent.ACTION_UP;
                    updateViewPositionEnd();
                    move_oldX = -1000;
                    move_oldY = -1000;
                    mTouchStartX = mTouchStartY = 0;
                    up_event = true;
                    clickHandler.sendEmptyMessage(1);
                    break;
            }
            return true;
        }
    });
}
Also used : ViewConfiguration(android.view.ViewConfiguration) OnTouchListener(android.view.View.OnTouchListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WindowManager(android.view.WindowManager) MotionEvent(android.view.MotionEvent)

Example 7 with OnTouchListener

use of android.view.View.OnTouchListener in project GT by Tencent.

the class GTFloatView method initInParamLayout.

private void initInParamLayout() {
    // 初始化出参布局
    tv_floatview_ip1 = (TextView) view_floatview.findViewById(R.id.floatview_ip1);
    tv_floatview_ip1_value = (TextView) view_floatview.findViewById(R.id.floatview_ip1_value);
    tv_floatview_ip2 = (TextView) view_floatview.findViewById(R.id.floatview_ip2);
    tv_floatview_ip2_value = (TextView) view_floatview.findViewById(R.id.floatview_ip2_value);
    tv_floatview_ip3 = (TextView) view_floatview.findViewById(R.id.floatview_ip3);
    tv_floatview_ip3_value = (TextView) view_floatview.findViewById(R.id.floatview_ip3_value);
    // 初始化相应点击事件的view
    // 设置点击事件
    tv_floatview_ip1.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(0);
                    break;
            }
            return false;
        }
    });
    tv_floatview_ip1_value.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(0);
                    break;
            }
            return false;
        }
    });
    tv_floatview_ip2.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(1);
                    break;
            }
            return false;
        }
    });
    tv_floatview_ip2_value.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(1);
                    break;
            }
            return false;
        }
    });
    tv_floatview_ip3.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(2);
                    break;
            }
            return false;
        }
    });
    tv_floatview_ip3_value.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    tv_floatview_ip_clickHandler.sendEmptyMessage(2);
                    break;
            }
            return false;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent)

Example 8 with OnTouchListener

use of android.view.View.OnTouchListener in project Fairphone by Kwamecorp.

the class OOBEActivity method setupTheVideo.

private void setupTheVideo() {
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.oobeVideoViewGroup);
    rl.setVisibility(View.VISIBLE);
    mVideo = (VideoView) findViewById(R.id.fp_oobe_video);
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fp_buy_a_phone_start_a_movement);
    mVideo.setMediaController(null);
    mVideo.requestFocus();
    mVideo.setVideoURI(uri);
    mVideo.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    mVideo.start();
    mVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            stopIntroVideo();
        }
    });
    // button
    mSkipVideoButton = (Button) findViewById(R.id.fp_oobe_video_skip_button);
    mSkipVideoButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            stopIntroVideo();
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) Uri(android.net.Uri) View(android.view.View) VideoView(android.widget.VideoView) MotionEvent(android.view.MotionEvent) MediaPlayer(android.media.MediaPlayer)

Example 9 with OnTouchListener

use of android.view.View.OnTouchListener in project KJFrameForAndroid by kymjs.

the class Browser method initWidget.

@Override
public void initWidget() {
    super.initWidget();
    initWebView();
    initBarAnim();
    mGestureDetector = new GestureDetector(aty, new MyGestureListener());
    mWebView.loadUrl(mCurrentUrl);
    mWebView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return mGestureDetector.onTouchEvent(event);
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) GestureDetector(android.view.GestureDetector) ImageView(android.widget.ImageView) View(android.view.View) BindView(org.kymjs.kjframe.ui.BindView) WebView(android.webkit.WebView) MotionEvent(android.view.MotionEvent)

Example 10 with OnTouchListener

use of android.view.View.OnTouchListener in project MaterialDesignLibrary by navasmdc.

the class ColorSelector method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.color_selector);
    view = (LinearLayout) findViewById(R.id.contentSelector);
    backView = (RelativeLayout) findViewById(R.id.rootSelector);
    backView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getX() < view.getLeft() || event.getX() > view.getRight() || event.getY() > view.getBottom() || event.getY() < view.getTop()) {
                dismiss();
            }
            return false;
        }
    });
    colorView = findViewById(R.id.viewColor);
    colorView.setBackgroundColor(color);
    // Resize ColorView
    colorView.post(new Runnable() {

        @Override
        public void run() {
            LayoutParams params = (LayoutParams) colorView.getLayoutParams();
            params.height = colorView.getWidth();
            colorView.setLayoutParams(params);
        }
    });
    // Configure Sliders
    red = (Slider) findViewById(R.id.red);
    green = (Slider) findViewById(R.id.green);
    blue = (Slider) findViewById(R.id.blue);
    int r = (this.color >> 16) & 0xFF;
    int g = (this.color >> 8) & 0xFF;
    int b = (this.color >> 0) & 0xFF;
    red.setValue(r);
    green.setValue(g);
    blue.setValue(b);
    red.setOnValueChangedListener(this);
    green.setOnValueChangedListener(this);
    blue.setOnValueChangedListener(this);
}
Also used : OnTouchListener(android.view.View.OnTouchListener) LayoutParams(android.widget.LinearLayout.LayoutParams) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)44 View (android.view.View)44 OnTouchListener (android.view.View.OnTouchListener)44 TextView (android.widget.TextView)28 ImageView (android.widget.ImageView)15 OnClickListener (android.view.View.OnClickListener)14 ListView (android.widget.ListView)8 SuppressLint (android.annotation.SuppressLint)7 AdapterView (android.widget.AdapterView)7 Intent (android.content.Intent)5 Rect (android.graphics.Rect)5 OnGenericMotionListener (android.view.View.OnGenericMotionListener)5 AbsListView (android.widget.AbsListView)5 DialogInterface (android.content.DialogInterface)4 KeyEvent (android.view.KeyEvent)4 RelativeLayout (android.widget.RelativeLayout)4 ScrollView (android.widget.ScrollView)4 Builder (android.app.AlertDialog.Builder)3 WindowManager (android.view.WindowManager)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3