Search in sources :

Example 1 with TimePickerDialog

use of com.rey.material.app.TimePickerDialog in project Slide by ccrama.

the class ManageOfflineContent method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_manage_history);
    setupAppBar(R.id.toolbar, R.string.manage_offline_content, true, true);
    if (!NetworkUtil.isConnected(this))
        SettingsTheme.changed = true;
    findViewById(R.id.clear_all).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean wifi = Reddit.cachedData.getBoolean("wifiOnly", false);
            String sync = Reddit.cachedData.getString("toCache", "");
            int hour = (Reddit.cachedData.getInt("hour", 0));
            int minute = (Reddit.cachedData.getInt("minute", 0));
            Reddit.cachedData.edit().clear().apply();
            Reddit.cachedData.edit().putBoolean("wifiOnly", wifi).putString("toCache", sync).putInt("hour", hour).putInt("minute", minute).apply();
            finish();
        }
    });
    if (NetworkUtil.isConnectedNoOverride(this)) {
        findViewById(R.id.sync_now).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new CommentCacheAsync(ManageOfflineContent.this, Reddit.cachedData.getString("toCache", "").split(",")).execute();
            }
        });
    } else {
        findViewById(R.id.sync_now).setVisibility(View.GONE);
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.wifi);
        single.setChecked(Reddit.cachedData.getBoolean("wifiOnly", false));
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Reddit.cachedData.edit().putBoolean("wifiOnly", isChecked).apply();
            }
        });
    }
    updateBackup();
    updateFilters();
    final List<String> commentDepths = ImmutableList.of("2", "4", "6", "8", "10");
    final String[] commentDepthArray = new String[commentDepths.size()];
    findViewById(R.id.comments_depth).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String commentDepth = SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "2");
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
            builder.setTitle(R.string.comments_depth);
            builder.setSingleChoiceItems(commentDepths.toArray(commentDepthArray), commentDepths.indexOf(commentDepth), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SettingValues.prefs.edit().putString(SettingValues.COMMENT_DEPTH, commentDepths.get(which)).apply();
                }
            });
            builder.show();
        }
    });
    final List<String> commentCounts = ImmutableList.of("20", "40", "60", "80", "100");
    final String[] commentCountArray = new String[commentCounts.size()];
    findViewById(R.id.comments_count).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String commentCount = SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "2");
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
            builder.setTitle(R.string.comments_count);
            builder.setSingleChoiceItems(commentCounts.toArray(commentCountArray), commentCounts.indexOf(commentCount), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SettingValues.prefs.edit().putString(SettingValues.COMMENT_COUNT, commentCounts.get(which)).apply();
                }
            });
            builder.show();
        }
    });
    findViewById(R.id.autocache).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(ManageOfflineContent.this));
            final String[] all = new String[sorted.size()];
            boolean[] checked = new boolean[all.length];
            int i = 0;
            List<String> s2 = new ArrayList<>();
            Collections.addAll(s2, Reddit.cachedData.getString("toCache", "").split(","));
            for (String s : sorted) {
                all[i] = s;
                if (s2.contains(s)) {
                    checked[i] = true;
                }
                i++;
            }
            final ArrayList<String> toCheck = new ArrayList<>();
            toCheck.addAll(s2);
            new AlertDialogWrapper.Builder(ManageOfflineContent.this).alwaysCallMultiChoiceCallback().setMultiChoiceItems(all, checked, new DialogInterface.OnMultiChoiceClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    if (!isChecked) {
                        toCheck.remove(all[which]);
                    } else {
                        toCheck.add(all[which]);
                    }
                }
            }).setTitle(R.string.multireddit_selector).setPositiveButton(getString(R.string.btn_add).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Reddit.cachedData.edit().putString("toCache", Reddit.arrayToString(toCheck)).apply();
                    updateBackup();
                }
            }).show();
        }
    });
    updateTime();
    findViewById(R.id.autocache_time_touch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final TimePickerDialog d = new TimePickerDialog(ManageOfflineContent.this);
            d.hour(Reddit.cachedData.getInt("hour", 0));
            d.minute(Reddit.cachedData.getInt("minute", 0));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                d.applyStyle(new ColorPreferences(ManageOfflineContent.this).getFontStyle().getBaseId());
            d.positiveAction("SET");
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = getTheme();
            theme.resolveAttribute(R.attr.activity_background, typedValue, true);
            int color = typedValue.data;
            d.backgroundColor(color);
            d.actionTextColor(getResources().getColor(new ColorPreferences(ManageOfflineContent.this).getFontStyle().getColor()));
            d.positiveActionClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Reddit.cachedData.edit().putInt("hour", d.getHour()).putInt("minute", d.getMinute()).commit();
                    Reddit.autoCache = new AutoCacheScheduler(ManageOfflineContent.this);
                    Reddit.autoCache.start(getApplicationContext());
                    updateTime();
                    d.dismiss();
                }
            });
            theme.resolveAttribute(R.attr.fontColor, typedValue, true);
            int color2 = typedValue.data;
            d.setTitle(getString(R.string.choose_sync_time));
            d.titleColor(color2);
            d.show();
        }
    });
}
Also used : AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TypedValue(android.util.TypedValue) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) ColorPreferences(me.ccrama.redditslide.ColorPreferences) TimePickerDialog(com.rey.material.app.TimePickerDialog) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 2 with TimePickerDialog

use of com.rey.material.app.TimePickerDialog in project caronae-android by caronae.

the class RideSearchFrag method timeEt.

@OnClick(R.id.time_et)
public void timeEt() {
    Dialog.Builder builder = new TimePickerDialog.Builder(R.style.Material_App_Dialog_TimePicker_Light, 24, 0) {

        @Override
        public void onPositiveActionClicked(DialogFragment fragment) {
            TimePickerDialog dialog = (TimePickerDialog) fragment.getDialog();
            time_et.setText(dialog.getFormattedTime(new SimpleDateFormat("HH:mm", Locale.US)));
            super.onPositiveActionClicked(fragment);
        }

        @Override
        public void onNegativeActionClicked(DialogFragment fragment) {
            super.onNegativeActionClicked(fragment);
        }
    };
    builder.positiveAction(getContext().getString(R.string.ok)).negativeAction(getContext().getString(R.string.cancel));
    DialogFragment fragment = DialogFragment.newInstance(builder);
    fragment.show(getFragmentManager(), null);
}
Also used : TimePickerDialog(com.rey.material.app.TimePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.support.v7.app.AlertDialog) DatePickerDialog(com.rey.material.app.DatePickerDialog) SimpleDialog(com.rey.material.app.SimpleDialog) Dialog(com.rey.material.app.Dialog) DialogFragment(com.rey.material.app.DialogFragment) TimePickerDialog(com.rey.material.app.TimePickerDialog) SimpleDateFormat(java.text.SimpleDateFormat) OnClick(butterknife.OnClick)

Example 3 with TimePickerDialog

use of com.rey.material.app.TimePickerDialog in project material by rey5137.

the class DialogsFragment method onClick.

@Override
public void onClick(View v) {
    Dialog.Builder builder = null;
    boolean isLightTheme = ThemeManager.getInstance().getCurrentTheme() == 0;
    switch(v.getId()) {
        case R.id.dialog_bt_title_only:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Discarded", Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Canceled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            builder.title("Discard draft?").positiveAction("DISCARD").negativeAction("CANCEL");
            break;
        case R.id.dialog_bt_msg_only:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Deleted", Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).message("Delete this conversation?").positiveAction("DELETE").negativeAction("CANCEL");
            break;
        case R.id.dialog_bt_title_msg:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Agreed", Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Disagreed", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).message("Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.").title("Use Google's location service?").positiveAction("AGREE").negativeAction("DISAGREE");
            break;
        case R.id.dialog_bt_custom:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                protected void onBuildDone(Dialog dialog) {
                    dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                }

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    EditText et_pass = (EditText) fragment.getDialog().findViewById(R.id.custom_et_password);
                    Toast.makeText(mActivity, "Connected. pass=" + et_pass.getText().toString(), Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            builder.title("Google Wi-Fi").positiveAction("CONNECT").negativeAction("CANCEL").contentView(R.layout.layout_dialog_custom);
            break;
        case R.id.dialog_bt_choice:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "You have selected " + getSelectedValue() + " as phone ringtone.", Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).items(new String[] { "None", "Callisto", "Dione", "Ganymede", "Hangouts Call", "Luna", "Oberon", "Phobos" }, 0).title("Phone Ringtone").positiveAction("OK").negativeAction("CANCEL");
            break;
        case R.id.dialog_bt_multi_choice:
            builder = new SimpleDialog.Builder(isLightTheme ? R.style.SimpleDialogLight : R.style.SimpleDialog) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    CharSequence[] values = getSelectedValues();
                    if (values == null)
                        Toast.makeText(mActivity, "You have selected nothing.", Toast.LENGTH_SHORT).show();
                    else {
                        StringBuffer sb = new StringBuffer();
                        sb.append("You have selected ");
                        for (int i = 0; i < values.length; i++) sb.append(values[i]).append(i == values.length - 1 ? "." : ", ");
                        Toast.makeText(mActivity, sb.toString(), Toast.LENGTH_SHORT).show();
                    }
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).multiChoiceItems(new String[] { "Soup", "Pizza", "Hotdogs", "Hamburguer", "Coffee", "Juice", "Milk", "Water" }, 2, 5).title("Food Order").positiveAction("OK").negativeAction("CANCEL");
            break;
        case R.id.dialog_bt_time:
            builder = new TimePickerDialog.Builder(isLightTheme ? R.style.Material_App_Dialog_TimePicker_Light : R.style.Material_App_Dialog_TimePicker, 24, 00) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    TimePickerDialog dialog = (TimePickerDialog) fragment.getDialog();
                    Toast.makeText(mActivity, "Time is " + dialog.getFormattedTime(SimpleDateFormat.getTimeInstance()), Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            builder.positiveAction("OK").negativeAction("CANCEL");
            break;
        case R.id.dialog_bt_date:
            builder = new DatePickerDialog.Builder(isLightTheme ? R.style.Material_App_Dialog_DatePicker_Light : R.style.Material_App_Dialog_DatePicker) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    DatePickerDialog dialog = (DatePickerDialog) fragment.getDialog();
                    String date = dialog.getFormattedDate(SimpleDateFormat.getDateInstance());
                    Toast.makeText(mActivity, "Date is " + date, Toast.LENGTH_SHORT).show();
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    Toast.makeText(mActivity, "Cancelled", Toast.LENGTH_SHORT).show();
                    super.onNegativeActionClicked(fragment);
                }
            };
            builder.positiveAction("OK").negativeAction("CANCEL");
            break;
    }
    DialogFragment fragment = DialogFragment.newInstance(builder);
    fragment.show(getFragmentManager(), null);
}
Also used : EditText(com.rey.material.widget.EditText) DatePickerDialog(com.rey.material.app.DatePickerDialog) DialogFragment(com.rey.material.app.DialogFragment) TimePickerDialog(com.rey.material.app.TimePickerDialog) SimpleDialog(com.rey.material.app.SimpleDialog) TimePickerDialog(com.rey.material.app.TimePickerDialog) DatePickerDialog(com.rey.material.app.DatePickerDialog) SimpleDialog(com.rey.material.app.SimpleDialog) BottomSheetDialog(com.rey.material.app.BottomSheetDialog) Dialog(com.rey.material.app.Dialog)

Example 4 with TimePickerDialog

use of com.rey.material.app.TimePickerDialog in project caronae-android by caronae.

the class RideOfferFrag method time_et.

@OnClick(R.id.time_et)
public void time_et() {
    Dialog.Builder builder = new TimePickerDialog.Builder(R.style.Material_App_Dialog_TimePicker_Light, 24, 0) {

        @Override
        public void onPositiveActionClicked(DialogFragment fragment) {
            TimePickerDialog dialog = (TimePickerDialog) fragment.getDialog();
            time_et.setText(dialog.getFormattedTime(new SimpleDateFormat("HH:mm", Locale.US)));
            super.onPositiveActionClicked(fragment);
        }

        @Override
        public void onNegativeActionClicked(DialogFragment fragment) {
            super.onNegativeActionClicked(fragment);
        }
    };
    builder.positiveAction(getContext().getString(R.string.ok)).negativeAction(getContext().getString(R.string.cancel));
    DialogFragment fragment = DialogFragment.newInstance(builder);
    fragment.show(getFragmentManager(), null);
}
Also used : TimePickerDialog(com.rey.material.app.TimePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.support.v7.app.AlertDialog) DatePickerDialog(com.rey.material.app.DatePickerDialog) SimpleDialog(com.rey.material.app.SimpleDialog) Dialog(com.rey.material.app.Dialog) DialogFragment(com.rey.material.app.DialogFragment) TimePickerDialog(com.rey.material.app.TimePickerDialog) SimpleDateFormat(java.text.SimpleDateFormat) OnClick(butterknife.OnClick)

Aggregations

TimePickerDialog (com.rey.material.app.TimePickerDialog)4 DatePickerDialog (com.rey.material.app.DatePickerDialog)3 Dialog (com.rey.material.app.Dialog)3 DialogFragment (com.rey.material.app.DialogFragment)3 SimpleDialog (com.rey.material.app.SimpleDialog)3 ProgressDialog (android.app.ProgressDialog)2 AlertDialog (android.support.v7.app.AlertDialog)2 OnClick (butterknife.OnClick)2 SimpleDateFormat (java.text.SimpleDateFormat)2 DialogInterface (android.content.DialogInterface)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 TypedValue (android.util.TypedValue)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 BottomSheetDialog (com.rey.material.app.BottomSheetDialog)1 EditText (com.rey.material.widget.EditText)1 ArrayList (java.util.ArrayList)1