Wednesday, September 5, 2018

How to add Recyclerview item Animations like from left,right and Rotate

when we Displaying List type of Data Recycler view Plays a Major Role, I have already explained how to create Recyclerview if you wan u can check this article  android-recyclerview

when we loading data in Recyclerview we can add animations also, for example, I have added the following




full source code is available for Download Github


Share:

how to clear all markers and add and Update in Android


When we developing Mobile Applications Maps also Plays a great and important Role, like sometimes we have to Display user current Location or Display office locations or specific address at that time we have to use Google maps 
and we have to show some identification for that location in this example I have explained how to add markers and Update markers also, if anyone want to learn how to display Google maps please check this article  
Share:

Android RecyclerView How to change the color of Alternate rows




 In Android Application some cases we have to show List with alternate colors
To achieve this we have used following small snippet, and full Sourcecode is available in Github
Recyclerview_alternate_rows



 //add  following code in onBindViewHolder
       if(position %2 == 1)
        {
            holder.lyt_content_view.setBackgroundColor(Color.WHITE);
        }
        else
        {
            holder.lyt_content_view.setBackgroundColor(Color.GRAY);
        }

add Following snippet in Adapter on Bind for reference i have added Adapter class Following



public class PropertyListAdapter extends RecyclerView.Adapter<PropertyListAdapter.RcvViewHolder> {

    private List<PropertyModel> propertyModelList = new ArrayList<>();
    private Context mContext;
    private RecyclerView rcvPro;
    int Previusposition = 0;

    public PropertyListAdapter(List<PropertyModel> propertyModelList, Context mContext, RecyclerView rcvPro) {

        this.propertyModelList = propertyModelList;
        this.mContext = mContext;
        this.rcvPro = rcvPro;

    }

    @NonNull
    @Override
    public RcvViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.rcv_pro_row, null);
        return new RcvViewHolder(v);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull RcvViewHolder holder, int position) {

        Picasso.with(mContext).load(propertyModelList.get(position).getPro_image()).transform(new CommonUtl.CircleTransform()).into(holder.img_pr);
        holder.txt_name.setText(propertyModelList.get(position).getPro_name());
        holder.txt_ads.setText(propertyModelList.get(position).getPro_adrs());
        if (Previusposition == 0) {
            AnimationUtil.animate(holder, true);
        } else if (position > Previusposition) {
            AnimationUtil.animate(holder, true);
        } else {
            AnimationUtil.animate(holder, false);
        }
        Previusposition = position;
        if(position %2 == 1)
        {
            holder.lyt_content_view.setBackgroundColor(Color.WHITE);
        }
        else
        {
            holder.lyt_content_view.setBackgroundColor(Color.GRAY);
        }


    }

    public void setFadeAnimation(View view) {
        AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
        anim.setDuration(1000);
        view.startAnimation(anim);
    }

    @Override
    public int getItemCount() {
        if (propertyModelList.size() > 0)
            return propertyModelList.size();
        else
            return 0;
    }

    class RcvViewHolder extends RecyclerView.ViewHolder {
        ImageView img_pr;
        TextView txt_name, txt_ads;
        LinearLayout lyt_content_view;

        public RcvViewHolder(View itemView) {
            super(itemView);
            img_pr = itemView.findViewById(R.id.img_pro);
            txt_name = itemView.findViewById(R.id.pro_name);
            txt_ads = itemView.findViewById(R.id.pro_ads);
            lyt_content_view= itemView.findViewById(R.id.lyt_content_view);

        }
    }
}
Full source code is available ins Github  Source_code
Share:

Tuesday, September 4, 2018

Passing Data between Activity & Passing data back to First Activity

Passing Data between Activity & Passing data back to First Activity: When we building Android application we will use multiple activities for show Data, And We need to send data from One activity to Other activity  Project code : code-from-drive Project Code zip : code-Zip-file
Create two  Activities 1. FirstActivity 2.SecondActivity update code like following Update code On FirstActivity XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="in.arula.statusdownload.FirstActivity">

    <Button
        android:id="@+id/btnFirstActivity"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_centerVertical="true"
        android:layout_margin="20dp"
        android:text="GO TO Second Activity" />

</RelativeLayout>
Update code On SecondActivity XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="in.arula.statusdownload.SecondActivity">

<Button
    android:id="@+id/btnSecondActivity"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_centerVertical="true"
    android:layout_margin="20dp"
    android:text="GO TO First Activity" />
</RelativeLayout>
Update FirstActrivity Java Code:
public class FirstActivity extends AppCompatActivity {
    Button btnFirstActivity;
    final private int REQUESTCODE = 2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        btnFirstActivity = findViewById(R.id.btnFirstActivity);
        btnFirstActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // PROCESS -1 START activity
             //   startActivity(new Intent(FirstActivity.this, SecondActivity.class));
                // PROCESS -2 START activity
                Intent i=new Intent(FirstActivity.this,SecondActivity.class);
                i.putExtra("Value","From-Activity-One");
                startActivityForResult(i,REQUESTCODE);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if ( requestCode== REQUESTCODE)
        {
            if (resultCode==RESULT_OK)
            {
                String data_val= data.getExtras().getString("Value");
                Toast.makeText(this, "FROM 2 :"+data_val, Toast.LENGTH_SHORT).show();
            }
        }

    }
}
Update SecondActrivity Java Code:
public class SecondActivity extends AppCompatActivity {

    Button btnSecondActivity;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        btnSecondActivity = findViewById(R.id.btnSecondActivity);
        if (getIntent().getExtras() != null) {
            String data = getIntent().getExtras().getString("Value");
            Toast.makeText(this, "Value:" + data, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "No data Found", Toast.LENGTH_SHORT).show();
        }


        btnSecondActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(SecondActivity.this, "Back TO First Activity", Toast.LENGTH_SHORT).show();
                Intent i = getIntent();
                i.putExtra("Value", "DATA FROM SECOND ACTIVITY");
                setResult(RESULT_OK, i);
                finish();

            }
        });
    }


}
Share:

Android Architecture

This part we will learn about Android architecture or Android Software Stack Android Architecture is 5 layer stack those are
  1. Linux Kernel
  2. Native libraries
  3. Android Runtime
  4. Android Framework
  5. Applications 
Linux Kernal : 
  • This is Heart Of android Architecture
  • It Exists at the root 
  • it is Only Responsible for the Drivers and memory management & Power management
Native Libraries :
  • It is Present On Top Of Linux-Kernel
  • it consists Of open libraries Such as OpenGL, SQLite Media...Etc
  • The WebKit library is responsible for browser support, SQLite is for database, FreeType for font support, Media for playing and recording audio and video formats.
Android Runtime :
  • we have DVM (Dalvik Virtual Machine) which is responsible to run android application.
  • DVM is like JVM but it is optimized for mobile devices.
  • It consumes less memory and provides fast performance.
Android Framework :
  • Top of the Android Runtime we have android Framework.
  • Android framework includes APIs such as UI (User Interface), telephony, resources, locations, Content Providers (data) and package managers.
  • It provides a lot of classes and interfaces for android application development.
Applications  : 
  • Top of The Framework we have Applications such as home, contact, settings, games, browsers.
  • These applications work with the help of Android API services.
                                                ***
Share:

how to Display google maps in Android with a Circle Radius

Working with Google Maps V2 : Nowadays we So many applications Using maps to show Current location, this Info is More useful identify the Exact location of particular shop or Office.   In android application, we have to use Google Map Service for Loadmaps in this tutorial we learn about  Google maps v2 and how to show circle, markers Requirements for Show maps in Android App : 1). Google play services 2). Google API key  How To Import Google PlayServices in Android:  Google Mad new Maps v2 API part in Google Play services SDK. before you start working with maps we have to import Play services on Application First  Add following line on Gradel file  
implementation 'com.google.android.gms:play-services-maps:11.8.0'

How TO Get Google Maps API key : 
Step1:-Open Google Developer Console  url
Step2:- Create new Project 
  
Step3:- Get API key from Console, by selecting a project 
copy key from the Console application  How To Display Google Maps in Android Application:  Create New Application with a name of Googlemapsv2.  Add Following code in Manifest 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.arula.googlemapsv2">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.truiton.supportmapfragment.permission.MAPS_RECEIVE" />
    <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>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR KEY" />
    </application>

</manifest>
Add Following code To Mainactivity UI:
<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.imaadv.leaynik.ClinicFragment" />

</android.support.constraint.ConstraintLayout>
Add Following Code in Main activity : 
package in.arula.googlemapsv2;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {


    private GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // initilizeMap();

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

    }
    private void initilizeMap() {
        if (googleMap == null) {
            ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMapAsync(this);

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        this.googleMap=googleMap;

        Circle circle = googleMap.addCircle(new CircleOptions()
                .center(new LatLng(-33.87365, 151.20689))
                .radius(10000)
                .strokeColor(Color.RED)
                .fillColor(Color.BLUE));

        LatLng sydney = new LatLng(-33.87365, 151.20689);
        googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
        googleMap.setMinZoomPreference(11);
    }
}
Share:

BTemplates.com

Search This Blog

Powered by Blogger.

Blog Archive

How to add Recyclerview item Animations like from left,right and Rotate

when we Displaying List type of Data Recycler view Plays a Major Role, I have already explained how to create Recyclerview if you wan u c...