예제 #1
0
  public DateTimePicker(Context context) {
    super(context);
    /*
     *獲取系統時間
     */
    mDate = Calendar.getInstance();
    mHour = mDate.get(Calendar.HOUR_OF_DAY);
    mMinute = mDate.get(Calendar.MINUTE);
    /** 加载布局 */
    inflate(context, R.layout.datadialog, this);
    /** 初始化控件 */
    mDateSpinner = (NumberPicker) this.findViewById(R.id.np_date);
    mDateSpinner.setMinValue(0);
    mDateSpinner.setMaxValue(6);
    updateDateControl();
    mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
    mHourSpinner = (NumberPicker) this.findViewById(R.id.np_hour);
    mHourSpinner.setMaxValue(23);
    mHourSpinner.setMinValue(0);
    mHourSpinner.setValue(mHour);
    mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
    mHourSpinner.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);

    mMinuteSpinner = (NumberPicker) this.findViewById(R.id.np_minute);
    mMinuteSpinner.setMaxValue(59);
    mMinuteSpinner.setMinValue(0);
    mMinuteSpinner.setValue(mMinute);
    mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
    mMinuteSpinner.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
    mMinuteSpinner.setWrapSelectorWheel(true);

    FixScroller mScroller =
        new FixScroller(mDateSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mDateSpinner, mScroller);

    FixScroller mScroller1 =
        new FixScroller(mHourSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mHourSpinner, mScroller1);

    FixScroller mScroller2 =
        new FixScroller(mMinuteSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mMinuteSpinner, mScroller2);
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    type = SET_SELECTION;
    prev = getArguments().getInt(Constants.TOTAL_PLAYERS_KEY, 8);
    next = Integer.MAX_VALUE;

    final Dialog dialog = new Dialog(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
    dialog.setTitle("Select Number of Total Players");
    dialog.setContentView(R.layout.dialog_number_picker);
    Button negative = (Button) dialog.findViewById(R.id.game_setup_dialog_negativebutton);
    Button positive = (Button) dialog.findViewById(R.id.game_setup_dialog_positivebutton);

    NumberPicker picker = (NumberPicker) dialog.findViewById(R.id.game_setup_dialog_numberpicker);

    picker.setMaxValue(10);
    picker.setMinValue(5);
    picker.setValue(prev);

    picker.setWrapSelectorWheel(false);
    picker.setOnValueChangedListener(this);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    negative.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            dialog.dismiss();
          }
        });

    positive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (prev > next) type = CLEAR_SELECTION;

            if (next == Integer.MAX_VALUE) next = prev;

            getPlotListener().onEventStart(type, next);

            dialog.dismiss();
          }
        });

    return dialog;
  }
예제 #3
0
  private void init() {

    // Holds all BoardItems
    Settings.allBoardItems = new ArrayList<BoardItem>();
    // Holds all Players
    Settings.allPlayers = new ArrayList<Player>();

    Settings.colors = new ArrayList<String>();
    Settings.colors.add("Farbe wählen");
    Settings.colors.add("Schwarz");
    Settings.colors.add("Grün");
    Settings.colors.add("Blau");
    Settings.colors.add("Rot");
    Settings.colors.add("Violett");
    Settings.colors.add("Grau");
    Settings.colors.add("Gelb");
    Settings.colors.add("Pink");
    Settings.colors.add("Orange");

    // TODO Auto-generated method stub
    playerPicker = (NumberPicker) findViewById(R.id.main_how_many_player_picker);

    playerPicker.setMinValue(MIN_PLAYERS);
    playerPicker.setMaxValue(MAX_PLAYERS);
    playerPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    mainNext = (Button) findViewById(R.id.main_next);

    mainNext.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Settings.numberOfPlayers = playerPicker.getValue();
            String text =
                String.format(
                    getResources().getString(R.string.player_x), Settings.numberOfPlayers);
            System.out.println("numPlayers: " + Settings.numberOfPlayers + "; " + text);
            startActivity(new Intent(getApplicationContext(), PlayerSettings.class));
          }
        });
  }
        @Override
        public void onClick(View view) {
          mInitialOrientation = -1;

          mNumberPicker = new NumberPicker(mContext);
          String[] names = new String[mResolutionsName.size()];
          mResolutionsName.toArray(names);
          if (names.length > 0) {
            mNumberPicker.setDisplayedValues(names);

            mNumberPicker.setMinValue(0);
            mNumberPicker.setMaxValue(names.length - 1);
          } else {
            mNumberPicker.setMinValue(0);
            mNumberPicker.setMaxValue(0);
          }
          mNumberPicker.setWrapSelectorWheel(false);
          mNumberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
          mNumberPicker.setFormatter(
              new NumberPicker.Formatter() {
                @Override
                public String format(int i) {
                  return mResolutionsName.get(i);
                }
              });

          if (CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_VIDEO) {
            // TODO set correct menu selection also for video
            String actualSz = getActualProfileResolution();
            if (mVideoResolutions != null) {
              for (int i = 0; i < mVideoResolutions.size(); i++) {
                if (mVideoResolutions.get(i).equals(actualSz)) {
                  mNumberPicker.setValue(i);
                  break;
                }
              }
            }
          } else {
            Camera.Size actualSz = mCamManager.getParameters().getPictureSize();
            if (mResolutions != null) {
              for (int i = 0; i < mResolutions.size(); i++) {
                if (mResolutions.get(i).equals(actualSz)) {
                  mNumberPicker.setValue(i);
                  break;
                }
              }
            }
          }

          AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
          builder.setView(mNumberPicker);
          builder.setTitle(null);
          builder.setCancelable(false);
          builder.setPositiveButton(
              mContext.getString(R.string.ok),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                  mInitialOrientation = -1;

                  if (CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_PHOTO
                      || CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_PICSPHERE) {
                    // Set picture size
                    Camera.Size size = mResolutions.get(mNumberPicker.getValue());
                    // TODO: only one method
                    mCamManager.setPictureSize("" + size.width + "x" + size.height);

                    if (CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_PHOTO) {
                      SettingsStorage.storeCameraSetting(
                          mContext,
                          mCamManager.getCurrentFacing(),
                          "picture-size",
                          "" + size.width + "x" + size.height);
                    } else {
                      SettingsStorage.storeCameraSetting(
                          mContext,
                          mCamManager.getCurrentFacing(),
                          "picsphere-picture-size",
                          "" + size.width + "x" + size.height);
                    }
                  } else if (CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_VIDEO) {
                    // Set video size
                    String size = mVideoResolutions.get(mNumberPicker.getValue());
                    applyVideoResolution(size);

                    String[] splat = size.split("x");
                    int width = Integer.parseInt(splat[0]);
                    int height = Integer.parseInt(splat[1]);

                    SettingsStorage.storeCameraSetting(
                        mContext,
                        mCamManager.getCurrentFacing(),
                        "video-size",
                        "" + width + "x" + height);
                  }
                }
              });

          mResolutionDialog = builder.create();
          mResolutionDialog.show();
          ((ViewGroup) mNumberPicker.getParent().getParent().getParent())
              .animate()
              .rotation(mOrientation)
              .setDuration(300)
              .start();
        }