Java Code Examples for androidx.appcompat.widget.SwitchCompat#setChecked()

The following examples show how to use androidx.appcompat.widget.SwitchCompat#setChecked() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: ProfileFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
                         @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_apply_on_boot, container, false);

    ((TextView) rootView.findViewById(R.id.title)).setText(getString(R.string.profile_tasker_toast));
    SwitchCompat switchCompat = rootView.findViewById(R.id.switcher);
    switchCompat.setChecked(AppSettings.isShowTaskerToast(getActivity()));
    switchCompat.setOnCheckedChangeListener((compoundButton, b)
            -> AppSettings.saveShowTaskerToast(b, getActivity()));

    return rootView;
}
 
Example 11
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 12
Source File: ProfileFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_apply_on_boot, container, false);

    ((TextView) rootView.findViewById(R.id.title)).setText(getString(R.string.profile_tasker_toast));
    SwitchCompat switchCompat = rootView.findViewById(R.id.switcher);
    switchCompat.setChecked(Prefs.getBoolean("showtaskertoast", true, getActivity()));
    switchCompat.setOnCheckedChangeListener((compoundButton, b) -> Prefs.saveBoolean("showtaskertoast", b, getActivity()));

    return rootView;
}
 
Example 13
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 14
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 15
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 16
Source File: GalleryActivity.java    From MHViewer 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 17
Source File: DevicePluginListFragment.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    View cv;
    if (convertView == null) {
        cv = mInflater.inflate(R.layout.item_deviceplugin_list, parent, false);
    } else {
        cv = convertView;
    }

    final PluginContainer container = getItem(position);
    final DevicePlugin plugin = container.getPluginEntity();

    String name = container.getLabel();

    TextView nameView = cv.findViewById(R.id.devicelist_package_name);
    nameView.setText(name);

    Drawable icon = container.getIcon();
    if (icon != null) {
        ImageView iconView = cv.findViewById(R.id.devicelist_icon);
        iconView.setImageDrawable(icon);
    }

    String version = container.getVersion();
    TextView versionView = cv.findViewById(R.id.devicelist_version);
    versionView.setText(getString(R.string.activity_devicepluginlist_version) + version);

    SwitchCompat switchCompat = cv.findViewById(R.id.switch_plugin_enable_status);
    switchCompat.setOnCheckedChangeListener(null);
    switchCompat.setChecked(plugin.isEnabled());
    switchCompat.setOnCheckedChangeListener((button, isOn) -> {
        requestPluginStateChange(plugin.getPluginId(), isOn);
    });

    View progressCircle = cv.findViewById(R.id.progress_plugin_enable_status);
    if (container.isConnecting()) {
        progressCircle.setVisibility(View.VISIBLE);
    } else {
        progressCircle.setVisibility(View.INVISIBLE);
    }

    ConnectionErrorView errorView = cv.findViewById(R.id.plugin_connection_error_view);
    errorView.showErrorMessage(plugin);

    if (plugin.canCommunicate()) {
        cv.setBackgroundResource(R.color.plugin_list_row_background_color_connected);
    } else {
        cv.setBackgroundResource(R.color.plugin_list_row_background_color_not_connected);
    }

    return cv;
}
 
Example 18
Source File: ActivityMain.java    From tracker-control-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("enabled".equals(name)) {
        // Get enabled
        boolean enabled = prefs.getBoolean(name, false);

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

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

    } else if ("whitelist_wifi".equals(name) ||
            "screen_on".equals(name) ||
            "screen_wifi".equals(name) ||
            "whitelist_other".equals(name) ||
            "screen_other".equals(name) ||
            "whitelist_roaming".equals(name) ||
            "show_user".equals(name) ||
            "show_system".equals(name) ||
            "show_nointernet".equals(name) ||
            "show_disabled".equals(name) ||
            "sort".equals(name) ||
            "imported".equals(name)) {
        updateApplicationList(null);

        final LinearLayout llWhitelist = findViewById(R.id.llWhitelist);
        boolean screen_on = prefs.getBoolean("screen_on", true);
        boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false);
        boolean whitelist_other = prefs.getBoolean("whitelist_other", false);
        boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true);
        llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE);

    } else if ("manage_system".equals(name)) {
        invalidateOptionsMenu();
        updateApplicationList(null);

        LinearLayout llSystem = findViewById(R.id.llSystem);
        boolean system = prefs.getBoolean("manage_system", false);
        boolean hint = prefs.getBoolean("hint_system", true);
        llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);

    } else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();
}
 
Example 19
Source File: EventStatusPopupWindow.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetTextI18n")
EventStatusPopupWindow(final EditorEventListFragment fragment, Event event) {
    super(R.layout.popup_window_event_status, R.string.editor_event_list_item_event_status, fragment.getActivity());

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

    final TextView textView = popupView.findViewById(R.id.event_status_popup_window_text7);
    textView.setClickable(true);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (fragment.getActivity() != null) {
                Intent intentLaunch = new Intent(fragment.getActivity(), ImportantInfoActivity.class);
                intentLaunch.putExtra(ImportantInfoActivity.EXTRA_SHOW_QUICK_GUIDE, false);
                intentLaunch.putExtra(ImportantInfoActivity.EXTRA_SCROLL_TO, R.id.activity_info_notification_events);
                fragment.getActivity().startActivity(intentLaunch);
            }

            dismiss();
        }
    });

    if (event != null) {
        final Event _event = event;

        TextView eventName = popupView.findViewById(R.id.event_status_popup_window_text0);
        eventName.setText(fragment.getString(R.string.event_string_0)+": "+event._name);

        final SwitchCompat checkBox = popupView.findViewById(R.id.event_status_popup_window_checkbox);
        checkBox.setChecked(event.getStatus() != Event.ESTATUS_STOP);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                //noinspection ConstantConditions
                if (fragment != null) {
                    if (!fragment.runStopEvent(_event))
                        checkBox.setChecked(false);
                }
            }
        });
    }
}
 
Example 20
Source File: SinglePhotoSetting.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
public void show() {
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), getActivity().getDialogStyle());

    View dialogLayout = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_media_viewer_theme, null);
    final SwitchCompat swApplyTheme = dialogLayout.findViewById(R.id.sw_apply_theme);

    ((CardView) dialogLayout.findViewById(R.id.dialog_card_)).setCardBackgroundColor(getActivity().getCardBackgroundColor());
    dialogLayout.findViewById(R.id.dialog_title).setBackgroundColor(getActivity().getPrimaryColor());
    ((TextView) dialogLayout.findViewById(R.id.apply_theme)).setTextColor(getActivity().getTextColor());
    ((TextView) dialogLayout.findViewById(R.id.apply_theme_3thAct_title_Sub)).setTextColor(getActivity().getSubTextColor());
    ((ThemedIcon) dialogLayout.findViewById(R.id.ll_apply_theme_icon)).setColor(getActivity().getIconColor());

    swApplyTheme.setChecked(getActivity().themeOnSingleImgAct());
    swApplyTheme.setClickable(false);
    dialogLayout.findViewById(R.id.ll_apply_theme).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            swApplyTheme.setChecked(!swApplyTheme.isChecked());
            getActivity().setSwitchColor(getActivity().getAccentColor(), swApplyTheme);
        }
    });
    getActivity().setSwitchColor(getActivity().getAccentColor(), swApplyTheme);

    final LineColorPicker transparencyColorPicker = dialogLayout.findViewById(R.id.pickerTransparent);
    transparencyColorPicker.setColors(ColorPalette.getTransparencyShadows(getActivity().getPrimaryColor()));
    transparencyColorPicker.setSelectedColor(ColorPalette.getTransparentColor(getActivity().getPrimaryColor(), 255 - Hawk.get(getActivity().getString(R.string.preference_transparency), 0)));

    /**TEXT VIEWS**/
    ((TextView) dialogLayout.findViewById(R.id.seek_bar_alpha_title)).setTextColor(getActivity().getTextColor());
    ((TextView) dialogLayout.findViewById(R.id.seek_bar_alpha_title_Sub)).setTextColor(getActivity().getSubTextColor());

    dialogBuilder.setView(dialogLayout);
    dialogBuilder.setNeutralButton(getActivity().getString(R.string.cancel).toUpperCase(), null);
    dialogBuilder.setPositiveButton(getActivity().getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            boolean applyTheme = swApplyTheme.isChecked();
            Hawk.put(getActivity().getString(R.string.preference_apply_theme_pager), applyTheme);
            if (applyTheme) {
                int c = Color.alpha(transparencyColorPicker.getColor());
                Hawk.put(getActivity().getString(R.string.preference_transparency), 255 - c);
            }
            getActivity().updateTheme();
        }
    });
    dialogBuilder.show();
}