Android Open Source - rsmonitor-heartrate Default Date Slider






From Project

Back to project page rsmonitor-heartrate.

License

The source code is released under:

GNU General Public License

If you think the Android project rsmonitor-heartrate 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

/*
 * Copyright (C) 2011 Daniel Berndt - Codeus Ltd  -  DateSlider
 * // w w w .j a v  a  2 s.co  m
 * Default DateSlider which allows for an easy selection of a date 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.android.widgets.DateSlider;

import java.util.Calendar;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout.LayoutParams;

import com.googlecode.android.widgets.DateSlider.TimeView.DayTimeLayoutView;
import com.googlecode.android.widgets.DateSlider.TimeView.TimeLayoutView;
import com.renaultsport.heartrate.R;

public class DefaultDateSlider extends DateSlider {
  
  /**
   * initialise the DateSlider
   * 
   * @param context
   * @param l
   * @param calendar calendar set with the date that should appear at start up
   */
  public DefaultDateSlider(Context context, OnDateSetListener l, Calendar calendar) {
    super(context, l, calendar);
  }
  
  /**
   * Create the month and the dayscroller and feed them with their labelers
   * and place them on the layout.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // this needs to be called before everything else to set up the main layout of the DateSlider  
    super.onCreate(savedInstanceState);    
    
    LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
    
    // create the month scroller and assign its labeler and add it to the layout
    ScrollLayout mMonthScroller = (ScrollLayout) inflater.inflate(R.layout.scroller, null);
    mMonthScroller.setLabeler(monthLabeler, mTime.getTimeInMillis(),90,60);
    mLayout.addView(mMonthScroller, 0,lp);
    mScrollerList.add(mMonthScroller);
    
    // create the month scroller and assign its labeler and add it to the layout
    ScrollLayout mDayScroller = (ScrollLayout) inflater.inflate(R.layout.scroller, null);
    mDayScroller.setLabeler(dayLabeler, mTime.getTimeInMillis(),45,60);
    mLayout.addView(mDayScroller, 1, lp);
    mScrollerList.add(mDayScroller);
    
    // this method _has_ to be called to set the onScrollListeners for all the Scrollers
    // in the mScrollerList.
    setListeners();
  }
  
  // the month labeler  takes care of providing each TimeTextView element in the monthScroller
  // with the right label and information about its time representation
  protected Labeler monthLabeler = new Labeler() {

    /**
     * add "val" months to the month object that contains "time" and returns the new TimeObject
     */
    @Override
    public TimeObject add(long time, int val) {
      Calendar c = Calendar.getInstance(mTimeZone);
      c.setTimeInMillis(time);
      c.add(Calendar.MONTH, val);
      return timeObjectfromCalendar(c);
    }
    
    /**
     * creates an TimeObject from a CalendarInstance
     */
    @Override
    protected TimeObject timeObjectfromCalendar(Calendar c) {
      int year = c.get(Calendar.YEAR);
      int month = c.get(Calendar.MONTH);
      // set calendar to first millisecond of the month
      c.set(year, month, 1, 0, 0, 0);
      c.set(Calendar.MILLISECOND, 0);
      long startTime = c.getTimeInMillis();
      // set calendar to last millisecond of the month
      c.set(year, month, c.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);
      c.set(Calendar.MILLISECOND, 999);
      long endTime = c.getTimeInMillis();
      return new TimeObject(String.format("%tb %tY",c,c), startTime, endTime);
    }
    
    @Override
    /**
     * rather than a standard TextView this is returning a LimearLayout with two TextViews
     */
    public TimeView createView(Context context, boolean isCenterView) {
      return new TimeLayoutView(context, isCenterView,25,8,0.95f);
    }
    
  };
  

  // the day labeler takes care of providing each TimeTextView element in the dayScroller
  // with the right label and information about its time representation
  protected Labeler dayLabeler = new Labeler() {

    /**
     * add "val" days to the month object that contains "time" and returns the new TimeObject
     */
    @Override
    public TimeObject add(long time, int val) {
      Calendar c = Calendar.getInstance(mTimeZone);
      c.setTimeInMillis(time);
      c.add(Calendar.DAY_OF_MONTH, val);
      return timeObjectfromCalendar(c);
    }
    
    /**
     * creates an TimeObject from a CalendarInstance
     */
    @Override
    protected TimeObject timeObjectfromCalendar(Calendar c) {
      int year = c.get(Calendar.YEAR);
      int month = c.get(Calendar.MONTH);
      int day = c.get(Calendar.DAY_OF_MONTH);
      // set calendar to first millisecond of the day
      c.set(year, month, day, 0, 0, 0);
      c.set(Calendar.MILLISECOND, 0);
      long startTime = c.getTimeInMillis();
      // set calendar to last millisecond of the day
      c.set(year, month, day, 23, 59, 59);
      c.set(Calendar.MILLISECOND, 999);
      long endTime = c.getTimeInMillis();
      return new TimeObject(String.format("%td %ta",c,c), startTime, endTime);
    }
    
    @Override
    /**
     * rather than a standard TextView this is returning a LimearLayout with two TextViews
     */
    public TimeView createView(Context context, boolean isCenterView) {
      return new DayTimeLayoutView(context, isCenterView,30,8,0.8f);
    }
    
  };
}




Java Source Code List

com.facebook.android.AsyncFacebookRunner.java
com.facebook.android.BaseDialogListener.java
com.facebook.android.BaseRequestListener.java
com.facebook.android.DialogError.java
com.facebook.android.FQLQuery.java
com.facebook.android.FacebookError.java
com.facebook.android.FacebookFunctions.java
com.facebook.android.Facebook.java
com.facebook.android.FbDialog.java
com.facebook.android.FieldsConnectionsDialog.java
com.facebook.android.FriendsGetProfilePics.java
com.facebook.android.FriendsList.java
com.facebook.android.GraphExplorer.java
com.facebook.android.IntentUriHandler.java
com.facebook.android.LoginButton.java
com.facebook.android.PermissionsDialog.java
com.facebook.android.Places.java
com.facebook.android.SessionEvents.java
com.facebook.android.SessionStore.java
com.facebook.android.TokenRefreshDialog.java
com.facebook.android.UpdateStatusResultDialog.java
com.facebook.android.UploadPhotoResultDialog.java
com.facebook.android.Util.java
com.facebook.android.Utility.java
com.googlecode.android.widgets.DateSlider.AlternativeDateSlider.java
com.googlecode.android.widgets.DateSlider.CustomDateSlider.java
com.googlecode.android.widgets.DateSlider.DateSlider.java
com.googlecode.android.widgets.DateSlider.DateTimeSlider.java
com.googlecode.android.widgets.DateSlider.DefaultDateSlider.java
com.googlecode.android.widgets.DateSlider.MonthYearDateSlider.java
com.googlecode.android.widgets.DateSlider.ScrollLayout.java
com.googlecode.android.widgets.DateSlider.TimeSlider.java
com.googlecode.android.widgets.DateSlider.TimeView.java
com.renaultsport.heartrate.ActivityMain.java
com.renaultsport.heartrate.ActivityRecord.java
com.renaultsport.heartrate.ActivitySplash.java
com.renaultsport.heartrate.ActivityUpload.java
com.renaultsport.heartrate.ActivityVideoReader.java
com.renaultsport.heartrate.ActivityWarning.java
com.renaultsport.heartrate.MainApplication.java
com.renaultsport.heartrate.utils.CaptureCamera.java
com.renaultsport.heartrate.utils.ClientThread.java
com.renaultsport.heartrate.utils.Constants.java
com.renaultsport.heartrate.utils.RunEncoder.java
team.stride.tabs.TabGroupActivity.java