Search in sources :

Example 31 with OnTouchListener

use of android.view.View.OnTouchListener in project platform_frameworks_base by android.

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.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 32 with OnTouchListener

use of android.view.View.OnTouchListener in project umeng-android-sdk-theme by umeng.

the class ConversationActivity method setListViewHeader.

private void setListViewHeader() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    header = (RelativeLayout) inflater.inflate(R.layout.umeng_fb_list_header, replyListView, false);
    replyListView.addHeaderView(header);
    measureView(header);
    headerHeight = header.getMeasuredHeight();
    headerPaddingOriginal = header.getPaddingTop();
    header.setPadding(header.getPaddingLeft(), -headerHeight, header.getPaddingRight(), header.getPaddingBottom());
    header.setVisibility(View.GONE);
    replyListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // nothing. Do not show the header.
            if (replyListView.getAdapter().getCount() < 2)
                return false;
            switch(event.getAction()) {
                case MotionEvent.ACTION_UP:
                    if (replyListView.getFirstVisiblePosition() == 0) {
                        if ((header.getBottom() >= headerHeight + 20 || header.getTop() > 0)) {
                            header.setVisibility(View.VISIBLE);
                            header.setPadding(header.getPaddingLeft(), headerPaddingOriginal, header.getPaddingRight(), header.getPaddingBottom());
                        } else // if (header.getBottom() < headerHeight + 20 ||
                        // header.getTop() <= 0)
                        {
                            replyListView.setSelection(1);
                            header.setVisibility(View.GONE);
                            header.setPadding(header.getPaddingLeft(), -headerHeight, header.getPaddingRight(), header.getPaddingBottom());
                        }
                    }
                    break;
                case MotionEvent.ACTION_DOWN:
                    mLastMotionY = (int) event.getY();
                    // header.setVisibility(View.VISIBLE);
                    break;
                case MotionEvent.ACTION_MOVE:
                    applyHeaderPadding(event);
                    break;
            }
            return false;
        }

        private void applyHeaderPadding(MotionEvent ev) {
            // getHistorySize has been available since API 1
            int pointerCount = ev.getHistorySize();
            for (int p = 0; p < pointerCount; p++) {
                if (replyListView.getFirstVisiblePosition() == 0) {
                    int historicalY = (int) ev.getHistoricalY(p);
                    // Calculate the padding to apply, we divide by 1.7 to
                    // simulate a more resistant effect during pull.
                    int topPadding = (int) (((historicalY - mLastMotionY) - headerHeight) / 1.7);
                    header.setVisibility(View.VISIBLE);
                    header.setPadding(header.getPaddingLeft(), topPadding, header.getPaddingRight(), header.getPaddingBottom());
                }
            }
        }
    });
    replyListView.setOnScrollListener(new OnScrollListener() {

        private int mScrollState;

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (mScrollState == OnScrollListener.SCROLL_STATE_FLING && firstVisibleItem == 0) {
            // replyListView.setSelection(1);
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            mScrollState = scrollState;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) OnScrollListener(android.widget.AbsListView.OnScrollListener) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent)

Example 33 with OnTouchListener

use of android.view.View.OnTouchListener in project android-app by spark.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log_in);
    mEmailView = Ui.findView(this, R.id.email);
    mPasswordView = Ui.findView(this, R.id.password);
    mEmailView.setText(prefs.getUsername());
    netConnectionHelper = new NetConnectionHelper(this);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });
    accountAction = Ui.findView(this, R.id.sign_up_button);
    accountAction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    // keyboard pops up
    for (View view : list(mEmailView, mPasswordView)) {
        view.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    scrollAccountForm();
                }
                return false;
            }
        });
    }
    TextView noAccountYet = Ui.setTextFromHtml(this, R.id.no_account_yet, R.string.i_dont_have_an_account);
    noAccountYet.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            launchSignUpActivity();
        }
    });
    TextView forgotPassword = Ui.setTextFromHtml(this, R.id.forgot_password, R.string.action_forgot_password);
    forgotPassword.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openUri(R.string.uri_forgot_password);
        }
    });
}
Also used : NetConnectionHelper(io.spark.core.android.util.NetConnectionHelper) KeyEvent(android.view.KeyEvent) OnTouchListener(android.view.View.OnTouchListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent)

Example 34 with OnTouchListener

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

the class GTLogFragment method onCreateView.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View logLayout = inflater.inflate(R.layout.gt_logactivity, container, false);
    displayWidth = DeviceUtils.getDisplayWidth(getActivity());
    rl_log_filter = (RelativeLayout) logLayout.findViewById(R.id.rl_log_filter);
    cb_logcatSwitch = (GTCheckBox) logLayout.findViewById(R.id.cb_logcat_switch);
    cb_logcatSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // TODO logcat的简单实现
                logcatTask = new LogcatRunnable();
                new Thread(logcatTask).start();
            } else {
                logcatTask.killReader();
            }
        }
    });
    btn_delete = (ImageButton) logLayout.findViewById(R.id.gtlog_delete);
    btn_save = (ImageButton) logLayout.findViewById(R.id.gtlog_save);
    btn_open = (ImageButton) logLayout.findViewById(R.id.gtlog_open);
    btn_level_toast = (ImageButton) logLayout.findViewById(R.id.log_level_toast);
    btn_tag_toast = (ImageButton) logLayout.findViewById(R.id.log_tag_toast);
    /*
		 * 用于覆盖整个屏幕的透明ImageView, 主要帮助点击非filterListView区域使filterListView消失
		 */
    img_empty = (ImageView) logLayout.findViewById(R.id.view_empty);
    img_empty.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            img_empty.setVisibility(View.GONE);
            filterListView.setVisibility(View.GONE);
            cancelFilterMsgInput(v);
            return false;
        }
    });
    /*
		 * 保存相关控件
		 */
    RelativeLayout rl_save = (RelativeLayout) LayoutInflater.from(getActivity()).inflate(R.layout.gt_dailog_save, null, false);
    ImageButton btn_cleanSavePath = (ImageButton) rl_save.findViewById(R.id.save_clean);
    btn_cleanSavePath.setOnClickListener(this);
    et_savePath = (EditText) rl_save.findViewById(R.id.save_editor);
    String lastSaveLog = GTLogInternal.getLastSaveLog();
    if (lastSaveLog != null && lastSaveLog.contains(".") && lastSaveLog.endsWith(LogUtils.LOG_POSFIX)) {
        lastSaveLog = lastSaveLog.substring(0, lastSaveLog.lastIndexOf("."));
    }
    et_savePath.setText(lastSaveLog);
    dlg_save = new Builder(getActivity()).setTitle(getString(R.string.save_file)).setView(rl_save).setPositiveButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // 简单过滤保存
            String path = et_savePath.getText().toString();
            try {
                File f = null;
                if (FileUtil.isPathStringValid(path)) {
                    String validPath = FileUtil.convertValidFilePath(path, LogUtils.LOG_POSFIX);
                    if (FileUtil.isPath(validPath)) {
                        f = new File(validPath);
                        f.mkdirs();
                    } else {
                        f = new File(Env.ROOT_LOG_FOLDER, validPath);
                    }
                    GTLogInternal.setLastSaveLog(validPath);
                }
                if (f.exists()) {
                    f.delete();
                }
                LogUtils.writeLog(logAdapter.getUIEntryList(), f, false);
            } catch (Exception e) {
                e.printStackTrace();
            }
            dialog.dismiss();
        }
    }).create();
    btn_save.setOnClickListener(this);
    // 删除按钮
    btn_delete.setOnClickListener(this);
    // 打开日志文件按钮
    btn_open.setOnClickListener(this);
    // 日志列表
    rl_loglist = (RelativeLayout) logLayout.findViewById(R.id.rl_loglist);
    listView = (ListView) logLayout.findViewById(R.id.loglist);
    initCurLogAdapter();
    logAdapter.setFilter();
    listView.setAdapter(logAdapter);
    // 滑动时,把置顶置底button隐藏起来
    listView.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            rl_log_filter.setVisibility(View.GONE);
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (visibleItemCount + firstVisibleItem == totalItemCount) {
                logAdapter.setAutoRefresh(true);
            } else {
                logAdapter.setAutoRefresh(false);
            }
        }
    });
    // 点触时,把置顶置底button呼唤出来
    rl_loglist.setOnClickListener(this);
    listView.setOnTouchListener(logListTouchListener);
    // 过滤数据展示列表
    filterListView = (ListView) logLayout.findViewById(R.id.spinner_list);
    tagAdapter = new ArrayAdapter<String>(getActivity(), R.layout.gt_simple_dropdown_item);
    filterListView.setAdapter(tagAdapter);
    filterListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long arg3) {
            img_empty.setVisibility(View.GONE);
            filterListView.setVisibility(View.GONE);
            if (parent.getAdapter() == tagAdapter) {
                if (position == 0)
                    GTLogInternal.setCurFilterTag("");
                else
                    GTLogInternal.setCurFilterTag((String) parent.getAdapter().getItem(position));
                btn_tag.setText(tagAdapter.getItem(position));
            } else if (parent.getAdapter() instanceof MsgAdaptor) {
                String sCurSelectedMsg = (String) parent.getAdapter().getItem(position);
                LinkedList<String> curShowDownMsgList = GTLogInternal.getCurFilterShowDownMsgList();
                LinkedList<String> msgHistory = GTLogInternal.getCurFilterMsgHistory();
                GTLogInternal.setCurFilterMsg(sCurSelectedMsg);
                msgWatched = false;
                et_Msg.removeTextChangedListener(msg_watcher);
                String s = curShowDownMsgList.remove(position);
                curShowDownMsgList.addFirst(s);
                msgHistory.remove(s);
                msgHistory.addFirst(s);
                et_Msg.setText(sCurSelectedMsg);
                btn_msg_clear.setVisibility(View.VISIBLE);
                cancelFilterMsgInput(parent);
            } else {
                GTLogInternal.setCurFilterLevel(position);
                btn_level.setText(levelAdapter.getItem(position));
            }
            onLogChanged();
        }
    });
    // 将本Activity作为日志数据源的监听
    GTLogInternal.addLogListener(this);
    // 搜索按钮
    //btn_search = (ImageButton) findViewById(R.id.log_search);
    btn_search = (ImageButton) logLayout.findViewById(R.id.gtlog_search);
    btn_search.setOnClickListener(this);
    // 过滤级别
    btn_level = (Button) logLayout.findViewById(R.id.log_level);
    levelAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.log_level, R.layout.gt_simple_dropdown_item);
    btn_level.setText(levelAdapter.getItem(GTLogInternal.getCurFilterLevel()));
    btn_level.setOnClickListener(this);
    // 过滤TAG
    btn_tag = (Button) logLayout.findViewById(R.id.log_tag);
    if (GTLogInternal.getCurFilterTag().length() == 0) {
        btn_tag.setText("TAG");
    } else {
        btn_tag.setText(GTLogInternal.getCurFilterTag());
    }
    btn_tag.setOnClickListener(this);
    // 过滤文本
    et_Msg = (EditText) logLayout.findViewById(R.id.log_msg);
    et_Msg.setText(GTLogInternal.getCurFilterMsg());
    et_Msg.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (// 因为日志空时,edit会自动获取焦点
            hasFocus && !logAdapter.isEmpty()) {
                msgEtOnFocusOrClick();
            }
        }
    });
    et_Msg.setOnClickListener(this);
    et_Msg.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            switch(keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    // 要先把过滤showdown去掉,否则会多弹出一次
                    msgWatched = false;
                    et_Msg.removeTextChangedListener(msg_watcher);
                    String word = et_Msg.getText().toString();
                    if (!word.equals("")) {
                        LinkedList<String> curShowDownMsgList = GTLogInternal.getCurFilterShowDownMsgList();
                        LinkedList<String> msgHistory = GTLogInternal.getCurFilterMsgHistory();
                        msgHistory.remove(word);
                        msgHistory.addFirst(word);
                        curShowDownMsgList.remove(word);
                        curShowDownMsgList.addFirst(word);
                    }
                    filterListView.setVisibility(View.GONE);
                    img_empty.setVisibility(View.GONE);
                    cancelFilterMsgInput(v);
                    return true;
            }
            return false;
        }
    });
    // 过滤文本的清理
    btn_msg_clear = (ImageButton) logLayout.findViewById(R.id.log_msg_clear);
    btn_msg_clear.setOnClickListener(this);
    if (et_Msg.getText().toString().length() > 0) {
        btn_msg_clear.setVisibility(View.VISIBLE);
    } else {
        btn_msg_clear.setVisibility(View.GONE);
    }
    // 过滤文本输入的取消
    btn_msg_input_cancel = (Button) logLayout.findViewById(R.id.log_msg_cancel);
    btn_msg_input_cancel.setOnClickListener(this);
    handler = new Handler();
    return logLayout;
}
Also used : OnFocusChangeListener(android.view.View.OnFocusChangeListener) OnTouchListener(android.view.View.OnTouchListener) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) OnScrollListener(android.widget.AbsListView.OnScrollListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) AbsListView(android.widget.AbsListView) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) LinkedList(java.util.LinkedList) MotionEvent(android.view.MotionEvent) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Example 35 with OnTouchListener

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

the class GTMemHelperFloatview method createView.

private void createView() {
    wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    wmParams = new WindowManager.LayoutParams();
    wmParams.type = 2002;
    wmParams.flags |= 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(net_switch_view, wmParams);
    } catch (Exception e) {
        /*
			 * 有的Android6会报permission denied for this window type问题
			 * https://github.com/intercom/intercom-android/issues/116
			 * 在这种系统上直接屏蔽悬浮窗
			 */
        stopSelf();
        return;
    }
    net_switch_view.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // 获取相对屏幕的坐标,即以屏幕左上角为原点
            x = event.getRawX();
            if (SCREEN_VERTICAL == checkScreenOrientation()) {
                y = event.getRawY() - DeviceUtils.getStatusBarHeight(mContext);
            } else {
                y = event.getRawY();
            }
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    StartX = x;
                    StartY = y;
                    // 获取相对View的坐标,即以此View左上角为原点
                    mTouchStartX = event.getX();
                    mTouchStartY = event.getY();
                    isMoved = false;
                    break;
                case MotionEvent.ACTION_MOVE:
                    updateViewPosition();
                    break;
                case MotionEvent.ACTION_UP:
                    updateViewPosition();
                    mTouchStartX = mTouchStartY = 0;
                    if (!isMoved) {
                        if (isMem) {
                            tv_mem.setBackgroundDrawable(drawSelect);
                            handler.sendEmptyMessage(1);
                            isMem = false;
                        }
                        if (isDump) {
                            tv_dump.setBackgroundDrawable(drawSelect);
                            handler.sendEmptyMessage(2);
                            isDump = false;
                        }
                        if (isGc) {
                            tv_gc.setBackgroundDrawable(drawSelect);
                            handler.sendEmptyMessage(3);
                            isGc = false;
                        }
                        isMoved = false;
                    }
                    break;
            }
            return true;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) View(android.view.View) TextView(android.widget.TextView) WindowManager(android.view.WindowManager) MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)48 View (android.view.View)48 OnTouchListener (android.view.View.OnTouchListener)48 TextView (android.widget.TextView)28 OnClickListener (android.view.View.OnClickListener)16 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)10 AdapterView (android.widget.AdapterView)9 SuppressLint (android.annotation.SuppressLint)7 Intent (android.content.Intent)5 Rect (android.graphics.Rect)5 KeyEvent (android.view.KeyEvent)5 OnGenericMotionListener (android.view.View.OnGenericMotionListener)5 AbsListView (android.widget.AbsListView)5 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)5 DialogInterface (android.content.DialogInterface)4 Editable (android.text.Editable)4 RelativeLayout (android.widget.RelativeLayout)4 ScrollView (android.widget.ScrollView)4 Builder (android.app.AlertDialog.Builder)3