Example usage for android.widget NumberPicker setMaxValue

List of usage examples for android.widget NumberPicker setMaxValue

Introduction

In this page you can find the example usage for android.widget NumberPicker setMaxValue.

Prototype

public void setMaxValue(int maxValue) 

Source Link

Document

Sets the max value of the picker.

Usage

From source file:com.untie.daywal.activity.MainActivity.java

private void showDayPicker() {

    Calendar calender = Calendar.getInstance();
    pickedYear = calender.get(Calendar.YEAR);
    pickedMonth = calender.get(Calendar.MONTH) + 1;
    final Dialog dayPickerDialog = new Dialog(this);
    dayPickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dayPickerDialog.setContentView(R.layout.dialog);
    Button okBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_ok);
    Button cancelBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_cancel);
    dialog_year_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_year_title);
    dialog_month_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_month_title);
    final NumberPicker yearPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.yearPicker);
    final NumberPicker monthPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.monthPicker);

    dialog_year_title.setText(String.valueOf(pickedYear) + "");
    dialog_month_title.setText(String.valueOf(pickedMonth) + "");
    yearPicker.setMinValue(pickedYear - 100);
    yearPicker.setMaxValue(pickedYear + 40);
    yearPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(yearPicker, android.R.color.white );
    yearPicker.setWrapSelectorWheel(false);
    yearPicker.setValue(pickedYear);// w  ww .ja v a2 s.  c  o  m
    yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_year_title.setText(String.valueOf(newVal) + "");
        }
    });

    monthPicker.setMinValue(1);
    monthPicker.setMaxValue(12);
    monthPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(monthPicker, android.R.color.white);
    //monthPicker.setWrapSelectorWheel(false);
    monthPicker.setValue(pickedMonth);
    monthPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_month_title.setText(String.valueOf(newVal) + "");
        }
    });

    okBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //TODO :  ?? yearPicker.getValue() monthPicker.getValue()

            //Toast.makeText(MainActivity.this, String.valueOf(yearPicker.getValue())+"/"+monthPicker.getValue(), Toast.LENGTH_SHORT).show();

            Intent intent = new Intent(MainActivity.this, MainActivity.class);
            intent.putExtra("year", yearPicker.getValue());
            intent.putExtra("month", monthPicker.getValue());
            intent.putExtra("order", 1);
            dayPickerDialog.dismiss();
            startActivity(intent);
            overridePendingTransition(0, 0);

        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dayPickerDialog.dismiss();
        }
    });
    dayPickerDialog.show();

}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Show the user the octave changer prompt.
 *//* w w  w. j  a v a  2 s . c o  m*/
private void octavePrompt() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();

    final View tempo_picker = inflater.inflate(R.layout.octave_picker, null);
    final NumberPicker np = (NumberPicker) tempo_picker.findViewById(R.id.octavePickerField);
    np.setMaxValue(8);
    np.setMinValue(0);
    np.setValue(noteSUB);

    builder.setTitle("Set Measure Octave").setView(tempo_picker)
            .setPositiveButton(R.string.set, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    int sub = np.getValue();
                    noteSUB = sub;

                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    AlertDialog dialog = builder.create();

    dialog.show();
}

From source file:it.durip_app.ExperimentMasterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    s = new String[3];

    setContentView(R.layout.activity_experiment_master);
    setupActionBar();//w  w  w  . j  a  va  2 s  .com
    boxAdapter = new IpListAdapter(this, managedIps);

    ListView lvMain = (ListView) findViewById(R.id.IpListToManage);
    lvMain.setAdapter(boxAdapter);

    //      final View controlsView = findViewById(R.id.fullscreen_content_controls);
    //      final View contentView = findViewById(R.id.fullscreen_content);

    NumberPicker ip1 = (NumberPicker) findViewById(R.id.ip1);
    NumberPicker ip2 = (NumberPicker) findViewById(R.id.ip2);
    NumberPicker ip3 = (NumberPicker) findViewById(R.id.ip3);
    NumberPicker ip4 = (NumberPicker) findViewById(R.id.ip4);
    ip1.setMinValue(1);
    ip1.setMaxValue(254);
    ip1.setWrapSelectorWheel(true);
    ip2.setMinValue(0);
    ip2.setMaxValue(254);
    ip2.setWrapSelectorWheel(true);
    ip3.setMinValue(0);
    ip3.setMaxValue(254);
    ip3.setWrapSelectorWheel(true);
    ip4.setMinValue(0);
    ip4.setMaxValue(254);
    ip4.setWrapSelectorWheel(true);

    BufferedReader br;
    String newIp;
    boolean addme;
    try {
        br = new BufferedReader(new FileReader(fileIPExperiment));
        while ((newIp = br.readLine()) != null) {
            addme = true;
            // if already in the list do not add another one
            if (managedIps.contains(new ManagedIp(newIp, newIp, true)))
                addme = false;

            Log.d("managermanager", "writing");
            if (addme) {
                managedIps.add(new ManagedIp(newIp, newIp, true));
            }
        }
        br.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    /*
    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, contentView,
    HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider
    .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
       // Cached values.
       int mControlsHeight;
       int mShortAnimTime;
            
       @Override
       @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
       public void onVisibilityChange(boolean visible) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
             // If the ViewPropertyAnimator API is available
             // (Honeycomb MR2 and later), use it to animate the
             // in-layout UI controls at the bottom of the
             // screen.
             if (mControlsHeight == 0) {
                mControlsHeight = controlsView.getHeight();
             }
             if (mShortAnimTime == 0) {
                mShortAnimTime = getResources().getInteger(
                      android.R.integer.config_shortAnimTime);
             }
             controlsView
                   .animate()
                   .translationY(visible ? 0 : mControlsHeight)
                   .setDuration(mShortAnimTime);
          } else {
             // If the ViewPropertyAnimator APIs aren't
             // available, simply show or hide the in-layout UI
             // controls.
             controlsView.setVisibility(visible ? View.VISIBLE
                   : View.GONE);
          }
            
          if (visible && AUTO_HIDE) {
             // Schedule a hide().
             delayedHide(AUTO_HIDE_DELAY_MILLIS);
          }
       }
    });
            
    // Set up the user interaction to manually show or hide the system UI.
    contentView.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
    if (TOGGLE_ON_CLICK) {
       mSystemUiHider.toggle();
    } else {
       mSystemUiHider.show();
    }
       }
    });
            
    // Upon interacting with UI controls, delay any scheduled hide()
    // operations to prevent the jarring behavior of controls going away
    // while interacting with the UI.
    findViewById(R.id.startexperiment).setOnTouchListener(
    mDelayHideTouchListener);*/
}

From source file:com.sean.takeastand.ui.MainActivity.java

private void showPauseSettingsDialog() {
    LayoutInflater inflater = getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View dialogView = inflater.inflate(R.layout.dialog_pause, null);
    TextView title = new TextView(this);
    title.setPadding(50, 50, 50, 50);/*from  w  w w. ja va  2  s.  c  o  m*/
    title.setTextSize(22);
    title.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
    title.setText(getResources().getString(R.string.select_pause_type));
    builder.setCustomTitle(title);
    String[] valueSet = new String[pauseTimes.length];
    for (int i = 0; i < pauseTimes.length; i++) {
        valueSet[i] = Integer.toString(pauseTimes[i]);
    }
    builder.setView(dialogView);
    final NumberPicker npPause = (NumberPicker) dialogView.findViewById(R.id.pauseNumberPicker);
    npPause.setDisplayedValues(valueSet);
    npPause.setMinValue(0);
    npPause.setMaxValue(valueSet.length - 1);
    npPause.setWrapSelectorWheel(false);
    int initialValue = Utils.getDefaultPauseAmount(this);
    for (int i = 0; i < pauseTimes.length; i++) {
        if (initialValue == pauseTimes[i]) {
            initialValue = i;
        }
    }
    npPause.setValue(initialValue);
    builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //getValue returns the index number, so need to do some math to correct correct
            //actual value
            setDefaultPauseAmount(pauseTimes[npPause.getValue()]);
            int currentStatus = Utils.getImageStatus(MainActivity.this);
            if (currentStatus == Constants.NON_SCHEDULE_ALARM_RUNNING
                    || currentStatus == Constants.NON_SCHEDULE_STOOD_UP
                    || currentStatus == Constants.NON_SCHEDULE_TIME_TO_STAND) {
                pauseUnscheduled();
            } else {
                pauseSchedule();
                sendAnalyticsEvent("Paused");
            }
            dialogInterface.dismiss();
        }
    });
    builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            mPausePlay.setIcon(getResources().getDrawable(R.drawable.ic_action_pause));
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

/**
 * Screen to select the number of questions in the test
 *//*w  w w  .j a v a2  s  .  c  o  m*/
private void selectNumQuestions() {
    screenStep = ScreenStep.NUM_QUESTIONS;

    setLayout(R.layout.tests_num_questions);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.widget.NumberPicker numberPicker = (android.widget.NumberPicker) findViewById(
                R.id.testNumQuestionsNumberPicker);

        numberPicker.setMaxValue(test.getMax());
        numberPicker.setMinValue(test.getMin());
        numberPicker.setValue(test.getDef());
        numberPicker.setVisibility(View.VISIBLE);
    } else {
        es.ugr.swad.swadroid.gui.widget.NumberPicker numberPickerOld = (es.ugr.swad.swadroid.gui.widget.NumberPicker) findViewById(
                R.id.testNumQuestionsNumberPickerOld);

        numberPickerOld.setRange(test.getMin(), test.getMax());
        numberPickerOld.setCurrent(test.getDef());
        numberPickerOld.setVisibility(View.VISIBLE);
    }
}

From source file:com.fitme.MainActivity.java

public void onExerciseCreationRequested(final String trainName, final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_exercise_dialog);
    View view = getLayoutInflater().inflate(R.layout.dialog_add_exercise, null);
    builder.setView(view);/*  w  w w  .j  a v a  2  s  .c  o  m*/
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialogEx = builder.create();
    dialogEx.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = dialogEx.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
                    Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
                    NumberPicker numpickRepeats = (NumberPicker) dialogEx
                            .findViewById(R.id.numberpicker_repeats_ex);
                    //Since we decide to have all spinners pre-populated no need to check data
                    Exercise e = new Exercise();
                    e.setName(spinExName.getSelectedItem().toString());
                    e.setMuscleGroup(spinMuscleGroup.getSelectedItem().toString());
                    e.setRepeats(numpickRepeats.getValue());
                    //Identifying program and training
                    long programId = MainActivity.this.getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    long trId = td.getTrainingByName(programId, trainName).getId();
                    e.setTrainId(trId);

                    //Insert new entry to db
                    ExerciseDAO ed = new ExerciseDAO(MainActivity.this);
                    long exId = ed.createExercise(e).getId();
                    e.setId(exId);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_exercise_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addExercise(e, trainName);
                    dialogEx.dismiss();
                }
            });

        }
    });
    dialogEx.show();
    // Populate dialog fields
    NumberPicker np = (NumberPicker) dialogEx.findViewById(R.id.numberpicker_repeats_ex);
    final Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
    final Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
    np.setMaxValue(Exercise.MAX_REPEATS);
    np.setMinValue(Exercise.MIN_REPEATS);

    //Filling muscle groups spinner
    String[] muscleGroups = getResources().getStringArray(R.array.muscle_groups);

    ArrayAdapter<String> mgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            muscleGroups);
    spinMuscleGroup.setAdapter(mgAdapter);

    spinMuscleGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String arrayName = ("exercises_" + spinMuscleGroup.getSelectedItem().toString()).toLowerCase();
            int id = getResources().getIdentifier(arrayName, "array", MainActivity.this.getPackageName());
            String[] exercises = getResources().getStringArray(id);
            ArrayAdapter<String> exAdapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_spinner_item, exercises);
            spinExName.setAdapter(exAdapter);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    spinMuscleGroup.setSelection(1);

}

From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java

private void drawQuickSilenceWidget() {
    LinearLayout quicksilenceBox = (LinearLayout) rootView
            .findViewById(R.id.advanced_settings_quicksilence_box);
    quicksilenceBox.setOnClickListener(new View.OnClickListener() {
        @Override//w  w w .  j  a  v  a 2 s.c  om
        public void onClick(View v) {
            LayoutInflater inflater = LayoutInflater.from(v.getContext());
            View dialogView = inflater.inflate(R.layout.dialog_quicksilent, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.Dialog));
            builder.setTitle(R.string.notification_quicksilence_title);
            builder.setView(dialogView);

            final NumberPicker hourP = (NumberPicker) dialogView.findViewById(R.id.hourPicker);
            final NumberPicker minP = (NumberPicker) dialogView.findViewById(R.id.minutePicker);

            String[] hours = new String[25];
            String[] minutes = new String[59];

            for (int i = 0; i < hours.length; i++) {
                hours[i] = Integer.toString(i);
            }

            int i = 0;
            while (i < minutes.length) {
                minutes[i] = Integer.toString(++i);
            }

            hourP.setMinValue(1);
            hourP.setMaxValue(hours.length - 1);
            hourP.setWrapSelectorWheel(false);
            hourP.setDisplayedValues(hours);
            hourP.setValue(prefs.getQuickSilenceHours() + 1);

            minP.setMinValue(1);
            minP.setMaxValue(minutes.length - 1);
            minP.setWrapSelectorWheel(false);
            minP.setDisplayedValues(minutes);
            minP.setValue(prefs.getQuicksilenceMinutes());

            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    prefs.setQuickSilenceHours(hourP.getValue() - 1);
                    prefs.setQuicksilenceMinutes(minP.getValue());
                    drawQuickSilenceWidget();
                }
            });

            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do nothing
                }
            });

            AlertDialog dialog = builder.show();
        }
    });

    //the quick silence button
    TextView quickTV = (TextView) rootView.findViewById(R.id.quickSilenceDescription);
    String quicksilenceText = getResources()
            .getString(R.string.advanced_settings_section_interval_quicksilence_duration);
    String hrs = "";
    if (prefs.getQuickSilenceHours() > 0) {
        hrs = String.valueOf(prefs.getQuickSilenceHours()) + " " + getString(R.string.hours_lower) + " ";
    }
    quickTV.setText(String.format(quicksilenceText, hrs, prefs.getQuicksilenceMinutes()));
}

From source file:butter.droid.base.fragments.dialog.NumberPickerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    if (getArguments() == null || !getArguments().containsKey(MAX_VALUE)
            || !getArguments().containsKey(MIN_VALUE) || !getArguments().containsKey(TITLE)
            || mOnResultListener == null) {
        return builder.create();
    }//from  w ww.j av a 2  s . co m

    final NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setLayoutParams(new NumberPicker.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    numberPicker.setWrapSelectorWheel(false);

    final int minValue = getArguments().getInt(MIN_VALUE);
    final int maxValue = getArguments().getInt(MAX_VALUE);
    final int currentValue = getArguments().getInt(DEFAULT_VALUE,
            (int) Math.floor((numberPicker.getMaxValue() - numberPicker.getMinValue()) / 2));

    List<String> displayValues = new ArrayList<>();
    for (int i = minValue; i < maxValue + 1; i++) {
        displayValues.add(Integer.toString(i));
    }
    numberPicker.setDisplayedValues(displayValues.toArray(new String[displayValues.size()]));

    if (minValue < 0) {
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(maxValue + Math.abs(minValue));
        numberPicker.setValue(currentValue + Math.abs(minValue));
    } else {
        numberPicker.setMinValue(minValue);
        numberPicker.setMaxValue(maxValue);
        numberPicker.setValue(currentValue);
    }

    if (getArguments().containsKey(FOCUSABLE) && !getArguments().getBoolean(FOCUSABLE))
        numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    builder.setView(numberPicker).setTitle(getArguments().getString(TITLE))
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0));
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    return builder.create();
}

From source file:hu.fnf.devel.atlas.Atlas.java

public void onMonthClick(View v) {
    AlertDialog.Builder picker = new AlertDialog.Builder(this);
    View pick = getLayoutInflater().inflate(R.layout.number_picker, null);
    Calendar now = new GregorianCalendar(TimeZone.getDefault());
    String[] date = AtlasData.config.getString(AtlasData.CONFIG_DATE, "1900.01").split("\\.");

    NumberPicker y = (NumberPicker) pick.findViewById(R.id.yearpicker);
    y.setMaxValue(now.get(Calendar.YEAR));
    y.setMinValue(1900);//www  . jav  a 2 s .  c o m
    y.setValue(Integer.valueOf(date[0]));

    NumberPicker m = (NumberPicker) pick.findViewById(R.id.monthpicker);
    m.setMaxValue(12);
    m.setMinValue(1);
    m.setValue(Integer.valueOf(date[1]));

    picker.setView(pick);
    dialog = picker.create();
    dialog.show();
}

From source file:ir.irani.telecam.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    if (type != 3) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    }/*  w  ww  . ja v a  2 s .c om*/
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}