Search in sources :

Example 1 with Switch

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

the class InputMethodManagerService method showInputMethodMenuInternal.

private void showInputMethodMenuInternal(boolean showSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu");
    final Context context = getUiContext();
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mImListManager.getSortedInputMethodAndSubtypeList(showSubtypes, mInputShown, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final TypedArray a = context.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        mDialogBuilder = new AlertDialog.Builder(context).setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        }).setIcon(a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogTitle));
        a.recycle();
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerService.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = ((Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch));
        hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mWindowManagerService.setHardKeyboardEnabled(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, com.android.internal.R.layout.simple_list_item_2_single_choice, imList, checkedItem);
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if ((subtypeId < 0) || (subtypeId >= im.getSubtypeCount())) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        });
        if (showSubtypes && !isScreenLocked) {
            mDialogBuilder.setPositiveButton(com.android.internal.R.string.configure_input_methods, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    showConfigureInputMethods();
                }
            });
        }
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        mSwitchingDialog.show();
    }
}
Also used : IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) AlertDialog(android.app.AlertDialog) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) DialogInterface(android.content.DialogInterface) View(android.view.View) TextView(android.widget.TextView) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Switch(android.widget.Switch) TypedArray(android.content.res.TypedArray) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) List(java.util.List) CompoundButton(android.widget.CompoundButton) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 2 with Switch

use of android.widget.Switch in project PushSms by koush.

the class MyActivity method onCreate.

/**
     * Called when the activity is first created.
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    accounts = getSharedPreferences("accounts", MODE_PRIVATE);
    settings = getSharedPreferences("settings", MODE_PRIVATE);
    ListView lv = (ListView) findViewById(R.id.list);
    View header = getLayoutInflater().inflate(R.layout.header, null);
    lv.addHeaderView(header);
    lv.setAdapter(accountAdapter = new AccountAdapter());
    final Switch toggle = (Switch) header.findViewById(R.id.toggle);
    toggle.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            settings.edit().putBoolean("enabled", toggle.isChecked()).commit();
        }
    });
    toggle.setChecked(settings.getBoolean("enabled", true));
    final Button phoneNumber = (Button) header.findViewById(R.id.phone_number);
    phoneNumber.setText(getNumber());
    phoneNumber.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final EditText input = new EditText(MyActivity.this);
            new AlertDialog.Builder(MyActivity.this).setTitle(R.string.phone_number).setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    settings.edit().putString("phone_number", input.getText().toString()).commit();
                    phoneNumber.setText(getNumber());
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                // Do nothing.
                }
            }).show();
        }
    });
    for (Account account : AccountManager.get(this).getAccountsByType("com.google")) {
        accountAdapter.add(account);
    }
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckedTextView tv = (CheckedTextView) view.findViewById(android.R.id.text1);
            Account account = accountAdapter.getItem((int) id);
            if (tv.isChecked()) {
                accounts.edit().putBoolean(account.name, false).commit();
                tv.toggle();
                reregister();
                return;
            }
            login(account.name);
        }
    });
    startService(new Intent(this, MiddlewareService.class));
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new Thread() {

                @Override
                public void run() {
                    try {
                        GoogleCloudMessaging.getInstance(MyActivity.this).unregister();
                    } catch (Exception e) {
                    }
                }
            }.start();
        }
    });
}
Also used : EditText(android.widget.EditText) Account(android.accounts.Account) DialogInterface(android.content.DialogInterface) CheckedTextView(android.widget.CheckedTextView) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) GoogleAuthException(com.google.android.gms.auth.GoogleAuthException) UserRecoverableAuthException(com.google.android.gms.auth.UserRecoverableAuthException) GooglePlayServicesAvailabilityException(com.google.android.gms.auth.GooglePlayServicesAvailabilityException) IOException(java.io.IOException) ListView(android.widget.ListView) Switch(android.widget.Switch) Button(android.widget.Button) AdapterView(android.widget.AdapterView)

Example 3 with Switch

use of android.widget.Switch in project android-uploader by nightscout.

the class CustomSwitchPreference method clearListenerInViewGroup.

/**
     * Clear listener in Switch for specify ViewGroup.
     *
     * @param viewGroup The ViewGroup that will need to clear the listener.
     */
private void clearListenerInViewGroup(ViewGroup viewGroup) {
    if (null == viewGroup) {
        return;
    }
    int count = viewGroup.getChildCount();
    for (int n = 0; n < count; ++n) {
        View childView = viewGroup.getChildAt(n);
        if (childView instanceof Switch) {
            final Switch switchView = (Switch) childView;
            switchView.setOnCheckedChangeListener(null);
            return;
        } else if (childView instanceof ViewGroup) {
            ViewGroup childGroup = (ViewGroup) childView;
            clearListenerInViewGroup(childGroup);
        }
    }
}
Also used : Switch(android.widget.Switch) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 4 with Switch

use of android.widget.Switch in project Android-Material-Examples by saulmm.

the class ColorActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the saved theme
    sharedpreferences = getSharedPreferences("test", Context.MODE_PRIVATE);
    setTheme(sharedpreferences.getInt("theme", R.style.AppTheme));
    setContentView(R.layout.activity_color);
    // Views
    Switch themeSwitch = (Switch) findViewById(R.id.theme_switch);
    themeSwitch.setChecked(sharedpreferences.getBoolean(themeSwitch.getId() + "", false));
    themeSwitch.setOnCheckedChangeListener(checkedListener);
    CheckBox themeCheck = (CheckBox) findViewById(R.id.theme_check);
    themeCheck.setChecked(sharedpreferences.getBoolean(themeCheck.getId() + "", false));
    themeCheck.setOnCheckedChangeListener(checkedListener);
    revealView = findViewById(R.id.reveal_view);
    // Show the unReveal effect
    final int cx = sharedpreferences.getInt("x", 0);
    final int cy = sharedpreferences.getInt("y", 0);
    startHideRevealEffect(cx, cy);
}
Also used : Switch(android.widget.Switch) CheckBox(android.widget.CheckBox)

Example 5 with Switch

use of android.widget.Switch in project platform_frameworks_base by android.

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));
    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));
        }
    });
}
Also used : Switch(android.widget.Switch) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Switch (android.widget.Switch)54 View (android.view.View)29 TextView (android.widget.TextView)18 CompoundButton (android.widget.CompoundButton)17 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 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)6 JSONObject (org.json.JSONObject)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 Intent (android.content.Intent)5 Drawable (android.graphics.drawable.Drawable)5 LocaleList (android.os.LocaleList)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5