RecylerView with double adapter(horzondal cards on vertical card item)

dependencies

compile 'com.android.support:recyclerview-v7:26+'
compile 'com.android.support:cardview-v7:26+'

Main2Activity.java

package creopedia.doubleadapterrecyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import java.util.ArrayList;

import creopedia.doubleadapterrecyclerview.Adapters.RecyclerViewDataAdapter;
import creopedia.doubleadapterrecyclerview.Models.SectionDataModel;
import creopedia.doubleadapterrecyclerview.Models.SingleItemModel;

public class Main2Activity extends AppCompatActivity {
    private Toolbar toolbar;


    ArrayList<SectionDataModel> allSampleData;

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

        toolbar = (Toolbar) findViewById(R.id.toolbar);

        allSampleData = new ArrayList<SectionDataModel>();

    /*    if (toolbar != null) {
            setSupportActionBar(toolbar);
            toolbar.setTitle("G PlayStore");

        }*/


        createDummyData();


        RecyclerView my_recycler_view = (RecyclerView) findViewById(R.id.my_recycler_view);

        my_recycler_view.setHasFixedSize(true);

        RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(this, allSampleData);

        my_recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        my_recycler_view.setAdapter(adapter);
    }


    public void createDummyData() {
        for (int i = 1; i <= 5; i++) {

            SectionDataModel dm = new SectionDataModel();

            dm.setHeaderTitle("Section " + i);

            ArrayList<SingleItemModel> singleItem = new ArrayList<SingleItemModel>();
            for (int j = 0; j <= 5; j++) {
                singleItem.add(new SingleItemModel("Item " + j, "URL " + j));
            }

            dm.setAllItemsInSection(singleItem);

            allSampleData.add(dm);

        }
    }
}
//https://stackoverflow.com/questions/44211617/horizontal-recycler-view-with-horizontal-scroll

SectionDataModel

package creopedia.doubleadapterrecyclerview.Models;

import java.util.ArrayList;

/**
 * Created by karthik on 4/29/2018.
 */

public class SectionDataModel {

    private String headerTitle;
    private ArrayList<SingleItemModel> allItemsInSection;

    public String getHeaderTitle() {
        return headerTitle;
    }

    public void setHeaderTitle(String headerTitle) {
        this.headerTitle = headerTitle;
    }

    public ArrayList<SingleItemModel> getAllItemsInSection() {
        return allItemsInSection;
    }

    public void setAllItemsInSection(ArrayList<SingleItemModel> allItemsInSection) {
        this.allItemsInSection = allItemsInSection;
    }

}

SectionDataModel.java

package creopedia.doubleadapterrecyclerview.Models;

import java.util.ArrayList;

/**
 * Created by karthik on 4/29/2018.
 */

public class SectionDataModel {

    private String headerTitle;
    private ArrayList<SingleItemModel> allItemsInSection;

    public String getHeaderTitle() {
        return headerTitle;
    }

    public void setHeaderTitle(String headerTitle) {
        this.headerTitle = headerTitle;
    }

    public ArrayList<SingleItemModel> getAllItemsInSection() {
        return allItemsInSection;
    }

    public void setAllItemsInSection(ArrayList<SingleItemModel> allItemsInSection) {
        this.allItemsInSection = allItemsInSection;
    }

}

SingleItemModel.java

package creopedia.doubleadapterrecyclerview.Models;

/**
 * Created by karthik on 4/29/2018.
 */

public class SingleItemModel {

    private String name;
    private String url;
    private String description;

    public SingleItemModel(String name, String url) {
        this.name = name;
        this.url = url;
    }

    public String getName() {
        return name;
    }

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

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDescription() {
        return description;
    }

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


}

activity_main2.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"
    tools:context="creopedia.doubleadapterrecyclerview.Main2Activity">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="8dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none" />

</LinearLayout>

RecyclerviewDataAdapter.java

package creopedia.doubleadapterrecyclerview.Adapters;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

import creopedia.doubleadapterrecyclerview.Models.SectionDataModel;
import creopedia.doubleadapterrecyclerview.R;

/**
 * Created by karthik on 4/29/2018.
 */

public class RecyclerViewDataAdapter  extends RecyclerView.Adapter<RecyclerViewDataAdapter.ItemRowHolder> {
    private ArrayList<SectionDataModel> dataList;
    private Context mContext;

    public RecyclerViewDataAdapter(Context context, ArrayList<SectionDataModel> dataList) {
        this.dataList = dataList;
        this.mContext = context;
    }

    @Override
    public RecyclerViewDataAdapter.ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, null);
        ItemRowHolder mh = new ItemRowHolder(v);
        return mh;
    }

    @Override
    public void onBindViewHolder(RecyclerViewDataAdapter.ItemRowHolder itemRowHolder, int i) {

        final String sectionName = dataList.get(i).getHeaderTitle();

        ArrayList singleSectionItems = dataList.get(i).getAllItemsInSection();

        itemRowHolder.itemTitle.setText(sectionName);
        SectionListDataAdapter itemListDataAdapter = new SectionListDataAdapter(mContext, singleSectionItems);

        itemRowHolder.recycler_view_list.setHasFixedSize(true);
        itemRowHolder.recycler_view_list.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        itemRowHolder.recycler_view_list.setAdapter(itemListDataAdapter);

        itemRowHolder.btnMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Toast.makeText(v.getContext(), "click event on more, "+sectionName , Toast.LENGTH_SHORT).show();



            }
        });

            /* Glide.with(mContext)
                .load(feedItem.getImageURL())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .error(R.drawable.bg)
                .into(feedListRowHolder.thumbView);*/

    }

    @Override
    public int getItemCount() {
        return (null != dataList ? dataList.size() : 0);
    }


    public class ItemRowHolder extends RecyclerView.ViewHolder {

        protected TextView itemTitle;

        protected RecyclerView recycler_view_list;

        protected Button btnMore;



        public ItemRowHolder(View view) {
            super(view);

            this.itemTitle = (TextView) view.findViewById(R.id.itemTitle);
            this.recycler_view_list = (RecyclerView) view.findViewById(R.id.recycler_view_list);
            this.btnMore= (Button) view.findViewById(R.id.btnMore);


        }

    }

}

List_item.xml

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

    android:background="?android:selectableItemBackground"
    android:orientation="vertical"
    android:padding="5dp">

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


        <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            app:cardCornerRadius="5dp"
            app:cardUseCompatPadding="true"
            android:id="@+id/card"
            >

        <TextView
            android:id="@+id/itemTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_toLeftOf="@+id/btnMore"
            android:text="Sample title"
            android:textColor="@android:color/black"
            android:textSize="18sp" />
        </android.support.v7.widget.CardView>

        <Button
            android:id="@+id/btnMore"
            android:layout_width="wrap_content"
            android:layout_height="42dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="more"
            android:textColor="#FFF" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="horizontal"
            android:layout_marginTop="40dp"
            android:elevation="5dp"/>


    </RelativeLayout>

</LinearLayout>

SectionListDataAdapter.java

package creopedia.doubleadapterrecyclerview.Adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
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 java.util.ArrayList;

import creopedia.doubleadapterrecyclerview.Models.SingleItemModel;
import creopedia.doubleadapterrecyclerview.R;

/**
 * Created by karthik on 4/29/2018.
 */

public class SectionListDataAdapter extends RecyclerView.Adapter<SectionListDataAdapter.SingleItemRowHolder> {

    private ArrayList<SingleItemModel> itemsList;
    private Context mContext;

    public SectionListDataAdapter(Context context, ArrayList<SingleItemModel> itemsList) {
        this.itemsList = itemsList;
        this.mContext = context;
    }

    @Override
    public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_single_card, null);
        SingleItemRowHolder mh = new SingleItemRowHolder(v);
        return mh;
    }

    @Override
    public void onBindViewHolder(SingleItemRowHolder holder, int i) {

        SingleItemModel singleItem = itemsList.get(i);

        holder.tvTitle.setText(singleItem.getName());


       /* Glide.with(mContext)
                .load(feedItem.getImageURL())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .error(R.drawable.bg)
                .into(feedListRowHolder.thumbView);*/
    }

    @Override
    public int getItemCount() {
        return (null != itemsList ? itemsList.size() : 0);
    }

    public class SingleItemRowHolder extends RecyclerView.ViewHolder {

        protected TextView tvTitle;

        protected ImageView itemImage;


        public SingleItemRowHolder(View view) {
            super(view);

            this.tvTitle = (TextView) view.findViewById(R.id.tvTitle);
            this.itemImage = (ImageView) view.findViewById(R.id.itemImage);


            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                    Toast.makeText(v.getContext(), tvTitle.getText(), Toast.LENGTH_SHORT).show();

                }
            });


        }

    }

}

list_singlecard.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:cardCornerRadius="5dp"
    app:cardUseCompatPadding="true"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:background="?android:selectableItemBackground"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/itemImage"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_launcher_background" />


        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/itemImage"
            android:gravity="center"
            android:padding="5dp"
            android:text="Sample title"
            android:textColor="@android:color/black"
            android:textSize="18sp" />


    </LinearLayout>

</android.support.v7.widget.CardView>

link

https://stackoverflow.com/questions/44211617/horizontal-recycler-view-with-horizontal-scroll

Custom Progress bar- with multiple colors

 

reference link

https://android-dev-examples.blogspot.in/2014/09/android-custom-horizontal-progressbar.html

progrossactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:padding="20dp">
 <ProgressBar
  style="@android:style/Widget.ProgressBar.Horizontal"
  android:layout_centerInParent="true"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:max="100"
  android:progress="50"
  android:progressDrawable="@drawable/progress_drawable" />
</RelativeLayout>

Progress_drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:id="@android:id/background">
  <shape>
   <solid android:color="#777" />
   <size
    android:width="15dp"
    android:height="15dp" />
   <corners android:radius="10dp" />
  </shape>
 </item>
 <item android:id="@android:id/progress">
  <clip>
   <layer-list>
    <item>
     <color android:color="#00000000" />
    </item>
    <item
     android:left="2dp"
     android:top="2dp"
     android:right="2dp"
     android:bottom="2dp">
     <shape>
      <gradient
       android:startColor="#00FF00"
       android:centerColor="#FFFF00"
       android:endColor="#FF0000" />
      <size
       android:width="15dp"
       android:height="15dp" />
      <corners android:radius="10dp" />
     </shape>
    </item>
   </layer-list>
  </clip>
 </item>
</layer-list>

 

Custom Navigation drawer in android

abarmain.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="nithra.mydrawertwo.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
<!--
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"

         />-->

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/nav_view"
        android:layout_gravity="start"

        >

        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#ea0fcd"
            android:id="@+id/lin_security"
            android:layout_gravity="start"

            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:src="@drawable/key"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Security"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#a306c4"
            android:id="@+id/lin_not"
            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/notification"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Notification"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#6707ed"
            android:id="@+id/lin_alapp"
            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/all_app"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="All Apps"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#2280ec"
            android:id="@+id/lin_backup"
            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/backp"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Back Up"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#07bfed"
            android:id="@+id/lin_exit"
            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/exit"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Exit"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:background="#0fe4d2"
            android:id="@+id/lin_fdback"
            >
            <ImageView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/feedback"
                android:layout_gravity="center"
                />
            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Feedback"
                android:layout_marginLeft="5dp"
                android:layout_gravity="center"
                android:textColor="#ffffff"
                android:textStyle="bold"/>
        </LinearLayout>

    </LinearLayout>


</android.support.v4.widget.DrawerLayout>

MainActivity.java

package nithra.mydrawertwo;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;

import yalantis.com.sidemenu.interfaces.Resourceble;
import yalantis.com.sidemenu.util.ViewAnimator;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener {
    LinearLayout lin_security, lin_not, lin_alapp, lin_backup, lin_exit, lin_fdback;
    DrawerLayout drawer;
    LinearLayout navigationView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
       FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

      drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();


        navigationView = (LinearLayout) findViewById(R.id.nav_view);
        lin_security = (LinearLayout) findViewById(R.id.lin_security);
        lin_not = (LinearLayout) findViewById(R.id.lin_not);
        lin_alapp = (LinearLayout) findViewById(R.id.lin_alapp);
        lin_backup = (LinearLayout) findViewById(R.id.lin_backup);
        lin_exit = (LinearLayout) findViewById(R.id.lin_exit);
        lin_fdback = (LinearLayout) findViewById(R.id.lin_fdback);


        lin_alapp.setOnClickListener(this);
        lin_backup.setOnClickListener(this);
        lin_exit.setOnClickListener(this);
        lin_not.setOnClickListener(this);
        lin_fdback.setOnClickListener(this);
        lin_security.setOnClickListener(this);





        /*navigationView.setNavigationItemSelectedListener(this);*/
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onClick(View v) {

        int id = v.getId();
        switch (id) {
            case R.id.lin_security: {

                Intent i=new Intent(MainActivity.this,Loginact.class);
                startActivity(i);
                drawer.closeDrawer(navigationView);
            }
            break;
            case R.id.lin_alapp: {
                Toast.makeText(MainActivity.this, "all apps", Toast.LENGTH_SHORT).show();
                drawer.closeDrawer(navigationView);
            }
            break;
            case R.id.lin_backup: {
                Toast.makeText(MainActivity.this, "back up", Toast.LENGTH_SHORT).show();
                drawer.closeDrawer(navigationView);
            }
            break;
            case R.id.lin_exit: {
                Toast.makeText(MainActivity.this, "exit", Toast.LENGTH_SHORT).show();
                drawer.closeDrawer(navigationView);
            }
            break;
            case R.id.lin_fdback: {
                Toast.makeText(MainActivity.this, "feedback", Toast.LENGTH_SHORT).show();
                drawer.closeDrawer(navigationView);

            }
            break;
            case R.id.lin_not: {
                Toast.makeText(MainActivity.this, "notification", Toast.LENGTH_SHORT).show();
                drawer.closeDrawer(navigationView);
            }
            break;

        }
    }
}

update one-Google map integration

step1

Refer this link : create google map activity and get link paste it in browser, and then get app key .replace in your project

ref link:

https://www.androidtutorialpoint.com/intermediate/android-map-app-showing-current-location-android/

this covered

  • map points to sydiney location(default),
  • map point to current location.
  • map points to searched location.
  • types of map views(normal,satilite,teri…..etc)

code

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="creopedia.myshopping">


      <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-feature android:name="android.hardware.location.gps" />

     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />



    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />


        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" />
        <activity
            android:name=".MapActivity"/>

        <activity android:name=".LocationPickerActivity"/>
    </application>

</manifest>

build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
       // classpath 'com.google.gms:google-services:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url "https//maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

buildgradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "creopedia.myshopping"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.google.android.gms:play-services:12.0.1'

}
//apply plugin: 'com.google.gms.google-services'

/*
implementation 'com.google.android.gms:play-services-places:12.0.1'
compile 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services-maps:12.0.1'*/

activitymaps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rel"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="creopedia.myshopping.MapsActivity"
    android:background="@color/white">

<fragment android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
  android:layout_above="@+id/btn_pic_loc"
 />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:elevation="10dp"
        android:background="@drawable/white_border"
        android:id="@+id/relLayout1">
        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:textSize="15sp"
            android:textColor="#000"
            android:background="@null"
            android:hint="Enter Address, City or Zip Code"
            android:imeOptions="actionSearch"
            android:layout_marginLeft="5dp"
            />

        <ImageView
            android:id="@+id/search_button"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_magnify"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:onClick="onMapSearch"
           />
    </RelativeLayout>
    <Button
        android:id="@+id/btn_pic_loc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button"
        android:background="@color/colorPrimary"
        android:textColor="@color/white"/>
</RelativeLayout>

MapsActivity.java

package creopedia.myshopping;

import android.*;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    //To store longitude and latitude from map
    private double longitude;
    private double latitude;
    public static final int LOCATION_UPDATE_MIN_DISTANCE = 10;
    public static final int LOCATION_UPDATE_MIN_TIME = 5000;
    private LocationManager mLocationManager;
    private static final float DEFAULT_ZOOM = 15f;
    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;

    //Google ApiClient
    private GoogleApiClient googleApiClient;
    private static final String FINE_LOCATION = android.Manifest.permission.ACCESS_FINE_LOCATION;
    private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
    //vars
    private Boolean mLocationPermissionsGranted = false;

    private LocationListener mLocationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
          // Logger.d(String.format("%f, %f", location.getLatitude(), location.getLongitude()));

                drawMarker();
                mLocationManager.removeUpdates(mLocationListener);
            } else {
                // Logger.d("Location is null");
            }
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {

        }

        @Override
        public void onProviderEnabled(String s) {

        }

        @Override
        public void onProviderDisabled(String s) {

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        if (mLocationPermissionsGranted) {

            // 1. Add a marker in Sydney and move the camera
            LatLng sydney = new LatLng(-34, 151);
            mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

       /* if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            return;
        }
        mMap.setMyLocationEnabled(true);*/

            //2. to set current location
            mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            initMap();
            //statusCheck();
        }else{
           getLocationPermission();
        }

    }


    private void initMap() {
        int googlePlayStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (googlePlayStatus != ConnectionResult.SUCCESS) {
            GooglePlayServicesUtil.getErrorDialog(googlePlayStatus, this, -1).show();
            finish();
        } else {
            if (mMap != null) {

                if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }
                mMap.setMyLocationEnabled(true);
                mMap.getUiSettings().setMyLocationButtonEnabled(true);
                mMap.getUiSettings().setAllGesturesEnabled(true);
            }
        }
    }



    private void drawMarker() {

        // check if GPS enabled
        GPSTracker gpsTracker = new GPSTracker(this);

        if (gpsTracker.getIsGPSTrackingEnabled()) {
            if (mMap != null) {
                mMap.clear();
                LatLng gps = new LatLng(gpsTracker.getLatitude(), gpsTracker.getLongitude());
                //Adding marker to map
                mMap.addMarker(new MarkerOptions()
                        .position(gps)//setting position
                        //.draggable(true) //Making the marker draggable
                        .title("Current Position")); //Adding a title
                //Animating the camera
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(gps, 12));

                //Moving the camera
                //  mMap.moveCamera(CameraUpdateFactory.newLatLng(gps));


                //String to display current latitude and longitude
                //String msg = location.getLatitude() + ", " + location.getLongitude();


                //Displaying current coordinates in toast
                //Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
            }
        }

    }



    //3. search and get location in google map
    public void onMapSearch(View view) {
        EditText locationSearch = (EditText) findViewById(R.id.editText);
        String location = locationSearch.getText().toString();
        List<Address> addressList = null;

        if (location != null || !location.equals("")) {
            Geocoder geocoder = new Geocoder(this);
            try {
                addressList = geocoder.getFromLocationName(location, 1);

            } catch (IOException e) {
                e.printStackTrace();
            }
            Address address = addressList.get(0);
            LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
            mMap.clear();
            moveCamera(new LatLng(address.getLatitude(), address.getLongitude()), DEFAULT_ZOOM,
                    address.getAddressLine(0));
            //mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
          //  mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
        }
    }

    private void moveCamera(LatLng latLng, float zoom, String title){
        Log.d("MapsAct", "moveCamera: moving the camera to: lat: " + latLng.latitude + ", lng: " + latLng.longitude );
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));

        if(!title.equals("My Location")){
            MarkerOptions options = new MarkerOptions()
                    .position(latLng)
                    .title(title);
            mMap.addMarker(options);
        }

    }

    

   
    private void getLocationPermission(){
        Log.d("MapsActivity", "getLocationPermission: getting location permissions");
        String[] permissions = {android.Manifest.permission.ACCESS_FINE_LOCATION,
                android.Manifest.permission.ACCESS_COARSE_LOCATION};

        if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
                FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
            if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
                    COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED){
                mLocationPermissionsGranted = true;
                initMap();
                foo(MapsActivity.this);
            }else{
                ActivityCompat.requestPermissions(this,
                        permissions,
                        LOCATION_PERMISSION_REQUEST_CODE);
            }
        }else{
            ActivityCompat.requestPermissions(this,
                    permissions,
                    LOCATION_PERMISSION_REQUEST_CODE);
        }


      
    }





    public void foo(Context context) {
        // when you need location
        // if inside activity context = this;

        SingleShotLocationProvider.requestSingleUpdate(context,
                new SingleShotLocationProvider.LocationCallback() {
                    @Override
                    public void onNewLocationAvailable(SingleShotLocationProvider.GPSCoordinates location) {
                        Log.d("Location", "my location is " + location.toString());
                       if (mMap != null) {
                               // mMap.clear();
                                LatLng gps = new LatLng(location.latitude, location.longitude);
                                //Adding marker to map
                                mMap.addMarker(new MarkerOptions()
                                        .position(gps)//setting position
                                        //.draggable(true) //Making the marker draggable
                                        .title("Current Position")); //Adding a title
                                //Animating the camera
                                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(gps, 12));
                            }

                    }



                });

    }




}


//reference links
// http://www.viralandroid.com/2016/04/changing-map-type-google-maps-android-api-tutorial.html

SingleShotLocationProvider.java

package creopedia.myshopping;

import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;

/**
 * Created by karthik on 4/16/2018.
 */

public class SingleShotLocationProvider {

    public static interface LocationCallback {
        public void onNewLocationAvailable(GPSCoordinates location);
    }

    // calls back to calling thread, note this is for low grain: if you want higher precision, swap the
    // contents of the else and if. Also be sure to check gps permission/settings are allowed.
    // call usually takes <10ms
    public static void requestSingleUpdate(final Context context, final LocationCallback callback) {
        final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (isNetworkEnabled) {
            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            locationManager.requestSingleUpdate(criteria, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    callback.onNewLocationAvailable(new GPSCoordinates(location.getLatitude(), location.getLongitude()));
                }

                @Override
                public void onStatusChanged(String provider, int status, Bundle extras) {
                }

                @Override
                public void onProviderEnabled(String provider) {
                }

                @Override
                public void onProviderDisabled(String provider) {
                }
            }, null);
        } else {
            boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            if (isGPSEnabled) {
                Criteria criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }
                locationManager.requestSingleUpdate(criteria, new LocationListener() {
                    @Override
                    public void onLocationChanged(Location location) {
                        callback.onNewLocationAvailable(new GPSCoordinates(location.getLatitude(), location.getLongitude()));
                    }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                    }
                }, null);
            }
        }
    }


    // consider returning Location instead of this dummy wrapper class
    public static class GPSCoordinates {
        public float longitude = -1;
        public float latitude = -1;

        public GPSCoordinates(float theLatitude, float theLongitude) {
            longitude = theLongitude;
            latitude = theLatitude;
        }

        public GPSCoordinates(double theLatitude, double theLongitude) {
            longitude = (float) theLongitude;
            latitude = (float) theLatitude;
        }
    }
}

FCM-Custom Push NOtification

steps

  1. Tools checkup
  2.  Fire base console – register app
  3.  Project Modifications
  4. sending key-values to firebase using ART(google – Advanced rest client)

1.Tools Check up

i) min api level   9 – android 2.3(Android studio)

ii) Play services 9.0 or later (Emulator)

if its not go to app-play services and update it to newer version

iii) sdk manager(android)

  •   play services revison 30 or above
  • google reprository 26 and above

if its not go to sdk manager select and download or update it

2.Fire base console – register app

create android project

https://console.firebase.google.com/ – go to this link. choose add project and give project name, select country and press create project.

now give package name, download json file. paste it in your andoir app folder .

then enable  authendication with gmail password in fire base console.

(note: for newer version 3.0.0 above we can add it by using tools–>fire base–>notification)

3. Project Modifications

build.gradle(project:mynotification)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        jcenter()
        mavenLocal()
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}



allprojects {
    repositories {
        jcenter()
        mavenLocal()
        maven {
            url 'https://maven.google.com'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(app:module)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.example.mboxuser.mynotification"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta1'
   // compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:9.2.1'
    compile 'com.firebase:firebase-jobdispatcher:0.8.5'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mboxuser.mynotification">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK"/>


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name=".MyAndroidFirebaseMsgService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name=".MyAndroidFirebaseInstanceIdService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>


    </application>

</manifest>

activity_main.xml

package com.example.mboxuser.mynotification;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import com.firebase.jobdispatcher.Trigger;
import com.google.firebase.iid.FirebaseInstanceId;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();
  /*  public static final String MyPREFERENCES = "mynoti" ;
    SharedPreferences sharedpreferences;*/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String tokenFirebase = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + tokenFirebase);


    }}

 

MainActivity.java

package com.example.mboxuser.mynotification;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import com.firebase.jobdispatcher.Trigger;
import com.google.firebase.iid.FirebaseInstanceId;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();
  /*  public static final String MyPREFERENCES = "mynoti" ;
    SharedPreferences sharedpreferences;*/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String tokenFirebase = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + tokenFirebase);


    }}

MyAndroidFirebaseMsgService.java

package com.example.mboxuser.mynotification;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.RemoteViews;

import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import com.firebase.jobdispatcher.Trigger;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.net.URL;
import java.util.Map;

import static android.app.PendingIntent.FLAG_ONE_SHOT;
import static android.support.v7.appcompat.R.id.info;

/**
* Created by mboxuser on 2/15/2018.
*/

public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
RemoteViews contentViewBig, contentViewSmall;

String imgUrl = “”;
String appImgUrl = “”;
String notifTitle = “”;
String notifText = “”;
String activity = “ResultActivity.class”;
String name = “”;
Intent notificationIntent;

// private static final String TAG = “MyAndroidFCMService”;
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {

new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
public void run() {
new GenerateNotification(getApplicationContext(),
remoteMessage.getData().get(“title”),
remoteMessage.getData().get(“message”),remoteMessage.getData().get(“activity”)).execute(remoteMessage.getData().get(“url”));
}
}, 100);

 

}

 

}

GenerateNotification.java

package com.example.mboxuser.mynotification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
* Created by ARUN on 2/18/2018.
*/

public class GenerateNotification extends AsyncTask<String, Void, Bitmap> {

Context ctx;
String message = “”, title = “”,activity = “ResultActivity.class”;

private static final int REQUEST_CODE = 1;
private static final int NOTIFICATION_ID = 100;
Bitmap myBitmap;
RemoteViews contentViewBig, contentViewSmall;
String imgUrl = “”;
Intent notificationIntent;

public GenerateNotification(Context ctx, String message, String title,String activity) {
this.ctx = ctx;
this.message = message;
this.title = title;
this.activity=activity;
}

@Override
protected Bitmap doInBackground(String… params) {
InputStream in;
try {

URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
in = connection.getInputStream();
myBitmap= BitmapFactory.decodeStream(in);
return myBitmap;

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Bitmap result) {

super.onPostExecute(result);
try {
long when = System.currentTimeMillis();

 

NotificationManager mNotificationManager = (NotificationManager)ctx.getSystemService(ctx.NOTIFICATION_SERVICE);
contentViewBig = new RemoteViews(ctx.getPackageName(), R.layout.custom_notification);
contentViewSmall = new RemoteViews(ctx.getPackageName(),R.layout.custom_notification_small);
//Null and Empty checks for your Key Value Pairs
/* if(imgUrl!=null && !imgUrl.isEmpty()) {
URL imgUrlLink = new URL(imgUrl);
contentViewBig.setImageViewBitmap(R.id.image_pic, BitmapFactory.decodeStream(imgUrlLink.openConnection().getInputStream()));
}
if(appImgUrl!=null && !appImgUrl.isEmpty()) {
URL appImgUrlLink = new URL(appImgUrl);
contentViewBig.setImageViewBitmap(R.id.image_app, BitmapFactory.decodeStream(appImgUrlLink.openConnection().getInputStream()));
contentViewSmall.setImageViewBitmap(R.id.image_app, BitmapFactory.decodeStream(appImgUrlLink.openConnection().getInputStream()));
}*/

if(result!=null){
contentViewBig.setImageViewBitmap(R.id.bimage_pic,result);
//contentViewSmall.setImageViewBitmap(R.id.simage_app,result);
}

 

if(title!=null && !title.isEmpty()) {
contentViewBig.setTextViewText(R.id.btitle, title);
contentViewSmall.setTextViewText(R.id.stitle, title);
}

if(message!=null && !message.isEmpty()) {
contentViewBig.setTextViewText(R.id.btext, message);
contentViewSmall.setTextViewText(R.id.stext, message);
}

 

if(activity.equals(“MainActivity”)){
notificationIntent = new Intent(ctx,MainActivity.class);}
else{
notificationIntent = new Intent(ctx,ResultActivity.class);
}

notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent contentIntent = PendingIntent.getActivity(ctx,REQUEST_CODE , notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ctx)
.setSmallIcon(R.mipmap.ic_launcher)
.setCustomContentView(contentViewSmall)
.setCustomBigContentView(contentViewBig)
.setContentTitle(“Custom Notification”)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setWhen(when);

mNotificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());

 

} catch (Exception e) {
e.printStackTrace();
}
}

}

//server – notification // – http://androidbash.com/firebase-push-notification-android/

custom_notification_small.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:id=”@+id/layout”
android:background=”@android:color/white”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding=”10dp” >

<ImageView android:id=”@+id/simage_app”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_marginRight=”10dp”
android:src=”@mipmap/ic_launcher_round”/>
<TextView android:id=”@+id/stitle”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Title”
android:layout_toRightOf=”@+id/simage_app”
android:textAppearance=”@style/TextAppearance.AppCompat.Headline”
android:textColor=”@android:color/black”
style=”Custom Notification Title” />
<TextView android:id=”@+id/stext”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textColor=”@android:color/black”
android:layout_toRightOf=”@+id/simage_app”
android:text=”Text”
android:layout_below=”@id/stitle”
style=”Custom Notification Text” />
</RelativeLayout>

custom_notification.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:id=”@+id/layout”
android:background=”@android:color/white”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>
<RelativeLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:id=”@+id/rel_lyt”
android:padding=”10dp”>
<ImageView android:id=”@+id/bimage_app”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:src=”@mipmap/ic_launcher_round”/>
<TextView android:id=”@+id/btitle”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Title”
android:layout_toRightOf=”@+id/bimage_app”
android:textAppearance=”@style/TextAppearance.AppCompat.Headline”
android:textColor=”@android:color/black”
style=”Custom Notification Title” />

<TextView android:id=”@+id/btext”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textColor=”@android:color/black”
android:layout_toRightOf=”@+id/bimage_app”
android:text=”Text”
android:layout_below=”@id/btitle”
style=”Custom Notification Text” />

</RelativeLayout>
<ImageView android:id=”@+id/bimage_pic”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:src=”@drawable/notimage”
android:layout_below=”@+id/rel_lyt”
/>

</RelativeLayout>

Android Squlite DB – create db and fetch data in db

public class MainActivity extends AppCompatActivity{

//decleration
SQLiteDatabase mydb,indb;

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

//defenition

mydb=this.openOrCreateDatabase(“myDB”, MODE_PRIVATE, null);
indb = openOrCreateDatabase(“Expense_manage”, Context.MODE_PRIVATE, null);

//create incometable table in indb data base

indb.execSQL(“CREATE TABLE IF NOT EXISTS incometable(ID integer primary key autoincrement,iID integer,Type varchar,Amount float” + /*income table*/
“,sDate varchar,eDate varchar,sTime varchar,Remarks varchar,inimage BLOB,iday integer,imonth integer,iyear integer );”);

create itypes table in indb data base

indb.execSQL(“CREATE TABLE IF NOT EXISTS itypes_table(ID integer primary key autoincrement,iID integer,Type varchar,changed varchar);”);

// inserting values in to itypes table

Cursor c = indb.rawQuery(“select * from itypes_table”, null);

if (c.getCount() == 0) {

indb.execSQL(“insert into itypes_table (iID,Type,changed) values (‘1′,’BUSINESS’,’1′)”);
}

// insert values into itypes table
Cursor c = indb.rawQuery(“select * from incometable”, null);

if (c.getCount() == 0) {
h = 1;
} else {
c.moveToLast();
h = (c.getInt(c.getColumnIndex(“iID”)) + 1);

}

ContentValues values = new ContentValues();
values.put(“iID”, h);

if (Str != spinner.getItemAtPosition(0)) {
values.put(“Type”, Str);
}

values.put(“Amount”, edt_amount.getText().toString());
values.put(“eDate”, str_year + “-” + str_month + “-” + str_day);

String currentTime = DateFormat.getTimeInstance().format(new Date());
time_text.setText(currentTime);
String currentdate = DateFormat.getDateInstance().format(new Date());
currentdate_text.setText(currentdate);

values.put(“sDate”, currentdate_text.getText().toString());
values.put(“sTime”, time_text.getText().toString());
String s = edt_remarks.getText().toString();

String sb = s.replaceAll(“(.{25})”, “$1\n”);
if (sb.length() == 0) {
values.put(“Remarks”, “NA”);
} else {
values.put(“Remarks”, sb);
}
if(byteArray!=null){
values.put(“inimage”,byteArray);
}else{
values.put(“inimage”,emptyArray);
}

values.put(“iday”, mday);
values.put(“imonth”, (mmonth + 1));
values.put(“iyear”, myear);

indb.insert(“incometable”, null, values);
Toast.makeText(getActivity(), “Income added successfully”, Toast.LENGTH_SHORT).show();

edt_amount.setText(“”);
edt_date.setText(“”);
edt_remarks.setText(“”);
spinner.setSelection(0);
edit.remove(“cal_rst”);
edit.commit();
byteArray=null;

Intent intent = new Intent(context, Income_history.class);
context.finish();
startActivity(intent);
getActivity().overridePendingTransition(R.anim.slide, R.anim.slide2);
}

}

}