Search in sources :

Example 96 with Handler

use of android.os.Handler in project NewPipe by TeamNewPipe.

the class PlayVideoActivity method showUi.

private void showUi() {
    try {
        uiIsHidden = false;
        mediaController.show(100000);
        actionBar.show();
        adjustMediaControlMetrics();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                if ((System.currentTimeMillis() - lastUiShowTime) >= HIDING_DELAY) {
                    hideUi();
                }
            }
        }, HIDING_DELAY);
        lastUiShowTime = System.currentTimeMillis();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Handler(android.os.Handler)

Example 97 with Handler

use of android.os.Handler in project GT by Tencent.

the class GTUncaughtExceptionHandler method handleException.

private void handleException(Throwable ex) {
    // 先抛出异常到logcat
    ex.printStackTrace();
    // 保存环境
    // 延迟半秒杀进程
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Process.killProcess(Process.myPid());
        }
    }, 500);
//		// 先直接退出虚拟机
//		System.exit(0);
}
Also used : UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Handler(android.os.Handler)

Example 98 with Handler

use of android.os.Handler 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 99 with Handler

use of android.os.Handler 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 100 with Handler

use of android.os.Handler in project tinker by Tencent.

the class SampleResultService method onPatchResult.

@Override
public void onPatchResult(final PatchResult result) {
    if (result == null) {
        TinkerLog.e(TAG, "SampleResultService received null result!!!!");
        return;
    }
    TinkerLog.i(TAG, "SampleResultService receive result: %s", result.toString());
    //first, we want to kill the recover process
    TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        @Override
        public void run() {
            if (result.isSuccess) {
                Toast.makeText(getApplicationContext(), "patch success, please restart process", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(), "patch fail, please check reason", Toast.LENGTH_LONG).show();
            }
        }
    });
    // for old patch, you can't delete the patch file
    if (result.isSuccess) {
        deleteRawPatchFile(new File(result.rawPatchFilePath));
        //if you have not install tinker this moment, you can use TinkerApplicationHelper api
        if (checkIfNeedKill(result)) {
            if (Utils.isBackground()) {
                TinkerLog.i(TAG, "it is in background, just restart process");
                restartProcess();
            } else {
                //we can wait process at background, such as onAppBackground
                //or we can restart when the screen off
                TinkerLog.i(TAG, "tinker wait screen to restart process");
                new ScreenState(getApplicationContext(), new ScreenState.IOnScreenOff() {

                    @Override
                    public void onScreenOff() {
                        restartProcess();
                    }
                });
            }
        } else {
            TinkerLog.i(TAG, "I have already install the newly patch version!");
        }
    }
}
Also used : Handler(android.os.Handler) File(java.io.File)

Aggregations

Handler (android.os.Handler)1843 Message (android.os.Message)253 View (android.view.View)201 Intent (android.content.Intent)165 HandlerThread (android.os.HandlerThread)135 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 TextView (android.widget.TextView)114 ArrayList (java.util.ArrayList)95 Test (org.junit.Test)80 Context (android.content.Context)67 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)61 IntentFilter (android.content.IntentFilter)57 ComponentName (android.content.ComponentName)56 ImageView (android.widget.ImageView)55 RecyclerView (android.support.v7.widget.RecyclerView)52 Bundle (android.os.Bundle)51 Looper (android.os.Looper)51 File (java.io.File)45 HashMap (java.util.HashMap)44