Android Open Source - HijriCalendar-master Caldroid Sample Custom Adapter






From Project

Back to project page HijriCalendar-master.

License

The source code is released under:

MIT License

If you think the Android project HijriCalendar-master listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.caldroidsample;
/*from w ww  .  j ava  2 s. co m*/
import hirondelle.date4j.DateTime;

import java.util.HashMap;

import com.sahaab.hijri.caldroid.CaldroidFragment;
import com.sahaab.hijri.caldroid.CaldroidGridAdapter;
import com.sahaab.hijricalsample.R;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CaldroidSampleCustomAdapter extends CaldroidGridAdapter {

  public CaldroidSampleCustomAdapter(Context context, int month, int year,
      HashMap<String, Object> caldroidData,
      HashMap<String, Object> extraData) {
    super(context, month, year, caldroidData, extraData);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View cellView = convertView;

    // For reuse
    if (convertView == null) {
      cellView = inflater.inflate(R.layout.custom_cell, null);
    }

    int topPadding = cellView.getPaddingTop();
    int leftPadding = cellView.getPaddingLeft();
    int bottomPadding = cellView.getPaddingBottom();
    int rightPadding = cellView.getPaddingRight();

    TextView tv1 = (TextView) cellView.findViewById(R.id.tv1);
    TextView tv2 = (TextView) cellView.findViewById(R.id.tv2);

    tv1.setTextColor(Color.BLACK);

    // Get dateTime of this cell
    DateTime dateTime = this.datetimeList.get(position);
    Resources resources = context.getResources();

    // Set color of the dates in previous / next month
    if (dateTime.getMonth() != month) {
      tv1.setTextColor(resources
          .getColor(R.color.caldroid_darker_gray));
    }

    boolean shouldResetDiabledView = false;
    boolean shouldResetSelectedView = false;

    // Customize for disabled dates and date outside min/max dates
    if ((minDateTime != null && dateTime.lt(minDateTime))
        || (maxDateTime != null && dateTime.gt(maxDateTime))
        || (disableDates != null && disableDates.indexOf(dateTime) != -1)) {

      tv1.setTextColor(CaldroidFragment.disabledTextColor);
      if (CaldroidFragment.disabledBackgroundDrawable == -1) {
        cellView.setBackgroundResource(R.drawable.disable_cell);
      } else {
        cellView.setBackgroundResource(CaldroidFragment.disabledBackgroundDrawable);
      }

      if (dateTime.equals(getToday())) {
        cellView.setBackgroundResource(R.drawable.red_border_gray_bg);
      }

    } else {
      shouldResetDiabledView = true;
    }

    // Customize for selected dates
    if (selectedDates != null && selectedDates.indexOf(dateTime) != -1) {
      if (CaldroidFragment.selectedBackgroundDrawable != -1) {
        cellView.setBackgroundResource(CaldroidFragment.selectedBackgroundDrawable);
      } else {
        cellView.setBackgroundColor(resources
            .getColor(R.color.caldroid_sky_blue));
      }

      tv1.setTextColor(CaldroidFragment.selectedTextColor);

    } else {
      shouldResetSelectedView = true;
    }

    if (shouldResetDiabledView && shouldResetSelectedView) {
      // Customize for today
      if (dateTime.equals(getToday())) {
        cellView.setBackgroundResource(R.drawable.red_border);
      } else {
        cellView.setBackgroundResource(R.drawable.cell_bg);
      }
    }

    tv1.setText("" + dateTime.getDay());
    tv2.setText("Hi");

    // Somehow after setBackgroundResource, the padding collapse.
    // This is to recover the padding
    cellView.setPadding(leftPadding, topPadding, rightPadding,
        bottomPadding);

    // Set custom color if required
    setCustomResources(dateTime, cellView, tv1);

    return cellView;
  }

}




Java Source Code List

com.antonyt.infiniteviewpager.InfinitePagerAdapter.java
com.antonyt.infiniteviewpager.InfiniteViewPager.java
com.caldroidsample.CaldroidSampleActivity.java
com.caldroidsample.CaldroidSampleCustomAdapter.java
com.caldroidsample.CaldroidSampleCustomFragment.java
com.sahaab.hijri.caldroid.CaldroidFragment.java
com.sahaab.hijri.caldroid.CaldroidGridAdapter.java
com.sahaab.hijri.caldroid.CaldroidListener.java
com.sahaab.hijri.caldroid.CalendarHelper.java
com.sahaab.hijri.caldroid.DateGridFragment.java
com.sahaab.hijri.caldroid.MonthPagerAdapter.java
com.sahaab.hijri.caldroid.SquareTextView.java
com.sahaab.hijri.caldroid.WeekdayArrayAdapter.java
com.sahaab.hijricalendar.HijriCalendarDate.java