List of usage examples for android.view View setOnFocusChangeListener
public void setOnFocusChangeListener(OnFocusChangeListener l)
From source file:com.micabyte.android.app.BaseActivity.java
private static void unbindViewReferences(View view) { // set all listeners to null try {//from w w w . j av a2 s. com view.setOnClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnCreateContextMenuListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnFocusChangeListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnKeyListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnLongClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } try { view.setOnClickListener(null); } catch (Throwable mayHappen) { // NOOP - not supported by all views/versions } // set background to null Drawable d = view.getBackground(); if (d != null) { d.setCallback(null); } if (view instanceof ImageView) { final ImageView imageView = (ImageView) view; d = imageView.getDrawable(); if (d != null) { d.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } if (view instanceof ImageButton) { final ImageButton imageB = (ImageButton) view; d = imageB.getDrawable(); if (d != null) { d.setCallback(null); } imageB.setImageDrawable(null); } // destroy WebView if (view instanceof WebView) { view.destroyDrawingCache(); ((WebView) view).destroy(); } }
From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java
@SuppressLint("ObsoleteSdkInt") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void unBindView(View view) { if (view == null) return;/*from w w w. j a v a 2 s .c om*/ Drawable drawable; int i; //1. try { view.setOnClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //2. try { view.setOnCreateContextMenuListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //3. try { view.setOnFocusChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //4. try { view.setOnKeyListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //5. try { view.setOnLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //6. try { view.setOnTouchListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //7. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { view.setOnApplyWindowInsetsListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //8. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnContextClickListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //9. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnScrollChangeListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //10. try { view.setOnDragListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //11. try { view.setOnGenericMotionListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //12. try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13 view.setOnHoverListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //13. try { view.setOnSystemUiVisibilityChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } /** * @see SwipeRefreshLayout#onDetachedFromWindow() */ if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) { try { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16 view.setBackgroundDrawable(null); } else { view.setBackground(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageView if (view instanceof ImageView) { try { ImageView imageView = (ImageView) view; drawable = imageView.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //TextView if (view instanceof TextView) { try { TextView textView = (TextView) view; textView.setCompoundDrawables(null, null, null, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(null, null, null, null); } textView.setCursorVisible(false); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageButton if (view instanceof ImageButton) { try { ImageButton imageButton = (ImageButton) view; drawable = imageButton.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageButton.setImageDrawable(null); imageButton.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ListView if (view instanceof ListView) { ListView listView = (ListView) view; try { listView.setAdapter(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnScrollListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemSelectedListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //RecyclerView if (view instanceof RecyclerView) { try { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setAdapter(null); recyclerView.setChildDrawingOrderCallback(null); recyclerView.setOnScrollListener(null); recyclerView.addOnScrollListener(null); recyclerView.removeOnScrollListener(null); recyclerView.setRecyclerListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //WebView if (view instanceof WebView) { WebView webView = (WebView) view; try { webView.stopLoading(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.removeAllViews(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebChromeClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebViewClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.destroy(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { if (null != view.getParent() && view.getParent() instanceof ViewGroup) { ((ViewGroup) view.getParent()).removeView(view); } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } //SurfaceView if (view instanceof SurfaceView) { try { SurfaceView surfaceView = (SurfaceView) view; SurfaceHolder holder = surfaceView.getHolder(); if (holder != null) { Surface surface = holder.getSurface(); if (surface != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { surface.release(); } } } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } view.destroyDrawingCache(); view.clearAnimation(); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = (viewGroup).getChildCount(); for (i = 0; i < childCount; i++) { unBindView((viewGroup).getChildAt(i)); } } }
From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java
/** * View./*from w ww .ja v a2 s. c o m*/ * * @param view the view */ public void addContentView(View view) { addView(view, 0, getLayoutParams()); view.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { showPrevious(); } } }); view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEvent.ACTION_DOWN == event.getAction()) { showPrevious(); } return false; } }); }
From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java
/** * View./*from w ww. j a va 2s .c om*/ * * @param view the view */ public void addNextView(View view) { addView(view, 1, getLayoutParams()); view.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { showNext(); } } }); view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEvent.ACTION_DOWN == event.getAction()) { showNext(); } return false; } }); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static boolean updateButtonBar(Activity a, int highlight) { final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar); boolean withtabs = false; Intent intent = a.getIntent();//from ww w . jav a2 s. co m if (intent != null) { withtabs = intent.getBooleanExtra("withtabs", false); } if (highlight == 0 || !withtabs) { ll.setVisibility(View.GONE); return withtabs; } else if (withtabs) { ll.setVisibility(View.VISIBLE); } for (int i = ll.getChildCount() - 1; i >= 0; i--) { View v = ll.getChildAt(i); boolean isActive = (v.getId() == highlight); if (isActive) { ll.setCurrentTab(i); sActiveTabIndex = i; } v.setTag(i); v.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { for (int i = 0; i < ll.getTabCount(); i++) { if (ll.getChildTabViewAt(i) == v) { ll.setCurrentTab(i); processTabClick((Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId()); break; } } } } }); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { processTabClick((Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId()); } }); } return withtabs; }
From source file:vn.cybersoft.obs.android.activities.PowerScheduleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(LAYOUT_ID);/*from w ww.j a va 2 s . c om*/ setTitle(getString(R.string.app_name) + " > " + getString(R.string.schedule_by_power)); mInflater = LayoutInflater.from(this); getSupportLoaderManager().initLoader(TIME_SCHEDULE_LIST_LOADER, null, this); mScheduleList = (ListView) findViewById(android.R.id.list); mSchedules = new ScheduleAdapter(this, R.layout.power_schedule_list_row); mScheduleList.setAdapter(mSchedules); mScheduleList.setVerticalScrollBarEnabled(true); mScheduleList.setOnItemClickListener(this); mScheduleList.setOnCreateContextMenuListener(this); View addSchedule = findViewById(R.id.add_schedule); addSchedule.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { addNewSchedule(); } }); // Make the entire view selected when focused. addSchedule.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { v.setSelected(hasFocus); } }); }
From source file:vn.cybersoft.obs.android.activities.TimeScheduleActivity.java
private void updateLayout() { setContentView(LAYOUT_ID);/* w w w . j av a 2s . com*/ setTitle(getString(R.string.app_name) + " > " + getString(R.string.schedule_by_time)); mScheduleList = (ListView) findViewById(android.R.id.list); //mSchedules = new ScheduleAdapter(this, R.layout.schedule_list_row, mCursor); mSchedules = new ScheduleAdapter(this, R.layout.time_schedule_list_row); mScheduleList.setAdapter(mSchedules); mScheduleList.setVerticalScrollBarEnabled(true); mScheduleList.setOnItemClickListener(this); mScheduleList.setOnCreateContextMenuListener(this); getSupportLoaderManager().initLoader(TIME_SCHEDULE_LIST_LOADER, null, this); View addSchedule = findViewById(R.id.add_schedule); addSchedule.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { addNewSchedule(); } }); // Make the entire view selected when focused. addSchedule.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { v.setSelected(hasFocus); } }); }
From source file:vn.cybersoft.obs.android.fragments.ModeTabFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mInflater = inflater;//from ww w. j a v a2 s. c o m final View rootView = mInflater.inflate(LAYOUT_ID, container, false); mModeList = (ListView) rootView.findViewById(R.id.modes_list); mAdapter = new OptimalModeAdapter(getActivity(), R.layout.mode_optimization_list_row); mModeList.setAdapter(mAdapter); mModeList.setVerticalScrollBarEnabled(true); mModeList.setOnCreateContextMenuListener(this); mModeList.setOnItemClickListener(this); View addSchedule = rootView.findViewById(R.id.add_new_mode); addSchedule.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { addNewMode(); } }); // Make the entire view selected when focused. addSchedule.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { v.setSelected(hasFocus); } }); return rootView; }
From source file:net.niyonkuru.koodroid.ui.PageFragment.java
@Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.plan_title: case R.id.bill_title: case R.id.tab_title: case R.id.billing_cycle_title: case R.id.airtime_title: case R.id.data_title: final View options = ((FrameLayout) v).getChildAt(2); AnimUtils.fade(options);// w w w. jav a 2s. co m v.setFocusableInTouchMode(true); v.requestFocusFromTouch(); v.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { AnimUtils.fadeOut(options); v.setFocusableInTouchMode(false); } updateTimestamps(); } }); } /* give the user feedback as to how fresh the data is */ updateTimestamps(); }
From source file:ti.modules.titanium.ui.widget.tableview.TiTableView.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { // To prevent undesired "focus" and "blur" events during layout caused // by ListView temporarily taking focus, we will disable focus events until // layout has finished. // First check for a quick exit. listView can be null, such as if window closing. if (listView == null) { super.onLayout(changed, left, top, right, bottom); return;/*from w ww . jav a2 s . co m*/ } OnFocusChangeListener focusListener = null; View focusedView = listView.findFocus(); if (focusedView != null) { OnFocusChangeListener listener = focusedView.getOnFocusChangeListener(); if (listener != null && listener instanceof TiUIView) { focusedView.setOnFocusChangeListener(null); focusListener = listener; } } super.onLayout(changed, left, top, right, bottom); if (proxy != null) { if (changed) { TiUIHelper.firePostLayoutEvent(proxy.peekView()); } } // Layout is finished, re-enable focus events. if (focusListener != null) { focusedView.setOnFocusChangeListener(focusListener); // If the configuration changed, we manually fire the blur event if (changed) { focusListener.onFocusChange(focusedView, false); } } }