Search in sources :

Example 46 with Switch

use of android.widget.Switch in project orWall by EthACKdotOrg.

the class HomeFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    home = inflater.inflate(R.layout.fragment_tabbed_home, container, false);
    iptables = new Iptables(getActivity());
    boolean initSupported = Iptables.initSupported();
    Switch orwallStatus = (Switch) home.findViewById(R.id.orwall_status);
    // Status switches — most of them are read-only, as they just displays devices capabilities.
    Switch status_initscript = (Switch) home.findViewById(R.id.status_initscript);
    Switch status_root = (Switch) home.findViewById(R.id.status_root);
    Switch status_iptables = (Switch) home.findViewById(R.id.status_iptables);
    Switch status_ipt_comments = (Switch) home.findViewById(R.id.status_ipt_comments);
    Switch status_orbot = (Switch) home.findViewById(R.id.status_orbot);
    // Buttons
    Button settings = (Button) home.findViewById(R.id.id_settings);
    Button about = (Button) home.findViewById(R.id.id_about);
    Button wizard = (Button) home.findViewById(R.id.id_wizard);
    // If we know there is no init-script support, then don't show it.
    if (initSupported && !iptables.isInitialized()) {
        home.findViewById(R.id.warn_init).setVisibility(View.VISIBLE);
    }
    orwallStatus.setChecked(Preferences.isOrwallEnabled(getActivity()));
    // orWall might be deactivated. Let's test it!
    orwallStatus.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            toggleOrwall(view);
        }
    });
    // Set status switches in order to show the user what's working. Or not working.
    // Init script: try to install it and so on
    InstallScripts installScripts = new InstallScripts(getActivity());
    installScripts.run();
    boolean enforceInit = Preferences.isEnforceInitScript(getActivity());
    status_initscript.setChecked((enforceInit && initSupported));
    status_initscript.setEnabled(initSupported);
    // If init script cannot be enabled, display why
    if (!initSupported) {
        TextView explain = (TextView) home.findViewById(R.id.status_initscript_description);
        explain.setText(String.format(getString(R.string.explain_no_initscript), Iptables.DST_FILE));
        explain.setVisibility(View.VISIBLE);
    }
    // add a listener to this switch
    status_initscript.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            boolean checked = compoundButton.isChecked();
            if (checked) {
                Iptables.installInitScript(getActivity());
            } else {
                Iptables.removeIniScript(getActivity());
            }
        }
    });
    // Do we have root access ?
    if (RootCommands.rootAccessGiven()) {
        status_root.setChecked(true);
        home.findViewById(R.id.warn_root).setVisibility(View.GONE);
    } else {
        status_root.setChecked(false);
        home.findViewById(R.id.warn_root).setVisibility(View.VISIBLE);
    }
    // Hopefully there IS iptables on this device…
    if (Iptables.iptablesExists()) {
        status_iptables.setChecked(true);
        home.findViewById(R.id.warn_iptables).setVisibility(View.GONE);
        home.findViewById(R.id.status_iptables_description).setVisibility(View.GONE);
    } else {
        status_iptables.setChecked(false);
        home.findViewById(R.id.warn_iptables).setVisibility(View.VISIBLE);
        home.findViewById(R.id.status_iptables_description).setVisibility(View.VISIBLE);
    }
    status_ipt_comments.setChecked(iptables.getSupportComment());
    // Is orbot installed?
    status_orbot.setChecked(Util.isOrbotInstalled(getActivity()));
    // Shows settings
    settings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), PreferencesActivity.class);
            startActivity(intent);
        }
    });
    // Shows alert dialog with "about" stuff
    about.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            showAbout();
        }
    });
    // Start wizard
    wizard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent wizard = new Intent(getActivity(), WizardActivity.class);
            startActivity(wizard);
        }
    });
    return home;
}
Also used : PreferencesActivity(org.ethack.orwall.PreferencesActivity) Iptables(org.ethack.orwall.lib.Iptables) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) View(android.view.View) TextView(android.widget.TextView) Switch(android.widget.Switch) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) InstallScripts(org.ethack.orwall.lib.InstallScripts) WizardActivity(org.ethack.orwall.WizardActivity) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 47 with Switch

use of android.widget.Switch in project orWall by EthACKdotOrg.

the class WizardFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_wizard, container, false);
    int[] titles = { R.string.wizard_title_one, R.string.wizard_title_two, R.string.wizard_title_three };
    String title = getString(R.string.wizard_title_one);
    String step = "Step 1: ";
    if (mPageNumber < titles.length) {
        title = getString(titles[mPageNumber]);
        step = String.format(Locale.US, "Step %d: ", mPageNumber + 1);
    }
    ((TextView) rootView.findViewById(R.id.wizard_step_title)).setText(step + title);
    int[] fragments = { R.string.wizard_first, R.string.wizard_second, R.string.wizard_third };
    String fragment = getString(fragments[0]);
    if (mPageNumber < fragments.length) {
        fragment = getString(fragments[mPageNumber]);
    }
    ((TextView) rootView.findViewById(R.id.wizard_fragment_content)).setText(fragment);
    rootView.findViewById(R.id.wizard_close).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Preferences.setFirstRun(getActivity(), false);
            getActivity().finish();
        }
    });
    // Add some stuff on the very first Wizard page
    if (mPageNumber == 0) {
        ViewGroup main_content = (ViewGroup) rootView.findViewById(R.id.id_main_content);
        final Iptables iptables = new Iptables(getActivity());
        // Extract scripts
        InstallScripts installScripts = new InstallScripts(getActivity());
        installScripts.run();
        // init-script installation
        // install init as default behavior
        Iptables.installInitScript(getActivity());
        boolean enforceInit = Preferences.isEnforceInitScript(getActivity());
        boolean initSupported = Iptables.initSupported();
        Switch initScript = new Switch(getActivity());
        initScript.setChecked((enforceInit && initSupported));
        initScript.setText(getString(R.string.wizard_init_script_text));
        initScript.setEnabled(initSupported);
        initScript.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                boolean checked = compoundButton.isChecked();
                if (checked) {
                    Iptables.installInitScript(getActivity());
                } else {
                    Iptables.removeIniScript(getActivity());
                }
            }
        });
        main_content.addView(initScript);
        // Root status
        Switch rootStatus = new Switch(getActivity());
        rootStatus.setChecked(RootCommands.rootAccessGiven());
        rootStatus.setEnabled(false);
        rootStatus.setText(getString(R.string.wizard_init_root_text));
        main_content.addView(rootStatus);
        // Does iptables exist?
        Switch iptablesStatus = new Switch(getActivity());
        iptablesStatus.setChecked(Iptables.iptablesExists());
        iptablesStatus.setEnabled(false);
        iptablesStatus.setText(getString(R.string.wizard_init_iptables_text));
        main_content.addView(iptablesStatus);
        // Does current kernel support IPTables comments?
        Switch iptablesComments = new Switch(getActivity());
        iptablesComments.setChecked(iptables.getSupportComment());
        iptablesComments.setEnabled(false);
        iptablesComments.setText(getString(R.string.wizard_init_ipt_comments_text));
        main_content.addView(iptablesComments);
        // Is orbot installed?
        Switch orbotStatus = new Switch(getActivity());
        orbotStatus.setChecked(Util.isOrbotInstalled(getActivity()));
        orbotStatus.setEnabled(false);
        orbotStatus.setText(getString(R.string.wizard_orbot_status_text));
        main_content.addView(orbotStatus);
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) Iptables(org.ethack.orwall.lib.Iptables) TextView(android.widget.TextView) View(android.view.View) Switch(android.widget.Switch) InstallScripts(org.ethack.orwall.lib.InstallScripts) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 48 with Switch

use of android.widget.Switch in project android_frameworks_base by ParanoidAndroid.

the class SwitchPreference method onBindView.

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    View checkableView = view.findViewById(com.android.internal.R.id.switchWidget);
    if (checkableView != null && checkableView instanceof Checkable) {
        ((Checkable) checkableView).setChecked(mChecked);
        sendAccessibilityEvent(checkableView);
        if (checkableView instanceof Switch) {
            final Switch switchView = (Switch) checkableView;
            switchView.setTextOn(mSwitchOn);
            switchView.setTextOff(mSwitchOff);
            switchView.setOnCheckedChangeListener(mListener);
        }
    }
    syncSummaryView(view);
}
Also used : Switch(android.widget.Switch) Checkable(android.widget.Checkable) View(android.view.View)

Example 49 with Switch

use of android.widget.Switch in project android_frameworks_base by DirtyUnicorns.

the class ElementLayoutActivity method createSwitch.

private void createSwitch() {
    Switch button = new Switch(this);
    button.setChecked(mRandom.nextBoolean());
    mLayout.addView(button);
}
Also used : Switch(android.widget.Switch)

Example 50 with Switch

use of android.widget.Switch in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsDialogPreference method configureLayoutForView.

private View configureLayoutForView(LinearLayout view) {
    JSONObject settingsJson = null;
    String[] settingsArray = new String[0], settingsValues = new String[0], summaryArray = new String[0];
    String typeString = mType.toString();
    switch(mChannel) {
        case BLOGS:
            settingsJson = JSONUtils.queryJSON(mSettings.getBlogSettings().get(mBlogId), typeString, new JSONObject());
            settingsArray = getContext().getResources().getStringArray(R.array.notifications_blog_settings);
            settingsValues = getContext().getResources().getStringArray(R.array.notifications_blog_settings_values);
            break;
        case OTHER:
            settingsJson = JSONUtils.queryJSON(mSettings.getOtherSettings(), typeString, new JSONObject());
            settingsArray = getContext().getResources().getStringArray(R.array.notifications_other_settings);
            settingsValues = getContext().getResources().getStringArray(R.array.notifications_other_settings_values);
            break;
        case DOTCOM:
            settingsJson = mSettings.getDotcomSettings();
            settingsArray = getContext().getResources().getStringArray(R.array.notifications_wpcom_settings);
            settingsValues = getContext().getResources().getStringArray(R.array.notifications_wpcom_settings_values);
            summaryArray = getContext().getResources().getStringArray(R.array.notifications_wpcom_settings_summaries);
            break;
    }
    if (settingsJson != null && settingsArray.length == settingsValues.length) {
        for (int i = 0; i < settingsArray.length; i++) {
            String settingName = settingsArray[i];
            String settingValue = settingsValues[i];
            // Skip a few settings for 'Email' section
            if (mType == Type.EMAIL && settingValue.equals(SETTING_VALUE_ACHIEVEMENT)) {
                continue;
            }
            View commentsSetting = View.inflate(getContext(), R.layout.notifications_settings_switch, null);
            TextView title = (TextView) commentsSetting.findViewById(R.id.notifications_switch_title);
            title.setText(settingName);
            // Add special summary text for the DOTCOM section
            if (mChannel == Channel.DOTCOM && i < summaryArray.length) {
                String summaryText = summaryArray[i];
                TextView summary = (TextView) commentsSetting.findViewById(R.id.notifications_switch_summary);
                summary.setVisibility(View.VISIBLE);
                summary.setText(summaryText);
            }
            Switch toggleSwitch = (Switch) commentsSetting.findViewById(R.id.notifications_switch);
            toggleSwitch.setChecked(JSONUtils.queryJSON(settingsJson, settingValue, true));
            toggleSwitch.setTag(settingValue);
            toggleSwitch.setOnCheckedChangeListener(mOnCheckedChangedListener);
            view.addView(commentsSetting);
        }
    }
    return view;
}
Also used : JSONObject(org.json.JSONObject) Switch(android.widget.Switch) TextView(android.widget.TextView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View)

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