Search in sources :

Example 16 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project xabber-android by redsolution.

the class AccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent intent = getIntent();
    account = getAccount(intent);
    if (account == null) {
        LogManager.i(LOG_TAG, "Account is null, finishing!");
        finish();
        return;
    }
    accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
        finish();
        return;
    }
    if (ACTION_CONNECTION_SETTINGS.equals(intent.getAction())) {
        isConnectionSettingsAction = true;
        startAccountSettingsActivity();
        setIntent(null);
    }
    setContentView(R.layout.activity_account);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(AccountActivity.this);
        }
    });
    toolbar.setTitle(R.string.contact_account);
    toolbar.inflateMenu(R.menu.toolbar_account);
    MenuItem item = toolbar.getMenu().findItem(R.id.action_account_switch);
    switchCompat = (SwitchCompat) item.getActionView().findViewById(R.id.account_switch_view);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AccountManager.getInstance().setEnabled(accountItem.getAccount(), isChecked);
        }
    });
    barPainter = new BarPainter(this, toolbar);
    UserJid fakeAccountUser;
    try {
        fakeAccountUser = UserJid.from(account.getFullJid().asBareJid());
    } catch (UserJid.UserJidCreateException e) {
        throw new IllegalStateException();
    }
    bestContact = RosterManager.getInstance().getBestContact(account, fakeAccountUser);
    contactTitleView = findViewById(R.id.contact_title_expanded);
    statusIcon = findViewById(R.id.ivStatus);
    statusText = (TextView) findViewById(R.id.status_text);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.account_options_recycler_view);
    accountOptionsAdapter = new AccountOptionsAdapter(AccountOption.values(), this, accountItem);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(accountOptionsAdapter);
    recyclerView.setNestedScrollingEnabled(false);
    Fragment fragmentById = getFragmentManager().findFragmentById(R.id.account_fragment_container);
    if (fragmentById == null) {
        getFragmentManager().beginTransaction().add(R.id.account_fragment_container, ContactVcardViewerFragment.newInstance(account)).commit();
    }
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent) MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ContactVcardViewerFragment(com.xabber.android.ui.fragment.ContactVcardViewerFragment) Fragment(android.app.Fragment) BarPainter(com.xabber.android.ui.color.BarPainter) AccountOptionsAdapter(com.xabber.android.ui.adapter.accountoptions.AccountOptionsAdapter) RecyclerView(android.support.v7.widget.RecyclerView) CompoundButton(android.widget.CompoundButton) Toolbar(android.support.v7.widget.Toolbar)

Example 17 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project Shuttle by timusus.

the class EqualizerFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_equalizer, container, false);
    unbinder = ButterKnife.bind(this, rootView);
    toolbar.inflateMenu(R.menu.menu_equalizer);
    toolbar.setNavigationOnClickListener(v -> getNavigationController().popViewController());
    toolbar.setOnMenuItemClickListener(this);
    MenuItem item = toolbar.getMenu().findItem(R.id.action_equalizer);
    SwitchCompat switchItem = (SwitchCompat) item.getActionView();
    boolean isEnabled = prefs.getBoolean("audiofx.global.enable", false);
    switchItem.setChecked(isEnabled);
    switchItem.setOnCheckedChangeListener(this);
    // Hide the 'open DSP' button if DSP/Other audio effects aren't available
    final Intent intent = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    if (ShuttleApplication.getInstance().getPackageManager().resolveActivity(intent, 0) == null) {
        MenuItem openDSPItem = toolbar.getMenu().findItem(R.id.menu_dsp);
        if (openDSPItem != null) {
            openDSPItem.setVisible(false);
        }
    }
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            eqPreset = position;
            equalizerSetPreset(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    setupPresets();
    if (spinnerAdapter != null && spinnerAdapter.getCount() > eqPreset) {
        spinner.setSelection(eqPreset);
    }
    // Initialize the equalizer elements
    numberEqualizerBands = Integer.parseInt(prefs.getString("equalizer.number_of_bands", "5"));
    final int[] centerFreqs = getCenterFreqs();
    final int[] bandLevelRange = getBandLevelRange();
    for (int band = 0; band < numberEqualizerBands; band++) {
        // Unit conversion from mHz to Hz and use k prefix if necessary to display
        float centerFreqHz = centerFreqs[band] / 1000;
        String unitPrefix = "";
        if (centerFreqHz >= 1000) {
            centerFreqHz = centerFreqHz / 1000;
            unitPrefix = "k";
        }
        (eqContainer.findViewById(eqViewElementIds[band][0])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewTextElementIds[band][0])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewElementIds[band][1])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewTextElementIds[band][1])).setVisibility(View.VISIBLE);
        ((TextView) eqContainer.findViewById(eqViewElementIds[band][0])).setText(format("%.0f ", centerFreqHz) + unitPrefix + "Hz");
        mEqualizerSeekBar[band] = eqContainer.findViewById(eqViewElementIds[band][1]);
        mEqualizerSeekBar[band].setMax((bandLevelRange[1] / 100) - (bandLevelRange[0] / 100));
        mEqualizerSeekBar[band].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                if (fromUser) {
                    // Determine which band changed
                    int seekbarId = seekBar.getId();
                    int band = 0;
                    for (int i = 0; i < eqViewElementIds.length; i++) {
                        if (eqViewElementIds[i][1] == seekbarId) {
                            band = i;
                        }
                    }
                    if (eqPreset != eqCustomPresetPosition) {
                        equalizerCopyToCustom();
                        if (spinnerAdapter != null && spinnerAdapter.getCount() > eqCustomPresetPosition) {
                            spinner.setSelection(eqCustomPresetPosition);
                        }
                    } else {
                        int level = getBandLevelRange()[0] + (progress * 100);
                        equalizerBandUpdate(band, level);
                    }
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                MusicUtils.updateEqualizer();
            }
        });
    }
    // Set the SeekBar listener.
    if (bassBoostSupported) {
        baseBoostSeekbar.setMax(OpenSLESConstants.BASSBOOST_MAX_STRENGTH - OpenSLESConstants.BASSBOOST_MIN_STRENGTH);
        baseBoostSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                // set parameter and state
                if (fromUser) {
                    prefs.edit().putBoolean("audiofx.bass.enable", true).apply();
                    prefs.edit().putString("audiofx.bass.strength", String.valueOf(progress)).apply();
                    MusicUtils.updateEqualizer();
                }
            }

            // If slider pos was 0 when starting re-enable effect
            @Override
            public void onStartTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    prefs.edit().putBoolean("audiofx.bass.enable", true).apply();
                    MusicUtils.updateEqualizer();
                }
            }

            // If slider pos = 0 when stopping disable effect
            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    // disable
                    prefs.edit().putBoolean("audiofx.bass.enable", false).apply();
                    MusicUtils.updateEqualizer();
                }
            }
        });
    }
    // Set the SeekBar listener.
    if (virtualizerSupported) {
        virtualizerSeekbar.setMax(OpenSLESConstants.VIRTUALIZER_MAX_STRENGTH - OpenSLESConstants.VIRTUALIZER_MIN_STRENGTH);
        virtualizerSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                // set parameter and state
                if (fromUser) {
                    prefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
                    prefs.edit().putString("audiofx.virtualizer.strength", String.valueOf(progress)).apply();
                    MusicUtils.updateEqualizer();
                }
            }

            // If slider pos was 0 when starting re-enable effect
            @Override
            public void onStartTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    prefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
                    MusicUtils.updateEqualizer();
                }
            }

            // If slider pos = 0 when stopping disable effect
            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    // disable
                    prefs.edit().putBoolean("audiofx.virtualizer.enable", false).apply();
                    MusicUtils.updateEqualizer();
                }
            }
        });
    }
    return rootView;
}
Also used : SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) SeekBar(android.widget.SeekBar) MenuItem(android.view.MenuItem) Intent(android.content.Intent) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat) Nullable(android.support.annotation.Nullable)

Example 18 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project Shuttle by timusus.

the class TintHelper method setTintAuto.

@SuppressWarnings("deprecation")
@SuppressLint("PrivateResource")
static void setTintAuto(@NonNull final View view, @ColorInt final int color, boolean background, final boolean isDark) {
    if (!background) {
        if (view instanceof RadioButton) {
            setTint((RadioButton) view, color, isDark);
        } else if (view instanceof SeekBar) {
            setTint((SeekBar) view, color, isDark);
        } else if (view instanceof ProgressBar) {
            setTint((ProgressBar) view, color);
        } else if (view instanceof EditText) {
            setTint((EditText) view, color, isDark);
        } else if (view instanceof CheckBox) {
            setTint((CheckBox) view, color, isDark);
        } else if (view instanceof ImageView) {
            setTint((ImageView) view, color);
        } else if (view instanceof Switch) {
            setTint((Switch) view, color, isDark);
        } else if (view instanceof SwitchCompat) {
            setTint((SwitchCompat) view, color, isDark);
        } else {
            background = true;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !background && view.getBackground() instanceof RippleDrawable) {
            // Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
            RippleDrawable rd = (RippleDrawable) view.getBackground();
            final int unchecked = ContextCompat.getColor(view.getContext(), isDark ? R.color.ripple_material_dark : R.color.ripple_material_light);
            final int checked = Util.adjustAlpha(color, 0.4f);
            final ColorStateList sl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_activated, -android.R.attr.state_checked }, new int[] { android.R.attr.state_activated }, new int[] { android.R.attr.state_checked } }, new int[] { unchecked, checked, checked });
            rd.setColor(sl);
        }
    }
    if (background) {
        // Need to tint the background of a view
        if (view instanceof FloatingActionButton || view instanceof Button) {
            setTintSelector(view, color, false, isDark);
        } else if (view.getBackground() != null) {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                if (view instanceof TextInputEditText) {
                    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                } else {
                    drawable = createTintedDrawable(drawable, color);
                    Util.setBackgroundCompat(view, drawable);
                }
            }
        }
    }
}
Also used : TextInputEditText(android.support.design.widget.TextInputEditText) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable) Switch(android.widget.Switch) RadioButton(android.widget.RadioButton) Button(android.widget.Button) FloatingActionButton(android.support.design.widget.FloatingActionButton) CheckBox(android.widget.CheckBox) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextInputEditText(android.support.design.widget.TextInputEditText) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) SwitchCompat(android.support.v7.widget.SwitchCompat) SuppressLint(android.annotation.SuppressLint)

Example 19 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project ahbottomnavigation by aurelhubert.

the class DemoFragment method initDemoSettings.

/**
	 * Init demo settings
	 */
private void initDemoSettings(View view) {
    final DemoActivity demoActivity = (DemoActivity) getActivity();
    final SwitchCompat switchColored = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_colored);
    final SwitchCompat switchFiveItems = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_five_items);
    final SwitchCompat showHideBottomNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_show_hide);
    final SwitchCompat showSelectedBackground = (SwitchCompat) view.findViewById(R.id.fragment_demo_selected_background);
    final SwitchCompat switchForceTitleHide = (SwitchCompat) view.findViewById(R.id.fragment_demo_force_title_hide);
    final SwitchCompat switchTranslucentNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_translucent_navigation);
    switchColored.setChecked(demoActivity.isBottomNavigationColored());
    switchFiveItems.setChecked(demoActivity.getBottomNavigationNbItems() == 5);
    switchTranslucentNavigation.setChecked(getActivity().getSharedPreferences("shared", Context.MODE_PRIVATE).getBoolean("translucentNavigation", false));
    switchTranslucentNavigation.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? View.VISIBLE : View.GONE);
    switchTranslucentNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            getActivity().getSharedPreferences("shared", Context.MODE_PRIVATE).edit().putBoolean("translucentNavigation", isChecked).apply();
            demoActivity.reload();
        }
    });
    switchColored.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            demoActivity.updateBottomNavigationColor(isChecked);
        }
    });
    switchFiveItems.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            demoActivity.updateBottomNavigationItems(isChecked);
        }
    });
    showHideBottomNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            demoActivity.showOrHideBottomNavigation(isChecked);
        }
    });
    showSelectedBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            demoActivity.updateSelectedBackgroundVisibility(isChecked);
        }
    });
    switchForceTitleHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            demoActivity.setForceTitleHide(isChecked);
        }
    });
}
Also used : CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 20 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project fresco by facebook.

the class ImageFormatColorFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mSimpleDraweeView1 = (SimpleDraweeView) view.findViewById(R.id.drawee1);
    mSimpleDraweeView2 = (SimpleDraweeView) view.findViewById(R.id.drawee2);
    // Set a simple custom color resource as the image.
    // The format of custom_color1 is <color>#rrggbb</color>
    mSimpleDraweeView1.setImageURI(UriUtil.getUriForResourceId(R.raw.custom_color1));
    mSimpleDraweeView2.setImageURI(UriUtil.getUriForResourceId(R.raw.custom_color2));
    final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background);
    switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSimpleDraweeView1.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
            mSimpleDraweeView2.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
        }
    });
    SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.decoder_switch);
    switchCompat.setChecked(CustomImageFormatConfigurator.isGlobalColorDecoderEnabled(getContext()));
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            CustomImageFormatConfigurator.setGlobalColorDecoderEnabled(getContext(), isChecked);
        }
    });
}
Also used : CheckerBoardDrawable(com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

SwitchCompat (android.support.v7.widget.SwitchCompat)33 TextView (android.widget.TextView)25 View (android.view.View)24 CompoundButton (android.widget.CompoundButton)20 Intent (android.content.Intent)10 AlertDialog (android.support.v7.app.AlertDialog)8 ImageView (android.widget.ImageView)8 DialogInterface (android.content.DialogInterface)7 CardView (android.support.v7.widget.CardView)6 MenuItem (android.view.MenuItem)6 ScrollView (android.widget.ScrollView)6 AdapterView (android.widget.AdapterView)5 LinearLayout (android.widget.LinearLayout)5 SeekBar (android.widget.SeekBar)5 SearchView (android.support.v7.widget.SearchView)4 Button (android.widget.Button)4 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)4 ArrayList (java.util.ArrayList)4 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3 Uri (android.net.Uri)3