Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add edit text option to prompt dialog #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand All @@ -37,16 +39,19 @@ public class PromptDialog extends Dialog {
public static final int DIALOG_TYPE_WRONG = 2;
public static final int DIALOG_TYPE_SUCCESS = 3;
public static final int DIALOG_TYPE_WARNING = 4;
public static final int DIALOG_TYPE_EDIT = 5;
public static final int DIALOG_TYPE_DEFAULT = DIALOG_TYPE_INFO;

private AnimationSet mAnimIn, mAnimOut;
private View mDialogView;
private TextView mTitleTv, mContentTv, mPositiveBtn;

private EditText editText;
private OnPositiveListener mOnPositiveListener;

private int mDialogType;
private boolean mIsShowAnim;
private CharSequence mTitle, mContent, mBtnText;
private boolean mIsShowAnim, mIsEditTextSecure;
private CharSequence mTitle, mContent, mBtnText, mEditTextContent, mEditTextHint;

public PromptDialog(Context context) {
this(context, 0);
Expand Down Expand Up @@ -82,6 +87,7 @@ private void initView() {
mTitleTv = (TextView) contentView.findViewById(R.id.tvTitle);
mContentTv = (TextView) contentView.findViewById(R.id.tvContent);
mPositiveBtn = (TextView) contentView.findViewById(R.id.btnPositive);
editText = (EditText) contentView.findViewById(R.id.editText);

View llBtnGroup = findViewById(R.id.llBtnGroup);
ImageView logoIv = (ImageView) contentView.findViewById(R.id.logoIv);
Expand Down Expand Up @@ -109,6 +115,26 @@ private void initView() {
mTitleTv.setText(mTitle);
mContentTv.setText(mContent);
mPositiveBtn.setText(mBtnText);

configureEditText();
}

private void configureEditText()
{
if(mDialogType == DIALOG_TYPE_EDIT)
{
editText.setVisibility(View.VISIBLE);
editText.setHint(mEditTextHint);
editText.setText(mEditTextContent);
if(mIsEditTextSecure)
{
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
}
}
else
{
editText.setVisibility(View.GONE);
}
}

private void resizeDialog() {
Expand Down Expand Up @@ -161,6 +187,9 @@ private int getLogoResId(int mDialogType) {
if (DIALOG_TYPE_WARNING == mDialogType) {
return R.mipmap.icon_warning;
}
if(DIALOG_TYPE_EDIT == mDialogType) {
return R.mipmap.icon_edit;
}
return R.mipmap.ic_info;
}

Expand All @@ -183,6 +212,10 @@ private int getColorResId(int mDialogType) {
if (DIALOG_TYPE_WARNING == mDialogType) {
return R.color.color_type_warning;
}
if(DIALOG_TYPE_EDIT == mDialogType) {
return R.color.color_type_edit;
}

return R.color.color_type_info;
}

Expand All @@ -205,6 +238,9 @@ private int getSelBtn(int mDialogType) {
if (DIALOG_TYPE_WARNING == mDialogType) {
return R.drawable.sel_btn_warning;
}
if(DIALOG_TYPE_EDIT == mDialogType) {
return R.drawable.sel_btn_edit;
}
return R.drawable.sel_btn;
}

Expand Down Expand Up @@ -375,4 +411,49 @@ public interface OnPositiveListener {
void onClick(PromptDialog dialog);
}

public EditText getEditText()
{
return editText;
}

public PromptDialog setEditTextContent(CharSequence editTextContent)
{
mEditTextContent = editTextContent;
return this;
}

public PromptDialog setEditTextContent(int resId)
{
mEditTextContent = getContext().getString(resId);
return this;
}

public CharSequence getEditTextContent()
{
return mEditTextContent;
}

public CharSequence getEditTextHint()
{
return mEditTextHint;
}

public PromptDialog setEditTextHint(CharSequence editTextHint)
{
mEditTextHint = editTextHint;
return this;
}

public PromptDialog setEditTextHint(int resId)
{
mEditTextHint = getContext().getString(resId);
return this;
}

public PromptDialog setIsEditTextContentSecure(Boolean isSecure)
{
mIsEditTextSecure = isSecure;
return this;
}

}
9 changes: 9 additions & 0 deletions ColorDialog/src/main/res/drawable/black_border_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dip" android:color="@color/color_dialog_content_prompt" />
<corners android:radius="1dp" />
</shape>
</item>
</selector>
17 changes: 17 additions & 0 deletions ColorDialog/src/main/res/drawable/sel_btn_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<stroke android:width="1dp" android:color="@color/color_dialog_gray" />
<corners android:radius="6dp" />
</shape>
</item>

<item>
<shape>
<stroke android:width="1dp" android:color="@color/color_type_edit" />
<corners android:radius="6dp" />
</shape>
</item>

</selector>
18 changes: 17 additions & 1 deletion ColorDialog/src/main/res/layout/layout_promptdialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,23 @@
android:paddingRight="10dp"
android:paddingTop="5dp"
android:textColor="@color/color_dialog_content_prompt"
android:visibility="visible" />
android:visibility="visible"
/>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:textColor="@color/color_dialog_content_prompt"
android:background="@drawable/black_border_background"
android:inputType="text" />
</LinearLayout>


Expand Down
Binary file added ColorDialog/src/main/res/mipmap/icon_edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ColorDialog/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<color name="color_type_wrong">#ed7861</color>
<color name="color_type_warning">#e8bd4b</color>
<color name="color_type_success">#90b06e</color>
<color name="color_type_edit">#222da1</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ public void showPromptDialog(View view) {
showPromptDlg();
}

public void showPromptDialogWithEditText(View view)
{
new PromptDialog(this)
.setDialogType(PromptDialog.DIALOG_TYPE_EDIT)
.setAnimationEnable(true)
.setTitleText("EDIT")
.setContentText("Sub Title")
.setEditTextHint("Enter Text")
.setPositiveListener(getString(R.string.edit), new PromptDialog.OnPositiveListener() {
@Override
public void onClick(PromptDialog dialog) {
dialog.dismiss();
Toast.makeText(MainActivity.this,dialog.getEditText().getText().toString(),Toast.LENGTH_LONG).show();
}
}).show();
}


private void showPromptDlg() {
new PromptDialog(this)
.setDialogType(PromptDialog.DIALOG_TYPE_SUCCESS)
Expand Down
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
android:layout_height="wrap_content"
android:text="@string/prompt_dialog"/>

<Button
android:onClick="showPromptDialogWithEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/prompt_dialog_edit_text"/>

<Button
android:onClick="showPicDialog"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<string name="info">Info</string>
<string name="error">Error</string>
<string name="warning">Warning</string>
<string name="edit">Save</string>
<string name="text_data">Your info text goes here. Loremipsum dolor sit amet, consecteturn adipisicing elit, sed do eiusmod.</string>
<string name="prompt_dialog">Prompt Dialog</string>
<string name="prompt_dialog_edit_text">Prompt Dialog with Edit Text</string>
<string name="pic">Pic</string>
<string name="text">Text</string>
<string name="text_and_pic">Text And Pic</string>
Expand Down