Search in sources :

Example 76 with KeyEvent

use of android.view.KeyEvent in project NewPipe by TeamNewPipe.

the class PlayVideoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_video);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    //set background arrow style
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
    isLandscape = checkIfLandscape();
    hasSoftKeys = checkIfHasSoftKeys();
    actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    if (mediaController == null) {
        //prevents back button hiding media controller controls (after showing them)
        //instead of exiting video
        //see http://stackoverflow.com/questions/6051825
        //also solves https://github.com/theScrabi/NewPipe/issues/99
        mediaController = new MediaController(this) {

            @Override
            public boolean dispatchKeyEvent(KeyEvent event) {
                int keyCode = event.getKeyCode();
                final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    if (uniqueDown) {
                        if (isShowing()) {
                            finish();
                        } else {
                            hide();
                        }
                    }
                    return true;
                }
                return super.dispatchKeyEvent(event);
            }
        };
    }
    //convert from seconds to milliseconds
    position = intent.getIntExtra(START_POSITION, 0) * 1000;
    videoView = (VideoView) findViewById(R.id.video_view);
    progressBar = (ProgressBar) findViewById(R.id.play_video_progress_bar);
    try {
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(Uri.parse(intent.getStringExtra(STREAM_URL)));
    } catch (Exception e) {
        e.printStackTrace();
    }
    videoView.requestFocus();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            progressBar.setVisibility(View.GONE);
            videoView.seekTo(position);
            if (position <= 0) {
                videoView.start();
                showUi();
            } else {
                videoView.pause();
            }
        }
    });
    videoUrl = intent.getStringExtra(VIDEO_URL);
    Button button = (Button) findViewById(R.id.content_button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uiIsHidden) {
                showUi();
            } else {
                hideUi();
            }
        }
    });
    decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if (visibility == View.VISIBLE && uiIsHidden) {
                showUi();
            }
        }
    });
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }
    prefs = getPreferences(Context.MODE_PRIVATE);
    if (prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) {
        toggleOrientation();
    }
}
Also used : KeyEvent(android.view.KeyEvent) MediaController(android.widget.MediaController) Button(android.widget.Button) Intent(android.content.Intent) View(android.view.View) VideoView(android.widget.VideoView) MediaPlayer(android.media.MediaPlayer)

Example 77 with KeyEvent

use of android.view.KeyEvent in project GT by Tencent.

the class GTLogSearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gt_log_search_activity);
    handler = new Handler();
    tv_count = (TextView) findViewById(R.id.log_search_count);
    btn_pre = (ImageButton) findViewById(R.id.log_msg_pre);
    btn_next = (ImageButton) findViewById(R.id.log_msg_next);
    /*
		 * 用于覆盖整个屏幕的透明ImageView,
		 * 主要帮助点击非filterListView区域使filterListView消失
		 */
    img_empty = (ImageView) findViewById(R.id.log_search_view_empty);
    img_empty.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    img_empty.setVisibility(View.GONE);
                    filterListView.setVisibility(View.GONE);
                    cancelFilterMsgInput(v);
                    break;
                case MotionEvent.ACTION_UP:
                    v.performClick();
                    break;
                default:
                    break;
            }
            return false;
        }
    });
    // 过滤数据展示列表
    filterListView = (ListView) findViewById(R.id.log_search_spinner_list);
    //		filterLock = new ReentrantLock();
    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);
            String sCurSelectedMsg = (String) parent.getAdapter().getItem(position);
            LinkedList<String> curShowDownMsgList = GTLogInternal.getCurShowDownMsgList();
            LinkedList<String> msgHistory = GTLogInternal.getCurSearchMsgHistory();
            GTLogInternal.setCurSearchMsg(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);
            //				filterLock.lock();
            ((MsgAdaptor) filterListView.getAdapter()).getFilter().filter(sCurSelectedMsg);
            //				filterLock.unlock();
            doSearch(sCurSelectedMsg);
        }
    });
    // 过滤文本
    et_Msg = (EditText) findViewById(R.id.log_search_msg);
    //		et_Msg.setText(BHLog.getCurSearchMsg());
    et_Msg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!msgWatched) {
                et_Msg.addTextChangedListener(msg_watcher);
                msgWatched = true;
            }
            MsgAdaptor adapter = new MsgAdaptor(GTLogSearchActivity.this);
            adapter.getFilter().filter(et_Msg.getText().toString());
            //				filterLock.lock();
            filterListView.setAdapter(adapter);
            //				filterLock.unlock();
            if (!filterListView.getAdapter().isEmpty()) {
                filterListView.setVisibility(View.VISIBLE);
                img_empty.setVisibility(View.VISIBLE);
            }
        }
    });
    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();
                    filterListView.setVisibility(View.GONE);
                    img_empty.setVisibility(View.GONE);
                    cancelFilterMsgInput(v);
                    if (word.trim().length() == 0) {
                        return true;
                    }
                    LinkedList<String> curShowDownMsgList = GTLogInternal.getCurShowDownMsgList();
                    LinkedList<String> msgHistory = GTLogInternal.getCurSearchMsgHistory();
                    msgHistory.remove(word);
                    msgHistory.addFirst(word);
                    curShowDownMsgList.remove(word);
                    curShowDownMsgList.addFirst(word);
                    doSearch(word);
                    return true;
            }
            return false;
        }
    });
    // 过滤文本的清理
    btn_msg_clear = (ImageButton) findViewById(R.id.log_msg_search_clear);
    btn_msg_clear.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            et_Msg.setText("");
            // 清理本次搜索标记
            GTLogInternal.clearLastSearchMarks();
            tv_count.setText("0 / 0");
            arrayAdapter.notifyDataSetChanged();
            btn_msg_clear.setVisibility(View.GONE);
        }
    });
    // 改成back功能了
    btn_back = (Button) findViewById(R.id.log_msg_search_cancel);
    btn_back.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // 20130404 改成back功能了
            finish();
        }
    });
    btn_pre.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int historySeq = GTLogInternal.getLastMatchedSeq();
            if (historySeq > 0) {
                GTLogInternal.setLastMatchedSeq(historySeq - 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(historySeq - 1).posionInDataSet);
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                historySeq + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            } else if (historySeq == 0 && GTLogInternal.getLastMatchedEntryList().size() > 0) {
                GTLogInternal.setLastMatchedSeq(GTLogInternal.getLastMatchedEntryList().size() - 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(GTLogInternal.getLastMatchedEntryList().size() - 1).posionInDataSet);
                tv_count.setText(GTLogInternal.getLastMatchedEntryList().size() + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            }
        }
    });
    btn_next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int historySeq = GTLogInternal.getLastMatchedSeq();
            if (historySeq < GTLogInternal.getLastMatchedEntryList().size() - 1) {
                GTLogInternal.setLastMatchedSeq(historySeq + 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(historySeq + 1).posionInDataSet);
                int viewSeq = historySeq + 2;
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                viewSeq + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            } else if (historySeq == GTLogInternal.getLastMatchedEntryList().size() - 1) {
                GTLogInternal.setLastMatchedSeq(0);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(0).posionInDataSet);
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                1 + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            }
        }
    });
    // 准备日志列表数据
    listView = (ListView) findViewById(R.id.log_search_list);
    Intent intent = getIntent();
    String openFileName = intent.getStringExtra("openFileName");
    if (openFileName == null) {
        // 日志列表
        dataSet = GTLogInternal.getCurFilteredLogs();
        arrayAdapter = new SearchLogAdapter(this, dataSet);
        listView.setAdapter(arrayAdapter);
    } else // 打开历史日志
    {
        openLog(openFileName);
    }
}
Also used : SearchLogAdapter(com.tencent.wstt.gt.log.SearchLogAdapter) OnTouchListener(android.view.View.OnTouchListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) LinkedList(java.util.LinkedList) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener)

Example 78 with KeyEvent

use of android.view.KeyEvent in project GT by Tencent.

the class GTCaptureActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pi_capture);
    initLayout();
    tv_tcpdump_back = (TextView) findViewById(R.id.tcpdump_back_gt);
    tv_tcpdump_back.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    tv_tcpdump_curFile.setText(curFilePath == null ? "" : curFilePath);
    tv_tcpdump_progress.setText(curFileSize == null ? "" : curFileSize + "KB");
    tv_param_switch = (TextView) findViewById(R.id.tcpdump_param_switch);
    tv_param_switch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!switch_param) {
                switch_param = true;
                tv_param_title.setVisibility(View.VISIBLE);
                fl_param.setVisibility(View.VISIBLE);
            } else {
                switch_param = false;
                et_param.setText(param);
                tv_param_title.setVisibility(View.GONE);
                fl_param.setVisibility(View.GONE);
            }
        }
    });
    btn_param_clear = (Button) findViewById(R.id.tcpdump_param_cancel);
    btn_param_clear.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            param = "";
            et_param.setText(param);
        }
    });
    et_param = (EditText) findViewById(R.id.tcpdump_param);
    et_param.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            return (event.getKeyCode() == KeyEvent.KEYCODE_ENTER);
        }
    });
    tv_switch = (TextView) findViewById(R.id.tcpdump_switch);
    tv_switch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // 获取权限过程比较耗时,交给菊花去处理
            Thread t = new Thread(new ProgressRunnable());
            t.start();
        }
    });
    cb_param_switch = (GTCheckBox) findViewById(R.id.cb_param_switch);
    cb_param_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                cur_param_switch_status = isChecked;
                tv_param_title.setVisibility(View.VISIBLE);
                fl_param.setVisibility(View.VISIBLE);
                String cur_param = et_param.getText().toString();
                if (cur_param.equals("") || cur_param.trim().equals("")) {
                    et_param.setText(default_param);
                }
            } else {
                cur_param_switch_status = isChecked;
                tv_param_title.setVisibility(View.GONE);
                fl_param.setVisibility(View.GONE);
            }
        }
    });
    tcpdumpSwitchHandler = new Handler() {

        public void handleMessage(Message msg) {
            switch(msg.what) {
                case // 启动抓包开始,控件状态置为红色,显示stop
                0:
                    switch_tcpdump = true;
                    tv_switch.setBackgroundResource(R.drawable.switch_off_border);
                    tv_switch.setText(getString(R.string.stop));
                    break;
                case // 抓包结束,控件状态置为绿色,显示start
                1:
                    switch_tcpdump = false;
                    tv_switch.setBackgroundResource(R.drawable.switch_on_border);
                    tv_switch.setText(getString(R.string.start));
                    break;
                case // 吐槽提示
                2:
                    String message = msg.obj == null ? "" : msg.obj.toString();
                    WidgetUtils.openToast(message);
                    // 有菊花则停止菊花
                    dismissProDialog();
                    break;
                case // 抓包文件发生大小变化时
                3:
                    curFileSize = msg.obj == null ? "" : msg.obj.toString();
                    tv_tcpdump_progress.setText(curFileSize + "KB");
                    break;
                case // 启动抓包完成,显示当前保存的抓包文件  TODO
                4:
                    curFilePath = msg.obj == null ? "" : msg.obj.toString();
                    tv_tcpdump_curFile.setText(curFilePath == null ? "" : curFilePath);
                    // 停止菊花
                    dismissProDialog();
                    break;
                case // 抓包之前的校验,转菊花
                5:
                    showProDialog();
                    break;
            }
        }
    };
    GTCaptureEngine.getInstance().addListener(this);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 79 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class MediaKeyEventButton method sendMediaKeyEvent.

protected void sendMediaKeyEvent(Context context, int code) {
    long eventtime = SystemClock.uptimeMillis();
    KeyEvent key = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
    dispatchMediaKeyWithWakeLockToAudioService(key);
    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction(key, KeyEvent.ACTION_UP));
}
Also used : KeyEvent(android.view.KeyEvent)

Example 80 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class PhoneFallbackEventHandler method onKeyDown.

boolean onKeyDown(int keyCode, KeyEvent event) {
    /* ****************************************************************************
         * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES.
         * See the comment in PhoneWindow.onKeyDown
         * ****************************************************************************/
    final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
    switch(keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            {
                getAudioManager().handleKeyDown(event, AudioManager.USE_DEFAULT_STREAM_TYPE);
                return true;
            }
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            /* Suppress PLAY/PAUSE toggle when phone is ringing or in-call
                 * to avoid music playback */
            if (getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                // suppress key event
                return true;
            }
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            {
                handleMediaKeyEvent(event);
                return true;
            }
        case KeyEvent.KEYCODE_CALL:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    // launch the VoiceDialer
                    Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        sendCloseSystemWindows();
                        mContext.startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        startCallActivity();
                    }
                }
                return true;
            }
        case KeyEvent.KEYCODE_CAMERA:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    sendCloseSystemWindows();
                    // Broadcast an intent that the Camera button was longpressed
                    Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
                    intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
                    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF, null, null, null, 0, null, null);
                }
                return true;
            }
        case KeyEvent.KEYCODE_SEARCH:
            {
                if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
                    break;
                }
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    Configuration config = mContext.getResources().getConfiguration();
                    if (config.keyboard == Configuration.KEYBOARD_NOKEYS || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
                        // launch the search activity
                        Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        try {
                            mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                            sendCloseSystemWindows();
                            getSearchManager().stopSearch();
                            mContext.startActivity(intent);
                            // Only clear this if we successfully start the
                            // activity; otherwise we will allow the normal short
                            // press action to be performed.
                            dispatcher.performedLongPress(event);
                            return true;
                        } catch (ActivityNotFoundException e) {
                        // Ignore
                        }
                    }
                }
                break;
            }
    }
    return false;
}
Also used : KeyEvent(android.view.KeyEvent) Configuration(android.content.res.Configuration) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Aggregations

KeyEvent (android.view.KeyEvent)513 View (android.view.View)145 TextView (android.widget.TextView)109 Intent (android.content.Intent)53 ImageView (android.widget.ImageView)38 DialogInterface (android.content.DialogInterface)36 EditText (android.widget.EditText)36 KeyCharacterMap (android.view.KeyCharacterMap)35 Editable (android.text.Editable)34 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Instrumentation (android.app.Instrumentation)30 OnClickListener (android.view.View.OnClickListener)30 Paint (android.graphics.Paint)27 Button (android.widget.Button)27 TextWatcher (android.text.TextWatcher)24 InputMethodManager (android.view.inputmethod.InputMethodManager)22 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 LayoutInflater (android.view.LayoutInflater)21 Test (org.junit.Test)20