This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disabled the positive button instead of toast
- Loading branch information
1 parent
1170e12
commit 7c80232
Showing
5 changed files
with
119 additions
and
59 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/CustomEditTextPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.odk.share.views.ui.settings; | ||
|
||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.preference.EditTextPreference; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.util.AttributeSet; | ||
import android.widget.Button; | ||
|
||
/** | ||
* @author by Chromicle ([email protected]) | ||
* @since 1/30/2020 | ||
*/ | ||
public class CustomEditTextPreference extends EditTextPreference implements DialogInterface.OnClickListener { | ||
|
||
|
||
private EditTextWatcher editTextWatcher = new EditTextWatcher(); | ||
|
||
public CustomEditTextPreference(Context ctx, AttributeSet attrs, int defStyle) { | ||
super(ctx, attrs, defStyle); | ||
} | ||
|
||
|
||
public CustomEditTextPreference(Context ctx, AttributeSet attrs) { | ||
super(ctx, attrs); | ||
} | ||
|
||
/** | ||
* Return true in order to enable positive button or false to disable it. | ||
*/ | ||
private boolean onCheckValue(String value) { | ||
return !value.trim().equals(""); | ||
} | ||
|
||
private void onEditTextChanged() { | ||
boolean enable = onCheckValue(getEditText().getText().toString()); | ||
Dialog dlg = getDialog(); | ||
if (dlg instanceof AlertDialog) { | ||
AlertDialog alertDlg = (AlertDialog) dlg; | ||
Button possitiveButton = alertDlg.getButton(AlertDialog.BUTTON_POSITIVE); | ||
possitiveButton.setEnabled(enable); | ||
} | ||
} | ||
|
||
@Override | ||
protected void showDialog(Bundle state) { | ||
super.showDialog(state); | ||
|
||
getEditText().removeTextChangedListener(editTextWatcher); | ||
getEditText().addTextChangedListener(editTextWatcher); | ||
onEditTextChanged(); | ||
} | ||
|
||
private class EditTextWatcher implements TextWatcher { | ||
@Override | ||
public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
onEditTextChanged(); | ||
} | ||
|
||
@Override | ||
public void beforeTextChanged(CharSequence s, int start, int before, int count) { | ||
} | ||
|
||
@Override | ||
public void afterTextChanged(Editable s) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters