Пример #1
0
 /**
  * when the scrolling procedure causes "steps" elements to fall out of the visible layout, all
  * TimeTextViews swap their contents so that it appears that there happens an endless scrolling
  * with a very limited amount of views
  *
  * @param steps
  */
 protected void moveElements(int steps) {
   if (steps < 0) {
     for (int i = 0; i < getChildCount() + steps; i++) {
       ((TimeView) getChildAt(i)).setVals((TimeView) getChildAt(i - steps));
     }
     for (int i = getChildCount() + steps; i > 0 && i < getChildCount(); i++) {
       DateSlider.TimeObject newTo = labeler.add(((TimeView) getChildAt(i - 1)).getEndTime(), 1);
       ((TimeView) getChildAt(i)).setVals(newTo);
     }
     if (getChildCount() + steps <= 0) {
       for (int i = 0; i < getChildCount(); i++) {
         DateSlider.TimeObject newTo =
             labeler.add(((TimeView) getChildAt(i)).getEndTime(), -steps);
         ((TimeView) getChildAt(i)).setVals(newTo);
       }
     }
   } else if (steps > 0) {
     for (int i = getChildCount() - 1; i >= steps; i--) {
       ((TimeView) getChildAt(i)).setVals((TimeView) getChildAt(i - steps));
     }
     for (int i = steps - 1; i >= 0 && i < getChildCount() - 1; i--) {
       DateSlider.TimeObject newTo = labeler.add(((TimeView) getChildAt(i + 1)).getEndTime(), -1);
       ((TimeView) getChildAt(i)).setVals(newTo);
     }
     if (steps >= getChildCount()) {
       for (int i = 0; i < getChildCount(); i++) {
         DateSlider.TimeObject newTo =
             labeler.add(((TimeView) getChildAt(i)).getEndTime(), -steps);
         ((TimeView) getChildAt(i)).setVals(newTo);
       }
     }
   }
 }
Пример #2
0
  /**
   * This method is called usually after a ScrollLayout is instanciated, it provides the scroller
   * with all necessary information
   *
   * @param labeler the labeler instance which will provide the ScrollLayout with time unit
   *     information
   * @param time the start time as timestamp representation
   * @param objwidth the width of an TimeTextView in dps
   * @param objheight the height of an TimeTextView in dps
   */
  public void setLabeler(DateSlider.Labeler labeler, long time, int objwidth, int objheight) {
    this.labeler = labeler;
    currentTime = time;
    objWidth = (int) (objwidth * getContext().getResources().getDisplayMetrics().density);
    objHeight = (int) (objheight * getContext().getResources().getDisplayMetrics().density);

    // TODO: make it not dependent on the display width but rather on the layout width
    Display display =
        ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int displayWidth = display.getWidth();
    while (displayWidth > childrenWidth - 0 * objWidth && labeler != null) {
      LayoutParams lp = new LayoutParams(objWidth, objHeight);
      if (childrenWidth == 0) {
        TimeView ttv = labeler.createView(getContext(), true);
        ttv.setVals(labeler.getElem(currentTime));
        addView((View) ttv, lp);
        mCenterView = ttv;
        childrenWidth += objWidth;
      }
      TimeView ttv = labeler.createView(getContext(), false);
      ttv.setVals(labeler.add(((TimeView) getChildAt(getChildCount() - 1)).getEndTime(), 1));
      addView((View) ttv, lp);
      ttv = labeler.createView(getContext(), false);
      ttv.setVals(labeler.add(((TimeView) getChildAt(0)).getEndTime(), -1));
      addView((View) ttv, 0, lp);
      childrenWidth += objWidth + objWidth;
    }
  }