Search in sources :

Example 1 with NumberPickerView

use of cn.carbswang.android.numberpickerview.library.NumberPickerView in project Signal-Android by WhisperSystems.

the class ExpirationDialog method createNumberPickerView.

private static View createNumberPickerView(final Context context, final int currentExpiration) {
    final LayoutInflater inflater = LayoutInflater.from(context);
    final View view = inflater.inflate(R.layout.expiration_dialog, null);
    final NumberPickerView numberPickerView = (NumberPickerView) view.findViewById(R.id.expiration_number_picker);
    final TextView textView = (TextView) view.findViewById(R.id.expiration_details);
    final int[] expirationTimes = context.getResources().getIntArray(R.array.expiration_times);
    final String[] expirationDisplayValues = new String[expirationTimes.length];
    int selectedIndex = expirationTimes.length - 1;
    for (int i = 0; i < expirationTimes.length; i++) {
        expirationDisplayValues[i] = ExpirationUtil.getExpirationDisplayValue(context, expirationTimes[i]);
        if ((currentExpiration >= expirationTimes[i]) && (i == expirationTimes.length - 1 || currentExpiration < expirationTimes[i + 1])) {
            selectedIndex = i;
        }
    }
    numberPickerView.setDisplayedValues(expirationDisplayValues);
    numberPickerView.setMinValue(0);
    numberPickerView.setMaxValue(expirationTimes.length - 1);
    NumberPickerView.OnValueChangeListener listener = new NumberPickerView.OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPickerView picker, int oldVal, int newVal) {
            if (newVal == 0) {
                textView.setText(R.string.ExpirationDialog_your_messages_will_not_expire);
            } else {
                textView.setText(context.getString(R.string.ExpirationDialog_your_messages_will_disappear_s_after_they_have_been_seen, picker.getDisplayedValues()[newVal]));
            }
        }
    };
    numberPickerView.setOnValueChangedListener(listener);
    numberPickerView.setValue(selectedIndex);
    listener.onValueChange(numberPickerView, selectedIndex, selectedIndex);
    return view;
}
Also used : NumberPickerView(cn.carbswang.android.numberpickerview.library.NumberPickerView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) NumberPickerView(cn.carbswang.android.numberpickerview.library.NumberPickerView)

Example 2 with NumberPickerView

use of cn.carbswang.android.numberpickerview.library.NumberPickerView in project Signal-Android by WhisperSystems.

the class ExpirationDialog method show.

public static void show(final Context context, final int currentExpiration, @NonNull final OnClickListener listener) {
    final View view = createNumberPickerView(context, currentExpiration);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.ExpirationDialog_disappearing_messages));
    builder.setView(view);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int selected = ((NumberPickerView) view.findViewById(R.id.expiration_number_picker)).getValue();
            listener.onClick(context.getResources().getIntArray(R.array.expiration_times)[selected]);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) View(android.view.View) NumberPickerView(cn.carbswang.android.numberpickerview.library.NumberPickerView)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 NumberPickerView (cn.carbswang.android.numberpickerview.library.NumberPickerView)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 LayoutInflater (android.view.LayoutInflater)1