Skip to main content

Posts

Showing posts from April, 2017

Flexbox inside the RecyclerView as a LayoutManager (FlexboxLayoutManager).

Currently google has release the Flexbox which can be used for building flexible layouts using FlexboxLayout, it can be interpreted as an advanced LinearLayout because both layouts align their child views sequentially. For more detail on this flexbox-layout But here we are gonna work on Flexbox with RecyclerView. Flexbox with a large number of items in a scrollable container! Let's first see what are the Supported attributes / features comparison Due to some characteristics of the RecyclerView, some Flexbox attributes are not available/not implemented to the FlexboxLayoutManager. Here is a quick overview of the attributes/features comparison between the two containers. Attribute / Feature FlexboxLayout                FlexboxLayoutManager (RecyclerView) flexDirection flexWrap (except wrap_reverse ) justifyContent alignItems alignContent - layout_order - layout_flexGrow layout_flexShrink layout_alignSelf layout_fl

Image Compression like WhatsApp in android

How to compress the image without loosing the quality. You can compress the image just like whatsapp like quality. File externalFile = new File(Environment. getExternalStorageDirectory () , " ProfilePic /helloimg.jpg" ) ; Uri externaluri = Uri. parse (externalFile.getPath()) ; compressImage(externaluri.toString() , "helloimg" ) ; // Method to compress Image Compress image public String compressImage (String imageUri , String imagenameName) { String filePath = getRealPathFromURI(imageUri) ; String fileName = imagenameName ; Bitmap scaledBitmap = null; BitmapFactory.Options options = new BitmapFactory.Options() ; //by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If //you try the use the bitmap here, you will get null. options. inJustDecodeBounds = true; Bitmap bmp = BitmapFactory. decodeFile (filePath

How to reduce the image size without loosing the quality using WebP Images

WebP is an image file format from Google that provides lossy compression (like JPEG) as well as transparency (like PNG) but can provide better compression than either JPEG or PNG. Lossy WebP images are supported in Android 4.0 (API level 14) and higher, and lossless and transparent WebP images are supported in Android 4.3 (API level 18) and higher. This page shows how to convert images to WebP format and how to convert WebP images to PNG format. Convert images to WebP: Android Studio can convert PNG, JPG, BMP, or static GIF images to WebP format. You can convert individual images or folders of images. To convert an image or folder of images, proceed as follows: Right click on an image file or a folder containing a number of images files, and then click Convert to WebP . The Converting Images to WebP dialog opens. The default settings depend on the minSdkVersion setting for the current module. Figure 1. The Converting Images to WebP dialog. Select either lossy

Pick Color from Image

Picking the Color from the Image in Android in HEX and RGB In android we use HEX for color code and in ios we use RGB so here we are gonna work on both. You can download the full source code from github PickColorFromImageAndroid . ImageView picked_imageView ; picked_imageView = (ImageView) findViewById(R.id. imageView2 ) ; picked_imageView .setOnTouchListener( this ) ; picked_imageView .setImageBitmap(bitmapImage) ; OnTouch of picked_imageView we can get the color code in onTouch method. When we touch the imageView we will get the color code from the image and here you can format it in HEX and RGB. @Override public boolean onTouch (View v , MotionEvent event) { Matrix inverse = new Matrix() ; picked_imageView .getImageMatrix().invert(inverse) ; float [] touchPoint = new float [] {event.getX() , event.getY()} ; inverse.mapPoints(touchPoint) ; int x = Integer. valueOf (( int )touchPoint[ 0 ]) ; int y = Integer. valueOf (( int

Vertical AutoScrolling TextView in Android

In android by default we can scroll the text in horizontal using marquee in layout, but if we want to scroll the text in vertical its not possible by default. So here we will learn to create a custom TextView which will auto-scroll in vertical direction. Source Code:  VerticalScrollingTextView-Android Create a AutoScrollingTextView.class which extends TextView: @SuppressLint ( "AppCompatCustomView" ) public class AutoScrollingTextView extends TextView { private static final float DEFAULT_SPEED = 65.0f ; public Scroller scroller ; public float speed = DEFAULT_SPEED ; public boolean continuousScrolling = true; public AutoScrollingTextView (Context context) { super (context) ; init( null, 0 ) ; scrollerInstance(context) ; } public AutoScrollingTextView (Context context , AttributeSet attrs) { super (context , attrs) ; init(attrs , 0 ) ; scr

Custom FontTextView in Android

Customize font from layout for TextView In android layout textview  with font-family option with three fonts are given by default. If we have to add our own custom fonts from assert we have to do it by programmatically by adding these lines of code : TextView name = (TextView)findViewById(R.id.name);  Typeface type=Typeface.createFromAsset(getAssets(),"fonts/RobotoSlabRegular.ttf"); txtyour.setTypeface(type) ; Android 8.0 (API level 26) introduces a new feature, Fonts in XML, which lets you use fonts as resources. You can add the font file in the res/font/ folder to bundle fonts as resources. These fonts are compiled in your R file and are automatically available in Android Studio. You can access the font resources with the help of a new resource type, font . For example, to access a font resource, use @font/myfont , or R.font.myfont . To use the Fonts in XML feature on devices running Android 4.1 (API level 16) and higher, use the Support Library 26.