Search in sources :

Example 1 with EditText

use of carbon.widget.EditText in project Carbon by ZieIony.

the class SelectDialogActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    EditText titleText = findViewById(R.id.titleText);
    DropDown dropDown = findViewById(R.id.dropDown);
    dropDown.setItems(new String[] { "Single select", "Multi select" });
    StringFruitGenerator generator = new StringFruitGenerator();
    List<String> items = Stream.generate(generator::next).limit(5).toList();
    selectedItem = items.get(0);
    selectedItems = new ArrayList<>();
    selectedItems.add(selectedItem);
    findViewById(R.id.button).setOnClickListener(view -> {
        switch(dropDown.getSelectedIndex()) {
            case 0:
                {
                    SingleSelectDialog<String> dialog = new SingleSelectDialog<>(this);
                    if (titleText.length() > 0)
                        dialog.setTitle(titleText.getText());
                    dialog.setItems(items);
                    dialog.setOnDismissListener(dialogInterface -> selectedItem = dialog.getSelectedItem());
                    dialog.setSelectedItem(selectedItem);
                    dialog.show();
                }
                break;
            case 1:
                {
                    MultiSelectDialog<String> dialog = new MultiSelectDialog<>(this);
                    if (titleText.length() > 0)
                        dialog.setTitle(titleText.getText());
                    dialog.setItems(items);
                    dialog.addButton("ok", null);
                    dialog.setOnDismissListener(dialogInterface -> selectedItems = dialog.getSelectedItems());
                    dialog.setSelectedItems(selectedItems);
                    dialog.show();
                }
                break;
        }
    });
}
Also used : EditText(carbon.widget.EditText) ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) MultiSelectDialog(carbon.dialog.MultiSelectDialog) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) EditText(carbon.widget.EditText) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable) SingleSelectDialog(carbon.dialog.SingleSelectDialog) R(tk.zielony.carbonsamples.R) DropDown(carbon.widget.DropDown) StringFruitGenerator(tk.zielony.randomdata.food.StringFruitGenerator) StringFruitGenerator(tk.zielony.randomdata.food.StringFruitGenerator) SingleSelectDialog(carbon.dialog.SingleSelectDialog) MultiSelectDialog(carbon.dialog.MultiSelectDialog) DropDown(carbon.widget.DropDown)

Example 2 with EditText

use of carbon.widget.EditText in project Carbon by ZieIony.

the class FlowLayoutActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    DrawableAvatarGenerator avatarGenerator = new DrawableAvatarGenerator(this);
    StringFirstNameGenerator nameGenerator = new StringFirstNameGenerator(Gender.Both, false, false);
    Random random = new Random();
    FlowLayout layout = findViewById(R.id.flowLayout);
    Stream.of(layout.getViews()).filter(v -> v instanceof Chip).forEach(v -> {
        final Chip chip = (Chip) v;
        DataContext dataContext = new DataContext();
        chip.setText(nameGenerator.next(dataContext));
        if (random.nextBoolean())
            chip.setIcon(avatarGenerator.next(dataContext));
        chip.setRemovable(random.nextBoolean());
        chip.setOnRemoveListener(() -> {
            chip.setVisibility(View.GONE);
        });
    });
    EditText addChip = findViewById(R.id.addChip);
    addChip.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
            Chip chip = new Chip(FlowLayoutActivity.this);
            chip.setText(addChip.getText());
            chip.setRemovable(random.nextBoolean());
            chip.setSelected(random.nextBoolean());
            layout.addView(chip);
            addChip.setText("");
        }
        return true;
    });
}
Also used : ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Gender(tk.zielony.randomdata.person.Gender) Bundle(android.os.Bundle) KeyEvent(android.view.KeyEvent) Stream(com.annimon.stream.Stream) Chip(carbon.widget.Chip) Random(java.util.Random) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) StringFirstNameGenerator(tk.zielony.randomdata.person.StringFirstNameGenerator) EditText(carbon.widget.EditText) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) DataContext(tk.zielony.randomdata.DataContext) R(tk.zielony.carbonsamples.R) FlowLayout(carbon.widget.FlowLayout) View(android.view.View) EditText(carbon.widget.EditText) DataContext(tk.zielony.randomdata.DataContext) FlowLayout(carbon.widget.FlowLayout) Random(java.util.Random) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) StringFirstNameGenerator(tk.zielony.randomdata.person.StringFirstNameGenerator) Chip(carbon.widget.Chip)

Example 3 with EditText

use of carbon.widget.EditText in project Carbon by ZieIony.

the class ProgressDialogActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    EditText titleText = findViewById(R.id.titleText);
    EditText messageText = findViewById(R.id.messageText);
    EditText buttonText = findViewById(R.id.buttonText);
    findViewById(R.id.showProgressDialog).setOnClickListener(view -> {
        ProgressDialog dialog = new ProgressDialog(this);
        if (titleText.length() > 0)
            dialog.setTitle(titleText.getText());
        if (buttonText.length() > 0)
            dialog.addButton(buttonText.getText().toString(), null);
        Handler handler = new Handler(Looper.getMainLooper());
        Runnable dismissRunnable = dialog::dismiss;
        dialog.setOnDismissListener(dialogInterface -> handler.removeCallbacks(dismissRunnable));
        dialog.setText(messageText.getText());
        dialog.show();
        handler.postDelayed(dialog::dismiss, 2000);
    });
}
Also used : EditText(carbon.widget.EditText) Handler(android.os.Handler) ProgressDialog(carbon.dialog.ProgressDialog)

Aggregations

EditText (carbon.widget.EditText)3 Bundle (android.os.Bundle)2 Stream (com.annimon.stream.Stream)2 R (tk.zielony.carbonsamples.R)2 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)2 ThemedActivity (tk.zielony.carbonsamples.ThemedActivity)2 Handler (android.os.Handler)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 Nullable (androidx.annotation.Nullable)1 MultiSelectDialog (carbon.dialog.MultiSelectDialog)1 ProgressDialog (carbon.dialog.ProgressDialog)1 SingleSelectDialog (carbon.dialog.SingleSelectDialog)1 Chip (carbon.widget.Chip)1 DropDown (carbon.widget.DropDown)1 FlowLayout (carbon.widget.FlowLayout)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 DataContext (tk.zielony.randomdata.DataContext)1