androidx.appcompat.widget.SwitchCompat Java Examples

The following examples show how to use androidx.appcompat.widget.SwitchCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FindReplace.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
protected void assignBooleanSwitch(final APDE context, final String key, final boolean defaultValue, final SwitchCompat switchCompat, final MutableBoolean value, final CompoundButton.OnCheckedChangeListener listener) {
	boolean savedValue = getPreferences(context).getBoolean(key, defaultValue);
	value.set(savedValue);
	switchCompat.setChecked(savedValue);
	
	switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			value.set(isChecked);
			
			getPreferences(context).edit().putBoolean(key, value.get()).commit();
			
			if (listener != null) {
				listener.onCheckedChanged(buttonView, isChecked);
			}
		}
	});
}
 
Example #2
Source File: SliderContinuousDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void setUpSlider(
    View view,
    @IdRes int switchId,
    @IdRes int sliderId,
    @IdRes int valueId,
    final String valueFormat) {
  final TextView sliderValue = view.findViewById(valueId);
  final Slider slider = view.findViewById(sliderId);
  slider.addOnChangeListener(
      (slider1, value, fromUser) -> sliderValue.setText(String.format(valueFormat, value)));
  slider.setValue(slider.getValueFrom());
  SwitchCompat switchButton = view.findViewById(switchId);
  switchButton.setOnCheckedChangeListener(
      (buttonView, isChecked) -> slider.setEnabled(isChecked));
  switchButton.setChecked(true);
}
 
Example #3
Source File: AnnotationTab.java    From ssj with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param id    int
 * @param value boolean
 * @return boolean
 */
public boolean toggleAnnoButton(int id, final boolean value)
{
    if (annoClassList == null || activity == null || !running)
    {
        return false;
    }
    final LinearLayout anno = (LinearLayout) annoClassList.getChildAt(id);
    if (anno == null)
    {
        return false;
    }
    activity.runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            SwitchCompat button = (SwitchCompat) ((LinearLayout)anno.getChildAt(1)).getChildAt(0);
            if (button.isEnabled())
                button.setChecked(value);
        }
    });
    return true;
}
 
Example #4
Source File: AnnotationTab.java    From ssj with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
void startAnnotation()
{
    syncWithModel();
    enableComponents(false);
    running = true;

    activity.runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            //activate buttons
            for (int i = 0; i < annoClassList.getChildCount(); i++)
            {
                SwitchCompat button = (SwitchCompat) ((LinearLayout)((LinearLayout)(annoClassList.getChildAt(i))).getChildAt(1)).getChildAt(0);
                button.setEnabled(true);
            }
        }
    });
}
 
Example #5
Source File: DragSwipeListActivity.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
    mRecyclerView.addHeaderView(mHeaderView);

    SwitchCompat switchCompat = mHeaderView.findViewById(R.id.switch_compat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // 控制是否可以侧滑删除。
            mRecyclerView.setItemViewSwipeEnabled(isChecked);
        }
    });

    mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
    mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。
}
 
Example #6
Source File: DragGridActivity.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
    mRecyclerView.addHeaderView(mHeaderView);

    SwitchCompat switchCompat = mHeaderView.findViewById(R.id.switch_compat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mRecyclerView.setItemViewSwipeEnabled(isChecked);
        }
    });

    mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
    mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。
}
 
Example #7
Source File: SwitcherFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
                         @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_switcher, container, false);

    String title = getArguments().getString(INTENT_TITLE);
    String summary = getArguments().getString(INTENT_SUMMARY);
    boolean checked = getArguments().getBoolean(INTENT_CHECKED);

    ((TextView) view.findViewById(R.id.title)).setText(title);
    ((TextView) view.findViewById(R.id.summary)).setText(summary);
    SwitchCompat mSwitch = view.findViewById(R.id.switcher);
    mSwitch.setChecked(checked);
    mSwitch.setOnCheckedChangeListener(mOnCheckedChangeListener);
    return view;
}
 
Example #8
Source File: DefineActivity.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View header = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
    mRecyclerView.addHeaderView(header);

    SwitchCompat switchCompat = header.findViewById(R.id.switch_compat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // 控制是否可以侧滑删除。
            mRecyclerView.setItemViewSwipeEnabled(isChecked);
        }
    });

    mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
    mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。

    // 自定义拖拽控制参数。
    mRecyclerView.setOnItemMovementListener(mItemMovementListener);
}
 
Example #9
Source File: SwitcherFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_switcher, container, false);
    if (mTitle != null) {
        ((TextView) view.findViewById(R.id.title)).setText(mTitle);
    }
    if (mSummary != null) {
        ((TextView) view.findViewById(R.id.summary)).setText(mSummary);
    }
    SwitchCompat mSwitch = view.findViewById(R.id.switcher);
    mSwitch.setChecked(mChecked);
    mSwitch.setOnCheckedChangeListener(mOnCheckedChangeListener);
    return view;
}
 
Example #10
Source File: MainActivity.java    From Torchie-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setTitle("");

    but_flash = (ImageButton) findViewById(R.id.but_flash_pto);
    sw_func_toggle = (SwitchCompat) findViewById(R.id.sw_func_toggle);

    transAnimButFlash = (TransitionDrawable) but_flash.getBackground();
    transAnimButFlash.resetTransition();

    if (SettingsUtils.isFirstTime(this)) {
        this.showDialogWelcome();
    }
}
 
Example #11
Source File: SettingsActivity.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
@Override
public void initView() {
    RelativeLayout headerLayout = findViewById(R.id.rl_setting_header);
    account = findViewById(R.id.tv_setting_account);
    nick = findViewById(R.id.tv_tv_setting_nick);
    avatar = findViewById(R.id.riv_setting_avatar);
    SwitchCompat notification = findViewById(R.id.sc_activity_settings_notify);
    RelativeLayout clear = findViewById(R.id.rl_activity_settings_clear);
    RelativeLayout accountManage = findViewById(R.id.rl_activity_settings_account_manage);
    Button logout = findViewById(R.id.btn_setting_logout);
    headerLayout.setOnClickListener(this);
    clear.setOnClickListener(this);
    accountManage.setOnClickListener(this);
    logout.setOnClickListener(this);
    notification.setOnCheckedChangeListener(this);

}
 
Example #12
Source File: ActivityLog.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("log".equals(name)) {
        // Get enabled
        boolean log = prefs.getBoolean(name, false);

        // Display disabled warning
        TextView tvDisabled = findViewById(R.id.tvDisabled);
        tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);

        // Check switch state
        SwitchCompat swEnabled = getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
        if (swEnabled.isChecked() != log)
            swEnabled.setChecked(log);

        ServiceSinkhole.reload("changed " + name, ActivityLog.this, false);
    }
}
 
Example #13
Source File: UserFeedbackView.java    From applivery-android-sdk with Apache License 2.0 6 votes vote down vote up
private void initViewElements(View view) {

        cancelButton = (ImageButton) view.findViewById(R.id.applivery_feedback_cancel_button);
        okButton = (ImageButton) view.findViewById(R.id.applivery_feedback_ok_button);
        sendButton = (ImageButton) view.findViewById(R.id.applivery_feedback_send_button);
        feedbackButton = (LinearLayout) view.findViewById(R.id.applivery_tab_button_selector_feedback);
        bugButton = (LinearLayout) view.findViewById(R.id.applivery_tab_button_selector_bug);
        screenshot = (DrawingImageView) view.findViewById(R.id.appliveryScreenShot);
        feedbackImage = (ImageView) view.findViewById(R.id.applivery_feedback_image);
        feedbackMessage = (AppCompatEditText) view.findViewById(R.id.applivery_feedback_description);
        screenShotSwitch = (SwitchCompat) view.findViewById(R.id.attach_screenshot_switch);

        initViewState();

        initElementActions();
    }
 
Example #14
Source File: OptionsFragment.java    From chromadoze with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.options_fragment, container, false);

    mMinVolSeek = (SeekBar) v.findViewById(R.id.MinVolSeek);
    mMinVolText = (TextView) v.findViewById(R.id.MinVolText);
    mPeriodSeek = (SeekBar) v.findViewById(R.id.PeriodSeek);
    mPeriodText = (TextView) v.findViewById(R.id.PeriodText);

    mAutoPlayCheck = (SwitchCompat) v.findViewById(R.id.AutoPlayCheck);

    mIgnoreAudioFocusCheck = (SwitchCompat) v.findViewById(R.id.IgnoreAudioFocusCheck);
    mVolumeLimitCheck = (SwitchCompat) v.findViewById(R.id.VolumeLimitCheck);
    mVolumeLimitSeek = (SeekBar) v.findViewById(R.id.VolumeLimitSeek);

    return v;
}
 
Example #15
Source File: ImageFormatKeyframesFragment.java    From fresco with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
private void initAnimation(View view) {
  mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
  mSimpleDraweeView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  DraweeController controller =
      Fresco.newDraweeControllerBuilder()
          .setOldController(mSimpleDraweeView.getController())
          .setUri(sampleUris().createKeyframesUri())
          .setAutoPlayAnimations(true)
          .build();
  mSimpleDraweeView.setController(controller);

  final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background);
  switchBackground.setOnCheckedChangeListener(
      new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          mSimpleDraweeView
              .getHierarchy()
              .setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
        }
      });
}
 
Example #16
Source File: ActivityLog.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("log".equals(name)) {
        // Get enabled
        boolean log = prefs.getBoolean(name, false);

        // Display disabled warning
        TextView tvDisabled = findViewById(R.id.tvDisabled);
        tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);

        // Check switch state
        SwitchCompat swEnabled = getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
        if (swEnabled.isChecked() != log)
            swEnabled.setChecked(log);

        ServiceSinkhole.reload("changed " + name, ActivityLog.this, false);
    }
}
 
Example #17
Source File: FetchPreferencesActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fetch_preferences);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.fetch_preferences_menu);

    noContentView = findViewById(R.id.no_content_frame);

    boolean fetchEnabled = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getResources().getString(R.string.dataFetchEnabledKey), getResources().getBoolean(R.bool.dataFetchEnabledDefaultValue));

    SwitchCompat dataEnabledSwitch = (SwitchCompat) toolbar.findViewById(R.id.toolbar_switch);
    dataEnabledSwitch.setChecked(fetchEnabled);
    dataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PreferenceManager.getDefaultSharedPreferences(FetchPreferencesActivity.this).edit().putBoolean(getResources().getString(R.string.dataFetchEnabledKey), isChecked).commit();
            updateView(isChecked);
        }
    });

    updateView(fetchEnabled);

    getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, preference).commit();
}
 
Example #18
Source File: SwitchPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
/**
 * Adapts the preference's switch, depending on the preference's properties and on whether it is
 * currently checked or not.
 *
 * @param viewHolder
 *         The preference' view holder as an instance of the class {@link PreferenceViewHolder}.
 *         The view holder may not be null
 */
private void adaptSwitch(@NonNull final PreferenceViewHolder viewHolder) {
    View view = viewHolder.findViewById(R.id.compound_button);

    if (view instanceof SwitchCompat) {
        SwitchCompat switchWidget = (SwitchCompat) view;
        switchWidget.setTextOn(getSwitchTextOn());
        switchWidget.setTextOff(getSwitchTextOff());
        switchWidget.setShowText(!TextUtils.isEmpty(getSwitchTextOn()) ||
                !TextUtils.isEmpty(getSwitchTextOff()));
    }
}
 
Example #19
Source File: RunStopIndicatorPopupWindow.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
RunStopIndicatorPopupWindow(final DataWrapper dataWrapper, final Activity activity) {
    super(R.layout.popup_window_run_stop_indicator, R.string.editor_activity_targetHelps_trafficLightIcon_title, activity);

    // Disable default animation
    //setAnimationStyle(0);

    final TextView textView = popupView.findViewById(R.id.run_stop_indicator_popup_window_important_info);
    textView.setClickable(true);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intentLaunch = new Intent(activity, ImportantInfoActivity.class);
            intentLaunch.putExtra(ImportantInfoActivity.EXTRA_SHOW_QUICK_GUIDE, false);
            intentLaunch.putExtra(ImportantInfoActivity.EXTRA_SCROLL_TO, R.id.activity_info_notification_event_not_started);
            activity.startActivity(intentLaunch);

            dismiss();
        }
    });

    final SwitchCompat checkBox = popupView.findViewById(R.id.run_stop_indicator_popup_window_checkbox);
    checkBox.setChecked(Event.getGlobalEventsRunning());
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (dataWrapper != null)
                dataWrapper.runStopEventsWithAlert(activity, checkBox, isChecked);
        }
    });
}
 
Example #20
Source File: Settings.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    SettingItem item = (SettingItem)mAdapter.getItem(position);
    item.onClick(view);
    mRequestingPosition = position;
    if(item.mType == SettingItem.TYPE_SWITCH) {
        boolean value = (boolean)item.getValue();
        if(view!=null) {
            SwitchCompat sc = (SwitchCompat) view.getTag();
            sc.setChecked(value);
        }            
        handleSwitchOption(item.mId, value);
    }
}
 
Example #21
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InflateParams")
public GalleryMenuHelper(Context context) {
    mView = LayoutInflater.from(context).inflate(R.layout.dialog_gallery_menu, null);
    mScreenRotation = (Spinner) mView.findViewById(R.id.screen_rotation);
    mReadingDirection = (Spinner) mView.findViewById(R.id.reading_direction);
    mScaleMode = (Spinner) mView.findViewById(R.id.page_scaling);
    mStartPosition = (Spinner) mView.findViewById(R.id.start_position);
    mKeepScreenOn = (SwitchCompat) mView.findViewById(R.id.keep_screen_on);
    mShowClock = (SwitchCompat) mView.findViewById(R.id.show_clock);
    mShowProgress = (SwitchCompat) mView.findViewById(R.id.show_progress);
    mShowBattery = (SwitchCompat) mView.findViewById(R.id.show_battery);
    mShowPageInterval = (SwitchCompat) mView.findViewById(R.id.show_page_interval);
    mVolumePage = (SwitchCompat) mView.findViewById(R.id.volume_page);
    mReadingFullscreen = (SwitchCompat) mView.findViewById(R.id.reading_fullscreen);
    mCustomScreenLightness = (SwitchCompat) mView.findViewById(R.id.custom_screen_lightness);
    mScreenLightness = (SeekBar) mView.findViewById(R.id.screen_lightness);

    mScreenRotation.setSelection(Settings.getScreenRotation());
    mReadingDirection.setSelection(Settings.getReadingDirection());
    mScaleMode.setSelection(Settings.getPageScaling());
    mStartPosition.setSelection(Settings.getStartPosition());
    mKeepScreenOn.setChecked(Settings.getKeepScreenOn());
    mShowClock.setChecked(Settings.getShowClock());
    mShowProgress.setChecked(Settings.getShowProgress());
    mShowBattery.setChecked(Settings.getShowBattery());
    mShowPageInterval.setChecked(Settings.getShowPageInterval());
    mVolumePage.setChecked(Settings.getVolumePage());
    mReadingFullscreen.setChecked(Settings.getReadingFullscreen());
    mCustomScreenLightness.setChecked(Settings.getCustomScreenLightness());
    mScreenLightness.setProgress(Settings.getScreenLightness());
    mScreenLightness.setEnabled(Settings.getCustomScreenLightness());

    mCustomScreenLightness.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mScreenLightness.setEnabled(isChecked);
        }
    });
}
 
Example #22
Source File: NavigationViewTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testActionLayout() {
  // Open our drawer
  onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));

  // There are four conditions to "find" the menu item with action layout (switch):
  // 1. Is in the NavigationView
  // 2. Is direct child of a class that extends RecyclerView
  // 3. Has a child with "people" text
  // 4. Has fully displayed child that extends SwitchCompat
  // Note that condition 2 makes a certain assumption about the internal implementation
  // details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as
  // possible and to not rely on the internal details of the current layout implementation
  // of an individual menu item in NavigationMenu.
  Matcher<View> menuItemMatcher =
      allOf(
          isDescendantOfA(withId(R.id.start_drawer)),
          isChildOfA(isAssignableFrom(RecyclerView.class)),
          hasDescendant(withText(menuStringContent.get(R.id.destination_people))),
          hasDescendant(allOf(isAssignableFrom(SwitchCompat.class), isCompletelyDisplayed())));

  // While we don't need to perform any action on our row, the invocation of perform()
  // makes our matcher actually run. If for some reason NavigationView fails to inflate and
  // display our SwitchCompat action layout, the next line will fail in the matcher pass.
  onView(menuItemMatcher).perform(click());

  // Check that the full custom view is displayed without title and icon.
  final Resources res = activityTestRule.getActivity().getResources();
  Matcher<View> customItemMatcher =
      allOf(
          isDescendantOfA(withId(R.id.start_drawer)),
          isChildOfA(isAssignableFrom(RecyclerView.class)),
          hasDescendant(withText(res.getString(R.string.navigate_custom))),
          hasDescendant(
              allOf(isAssignableFrom(TextView.class), withEffectiveVisibility(Visibility.GONE))));
  onView(customItemMatcher).perform(click());
}
 
Example #23
Source File: FolderActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {
    inflater.inflate(R.layout.item_device_form, mDevicesContainer);
    SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
    deviceView.setOnCheckedChangeListener(null);
    deviceView.setChecked(mFolder.getDevice(device.deviceID) != null);
    deviceView.setText(device.getDisplayName());
    deviceView.setTag(device);
    deviceView.setOnCheckedChangeListener(mCheckedListener);
}
 
Example #24
Source File: EncodingDialog.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_encoding_list, null);
    list = (ListView) view.findViewById(android.R.id.list);
    SwitchCompat autoencoding = (SwitchCompat) view.findViewById(android.R.id.checkbox);
    autoencoding.setChecked(PreferenceHelper.getAutoEncoding(getActivity()));

    autoencoding.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PreferenceHelper.setAutoencoding(getActivity(), isChecked);
        }
    });

    list.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.item_single_choice, encodings));
    list.setOnItemClickListener(this);

    String currentEncoding = PreferenceHelper.getEncoding(getActivity());

    for (int i = 0; i < encodings.length; i++) {
        if (currentEncoding.equals(encodings[i])) {
            list.setItemChecked(i, true);
        }

    }

    return new AlertDialog.Builder(getActivity())
            .setView(view)
            .create();
}
 
Example #25
Source File: SliderDiscreteDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void setUpSlider(
    View view, @IdRes int switchId, @IdRes int sliderId, Slider.LabelFormatter labelFormatter) {
  final Slider slider = view.findViewById(sliderId);
  slider.setLabelFormatter(labelFormatter);
  SwitchCompat switchButton = view.findViewById(switchId);
  switchButton.setOnCheckedChangeListener(
      (buttonView, isChecked) -> slider.setEnabled(isChecked));
  switchButton.setChecked(true);
}
 
Example #26
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull SwitchCompat switchView, @ColorInt int color, boolean useDarker) {
    if (switchView.getTrackDrawable() != null) {
        switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getTrackDrawable(), color, false, true, useDarker));
    }
    if (switchView.getThumbDrawable() != null) {
        switchView.setThumbDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getThumbDrawable(), color, true, true, useDarker));
    }
}
 
Example #27
Source File: NeopixelComponentSelectorFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // Dismiss on click outside
    AppCompatDialog dialog = (AppCompatDialog) getDialog();
    if (dialog != null) {
        dialog.setCanceledOnTouchOutside(true);
    }

    // UI
    Context context = getContext();
    if (context != null) {
        RecyclerView standardComponentsRecyclerView = view.findViewById(R.id.standardComponentsRecyclerView);
        standardComponentsRecyclerView.setHasFixedSize(true);
        standardComponentsRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
        RecyclerView.Adapter standardBoardSizesAdapter = new StandardComponentsAdapter(mSelectedComponent, components -> {
            mSelectedComponent = components;
            if (mListener != null) {
                mListener.onComponentsSelected(components, mIs400KhzEnabled);
                dismiss();
            }
        });
        standardComponentsRecyclerView.setAdapter(standardBoardSizesAdapter);


        SwitchCompat mode400HhzSwitch = view.findViewById(R.id.mode400HhzSwitch);
        mode400HhzSwitch.setChecked(mIs400KhzEnabled);
        mode400HhzSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (buttonView.isPressed()) {
                mIs400KhzEnabled = isChecked;
                if (mListener != null) {
                    mListener.onComponentsSelected(mSelectedComponent, mIs400KhzEnabled);
                }
            }
        });
    }
}
 
Example #28
Source File: LSettingItem.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private void initView(Context context) {
    mView = View.inflate(context, R.layout.settingitem, this);
    mRootLayout = (RelativeLayout) mView.findViewById(R.id.rootLayout);
    mUnderLine = (View) mView.findViewById(R.id.underline);
    mTvLeftText = (TextView) mView.findViewById(R.id.tv_lefttext);
    mTvRightText = (TextView) mView.findViewById(R.id.tv_righttext);
    mIvLeftIcon = (ImageView) mView.findViewById(R.id.iv_lefticon);
    mIvRightIcon = (ImageView) mView.findViewById(R.id.iv_righticon);
    mRightLayout = (FrameLayout) mView.findViewById(R.id.rightlayout);
    mRightIcon_check = (AppCompatCheckBox) mView.findViewById(R.id.rightcheck);
    mRightIcon_switch = (SwitchCompat) mView.findViewById(R.id.rightswitch);
    mTvIntroText = (TextView) mView.findViewById(R.id.tv_intro);
}
 
Example #29
Source File: NetFragment.java    From pandora with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getToolbar().setTitle(R.string.pd_name_network);
    getToolbar().getMenu().add(-1, R.id.pd_menu_id_1, 0, "")
            .setActionView(new SwitchCompat(getContext()))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    getToolbar().getMenu().add(-1, R.id.pd_menu_id_2, 1, R.string.pd_name_search)
            .setActionView(new SearchView(getContext()))
            .setIcon(R.drawable.pd_search)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    getToolbar().getMenu().add(-1, R.id.pd_menu_id_3, 2, R.string.pd_name_clear);
    setSearchView();
    getToolbar().setOnMenuItemClickListener(this);
    SwitchCompat switchCompat = ((SwitchCompat) getToolbar()
            .getMenu().findItem(R.id.pd_menu_id_1).getActionView());
    switchCompat.setOnCheckedChangeListener(this);
    if (Config.isNetLogEnable()) {
        switchCompat.setChecked(true);
    } else {
        showOpenLogHint();
    }
    Pandora.get().getInterceptor().setListener(this);
    getAdapter().setListener(new UniversalAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(int position, BaseItem item) {
            if (item instanceof NetItem) {
                Bundle bundle = new Bundle();
                bundle.putLong(PARAM1, ((Summary)item.data).id);
                launch(NetSummaryFragment.class, bundle);
            }
        }
    });
}
 
Example #30
Source File: BooleanPreferenceData.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);

    SwitchCompat titleView = holder.v.findViewById(R.id.title);

    titleView.setOnCheckedChangeListener(null);
    titleView.setChecked(value);
    titleView.setOnCheckedChangeListener((compoundButton, b) -> {
        value = b;

        getIdentifier().setPreferenceValue(getContext(), b);
        onPreferenceChange(b);
    });
}