android Programming Glossary: instanceof
How did Google manage to do this? Slide ActionBar in Android application http://stackoverflow.com/questions/11234375/how-did-google-manage-to-do-this-slide-actionbar-in-android-application i if view.isFocusable view.setEnabled enabled if view instanceof ViewGroup enableDisableViewGroup ViewGroup view enabled else.. ViewGroup view enabled else if view instanceof ListView if view.isFocusable view.setEnabled enabled ListView..
How to maintain multi layers of ImageViews and keep their aspect ratio based on the largest one? http://stackoverflow.com/questions/16729169/how-to-maintain-multi-layers-of-imageviews-and-keep-their-aspect-ratio-based-on true Rect bounds d.getBounds if bounds.isEmpty if d instanceof BitmapDrawable int right d.getIntrinsicWidth int bottom d.getIntrinsicHeight.. NotFoundException Drawable d super.getDrawable id if d instanceof BitmapDrawable BitmapDrawable bd BitmapDrawable d bd.getBitmap..
Android image caching http://stackoverflow.com/questions/1945201/android-image-caching true Object response connection.getContent if response instanceof Bitmap Bitmap bitmap Bitmap response Provides both memory and..
Secure HTTP Post in Android http://stackoverflow.com/questions/2253061/secure-http-post-in-android urlString URLConnection conn url.openConnection if conn instanceof HttpURLConnection throw new IOException Not an HTTP connection..
How to prevent Custom Views from losing state across screen orientation changes http://stackoverflow.com/questions/3542333/how-to-prevent-custom-views-from-losing-state-across-screen-orientation-changes code so parent classes can restore state if state instanceof SavedState super.onRestoreInstanceState state return SavedState..
WebView and HTML5 <video> http://stackoverflow.com/questions/3815090/webview-and-html5-video callback super.onShowCustomView view callback if view instanceof FrameLayout FrameLayout frame FrameLayout view if frame.getFocusedChild.. frame FrameLayout view if frame.getFocusedChild instanceof VideoView VideoView video VideoView frame.getFocusedChild frame.removeView..
how to hide soft keyboard on android after clicking outside EditText? http://stackoverflow.com/questions/4165414/how-to-hide-soft-keyboard-on-android-after-clicking-outside-edittext through every View in your activity and check if it is an instanceof EditText if it is not register a setOnTouchListener to that.. listener for non text box views to hide keyboard. if view instanceof EditText view.setOnTouchListener new OnTouchListener public.. iterate over children and seed recursion. if view instanceof ViewGroup for int i 0 i ViewGroup view .getChildCount i View..
Android: Want to set custom fonts for whole application not runtime http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime View v for int i 0 i count i v group.getChildAt i if v instanceof TextView v instanceof Button etc. TextView v .setTypeface font.. i count i v group.getChildAt i if v instanceof TextView v instanceof Button etc. TextView v .setTypeface font else if v instanceof.. Button etc. TextView v .setTypeface font else if v instanceof ViewGroup setFont ViewGroup v font If you pass it the root..
How do I display the current value of an Android Preference in the Preference summary? http://stackoverflow.com/questions/531427/how-do-i-display-the-current-value-of-an-android-preference-in-the-preference-su String key Preference pref findPreference key if pref instanceof ListPreference ListPreference listPref ListPreference pref pref.setSummary..
Line-breaking widget layout for Android http://stackoverflow.com/questions/549451/line-breaking-widget-layout-for-android boolean checkLayoutParams LayoutParams p return p instanceof LayoutParams @Override protected void onLayout boolean changed..
Replace Fragment inside a ViewPager http://stackoverflow.com/questions/7723964/replace-fragment-inside-a-viewpager public int getItemPosition Object object if object instanceof FirstPageFragment mFragmentAtPos0 instanceof NextFragment return.. if object instanceof FirstPageFragment mFragmentAtPos0 instanceof NextFragment return POSITION_NONE return POSITION_UNCHANGED..
ViewPager and fragments ??what's the right way to store fragment's state? http://stackoverflow.com/questions/7951730/viewpager-and-fragments-whats-the-right-way-to-store-fragments-state activity mIsLastMessages activity instanceof DashboardActivity @Override public View onCreateView LayoutInflater..
How did Google manage to do this? Slide ActionBar in Android application http://stackoverflow.com/questions/11234375/how-did-google-manage-to-do-this-slide-actionbar-in-android-application for int i 0 i childCount i View view viewGroup.getChildAt i if view.isFocusable view.setEnabled enabled if view instanceof ViewGroup enableDisableViewGroup ViewGroup view enabled else if view instanceof ListView if view.isFocusable view.setEnabled.. view.setEnabled enabled if view instanceof ViewGroup enableDisableViewGroup ViewGroup view enabled else if view instanceof ListView if view.isFocusable view.setEnabled enabled ListView listView ListView view int listChildCount listView.getChildCount..
How to maintain multi layers of ImageViews and keep their aspect ratio based on the largest one? http://stackoverflow.com/questions/16729169/how-to-maintain-multi-layers-of-imageviews-and-keep-their-aspect-ratio-based-on m drawable d transformation new Transformation matrix m valid true Rect bounds d.getBounds if bounds.isEmpty if d instanceof BitmapDrawable int right d.getIntrinsicWidth int bottom d.getIntrinsicHeight d.setBounds 0 0 right bottom else String.. null @Override public Drawable getDrawable int id throws NotFoundException Drawable d super.getDrawable id if d instanceof BitmapDrawable BitmapDrawable bd BitmapDrawable d bd.getBitmap .setDensity DisplayMetrics.DENSITY_DEFAULT bd.setTargetDensity..
Android image caching http://stackoverflow.com/questions/1945201/android-image-caching connection url.openConnection connection.setUseCaches true Object response connection.getContent if response instanceof Bitmap Bitmap bitmap Bitmap response Provides both memory and flash rom cache shared with the browser. grr. I wish somebody..
Secure HTTP Post in Android http://stackoverflow.com/questions/2253061/secure-http-post-in-android IOException InputStream in null int response 1 URL url new URL urlString URLConnection conn url.openConnection if conn instanceof HttpURLConnection throw new IOException Not an HTTP connection try HttpURLConnection httpConn HttpURLConnection conn httpConn.setAllowUserInteraction..
How to prevent Custom Views from losing state across screen orientation changes http://stackoverflow.com/questions/3542333/how-to-prevent-custom-views-from-losing-state-across-screen-orientation-changes void onRestoreInstanceState Parcelable state begin boilerplate code so parent classes can restore state if state instanceof SavedState super.onRestoreInstanceState state return SavedState ss SavedState state super.onRestoreInstanceState ss.getSuperState..
WebView and HTML5 <video> http://stackoverflow.com/questions/3815090/webview-and-html5-video public void onShowCustomView View view CustomViewCallback callback super.onShowCustomView view callback if view instanceof FrameLayout FrameLayout frame FrameLayout view if frame.getFocusedChild instanceof VideoView VideoView video VideoView frame.getFocusedChild.. view callback if view instanceof FrameLayout FrameLayout frame FrameLayout view if frame.getFocusedChild instanceof VideoView VideoView video VideoView frame.getFocusedChild frame.removeView video a.setContentView video video.setOnCompletionListener..
how to hide soft keyboard on android after clicking outside EditText? http://stackoverflow.com/questions/4165414/how-to-hide-soft-keyboard-on-android-after-clicking-outside-edittext is when to call it. You can write a method that iterates through every View in your activity and check if it is an instanceof EditText if it is not register a setOnTouchListener to that component and everything will fall in place. In case you are.. is the method public void setupUI View view Set up touch listener for non text box views to hide keyboard. if view instanceof EditText view.setOnTouchListener new OnTouchListener public boolean onTouch View v MotionEvent event hideSoftKeyboard.. event hideSoftKeyboard return false If a layout container iterate over children and seed recursion. if view instanceof ViewGroup for int i 0 i ViewGroup view .getChildCount i View innerView ViewGroup view .getChildAt i setupUI innerView ..
Android: Want to set custom fonts for whole application not runtime http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime ViewGroup group Typeface font int count group.getChildCount View v for int i 0 i count i v group.getChildAt i if v instanceof TextView v instanceof Button etc. TextView v .setTypeface font else if v instanceof ViewGroup setFont ViewGroup v font.. font int count group.getChildCount View v for int i 0 i count i v group.getChildAt i if v instanceof TextView v instanceof Button etc. TextView v .setTypeface font else if v instanceof ViewGroup setFont ViewGroup v font If you pass it the root.. count i v group.getChildAt i if v instanceof TextView v instanceof Button etc. TextView v .setTypeface font else if v instanceof ViewGroup setFont ViewGroup v font If you pass it the root of your layout it will recursively check for TextView or Button..
How do I display the current value of an Android Preference in the Preference summary? http://stackoverflow.com/questions/531427/how-do-i-display-the-current-value-of-an-android-preference-in-the-preference-su onSharedPreferenceChanged SharedPreferences sharedPreferences String key Preference pref findPreference key if pref instanceof ListPreference ListPreference listPref ListPreference pref pref.setSummary listPref.getEntry This is easily extensible..
Line-breaking widget layout for Android http://stackoverflow.com/questions/549451/line-breaking-widget-layout-for-android new LayoutParams 1 1 default of 1px spacing @Override protected boolean checkLayoutParams LayoutParams p return p instanceof LayoutParams @Override protected void onLayout boolean changed int l int t int r int b final int count getChildCount final..
Replace Fragment inside a ViewPager http://stackoverflow.com/questions/7723964/replace-fragment-inside-a-viewpager @Override public int getCount return NUM_ITEMS @Override public int getItemPosition Object object if object instanceof FirstPageFragment mFragmentAtPos0 instanceof NextFragment return POSITION_NONE return POSITION_UNCHANGED public interface.. NUM_ITEMS @Override public int getItemPosition Object object if object instanceof FirstPageFragment mFragmentAtPos0 instanceof NextFragment return POSITION_NONE return POSITION_UNCHANGED public interface FirstPageFragmentListener void onSwitchToNextFragment..
ViewPager and fragments ??what's the right way to store fragment's state? http://stackoverflow.com/questions/7951730/viewpager-and-fragments-whats-the-right-way-to-store-fragments-state super.onAttach activity setting callback mListener OnMessageListActionListener activity mIsLastMessages activity instanceof DashboardActivity @Override public View onCreateView LayoutInflater inflater ViewGroup container Bundle savedInstanceState..
|