Tuesday, October 29, 2019

CardView in android

Cardview is another material added for designing a layout.It resprents your designin a card manner with the corner radius and  drop elevation (shadow).

Steps to Add CardView in your android studio:

1. Adding Design Dependency

       Build Gradle (Module:App)


dependencies {

implementation 'com.android.support:design:28.0.0'

}


2. Add the <android.support.v7.widget.CardView> widget to your layout and place UI widgets like TextViews, ImageViews inside it.


activity_main.xml

<android.support.constraint.ConstraintLayout
 xmlns:android="http://schemas.android.com/apk/res/android"   
 xmlns:app="http://schemas.android.com/apk/res-auto" 
   xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="match_parent"   
 android:layout_height="match_parent"  
  android:background="@drawable/login_back"  
  tools:context=".LoginActivity">

    <android.support.v7.widget.CardView   
     android:layout_width="match_parent"   
     android:layout_height="wrap_content"    
    android:layout_margin="20dp"      
  android:background="@drawable/ic_cardview_corner"  
      app:cardCornerRadius="15dp"      
  app:cardElevation="20dp"     
   app:layout_constraintBottom_toBottomOf="parent"   
     app:layout_constraintLeft_toLeftOf="parent"     
   app:layout_constraintRight_toRightOf="parent"    
    app:layout_constraintTop_toTopOf="parent">


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


 <android.support.design.widget.TextInputLayout     
           android:id="@+id/text_Username"       
         android:layout_width="match_parent"          
      android:layout_height="wrap_content">


                <EditText     
               android:id="@+id/username_l"  
                  android:layout_width="match_parent"    
                android:layout_height="wrap_content"     
               android:hint="Username"                
    android:textColorHint="#fff" />

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

            <android.support.design.widget.TextInputLayout      
          android:id="@+id/text_password"             
   android:layout_width="match_parent"              
  android:layout_height="wrap_content">


                <EditText                  
      android:id="@+id/password_l"              
      android:layout_width="match_parent"             
      android:layout_height="wrap_content"              
      android:hint="Password"                  
      android:textColorHint="#fff" />
            </android.support.design.widget.TextInputLayout>

            <Button                
   android:id="@+id/login"             
   android:layout_width="match_parent"         
   android:layout_height="wrap_content"
    android:text="Login" />

            <Button        
        android:id="@+id/newuser"    
        android:layout_width="match_parent"   
       android:layout_height="wrap_content"         
       android:text="Create New User" />

        </LinearLayout>
    </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>








3.Adding Boundary line to the CardView                                                                                             


Drawable                                                                                                                                

ic_caredview_boundary.xml                                                                                                                     

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke    
    android:width="2dp"
    android:color="#fff">
</stroke>

</shape>                                                                                                                           






Sunday, October 20, 2019

Multiple File Picker in android

Multiple File Picker Library ,with this a user can pick multiple files for uploading to the server using retrofit or volley..


Dependency used for File Picker

implementation 'com.github.jaiselrahman:FilePicker:1.2.2'



Java File



package com.example.filepicker;

import android.content.Intent;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jaiselrahman.filepicker.activity.FilePickerActivity;
import com.jaiselrahman.filepicker.config.Configurations;
import com.jaiselrahman.filepicker.model.MediaFile;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ArrayList<CustomMediaFile> imageArrayList;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==123 && resultCode==RESULT_OK){
            ArrayList<MediaFile> files = data.getParcelableArrayListExtra(FilePickerActivity.MEDIA_FILES);
            //Do something with files
            for (int i=0; i<files.size();i++){
                Log.d("MyPaths",files.get(i).getPath());
            }

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pickFiles();
            }
        });

    }
    public void pickFiles(){
        imageArrayList = new ArrayList<>();
        Intent filePickerIntent = new Intent(MainActivity.this, FilePickerActivity.class);
        filePickerIntent.putExtra(FilePickerActivity.CONFIGS, new Configurations.Builder()
                .setCheckPermission(true)
                .setMaxSelection(1)
                .setShowImages(false)
                .enableImageCapture(false)
                .setShowVideos(false)
                .setShowAudios(false)
                .setShowFiles(true)
                .setSuffixes(new String[]{"pdf", "doc", "xls"})
                .build());
        startActivityForResult(filePickerIntent, 123);
    }
}

One ProgressBar for whole Project .

ProgressBar can be used in whole Project by creating a single class.THis is demonstrated By the following code...


XML for ProgressBar...

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

    <ProgressBar       
 android:layout_width="wrap_content"       
 android:layout_height="wrap_content"      
 android:id="@+id/progressbar"      
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintLeft_toLeftOf="parent"     
 app:layout_constraintRight_toRightOf="parent"       
 app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>



Java File


package com.a.progressbaee;

import android.app.Dialog;
import android.content.Context;

public class ProgressBar extends Dialog {
    public ProgressBar(Context context) {
        super(context);
        setContentView(R.layout.activity_main);

    }

    @Override    public void show() {
        super.show();
    }

    @Override    public void hide() {
        super.hide();
    }

    @Override    public void dismiss() {
        super.dismiss();
    }

    @Override    public void cancel() {
        super.cancel();
    }
}



This can be called in other classes By just 

providing the progressbar class name and creating its object..

ProgressBar progressbar;


TO show progressbar

progressbar.show();


To hide the progressbar

progressbar.hide();

To dismiss the Progrressbar

progressbar.dismiss();

To cancel the progressbar

progressbar.cancel();




Alert Dialog Box

Alert Dialog Box Android AlertDialog   can be used to display the dialog message with OK and Cancel buttons. It can be used to inter...