Friday, 16 July 2021

Android Studio - Get Current Latitude And Longitude

1. Add this dependencies in your gradle file

    implementation 'com.google.android.gms:play-services-location:18.0.0'

2. Add this permission into your Manifest file


    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission. ACCESS_COARSE_LOCATION" />


Simple UI to show your Location

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center"

    tools:context=".MainActivity">


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Latitude: "

        android:id="@+id/tv_lat"

        android:textSize="20sp"

        android:layout_marginBottom="10dp"

        android:textFontWeight="@integer/material_motion_duration_long_1"/>

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Longitude: "

        android:id="@+id/tv_long"

        android:textSize="20sp"

        android:textFontWeight="@integer/material_motion_duration_long_1"/>

</LinearLayout>


MainActivity  Class



public class MainActivity extends AppCompatActivity {

//    Todo: 4. Java Class Or MainActivity class

    //Todo: FusedLocationProviderClient
    FusedLocationProviderClient fusedLocationProviderClient;
    TextView tv_lat, tv_long;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(MainActivity.this);
        tv_lat = (TextView) findViewById(R.id.tv_lat);
        tv_long = (TextView) findViewById(R.id.tv_long);

        //Todo: Check permission is granded or not
        if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            getCurrentLocation();
        } else {
//            Todo: If not then ask to tack location permission
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION
            }, 100);
        }
    }
    //Todo: Trace Location Permission is granded or not
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 100 && grantResults.length > 0 && (grantResults[0] + grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
            getCurrentLocation();
        } else {
            //Todo: If NOt Show a message
            Toast.makeText(MainActivity.this, "Can't trace your location", Toast.LENGTH_LONG).show();
        }
    }

    //Todo: GetCurrentLocationMethod To Get Current Cordinates
    @SuppressLint("MissingPermission")
    private void getCurrentLocation() {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

            fusedLocationProviderClient.getLastLocation().addOnCompleteListener(new OnCompleteListener<Location>() {
                @Override
                public void onComplete(@NonNull Task<Location> task) {
                    Location location = task.getResult();
                    if (location != null) {
                        tv_lat.setText("Latitude: " +String.valueOf(location.getLatitude()));
                        tv_long.setText("Longitude: "+String.valueOf(location.getLongitude()));
                    } else {
                        LocationRequest locationRequest = new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                                .setInterval(10000)
                                .setFastestInterval(1000)
                                .setNumUpdates(1);
                        LocationCallback locationCallback = new LocationCallback() {
                            @Override
                            public void onLocationResult(@NonNull LocationResult locationResult) {
                                super.onLocationResult(locationResult);
                                Location location1 = locationResult.getLastLocation();
                                tv_lat.setText("Latitude: " +String.valueOf(location.getLatitude()));
                                tv_long.setText("Longitude: "+String.valueOf(location.getLongitude()));
                            }
                        };
                        if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());
                        }

                    }
                }
            });
        } else {
            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS).
                    setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    }
}


Wednesday, 23 June 2021

Android Volley GET & POST Example In Kotlin

1. Add this dependency in your gradle fie

implementation 'com.android.volley:volley:1.1.0'


2. Volley Get Method

fun getVolley(){
        // Instantiate the Volley RequestQueue.
        val queue = Volley.newRequestQueue(this)
        val url: String = "PUT_YOUR_URL"
        // Request a string response from the URL
        val stringReq = StringRequest(
            Request.Method.GET, url,
            Response.Listener<String> { response ->
                var str_res = response.toString()
                Log.d("API", str_res)
            },
            Response.ErrorListener { error ->
                Log.d("API GET ERROR", "get error => $error") })
        queue.add(stringReq)
   }

3. Volley Post Method

fun postVolley() {
        val queue = Volley.newRequestQueue(this)
        val url = "https://reqres.in/api/users"

//PUT YOUR BODY IN STRAING WITH JSON KEY NAME
/*
Want to post this data
{
name:"mijas",
job:"Youtuber"
}
*/
        val requestBody = "name=Mijas" + "&job=Youtuber"
        val stringReq : StringRequest =
            object : StringRequest(Method.POST, url,
                Response.Listener { response ->
                    // response
                    var str_res = response.toString()
                    Log.d("API Response", str_res)
                },
                Response.ErrorListener { error ->
                    Log.d("API POST ERROR", "post error => $error")
                }
            ){
                override fun getBody(): ByteArray {
                    return requestBody.toByteArray(Charset.defaultCharset())
                }
            }
        queue.add(stringReq)
    }

Thursday, 29 August 2019

Android Staggered Layout With RecyclerView




1) Add this dependencies in your gradle file


implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.

2) create staggerd_layout.xml in res/layout folder

staggerd_layout.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="5dp">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="4dp"
        app:cardElevation="2dp"
        android:layout_centerHorizontal="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"
                android:id="@+id/imageview_widget"
                android:scaleType="center"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Canada"
                android:id="@+id/name_widget"
                android:layout_below="@+id/imageview_widget"
                android:layout_marginTop="10dp"
                android:textColor="#000"/>

        </RelativeLayout>


    </androidx.cardview.widget.CardView>
</RelativeLayout>

3)Create StaggeredRecyclerViewAdapter class 

StaggeredRecyclerViewAdapter.java

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;


public class StaggeredRecyclerViewAdapter extends RecyclerView.Adapter<StaggeredRecyclerViewAdapter.ViewHolder> {

    private ArrayList<String> Title = new ArrayList<>();
    private ArrayList<String> ImageUrl = new ArrayList<>();
    private Context mContext;

    public StaggeredRecyclerViewAdapter(Context context, ArrayList<String> names, ArrayList<String> imageUrls) {
        Title = names;
        ImageUrl = imageUrls;
        mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.staggerd_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.drawable.ic_launcher_background);

        Glide.with(mContext)
                .load(ImageUrl.get(position))
                .apply(requestOptions)
                .into(holder.image);

        holder.name.setText(Title.get(position));

        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(mContext, Title.get(position), Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public int getItemCount() {
        return ImageUrl.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        ImageView image;
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            this.image = itemView.findViewById(R.id.imageview_widget);
            this.name = itemView.findViewById(R.id.name_widget);
        }
    }
}

4)Add RecyclerView In Your activity_main.xml file


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@android:color/darker_gray">


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recyclerview"
        android:orientation="vertical"/>

</RelativeLayout>


5) Now Is Time To Implement Bind Data In MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
 
 
    private static final int NUM_COLUMNS = 2;

    private ArrayList<String> ImageUrl = new ArrayList<>();
    private ArrayList<String> Title = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initImageBitmap();
    }

    private void initImageBitmap() {

        ImageUrl.add("http://www.transindiatravels.com/wp-content/uploads/the-taj-mahal-agra.jpg");
        Title.add("Taj Mahal");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-varanasi.jpg");
        Title.add("Varanasi");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-jaisalmer.jpg");
        Title.add("Jaisalmer");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-gateway-india.jpg");
        Title.add("Gateway of India");

        ImageUrl.add("https://upload.wikimedia.org/wikipedia/commons/0/09/India_Gate_in_New_Delhi_03-2016.jpg");
        Title.add("India Gate");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-amer-fort.jpg");
        Title.add("Amer Fort, Jaipur");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-goa.jpg");
        Title.add("The Beaches of Goa");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-ellora-caves.jpg");
        Title.add("The Ellora Caves, Aurangabad");

        ImageUrl.add("https://images.mapsofindia.com/my-india/qutub-minar-delhi.jpg");
        Title.add("Kutub Minar");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-mysore-palace.jpg");
        Title.add("Mysore Palace");

        ImageUrl.add("https://www.planetware.com/photos-large/IND/india-top-attractions-mahabodhi-temple.jpg");
        Title.add("Mahabodhi Temple, Bodhgaya");

        initRecyclerView();
    }

    private void initRecyclerView() {

        RecyclerView recyclerView = findViewById(R.id.recyclerview);

        StaggeredRecyclerViewAdapter staggeredRecyclerViewAdapter =
                new StaggeredRecyclerViewAdapter(this, Title, ImageUrl);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager( NUM_COLUMNS,
                LinearLayoutManager.VERTICAL);

        /*
        Official Link Of StaggeredGridLayoutManager

  https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager

        */

        recyclerView.setLayoutManager(staggeredGridLayoutManager);
        recyclerView.setAdapter(staggeredRecyclerViewAdapter);
    }
}

Subscribe Our YouTube Channel:
Mijas Siklodi

Saturday, 10 August 2019

Android ListView With Multiple Items






Step 1: Create A List Item Layout File 



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_margin="5dp"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Id: "
        android:textStyle="bold"
        android:textSize="17sp"
        android:id="@+id/tv_id"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@mipmap/ic_launcher_round"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dp"
            android:layout_weight="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hello: "
                android:textColor="@android:color/black"
                android:textStyle="bold"
                android:textSize="17sp"
                android:id="@+id/tv_name"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello: "
                android:textColor="@android:color/black"
                android:textSize="15sp"
                android:id="@+id/tv_descr"/>
        </LinearLayout>
    </LinearLayout>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Price: "
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:textSize="17sp"
        android:id="@+id/tv_price"/>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp">


        <TextView
            android:layout_width="1.1in"
            android:layout_height="wrap_content"
            android:text="Category Id: "
            android:textSize="15sp"
            android:id="@+id/tv_catid"
            android:layout_alignParentLeft="true"/>

        <TextView
            android:layout_width="1.1in"
            android:layout_height="wrap_content"
            android:text="Category Name: "
            android:textSize="15sp"
            android:id="@+id/tv_catname"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>


</LinearLayout>


Step 2: Create A DataModel Class (POJO)

As per which kind of data you want to load,
in my case my formate from my api is data is:

 {
"id": "id",
"name": "Name",
"description": "Description",
"price": "Price",
"category_id": "Category ID",
"category_name": Category Name"
 }

public class DataModel {
    String id;
    String name;
    String description;
    String price;
    String category_id;
    String category_name;

    public DataModel() {
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public void setCategory_id(String category_id) {
        this.category_id = category_id;
    }

    public void setCategory_name(String category_name) {
        this.category_name = category_name;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getPrice() {
        return price;
    }

    public String getCategory_id() {
        return category_id;
    }

    public String getCategory_name() {
        return category_name;
    }
}

Step 3: Create A DataAdapter Class

In Adapter class we bind ui and data in app


public class DataAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<DataModel> dataModels;

    public DataAdapter(Context context, ArrayList<DataModel> dataModels) {
        this.context = context;
        this.dataModels = dataModels;
    }

    @Override
    public int getCount() {
        return dataModels.size();
    }

    @Override
    public Object getItem(int position) {
        return dataModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            holder = new ViewHolder();
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.card, null, true);

            holder.tv_id = (TextView) convertView.findViewById(R.id.tv_id);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_descr = (TextView) convertView.findViewById(R.id.tv_descr);
            holder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            holder.tv_catid = (TextView) convertView.findViewById(R.id.tv_catid);
            holder.tv_catname = (TextView) convertView.findViewById(R.id.tv_catname);

            convertView.setTag(holder);
        }else {

            holder = (ViewHolder)convertView.getTag();

        }

        holder.tv_id.setText("Id: " + dataModels.get(position).getId());
        holder.tv_name.setText(dataModels.get(position).getName());
        holder.tv_descr.setText(dataModels.get(position).getDescription());
        holder.tv_price.setText("Price:" + dataModels.get(position).getPrice());
        holder.tv_catid.setText("Cat Id" + dataModels.get(position).getCategory_id());
        holder.tv_catname.setText("Cat Name:" + dataModels.get(position).getCategory_name());
        return convertView;
    }

    private class ViewHolder {

        protected TextView tv_id, tv_name, tv_descr, tv_price, tv_catid, tv_catname;

    }


}


Step 4. Making Final UI Changes

For this, you need to replace your existing code of activity_main.xml with the following one

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"/>

</RelativeLayout>


After this, write down the below code snippet in MainActivity.java file.

public class MainActivity extends AppCompatActivity {
    
    private ListView listview;
    private ArrayList<DataModel> dataModelArrayList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        
        listview = (ListView) findViewById(R.id.listview);

        Retrofit get_retrofit = new Retrofit.Builder()
                .baseUrl(Api.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        Api api = get_retrofit.create(Api.class);

        Call<ResponseBody> call = api.getCatList();

        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    try {

                        JSONArray jsonArray = new JSONArray(response.body().string());
                        String[] listItem = new String[jsonArray.length()];
                        //listItem = getResources().getStringArray(R.array.array_technology);
                        ArrayList<DataModel> list = new ArrayList<>();
                        for(int i = 0; i< jsonArray.length(); i++){
                            //listItem[i] = jsonArray.getJSONObject(i).getString("name");
                            DataModel data = new DataModel();
                            data.setId(jsonArray.getJSONObject(i).getString("id"));
                            data.setName(jsonArray.getJSONObject(i).getString("name"));
                            data.setDescription(jsonArray.getJSONObject(i).getString("description"));
                            data.setCategory_name(jsonArray.getJSONObject(i).getString("category_name"));
                            data.setPrice(jsonArray.getJSONObject(i).getString("price"));

                            list.add(data);
                        }

                       dataModelArrayList = list;
                       
                       DataAdapter adapter = new DataAdapter(MainActivity.this, dataModelArrayList);
                       listview.setAdapter(adapter);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }catch (Exception ex) {
                    ex.printStackTrace();
                    Toast.makeText(MainActivity.this, "Network Error", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t)
            {
                t.printStackTrace();
                Toast.makeText(MainActivity.this, "Network Error", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

Monday, 22 July 2019

Android Make A New Phone Call, Email, Text SMS, Whatsapp SMS, Open Browser

1) Add This In Manifest.xml


 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 


Create a new folder name anim in res folder
Animation Files in anim folder


one.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="900"
    android:startOffset="500"
    android:interpolator="@android:anim/accelerate_interpolator"
    >

    <translate
        android:fromYDelta="200"
        android:toYDelta="1"
        />

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        />

</set>

two.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="800"
    android:startOffset="500"
    android:interpolator="@android:anim/accelerate_interpolator"
    >

    <translate
        android:fromYDelta="200"
        android:toYDelta="0"
        />

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        />

</set>

three.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="900"
    android:startOffset="500"
    android:interpolator="@android:anim/accelerate_interpolator"
    >

    <translate
        android:fromXDelta="200"
        android:toXDelta="1"
        />

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        />

</set>


Activity Files


Splash.xml




<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:background="#35F9BD"

    android:gravity="center"

    tools:context=".Splash">





    <ImageView

        android:id="@+id/spashLogo"

        android:layout_width="300dp"

        android:layout_height="300dp"

        android:src="@drawable/logo"/>



    <TextView

        android:id="@+id/tvWelcome"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Welcome"

        android:textSize="35sp"

        android:textStyle="bold"

        android:textColor="@android:color/holo_orange_dark"/>



</LinearLayout>


Splash.java


public class Splash extends AppCompatActivity {

    ImageView spashLogo;
    TextView tvWelcome;
    Animation one, two;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        spashLogo = (ImageView) findViewById(R.id.spashLogo);
        tvWelcome = (TextView) findViewById(R.id.tvWelcome);
        one = AnimationUtils.loadAnimation(this, R.anim.one);
        two = AnimationUtils.loadAnimation(this, R.anim.two);

        spashLogo.startAnimation(one);
        tvWelcome.startAnimation(two);


        new Handler().postDelayed(new Runnable() {

            @Override

            public void run() {

                Intent i = new Intent(Splash.this, MainActivity.class);

                startActivity(i);

                finish();

            }

        }, 3*1000);


    }
}

MainActivity.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F9FBFF"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:layout_width="match_parent"
            android:layout_height="230dp"
            android:background="@drawable/bgheader"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Home"
            android:textSize="25sp"
            android:textStyle="bold"
            android:textColor="@android:color/white"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"/>
    </RelativeLayout>



    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="182dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:background="@drawable/bgmenus"
        android:orientation="vertical"
        android:layout_marginTop="-150dp">

        <TextView
            android:id="@+id/mainmenus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="12dp"
            android:text="Main Menus"
            android:textColor="#818181"
            android:textSize="16sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="4">

            <LinearLayout
                android:id="@+id/youtube"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical"
                android:onClick="Youtube">

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_marginBottom="8dp"
                    android:src="@drawable/youtube" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Youtube"
                    android:textColor="#172646"
                    android:textSize="16sp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/instagram"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical"
                android:onClick="Instagram">

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_marginBottom="8dp"
                    android:src="@drawable/instagram" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Instagram"
                    android:textColor="#172646"
                    android:textSize="16sp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linkedin"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical"
                android:onClick="Linked">

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_marginBottom="8dp"
                    android:src="@drawable/linkid" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="LinkedIn"
                    android:textColor="#172646"
                    android:textSize="16sp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/twitter"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical"
                android:onClick="Twitter">

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_marginBottom="8dp"
                    android:src="@drawable/twitter" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="twitter"
                    android:textColor="#172646"
                    android:textSize="16sp" />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/layoutOne">

        <LinearLayout

                android:layout_width="1.1in"
                android:layout_height="182dp"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:background="@drawable/bgmenus"
                android:gravity="center"
                android:orientation="vertical"
                android:id="@+id/call"
                android:onClick="call">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher_round"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Open Call"
                android:textColor="@android:color/black"
                android:textSize="20sp" />



        </LinearLayout>

        <LinearLayout

                android:layout_width="1.1in"
                android:layout_height="182dp"
                android:background="@drawable/bgmenus"
                android:gravity="center"
                android:orientation="vertical"
                android:id="@+id/mail"
                android:onClick="mail">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher_round"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Open Gmail"
                    android:textColor="@android:color/black"
                    android:textSize="20sp"/>



            </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/layoutTwo">

        <LinearLayout

            android:layout_width="1.1in"
            android:layout_height="182dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:background="@drawable/bgmenus"
            android:gravity="center"
            android:orientation="vertical"
            android:id="@+id/whatsapp"
            android:onClick="whatsapp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher_round"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send Whatsapp"
                android:textColor="@android:color/black"
                android:textSize="20sp"/>



        </LinearLayout>

        <LinearLayout

            android:layout_width="1.1in"
            android:layout_height="182dp"
            android:background="@drawable/bgmenus"
            android:gravity="center"
            android:orientation="vertical"
            android:id="@+id/textsms"
            android:onClick="textsms">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher_round"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send Text SMS"
                android:textColor="@android:color/black"
                android:textSize="20sp"/>



        </LinearLayout>
    </LinearLayout>


</LinearLayout>


MainActivity.java


public class MainActivity extends AppCompatActivity {

    LinearLayout youtube, instagram, linkedin, twitter, layoutOne, layoutTwo;
    Animation three;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        youtube = (LinearLayout) findViewById(R.id.youtube);
        instagram = (LinearLayout) findViewById(R.id.instagram);
        linkedin = (LinearLayout) findViewById(R.id.linkedin);
        twitter = (LinearLayout) findViewById(R.id.twitter);
        layoutOne = (LinearLayout) findViewById(R.id.layoutOne);
        layoutTwo = (LinearLayout) findViewById(R.id.layoutTwo);

        three = AnimationUtils.loadAnimation(this, R.anim.three);

        youtube.startAnimation(three);
        instagram.startAnimation(three);
        linkedin.startAnimation(three);
        twitter.startAnimation(three);
        layoutOne.startAnimation(three);
        layoutTwo.startAnimation(three);




    }

    //I Add OnClick Method In XML File
    public void Youtube(View V){
        String url = "https://www.youtube.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    public void Instagram(View V){
        String url = "https://www.instagram.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    public void Linked(View V){
        String url = "/https://in.linkedin.com/";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    public void Twitter(View v){
        String url = "https://twitter.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    public void call(View view){
        int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE);
        if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 1);
        } else {
            Intent callIntent2 = new Intent(Intent.ACTION_CALL);

            callIntent2.setData(Uri.parse("tel:" + "MOBILE_NUMBER"));//change the number

            startActivity(callIntent2);
        }
    }

    public void mail(View view){
        Intent intent = new Intent (Intent.ACTION_VIEW , Uri.parse("mailto:" + "YOUR_MAIL_ID"));
        startActivity(intent);
    }

    public void whatsapp(View view){

        boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
        if (isWhatsappInstalled) {

            Intent sendIntent = new Intent("android.intent.action.MAIN");
            sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
            sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("8689852249") + "@s.whatsapp.net");//phone number without "+" prefix

            startActivity(sendIntent);
        } else {
            Uri uri = Uri.parse("market://details?id=com.whatsapp");
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            Toast.makeText(MainActivity.this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
            startActivity(goToMarket);
        }
    }
    private boolean whatsappInstalledOrNot(String uri) {
        PackageManager pm = getPackageManager();
        boolean app_installed = false;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        } catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }

    public void textsms(View view){
        Uri uri = Uri.parse("smsto:8689852249");
        Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
        intent.putExtra("sms_body", "The SMS text");
        startActivity(intent);
    }

}

Android Studio - Get Current Latitude And Longitude

1. Add this dependencies in your gradle file     implementation 'com.google.android.gms:play-services-location:18.0.0' 2. Add this p...