mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
disable reset button unless there's state to clear
Using a timer seemed easier than adding listeners on a bunch of fields.
This commit is contained in:
parent
ccd557658f
commit
59acc5d619
3 changed files with 41 additions and 3 deletions
|
@ -25,6 +25,7 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -141,6 +142,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
private Spinner m_spinnerMax;
|
||||
private boolean m_newAlertShown;
|
||||
private String m_desc;
|
||||
private Runnable mResetChecker;
|
||||
|
||||
private class DictListAdapter extends BaseAdapter
|
||||
implements SectionIndexer {
|
||||
|
@ -295,6 +297,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
{
|
||||
scrapeBrowseState();
|
||||
storeBrowseState();
|
||||
enableResetChecker( false );
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -669,8 +672,9 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
|
||||
private void setShowConfig()
|
||||
{
|
||||
findViewById(R.id.config).setVisibility( m_browseState.m_expanded
|
||||
? View.VISIBLE : View.GONE );
|
||||
boolean expanded = m_browseState.m_expanded;
|
||||
findViewById(R.id.config).setVisibility( expanded ? View.VISIBLE : View.GONE );
|
||||
enableResetChecker( expanded );
|
||||
}
|
||||
|
||||
private void setFindPats( PatDesc[] descs )
|
||||
|
@ -713,7 +717,6 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
simple_spinner_dropdown_item );
|
||||
spinner.setAdapter( adapter );
|
||||
spinner.setSelection( curVal - MIN_LEN );
|
||||
// spinner.setOnItemSelectedListener( this );
|
||||
}
|
||||
|
||||
private void setUpSpinners()
|
||||
|
@ -832,6 +835,35 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
final private static int sResetCheckMS = 500;
|
||||
private void enableResetChecker( boolean enable )
|
||||
{
|
||||
DbgUtils.assertOnUIThread();
|
||||
if ( !enable ) {
|
||||
mResetChecker = null;
|
||||
} else if ( null == mResetChecker ) {
|
||||
final Handler handler = new Handler();
|
||||
final Button resetButton = (Button)findViewById(R.id.button_reset);
|
||||
mResetChecker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ( null != mResetChecker ) {
|
||||
int curMin = MIN_LEN + m_spinnerMin.getSelectedItemPosition();
|
||||
int curMax = MIN_LEN + m_spinnerMax.getSelectedItemPosition();
|
||||
boolean hasState = curMin != MIN_LEN || curMax != MAX_LEN;
|
||||
for ( int ii = 0; !hasState && ii < m_rows.length; ++ii ) {
|
||||
hasState = m_rows[ii].hasState();
|
||||
}
|
||||
resetButton.setEnabled( hasState );
|
||||
|
||||
handler.postDelayed( mResetChecker, sResetCheckMS );
|
||||
}
|
||||
}
|
||||
};
|
||||
handler.postDelayed( mResetChecker, sResetCheckMS );
|
||||
}
|
||||
}
|
||||
|
||||
private static void launch( Delegator delegator, Bundle bundle )
|
||||
{
|
||||
delegator.addFragment( DictBrowseFrag.newInstance( delegator ),
|
||||
|
|
|
@ -49,6 +49,11 @@ public class PatTableRow extends TableRow implements OnEditorActionListener {
|
|||
|
||||
void setOnEnterPressed( EnterPressed proc ) { mEnterProc = proc; }
|
||||
|
||||
boolean hasState()
|
||||
{
|
||||
return 0 < mEdit.getText().length() || mCheck.isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
|
|
|
@ -123,6 +123,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/button_reset"
|
||||
android:enabled="false"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
|
|
Loading…
Add table
Reference in a new issue