Created
April 9, 2015 07:38
-
-
Save jasiek/755035318f92a2d67262 to your computer and use it in GitHub Desktop.
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
package com.example.jps.opensesame.tasks; | |
import android.view.View; | |
import android.os.AsyncTask; | |
import android.widget.LinearLayout; | |
import android.widget.ToggleButton; | |
import com.example.jps.opensesame.Sensor; | |
/** | |
* Created by jps on 09/04/2015. | |
*/ | |
public class OnOffTask extends AbstractAsyncTask<Void, Void, Boolean> { | |
private final ToggleButton toggleButton; | |
private final LinearLayout layout; | |
public OnOffTask(Sensor s, ToggleButton t, LinearLayout l) { | |
super(s); | |
// This feels a bit clunky. | |
this.toggleButton = t; | |
this.layout = l; | |
} | |
@Override | |
protected Boolean doInBackground(Void... params) { | |
return sensor.ping(); | |
} | |
@Override | |
protected void onPostExecute(Boolean b) { | |
if (toggleButton.isChecked()) { | |
if (b) { | |
layout.setVisibility(View.VISIBLE); | |
} | |
} else { | |
layout.setVisibility(View.INVISIBLE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment