Monday, 18 September 2017

Image Get Using Picasso

if (contact.getProfilePic() != null && !contact.getProfilePic().isEmpty()) {
    Picasso.with(context).load(contact.getProfilePic()).placeholder(R.mipmap.ic_launcher).resize(80, 100)
            .into(holder.imageView);
} else    holder.imageView.setImageResource(R.mipmap.ic_launcher);


first activity 

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
intent.putExtra("is",true);
startActivity(i);


Second activity 

if (getIntent().hasExtra("is")) {
    txtbagaccpect.setText("COMPLETE ORDER");
}


 

Sunday, 10 September 2017

Multi-pal Check Box Select

Java Class
MainActivityFragment.java

public class MainActivityFragment extends Fragment {

    ArrayList<Number> numbers;
    private RecyclerView list;
    private Button btnGetSelected;

    public MainActivityFragment() {
    }

    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

    @Override    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        btnGetSelected = (Button) view.findViewById(R.id.btnGetSelected);
        list = (RecyclerView) view.findViewById(R.id.list);
        list.setLayoutManager(new LinearLayoutManager(getActivity()));
        list.setHasFixedSize(true);
    }

    @Override    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        numbers = new ArrayList<>();
        String Ones[] = {"12th","10th", "Graduction", "Post Graduction", "Diploma", "ITI", "BE", "B Tech", "M tech",
                "MCA", "MBA", "MCA", "BSC", "MSC", "BA", "MA", "B.COM", "M.COM"};
        for (int i = 0; i <= 17; i++) {
            Number number = new Number();
            number.setTextONEs(Ones[i]);
            this.numbers.add(number);
        }
        NumbersAdapter adapter = new NumbersAdapter(this.numbers);
        list.setAdapter(adapter);

        btnGetSelected.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                StringBuilder stringBuilder = new StringBuilder();
                for (Number number : numbers) {
                    if (number.isSelected()) {
                        if (stringBuilder.length() > 0)
                            stringBuilder.append(", ");
                        stringBuilder.append(number.getTextOnes());
                    }
                }
                Toast.makeText(getActivity(), stringBuilder.toString(), Toast.LENGTH_LONG).show();
            }
        });
    }
}



Bean Class

public class Number {
    private String textONEs;
    private boolean isSelected;

    public String getTextOnes() {
        return textONEs;
    }

    public void setTextONEs(String textONEs) {
        this.textONEs = textONEs;
    }


    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }
}

Adapter Class 
public class NumbersAdapter extends RecyclerView.Adapter<NumbersAdapter.ViewHolder> {

    ArrayList<Number> numbers;

    public NumbersAdapter(List<Number> numbers) {
        this.numbers = new ArrayList<>(numbers);
    }

    @Override    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.client_list_item, parent, false);
        return new ViewHolder(v);
    }

    @Override    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.bindData(numbers.get(position));

        holder.checkbox.setOnCheckedChangeListener(null);

        holder.checkbox.setChecked(numbers.get(position).isSelected());

        holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                numbers.get(holder.getAdapterPosition()).setSelected(isChecked);
            }
        });

// Check Box Select Method 
holder.parentLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.checkbox.performClick(); } });
    }

    @Override    public int getItemCount() {
        return numbers.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textName;
        private CheckBox checkbox;
        private LinearLayout lRootLayout,parentLayout;

        public ViewHolder(View v) {
            super(v);
            textName = (TextView) v.findViewById(R.id.textName);
            checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            lRootLayout=(LinearLayout) v.findViewById(R.id.lRootLayout);
            parentLayout=(LinearLayout) v.findViewById(R.id.parentLayout);
        }

        public void bindData(Number number) {
            textName.setText(number.getTextOnes());
        }
    }
}


Main XML 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:orientation="vertical"    tools:context="com.guna.recyclerviewwithcheckbox.MainActivityFragment"    tools:showIn="@layout/activity_main">

    <android.support.v7.widget.RecyclerView        android:id="@+id/list"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="0.9"        android:scrollbars="vertical" />

    <Button        android:id="@+id/btnGetSelected"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="0.1"        android:text="GET SELECTED" />
</LinearLayout>



adb.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/lRootLayout"    android:layout_width="match_parent"    android:layout_marginBottom="5dp"    android:layout_height="wrap_content"    android:orientation="vertical">



            <LinearLayout                android:id="@+id/parentLayout"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal"                android:padding="5dp">

                <TextView                    android:id="@+id/textName"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:textColor="@android:color/black" />
                <CheckBox                    android:id="@+id/checkbox"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight=".2"                    />
        </LinearLayout>
</LinearLayout>

Wednesday, 6 September 2017

Search Data From Recycle View Using Volley

Menu.File
volly_menu.


<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item        android:id="@+id/actiob_search_item"        android:icon="@android:drawable/ic_search_category_default"        android:title="Search"        app:showAsAction="ifRoom|collapseActionView"        app:actionViewClass="android.support.v7.widget.SearchView"/>


</menu>


Xml File

<?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"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context=".recVi.ViewClass"    tools:showIn="@layout/activity_user_data">



    <android.support.v7.widget.RecyclerView        android:id="@+id/rview"        android:layout_width="match_parent"        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>

</RelativeLayout>




Java Class

public class UserData extends AppCompatActivity implements SearchView.OnQueryTextListener {

    private ArrayList<Getdata> list = new ArrayList<>();
    private RecyclerView recyclerView;
    private DataAdpter dataAdpter;
    private ProgressDialog pDialog;


    String JSON_NAME = "Name";
    String JSON_EMAIL = "EmailId";
    String JSON_NO = "MobileNo";
    String JSON_GENDER = "Gender";

    private String lat, log;
    String id;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        list = new ArrayList<>();

        if (id != null) {
            id = getIntent().getStringExtra("$id");
        }


        recyclerView = (RecyclerView) findViewById(R.id.rview);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        GetDetails();
    }

    private void GetDetails() {
        pDialog = new ProgressDialog(this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();
        JSONObject jsonObject = new JSONObject();
        try {

            jsonObject.put("RegistrationId", 0);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                "http://aeps.gear.host/api/Test/GetDetails", jsonObject, new Response.Listener<JSONObject>() {
            @Override            public void onResponse(JSONObject response) {
                try {
                    String Status = response.getString("Status");

                    JSONArray jsonArray = response.getJSONArray("Data");
                    for (int i = 0; i < jsonArray.length(); i++) {

                        Getdata GetDataAdapter2 = new Getdata();

                        try {
                            JSONObject json = jsonArray.getJSONObject(i);
                            GetDataAdapter2.setName(json.getString(JSON_NAME));

                            GetDataAdapter2.setEmailId(json.getString(JSON_EMAIL));

                            GetDataAdapter2.setMobileNo(json.getString(JSON_NO));

                            GetDataAdapter2.setGender(json.getString(JSON_GENDER));

                            lat = json.getString("Latitude");
                            log = json.getString("Longitude");


                        } catch (JSONException e) {

                            e.printStackTrace();
                        }
                        list.add(GetDataAdapter2);
                    }
                    dataAdpter = new DataAdpter(list);
                    recyclerView.setAdapter(dataAdpter);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                pDialog.dismiss();
            }
        },
                new Response.ErrorListener() {
                    @Override                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(UserData.this, error.toString(), Toast.LENGTH_LONG).show();
                        pDialog.hide();
                    }
                });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(jsonObjReq);
    }

    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.volly_menu, menu);
        MenuItem menuItem = menu.findItem(R.id.actiob_search_item);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
        searchView.setOnQueryTextListener(this);


        return true;
    }

    @Override    public boolean onQueryTextSubmit(String query) {
        return false;
    }

    @Override    public boolean onQueryTextChange(String newText) {
        newText = newText.toLowerCase();
        ArrayList<Getdata> newList = new ArrayList<>();
        for (Getdata getdata : list) {
            String name = getdata.getName().toLowerCase();
            String gender = getdata.getGender().toLowerCase();
            if (name.contains(newText) || gender.contains(newText))
                newList.add(getdata);
        }
        dataAdpter.setFilter(newList);

        return true;
    }
}




Adapter Class 

public class DataAdpter extends RecyclerView.Adapter<DataAdpter.ViewHolder> {

    ArrayList<Getdata> arrayList = new ArrayList<>();

    public DataAdpter(ArrayList<Getdata> arrayList) {
        this.arrayList = arrayList;

    }

    @Override    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adpter, parent, false);
        return new ViewHolder(v);
    }

    @Override    public void onBindViewHolder(ViewHolder holder, int position) {

        Getdata getDataAdapter1 = arrayList.get(position);

        holder.textView_name.setText(getDataAdapter1.getName());

        holder.textView_email.setText(String.valueOf(getDataAdapter1.getEmailId()));

        holder.Mobile.setText(getDataAdapter1.getMobileNo());

        holder.gender.setText(getDataAdapter1.getGender());


    }

    @Override    public int getItemCount() {

        return arrayList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView textView_name;
        public TextView textView_email;
        public TextView Mobile;
        public TextView gender;


        public ViewHolder(View itemView) {

            super(itemView);

            textView_name = (TextView) itemView.findViewById(R.id.textView_name);
            textView_email = (TextView) itemView.findViewById(R.id.textView_email);
            Mobile = (TextView) itemView.findViewById(R.id.Mobile);
            gender = (TextView) itemView.findViewById(R.id.gender);

        }
    }

    public void setFilter(ArrayList<Getdata> newList) {

        arrayList = new ArrayList<>();
        arrayList.addAll(newList);
        notifyDataSetChanged();

    }

}


Adapter xml


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:card_view="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:background="@android:color/white"    android:orientation="vertical">

    <android.support.v7.widget.CardView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="5dp">

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


            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:layout_marginTop="5dp"                android:orientation="horizontal">


                <TextView                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight=".6"                    android:text="Name : "                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView                    android:id="@+id/textView_name"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text=""                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>

            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:layout_marginTop="5dp"
                android:orientation="horizontal">

                <TextView                    android:id="@+id/textView3"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight=".6"                    android:text="Email : "                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView                    android:id="@+id/textView_email"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text=""                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>

            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:layout_marginTop="5dp"
                android:orientation="horizontal">

                <TextView                    android:id="@+id/textView5"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight=".6"                    android:text="Mobile : "                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView                    android:id="@+id/Mobile"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text=""                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>

            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:layout_marginTop="5dp"                android:orientation="horizontal">

                <TextView                    android:id="@+id/textView7"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight=".6"                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView                    android:id="@+id/gender"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text=""                    android:textAppearance="?android:attr/textAppearanceLarge" />

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

</LinearLayout>

Friday, 1 September 2017

Google Place Picker LIb


Java Class

private LocationManager service;

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_address, container, false);

    service = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
   
    return view;
}


edtsubrub.setOnClickListener(this);

case R.id.map:
    if (!service.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showSettingsAlert();
    } else {
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
        try {
            startActivityForResult(builder.build((AppCompatActivity) getActivity()), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }


public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle("GPS settings");
    alertDialog.setMessage("Location is not enabled. Do you want to go to settings menu?");
    alertDialog.setPositiveButton("Settings",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(
                            Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    getActivity().startActivity(intent);
                }
            });
    alertDialog.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    alertDialog.show();
}




case R.id.edtsubrub:
    try {
        Intent intent =
                new PlaceAutocomplete
                        .IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                        .build(getActivity());
        startActivityForResult(intent, 1);
    } catch (GooglePlayServicesRepairableException e) {
    } catch (GooglePlayServicesNotAvailableException e) {
    }
    break;
default:



Change Navigation Icon In run time

Java Code

case R.id.img_menu:
    if (HomeFragment.count == 1) {
        HomeFragment homeFragment = new HomeFragment();
        fragmentManager.beginTransaction().
addToBackStack(null).replace(R.id.frame_layout, homeFragment).commit();
        imgMenu.setImageResource(R.drawable.menu);
        HomeFragment.count = 0;
    } else {
        drawerLayout.openDrawer(Gravity.LEFT);
    }
    break;

Home fragment 

public static int count = 0;

btnupdateone.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View v) {
        Fragment fragment = new Influencer();
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame_layout, fragment);
        MainActivity.imgMenu.setImageResource(R.drawable.top_arrow);
        count = 1;
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
});