Posts

RecyclerView item animation

if (imageView. isSelected ) { ValueAnimator.ofInt(size, (size * 1.8 ).toInt()). apply { addUpdateListener { values -> imageView. layoutParams . width = values. animatedValue as Int imageView. layoutParams . height = values. animatedValue as Int imageView.requestLayout() } duration = 200 start() } val anim = ScaleAnimation( 0.5f , 1f , 0.5f , 1f , Animation. RELATIVE_TO_SELF , 0.5f , Animation. RELATIVE_TO_SELF , 0.5f ) anim. fillAfter = true imageView.startAnimation(anim) } else { imageView. layoutParams . width = size imageView. layoutParams . height = size }

RecyclerView reusing or recycling view holders

As the user scrolls the list, the  RecyclerView  creates new view holders as necessary. It also saves the view holders which have scrolled off-screen, so they can be reused. If the user switches the direction they were scrolling, the view holders which were scrolled off the screen can be brought right back. On the other hand, if the user keeps scrolling in the same direction, the view holders which have been off-screen the longest can be rebound to new data. The view holder does not need to be created or have its view inflated; instead, the app just updates the view's contents to match the new item it was bound to.

Android Secure data with cryptography

# Create public and private key with keyStore. # Get  KeyPairGenerator instance by providing algo and provider (algo: RSA, provider:  AndroidKeyStore ) # Create  AlgorithmParameterSpec and initialize to  KeyPairGenerator  instance. # Generate Key Pairs ,  kpGenerator .generateKeyPair(); #  Signs the data using the key pair stored in the Android Key Store. # Get  KeyStore  instance with provider ( AndroidKeyStore ) #  Load the key pair from the Android Key Store using alias # Get  Signature and init with private key. #  Sign the data, store the result as a Base64 encoded String.

change svg android drawable color

private void changeSearchDrawable() { Drawable drawable = ResourcesCompat. getDrawable (getResources(), R.drawable. icon_search , getTheme()); int colorVal; if (Build.VERSION. SDK_INT >= Build.VERSION_CODES. M ) { colorVal = this .getResources().getColor(R.color. nnnow_pink , getTheme()); } else { colorVal = this .getResources().getColor(R.color. nnnow_pink ); } drawable.setColorFilter(colorVal, PorterDuff.Mode. SRC_ATOP ); check .setImageDrawable(drawable); }

Activity lifecycle on configuration change

 onResume  onPause  onSaveInstanceState(Bundle outState)  onStop  onDestroy  onCreate  onStart  onRestoreInstanceState(Bundle savedInstanceState)  onResume

network request using urlconnection

try { String response = null ; URL url = new URL( url ); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); String payload = "{ \" pageSize \" :30, \" pageNumber \" :1, \" currentPriceRanges \" :[], \" filters \" :{ \" newArrivals \" :false, \" onSale \" :false, \" articleType \" :[], \" filterBy \" :{ \" Brand \" :[]}}, \" isFiltersRequired \" :true, \" source \" : \" listing \" , \" collections \" :[ \" FL-Top Nav-ALL-Mens Shirts \" ]}" ; connection.setDoInput( true ); connection.setDoOutput( true ); connection.setRequestMethod( "POST" ); connection.setRequestProperty( "Accept" , "application/json" ); connection.setRequestProperty( "Content-Type" , "application/json; charset=UTF-8" ); OutputStreamWriter writer = new OutputSt

Android: launch android email with email id

Intent intent = new Intent ( Intent . ACTION_SENDTO , Uri. parse ( "mailto:" + mEmail .getText().toString())); intent.putExtra( Intent . EXTRA_EMAIL , mEmail .getText().toString()); startActivity( Intent . createChooser (intent, "Send Email" ));