Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, September 5, 2018

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:

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:

Android Recyclerview with Picasso And item loading animation


Any Application Listview Always Plays a Major Role, in every Application,
we have lots of data example Users List, Company names, students List etc.  ListViews are very useful for Display this type of data
In Android Applications Recyclerview Very useful For Display list type of data.
In this example, I have created a recycle view with Sample data
Step: 1
Create new Project and Add following dependencies

    // RCV && CardView
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'

Step : 2

Create local data for Recyclerview content

public class PropertyData {
    public static List<PropertyModel> getPropertyData() {

        List<PropertyModel> pro_list = new ArrayList<>();
        pro_list.add(new PropertyModel(1, "pro_1", "pro_1_ads", "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"));
        pro_list.add(new PropertyModel(2, "pro_2", "pro_2_ads", "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"));
        pro_list.add(new PropertyModel(3, "pro_3", "pro_3_ads", "https://homepages.cae.wisc.edu/~ece533/images/baboon.png"));
        pro_list.add(new PropertyModel(4, "pro_4", "pro_4_ads", "https://homepages.cae.wisc.edu/~ece533/images/barbara.png"));
        pro_list.add(new PropertyModel(5, "pro_5", "pro_5_ads", "https://homepages.cae.wisc.edu/~ece533/images/boat.png"));

        pro_list.add(new PropertyModel(6, "pro_6", "pro_6_ads", "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"));
        pro_list.add(new PropertyModel(7, "pro_7", "pro_7_ads", "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"));
        pro_list.add(new PropertyModel(8, "pro_8", "pro_8_ads", "https://homepages.cae.wisc.edu/~ece533/images/baboon.png"));
        pro_list.add(new PropertyModel(9, "pro_9", "pro_9_ads", "https://homepages.cae.wisc.edu/~ece533/images/barbara.png"));
        pro_list.add(new PropertyModel(10, "pro_10", "pro_10_ads", "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"));

        pro_list.add(new PropertyModel(11, "pro_11", "pro_11_ads", "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"));
        pro_list.add(new PropertyModel(12, "pro_12", "pro_12_ads", "https://homepages.cae.wisc.edu/~ece533/images/baboon.png"));
        pro_list.add(new PropertyModel(13, "pro_13", "pro_13_ads", "https://homepages.cae.wisc.edu/~ece533/images/barbara.png"));
        pro_list.add(new PropertyModel(14, "pro_14", "pro_14_ads", "https://homepages.cae.wisc.edu/~ece533/images/boat.png"));
        pro_list.add(new PropertyModel(15, "pro_15", "pro_15_ads", "https://homepages.cae.wisc.edu/~ece533/images/cat.png"));

        return pro_list;

    }

}

Step : 3

Create recycle-view Item 

<?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"
    android:layout_marginBottom="5dp"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <android.support.v7.widget.CardView
        android:layout_marginBottom="@dimen/rcv_margin"
        android:background="@color/colorWhite"
        android:layout_width="match_parent"
        android:layout_height="@dimen/rcv_row_height"
        app:cardCornerRadius="@dimen/rcv_row_corner">

        <LinearLayout
            android:weightSum="3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="@dimen/rcv_row_lyt_margin"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/img_pro"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_weight="1"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:layout_gravity="center_vertical"
                android:textAlignment="center"
                android:textSize="24dp"
                android:id="@+id/pro_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Sample"
                android:textColor="@color/colorBlack" />

            <TextView
                android:id="@+id/pro_ads"
                android:layout_gravity="center_vertical"
                android:textAlignment="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Sample"
                android:textColor="@color/colorPrimary" />

        </LinearLayout>

    </android.support.v7.widget.CardView>
</RelativeLayout>
Step : 4

Create Activity for Recyclerview


<?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=".view.MainActivity"
    android:background="@color/colorWhiteSmoke">

   <android.support.v7.widget.RecyclerView

       android:layout_margin="@dimen/rcv_row_lyt_margin"
       android:id="@+id/rcv_pro"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
   </android.support.v7.widget.RecyclerView>

</RelativeLayout>


Main activity.java


public class MainActivity extends AppCompatActivity {

    private Context mContext;
    private RecyclerView rcv_pro;
    private LinearLayoutManager layoutManager;
    private List<PropertyModel> propertyDataList;
    private PropertyListAdapter propertyListAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        bind();



    }

    private void bind() {

        propertyDataList = PropertyData.getPropertyData();
        propertyListAdapter = new PropertyListAdapter(propertyDataList,mContext,rcv_pro);
        rcv_pro.setAdapter(propertyListAdapter);

    }


    private void init() {
        mContext =MainActivity.this;
        layoutManager = new LinearLayoutManager(mContext);
        rcv_pro = findViewById(R.id.rcv_pro);
        rcv_pro.setLayoutManager(layoutManager);


    }

}

Step 4: create Adapter for Recyclerview


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);
    }

    @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(position > Previusposition)
        {
            AnimationUtil.animate(holder,true);
        }else {
            AnimationUtil.animate(holder,false);
        }
        Previusposition = position;

    }
    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;
        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);

        }
    }
}


Full Source code Github_recyclerview_with_item_animation , sample_recyclerview
Download apk : apk Link 
Share:

Monday, September 3, 2018

Android Studio Shortcuts



When we working In any software application we have to use IDE, IDE have different Shortcuts,  I have placed few Shortcut For android Studio.

  •  Go to class Ctrl + N
  • Go to file Ctrl + Shift + N
  • Navigate open tabs ALT + Left-Arrow; ALT + Right-Arrow
  • Lookup recent files CTRL + E
  • Go to line CTRL + G
  • Navigate to last edit location CTRL + SHIFT + BACKSPACE
  • Go to declaration CTRL + B
  • Go to implementation CTRL + ALT + B
  • Go to source F4
  • Go to super Class CTRL + U
  • Show Call hierarchy Ctrl + Alt + H
  • Search in path/project CTRL + SHIFT + F

  • // Code Shortcuts
  • Reformat code CTRL + ALT + L
  • Optimize imports CTRL + ALT + O
  • Code Completion CTRL + SPACE
  • Issue quick fix ALT + ENTER
  • Surround code block CTRL + ALT + T
  • Rename and refactor Shift + F6
  • Line Comment or Uncomment CTRL + /
  • Block Comment or Uncomment CTRL + SHIFT + /
  • Go to previous/next method ALT + UP/DOWN
  • Show parameters for method CTRL + P
  • Quick documentation lookup CTRL + Q

  • //genaral Shortcuts
  • Delete line CTRL + Y
  • Safe Delete Alt + DELETE
  • Close Active Tab CTRL + F4
  • Build and run SHIFT + F10
  • Build CTRL + F9
  • All purpose (Meta)Shortcut CTRL + SHIFT + A
Share:

BTemplates.com

Search This Blog

Powered by Blogger.

Blog Archive

Labels