Google finally revealed Android N, which is Android Nougat, not Nutella, the name predicted by most of Android lovers before. 
Google revealed Android Nougat on June 30th , 2016, Google asked for suggestion for the name during Google IO in May. As we already know Android Nougat will have cool features like Multi-Window Support, The Notification Shade, Improvement in Doze Mode,  Better Data Saving, and new settings menu.



Android Nougat which will be available later this summer, can be downloaded as beta from google developer website. Android Nougat preview is available for Nexus5X, Nexus 6P, Nexus 6, Nexus 9, and Nexus Player.





Google announced today that name of new Android M is Marshmallow. Next version is believed to be released this fall. With the announcement of Android M Developer Preview in May at Google IO, the guessing started for the name of next version of Android. However Android M was called Android Macadamia Nut Cookie (or MNC in short) internally as seen during Android 6.0 SDK update, Google officially announced that it’s Android Marshmallow.

New android version will have several enhancements over the Lollipop version. Besides new exciting features include, better permission management, Android Pay and USB Type-C support.


Android Marshmallow will be released soon with new Nexus Devices form LG and Huawei. 






In May, Google Announced new version of Android operating system ‘Android M’ which is now named Marshmallow. With the release of Android M Developer Preview during the Google IO earlier this year, we got a glimpse of what is being cooked as new Android version and after a couple of Developer Preview updates We finally have final Developer Preview version of System images available for Nexus devices. That means Android Marshmallow is coming soon. With the release of Android version, another exciting part is the Nexus device.There have been rumors that Huawei is manufacturing the next nexus device. But recently Business Korea wrote about LG releasing next Nexus phone in October. So, the chances are, we will have two nexus phones each form LG and Huawei.

After huge fame of Nexus 4 and Nexus 5, Nexus 6 couldn’t come at the same level of popularity. It was not because of the lack of good hardware though. Specs of Nexus 6 are sophisticated enough to be in the top of the line of Android high end devices. Only factor that made Nexus 6 from Motorola less popular was it’s size. Not all android users prefer phablets for daily use. Next Nexus devices are reported to be 5inch and 5.7inch form LG and Huawei respectively. Huawei having limited market penetration in the smartphone world LG nexus could be weigh more in the popularity scale. From the leaked photos of new LG Nexus 5 (2015), we can see Android Pay is one of the most promising feature of next LG flagship. 


Android is one of the top mobile operating systems. With over 1.5 million android apps, android devices are so popular that we have apps for almost everything. 

Don’t you think it would be a great to have android apps running on your computer? 
Yes, you are right. We can run android apps on computers. There are various ways of running android apps on computer but Android Runtime for Chrome allows you to run android apps on computers on Chrome .

Android Runtime for Chrome, also called ARC, allows you to run Android apps inside chrome. ARC has been a major development in the process of bringing android apps to Chrome OS. You can use Arc with Chrome on Windows, OS X  or Linux.


Installing ARC Welder











After you download ARC Welder app it will appear on your Chrome App Launcher.


Click on it and add APK file. I used Loadshedding+ apk file. We can not download apk files directly to computer form play store but we can get apk files from various sources. For example, you can use websites like downloader-apk.com for downloading apk files. 




Once you have downloaded added the file you can select Orientation and form factor. Then click Test.




















The App opens and you can enjoy your favorite android apps on Chrome. Then the app is also pinned on Chrome app launcher so that you can launch the app clicking the app icon later.





Now download your favorite app and run on Chrome browser. 



In our previous tutorial about Navigation Drawer we saw how to create a navigation drawer using RecyclerView. Before Support Design Library was introduced we had to create navigation drawer using RecyclerView or ListView. We saw in two part series of the tutorial, how much work needed to create a Navigation drawer. It included the setting up adapter, creating different view types and implementing our own listener for selecting Menus.





NavigationView from Design Support Library comes really handy when we want to add Navigation Drawer to our app. Let's create a Navigation Drawer using NavigationView like the screenshot below.




Let's create an Android project with Blank Activity template and add a Toolbar, We will be using Toolbar instead of Actionbar so in values/styles.xml use theme with NoActionbar. Set toolbar as the actionbar of Mainactivity. So MainActivity.java looks like this.



public class MainActivity extends AppCompatActivity {

    private Toolbar mToolbar;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        mToolbar = (Toolbar)findViewById(R.id.appBar);
        setSupportActionBar(mToolbar);
    }


}


Since we will be using NavigationView from Design Support Library, let's at that to the dependencies. Open build.gradle file from app module and add following lines.
OR you can just select the project and hit f4 to open the Project Structure dialog and select dependencies tab , click plus icon at the bottom select library dependency and search recyclerview and select the following library from the list to include it.


    compile 'com.android.support:design:22.2.1'





Best thing about NavigationView is that we don't have to create layouts for each menu item as it uses our existing menu system. if you already have created new android project, let's add a menu called menu_nav_drawer.xml.


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_inbox"
        android:orderInCategory="100"
        android:title="@string/inbox"
        android:icon="@drawable/inbox"
        app:showAsAction="never" />
    <item
        android:id="@+id/menu_send"
        android:orderInCategory="200"
        android:title="@string/send"
        android:icon="@drawable/send"
        app:showAsAction="never" />

</menu>



We just created two menu items, Inbox and Send, If you need icons for them, please download from here.

Next, we create layout for Main activity, in change activity_main.xml as below.


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/abc_action_bar_default_height_material"
        android:background="#00bbff"/>



    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appBar">
        <!--Content-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/app_name" />

        </LinearLayout>

        <!-- Navigation Drawer-->
        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:menu="@menu/menu_nav_drawer"
            android:layout_gravity="left"/>

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

</RelativeLayout>

Here, we are using a LinearLayout for our content with a TextView in it. And for Navigation drawer we are using NavigationView.

In navigation we can set up the menu using menu attribute.  We assigned the menu that we created in XML.


            app:menu="@menu/menu_nav_drawer"


Now if you run the project you will see navigation drawer is all set with menu titles and icons





Now Let's add the ActionbarDrawerToggle to add nice icons.


        mDrawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout);


        ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close);

        mDrawerLayout.setDrawerListener(drawerToggle);
        drawerToggle.syncState();



Now finally let's add Listener to the menu items.


             mNavigationView.setNavigationItemSelectedListener(
                        new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                if (menuItem.getItemId() == R.id.menu_inbox) {
                    Toast.makeText(MainActivity.this, 
                                  "Selected Inbox", 
                                  Toast.LENGTH_SHORT).show();
                    mDrawerLayout.closeDrawer(mNavigationView);
                }
                return false;
            }
        });



Finally add a header view. For that just create a layout and use addHeaderView method on NavigationView.



       View view = getLayoutInflater().inflate(R.layout.layout_drawer_header, 
                   mNavigationView, false);

        mNavigationView.addHeaderView(view);






We saw how Support Design Library made it very easy to create a navigation drawer.


In Part 1, we created a navigation drawer without header. Now it's time to setup the header and click events.




For adding header we can use different item types for our RecyclerView Items. We will use different layout for the header item and the menu items.

Let's have a look at our Adapter code, if you see the   onCreateViewHolder   method, you can see there is second parameter called itemType. That's what determines what layout to use during the view holder creation.

Let's start by creating layout for our header view.


<?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_height="200dp"  
   android:background="@drawable/headerbg">  
   <TextView  
     android:id="@+id/headerText"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:textColor="@android:color/white"  
     android:layout_gravity="center"  
     android:paddingTop="100dp"  
     android:textSize="20sp"  
     android:text="Header"/>  
 </LinearLayout> 

Here we added just a textview to header and background image. You can download image from here.


Then, define our view types in our Adapter class. We will have two item types as follows.


   public final static int TYPE_HEADER = 0;  
   public final static int TYPE_MENU = 1; 

Since the LayoutManager needs to know how menu items the RecyclerView has,  add 1 to the getCount method as we are adding a headerView.


   @Override  
   public int getItemCount() {  
     return drawerMenuList.size()+1;  
   }  

And, let the LayoutManager know which item type is the header. We can do so by overriding getItemViewType method. We will have TYPE_HEADER at position 0 and rest of the items will be TYPE_MENU.


  @Override  
   public int getItemViewType(int position) {  
     if(position == 0){  
       return TYPE_HEADER;  
     }  
     return TYPE_MENU;  
   }  

Next we change our onCreateViewHolder class to have to different layouts based on view type.



  @Override  
   public DrawerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {  
     View view;  
     if(viewType == TYPE_HEADER){  
       view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_drawer_header, parent, false);  
     }else{  
       view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_menu_item, parent, false);  
     }  
     return new DrawerViewHolder(view, viewType);  
   }  

Here, we used layout_drawer_header for header type and layout_menu_item for normal menu items.
We also changed the constructor of DrawerViewHolder to accept the viewType as second parameter. So modify ViewHolder as below.


 class DrawerViewHolder extends RecyclerView.ViewHolder{  
     TextView title;  
     TextView headerText;  
     ImageView icon;  
     public DrawerViewHolder(View itemView, int viewType) {  
       super(itemView);  
       if(viewType == 0){  
         headerText = (TextView)itemView.findViewById(R.id.headerText);  
       }else {  
         title = (TextView) itemView.findViewById(R.id.title);  
         icon = (ImageView) itemView.findViewById(R.id.icon);  
       }  
     }  
   }  


Then, change onBindViewHolder method as below for setting up some Text to the TextView.


  @Override  
   public void onBindViewHolder(DrawerViewHolder holder, int position) {  
     if(position == 0) {  
       holder.headerText.setText("Header Text");  
     }else{  
       holder.title.setText(drawerMenuList.get(position - 1).getTitle());  
       holder.icon.setImageResource(drawerMenuList.get(position - 1).getIcon());  
     }  
   } 

Here we are using "position-1" to access the menu list items that's because we have added the header in the first position so the positions of the menu list and the adapter are not in sync.

And that's all, run the project and see we have a header on top of the menu items.



Finally, add click events to the menu items. For this let's write an OnItemSelectedListener interface with a method onItemSelected.


public interface OnItemSelecteListener{  
     public void onItemSelected(View v, int position);  
   } 

Then create a setOnClicklistener method in the adapter which will help us to set Listener from MainActivity. Create a field mListener of type OnItemSelecteListener and write following method.



public void setOnItemClickLister(OnItemSelecteListener mListener) {  
     this.mListener = mListener;  
   }  

Modify, DrawerViewHolder adding OnClickListener to the itemView so that whenever the itemView is clicked we can pass the clicked position through onItemSelectedMethod.


class DrawerViewHolder extends RecyclerView.ViewHolder{  
     TextView title;  
     TextView headerText;  
     ImageView icon;  
     public DrawerViewHolder(View itemView, int viewType) {  
       super(itemView);  
       if(viewType == 0){  
         headerText = (TextView)itemView.findViewById(R.id.headerText);  
       }else {  
         title = (TextView) itemView.findViewById(R.id.title);  
         icon = (ImageView) itemView.findViewById(R.id.icon);  
       }  
       itemView.setOnClickListener(new View.OnClickListener() {  
         @Override  
         public void onClick(View view) {  
           mListener.onItemSelected(view, getAdapterPosition());  
         }  
       });  
     }  
   }  

Set OnItemSelectedListener to the adapter form activity to perform various actions when menu items are selected. For now let's just show the Toasts. (Be careful about the positions if you have additional types added, for example now we have a header type added so we will have first menu at position 1 instead of 0)



 adapter.setOnItemClickLister(new DrawerAdapter.OnItemSelecteListener() {  
       @Override  
       public void onItemSelected(View v, int position) {  
         Toast.makeText(MainActivity.this, "You clicked at position: "+ position, Toast.LENGTH_SHORT).show();  
       }  
     }); 

Let's run the project.





We built navigation drawer using RecyclerView. You can find the full source code for this tutorial on github.



More

Download