Search in sources :

Example 36 with Switch

use of android.widget.Switch in project aplicativo by InCasa.

the class AlarmeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarme);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    final Switch AlarmeSwitch = (Switch) findViewById(R.id.switchAlarme);
    SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
    this.ip = mSharedPreferences.getString("servidor", " ");
    if (getAlarme() != false) {
        AlarmeSwitch.setChecked(true);
    }
    final String URLPRESENCA = "http://" + ip + "/backend/presencaValorNow";
    // Thread para checar se o modo alarme esta ativo a cada 3seg
    timer = new Timer();
    AlarmeThread = new TimerTask() {

        public void run() {
            getPresenca(URLPRESENCA);
            // checa se há presença e se o modo alarme esta ativo.
            if (ativo == true && getAlarme() == true) {
                // chama a notificação
                Notificacao();
            }
        }
    };
    timer.schedule(AlarmeThread, 0, 3000);
    Alerta = new NotificationCompat.Builder(this);
    AlarmeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (getAlarme() == true) {
                saveAlarme(false);
            } else {
                saveAlarme(true);
            }
        }
    });
}
Also used : Switch(android.widget.Switch) Timer(java.util.Timer) TimerTask(java.util.TimerTask) SharedPreferences(android.content.SharedPreferences) NotificationCompat(android.support.v7.app.NotificationCompat) CompoundButton(android.widget.CompoundButton)

Example 37 with Switch

use of android.widget.Switch in project aplicativo by InCasa.

the class ReleActivity method getRele1.

public void getRele1(String URLRELE1) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE1, null, new Response.Listener<JSONObject>() {

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele1 = (Switch) findViewById(R.id.switch1);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele1.setChecked(false);
                    estado1 = false;
                } else {
                    rele1.setChecked(true);
                    estado1 = 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);
}
Also used : VolleyError(com.android.volley.VolleyError) Context(android.content.Context) User(model.User) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 38 with Switch

use of android.widget.Switch in project aplicativo by InCasa.

the class ReleActivity method getRele4.

public void getRele4(String URLRELE4) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE4, null, new Response.Listener<JSONObject>() {

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele4 = (Switch) findViewById(R.id.switch4);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele4.setChecked(false);
                    estado4 = false;
                } else {
                    rele4.setChecked(true);
                    estado4 = 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);
}
Also used : VolleyError(com.android.volley.VolleyError) Context(android.content.Context) User(model.User) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 39 with Switch

use of android.widget.Switch in project aplicativo by InCasa.

the class ReleActivity method getRele3.

public void getRele3(String URLRELE3) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE3, null, new Response.Listener<JSONObject>() {

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele3 = (Switch) findViewById(R.id.switch3);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele3.setChecked(false);
                    estado3 = false;
                } else {
                    rele3.setChecked(true);
                    estado3 = 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);
}
Also used : VolleyError(com.android.volley.VolleyError) Context(android.content.Context) User(model.User) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 40 with Switch

use of android.widget.Switch in project facebook-android-sdk by facebook.

the class AccountKitLoginActivity method createAccountKitConfiguration.

private AccountKitConfiguration.AccountKitConfigurationBuilder createAccountKitConfiguration(final LoginType loginType) {
    AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder(loginType, getResponseType());
    final Switch titleTypeSwitch = (Switch) findViewById(R.id.title_type_switch);
    final Switch stateParamSwitch = (Switch) findViewById(R.id.state_param_switch);
    final Switch facebookNotificationsSwitch = (Switch) findViewById(R.id.facebook_notification_switch);
    final Switch useManualWhiteListBlacklist = (Switch) findViewById(R.id.whitelist_blacklist_switch);
    final Switch readPhoneStateSwitch = (Switch) findViewById(R.id.read_phone_state_switch);
    final Switch receiveSMS = (Switch) findViewById(R.id.receive_sms_switch);
    if (titleTypeSwitch != null && titleTypeSwitch.isChecked()) {
        configurationBuilder.setTitleType(AccountKitActivity.TitleType.APP_NAME);
    }
    final UIManager uiManager;
    if (advancedUISwitch != null && advancedUISwitch.isChecked()) {
        if (isReverbThemeSelected()) {
            if (switchLoginTypeReceiver == null) {
                switchLoginTypeReceiver = new BroadcastReceiver() {

                    @Override
                    public void onReceive(final Context context, final Intent intent) {
                        final String loginTypeString = intent.getStringExtra(ReverbUIManager.LOGIN_TYPE_EXTRA);
                        if (loginTypeString == null) {
                            return;
                        }
                        final LoginType loginType = LoginType.valueOf(loginTypeString);
                        onLogin(loginType);
                    }
                };
                LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(switchLoginTypeReceiver, new IntentFilter(ReverbUIManager.SWITCH_LOGIN_TYPE_EVENT));
            }
            uiManager = new ReverbUIManager(confirmButton, entryButton, loginType, textPosition, selectedThemeId);
        } else {
            uiManager = new AccountKitSampleAdvancedUIManager(confirmButton, entryButton, textPosition, loginType);
        }
    } else if (isSkinSelected()) {
        @ColorInt final int primaryColor = ContextCompat.getColor(this, R.color.default_color);
        if (getBackgroundImage() >= 0) {
            uiManager = new SkinManager(loginType, skin, primaryColor, getBackgroundImage(), getSkinTintOption(), getSkinBackgroundTintIntensity());
        } else {
            uiManager = new SkinManager(loginType, skin, primaryColor);
        }
    } else {
        uiManager = new ThemeUIManager(loginType, selectedThemeId);
    }
    configurationBuilder.setUIManager(uiManager);
    if (stateParamSwitch != null && stateParamSwitch.isChecked()) {
        initialStateParam = UUID.randomUUID().toString();
        configurationBuilder.setInitialAuthState(initialStateParam);
    }
    if (facebookNotificationsSwitch != null && !facebookNotificationsSwitch.isChecked()) {
        configurationBuilder.setFacebookNotificationsEnabled(false);
    }
    if (useManualWhiteListBlacklist != null && useManualWhiteListBlacklist.isChecked()) {
        final String[] blackList = getResources().getStringArray(R.array.blacklistedSmsCountryCodes);
        final String[] whiteList = getResources().getStringArray(R.array.whitelistedSmsCountryCodes);
        configurationBuilder.setSMSBlacklist(blackList);
        configurationBuilder.setSMSWhitelist(whiteList);
    }
    if (readPhoneStateSwitch != null && !(readPhoneStateSwitch.isChecked())) {
        configurationBuilder.setReadPhoneStateEnabled(false);
    }
    if (receiveSMS != null && !receiveSMS.isChecked()) {
        configurationBuilder.setReceiveSMS(false);
    }
    return configurationBuilder;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) UIManager(com.facebook.accountkit.ui.UIManager) ThemeUIManager(com.facebook.accountkit.ui.ThemeUIManager) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ThemeUIManager(com.facebook.accountkit.ui.ThemeUIManager) Switch(android.widget.Switch) AccountKitConfiguration(com.facebook.accountkit.ui.AccountKitConfiguration) LoginType(com.facebook.accountkit.ui.LoginType) SkinManager(com.facebook.accountkit.ui.SkinManager)

Aggregations

Switch (android.widget.Switch)56 View (android.view.View)29 CompoundButton (android.widget.CompoundButton)18 TextView (android.widget.TextView)18 Context (android.content.Context)11 DialogInterface (android.content.DialogInterface)8 AlertDialog (android.app.AlertDialog)7 LayoutInflater (android.view.LayoutInflater)7 Checkable (android.widget.Checkable)7 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6 Drawable (android.graphics.drawable.Drawable)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 JSONObject (org.json.JSONObject)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 Intent (android.content.Intent)5 LocaleList (android.os.LocaleList)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)5