make tap on whole line toggle expander

This commit is contained in:
Eric House 2020-09-28 13:05:24 -07:00
parent 574e50f235
commit 2f849efe2a
5 changed files with 64 additions and 17 deletions

View file

@ -352,7 +352,7 @@ public class DictsDelegate extends ListDelegateBase
protected DictsDelegate( Delegator delegator, Bundle savedInstanceState )
{
super( delegator, savedInstanceState, R.layout.dict_browse,
super( delegator, savedInstanceState, R.layout.dicts_browse,
R.menu.dicts_menu );
m_activity = delegator.getActivity();
}
@ -374,6 +374,7 @@ public class DictsDelegate extends ListDelegateBase
OnClickListener newSelLstnr =
new OnClickListener() {
@Override
public void onClick( DialogInterface dlgi, int item ) {
moveTo[0] = item;
AlertDialog dlg = (AlertDialog)dlgi;
@ -390,6 +391,7 @@ public class DictsDelegate extends ListDelegateBase
};
lstnr = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
DictLoc toLoc = itemToRealLoc( moveTo[0] );
moveDicts( selNames, toLoc );
@ -409,6 +411,7 @@ public class DictsDelegate extends ListDelegateBase
case SET_DEFAULT: {
final String name = m_selDicts.keySet().iterator().next();
lstnr = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
if ( DialogInterface.BUTTON_NEGATIVE == item
|| DialogInterface.BUTTON_POSITIVE == item ) {
@ -437,6 +440,7 @@ public class DictsDelegate extends ListDelegateBase
case DICT_OR_DECLINE: {
lstnr = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
Intent intent = getIntent();
int lang = intent.getIntExtra( MultiService.LANG, -1 );
@ -448,6 +452,7 @@ public class DictsDelegate extends ListDelegateBase
}
};
lstnr2 = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
curThis().finish();
}
@ -563,6 +568,7 @@ public class DictsDelegate extends ListDelegateBase
}
}
@Override
public void onClick( View view )
{
if ( view == m_checkbox ) {
@ -773,6 +779,7 @@ public class DictsDelegate extends ListDelegateBase
//////////////////////////////////////////////////////////////////////
// GroupStateListener interface
//////////////////////////////////////////////////////////////////////
@Override
public void onGroupExpandedChanged( Object groupObj, boolean expanded )
{
ListGroup lg = (ListGroup)groupObj;
@ -790,6 +797,7 @@ public class DictsDelegate extends ListDelegateBase
//////////////////////////////////////////////////////////////////////
// OnItemLongClickListener interface
//////////////////////////////////////////////////////////////////////
@Override
public boolean onItemLongClick( AdapterView<?> parent, View view,
int position, long id ) {
boolean success = view instanceof SelectableItem.LongClickHandler;
@ -1132,6 +1140,7 @@ public class DictsDelegate extends ListDelegateBase
(LinearLayout)inflate( R.layout.remote_dict_details );
Button button = (Button)view.findViewById( R.id.download_button );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {
DwnldDelegate.
downloadDictInBack( m_activity, info.m_lang,

View file

@ -25,8 +25,13 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
public class ExpandImageButton extends ImageButton {
import java.util.HashSet;
import java.util.Set;
public class ExpandImageButton extends ImageButton
implements View.OnClickListener {
private boolean m_expanded;
private Set<ExpandChangeListener> mListeners = new HashSet<>();
public interface ExpandChangeListener {
public void expandedChanged( boolean nowExpanded );
@ -37,27 +42,51 @@ public class ExpandImageButton extends ImageButton {
super( context, as );
}
@Override
protected void onFinishInflate()
{
super.onFinishInflate();
setOnClickListener( this );
setImageResource();
}
@Override
public void onClick( View view )
{
toggle();
}
public ExpandImageButton setExpanded( boolean expanded )
{
m_expanded = expanded;
boolean changed = m_expanded != expanded;
if ( changed ) {
m_expanded = expanded;
setImageResource( expanded ?
R.drawable.expander_ic_maximized :
R.drawable.expander_ic_minimized);
setImageResource();
for ( ExpandChangeListener proc : mListeners ) {
proc.expandedChanged( m_expanded );
}
}
return this;
}
public ExpandImageButton setOnExpandChangedListener( final ExpandChangeListener listener )
{
setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view )
{
m_expanded = ! m_expanded;
setExpanded( m_expanded );
listener.expandedChanged( m_expanded );
}
} );
mListeners.add( listener );
return this;
}
public void toggle()
{
setExpanded( ! m_expanded );
}
private void setImageResource()
{
setImageResource( m_expanded ?
R.drawable.expander_ic_maximized :
R.drawable.expander_ic_minimized);
}
}

View file

@ -214,7 +214,7 @@ public class KnownPlayersDelegate extends DelegateBase {
}
} );
ExpandImageButton eib = (ExpandImageButton)item.findViewById( R.id.expander );
final ExpandImageButton eib = (ExpandImageButton)item.findViewById( R.id.expander );
eib.setOnExpandChangedListener( new ExpandChangeListener() {
@Override
public void expandedChanged( boolean nowExpanded )
@ -224,6 +224,13 @@ public class KnownPlayersDelegate extends DelegateBase {
}
} );
item.findViewById( R.id.player_line )
.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {
eib.toggle();
}
} );
}
return view;
}

View file

@ -6,7 +6,8 @@
android:layout_height="match_parent"
>
<LinearLayout android:orientation="horizontal"
<LinearLayout android:id="@+id/player_line"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF7F7F7F"
@ -43,6 +44,7 @@
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button android:id="@+id/player_edit_name"
android:text="@string/player_edit_name"