use of android.widget.AbsListView.OnScrollListener 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.widget.AbsListView.OnScrollListener 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;
}
});
}
use of android.widget.AbsListView.OnScrollListener in project little-bear-dictionary by daimajia.
the class CalendarView method setUpListView.
@SuppressLint("NewApi")
private void setUpListView() {
mListView.setDivider(null);
mListView.setItemsCanFocus(true);
mListView.setVerticalScrollBarEnabled(false);
mListView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
CalendarView.this.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
CalendarView.this.onScrollStateChanged(view, scrollState);
}
});
if (VERSION.SDK_INT >= 11) {
mListView.setFriction(mFriction);
mListView.setVelocityScale(mVelocityScale);
}
}
Aggregations