Saturday, November 28, 2015

Open Right to Left Navigation Drawer Android

open right to left Navigation Drawer in android fragment activity. it is similar to left to right as we discuss http://invokecode.blogspot.com/2015/11/custom-navigation-drawer-in-android.html
but in this we need to change line.

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent">
    <android.support.v4.widget.DrawerLayout 
       android:id="@+id/drawer_layout" 
       android:layout_width="fill_parent"  
       android:layout_height="match_parent">
        <FrameLayout 
           android:id="@+id/content_frame_Home"            
           android:layout_width="match_parent"      
           android:layout_height="match_parent"/>
        <RelativeLayout  
          android:id="@+id/left_relative"   
          android:layout_width="300dp"   
          android:layout_height="wrap_content" 
           android:layout_gravity="start">
            <include layout="@layout/slider" />
        </RelativeLayout>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout> 
 
android:layout_gravity="start"   change to  android:layout_gravity="end"
in Coding we need to change GRAVITY LEFT To Right..
DrawerLayout drawerLayout;
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.openDrawer(Gravity.RIGHT);

Use Weight in Linear Layout Android

use weight for equal child of layout. margin and padding unable to set equal child because when multi screen support and margin and padding set fix, but in weight they remains same in all layout.

In Linear Layout need orientation horizontal and vertical.


XML for Linear layout weight.

<LinearLayout    
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="50dp" 
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:orientation="horizontal">

    <TextView       
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:text="FIRST"   
       android:gravity="center"  
       android:textSize="20sp"  
       android:textColor="#000000"/>

    <TextView  
      android:layout_width="0dp"   
      android:layout_weight="1"    
      android:layout_height="wrap_content"  
      android:text="SECOND"   
      android:gravity="center"   
      android:layout_marginLeft="20dp"
      android:textSize="20sp"   
     android:textColor="#000000"/>

</LinearLayout>

Monday, November 23, 2015

View Pager in android

View Pager-scroll page (slide) call view pager.



ViewPager pager;

private ArrayList<ModelClassPager> arrayOfPager;

                  pager1 = (ViewPager)findViewById(R.id.pager);
arrayOfPager = new ArrayList<ModelClass>();

arrayOfPager.add(new ModelClass(R.drawable.first));
arrayOfPager.add(new ModelClass(R.drawable.second));
arrayOfPager.add(new ModelClass(R.drawable.third));
                arrayOfPager.add(new ModelClass(R.drawable.four));

PagerAdapter  pagerAdapter = new PagerAdapter  (MainActivity.this,arrayOfPager);

pagerAdapter .setAdapter(pagerAdapter);


Custom Adapter for View Pager:


PagerAdapter   extends PagerAdapter {

LayoutInflater inflates;
ArrayList<ModelClass> arrayOfPager;

Context context;

public PagerAdapter   (Context context,
ArrayList<ModelClass> arrayOfPager_) {
this.context = context;
this.arrayOfPager = arrayOfPager_;
inflates = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

public Object instantiateItem(View collection, int position) {

ViewGroup container = null;
ImageView pgrImage;
View viewPgaer = inflates.inflate(R.layout.row_pager, null);

pgrImage = (ImageView)viewPgaer
.findViewById(R.id.pagerImage);

pgrImage.setImageResource(arrayOfPager.get(position).getPagerImg());

((ViewPager) collection).addView(viewPgaer, 0);

return viewPgaer;
}

public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}

public boolean isViewFromObject(View view, Object object) {
return view == (object);
}

public void finishUpdate(View arg0) {
}

@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}

@Override
public Parcelable saveState() {
return null;
}

@Override
public void startUpdate(View arg0) {
}

}


Model Class (Gettor Settor Class):

public class ModelClassPager {

int pagerImg = 0;

public int getPagerImg() {
return pagerImg;
}

public void setPagerImg(int pagerImg) {
this.pagerImg = pagerImg;
}
public ModelClassPager( int pagerImg_) {
// TODO Auto-generated constructor stub
pagerImg = pagerImg_;
}

}

XML Design For View Pager:
   <android.support.v4.view.ViewPager
        android:id="@+id/pagesCustmLayoutMAIN"
        android:layout_width="fill_parent"
        android:layout_height="160dp" />

Sunday, November 22, 2015

Custom Navigation Drawer in Android

Create Navigation Drawer in android using fragment.

Navigation Drawer
DrawerLayout drawerLayout;

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

// On drawerLayout click open and close


public void openDrawable() {
// TODO Auto-generated method stub
optionMenuStr="open";
//menuImage.setBackgroundResource(R.drawable.backk);
drawerLayout.openDrawer(Gravity.LEFT);
}

public void closeDrawable() {
// TODO Auto-generated method stub
optionMenuStr="close";
menuImage.setBackgroundResource(R.drawable.menu);
drawerLayout.closeDrawers();
}

Disable Swipe Open  Navigation Drawer Android:

Disable Swipe Open Navigation Drawer, sometime we use fragment and BaseActivity is same and fragment are different then in other fragments we need to stop swipe open Drawer then use this code.


drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Disable to Able Swipe Open  Navigation Drawer Android:


if one you have disable swipe open then again it need to open else it not working.


drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

XML Design.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:id="@+id/content_frame_Home"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <RelativeLayout
            android:id="@+id/left_relative"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="start" >

            <include layout="@layout/slider" />
        </RelativeLayout>
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

Saturday, November 21, 2015

Show Google Map V2 in FragmentActivity Android.

show google map v2 in fragment activity, we need SupportMapFragment for it and fragment in xml file.

Google map in android
Google Map in Android

private GoogleMap googleMap;

SupportMapFragment supportMapFrag=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

googleMap=supportMapFrag.getMap();

            /*set map type*/
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);






xml layout for map:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

  <fragment
      android:id="@+id/map"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>


add Google Play Service library and gilve all permission in manifest.


    <permission
        android:name="com.googlemap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="YOUR_PACKAGE_NAME.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />


before Application Tag add these.

 <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR API KEY" />