use of android.widget.Switch in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method showDefaultValue.
private void showDefaultValue(TableRow tableRow, Question rowQuestion) {
if (rowQuestion.getValueBySession() != null) {
return;
}
switch(rowQuestion.getOutput()) {
case Constants.PHONE:
case Constants.POSITIVE_INT:
case Constants.POSITIVE_OR_ZERO_INT:
case Constants.INT:
case Constants.LONG_TEXT:
case Constants.SHORT_TEXT:
final CustomEditText editCard = (CustomEditText) tableRow.findViewById(R.id.answer);
editCard.setText("");
break;
case Constants.DROPDOWN_LIST:
case Constants.DROPDOWN_OU_LIST:
Spinner dropdown = (Spinner) tableRow.findViewById(R.id.answer);
dropdown.setSelection(0);
break;
case Constants.SWITCH_BUTTON:
Switch switchView = (Switch) tableRow.findViewById(R.id.answer);
Option selectedOption = rowQuestion.getOptionBySession();
if (selectedOption == null) {
//the 0 option is the left option and is false in the switch, the 1 option is
// the right option and is true
boolean isChecked = false;
if (rowQuestion.getAnswer().getOptions().get(1).getOptionAttribute().getDefaultOption() == 1) {
isChecked = true;
}
saveSwitchOption(rowQuestion, isChecked);
switchView.setChecked(isChecked);
break;
}
switchView.setChecked(findSwitchBoolean(rowQuestion));
break;
}
}
use of android.widget.Switch in project android_frameworks_base by crdroidandroid.
the class PowerNotificationControlsFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final View switchBar = view.findViewById(R.id.switch_bar);
final Switch switchWidget = (Switch) switchBar.findViewById(android.R.id.switch_widget);
final TextView switchText = (TextView) switchBar.findViewById(R.id.switch_text);
switchWidget.setChecked(isEnabled());
switchText.setText(isEnabled() ? getString(R.string.switch_bar_on) : getString(R.string.switch_bar_off));
switchBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean newState = !isEnabled();
MetricsLogger.action(getContext(), MetricsEvent.ACTION_TUNER_POWER_NOTIFICATION_CONTROLS, newState);
Settings.Secure.putInt(getContext().getContentResolver(), KEY_SHOW_PNC, newState ? 1 : 0);
switchWidget.setChecked(newState);
switchText.setText(newState ? getString(R.string.switch_bar_on) : getString(R.string.switch_bar_off));
}
});
switchWidget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean newState = !isEnabled();
MetricsLogger.action(getContext(), MetricsEvent.ACTION_TUNER_POWER_NOTIFICATION_CONTROLS, newState);
Settings.Secure.putInt(getContext().getContentResolver(), KEY_SHOW_PNC, newState ? 1 : 0);
switchWidget.setChecked(newState);
switchText.setText(newState ? getString(R.string.switch_bar_on) : getString(R.string.switch_bar_off));
}
});
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}
use of android.widget.Switch in project android_frameworks_base by crdroidandroid.
the class InputMethodManagerService method updateKeyboardFromSettingsLocked.
public void updateKeyboardFromSettingsLocked() {
mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
if (mSwitchingDialog != null && mSwitchingDialogTitleView != null && mSwitchingDialog.isShowing()) {
final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
}
}
use of android.widget.Switch in project aplicativo by InCasa.
the class ReleActivity method getRele2.
public void getRele2(String URLRELE2) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE2, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
Switch rele2 = (Switch) findViewById(R.id.switch2);
temp = response.getString("valor");
if (temp.equals("0")) {
rele2.setChecked(false);
estado2 = false;
} else {
rele2.setChecked(true);
estado2 = true;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of android.widget.Switch in project aplicativo by InCasa.
the class ReleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rele);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
this.ip = mSharedPreferences.getString("servidor", " ");
final String URLRELE1 = "http://" + ip + "/backend/releValor/1";
final String URLRELE2 = "http://" + ip + "/backend/releValor/2";
final String URLRELE3 = "http://" + ip + "/backend/releValor/3";
final String URLRELE4 = "http://" + ip + "/backend/releValor/4";
final String URLPOSTRELE = "http://" + ip + "/backend/releValor";
Rele Objrele1 = new Rele();
Rele Objrele2 = new Rele();
Rele Objrele3 = new Rele();
Rele Objrele4 = new Rele();
Objrele1 = HomeActivity.Rele1;
Objrele2 = HomeActivity.Rele2;
Objrele3 = HomeActivity.Rele3;
Objrele4 = HomeActivity.Rele4;
getRele1(URLRELE1);
getRele2(URLRELE2);
getRele3(URLRELE3);
getRele4(URLRELE4);
// Thread para atualizar os valores dos reles a cada 10seg
timerObj = new Timer();
timerTaskObj = new TimerTask() {
public void run() {
getRele1(URLRELE1);
getRele2(URLRELE2);
getRele3(URLRELE3);
getRele4(URLRELE4);
}
};
timerObj.schedule(timerTaskObj, 0, 2000);
Switch rele1 = (Switch) findViewById(R.id.switch1);
Switch rele2 = (Switch) findViewById(R.id.switch2);
Switch rele3 = (Switch) findViewById(R.id.switch3);
Switch rele4 = (Switch) findViewById(R.id.switch4);
TextView nomeRele1 = (TextView) findViewById(R.id.lblRele1);
TextView nomeRele2 = (TextView) findViewById(R.id.lblRele2);
TextView nomeRele3 = (TextView) findViewById(R.id.lblRele3);
TextView nomeRele4 = (TextView) findViewById(R.id.lblRele4);
nomeRele1.setText(Objrele1.getNome());
nomeRele2.setText(Objrele2.getNome());
nomeRele3.setText(Objrele3.getNome());
nomeRele4.setText(Objrele4.getNome());
rele1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado1 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 1);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 1);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado2 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 2);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 2);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado3 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 3);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 3);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado4 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 4);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 4);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
}
Aggregations