Java Code Examples for android.widget.Switch#setChecked()

The following examples show how to use android.widget.Switch#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: SeekBarForm.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@SuppressLint("InflateParams")
public View inflate(Context context) {
	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View view = inflater.inflate(R.layout.dialog_seek_bar_preference, null);
	((TextView) view.findViewById(R.id.min_value)).setText(Integer.toString((int) (minValue * multipler)));
	((TextView) view.findViewById(R.id.max_value)).setText(Integer.toString((int) (maxValue * multipler)));
	seekBar = view.findViewById(R.id.seek_bar);
	seekBar.setMax((maxValue - minValue) / step);
	seekBar.setProgress((currentValue - minValue) / step);
	seekBar.setOnSeekBarChangeListener(this);
	Switch switchView = view.findViewById(R.id.switch_view);
	if (!showSwitch) {
		switchView.setVisibility(View.GONE);
	} else {
		switchView.setChecked(switchValue);
		switchView.setOnCheckedChangeListener(this);
		if (C.API_LOLLIPOP) {
			((ViewGroup.MarginLayoutParams) switchView.getLayoutParams()).rightMargin = 0;
		}
	}
	valueText = view.findViewById(R.id.current_value);
	updateCurrentValueText();
	return view;
}
 
Example 2
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the screen switch preference toggle based on whether and where the screen switch is
 * currently assigned.
 *
 * @param screenSwitchToggle A switch that corresponds to the current assignment status of the
 *     screen switch.
 * @param keyCombos List of keys currently assigned to this action
 * @param context Context used to determine if the screen switch is currently assigned to a
 *     different action
 * @param key The key to the map that pairs an action with a set of switches currently assigned to
 *     said action.
 */
public static void updateScreenAsASwitchToggle(
    Switch screenSwitchToggle, Set<Long> keyCombos, Context context, String key) {
  long screenSwitchKeyCombo =
      KeyAssignmentUtils.keyEventToExtendedKeyCode(SCREEN_SWITCH_EVENT_UP);

  if (!keyCombos.isEmpty() && keyCombos.contains(screenSwitchKeyCombo)) {
    screenSwitchToggle.setEnabled(true);
    screenSwitchToggle.setChecked(true);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle);
  } else if (KeyAssignmentUtils.otherActionAssociatedWithKey(
      screenSwitchKeyCombo, context, key)) {
    screenSwitchToggle.setEnabled(false);
    screenSwitchToggle.setChecked(false);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle_disabled);
  } else {
    screenSwitchToggle.setEnabled(true);
    screenSwitchToggle.setChecked(false);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle);
  }
}
 
Example 3
Source File: HOGPSettingActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * ユーザ認可UIの設定を行います.
 */
private void setLocalOAuthUI() {
    HOGPSetting setting = getHOGPMessageService().getHOGPSetting();
    final Switch oauthSwitch = findViewById(R.id.activity_setting_device_oauth_switch);
    oauthSwitch.setChecked(setting.isEnabledOAuth());
    oauthSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        HOGPMessageService service = getHOGPMessageService();
        if (service != null) {
            service.setEnabledOAuth(isChecked);
        }
    });

    findViewById(R.id.activity_setting_device_oauth_title).setOnClickListener((v) -> {
        oauthSwitch.setChecked(!oauthSwitch.isChecked());
    });
}
 
Example 4
Source File: FormBindings.java    From SimpleFTP with MIT License 6 votes vote down vote up
/**
 * Binding method for Switch
 * @param view The Switch widget.
 * @param observable The field value.
 */
@BindingAdapter("binding")
public static void bindSwitch(Switch view, final FieldViewModel<Boolean> observable) {
    if (view.getTag() == null) {
        view.setTag(true);
        view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                observable.set(isChecked);
            }
        });
    }

    boolean newValue = observable.get() == null ? false : observable.get().booleanValue();
    if (view.isChecked() != newValue) {
        view.setChecked(newValue);
    }

    String newError = observable.getError();
    if (view.getError() != newError) {
        view.setError(newError);
    }
}
 
Example 5
Source File: SettingsFragment.java    From block-this 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) {
    prefs = getActivity().getSharedPreferences(
            "com.savageorgiev.blockthis", Context.MODE_PRIVATE);

    v = inflater.inflate(R.layout.fragment_settings, container, false);
    switchAuto = (Switch) v.findViewById(R.id.switch_auto_start);

    int autoload = prefs.getInt("autoload", 0);
    if (autoload == 1) {
        switchAuto.setChecked(true);
    }

    switchAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked){
                prefs.edit().putInt("autoload", 1).apply();
            } else {
                prefs.edit().putInt("autoload", 0).apply();
            }
        }
    });

    return v;
}
 
Example 6
Source File: TaskerActivity.java    From Maying with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_tasker);

    profilesAdapter = new ProfilesAdapter();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    toolbar.setNavigationIcon(R.drawable.ic_navigation_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    taskerOption = TaskerSettings.fromIntent(getIntent());
    mSwitch = (Switch) findViewById(R.id.serviceSwitch);
    mSwitch.setChecked(taskerOption.switchOn);
    RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
    LinearLayoutManager lm = new LinearLayoutManager(this);
    profilesList.setLayoutManager(lm);
    profilesList.setItemAnimator(new DefaultItemAnimator());
    profilesList.setAdapter(profilesAdapter);

    if (taskerOption.profileId >= 0) {
        int position = 0;
        List<Profile> profiles = profilesAdapter.profiles;
        for (int i = 0; i < profiles.size(); i++) {
            Profile profile = profiles.get(i);
            if (profile.id == taskerOption.profileId) {
                position = i + 1;
                break;
            }
        }
        lm.scrollToPosition(position);
    }
}
 
Example 7
Source File: HomeFragment.java    From orWall with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    Switch orwallSwitch = (Switch) home.findViewById(R.id.orwall_status);
    // checking true orwall status
    if (Preferences.isOrwallEnabled(getActivity()) &&
            !iptables.haveBooted()){
        Preferences.setOrwallEnabled(getActivity(), false);
        orwallSwitch.setChecked(false);
    }

    updateOptions();
}
 
Example 8
Source File: TaskerActivity.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_tasker);

    profilesAdapter = new ProfilesAdapter();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    toolbar.setNavigationIcon(R.drawable.ic_navigation_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    taskerOption = TaskerSettings.fromIntent(getIntent());
    mSwitch = (Switch) findViewById(R.id.serviceSwitch);
    mSwitch.setChecked(taskerOption.switchOn);
    RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
    LinearLayoutManager lm = new LinearLayoutManager(this);
    profilesList.setLayoutManager(lm);
    profilesList.setItemAnimator(new DefaultItemAnimator());
    profilesList.setAdapter(profilesAdapter);

    if (taskerOption.profileId >= 0) {
        int position = 0;
        List<Profile> profiles = profilesAdapter.profiles;
        for (int i = 0; i < profiles.size(); i++) {
            Profile profile = profiles.get(i);
            if (profile.id == taskerOption.profileId) {
                position = i + 1;
                break;
            }
        }
        lm.scrollToPosition(position);
    }
}
 
Example 9
Source File: BaseSet.java    From MainScreenShow with GNU General Public License v2.0 5 votes vote down vote up
/**
 * show Switch 事件开关
 *
 * @param convertView
 * @param title
 */
protected void showEventStart(View convertView, String title) {

    TextView title1 = (TextView) convertView
            .findViewById(R.id.tv_msseventset_title);
    Switch sw = (Switch) convertView.findViewById(R.id.sw_msseventset);
    title1.setText(title);
    sw.setVisibility(View.VISIBLE);
    if (sp_date.getString("state" + VALUE, "").equals(getString(R.string.action_started)))

        sw.setChecked(true);
    else
        sw.setChecked(false);
    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                                     boolean isChecked) {

            if (isChecked) {
                sp_date.edit().putString("state" + VALUE, getString(R.string.action_started)).commit();
                listLength = setLenght + baseLenght + animationLenght;
                adapter.notifyDataSetChanged();
            } else {
                sp_date.edit().putString("state" + VALUE, getString(R.string.action_stoped)).commit();
                listLength = baseLenght;
                adapter.notifyDataSetChanged();
            }
        }
    });
}
 
Example 10
Source File: SettingsActivity.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private void setupSettingsSwitch(int containerId, int labelId, int switchId, boolean checked,
        CompoundButton.OnCheckedChangeListener checkedChangeListener) {
    ViewGroup container = findViewById(containerId);
    String switchLabel = ((TextView) container.findViewById(labelId)).getText().toString();
    final Switch switchView = container.findViewById(switchId);
    switchView.setContentDescription(switchLabel);
    switchView.setChecked(checked);
    container.setOnClickListener((view) -> switchView.performClick());
    switchView.setOnCheckedChangeListener(checkedChangeListener);
}
 
Example 11
Source File: MotionSampleActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.motion_parallax, menu);

    // Add parallax toggle
    final Switch mParallaxToggle = new Switch(getActivity());
    mParallaxToggle.setPadding(0, 0, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getResources().getDisplayMetrics()), 0);
    mParallaxToggle.setChecked(mParallaxSet);
    mParallaxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mBackground.registerSensorManager();
            } else {
                mBackground.unregisterSensorManager();
            }

            mParallaxSet = isChecked;
        }
    });
    MenuItem switchItem = menu.findItem(R.id.action_parallax);
    if (switchItem != null)
        switchItem.setActionView(mParallaxToggle);

    // Set lock/ unlock orientation text
    if (mPortraitLock) {
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        MenuItem orientationItem = menu.findItem(R.id.action_portrait);
        if (orientationItem != null)
            orientationItem.setTitle("action_unlock_portrait");
    }
}
 
Example 12
Source File: SettingsActivity.java    From MaxLock with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("WorldReadableFiles")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.toolbar_menu, menu);
    Switch master_switch = (Switch) menu.findItem(R.id.toolbar_master_switch).getActionView();
    master_switch.setChecked(MLPreferences.getPrefsApps(this).getBoolean(Common.MASTER_SWITCH_ON, true));
    master_switch.setOnCheckedChangeListener((button, b) -> MLPreferences.getPrefsApps(SettingsActivity.this).edit().putBoolean(Common.MASTER_SWITCH_ON, b).apply());
    return super.onCreateOptionsMenu(menu);
}
 
Example 13
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get us census data as a service feature table
  ServiceFeatureTable statesServiceFeatureTable = new ServiceFeatureTable(
      getResources().getString(R.string.us_census_feature_service));

  // add the service feature table to a feature layer
  final FeatureLayer statesFeatureLayer = new FeatureLayer(statesServiceFeatureTable);
  // set the feature layer to render dynamically to allow extrusion
  statesFeatureLayer.setRenderingMode(FeatureLayer.RenderingMode.DYNAMIC);

  // create a scene and add it to the scene view
  ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
  mSceneView = findViewById(R.id.sceneView);
  mSceneView.setScene(scene);

  // add the feature layer to the scene
  scene.getOperationalLayers().add(statesFeatureLayer);

  // define line and fill symbols for a simple renderer
  final SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 1.0f);
  final SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.BLUE, lineSymbol);
  final SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
  // set renderer extrusion mode to absolute height, which extrudes the feature to the specified z-value as flat top
  renderer.getSceneProperties().setExtrusionMode(Renderer.SceneProperties.ExtrusionMode.ABSOLUTE_HEIGHT);
  // set the simple renderer to the feature layer
  statesFeatureLayer.setRenderer(renderer);

  // define a look at point for the camera at geographical center of the continental US
  final Point lookAtPoint = new Point(-10974490, 4814376, 0, SpatialReferences.getWebMercator());
  // add a camera and set it to orbit the look at point
  final Camera camera = new Camera(lookAtPoint, 20000000, 0, 55, 0);
  mSceneView.setViewpointCamera(camera);

  // set switch listener
  Switch popSwitch = findViewById(R.id.populationSwitch);
  popSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
    // set extrusion properties to either show total population or population density based on flag
    if (isChecked) {
      // multiple population density by 5000 to make data legible
      renderer.getSceneProperties().setExtrusionExpression("[POP07_SQMI] * 5000 + 100000");
    } else {
      // divide total population by 10 to make data legible
      renderer.getSceneProperties().setExtrusionExpression("[POP2007] / 10");
    }
  });

  // set initial switch state
  popSwitch.setChecked(true);
}
 
Example 14
Source File: CreatePoiFragment.java    From AndroidApp with Mozilla Public License 2.0 4 votes vote down vote up
private void openingHoursLayoutSetup() {
    hoursSwitch24_7 = (Switch) getActivity().findViewById(R.id.hoursSwitch24_7);
    hoursSwitch24_7.setChecked(false);
    extendedOpeningHoursContainer = (LinearLayout) getActivity().findViewById(R.id.extendedOpeningHoursContainer);
    extendedOpeningHoursContainer.setVisibility(View.VISIBLE);
    openingHours = (TextView) getActivity().findViewById(R.id.openingHours);
    closingHours = (TextView) getActivity().findViewById(R.id.closingHours);

    //week CheckBoxes
    checkboxMonday = (CheckBox) getActivity().findViewById(R.id.checkboxMonday);
    checkboxTuesday = (CheckBox) getActivity().findViewById(R.id.checkboxTuesday);
    checkboxWednesday = (CheckBox) getActivity().findViewById(R.id.checkboxWednesday);
    checkboxThursday = (CheckBox) getActivity().findViewById(R.id.checkboxThursday);
    checkboxFriday = (CheckBox) getActivity().findViewById(R.id.checkboxFriday);
    checkboxSaturday = (CheckBox) getActivity().findViewById(R.id.checkboxSaturday);
    checkboxSunday = (CheckBox) getActivity().findViewById(R.id.checkboxSunday);
    checkboxAll = (CheckBox) getActivity().findViewById(R.id.checkboxAll);
    checkboxMonday.setOnClickListener(openingHoursViewListener);
    checkboxTuesday.setOnClickListener(openingHoursViewListener);
    checkboxWednesday.setOnClickListener(openingHoursViewListener);
    checkboxThursday.setOnClickListener(openingHoursViewListener);
    checkboxFriday.setOnClickListener(openingHoursViewListener);
    checkboxSaturday.setOnClickListener(openingHoursViewListener);
    checkboxSunday.setOnClickListener(openingHoursViewListener);
    checkboxAll.setOnClickListener(openingHoursViewListener);

    hoursSwitch24_7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (isChecked) {
                //do stuff when Switch is ON
                extendedOpeningHoursContainer.setVisibility(View.GONE);
            } else {
                //do stuff when Switch if OFF
                extendedOpeningHoursContainer.setVisibility(View.VISIBLE);
            }
        }
    });
    openingHours.setOnClickListener(openingHoursViewListener);
    closingHours.setOnClickListener(openingHoursViewListener);

}
 
Example 15
Source File: TouchWiz.java    From SystemUITuner2 with MIT License 4 votes vote down vote up
private void checkBL(@SuppressWarnings("SameParameterValue") boolean tralse) {
    for (Switch toggle : switches) {
        toggle.setChecked(tralse);
    }
}
 
Example 16
Source File: MainActivity.java    From internet-speed-meter with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String base64EncodedPublicKey = Decoder.decode
            ("miibiJanbGKQHKIg9W0baqefaaocaq8amiibcGkcaqeaPgHbZkGf6iZccjp1ofY6/NdZgyYYuDstGz13f95pmgiPIma22eXhNKtEKTftchaNV2S+JVtIKWgfxwcopMFqke+suocd724kKdipI7Es8WnLo1Vh3jiBZFYFV11p4Uvu1p75yHvs5L30a+RwmKd68v57mrQ4VahGmg7PlrDYX4L3AG2QqeIPJGyI3Ah1+YxK5OWkKUkwsrqMIPu3xj9KmeojXPra1GSEPsA2FTqEs71EflIbHreeEpO6yopRro6ruSExeiIBSsyKmGwr7blEl1zLHZKTmt0FFNA4x0OOA3sMIf0Opm0j8mgmerSMelWS3frufN+Caj5jDdHg+ESHCqidaqab");

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (result.isSuccess()) {
                try {
                    mHelper.queryInventoryAsync(mGotInventoryListener);
                } catch (IabHelper.IabAsyncInProgressException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    /*Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);*/

    final Intent ismServiceIntent = new Intent(this, ISMService.class);
    ismServiceIntent.setPackage(this.getPackageName());

    Switch meterSwitch = (Switch) findViewById(R.id.meter_switch);

    /*Get meter state so that we'll know if it's enabled/disabled by user upon start*/
    SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.shared_pref),
            Context.MODE_PRIVATE);
    int state = sharedPref.getInt(getString(R.string.meter_state), 0);
    if (state == 1) {
        meterSwitch.setChecked(true);
    }
    else {
        meterSwitch.setChecked(false);
    }

    final SharedPreferences.Editor editor = sharedPref.edit();

    meterSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                editor.putInt(getString(R.string.meter_state), 1);
                editor.commit();
                startService(ismServiceIntent);
            } else {
                editor.putInt(getString(R.string.meter_state), 0);
                editor.commit();
                stopService(ismServiceIntent);
            }
        }
    });

}
 
Example 17
Source File: MainActivity.java    From DeAutherDroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final boolean previous = Prefs.getInstance(getBaseContext()).isLogcatState();

    View mainOats = getLayoutInflater().inflate(R.layout.settings, null);

    Switch logcat = mainOats.findViewById(R.id.logcat);
    Switch wiRand = mainOats.findViewById(R.id.wiRand);
    final TextView location = mainOats.findViewById(R.id.location);

    File appDirectory = new File(Environment.getExternalStorageDirectory() + "/DeAuther");
    File logDirectory = new File(appDirectory + "/log");
    File logFile = new File(logDirectory, "logcat" + Prefs.getInstance(getBaseContext()).getTime() + ".txt");

    location.setText("Logcat will be saved to : " + logFile.getPath());

    logcat.setChecked(previous);
    wiRand.setChecked(Prefs.getInstance(getBaseContext()).isWIFIRand());

    if (Prefs.getInstance(getBaseContext()).isLogcatState()) {
        location.setVisibility(View.VISIBLE);
    }

    logcat.setOnCheckedChangeListener((buttonView, isChecked) -> {
        Prefs.getInstance(getBaseContext()).setIsLogcatEnabled(isChecked);
        if (isChecked) {
            location.setVisibility(View.VISIBLE);
        } else {
            location.setVisibility(View.GONE);
        }
    });

    wiRand.setOnCheckedChangeListener((buttonView, isChecked) -> Prefs.getInstance(getBaseContext()).setWIFIRand(isChecked));

    new AlertDialog.Builder(MainActivity.this)
            .setView(mainOats)
            .setTitle("Additional Config")
            .setPositiveButton("Okay", (dialog, which) -> {
                if (!previous == Prefs.getInstance(getBaseContext()).isLogcatState()) {
                    Toast.makeText(getBaseContext(), "Start Application Manually", Toast.LENGTH_SHORT).show();
                    System.exit(0);
                } else {
                    recreate();
                }
            }).show();
    return super.onOptionsItemSelected(item);
}
 
Example 18
Source File: SchedulerDialog.java    From Blackbulb with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
	mSettings = Settings.getInstance(getContext());
	hrsSunrise = mSettings.getInt(Settings.KEY_HOURS_SUNRISE, 6);
	minSunrise = mSettings.getInt(Settings.KEY_MINUTES_SUNRISE, 0);
	hrsSunset = mSettings.getInt(Settings.KEY_HOURS_SUNSET, 22);
	minSunset = mSettings.getInt(Settings.KEY_MINUTES_SUNSET, 0);

	View rootView = getLayoutInflater().inflate(R.layout.dialog_scheduler, null);
	setView(rootView);

	mLeftLayout = rootView.findViewById(R.id.left_layout);
	mRightLayout = rootView.findViewById(R.id.right_layout);
	mFrameLayout = rootView.findViewById(R.id.frame_layout);
	mFrameLayout.getViewTreeObserver().addOnGlobalLayoutListener(
			new ViewTreeObserver.OnGlobalLayoutListener() {
				@Override
				public void onGlobalLayout() {
					mFrameLayout.getViewTreeObserver()
                               .removeOnGlobalLayoutListener(this);
					final int measureWidth = mFrameLayout.getMeasuredWidth();
					final int dp20 = (int) Utility.dpToPx(getContext(), 20);
					Log.i("TAG", "measureWidth: " + measureWidth);
					mLeftLayout.getLayoutParams().width = measureWidth / 2 + dp20;
					mRightLayout.getLayoutParams().width = measureWidth / 2 + dp20;
				}
			});

	sunriseTime = rootView.findViewById(R.id.sunrise_time);
	sunsetTime = rootView.findViewById(R.id.sunset_time);
	sunriseTime.setText(String.format(Locale.getDefault(),
               "%1$02d:%2$02d", hrsSunrise, minSunrise));
	sunsetTime.setText(String.format(Locale.getDefault(),
               "%1$02d:%2$02d", hrsSunset, minSunset));

	Switch switchView = rootView.findViewById(R.id.auto_switch);
	switchView.setChecked(mSettings.getBoolean(Settings.KEY_AUTO_MODE, false));
	switchView.setOnCheckedChangeListener((compoundButton, b) -> {
           mSettings.putBoolean(Settings.KEY_AUTO_MODE, b);
           AlarmUtil.updateAlarmSettings(getContext());
       });

	rootView.findViewById(R.id.btn_ok).setOnClickListener(view -> dismiss());
	rootView.findViewById(R.id.sunrise_button).setOnClickListener(view -> {
           sunrisePicker = TimePickerDialog.newInstance(
                   SchedulerDialog.this,
                   hrsSunrise,
                   minSunrise,
                   true
           );
           if (mSettings.getBoolean(Settings.KEY_DARK_THEME, false)) {
               sunrisePicker.setThemeDark(true);
           }
           sunrisePicker.show(getOwnerActivity().getFragmentManager(), "sunrise_dialog");
       });
	rootView.findViewById(R.id.sunset_button).setOnClickListener(view -> {
           sunsetPicker = TimePickerDialog.newInstance(
                   SchedulerDialog.this,
                   hrsSunset,
                   minSunset,
                   true
           );
           if (mSettings.getBoolean(Settings.KEY_DARK_THEME, false)) {
               sunsetPicker.setThemeDark(true);
           }
           if (getOwnerActivity() != null) {
               sunsetPicker.show(getOwnerActivity().getFragmentManager(), "sunset_dialog");
           }
       });
}
 
Example 19
Source File: StatBar.java    From SystemUITuner2 with MIT License 4 votes vote down vote up
private void checkBL(@SuppressWarnings("SameParameterValue") boolean tralse) {
    for (Switch toggle : switches) {
        toggle.setChecked(tralse);
    }
}
 
Example 20
Source File: BaseSet.java    From MainScreenShow with GNU General Public License v2.0 4 votes vote down vote up
/**
 * show Switch 事件开关
 *
 * @param convertView
 * @param title
 */
protected void showEventStartForDesktop(View convertView, String title,boolean isStart) {

    TextView title1 = (TextView) convertView
            .findViewById(R.id.tv_msseventset_title);
    final Switch sw = (Switch) convertView.findViewById(R.id.sw_msseventset);
    title1.setText(title);
    sw.setVisibility(View.VISIBLE);
    if(isStart){
        sw.setChecked(true);
    }else{
        sw.setChecked(false);
    }
    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                                     boolean isChecked) {

            if (isChecked) {
                new AlertDialog.Builder(BaseSet.this).setTitle(R.string.tip)
                        .setMessage("请设置桌面秀动态壁纸,以此激活桌面动画!")
                        .setPositiveButton("前往", new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent();
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
                                startActivity(intent);
                                listLength = setLenght + baseLenght + animationLenght;
                                adapter.notifyDataSetChanged();
                            }
                        }).setNegativeButton(R.string.action_cancel, null).show();
                sw.setChecked(false);

            } else {
                new AlertDialog.Builder(BaseSet.this).setTitle(R.string.tip)
                        .setMessage("请设重新设置壁纸,即可关闭桌面动画!")
                        .setPositiveButton(R.string.action_ok, null).show();
                sw.setChecked(true);
            }
        }
    });
}