Skip to main content

Posts

Set custom marker on Google Map

This exercise will help to set custom marker instead of default marker.🚩 Something like in the screenshot below To set an custom marker you can use the previous exercise -  Draw Polyline on GoogleMap of Google Maps Android API v2 And make an edit on set marker on it. Place where the marker is set MarkerOptions markerOptions = new MarkerOptions();         markerOptions.position(latLng);         markerOptions.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(R.drawable.pulis, context))); Custom Marker function[getMarkerBitmapFromView(int,context)] public static Bitmap getMarkerBitmapFromView(@DrawableRes int resId, Context context, int check) {         View customMarkerView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.view_custom_marker, null);         CircleImageView markerImageView = customMarkerView.findViewById(R.id.profile_image);         markerImageView.setImageResource(resId);         customM

Draw Polyline on GoogleMap of Google Maps Android API v2

This exercise will help to draw a line on Google map between two or more co - ordinates. Like in an Screenshot below. Let's see how to do this: Important- Generate SHA1 certificate for your Google map from google developer account from below link- https://code.google.com/apis/ Add the dependency: implementation 'com.google.android.gms:play-services:8.3.0' 1. activity_main.xml <fragment         android:id="@+id/map"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:name="com.google.android.gms.maps.SupportMapFragment" /> 2. MainAction.java public class MainAction extends AppCompatActivity         implements OnMapReadyCallback,         GoogleApiClient.ConnectionCallbacks,         GoogleApiClient.OnConnectionFailedListener,         LocationListener {     GoogleMap mGoogleMap;     SupportMapFragment mapFrag;     LocationRequest mLocationRequest;

How to set an ATM Input EditText

This tutorial will show you how to form an ATM Input EditText Let's see how to do this Create your xml with a EditText <EditText     android:id="@+id/id_edttext_amt"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:text="$0.00"     android:gravity="center"     android:inputType="number"/> Now in you activity, Implement TextWatcher for the EditText you need ATM type input private String current = ""; edtAtm.addTextChangedListener(new TextWatcher() {     @Override     public void beforeTextChanged(CharSequence s, int start, int count, int after{     }     @Override     public void onTextChanged(CharSequence s, int start, int before, int count) {         if(!s.toString().equals(current)){             edtAtm.removeTextChangedListener(this);             String cleanString = s.toString().replaceAll("[$,.]", "");

How to work with Swipe Gestures in Android

Gesture? Gestures in android is defined as the movements of your fingers on android device screen and respond accordingly if there is any listener is implemented for gesture detection. In this article we can see how to do action by SwipeTop , SwipeBottom , SwipeRight , SwipeLeft . Let's Start Create a class  OnSwipeTouchListener public class OnSwipeTouchListener implements View.OnTouchListener { private final GestureDetector gestureDetector = new GestureDetector( new GestureListener()); public boolean onTouch( final View v, final MotionEvent event) { return gestureDetector .onTouchEvent(event); } private final class GestureListener extends GestureDetector.SimpleOnGestureListener { private static final int SWIPE_THRESHOLD = 100 ; private static final int SWIPE_VELOCITY_THRESHOLD = 100 ; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { boolean resu

Barcode or QR scanner - Android Tutorial

This tutorial explains how to scan Bar-code or QR-code . We have many third party libraries and here we can see one among them zxing-android-embedded library How to use this Step 1: Add the dependency   implementation 'com.journeyapps:zxing-android-embedded:3.5.0' Step 2 : Initialize it in your activity IntentIntegrator qbScan = new IntentIntegrator(this);  Step 3: Call on button call or on any trigger qbScan.initiateScan(); For Portrait mode, in Manifest file   <activity     android:name="com.journeyapps.barcodescanner.CaptureActivity"     android:screenOrientation="portrait"     tools:replace="screenOrientation" /> _____________________________________________________________________________ Happy Coding...

Encryption on Android

Encryption is a simple way to encrypt and decrypt strings on Android This can be achieved by some third-party libraries, here we look about one among them How to use   1.  Add JitPack to your build file allprojects {   repositories {     ...     maven { url 'https://jitpack.io' }   } } 2.Add the gradle dependency compile 'com.github.simbiose:Encryption:2.0.1' 3.  Get an Encryption instance String key = "YourKey"; String salt = "YourSalt"; byte[] iv = new byte[16]; Encryption encryption = Encryption.getDefault(key, salt, iv); 4. Encrypt your text String encrypted = encryption.encryptOrNull("Text to be encrypt"); 5. Decrypt your text String decrypted = encryption.decryptOrNull(encrypted); for more ... ---------------------------------------------------------------------------------------------------------------- Happy Coding...

How to clear the orientation issue on Camera Image

We will be taking a picture with this library and create a Bitmap and set it in an ImageView as follow public void onPictureTaken(CameraView cameraView, byte[] data) {      Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);      imageView.setImageBitmap(bitmap); } This will work fine on most of the devices however there are some exceptional devices too, where the picture orientation appears to be incorrectly rotated 90 degrees to the left when the device orientations is portrait. Solution to overcome this issue in your application  Trick :  Check if the  width > height  of the image then rotate by 90  Follow the steps: private static int fixOrientation(Bitmap bitmap) {         if (bitmap.getWidth() > bitmap.getHeight()) {             return 90;         }         return 0;     } Call this method to apply the rotation if needed public static Bitmap flipIMage(Bitmap bitmap) {         //Moustafa: fix

Underline TextView Text - Android

If your app need an underline for the text in TextView  Achieve it in simple way  - (By both xml and code part) xml It can be achieved if you are using a string resource xml file, which supports HTML tags like <b></b>, <i></i> and <u></u> <resources> <string name = "your_string_here" > This is an <u> underline </u> . </string> </resources> Code Way - 1 TextView textView = ( TextView ) view . findViewById ( R . id . textview ); SpannableString content = new SpannableString ( "Hello, Android !!!" ); content . setSpan ( new UnderlineSpan (), 0 , content . length (), 0 ); textView . setText ( content ); Way - 2 textview . setPaintFlags ( textview . getPaintFlags ()| Paint . UNDERLINE_TEXT_FLAG ); Way - 3 textview . setText ( Html . fromHtml ( "<u>Text to underline</u>" ));