private void Switch(LinearLayout linLayout, final int featNum, final String
featName, boolean swiOn) {
final Switch switchR = new Switch(getContext);
final GradientDrawable THUMB = new GradientDrawable();
THUMB.setShape(1);
THUMB.setSize(40,40);
final GradientDrawable TRACK = new GradientDrawable();
TRACK.setCornerRadius(100);
TRACK.setSize(20,20);
boolean isOn = Preferences.loadPrefBool(featName, featNum, swiOn);
if(isOn){
THUMB.setColor(BTN_COLOR);
THUMB.setStroke(2,BTN_COLOR);
TRACK.setColor(Color.parseColor("#AB143568"));
TRACK.setStroke(2, BTN_COLOR);
}
else{
THUMB.setColor(Color.WHITE);
THUMB.setStroke(2,BTN_COLOR);
TRACK.setColor(Color.argb(200,255,255,255));
TRACK.setStroke(2, BTN_COLOR);
}
switchR.setText(featName);
switchR.setTextColor(TEXT_COLOR_2);
switchR.setThumbDrawable(THUMB);
switchR.setTrackDrawable(TRACK);
switchR.setPadding(10, 5, 0, 5);
switchR.setChecked(Preferences.loadPrefBool(featName, featNum, swiOn));
switchR.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton compoundButton, boolean
bool) {
Preferences.changeFeatureBool(featName, featNum, bool);
if(bool){
THUMB.setColor(BTN_COLOR);
THUMB.setStroke(2,BTN_COLOR);
TRACK.setColor(Color.parseColor("#AB143568"));
TRACK.setStroke(2, BTN_COLOR);
}
else{
THUMB.setColor(Color.WHITE);
THUMB.setStroke(2,BTN_COLOR);
TRACK.setColor(Color.argb(200,255,255,255));
TRACK.setStroke(2, BTN_COLOR);
}
switch (featNum) {
case -1: //Save perferences
Preferences.with(switchR.getContext()).writeBoolean(-1,
bool);
if (bool == false)
Preferences.with(switchR.getContext()).clear(); //Clear
perferences if switched off
break;
case -3:
Preferences.isExpanded = bool;
scrollView.setLayoutParams(bool ? scrlLLExpanded : scrlLL);
break;
}
}
});
linLayout.addView(switchR);
}