• This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Find Place Autocomplete Textview

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.PlaceBuffer;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;

import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.ResultCallback;

public class GoogeAotoText extends AppCompatActivity implements        GoogleApiClient.OnConnectionFailedListener,
        GoogleApiClient.ConnectionCallbacks {
    private static final String LOG_TAG = "MainActivity";
    private static final int GOOGLE_API_CLIENT_ID = 0;
    private AutoCompleteTextView mAutocompleteTextView;

    private GoogleApiClient mGoogleApiClient;
    private PlaceArrayAdapter mPlaceArrayAdapter;
    private TextView mAddressTextView;

    private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds(
            new LatLng(37.398160, -122.180831), new LatLng(37.430610, -121.972090));

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_googe_aoto_text);
        mGoogleApiClient = new GoogleApiClient.Builder(GoogeAotoText.this)
                .addApi(Places.GEO_DATA_API)
                .enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
                .addConnectionCallbacks(this)
                .build();
        mAutocompleteTextView = (AutoCompleteTextView) findViewById(R.id
                .etPopupDestination);
        mAutocompleteTextView.setThreshold(3);
        mAddressTextView = (TextView) findViewById(R.id.address);
        mAutocompleteTextView.setOnItemClickListener(mAutocompleteClickListener);
        mPlaceArrayAdapter = new PlaceArrayAdapter(this, android.R.layout.simple_list_item_1,
                BOUNDS_MOUNTAIN_VIEW, null);
        mAutocompleteTextView.setAdapter(mPlaceArrayAdapter);    }

    private AdapterView.OnItemClickListener mAutocompleteClickListener            = new AdapterView.OnItemClickListener() {
        @Override        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final PlaceArrayAdapter.PlaceAutocomplete item = mPlaceArrayAdapter.getItem(position);
            final String placeId = String.valueOf(item.placeId);
            Log.i(LOG_TAG, "Selected: " + item.description);
            PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
            Log.i(LOG_TAG, "Fetching details for ID: " + item.placeId);
        }
    };

    private ResultCallback<PlaceBuffer> mUpdatePlaceDetailsCallback            = new ResultCallback<PlaceBuffer>() {
        @Override        public void onResult(PlaceBuffer places) {
            if (!places.getStatus().isSuccess()) {
                Log.e(LOG_TAG, "Place query did not complete. Error: " +
                        places.getStatus().toString());
                return;
            }
            // Selecting the first object buffer.            final Place place = places.get(0);
            CharSequence attributions = places.getAttributions();
            mAddressTextView.setText(Html.fromHtml(place.getAddress() + ""));
           /* mNameTextView.setText(Html.fromHtml(place.getName() + ""));
            mIdTextView.setText(Html.fromHtml(place.getId() + ""));            mPhoneTextView.setText(Html.fromHtml(place.getPhoneNumber() + ""));            mWebTextView.setText(place.getWebsiteUri() + "");            if (attributions != null) {                mAttTextView.setText(Html.fromHtml(attributions.toString()));            }*/        }
    };

    @Override    public void onConnected(Bundle bundle) {
        mPlaceArrayAdapter.setGoogleApiClient(mGoogleApiClient);
        Log.i(LOG_TAG, "Google Places API connected.");

    }

    @Override    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.e(LOG_TAG, "Google Places API connection failed with error code: "                + connectionResult.getErrorCode());

        Toast.makeText(this,
                "Google Places API connection failed with error code:" +
                        connectionResult.getErrorCode(),
                Toast.LENGTH_LONG).show();
    }

    @Override    public void onConnectionSuspended(int i) {
        mPlaceArrayAdapter.setGoogleApiClient(null);
        Log.e(LOG_TAG, "Google Places API connection suspended.");
    }
}


-----------------------------****--------------------------------------------------------

layout  :-  activity_googe_aoto_text


<?xml version="1.0" encoding="utf-8"?><LinearLayout 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="com.nagraj.customiamge.GoogeAotoText">
    <AutoCompleteTextView        android:id="@+id/etPopupDestination"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1"        android:background="@null"
        android:drawablePadding="5dp"        android:hint="Search destination"        android:imeOptions="actionDone"        android:inputType="textNoSuggestions"        android:paddingLeft="10dp"        android:paddingRight="2dp"        android:singleLine="true"        android:textColor="#FFFFFF"        android:textSize="25dp" >

        <requestFocus />
    </AutoCompleteTextView>
    <TextView        android:id="@+id/address"        android:layout_width="wrap_content"        android:layout_height="wrap_content"       />


    </LinearLayout>


--------------------*******************--------------------------------

Adapter  :-- PlaceArrayAdapter

        import android.content.Context;
        import android.util.Log;
        import android.widget.ArrayAdapter;
        import android.widget.Filter;
        import android.widget.Filterable;
        import android.widget.Toast;

        import com.google.android.gms.common.api.GoogleApiClient;
        import com.google.android.gms.common.api.PendingResult;
        import com.google.android.gms.common.api.Status;
        import com.google.android.gms.location.places.AutocompleteFilter;
        import com.google.android.gms.location.places.AutocompletePrediction;
        import com.google.android.gms.location.places.AutocompletePredictionBuffer;
        import com.google.android.gms.location.places.Places;
        import com.google.android.gms.maps.model.LatLngBounds;

        import java.util.ArrayList;
        import java.util.Iterator;
        import java.util.concurrent.TimeUnit;

public class PlaceArrayAdapter
        extends ArrayAdapter<PlaceArrayAdapter.PlaceAutocomplete> implements Filterable {
    private static final String TAG = "PlaceArrayAdapter";
    private GoogleApiClient mGoogleApiClient;
    private AutocompleteFilter mPlaceFilter;
    private LatLngBounds mBounds;
    private ArrayList<PlaceAutocomplete> mResultList;

    /**     * Constructor     *     * @param context  Context     * @param resource Layout resource     * @param bounds   Used to specify the search bounds     * @param filter   Used to specify place types     */    public PlaceArrayAdapter(Context context, int resource, LatLngBounds bounds,
                             AutocompleteFilter filter) {
        super(context, resource);
        mBounds = bounds;
        mPlaceFilter = filter;
    }

    public void setGoogleApiClient(GoogleApiClient googleApiClient) {
        if (googleApiClient == null || !googleApiClient.isConnected()) {
            mGoogleApiClient = null;
        } else {
            mGoogleApiClient = googleApiClient;
        }
    }

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

    @Override    public PlaceAutocomplete getItem(int position) {
        return mResultList.get(position);
    }

    private ArrayList<PlaceAutocomplete> getPredictions(CharSequence constraint) {
        if (mGoogleApiClient != null) {
            Log.i(TAG, "Executing autocomplete query for: " + constraint);
            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi                            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                    mBounds, mPlaceFilter);
            // Wait for predictions, set the timeout.            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);
            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                Toast.makeText(getContext(), "Error: " + status.toString(),
                        Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Error getting place predictions: " + status
                        .toString());
                autocompletePredictions.release();
                return null;
            }

            Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                    + " predictions.");
            Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
            ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
            while (iterator.hasNext()) {
                AutocompletePrediction prediction = iterator.next();
                resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                        prediction.getFullText(null)));
            }
            // Buffer release            autocompletePredictions.release();
            return resultList;
        }
        Log.e(TAG, "Google API client is not connected.");
        return null;
    }

    @Override    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults results = new FilterResults();
                if (constraint != null) {
                    // Query the autocomplete API for the entered constraint                    mResultList = getPredictions(constraint);
                    if (mResultList != null) {
                        // Results                        results.values = mResultList;
                        results.count = mResultList.size();
                    }
                }
                return results;
            }

            @Override            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    // The API returned at least one result, update the data.                    notifyDataSetChanged();
                } else {
                    // The API did not return any results, invalidate the data set.                    notifyDataSetInvalidated();
                }
            }
        };
        return filter;
    }

    class PlaceAutocomplete {

        public CharSequence placeId;
        public CharSequence description;

        PlaceAutocomplete(CharSequence placeId, CharSequence description) {
            this.placeId = placeId;
            this.description = description;
        }

        @Override        public String toString() {
            return description.toString();
        }
    }
}

----------------------------*******************----------------------------

manifest:-


<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.nagraj.customiamge">

    <uses-permission android:name="android.permission.INTERNET" />
    <!--plase -->    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>



    <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=".GoogeAotoText">
            <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.geo.API_KEY"            android:value="Your key"/>
        <meta-data            android:name="com.google.android.gms.version"            android:value="@integer/google_play_services_version"/>

    </application>

</manifest>


---------------------------------------*********************-------------------------------

dependencies :-
    compile 'com.google.android.gms:play-services-places:10.2.1'
Share:

Pick multiple images from gallery OR Custom gallery

import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import java.util.ArrayList;

import static android.R.attr.action;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button camera,gallery;
    private LinearLayout lnrImages;
    private Button btnAddPhots;
    private Button btnSaveImages;
    private ArrayList<String> imagesPathList;
    private Bitmap yourbitmap;
    private Bitmap resized;
    private final int PICK_IMAGE_MULTIPLE =1;
private final int SELECT_PHOTO =2;
private ArrayList<String>photos;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); camera = (Button) findViewById(R.id.camera); gallery = (Button) findViewById(R.id.gallery); camera.setOnClickListener(this); gallery.setOnClickListener(this); } @Override public void onClick(View v) { if(v == camera){
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
} if(v == gallery){ Intent intent = new Intent(MainActivity.this,CustomPhotoGalleryActivity.class); startActivityForResult(intent,PICK_IMAGE_MULTIPLE); } }
Share:

zz

https://github.com/ddanny/achartengine/blob/master/achartengine/demo/org/achartengine/chartdemo/demo/chart/PieChartBuilder.java
Share:

RecyclerView

Add dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:24.2.1'


    compile 'com.android.support:recyclerview-v7:24.1.1'    compile 'com.android.support:design:24.1.1'
}

----------------------------***-------------------------------

main class


package com.wdp.recyclerviewdemo;

import android.graphics.Movie;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.wdp.recyclerviewdemo.Adapter.MoviesAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerList;
    private MoviesAdapter mAdapter;
    private List<String> movieList = new ArrayList<>();

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        movieList.add("nagjee");
        movieList.add("Harsh");
        movieList.add("Gaurav");

        recyclerList = (RecyclerView) findViewById(R.id.recyclerList);
        mAdapter = new MoviesAdapter(movieList);
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
        recyclerList.setLayoutManager(mLayoutManager);

        recyclerList.setAdapter(mAdapter);

        //prepareMovieData();    }

   /* private void prepareMovieData() {        Movies movies = new Movies("Mad Max: Fury Road", "Action & Adventure", "2015");        movieList.add(movies);    }*/}

__________________________________________________***________________

layout  


<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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.support.v7.widget.RecyclerView        android:id="@+id/recyclerList"        android:layout_width="match_parent"        android:layout_height="wrap_content">
   </android.support.v7.widget.RecyclerView>
</RelativeLayout>




_______________________***______________________-

Adapter 

import android.content.Context;
import android.graphics.Movie;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wdp.recyclerviewdemo.Movies;
import com.wdp.recyclerviewdemo.R;

import java.util.ArrayList;
import java.util.List;


public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.MyViewHolder> {
    Context context;
    LayoutInflater layoutInflater;
    private List<String> moviesLists;

    public MoviesAdapter(List<String> movieList) {
        this.moviesLists = movieList;
    }

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

    @Override    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.title.setText(moviesLists.get(position));

    }

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

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView title, genre, year;

        public MyViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            genre = (TextView) itemView.findViewById(R.id.genre);
            year = (TextView) itemView.findViewById(R.id.year);
        }
    }
}


-------------------**-------------------------------
layout



<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:padding="10dp">

    <TextView        android:hint="dfsd"        android:id="@+id/title"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:padding="10dp"        android:textColor="@android:color/black"        android:textSize="16dp"        android:textStyle="bold" />

    <TextView        android:id="@+id/genre"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_below="@id/title"        android:padding="10dp"        android:textColor="@android:color/black" />

    <TextView        android:id="@+id/year"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentRight="true"        android:padding="10dp"        android:text="dgfdhgjhhg"        android:textColor="@android:color/black" />
</RelativeLayout>


--------------------------***------------------------------

model class


public class Movies {
    private String title, genre, year;

    public Movies() {
    }

    public Movies(String title, String genre, String year) {
        this.title = title;
        this.genre = genre;
        this.year = year;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String name) {
        this.title = name;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }
}

Share:

Couston TextViewNormal set font

Custom text view set font

* first of all assest folder paste font



import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;



public class TextViewNormal extends TextView {


    public TextViewNormal(Context context) {
        super(context);
        init();
       /* Typeface face=Typeface.createFromAsset(context.getAssets(), "helvetica_neue_lt_pro.otf");        this.setTypeface(face);*/    }

    public TextViewNormal(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TextViewNormal(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

   
    private void init() {
        Typeface face=Typeface.createFromAsset(getContext().getAssets(), "helvetica_neue_lt_pro.otf");
        this.setTypeface(face);
    }
}

______________________________________________________________________


<com.view.TextViewNormal 
    android:layout_width="wrap_content"    android:layout_height="wrap_content"     />
Share:

retrofitdemo

<uses-permission android:name="android.permission.INTERNET"/>








Share:

custom calendar in android



Create CalenderDemo calss


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Locale;

public class CalenderDemo extends AppCompatActivity implements View.OnClickListener, CalenderViewAdapter.Test {

    String TAG = getClass().getName();

    private TextView currentMonth;
    LinearLayout prevMonth, nextMonth;

    private GridView calendarView;
    private CalenderViewAdapter adapter;
    private Calendar _calendar;
    private int month, year;
    private final DateFormat dateFormatter = new DateFormat();
    private static final String dateTemplate = "MMMM yyyy";
    RelativeLayout dynamicMenuViewRelativeView;
    CalenderDemo act = this;

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

        initializeView();
        _calendar = Calendar.getInstance(Locale.getDefault());
        month = _calendar.get(Calendar.MONTH) + 1;
        year = _calendar.get(Calendar.YEAR);
        currentMonth.setText(DateFormat.format(dateTemplate, _calendar.getTime()));

        adapter = new CalenderViewAdapter(getApplicationContext(), R.id.calendar_day_grid_cell, month, year, this);
        calendarView.setAdapter(adapter);
        adapter.notifyDataSetChanged();

        //getJobsOfUser();
       /* calendarView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               // Toast.makeText(getApplicationContext(), "calendarView", Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "calendarView" + parent + " " + position + " " + id, Toast.LENGTH_LONG).show();
            }
        });*/

       /* calendarView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getBaseContext(), "calendarView", Toast.LENGTH_LONG).show();
            }
        });*/
    }


    private void initializeView() {
        prevMonth = (LinearLayout) this.findViewById(R.id.prev_month);
        currentMonth = (TextView) this.findViewById(R.id.current_month);
        nextMonth = (LinearLayout) this.findViewById(R.id.next_month);
        calendarView = (GridView) this.findViewById(R.id.calender_grid);
        dynamicMenuViewRelativeView = (RelativeLayout) findViewById(R.id.add_menu_view_relative_layout);

        prevMonth.setOnClickListener(this);

        nextMonth.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.prev_month:

                if (month <= 1) {
                    month = 12;
                    year--;
                } else {
                    month--;
                }


                setGridCellAdapterToDate(month, year);

                break;

            case R.id.next_month:

                if (month > 11) {
                    month = 1;
                    year++;
                } else {
                    month++;
                }
                setGridCellAdapterToDate(month, year);
                break;

        }
    }


    private void setGridCellAdapterToDate(int month, int year) {
        adapter = new CalenderViewAdapter(getApplicationContext(), R.id.calendar_day_grid_cell, month, year, this);
        _calendar.set(year, month - 1, _calendar.get(Calendar.DAY_OF_MONTH));
        currentMonth.setText(DateFormat.format(dateTemplate, _calendar.getTime()));

        adapter.notifyDataSetChanged();
        calendarView.setAdapter(adapter);
    }

    @Override
    public void onDateClick(String date) {
        Toast.makeText(this, "oks" + date, Toast.LENGTH_SHORT).show();
        adapter.notifyDataSetChanged();
        calendarView.setAdapter(adapter);
    }
}


Xml  activity_calender_demo



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#FFF">


    <GridView
        android:clickable="true"
        android:id="@+id/calender_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/rl"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="15dp"
        android:background="#fff"
        android:numColumns="7">

    </GridView>

    <View
        android:id="@+id/view_of_line"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/calender_grid"
        android:layout_marginTop="15dp"
        android:background="#7aac7e">

    </View>

   <!-- <ListView
        android:id="@+id/job_list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linear_layout_below_list_view"
        android:layout_below="@+id/view_of_line"
        android:layout_marginBottom="@dimen/small_size"
        android:layout_marginLeft="@dimen/medium_size"
        android:layout_marginTop="@dimen/small_size"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp">

    </ListView>-->


    <!--<TextView
        android:id="@+id/list_empty_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linear_layout_below_list_view"
        android:layout_below="@+id/view_of_line"
        android:layout_marginBottom="@dimen/small_size"
        android:layout_marginLeft="@dimen/medium_size"
        android:layout_marginTop="@dimen/small_size"
        android:text="@string/no_jobs_available"/>
-->

   <!-- <LinearLayout
        android:id="@+id/linear_layout_below_list_view"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/edtText_height"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="@dimen/small_size"
        android:layout_marginLeft="@dimen/small_size"
        android:layout_marginRight="@dimen/small_size"
        android:background="@drawable/radio_button_selector"
        android:orientation="horizontal"
        android:weightSum="3">

        <LinearLayout
            android:id="@+id/completed_linear_layout"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/completed_layout_background_checked"
            android:clickable="true"
            android:focusable="true"
            android:gravity="center">

            <TextView
                android:id="@+id/show_completed_job_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="Completed" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/active_linear_layout"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:background="@drawable/active_layout_background_unchecked"
            android:focusable="true"
            android:gravity="center"

            >


            <TextView
                android:id="@+id/show_active_job_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="Active" />

        </LinearLayout>
        &lt;!&ndash;nag&ndash;&gt;
        <LinearLayout
            android:id="@+id/runbal_linear_layout"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:background="@drawable/active_layout_background_unchecked"
            android:focusable="true"
            android:gravity="center"

            >


            <TextView
                android:id="@+id/run_active_job_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="Posted" />

        </LinearLayout>
    </LinearLayout>-->

    <RelativeLayout
        android:id="@+id/add_menu_view_relative_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/rl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#fcfafa"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/add_menu_view_relative_layout"
        android:layout_toEndOf="@+id/add_menu_view_relative_layout">

        <RelativeLayout

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="15dp">

            <LinearLayout
                android:id="@+id/prev_month"
                android:layout_width="50dp"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="#79209c">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:layout_gravity="center"
                    android:background="#79209c" />

            </LinearLayout>


            <TextView
                android:id="@+id/current_month"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="JANUARY 2015"
                android:textSize="16dp"
                android:textStyle="bold" />

            <LinearLayout
                android:id="@+id/next_month"
                android:layout_width="50dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:gravity="right"
                android:background="#79209c">

                <ImageView
                    android:layout_width="wrap_content"


                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:background="#79209c" />


            </LinearLayout>


        </RelativeLayout>

        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:orientation="horizontal"
            android:paddingBottom="15dp"
            android:weightSum="7">

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Su"
                />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Mo" />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Tu" />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="We" />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Th" />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Fr" />

            <TextView

                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Sa" />
        </LinearLayout>
    </LinearLayout>


</RelativeLayout>


Create CalenderViewAdapter 


import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;

public class CalenderViewAdapter extends BaseAdapter implements OnClickListener {

    private static final String tag = "GridCellAdapter";
    private final Context _context;
    ArrayList model;
    Test test;

    String getdat= "29/3/2017";
    private final List<String> list;
    private static final int DAY_OFFSET = 1;
    private final String[] weekdays = new String[]{"Su", "Mo", "Tu", "We",
            "Th", "Fr", "Sa"};
    private final String[] months = {"January", "February", "March",
            "April", "May", "June", "July", "August", "September",
            "October", "November", "December"};
    private final int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30,
            31, 30, 31};
    private int daysInMonth;
    private int currentDayOfMonth;
    private int currentWeekDay;
    private TextView gridcell;
    RelativeLayout mRelative_Root;
    // private final HashMap<String, Integer> eventsPerMonthMap;
    Activity av;
    private final SimpleDateFormat dateFormatter = new SimpleDateFormat(
            "dd-MMM-yyyy");
    boolean dot_check_flag = false;
    String dddddd ;

    public CalenderViewAdapter(Context context, int calendarDayGridcell, int month, int year, Test test) {
        super();
        this._context = context;
        this.list = new ArrayList<String>();
        Log.d(tag, "==> Passed in Date FOR Month: " + month + " "
                + "Year: " + year);
        Calendar calendar = Calendar.getInstance();
        setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
        setCurrentWeekDay(calendar.get(Calendar.DAY_OF_WEEK));
        Log.d(tag, "New Calendar:= " + calendar.getTime().toString());
        Log.d(tag, "CurrentDayOfWeek :" + getCurrentWeekDay());
        Log.d(tag, "CurrentDayOfMonth :" + getCurrentDayOfMonth());

        this.test = test;
        printMonth(month, year);

        // Find Number of Events
        //   eventsPerMonthMap = findNumberOfEventsPerMonth(year, month);

    }

    public interface Test {
        public void onDateClick(String date);
    }

    private String getMonthAsString(int i) {
        return months[i];
    }

    private String getWeekDayAsString(int i) {
        return weekdays[i];
    }

    private int getNumberOfDaysOfMonth(int i) {
        return daysOfMonth[i];
    }


    private void printMonth(int mm, int yy) {
        Log.d(tag, "==> printMonth: mm: " + mm + " " + "yy: " + yy);
        int trailingSpaces = 0;
        int daysInPrevMonth = 0;
        int prevMonth = 0;
        int prevYear = 0;
        int nextMonth = 0;
        int nextYear = 0;

        int currentMonth = mm - 1;
        String currentMonthName = getMonthAsString(currentMonth);
        daysInMonth = getNumberOfDaysOfMonth(currentMonth);

        Log.d(tag, "Current Month: " + " " + currentMonthName + " having "
                + daysInMonth + " days.");

        GregorianCalendar cal = new GregorianCalendar(yy, currentMonth, 1);
        Log.d(tag, "Gregorian Calendar:= " + cal.getTime().toString());

        if (currentMonth == 11) {
            prevMonth = currentMonth - 1;
            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
            nextMonth = 0;
            prevYear = yy;
            nextYear = yy + 1;
            Log.d(tag, "*->PrevYear: " + prevYear + " PrevMonth:"
                    + prevMonth + " NextMonth: " + nextMonth
                    + " NextYear: " + nextYear);
        } else if (currentMonth == 0) {
            prevMonth = 11;
            prevYear = yy - 1;
            nextYear = yy;
            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
            nextMonth = 1;
            Log.d(tag, "**--> PrevYear: " + prevYear + " PrevMonth:"
                    + prevMonth + " NextMonth: " + nextMonth
                    + " NextYear: " + nextYear);
        } else {
            prevMonth = currentMonth - 1;
            nextMonth = currentMonth + 1;
            nextYear = yy;
            prevYear = yy;
            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
            Log.d(tag, "***---> PrevYear: " + prevYear + " PrevMonth:"
                    + prevMonth + " NextMonth: " + nextMonth
                    + " NextYear: " + nextYear);
        }

        int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
        trailingSpaces = currentWeekDay;

        Log.d(tag, "Week Day:" + currentWeekDay + " is "
                + getWeekDayAsString(currentWeekDay));
        Log.d(tag, "No. Trailing space to Add: " + trailingSpaces);
        Log.d(tag, "No. of Days in Previous Month: " + daysInPrevMonth);

        if (cal.isLeapYear(cal.get(Calendar.YEAR)))
            if (mm == 2)
                ++daysInMonth;
            else if (mm == 3)
                ++daysInPrevMonth;

        // Trailing Month days
        for (int i = 0; i < trailingSpaces; i++) {
            Log.d(tag, "PREV MONTH:= " + prevMonth + " => " + getMonthAsString(prevMonth) + " " + String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET) + i));

            list.add(String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET) + i) + "-GREY" + "-" + getMonthAsString(prevMonth) + "-" + prevYear);
        }

        // Current Month Days
        for (int i = 1; i <= daysInMonth; i++) {
            Log.d(currentMonthName, String.valueOf(i) + " "
                    + getMonthAsString(currentMonth) + " " + yy);
            if (i == getCurrentDayOfMonth()) {
                list.add(String.valueOf(i) + "-BLUE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
            } else {
                list.add(String.valueOf(i) + "-WHITE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
            }
        }

        // Leading Month days
        for (int i = 0; i < list.size() % 7; i++) {
            Log.d(tag, "NEXT MONTH:= " + getMonthAsString(nextMonth));
            list.add(String.valueOf(i + 1) + "-GREY" + "-" + getMonthAsString(nextMonth) + "-" + nextYear);
        }
    }


    private HashMap<String, Integer> findNumberOfEventsPerMonth(int year,
                                                                int month) {
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        return map;
    }


    @Override
    public void onClick(View view) {
        String date_month_year = (String) view.getTag();

        Log.e("Selected date", date_month_year);

        try {
            Date parsedDate = dateFormatter.parse(date_month_year);
            Log.d(tag, "Parsed Date: " + parsedDate.toString());

        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

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

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) _context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.calender_view_layout, parent, false);
        }

        // Get a reference to the Day gridcell
        gridcell = (TextView) row.findViewById(R.id.calendar_day_grid_cell);
        mRelative_Root = (RelativeLayout) row.findViewById(R.id.mRelative_Root);
        gridcell.setOnClickListener(this);
        TextView tvdot = (TextView) row.findViewById(R.id.cdot_tv);

        // ACCOUNT FOR SPACING

        Log.d(tag, "Current Day: " + getCurrentDayOfMonth());

        String[] day_color = list.get(position).split("-");
        final String theday = day_color[0];
        String themonth = day_color[2];
        String theyear = day_color[3];


  /*if ((!eventsPerMonthMap.isEmpty()) && (eventsPerMonthMap != null))
           {
   if (eventsPerMonthMap.containsKey(theday))
   {
    num_events_per_day = (TextView) row
      .findViewById(R.id.num_events_per_day);

    Integer numEvents = (Integer) eventsPerMonthMap.get(theday);
    num_events_per_day.setText(numEvents.toString());
   }
  }*/

        int monthPosition = 0;
        for (int i = 0; i < months.length; i++) {
            if (months[i].equals(themonth.trim())) {
                monthPosition++;
                break;
            } else {
                monthPosition++;
            }

        }
        gridcell.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(test!=null)
                {
                    test.onDateClick(theday);
                    dddddd =theday;
                }
            }
        });

        String date_for_dot = theday + "/" + monthPosition + "/" + theyear;
       /* for(int i=0;i<model.size();i++)
        {*/
           /* String f=model.get(i).getJobDate();
            if(f.equals(date_for_dot)){
                dot_check_flag=true;
                break;
            }else{
                dot_check_flag=false;
            }*/
        //Toast.makeText(_context,themonth+"\n"+date_for_dot+"\n"+dot_check_flag+"\n"+f,Toast.LENGTH_SHORT).show();

        // }


        // Set the Day GridCell
        gridcell.setText(theday);


        gridcell.setTag(theday + "-" + themonth + "-" + theyear);
        Log.d(tag, "Setting GridCell " + theday + "-" + themonth + "-" + theyear);

        if(dddddd != null){
            if (theday.equalsIgnoreCase(dddddd)){
                gridcell.setTextColor(_context.getResources().getColor(R.color.white));
                gridcell.setBackgroundDrawable(_context.getResources().getDrawable(R.drawable.blue_circle_drawable));
                if (!dot_check_flag)
                    tvdot.setBackgroundResource(R.color.white);
            }else {
                gridcell.setTextColor(_context.getResources().getColor(R.color.lightgray02));
                if (!dot_check_flag)
                    tvdot.setBackgroundResource(R.color.white);
            }
        }

        if(date_for_dot.equalsIgnoreCase(getdat)){
            gridcell.setTextColor(_context.getResources().getColor(R.color.white));
            gridcell.setBackgroundDrawable(_context.getResources().getDrawable(R.drawable.blue_circle_drawable));
            if (!dot_check_flag)
                tvdot.setBackgroundResource(R.color.white);
        }


        //22/8/2015
        if (day_color[1].equals("GREY")) {
            gridcell.setTextColor(_context.getResources().getColor(R.color.lightgray));
            if (!dot_check_flag)
                tvdot.setBackgroundResource(R.color.white);

        }
        if (day_color[1].equals("WHITE")) {
            gridcell.setTextColor(_context.getResources().getColor(R.color.lightgray02));
            if (!dot_check_flag)
                tvdot.setBackgroundResource(R.color.white);

        }
        if (day_color[1].equals("BLUE")) {
            gridcell.setTextColor(_context.getResources().getColor(R.color.white));
            gridcell.setBackgroundDrawable(_context.getResources().getDrawable(R.drawable.blue_circle_drawable));
            if (!dot_check_flag)
                tvdot.setBackgroundResource(R.color.white);


        }

        return row;

    }

    public int getCurrentDayOfMonth() {
        return currentDayOfMonth;
    }

    private void setCurrentDayOfMonth(int currentDayOfMonth) {
        this.currentDayOfMonth = currentDayOfMonth;
    }

    public void setCurrentWeekDay(int currentWeekDay) {
        this.currentWeekDay = currentWeekDay;
    }

    public int getCurrentWeekDay() {
        return currentWeekDay;
    }


}

Create calender_view_layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:gravity="center"
    android:id="@+id/mRelative_Root"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/calendar_day_grid_cell"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:gravity="center"
        android:text="8"
        android:textSize="15dp"
        android:textColor="#343663" >
    </TextView>
    <TextView
        android:id="@+id/cdot_tv"
        android:layout_width="3dp"
        android:layout_below="@id/calendar_day_grid_cell"
        android:layout_height="3dp"
        android:layout_marginLeft="13dp"
        android:gravity="center_vertical"
        android:background="#343663"
         >
    </TextView>
</RelativeLayout>

Create drawable   
blue_circle_drawable

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

    <solid android:color="@color/blue"></solid>
    <size android:width="1dp" android:height="1dp" ></size>

</shape>

Share:
Powered by Blogger.

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.