Home | History | Annotate | Download | only in modifiers
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.holo.cts.modifiers;
     18 
     19 import android.holo.cts.LayoutModifier;
     20 import android.view.View;
     21 import android.widget.CalendarView;
     22 
     23 import java.util.Calendar;
     24 import java.util.GregorianCalendar;
     25 import java.util.TimeZone;
     26 
     27 /**
     28  * {@LayoutModifier} to set a precise date on a {@link CalendarView}.
     29  */
     30 public class CalendarViewModifier implements LayoutModifier {
     31     /**
     32      * Long representation of a date that is 30 years in milliseconds from
     33      * Unix epoch (January 1, 1970 00:00:00).
     34      */
     35     private static final long JANUARY_DATE = 946707779241L;
     36 
     37     private static final long FEBRUARY_DATE = 951033600000L;
     38 
     39     private static final TimeZone TZ = TimeZone.getTimeZone("GMT+00:00");
     40 
     41     private final boolean mJanuary;
     42 
     43     public CalendarViewModifier(boolean january) {
     44         mJanuary = january;
     45     }
     46 
     47     @Override
     48     public void prepare() {
     49         TimeZone.setDefault(TZ);
     50     }
     51 
     52     @Override
     53     public View modifyView(View view) {
     54         ((CalendarView) view).setDate(mJanuary ? JANUARY_DATE : FEBRUARY_DATE);
     55         return view;
     56     }
     57 
     58     public static boolean isMonth(int month) {
     59         Calendar cal = new GregorianCalendar(TZ);
     60         return cal.get(Calendar.MONTH) == month;
     61     }
     62 }
     63