Android Open Source - Common-Library Calendar Grid View






From Project

Back to project page Common-Library.

License

The source code is released under:

Apache License

If you think the Android project Common-Library 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.morgan.library.widget.calendar;
/*w  w  w  .  jav a2s  .  com*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.morgan.library.R;
import com.morgan.library.widget.calendar.CalendarWidget.Day;

public class CalendarGridView extends LinearLayout {

  private Context mContext;
  private ArrayList<TextView> mTextViews = new ArrayList<TextView>();
  private OnItemClickListener mOnItemClickListener;
  private List<Day> mDays;
  private int indexOfFirstDay;
  private int indexOfLastDay;
  transient int selectedPositon = -1;

  public CalendarGridView(Context context) {
    super(context);
    mContext = context;
    setGirdView();
  }

  private void setGirdView() {
    LayoutInflater.from(mContext).inflate(R.layout.calendar_grid, this);
    for (int i = 0; i < 42; i++) {
      TextView v = (TextView) findViewWithTag("" + i);
      v.setText("" + i);
      mTextViews.add(v);
    }
  }

  public void setListDay(ArrayList<Day> days, int indexOfFirstDay,
      int indexOfLastDay) {
    mDays = days;
    this.indexOfFirstDay = indexOfFirstDay;
    this.indexOfLastDay = indexOfLastDay;

    notifyDataSetChanged();
  }

  public void notifyDataSetChanged() {
    int i = 0;
    for (TextView v : mTextViews) {
      Day day = getItem(i);
      v.setText(day.getDay() + "");
      v.setTextColor(getResources().getColor(R.color.black));
      v.setBackgroundResource(android.R.color.transparent);
      if (i < indexOfFirstDay || i > indexOfLastDay) {
        v.setTextColor(getResources().getColor(
            R.color.calendar_other_day_color));
      }

      if (day.isToday()) {
        v.setBackgroundResource(R.color.canlendar_divider_color);
      }

      if (day.isSelectedDay()) {
        v.setTextColor(getResources().getColor(R.color.white));
        v.setBackgroundResource(R.color.calendar_select_day_color);
      }

      i++;
    }
  }

  public Day getItem(int p) {
    return mDays.get(p);
  }

  public int getCount() {
    return mDays.size();
  }

  public void setSelectedPositon(int p) {
    selectedPositon = p;
  }

  public int selectedPositonToPos(int p) {
    if (getCount() - indexOfLastDay > 8) {
      return p + getCount() - 14;
    } else {
      return p + getCount() - 7;
    }
  }

  public int pointToPosition(int x, int y) {
    int line = y / (getHeight() / 6);
    int p = (int) (line * 7 + Math.ceil(x / (float) (getWidth() / 7)));
    if (mOnItemClickListener != null)
      mOnItemClickListener.onItemClick(null, this, p - 1, 0l);
    return p;
  }

  public void setOnItemClickListener(OnItemClickListener l) {
    mOnItemClickListener = l;
  }
}




Java Source Code List

com.morgan.library.app.APPContext.java
com.morgan.library.app.AppManager.java
com.morgan.library.app.BaseActivity.java
com.morgan.library.app.BaseFragmentActivity.java
com.morgan.library.app.BaseListActivity.java
com.morgan.library.app.BaseScreenShotActivity.java
com.morgan.library.app.CommonApplication.java
com.morgan.library.async.CustomAsyncTask.java
com.morgan.library.async.Destroyable.java
com.morgan.library.async.IFeedback.java
com.morgan.library.async.TaskManager.java
com.morgan.library.model.NetResult.java
com.morgan.library.model.SpinnerItem.java
com.morgan.library.model.WeatherType.java
com.morgan.library.model.Weather.java
com.morgan.library.net.ApiClient.java
com.morgan.library.net.ApiManager.java
com.morgan.library.net.ApiUrl.java
com.morgan.library.net.IApiClient.java
com.morgan.library.net.JsonUtils.java
com.morgan.library.net.MockApiClient.java
com.morgan.library.service.LocationManager.java
com.morgan.library.service.WeatherManager.java
com.morgan.library.snippet.CookieShare.java
com.morgan.library.snippet.CustomService.java
com.morgan.library.snippet.ExceptionCatcher.java
com.morgan.library.snippet.ProxyUsage.java
com.morgan.library.snippet.SocketClient.java
com.morgan.library.snippet.SocketServer.java
com.morgan.library.snippet.UDPClient.java
com.morgan.library.snippet.UDPServer.java
com.morgan.library.snippet.XMLAnalyze.java
com.morgan.library.task.GetWeatherTask.java
com.morgan.library.utils.AppUtils.java
com.morgan.library.utils.DateUtils.java
com.morgan.library.utils.DensityUtils.java
com.morgan.library.utils.FileUtils.java
com.morgan.library.utils.GB2Alpha.java
com.morgan.library.utils.HttpClientUtil.java
com.morgan.library.utils.HttpClientUtils.java
com.morgan.library.utils.HttpURLUtil.java
com.morgan.library.utils.ImageUtils.java
com.morgan.library.utils.KeyBoardUtils.java
com.morgan.library.utils.LocationUtils.java
com.morgan.library.utils.Logger.java
com.morgan.library.utils.NetUtils.java
com.morgan.library.utils.PhoneUtils.java
com.morgan.library.utils.SDCardUtils.java
com.morgan.library.utils.StrUtils.java
com.morgan.library.widget.AutoHideMenuWidget.java
com.morgan.library.widget.BadgeView.java
com.morgan.library.widget.CityPickerWidget.java
com.morgan.library.widget.CustomGridView.java
com.morgan.library.widget.CustomListView.java
com.morgan.library.widget.CustomToast.java
com.morgan.library.widget.CustomViewPager.java
com.morgan.library.widget.DatePickerWidget.java
com.morgan.library.widget.DirectionScrollView.java
com.morgan.library.widget.FallBallView.java
com.morgan.library.widget.HeightPickerWidget.java
com.morgan.library.widget.InterceptPressLayout.java
com.morgan.library.widget.ItalicTextView.java
com.morgan.library.widget.PopupMenuWidget.java
com.morgan.library.widget.PullToRefreshListView.java
com.morgan.library.widget.ScreenShotView.java
com.morgan.library.widget.SexPickerWidget.java
com.morgan.library.widget.SlideUpOpenWidget.java
com.morgan.library.widget.SwipeListView.java
com.morgan.library.widget.TimePickerWidget.java
com.morgan.library.widget.TouchZoomImageView.java
com.morgan.library.widget.WaitScreenWidget.java
com.morgan.library.widget.WebViewDialog.java
com.morgan.library.widget.WeightPickerWidget.java
com.morgan.library.widget.calendar.CalendarGridView.java
com.morgan.library.widget.calendar.CalendarScrollView.java
com.morgan.library.widget.calendar.CalendarViewFlipper.java
com.morgan.library.widget.calendar.CalendarWidget.java
com.morgan.library.widget.numberpicker.NumberPicker.java
com.morgan.library.widget.numberpicker.Scroller.java
com.morgan.library.widget.slidemenu.ScrollDetectorFactory.java
com.morgan.library.widget.slidemenu.ScrollDetectors.java
com.morgan.library.widget.slidemenu.SlideMenu.java