Wednesday 30 August 2017

Simple Carousel Layout


step 1:
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.moondroid.coverflow:library:1.0'
compile 'com.android.support:cardview-v7:23.0.1'

step 2:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
 xmlns:tools="http://schemas.android.com/tools"    
 xmlns:coverflow="http://schemas.android.com/apk/res-auto"   
 android:layout_width="match_parent"   
 android:layout_height="match_parent"   
 android:paddingBottom="10dp"   
 android:paddingLeft="10dp"   
 android:paddingRight="10dp"   
 android:paddingTop="10dp"   
 tools:context=".MainActivity">
    <it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow        
       android:id="@+id/coverflow"        
       coverflow:coverHeight="150dp"        
       coverflow:coverWidth="100dp"        
       coverflow:maxScaleFactor="1.5"        
       coverflow:reflectionGap="0px"        
       coverflow:rotationThreshold="0.5"        
       coverflow:scalingThreshold="0.5"        
       coverflow:spacing="0.6"        
       android:layout_width="match_parent"        
       android:layout_height="match_parent" />
</RelativeLayout>
step 3:
activity_game.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android       
             android:layout_width="match_parent">
             android:layout_height="wrap_content">

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

        <ImageView           
 android:id="@+id/image"           
 android:layout_width="150dp"           
 android:layout_height="150dp"           
 android:layout_gravity="center"           
 android:contentDescription="@string/app_name"           
 android:scaleType="centerCrop" />

        <TextView           
             android:id="@+id/name"           
             android:layout_width="match_parent"           
             android:layout_height="wrap_content"           
             android:gravity="center"            
             android:textColor="@android:color/holo_green_dark" />
    </LinearLayout>
</android.support.v7.widget.CardView>
step 4:
item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"   
             android:layout_width="140dp"   
             android:layout_height="180dp">

    <ImageView        
            android:id="@+id/image"        
            android:contentDescription="@string/app_name"        
            android:layout_width="match_parent"        
            android:layout_height="match_parent"       
            android:scaleType="centerCrop" />

    <TextView        
            android:id="@+id/name"       
            android:layout_gravity="bottom"        
            android:layout_width="match_parent"        
            android:layout_height="wrap_content"        
            android:gravity="center"        
            android:textAppearance="?android:attr/textAppearanceSmallInverse" />

</FrameLayout>
step 4:
Game.java
public class Game {
    private String name;
    private int imageSource;

    public Game (int imageSource, String name) {
        this.name = name;
        this.imageSource = imageSource;
    }

    public String getName() {
        return name;
    }

    public int getImageSource() {
        return imageSource;
    }
}
step 5:
 class name:Adapter
public class Adapter extends BaseAdapter {

    private ArrayList<Game> data;
    private AppCompatActivity activity;

    public Adapter(AppCompatActivity context, ArrayList<Game> objects) {
        this.activity = context;
        this.data = objects;
    }

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

    @Override    
    public Game getItem(int position) {
        return data.get(position);
    }

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

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

        ViewHolder viewHolder;

        if (convertView == null) {
         LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_view, null, false);

            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.gameImage.setImageResource(data.get(position).getImageSource());
        viewHolder.gameName.setText(data.get(position).getName());

        convertView.setOnClickListener(onClickListener(position));

        return convertView;
    }

    private View.OnClickListener onClickListener(final int position) {
        return new View.OnClickListener() {

            @Override           
                public void onClick(View v) {
                final Dialog dialog = new Dialog(activity);
                dialog.setContentView(R.layout.game);
                dialog.setCancelable(true);
 // dimiss when touching outside               
                dialog.setTitle("Game Details");
                TextView text = (TextView) dialog.findViewById(R.id.name);
                text.setText(getItem(position).getName());
                ImageView image = (ImageView) dialog.findViewById(R.id.image);
                image.setImageResource(getItem(position).getImageSource());

                dialog.show();
            }
        };
    }


    private static class ViewHolder {
        private TextView gameName;
        private ImageView gameImage;

        public ViewHolder(View v) {
            gameImage = (ImageView) v.findViewById(R.id.image);
            gameName = (TextView) v.findViewById(R.id.name);
        }
    }
step 6:
MainActivity
public class MainActivity extends AppCompatActivity {

    private FeatureCoverFlow coverFlow;
    private Adapter adapter;
    private ArrayList<Game> games;

    @Override   
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        coverFlow = (FeatureCoverFlow) findViewById(R.id.coverflow);

        settingDummyData();
        adapter = new Adapter(this, games);
        coverFlow.setAdapter(adapter);
        coverFlow.setOnScrollPositionListener(onScrollListener());
    }

    private FeatureCoverFlow.OnScrollPositionListener onScrollListener() {
        return new FeatureCoverFlow.OnScrollPositionListener() {
            @Override           
            public void onScrolledToPosition(int position) {
                Log.v("MainActiivty", "position: " + position);
            }

            @Override            
            public void onScrolling() {
                Log.i("MainActivity", "scrolling");
            }
        };
    }

    private void settingDummyData() {
        games = new ArrayList<>();
        games.add(new Game(R.drawable.fruits, "FRUITS"));
        games.add(new Game(R.drawable.grape,"Grape"));
        games.add(new Game(R.drawable.guava, "Guava"));
        games.add(new Game(R.drawable.mango, "Mango"));
        games.add(new Game(R.drawable.watermelon,"WaterMelon"));
        games.add(new Game(R.drawable.panana, "Panana"));
        games.add(new Game(R.drawable.papaya, "Papaya"));
        games.add(new Game(R.drawable.peach,"Peach"));
        games.add(new Game(R.drawable.tangelo, "Tangelo"));
        games.add(new Game(R.drawable.fruits, "Fruits"));
    }
}

Create Simple CarouselView

step1:
compile 'com.synnapps:carouselview:0.1.4'

step 2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:tools="http://schemas.android.com/tools"   
android:orientation="vertical"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
tools:context="com.carousel.carouselview.MainActivity">
<com.synnapps.carouselview.CarouselView  
     android:id="@+id/carouselView"       
     android:layout_width="368dp"        
     android:layout_height="200dp"        
     app:fillColor="#FFFFFFFF"        
     app:pageColor="#00000000"        
     app:radius="6dp"       
     app:slideInterval="3000"       
     app:strokeColor="#FF777777"       
     app:strokeWidth="1dp"       
     tools:layout_editor_absoluteY="0dp"       
     tools:layout_editor_absoluteX="8dp" />
</LinearLayout>

step3:
public class MainActivity extends AppCompatActivity
       int[] sampleImages = {R.drawable.image1
                             R.drawable.image2,
                             R.drawable.image3,
                             R.drawable.image4,
                             R.drawable.image5};
    CarouselView carouselView;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.carousel_view);
        carouselView=(CarouselView)findViewById(R.id.carouselView);
        carouselView.setPageCount(sampleImages.length);
        ImageListener imageListener = new ImageListener() {
    @Override    public void setImageForPosition(int position, ImageView imageView) {
        imageView.setImageResource(sampleImages[position]);
    }
};
carouselView.setImageListener(imageListener);}

Saturday 26 August 2017

Create Back Press Button

  @Override
    public void onBackPressed() {
        new AlertDialog.Builder(this).setTitle("EXIT").setMessage("ARE YOU SURE")
                .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                        finish();
                    }
                }).setNegativeButton("NO", null).show();

    }

Create Alert Dialog box

    final AlertDialog.Builder alert = new AlertDialog.Builder(DeleteActivity.this);
        alert.setTitle("Conformize");
        alert.setMessage("Are you sure won't to  Delete");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        alert.show();
    }
});

Tuesday 22 August 2017

Create Custom Toolbar

step1


<style name="noaction" parent="Theme.AppCompat.DayNight.NoActionBar"></style>

step2
  <android.support.v7.widget.Toolbar      
          android:id="@+id/toolbar_top"        
          android:layout_height="wrap_content"      
          android:layout_width="match_parent"        
          android:minHeight="?attr/actionBarSize"      
          android:background="@color/colorBlue"        
          app:theme="@style/noaction"      
          android:weightSum="1">
<ImageView    
          android:layout_width="47dp"  
          android:background="@drawable/tittle"   
          android:layout_height="42dp" />

 <TextView            
          android:layout_width="wrap_content"           
          android:layout_height="wrap_content"          
          android:text="My Toolbar"          
          android:textSize="24dp"          
          android:layout_marginLeft="40dp"            
          android:textColor="@android:color/white"          
          android:layout_gravity="center"           
          android:id="@+id/toolbar_title" /></android.support.v7.widget.Toolbar>

Circle Text View

step 1:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"   
      android:shape="oval">
   
    <solid 
        android:color="@android:color/white" />

   <size        
         android:height="120dp"        
         android:width="120dp" />
  <stroke       
         android:width="1dp"        
         android:color="@color/colorBlue" />

</shape>
 
save file name:circle_text.xml

setp 2:

<TextView    
        android:id="@+id/circle_textview"    
        android:layout_width="wrap_content"    
        android:layout_height="wrap_content"    
        android:gravity="center"    
        android:layout_gravity="center"    
        android:text="4"    
        android:background="@drawable/circle_text"    
        android:textColor="@color/colorBlue"    
        android:textSize="80dp" />

Circle Image View

step 1:
compile 'de.hdodenhof:circleimageview:2.1.0'
step 2:

<de.hdodenhof.circleimageview.CircleImageView  
         xmlns:app="http://schemas.android.com/apk/res-auto"   
         android:id="@+id/profile_image"    
         android:layout_width="96dp"    
         android:layout_height="96dp"    
         android:src="@drawable/profile"    
         app:civ_border_width="2dp"    
         app:civ_border_color="#FF000000"/>

Monday 21 August 2017

Simple List View

Step 1:
<LinearLayout    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:layout_weight="0.5"   
 android:layout_marginLeft="15dp"    
android:layout_marginRight="15dp"    
android:background="@android:color/white"   
 android:orientation="vertical">

    <ListView        
android:id="@+id/Appoinment_list"        
android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:dividerHeight="4sp"        
android:divider="@android:color/white"        
tools:layout_editor_absoluteX="8dp"        
tools:layout_editor_absoluteY="0dp" />

Step 2:.

Save File name : layout.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dp" 
          android:color="@color/colorgray" />
 <padding 
         android:left="7dp"        
         android:top="7dp"        
         android:right="7dp"        
         android:bottom="7dp"        />
 <corners
         android:radius="4dp" />
</shape>

Step 3:
<?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="match_parent">
 <LinearLayout        
      android:layout_gravity="center"        
      android:layout_width="match_parent"        
      android:layout_height="match_parent"        
      android:background="@drawable/layout"       
      android:orientation="horizontal">

 <TextView           
      android:id="@+id/time"            
      android:gravity="center"            
      android:padding="10dip"            
      android:textSize="13dip"           
      android:layout_width="fill_parent"           
      android:layout_height="fill_parent"           
      android:layout_weight="1"            
      android:text="TextView" />

<TextView           
      android:id="@+id/name"           
      android:gravity="center"            
      android:padding="10dip"           
      android:textSize="13dip"          
      android:layout_width="fill_parent"           
      android:layout_height="fill_parent"            
      android:layout_weight="1"           
      android:text="TextView" />
    </LinearLayout>
</LinearLayout>

Create list view

step 1: file name : style_list.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android"    
      android:shape="rectangle">
<gradient       
      android:startColor="@color/colorBlue"        
      android:angle="270"/>

<corners        
      android:bottomRightRadius="7dp"        
      android:bottomLeftRadius="7dp"        
      android:topLeftRadius="7dp"        
      android:topRightRadius="7dp"/>
</shape>

step 2: file name:listview.xml

<ListView    
        android:id="@+id/Appoinment_list"    
        android:layout_width="368dp"    
        android:layout_height="wrap_content"    
        android:dividerHeight="10.0sp"    
        tools:layout_editor_absoluteY="0dp"    
        tools:layout_editor_absoluteX="8dp"    />

step 3: file name:listview_item.xml

<?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="match_parent">
 <LinearLayout       
         android:layout_gravity="center"        
         android:layout_width="match_parent"        
         android:layout_height="match_parent"  
         android:background="@drawable/style_list"        
         android:orientation="horizontal">

<TextView  
            android:id="@+id/time"           
            android:gravity="center"            
            android:padding="10dip"            
            android:textSize="16dip"            
            android:layout_width="fill_parent"           
            android:layout_height="fill_parent"            
            android:layout_weight="1"           
            android:text="TextView" />
  
    <TextView              
            android:id="@+id/name"            
            android:gravity="center"            
            android:padding="10dip"            
            android:textSize="16dip"            
            android:layout_width="fill_parent"           
            android:layout_height="fill_parent"           
            android:layout_weight="1"            
            android:text="TextView" />
    </LinearLayout>
</LinearLayout>

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...