use of android.view.View.OnTouchListener in project SeaStar by 13120241790.
the class RecordDialog method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getContext().setTheme(android.R.style.Theme_InputMethod);
setContentView(R.layout.layout_dialog_record);
Window window = getWindow();
WindowManager.LayoutParams attributesParams = window.getAttributes();
attributesParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
attributesParams.dimAmount = 0.4f;
@SuppressWarnings("deprecation") int width = (int) (window.getWindowManager().getDefaultDisplay().getWidth() * 0.85);
window.setLayout(width, LayoutParams.WRAP_CONTENT);
downMinTimer = new DownTimer();
downMinTimer.setListener(new DownTimerListener() {
@Override
public void onTick(long millisUntilFinished) {
recordTimeFlag = false;
}
@Override
public void onFinish() {
recordTimeFlag = true;
}
});
downMaxTimer = new DownTimer();
downMaxTimer.setListener(new DownTimerListener() {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
animation.stop();
recorderUtils.onRecord(false);
view_line.setVisibility(View.VISIBLE);
btn_detail_record.setVisibility(View.GONE);
img_record_animation.setVisibility(View.GONE);
btn_detail_confirm.setVisibility(View.VISIBLE);
btn_detail_confirm.setText(R.string.submit_text);
btn_detail_cancel.setVisibility(View.VISIBLE);
img_record_bg.setVisibility(View.VISIBLE);
tv_record_play.setVisibility(View.VISIBLE);
NToast.shortToast(getContext(), R.string.record_time_max_text);
}
});
recorderUtils = new MediaRecorderUtils();
img_record_animation = (ImageView) findViewById(R.id.img_record_animation);
img_record_bg = (ImageView) findViewById(R.id.img_record_bg);
tv_record_play = (TextView) findViewById(R.id.tv_record_play);
tv_record_play.setOnClickListener(this);
animation = (AnimationDrawable) img_record_animation.getBackground();
btn_detail_cancel = (Button) findViewById(R.id.btn_detail_cancel);
btn_detail_cancel.setOnClickListener(this);
btn_detail_cancel.setVisibility(View.GONE);
view_line = (View) findViewById(R.id.view_line);
view_line.setVisibility(View.GONE);
btn_detail_confirm = (Button) findViewById(R.id.btn_detail_confirm);
btn_detail_confirm.setOnClickListener(this);
btn_detail_confirm.setVisibility(View.GONE);
btn_detail_record = (Button) findViewById(R.id.btn_detail_record);
btn_detail_record.setVisibility(View.VISIBLE);
btn_detail_record.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
animation.stop();
animation.start();
if (downMinTimer != null) {
downMinTimer.stopDown();
}
downMinTimer.startDown(2000);
if (downMaxTimer != null) {
downMaxTimer.stopDown();
}
downMaxTimer.startDown(5000);
recorderUtils.onRecord(true);
break;
case MotionEvent.ACTION_UP:
animation.stop();
recorderUtils.onRecord(false);
if (downMaxTimer != null) {
downMaxTimer.stopDown();
}
if (recordTimeFlag) {
view_line.setVisibility(View.VISIBLE);
btn_detail_record.setVisibility(View.GONE);
img_record_animation.setVisibility(View.GONE);
btn_detail_confirm.setVisibility(View.VISIBLE);
btn_detail_confirm.setText(R.string.submit_text);
btn_detail_cancel.setVisibility(View.VISIBLE);
img_record_bg.setVisibility(View.VISIBLE);
tv_record_play.setVisibility(View.VISIBLE);
} else {
NToast.shortToast(getContext(), R.string.record_time_text);
}
break;
}
return false;
}
});
}
use of android.view.View.OnTouchListener in project edx-app-android by edx.
the class PlayerDemoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainHandler = new Handler(getMainLooper());
builder = getRendererBuilder();
setContentView(R.layout.activity_player_demo);
ViewGroup root = (ViewGroup) findViewById(R.id.root);
root.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
toggleControlsVisibility();
}
arg0.performClick();
return true;
}
});
mediaController = new EPlayerController(this);
mediaController.setAnchorView(root);
shutterView = findViewById(R.id.shutter);
surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
surfaceView.getHolder().addCallback(this);
}
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;
}
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;
}
});
}
use of android.view.View.OnTouchListener in project GT by Tencent.
the class GTLogo method createView.
private void createView() {
wm = (WindowManager) getApplicationContext().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(entrance_view, wmParams);
} catch (Exception e) {
/*
* 有的Android6会报permission denied for this window type问题
* https://github.com/intercom/intercom-android/issues/116
* 在这种系统上直接屏蔽悬浮窗
*/
stopSelf();
return;
}
entrance_img.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
x = event.getRawX();
y = event.getRawY() - DeviceUtils.getStatusBarHeight(getApplicationContext());
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
move_event = false;
mTouchStartX = event.getX();
mTouchStartY = event.getY();
ProX = event.getRawX();
ProY = event.getRawY();
clickHandler.sendEmptyMessage(0);
break;
case 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:
updateViewPositionEnd();
move_oldX = -1000;
move_oldY = -1000;
mTouchStartX = mTouchStartY = 0;
clickHandler.sendEmptyMessage(1);
break;
}
return true;
}
});
}
Aggregations