Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a04dc9c9 authored by Daniel Lehmann's avatar Daniel Lehmann
Browse files

Tweaked the input dialogs for the group name and the type

 - Tweaked padding in type editor
 - Made it so that OK is disabled in group editor
 - Automatically show the keyboard
 - Made the implementations a little more similar to each other

Change-Id: I2c1a131a7eb7ea3e306fdaa430be8945accf915b
parent d9132030
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="25dip"
    android:paddingRight="25dip"
    android:paddingBottom="25dip"
    android:paddingLeft="25dip">
    <EditText
        android:id="@+id/custom_dialog_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</FrameLayout>
+43 −8
Original line number Diff line number Diff line
@@ -31,19 +31,24 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Entity;
import android.content.DialogInterface.OnShowListener;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -376,20 +381,21 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
     */
    private Dialog createCustomDialog() {
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
        builder.setTitle(R.string.customLabelPickerTitle);

        final EditText customType = new EditText(builder.getContext());
        customType.setId(R.id.custom_dialog_content);
        customType.setInputType(INPUT_TYPE_CUSTOM);
        customType.setSaveEnabled(true);
        customType.requestFocus();
        final View view = layoutInflater.inflate(R.layout.contact_editor_label_name_dialog, null);
        final EditText editText = (EditText) view.findViewById(R.id.custom_dialog_content);
        editText.setInputType(INPUT_TYPE_CUSTOM);
        editText.setSaveEnabled(true);

        builder.setView(customType);
        builder.setView(view);
        editText.requestFocus();

        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                final String customText = customType.getText().toString().trim();
                final String customText = editText.getText().toString().trim();
                if (ContactsUtils.isGraphic(customText)) {
                    final List<EditType> allTypes =
                            EntityModifier.getValidTypes(mState, mKind, null);
@@ -413,7 +419,36 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,

        builder.setNegativeButton(android.R.string.cancel, null);

        return builder.create();
        final AlertDialog dialog = builder.create();
        dialog.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                updateCustomDialogOkButtonState(dialog, editText);
            }
        });
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                updateCustomDialogOkButtonState(dialog, editText);
            }
        });
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        return dialog;
    }

    /* package */ void updateCustomDialogOkButtonState(AlertDialog dialog, EditText editText) {
        final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
        okButton.setEnabled(!TextUtils.isEmpty(editText.getText().toString().trim()));
    }

    /**
+31 −34
Original line number Diff line number Diff line
@@ -28,16 +28,14 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

/**
 * A common superclass for creating and renaming groups.
 */
public abstract class GroupNameDialogFragment extends DialogFragment
        implements TextWatcher, OnShowListener {
    private EditText mEdit;

public abstract class GroupNameDialogFragment extends DialogFragment {
    protected abstract int getTitleResourceId();
    protected abstract void initializeGroupLabelEditText(EditText editText);
    protected abstract void onCompleted(String groupLabel);
@@ -47,45 +45,33 @@ public abstract class GroupNameDialogFragment extends DialogFragment
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
        final View view = layoutInflater.inflate(R.layout.group_name_dialog, null);
        mEdit = (EditText) view.findViewById(R.id.group_label);
        initializeGroupLabelEditText(mEdit);

        mEdit.addTextChangedListener(this);
        final EditText editText = (EditText) view.findViewById(R.id.group_label);
        initializeGroupLabelEditText(editText);

        builder.setTitle(getTitleResourceId());
        builder.setView(view);
        editText.requestFocus();
        builder.setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int whichButton) {
                        onCompleted(mEdit.getText().toString().trim());
                        onCompleted(editText.getText().toString().trim());
                    }
                }
            );

        builder.setNegativeButton(android.R.string.cancel, null);
        final AlertDialog dialog = builder.create();

        dialog.setOnShowListener(this);
        return dialog;
    }

        dialog.setOnShowListener(new OnShowListener() {
            @Override
    public void onShow(DialogInterface dialog) {
        updateOkButtonState((AlertDialog) dialog);
            public void onShow(DialogInterface dialogInterface) {
                updateOkButtonState(dialog, editText);
            }

        });
        editText.addTextChangedListener(new TextWatcher() {
            @Override
    public void afterTextChanged(Editable s) {
        AlertDialog dialog = (AlertDialog) getDialog();
        // Make sure the dialog has not already been dismissed or destroyed.
        if (dialog != null) {
            updateOkButtonState(dialog);
        }
    }

    private void updateOkButtonState(AlertDialog dialog) {
        Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
        okButton.setEnabled(!TextUtils.isEmpty(mEdit.getText().toString().trim()));
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
@@ -93,6 +79,17 @@ public abstract class GroupNameDialogFragment extends DialogFragment
            }

            @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
            public void afterTextChanged(Editable s) {
                updateOkButtonState(dialog, editText);
            }
        });
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return dialog;
    }

    /* package */ void updateOkButtonState(AlertDialog dialog, EditText editText) {
        final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
        okButton.setEnabled(!TextUtils.isEmpty(editText.getText().toString().trim()));
    }
}