use of android.view.View.OnFocusChangeListener in project GT by Tencent.
the class GTInputParamSetActivity method initAutoCompleteTV.
private void initAutoCompleteTV(ArrayList<String> vals, final AutoCompleteTextView auto) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.gt_drop_default_listitem, vals);
auto.setDropDownBackgroundResource(R.drawable.btn_gray);
auto.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
auto.showDropDown();
}
});
auto.setText(vals.get(0));
auto.setSelection(vals.get(0).length());
auto.setAdapter(adapter);
auto.setThreshold(1);
auto.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (auto.getText().toString().equals("")) {
btn_c.setVisibility(View.GONE);
} else {
btn_c.setVisibility(View.VISIBLE);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
auto.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
auto.showDropDown();
}
});
}
use of android.view.View.OnFocusChangeListener in project android_packages_apps_Dialer by MoKee.
the class CallLogActivity method prepareSearchView.
private void prepareSearchView() {
final View searchViewLayout = getLayoutInflater().inflate(R.layout.search_action_bar, null);
mSearchView = (EditText) searchViewLayout.findViewById(R.id.search_view);
mClearButtonView = (ImageView) searchViewLayout.findViewById(R.id.search_close_button);
mClearButtonView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSearchView.setText("");
}
});
mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
mClearButtonView.setVisibility(View.GONE);
mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
showInputMethod(v.findFocus());
} else {
hideInputMethod(v);
}
}
});
getSupportActionBar().setCustomView(searchViewLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
use of android.view.View.OnFocusChangeListener in project Android-Terminal-Emulator by jackpal.
the class AddShortcut method makeShortcut.
// ////////////////////////////////////////////////////////////////////
void makeShortcut() {
if (path == null)
path = "";
final AlertDialogCompat.Builder alert = AlertDialogCompat.newInstanceBuilder(context, AlertDialogCompat.THEME_HOLO_DARK);
LinearLayout lv = new LinearLayout(context);
lv.setOrientation(LinearLayout.VERTICAL);
for (int i = 0, n = et.length; i < n; i++) {
et[i] = new EditText(context);
et[i].setSingleLine(true);
}
if (!path.equals(""))
et[0].setText(path);
// "command");
et[PATH].setHint(getString(R.string.addshortcut_command_hint));
et[NAME].setText(name);
// "--example=\"a\"");
et[ARGS].setHint(getString(R.string.addshortcut_example_hint));
et[ARGS].setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean focus) {
if (!focus) {
String s;
if (et[NAME].getText().toString().equals("") && !(s = et[ARGS].getText().toString()).equals(""))
et[NAME].setText(s.split("\\s")[0]);
}
}
});
Button btn_path = new Button(context);
// "Find command");
btn_path.setText(getString(R.string.addshortcut_button_find_command));
btn_path.setOnClickListener(new View.OnClickListener() {
public void onClick(View p1) {
String lastPath = SP.getString("lastPath", null);
File get = (lastPath == null) ? Environment.getExternalStorageDirectory() : new File(lastPath).getParentFile();
Intent pickerIntent = new Intent();
if (SP.getBoolean("useInternalScriptFinder", false)) {
pickerIntent.setClass(getApplicationContext(), jackpal.androidterm.shortcuts.FSNavigator.class).setData(Uri.fromFile(get)).putExtra("title", // "SELECT SHORTCUT TARGET")
getString(R.string.addshortcut_navigator_title));
} else {
pickerIntent.putExtra("CONTENT_TYPE", "*/*").setAction(Intent.ACTION_PICK);
}
startActivityForResult(pickerIntent, OP_MAKE_SHORTCUT);
}
});
lv.addView(layoutTextViewH(// "Command window requires full path, no arguments. For other commands use Arguments window (ex: cd /sdcard)."
getString(R.string.addshortcut_command_window_instructions), null, false));
lv.addView(layoutViewViewH(btn_path, et[PATH]));
lv.addView(layoutTextViewH(getString(R.string.addshortcut_arguments_label), et[ARGS]));
lv.addView(layoutTextViewH(getString(R.string.addshortcut_shortcut_label), et[NAME]));
final ImageView img = new ImageView(context);
img.setImageResource(jackpal.androidterm.R.drawable.ic_launcher);
img.setMaxHeight(100);
img.setTag(0xFFFFFFFF);
img.setMaxWidth(100);
img.setAdjustViewBounds(true);
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
final Button btn_color = new Button(context);
// "Text icon");
btn_color.setText(getString(R.string.addshortcut_button_text_icon));
btn_color.setOnClickListener(new View.OnClickListener() {
public void onClick(View p1) {
new ColorValue(context, img, iconText);
}
});
lv.addView(layoutTextViewH(// "Optionally create a text icon:"
getString(R.string.addshortcut_text_icon_instructions), null, false));
lv.addView(layoutViewViewH(btn_color, img));
final ScrollView sv = new ScrollView(context);
sv.setFillViewport(true);
sv.addView(lv);
alert.setView(sv);
// "Term Shortcut");
alert.setTitle(getString(R.string.addshortcut_title));
alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
buildShortcut(path, et[ARGS].getText().toString(), et[NAME].getText().toString(), iconText[1], (Integer) img.getTag());
}
});
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
}
use of android.view.View.OnFocusChangeListener in project Android-CollapsibleSearchMenu by johnkil.
the class CollapsibleMenuUtils method addSearchMenuItem.
/**
* Adding collapsible search menu item to the menu.
* @param menu
* @param isLightTheme - true if use light them for ActionBar, else false
* @return
*/
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final TextWatcher textWatcher) {
final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
final View searchView = menuItem.getActionView();
final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
editText.addTextChangedListener(textWatcher);
editText.requestFocus();
showKeyboard(editText);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
editText.setText(null);
editText.removeTextChangedListener(textWatcher);
// editText.clearFocus();
hideKeyboard(editText);
return true;
}
});
final View searchPlate = searchView.findViewById(R.id.search_plate);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
searchView.post(new Runnable() {
public void run() {
searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
searchView.invalidate();
}
});
}
});
final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
closeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TextUtils.isEmpty(editText.getText())) {
editText.setText(null);
} else {
menuItem.collapseActionView();
}
}
});
return menuItem;
}
use of android.view.View.OnFocusChangeListener 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