Skip to content

Commit

Permalink
No callback fire first time.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonHolovin committed Nov 6, 2015
1 parent 6a5a70d commit 908b2b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/io/palaima/debugdrawer/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.actions.ActionsModule;
import io.palaima.debugdrawer.actions.models.ButtonAction;
import io.palaima.debugdrawer.actions.models.SwitchAction;
import io.palaima.debugdrawer.fps.FpsModule;
import io.palaima.debugdrawer.location.LocationModule;
import io.palaima.debugdrawer.log.LogModule;
Expand Down Expand Up @@ -70,13 +71,22 @@ public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {

if (BuildConfig.DEBUG) {
ActionsModule actionsModule = new ActionsModule();

SwitchAction switchAction = new SwitchAction(this, "Test switch", new SwitchAction.Listener() {
@Override
public void onCheckedChanged(boolean value) {
Toast.makeText(MainActivity.this, "Switch checked", Toast.LENGTH_LONG).show();
}
});

ButtonAction buttonAction = new ButtonAction("Test button", new ButtonAction.Listener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this, "Button clicked", Toast.LENGTH_LONG).show();
}
});

actionsModule.addAction(switchAction);
actionsModule.addAction(buttonAction);

mDebugDrawer = new DebugDrawer.Builder(this).modules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

public class SwitchAction implements Action {
private final Listener mListener;
private final Context mContext;
private final String mName;

private Context mContext;
private final Listener mListener;
private final CompoundButton.OnCheckedChangeListener mSwitchListener;

private Switch mSwitch;

public SwitchAction(Context context, String name, Listener listener) {
mContext = context.getApplicationContext();
mName = name;
mListener = listener;
mSwitchListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mListener.onCheckedChanged(isChecked);
writeValue(isChecked);
}
};
}

@Override
Expand All @@ -54,13 +61,7 @@ public View getView(LinearLayout linearLayout) {
textView.setGravity(Gravity.CENTER_VERTICAL);

mSwitch = new Switch(context);
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mListener.onCheckedChanged(isChecked);
writeValue(isChecked);
}
});
mSwitch.setOnCheckedChangeListener(mSwitchListener);

viewGroup.addView(textView);
viewGroup.addView(mSwitch);
Expand All @@ -81,7 +82,9 @@ public void onClosed() {
@Override
public void onStart() {
boolean checked = readValue();
mSwitch.setOnCheckedChangeListener(null);
mSwitch.setChecked(checked);
mSwitch.setOnCheckedChangeListener(mSwitchListener);
}

@Override
Expand Down

0 comments on commit 908b2b8

Please sign in to comment.