use of fr.neamar.kiss.toggles.TogglesHandler in project KISS by Neamar.
the class TogglesResult method doLaunch.
@Override
public void doLaunch(Context context, View v) {
CompoundButton toggleButton = null;
if (v != null) {
toggleButton = (CompoundButton) v.findViewById(R.id.item_toggle_action_toggle);
}
if (toggleButton != null) {
// Use the handler to check or un-check button
if (toggleButton.isEnabled()) {
toggleButton.performClick();
}
} else {
//in case it is pinned on kissbar
if (togglesHandler == null) {
togglesHandler = new TogglesHandler(context);
}
//get message based on current state of toggle
String msg = context.getResources().getString(togglesHandler.getState(togglePojo) ? R.string.toggles_off : R.string.toggles_on);
//toggle state
togglesHandler.setState(togglePojo, !togglesHandler.getState(togglePojo));
//show toast to inform user what the state is
Toast.makeText(context, String.format(msg, " " + this.pojo.displayName), Toast.LENGTH_SHORT).show();
}
}
use of fr.neamar.kiss.toggles.TogglesHandler in project KISS by Neamar.
the class TogglesResult method display.
@SuppressWarnings({ "ResourceType", "deprecation" })
@Override
public View display(Context context, int position, View v) {
// On first run, initialize handler
if (togglesHandler == null)
togglesHandler = new TogglesHandler(context);
if (v == null)
v = inflateFromId(context, R.layout.item_toggle);
String togglePrefix = "<small><small>" + context.getString(R.string.toggles_prefix) + "</small></small>";
TextView toggleName = (TextView) v.findViewById(R.id.item_toggle_name);
toggleName.setText(TextUtils.concat(Html.fromHtml(togglePrefix), enrichText(togglePojo.displayName, context)));
ImageView toggleIcon = (ImageView) v.findViewById(R.id.item_toggle_icon);
toggleIcon.setImageDrawable(context.getResources().getDrawable(togglePojo.icon));
toggleIcon.setColorFilter(getThemeFillColor(context), Mode.SRC_IN);
// Use the handler to check or un-check button
final CompoundButton toggleButton = (CompoundButton) v.findViewById(R.id.item_toggle_action_toggle);
//set listener to null to avoid calling the listener of the older toggle item
//(due to recycling)
toggleButton.setOnCheckedChangeListener(null);
Boolean state = togglesHandler.getState(togglePojo);
if (state != null)
toggleButton.setChecked(togglesHandler.getState(togglePojo));
else
toggleButton.setEnabled(false);
toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!togglesHandler.getState(togglePojo).equals(toggleButton.isChecked())) {
// record launch manually
recordLaunch(buttonView.getContext());
togglesHandler.setState(togglePojo, toggleButton.isChecked());
toggleButton.setEnabled(false);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
toggleButton.setEnabled(true);
}
}.execute();
}
}
});
return v;
}
Aggregations