Example #1
0
  private Dialog createDialog() {

    Dialog dialog = new Dialog(this, R.style.NobackDialog);
    View view = LayoutInflater.from(this).inflate(R.layout.dialog_time_picker, null);
    Button btn_submit = (Button) view.findViewById(R.id.btn_dialog_submit);
    final WheelView hours = (WheelView) view.findViewById(R.id.wheel_hour);
    hours.setViewAdapter(new NumericWheelAdapter(this, 0, 23));
    hours.setCyclic(true);
    final WheelView mins = (WheelView) view.findViewById(R.id.wheel_mins);
    mins.setViewAdapter(new NumericWheelAdapter(this, 0, 59, "%02d"));
    mins.setCyclic(true);
    int curHours = 0;
    int curMinutes = 0;
    Map<String, uSDKDeviceAttribute> attrs = mDevice.getAttributeMap();
    switch (mCurrentType) {
      case 1:
        if (!TextUtils.isEmpty(getTime(attrs, 1))) {
          curHours = Integer.parseInt(getTime(attrs, 1).split(":")[0]);
          curMinutes = Integer.parseInt(getTime(attrs, 1).split(":")[1]);
        }
        break;
      case 2:
        if (!TextUtils.isEmpty(getTime(attrs, 2))) {
          curHours = Integer.parseInt(getTime(attrs, 2).split(":")[0]);
          curMinutes = Integer.parseInt(getTime(attrs, 2).split(":")[1]);
        }
        break;
    }
    hours.setCurrentItem(curHours);
    mins.setCurrentItem(curMinutes);
    OnWheelClickedListener click =
        new OnWheelClickedListener() {
          public void onItemClicked(WheelView wheel, int itemIndex) {
            wheel.setCurrentItem(itemIndex, true);
          }
        };
    hours.addClickingListener(click);
    mins.addClickingListener(click);
    btn_submit.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            mSetTime = formatTime(hours.getCurrentItem(), mins.getCurrentItem());
            mDialog.dismiss();
            switch (mCurrentType) {
              case 1:
                mSetTime0 = mSetTime;
                mOvenTime.setText(mSetTime0);
                sendCommand(mDevice, "20v00f", mSetTime0);
                break;
            }
          }
        });
    dialog.setContentView(view);
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
  }
Example #2
0
  /**
   * Creates an wheelView (Dialog) so the user can set the date and time. Requires wheel_src library
   * project.
   *
   * @param Context to show in
   * @param Time to show in milliseconds
   * @return Dialog
   */
  public Dialog showDateDialog(Context in, long timeinms) {
    Dialog timeDialog = new Dialog(in);
    timeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    timeDialog.setContentView(R.layout.time2_layout);
    LayoutParams params = timeDialog.getWindow().getAttributes();
    params.width = LayoutParams.FILL_PARENT;
    timeDialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
    boolean tf = false;
    tf = sp.getBoolean("prefs_time_24", true);

    int nhours = 23;
    int startH = 0;
    if (tf) {
      nhours = 23;
      startH = 0;
    } else {
      startH = 1;
      nhours = 12;
    }

    final WheelView hours = (WheelView) timeDialog.findViewById(R.id.hour);
    NumericWheelAdapter hourAdapter = new NumericWheelAdapter(TimeClock.this, startH, nhours);
    hourAdapter.setItemResource(R.layout.wheel_text_item);
    hourAdapter.setItemTextResource(R.id.text);
    hours.setViewAdapter(hourAdapter);

    final WheelView mins = (WheelView) timeDialog.findViewById(R.id.mins);
    NumericWheelAdapter minAdapter = new NumericWheelAdapter(TimeClock.this, 0, 59, "%02d");
    minAdapter.setItemResource(R.layout.wheel_text_item);
    minAdapter.setItemTextResource(R.id.text);
    mins.setViewAdapter(minAdapter);
    mins.setCyclic(true);

    final WheelView ampm = (WheelView) timeDialog.findViewById(R.id.ampm);
    ArrayWheelAdapter<String> ampmAdapter =
        new ArrayWheelAdapter<String>(TimeClock.this, new String[] {"AM", "PM"});
    ampmAdapter.setItemResource(R.layout.wheel_text_item);
    ampmAdapter.setItemTextResource(R.id.text);
    ampm.setViewAdapter(ampmAdapter);

    // set current time
    Calendar calendar = Calendar.getInstance(Locale.US);
    calendar.setTimeInMillis(timeinms);

    mins.setCurrentItem(calendar.get(Calendar.MINUTE));

    ampm.setCurrentItem(calendar.get(Calendar.AM_PM));
    if (tf) {
      hours.setCurrentItem(calendar.get(Calendar.HOUR_OF_DAY));
      ampm.setVisibility(View.GONE);
    } else {
      hours.setCurrentItem(calendar.get(Calendar.HOUR) - 1);
      ampm.setVisibility(View.VISIBLE);
    }

    final WheelView day = (WheelView) timeDialog.findViewById(R.id.day);
    day.setViewAdapter(new DayArrayAdapter(TimeClock.this, calendar));
    day.setCurrentItem(20);
    return timeDialog;
  }
  private void showSetLeaveTimeDialog() {
    final AlertDialog updateDialogDlg = new AlertDialog.Builder(this).create();
    updateDialogDlg.show();
    Window win = updateDialogDlg.getWindow();
    win.setContentView(R.layout.dialog_setleavetime);
    WheelView wheelView = (WheelView) win.findViewById(R.id.wv_leavetime);
    TextView titleTextView = (TextView) win.findViewById(R.id.update_title);
    titleTextView.setText(R.string.setleavetimetitle);
    AbstractWheelTextAdapter adapter =
        new AbstractWheelTextAdapter(getApplicationContext()) {

          @Override
          public int getItemsCount() {
            // TODO Auto-generated method stub
            return leaveTimeStrings.size();
          }

          @Override
          protected CharSequence getItemText(int index) {
            // TODO Auto-generated method stub
            return leaveTimeStrings.get(index);
          }
        };
    OnWheelChangedListener wheelListener =
        new OnWheelChangedListener() {
          public void onChanged(WheelView wheel, int oldValue, int newValue) {
            String setTimeString = leaveTimeStrings.get(wheel.getCurrentItem());
            appLockApplication.setAllowedLeaveTime(setTimeString);
          }
        };
    adapter.setItemResource(R.layout.item_wheel_leavetime);
    adapter.setItemTextResource(R.id.tv_text);
    wheelView.setViewAdapter(adapter);
    wheelView.setCyclic(true);
    wheelView.addChangingListener(wheelListener);

    ImageView closeImageView = (ImageView) win.findViewById(R.id.updateclose);
    closeImageView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            updateDialogDlg.dismiss();
            Message msg = new Message();
            msg.what = SETLEAVEDIALOG_DISS;
            mHandler.sendMessage(msg);
          }
        });

    updateDialogDlg.setOnDismissListener(
        new OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            Message msg = new Message();
            msg.what = SETLEAVEDIALOG_DISS;
            mHandler.sendMessage(msg);
          }
        });
  }