19a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson/*
29a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * Copyright (C) 2011 The Android Open Source Project
39a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson *
49a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * Licensed under the Apache License, Version 2.0 (the "License");
59a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * you may not use this file except in compliance with the License.
69a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * You may obtain a copy of the License at
79a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson *
89a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson *      http://www.apache.org/licenses/LICENSE-2.0
99a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson *
109a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * Unless required by applicable law or agreed to in writing, software
119a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * distributed under the License is distributed on an "AS IS" BASIS,
129a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * See the License for the specific language governing permissions and
149a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * limitations under the License.
159a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson */
169a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
179a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonpackage com.android.calendar;
189a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
199a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport com.android.calendar.CalendarController.ViewType;
209a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
219a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.content.Context;
229a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.os.Handler;
239a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.text.format.DateUtils;
249a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.text.format.Time;
259a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.view.LayoutInflater;
269a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.view.View;
279a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.view.ViewGroup;
28e11975fa44a92c39b0994d6483483ba613761216RoboErikimport android.widget.BaseAdapter;
299a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport android.widget.TextView;
309a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
319a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport java.util.Formatter;
329a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelsonimport java.util.Locale;
339a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
349a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
359a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson/*
369a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * The MenuSpinnerAdapter defines the look of the ActionBar's pull down menu
379a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * for small screen layouts. The pull down menu replaces the tabs uses for big screen layouts
389a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson *
399a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson * The MenuSpinnerAdapter responsible for creating the views used for in the pull down menu.
409a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson */
419a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
42e11975fa44a92c39b0994d6483483ba613761216RoboErikpublic class CalendarViewAdapter extends BaseAdapter {
439a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
449a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private static final String TAG = "MenuSpinnerAdapter";
459a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
465925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final String mButtonNames [];           // Text on buttons
479a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
489a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Used to define the look of the menu button according to the current view:
499a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Day view: show day of the week + full date underneath
509a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Week view: show the month + year
519a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Month view: show the month + year
529a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Agenda view: show day of the week + full date underneath
539a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private int mCurrentMainView;
549a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
559a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private final LayoutInflater mInflater;
569a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
579a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Defines the types of view returned by this spinner
589a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private static final int BUTTON_VIEW_TYPE = 0;
599a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    static final int VIEW_TYPE_NUM = 1;  // Increase this if you add more view types
609a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
619a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public static final int DAY_BUTTON_INDEX = 0;
629a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public static final int WEEK_BUTTON_INDEX = 1;
639a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public static final int MONTH_BUTTON_INDEX = 2;
649a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public static final int AGENDA_BUTTON_INDEX = 3;
659a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
669a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // The current selected event's time, used to calculate the date and day of the week
679a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // for the buttons.
685925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private long mMilliTime;
695925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private String mTimeZone;
705925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private long mTodayJulianDay;
719a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
725925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final Context mContext;
735925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final Formatter mFormatter;
745925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final StringBuilder mStringBuilder;
759a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private Handler mMidnightHandler = null; // Used to run a time update every midnight
765925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final boolean mShowDate;   // Spinner mode indicator (view name or view name with date)
779a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
789a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Updates time specific variables (time-zone, today's Julian day).
795925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    private final Runnable mTimeUpdater = new Runnable() {
809a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        @Override
819a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        public void run() {
82be68675035dc4f53ef5e79d3113e27f8fc553f2aMichael Chan            refresh(mContext);
839a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
849a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    };
859a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
865925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson    public CalendarViewAdapter(Context context, int viewType, boolean showDate) {
879a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        super();
889a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
895d740e1320ba48ba66b72430f9896ab7d481fb54Michael Chan        mMidnightHandler = new Handler();
909a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mCurrentMainView = viewType;
919a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mContext = context;
925925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson        mShowDate = showDate;
939a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
949a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Initialize
959a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mButtonNames = context.getResources().getStringArray(R.array.buttons_list);
969a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
979a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder = new StringBuilder(50);
989a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
999a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1009a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Sets time specific variables and starts a thread for midnight updates
1015925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson        if (showDate) {
1025925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            refresh(context);
1035925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson        }
1049a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1059a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1069a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1079a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Sets the time zone and today's Julian day to be used by the adapter.
1089a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Also, notify listener on the change and resets the midnight update thread.
109be68675035dc4f53ef5e79d3113e27f8fc553f2aMichael Chan    public void refresh(Context context) {
1109a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mTimeZone = Utils.getTimeZone(context, mTimeUpdater);
1119a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        Time time = new Time(mTimeZone);
1129a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        long now = System.currentTimeMillis();
1139a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        time.set(now);
1149a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mTodayJulianDay = Time.getJulianDay(now, time.gmtoff);
115e11975fa44a92c39b0994d6483483ba613761216RoboErik        notifyDataSetChanged();
1169a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        setMidnightHandler();
1179a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1189a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1199a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Sets a thread to run 1 second after midnight and update the current date
1209a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // This is used to display correctly the date of yesterday/today/tomorrow
121be68675035dc4f53ef5e79d3113e27f8fc553f2aMichael Chan    private void setMidnightHandler() {
1225d740e1320ba48ba66b72430f9896ab7d481fb54Michael Chan        mMidnightHandler.removeCallbacks(mTimeUpdater);
1239a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Set the time updater to run at 1 second after midnight
1249a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        long now = System.currentTimeMillis();
1259a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        Time time = new Time(mTimeZone);
1269a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        time.set(now);
1279a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        long runInMillis = (24 * 3600 - time.hour * 3600 - time.minute * 60 -
1289a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                time.second + 1) * 1000;
1299a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mMidnightHandler.postDelayed(mTimeUpdater, runInMillis);
1309a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1319a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1329a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Stops the midnight update thread, called by the activity when it is paused.
133be68675035dc4f53ef5e79d3113e27f8fc553f2aMichael Chan    public void onPause() {
1345d740e1320ba48ba66b72430f9896ab7d481fb54Michael Chan        mMidnightHandler.removeCallbacks(mTimeUpdater);
1359a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1369a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1379a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Returns the amount of buttons in the menu
138e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
1399a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public int getCount() {
1409a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return mButtonNames.length;
1419a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1429a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1439a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
144e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
1459a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public Object getItem(int position) {
1469a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        if (position < mButtonNames.length) {
1479a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            return mButtonNames[position];
1489a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
1499a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return null;
1509a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1519a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
152e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
1539a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public long getItemId(int position) {
1549a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Item ID is its location in the list
1559a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return position;
1569a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1579a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
158e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
1599a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public boolean hasStableIds() {
1609a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return false;
1619a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
1629a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
163e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
1649a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public View getView(int position, View convertView, ViewGroup parent) {
1659a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
1669a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        View v;
1675925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson
1685925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson        if (mShowDate) {
1695925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            // Check if can recycle the view
1705925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            if (convertView == null || ((Integer) convertView.getTag()).intValue()
1715925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    != R.layout.actionbar_pulldown_menu_top_button) {
1725925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v = mInflater.inflate(R.layout.actionbar_pulldown_menu_top_button, parent, false);
1735925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                // Set the tag to make sure you can recycle it when you get it
1745925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                // as a convert view
1755925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v.setTag(new Integer(R.layout.actionbar_pulldown_menu_top_button));
1765925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            } else {
1775925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v = convertView;
1785925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            }
1795925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            TextView weekDay = (TextView) v.findViewById(R.id.top_button_weekday);
1805925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            TextView date = (TextView) v.findViewById(R.id.top_button_date);
1815925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson
1825925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            switch (mCurrentMainView) {
1835925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.DAY:
18494a74c4eae025de9d07d023d15640c1534fde572Isaac Katzenelson                    weekDay.setVisibility(View.VISIBLE);
1855925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    weekDay.setText(buildDayOfWeek());
1865925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildFullDate());
1875925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
1885925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.WEEK:
1895925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    if (Utils.getShowWeekNumber(mContext)) {
1905925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                        weekDay.setVisibility(View.VISIBLE);
1915925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                        weekDay.setText(buildWeekNum());
1925925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    } else {
1935925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                        weekDay.setVisibility(View.GONE);
1945925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    }
1955925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildMonthYearDate());
1965925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
1975925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.MONTH:
19894a74c4eae025de9d07d023d15640c1534fde572Isaac Katzenelson                    weekDay.setVisibility(View.GONE);
1995925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildMonthYearDate());
2005925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2015925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.AGENDA:
2025925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    weekDay.setVisibility(View.VISIBLE);
2035925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    weekDay.setText(buildDayOfWeek());
2045925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildFullDate());
2055925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2065925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                default:
2075925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    v = null;
2085925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2095925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            }
2105925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson        } else {
2115925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            if (convertView == null || ((Integer) convertView.getTag()).intValue()
2125925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    != R.layout.actionbar_pulldown_menu_top_button_no_date) {
2135925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v = mInflater.inflate(
2145925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                        R.layout.actionbar_pulldown_menu_top_button_no_date, parent, false);
2155925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                // Set the tag to make sure you can recycle it when you get it
2165925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                // as a convert view
2175925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v.setTag(new Integer(R.layout.actionbar_pulldown_menu_top_button_no_date));
2185925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            } else {
2195925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                v = convertView;
2205925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            }
2215925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            TextView title = (TextView) v;
2225925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            switch (mCurrentMainView) {
2235925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.DAY:
2245925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    title.setText(mButtonNames [DAY_BUTTON_INDEX]);
2255925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2265925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.WEEK:
2275925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    title.setText(mButtonNames [WEEK_BUTTON_INDEX]);
2285925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2295925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.MONTH:
2305925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    title.setText(mButtonNames [MONTH_BUTTON_INDEX]);
2315925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2325925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                case ViewType.AGENDA:
2335925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    title.setText(mButtonNames [AGENDA_BUTTON_INDEX]);
2345925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2355925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                default:
2365925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    v = null;
2375925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    break;
2385925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson            }
2399a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
2409a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return v;
2419a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
2429a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
243e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
2449a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public int getItemViewType(int position) {
2459a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Only one kind of view is used
2469a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return BUTTON_VIEW_TYPE;
2479a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
2489a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
249e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
2509a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public int getViewTypeCount() {
2519a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return VIEW_TYPE_NUM;
2529a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
2539a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
254e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
2559a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public boolean isEmpty() {
2569a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return (mButtonNames.length == 0);
2579a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
2589a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
259e11975fa44a92c39b0994d6483483ba613761216RoboErik    @Override
2609a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public View getDropDownView(int position, View convertView, ViewGroup parent) {
2619a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        View v = mInflater.inflate(R.layout.actionbar_pulldown_menu_button, parent, false);
2629a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        TextView viewType = (TextView)v.findViewById(R.id.button_view);
2639a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        TextView date = (TextView)v.findViewById(R.id.button_date);
2649a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        switch (position) {
2659a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            case DAY_BUTTON_INDEX:
2669a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                viewType.setText(mButtonNames [DAY_BUTTON_INDEX]);
2675925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                if (mShowDate) {
2685925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildMonthDayDate());
2695925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                }
2709a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                break;
2719a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            case WEEK_BUTTON_INDEX:
2729a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                viewType.setText(mButtonNames [WEEK_BUTTON_INDEX]);
2735925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                if (mShowDate) {
2745925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildWeekDate());
2755925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                }
2769a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                break;
2779a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            case MONTH_BUTTON_INDEX:
2789a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                viewType.setText(mButtonNames [MONTH_BUTTON_INDEX]);
2795925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                if (mShowDate) {
2805925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildMonthDate());
2815925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                }
2829a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                break;
2839a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            case AGENDA_BUTTON_INDEX:
2849a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                viewType.setText(mButtonNames [AGENDA_BUTTON_INDEX]);
2855925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                if (mShowDate) {
2865925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                    date.setText(buildMonthDayDate());
2875925a27fedffc650a6b70662bbd71f7c8bd7eb3eIsaac Katzenelson                }
2889a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                break;
2899a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            default:
2909a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                v = convertView;
2919a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                break;
2929a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
2939a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return v;
2949a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
2959a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
2969a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Updates the current viewType
2979a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Used to match the label on the menu button with the calendar view
2989a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public void setMainView(int viewType) {
2999a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mCurrentMainView = viewType;
300e11975fa44a92c39b0994d6483483ba613761216RoboErik        notifyDataSetChanged();
3019a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
3029a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3039a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Update the date that is displayed on buttons
3049a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Used when the user selects a new day/week/month to watch
3059a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    public void setTime(long time) {
3069a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mMilliTime = time;
307e11975fa44a92c39b0994d6483483ba613761216RoboErik        notifyDataSetChanged();
3089a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
3099a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3109a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Builds a string with the day of the week and the word yesterday/today/tomorrow
3119a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // before it if applicable.
3129a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildDayOfWeek() {
3139a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3149a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        Time t = new Time(mTimeZone);
3159a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        t.set(mMilliTime);
3169a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        long julianDay = Time.getJulianDay(mMilliTime,t.gmtoff);
3179a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        String dayOfWeek = null;
3189a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
3199a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3209a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        if (julianDay == mTodayJulianDay) {
3219a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            dayOfWeek = mContext.getString(R.string.agenda_today,
3229a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                    DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3239a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                            DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
3249a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        } else if (julianDay == mTodayJulianDay - 1) {
3259a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            dayOfWeek = mContext.getString(R.string.agenda_yesterday,
3269a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                    DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3279a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                            DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
3289a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        } else if (julianDay == mTodayJulianDay + 1) {
3299a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            dayOfWeek = mContext.getString(R.string.agenda_tomorrow,
3309a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                    DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3319a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                            DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
3329a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        } else {
3339a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            dayOfWeek = DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3349a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                    DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString();
3359a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
3369a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        return dayOfWeek.toUpperCase();
3379a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
3389a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3399a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Builds strings with different formats:
3409a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Full date: Month,day Year
3419a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Month year
3429a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Month day
3439a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Month
3449a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    // Week:  month day-day or month day - month day
3459a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildFullDate() {
3469a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
3479a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        String date = DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3489a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR, mTimeZone).toString();
349e11975fa44a92c39b0994d6483483ba613761216RoboErik        return date;
3509a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
351e11975fa44a92c39b0994d6483483ba613761216RoboErik
3529a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildMonthYearDate() {
3539a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
354e11975fa44a92c39b0994d6483483ba613761216RoboErik        String date = DateUtils.formatDateRange(
355e11975fa44a92c39b0994d6483483ba613761216RoboErik                mContext,
356e11975fa44a92c39b0994d6483483ba613761216RoboErik                mFormatter,
357e11975fa44a92c39b0994d6483483ba613761216RoboErik                mMilliTime,
358e11975fa44a92c39b0994d6483483ba613761216RoboErik                mMilliTime,
359e11975fa44a92c39b0994d6483483ba613761216RoboErik                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY
360e11975fa44a92c39b0994d6483483ba613761216RoboErik                        | DateUtils.FORMAT_SHOW_YEAR, mTimeZone).toString();
361e11975fa44a92c39b0994d6483483ba613761216RoboErik        return date;
3629a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
363e11975fa44a92c39b0994d6483483ba613761216RoboErik
3649a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildMonthDayDate() {
3659a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
3669a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        String date = DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime,
3679a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR, mTimeZone).toString();
368e11975fa44a92c39b0994d6483483ba613761216RoboErik        return date;
3699a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
370e11975fa44a92c39b0994d6483483ba613761216RoboErik
3719a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildMonthDate() {
3729a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
373e11975fa44a92c39b0994d6483483ba613761216RoboErik        String date = DateUtils.formatDateRange(
374e11975fa44a92c39b0994d6483483ba613761216RoboErik                mContext,
375e11975fa44a92c39b0994d6483483ba613761216RoboErik                mFormatter,
376e11975fa44a92c39b0994d6483483ba613761216RoboErik                mMilliTime,
377e11975fa44a92c39b0994d6483483ba613761216RoboErik                mMilliTime,
378e11975fa44a92c39b0994d6483483ba613761216RoboErik                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR
379e11975fa44a92c39b0994d6483483ba613761216RoboErik                        | DateUtils.FORMAT_NO_MONTH_DAY, mTimeZone).toString();
380e11975fa44a92c39b0994d6483483ba613761216RoboErik        return date;
3819a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
3829a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    private String buildWeekDate() {
3839a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3849a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3859a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // Calculate the start of the week, taking into account the "first day of the week"
3869a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // setting.
3879a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
3889a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        Time t = new Time(mTimeZone);
3899a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        t.set(mMilliTime);
3909a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        int firstDayOfWeek = Utils.getFirstDayOfWeek(mContext);
3919a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        int dayOfWeek = t.weekDay;
3929a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        int diff = dayOfWeek - firstDayOfWeek;
3939a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        if (diff != 0) {
3949a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            if (diff < 0) {
3959a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                diff += 7;
3969a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            }
3979a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            t.monthDay -= diff;
3989a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            t.normalize(true /* ignore isDst */);
3999a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
4009a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
4019a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        long weekStartTime = t.toMillis(true);
4028135093480db642734fb40d9627325bf9e97a8c9RoboErik        // The end of the week is 6 days after the start of the week
4038135093480db642734fb40d9627325bf9e97a8c9RoboErik        long weekEndTime = weekStartTime + DateUtils.WEEK_IN_MILLIS - DateUtils.DAY_IN_MILLIS;
4049a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
4059a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        // If week start and end is in 2 different months, use short months names
4069a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        Time t1 = new Time(mTimeZone);
4079a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        t.set(weekEndTime);
4089a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
4099a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        if (t.month != t1.month) {
4109a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson            flags |= DateUtils.FORMAT_ABBREV_MONTH;
4119a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        }
4129a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
4139a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        mStringBuilder.setLength(0);
4149a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson        String date = DateUtils.formatDateRange(mContext, mFormatter, weekStartTime,
4159a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson                weekEndTime, flags, mTimeZone).toString();
4169a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson         return date;
4179a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson    }
4189a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
41914e82b453a95456277fa5c40189c9b253a8e487fRoboErik    private String buildWeekNum() {
42014e82b453a95456277fa5c40189c9b253a8e487fRoboErik        int week = Utils.getWeekNumberFromTime(mMilliTime, mContext);
42114e82b453a95456277fa5c40189c9b253a8e487fRoboErik        return mContext.getResources().getQuantityString(R.plurals.weekN, week, week);
42214e82b453a95456277fa5c40189c9b253a8e487fRoboErik    }
42314e82b453a95456277fa5c40189c9b253a8e487fRoboErik
4249a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson}
4259a39bddb8e519b710a06d1c77257de6962ae5f72Isaac Katzenelson
426