Android Open Source - FlangeAssist Ata Time Picker






From Project

Back to project page FlangeAssist.

License

The source code is released under:

MIT License

If you think the Android project FlangeAssist 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.atasoft.helpers;
//from  w  ww .  j a va 2s. c o  m
import android.util.*;
import android.widget.*;

public class AtaTimePicker {
  
  private String[] HOURS;
  private String[] MINUTES;
  NumberPicker hourPick;
  NumberPicker minPick;
  LinearLayout pickLay;
  
  public AtaTimePicker(NumberPicker hourPicker, NumberPicker minPicker){
    this.hourPick = hourPicker;
    this.minPick = minPicker;
    
    this.HOURS = makeStringsFromRange(0, 23);
    this.MINUTES = makeStringsFromRange(0,59);
    
    populatePicker(hourPick, HOURS);
    populatePicker(minPick, MINUTES);
    
    //Prevents outOfBounds bug on orientation change.
    //hourPick.setSaveFromParentEnabled(false);
    //minPick.setSaveFromParentEnabled(false);
    //hourPick.setSaveEnabled(true);
    //minPick.setSaveEnabled(true);
    
    /*   Just incase I use something like this again. It bugged on orientation change though.
    this.pickLay = new LinearLayout(ctx);
    pickLay.setGravity(Gravity.CENTER_VERTICAL);
    LinearLayout.LayoutParams layPar = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
                              LinearLayout.LayoutParams.WRAP_CONTENT);
    pickLay.setLayoutParams(layPar);
    pickLay.setOrientation(LinearLayout.HORIZONTAL);
    
    //Label for time
    TextView label = new TextView(ctx);
    label.setText(labelName);
    label.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    pickLay.addView(label);
    
    //Hour number picker
    this.hourPick = makePicker(HOURS, ctx);
    pickLay.addView(hourPick);
    
    //Seperates hours from minutes
    TextView seperator = new TextView(ctx);
    seperator.setText(":");
    seperator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
    seperator.setPadding(8, 36, 8, 8);
    pickLay.addView(seperator);
    
    //Minute number picker
    this.minPick = makePicker(MINUTES, ctx);
    pickLay.addView(minPick);
    parent.addView(pickLay);
    hourPick.setValue(defTime[0]);
    minPick.setValue(defTime[1]);
    */
  }
  
  public void setPickerValue(int[] timeSet){
    timeSet = validateTime(timeSet);
    hourPick.setValue(timeSet[0]);
    minPick.setValue(timeSet[1]);
    //Log.w("AtaTimePicker", String.format("Set value to %2d:%2d", timeSet[0], timeSet[1]));
    return;
  }
  
  public int[] getVals() throws NullPointerException{
    int[] retInt = {0,0};
    try{
      retInt[0] = hourPick.getValue();
      retInt[1] = minPick.getValue();
    } catch(NullPointerException e){
      Log.e("AtaTimePicker", "NullPointerException when trying getValse()");
    }
    return retInt;
  }
  
  private int[] validateTime(int[] timeArr){
    timeArr[0] = (timeArr[0] >= 0 && timeArr[0] <= 23) ? timeArr[0] : 0;
    timeArr[1] = (timeArr[1] >= 0 && timeArr[1] <= 59) ? timeArr[1] : 0;
    return timeArr;
  }

  private String[] makeStringsFromRange(int floor, int ceiling){
    String[] retString = new String[ceiling - floor + 1];
    for(int i=floor; i <= ceiling; i++){
      retString[i] = Integer.toString(i);
      if(i < 10) retString[i] = "0" + retString[i];
    }
    return retString;
  }

  private void populatePicker(NumberPicker picker, String[] values){
    picker.setDisplayedValues(values);
    picker.setMaxValue(values.length-1);
    picker.setMinValue(0);
    return;
  }
}




Java Source Code List

com.atasoft.adapters.ExListAd.java
com.atasoft.adapters.ExpandableGroup.java
com.atasoft.adapters.TabsPagerAdapter.java
com.atasoft.flangeassist.FragFramer.java
com.atasoft.flangeassist.MainActivity.java
com.atasoft.flangeassist.PreferenceMenu.java
com.atasoft.flangeassist.ToolsActivity.java
com.atasoft.flangeassist.fragments.AboutFragment.java
com.atasoft.flangeassist.fragments.CashCounter.java
com.atasoft.flangeassist.fragments.FlangeFragment.java
com.atasoft.flangeassist.fragments.HallFragment.java
com.atasoft.flangeassist.fragments.NozzleCalc.java
com.atasoft.flangeassist.fragments.PaychequeFragment.java
com.atasoft.flangeassist.fragments.RigTrig.java
com.atasoft.flangeassist.fragments.ShapeCalcFrag.java
com.atasoft.flangeassist.fragments.TorqueFragment.java
com.atasoft.flangeassist.fragments.UnitConFragment.java
com.atasoft.flangeassist.fragments.WageCPIEstimate.java
com.atasoft.flangeassist.fragments.WeldingFrag.java
com.atasoft.helpers.AtaMathUtils.java
com.atasoft.helpers.AtaTimePicker.java
com.atasoft.helpers.ConvDataHold.java
com.atasoft.helpers.JsonPuller.java
com.atasoft.helpers.ShapeCalcHold.java
com.atasoft.helpers.TaxManager.java