Search in sources :

Example 41 with OnTouchListener

use of android.view.View.OnTouchListener in project android_frameworks_base by DirtyUnicorns.

the class Interaction method register.

public static void register(View v, final Callback callback) {
    v.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
    v.setOnGenericMotionListener(new OnGenericMotionListener() {

        @Override
        public boolean onGenericMotion(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) OnGenericMotionListener(android.view.View.OnGenericMotionListener) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 42 with OnTouchListener

use of android.view.View.OnTouchListener in project android_frameworks_base by ResurrectionRemix.

the class VolumeDialog method initRow.

@SuppressLint("InflateParams")
private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes, boolean important) {
    row.stream = stream;
    row.iconRes = iconRes;
    row.iconMuteRes = iconMuteRes;
    row.important = important;
    row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null);
    row.view.setId(row.stream);
    row.view.setTag(row);
    row.header = (TextView) row.view.findViewById(R.id.volume_row_header);
    row.header.setId(20 * row.stream);
    mSpTexts.add(row.header);
    row.slider = (SeekBar) row.view.findViewById(R.id.volume_row_slider);
    row.slider.setProgressTintMode(PorterDuff.Mode.SRC_ATOP);
    row.slider.setThumbTintMode(PorterDuff.Mode.SRC_ATOP);
    row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row));
    row.anim = null;
    row.cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS;
    // forward events above the slider into the slider
    row.view.setOnTouchListener(new OnTouchListener() {

        private final Rect mSliderHitRect = new Rect();

        private boolean mDragging;

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            row.slider.getHitRect(mSliderHitRect);
            if (!mDragging && event.getActionMasked() == MotionEvent.ACTION_DOWN && event.getY() < mSliderHitRect.top) {
                mDragging = true;
            }
            if (mDragging) {
                event.offsetLocation(-mSliderHitRect.left, -mSliderHitRect.top);
                row.slider.dispatchTouchEvent(event);
                if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
                    mDragging = false;
                }
                return true;
            }
            return false;
        }
    });
    row.icon = (ImageButton) row.view.findViewById(R.id.volume_row_icon);
    row.icon.setImageResource(iconRes);
    row.icon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState);
            mController.setActiveStream(row.stream);
            if (row.stream == AudioManager.STREAM_RING) {
                final boolean hasVibrator = mController.hasVibrator();
                if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) {
                    if (hasVibrator) {
                        mController.setRingerMode(AudioManager.RINGER_MODE_VIBRATE, false);
                    } else {
                        final boolean wasZero = row.ss.level == 0;
                        mController.setStreamVolume(stream, wasZero ? row.lastAudibleLevel : 0);
                    }
                } else {
                    mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false);
                    if (row.ss.level == 0) {
                        mController.setStreamVolume(stream, 1);
                    }
                }
            } else {
                final boolean vmute = row.ss.level == row.ss.levelMin;
                mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : row.ss.levelMin);
            }
            // reset the grace period, slider should update immediately
            row.userAttempt = 0;
        }
    });
}
Also used : Rect(android.graphics.Rect) OnTouchListener(android.view.View.OnTouchListener) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint)

Example 43 with OnTouchListener

use of android.view.View.OnTouchListener in project android_frameworks_base by ResurrectionRemix.

the class Interaction method register.

public static void register(View v, final Callback callback) {
    v.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
    v.setOnGenericMotionListener(new OnGenericMotionListener() {

        @Override
        public boolean onGenericMotion(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) OnGenericMotionListener(android.view.View.OnGenericMotionListener) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 44 with OnTouchListener

use of android.view.View.OnTouchListener in project JustAndroid by chinaltz.

the class ChatListActivity method initView.

public void initView() {
    abPullToRefreshView = (AbPullToRefreshView) findViewById(R.id.chat_PullRefreshView);
    navBack = (LinearLayout) findViewById(R.id.nav_back);
    navBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    titleText = (TextView) findViewById(R.id.nav_title);
    titleText.setText("简单的聊天布局");
    listView = (ListView) findViewById(R.id.chat_listView);
    mAdapter = new ChatAdapter(mContext);
    listView.setAdapter(mAdapter);
    listView.setItemsCanFocus(true);
    contentEt = (EditText) findViewById(R.id.tv_send_content);
    sendBtn = (Button) findViewById(R.id.sendBtn);
    addBtn = (ImageButton) findViewById(R.id.addBtn);
    voiceBtn = (ImageButton) findViewById(R.id.voiceBtn);
    voiceSendBtn = (Button) findViewById(R.id.voiceSendBtn);
    otherTypeLy = (LinearLayout) findViewById(R.id.chatAppPanel);
    sendPic = (ImageView) findViewById(R.id.send_picture);
    sendVedio = (ImageView) findViewById(R.id.send_vedio);
    sendCameraPic = (ImageView) findViewById(R.id.send_camera);
    // 添加不同的消息类型
    addBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (otherTypeLy.getVisibility() == View.VISIBLE) {
                otherTypeLy.setVisibility(View.GONE);
            } else {
                InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
                mInputMethodManager.hideSoftInputFromWindow(contentEt.getWindowToken(), 0);
                otherTypeLy.setVisibility(View.VISIBLE);
            }
        }
    });
    voiceSendBtn.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case // 按下
                MotionEvent.ACTION_DOWN:
                    voiceSendBtn.setText("松开取消");
                    break;
                case // 抬起
                MotionEvent.ACTION_UP:
                    voiceSendBtn.setText("按住说话");
                    break;
                default:
                    break;
            }
            return false;
        }
    });
    voiceBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (contentEt.getVisibility() == View.GONE) {
                contentEt.setVisibility(View.VISIBLE);
                voiceSendBtn.setVisibility(View.GONE);
                isHide = false;
                voiceBtn.setBackgroundResource(R.drawable.button_selector_chat_voice);
                if (!isHide) {
                    InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
                    mInputMethodManager.hideSoftInputFromWindow(contentEt.getWindowToken(), 0);
                    isHide = true;
                }
            } else {
                contentEt.setVisibility(View.GONE);
                voiceSendBtn.setVisibility(View.VISIBLE);
                voiceBtn.setBackgroundResource(R.drawable.button_selector_chat_key);
                InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
                mInputMethodManager.hideSoftInputFromWindow(contentEt.getWindowToken(), 0);
                isHide = true;
            }
            otherTypeLy.setVisibility(View.GONE);
        }
    });
    // 切换发送和添加按钮
    contentEt.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String str = contentEt.getText().toString().trim();
            int length = str.length();
            if (length > 0) {
                sendBtn.setVisibility(View.VISIBLE);
                addBtn.setVisibility(View.GONE);
            } else {
                sendBtn.setVisibility(View.GONE);
                addBtn.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    sendBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    // 拍照
    sendCameraPic.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        // 选择本地图片
        }
    });
    sendPic.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    sendVedio.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) OnClickListener(android.view.View.OnClickListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) ChatAdapter(com.litingzhe.justandroid.ui.listandGridView.adapter.ChatAdapter) ImageView(android.widget.ImageView) View(android.view.View) AbPullToRefreshView(com.ningcui.mylibrary.viewLib.refresh.AbPullToRefreshView) TextView(android.widget.TextView) ListView(android.widget.ListView) 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