use of android.view.View.OnTouchListener in project android_frameworks_base by crdroidandroid.
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;
}
});
}
use of android.view.View.OnTouchListener in project android_frameworks_base by crdroidandroid.
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;
}
});
}
use of android.view.View.OnTouchListener in project android by owncloud.
the class AuthenticatorActivity method initServerPreFragment.
/**
*
* @param savedInstanceState Saved activity state, as in {{@link #onCreate(Bundle)}
*/
private void initServerPreFragment(Bundle savedInstanceState) {
boolean checkHostUrl = true;
/// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input);
if (savedInstanceState == null) {
if (mAccount != null) {
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
// TODO do next in a setter for mBaseUrl
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);
} else {
mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
}
} else {
mServerStatusText = savedInstanceState.getString(KEY_SERVER_STATUS_TEXT);
mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);
mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);
mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);
// TODO parcelable
mServerInfo.mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);
mServerInfo.mBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
if (ocVersion != null) {
mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
}
mServerInfo.mAuthMethod = AuthenticationMethod.valueOf(savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));
}
/// step 2 - set properties of UI elements (text, visibility, enabled...)
mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
// Convert IDN to Unicode
mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false));
if (mAction != ACTION_CREATE) {
/// lock things that should not change
mHostUrlInput.setEnabled(false);
mHostUrlInput.setFocusable(false);
}
if (isUrlInputAllowed) {
if (mServerInfo.mBaseUrl.isEmpty()) {
checkHostUrl = false;
}
mRefreshButton = findViewById(R.id.embeddedRefreshButton);
} else {
findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
mRefreshButton = findViewById(R.id.centeredRefreshButton);
}
showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE);
mServerStatusView = (TextView) findViewById(R.id.server_status_text);
showServerStatus();
/// step 3 - bind some listeners and options
mHostUrlInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
mHostUrlInput.setOnEditorActionListener(this);
/// step 4 - create listeners that will be bound at onResume
mHostUrlInputWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (mOkButton.isEnabled() && !mServerInfo.mBaseUrl.equals(normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
mOkButton.setEnabled(false);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mAuthStatusIcon != 0) {
Log_OC.d(TAG, "onTextChanged: hiding authentication status");
mAuthStatusIcon = 0;
mAuthStatusText = "";
showAuthStatus();
}
}
};
// TODO find out if this is really necessary, or if it can done in a different way
findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) && mHostUrlInput.hasFocus()) {
checkOcServer();
}
}
return false;
}
});
/// step 4 - mark automatic check to be started when OperationsService is ready
mPendingAutoCheck = (savedInstanceState == null && (mAction != ACTION_CREATE || checkHostUrl));
}
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;
}
});
}
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;
}
Aggregations