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

The following examples show how to use android.widget.ToggleButton#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: IMPopupDialog.java    From opensudoku with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates selected numbers in note.
 *
 * @param numbers
 */
public void updateNote(Collection<Integer> numbers) {
    mNoteSelectedNumbers = new HashSet<>();

    if (numbers != null) {
        mNoteSelectedNumbers.addAll(numbers);
    }

    ToggleButton toggleButton;
    for (Integer number : mNoteNumberButtons.keySet()) {
        toggleButton = mNoteNumberButtons.get(number);
        toggleButton.setChecked(mNoteSelectedNumbers.contains(number));
        if (toggleButton.isChecked()) {
            ThemeUtils.applyIMButtonStateToView(toggleButton, ThemeUtils.IMButtonStyle.ACCENT);
        }
    }
}
 
Example 2
Source File: PostToAccountLoaderTask.java    From Onosendai with Apache License 2.0 6 votes vote down vote up
private void configureAccountBtn (final ToggleButton btn, final ServiceRef svc) {
	final String displayName = svc.getUiTitle();
	btn.setTextOn(displayName);
	btn.setTextOff(displayName);

	boolean checked = false;
	if (this.enabledSubAccounts.isEnabled(svc)) {
		checked = true;
	}
	else if (!this.enabledSubAccounts.isServicesPreSpecified()) {
		checked = svc.isDefault();
		if (checked) this.enabledSubAccounts.enable(svc);
	}
	btn.setChecked(checked);

	btn.setOnClickListener(new SubAccountToggleListener(svc, this.enabledSubAccounts));
}
 
Example 3
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
	ToggleButton tb = (ToggleButton) v;
	
	
	RadioGroup llLayout = (RadioGroup) tb.getParent();
	
       for(int i=0; i<((ViewGroup)llLayout).getChildCount(); ++i) {
           View nextChild = ((ViewGroup)llLayout).getChildAt(i);
           
           ToggleButton cb2=(ToggleButton) nextChild;
           
           if(nextChild instanceof ToggleButton && nextChild.getId()==tb.getId() ){
           	//cb2.setChecked(false);
           }else if (nextChild instanceof ToggleButton && nextChild.getId()!=tb.getId() ){
               cb2.setChecked(false);
           }
       }
	
}
 
Example 4
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
	ToggleButton tb = (ToggleButton) v;
	
	
	RadioGroup llLayout = (RadioGroup) tb.getParent();
	
       for(int i=0; i<((ViewGroup)llLayout).getChildCount(); ++i) {
           View nextChild = ((ViewGroup)llLayout).getChildAt(i);
           
           ToggleButton cb2=(ToggleButton) nextChild;
           
           if(nextChild instanceof ToggleButton && nextChild.getId()==tb.getId() ){
           	//cb2.setChecked(false);
           }else if (nextChild instanceof ToggleButton && nextChild.getId()!=tb.getId() ){
               cb2.setChecked(false);
           }
       }
	
}
 
Example 5
Source File: AlarmActivity.java    From Amadeus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarm);
    settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    alarmTimePicker = (TimePicker) findViewById(R.id.alarmTimePicker);
    alarmToggle = (ToggleButton) findViewById(R.id.alarmToggle);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getBroadcast(this, Alarm.ALARM_ID, new Intent(this, AlarmReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT);

    alarmTimePicker.setIs24HourView(settings.getBoolean("24-hour_format", true));

    if (settings.getBoolean("alarm_toggle", false)) {
        alarmToggle.setChecked(true);
    } else {
        alarmToggle.setChecked(false);
    }
}
 
Example 6
Source File: ActiveUserFgPresenter.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * 关注某个好友</br>
 * 
 * @param user
 */
public void followUser(final CommUser user, final ToggleButton toggleButton) {
    if (isMySelf(user)) {
        toggleButton.setChecked(!toggleButton.isChecked());
        return;
    }
    mCommunitySDK.followUser(user, new SimpleFetchListener<Response>() {

        @Override
        public void onComplete(Response response) {
            if (response.errCode == ErrorCode.NO_ERROR) {
                ToastMsg.showShortMsgByResName("umeng_comm_follow_user_success");
                toggleButton.setChecked(true);
                DatabaseAPI.getInstance().getFollowDBAPI().follow(user);
                // 改变状态
                List<CommUser> dataSource = mActiveUserFgView.getBindDataSource();
                int Index = dataSource.indexOf(user);
                dataSource.get(Index).extraData.putBoolean(Constants.IS_FOCUSED, true);
                mActiveUserFgView.notifyDataSetChanged();

                // 发送关注用户的广播
                BroadcastUtils.sendUserFollowBroadcast(mContext, user);
                BroadcastUtils.sendCountUserBroadcast(mContext, 1);
                return;
            }
            if (response.errCode == ErrorCode.ERROR_USER_FOCUSED) {
                ToastMsg.showShortMsgByResName("umeng_comm_user_has_focused");
                user.isFollowed = true;
                toggleButton.setChecked(true);
                return;
            }

            ToastMsg.showShortMsgByResName("umeng_comm_follow_user_failed");
            toggleButton.setChecked(false);
        }
    });
}
 
Example 7
Source File: SettingActivity.java    From AnimeTaste with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	mContext = this;
	ShareSDK.initSDK(mContext);
	setContentView(R.layout.activity_setting);
	getSupportActionBar().setDisplayShowTitleEnabled(false);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	mRecommand = findViewById(R.id.recommend);
	mSuggestion = findViewById(R.id.suggestion);
	mFocusUs = findViewById(R.id.focus_us);
	mCancelAuth = findViewById(R.id.cancel_auth);
	mRateForUs = findViewById(R.id.rate_for_us);
       mClearCache = findViewById(R.id.clear_cache);

	mSwitchOnlyWifi = (ToggleButton) findViewById(R.id.switch_wifi);
	mSwitchUseHD = (ToggleButton) findViewById(R.id.switch_hd);

	mSharedPreferences = PreferenceManager
			.getDefaultSharedPreferences(this);

	mRecommand.setOnClickListener(this);
	mSuggestion.setOnClickListener(this);
	mFocusUs.setOnClickListener(this);
	mSwitchOnlyWifi.setOnCheckedChangeListener(this);
	mSwitchUseHD.setOnCheckedChangeListener(this);
	mCancelAuth.setOnClickListener(this);
	mRateForUs.setOnClickListener(this);
       mClearCache.setOnClickListener(this);

	mSwitchOnlyWifi.setChecked(mSharedPreferences.getBoolean("only_wifi",
			true));
	mSwitchUseHD.setChecked(mSharedPreferences.getBoolean("use_hd", true));
}
 
Example 8
Source File: RawPrivateKeyActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private void initView() {
    findViewById(R.id.ibtn_back).setOnClickListener(new IBackClickListener());
    pager = (OverScrollableViewPager) findViewById(R.id.pager);
    tbtnDice = (ToggleButton) findViewById(R.id.tbtn_dice);
    tbtnBinary = (ToggleButton) findViewById(R.id.tbtn_binary);
    pager.setAdapter(adapter);
    pager.setCurrentItem(0);
    tbtnDice.setChecked(true);
    tbtnBinary.setChecked(false);
    tbtnDice.setOnClickListener(this);
    tbtnBinary.setOnClickListener(this);
    pager.setOnPageChangeListener(this);
}
 
Example 9
Source File: ActiveUserFgPresenter.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * 取消关注某个好友</br>
 * 
 * @param user
 */
public void cancelFollowUser(final CommUser user, final ToggleButton toggleButton) {
    if (isMySelf(user)) {
        toggleButton.setChecked(!toggleButton.isChecked());
        return;
    }
    mCommunitySDK.cancelFollowUser(user, new SimpleFetchListener<Response>() {

        @Override
        public void onComplete(Response response) {
            if (response.errCode == ErrorCode.NO_ERROR) {
                ToastMsg.showShortMsgByResName("umeng_comm_follow_cancel_success");
                toggleButton.setChecked(false);
                DatabaseAPI.getInstance().getFollowDBAPI().unfollow(user);
                // 改变状态
                int Index = mActiveUserFgView.getBindDataSource().indexOf(user);
                mActiveUserFgView.getBindDataSource().get(Index).extraData.putBoolean(
                        Constants.IS_FOCUSED,
                        false);
                mActiveUserFgView.notifyDataSetChanged();

                // 发送取消关注的广播
                BroadcastUtils.sendUserCancelFollowBroadcast(mContext, user);
                BroadcastUtils.sendCountUserBroadcast(mContext, -1);
                DatabaseAPI.getInstance().getFeedDBAPI().deleteFriendFeed(user.id);
                return;
            }
            if (response.errCode == ErrorCode.ERROR_USER_NOT_FOCUSED) {
                ToastMsg.showShortMsgByResName("umeng_comm_user_has_not_focused");
                user.isFollowed = false;
                toggleButton.setChecked(false);
                return;
            }

            ToastMsg.showShortMsgByResName("umeng_comm_follow_user_failed");
            toggleButton.setChecked(true);
        }
    });
}
 
Example 10
Source File: BinarySetting.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public View getView(Context context, ViewGroup root) {
    final BinarySetting self = this;

    View settingView = LayoutInflater.from(context).inflate(getLayoutId(), root, false);
    TextView title = (TextView) settingView.findViewById(R.id.setting_title);
    TextView description = (TextView) settingView.findViewById(R.id.setting_description);
    ToggleButton button = (ToggleButton) settingView.findViewById(R.id.toggle_button);
    View divider = settingView.findViewById(R.id.divider);

    divider.setBackgroundColor(isUseLightColorScheme() ? context.getResources().getColor(R.color.white_with_10) : context.getResources().getColor(R.color.black_with_10));
    title.setTextColor(isUseLightColorScheme() ? Color.WHITE : Color.BLACK);
    description.setTextColor(isUseLightColorScheme() ? context.getResources().getColor(R.color.white_with_35) : context.getResources().getColor(R.color.black_with_60));

    title.setText(getTitle());
    description.setText(getDescription());
    button.setChecked(currentState);

    // Hide the description if it's null
    description.setVisibility(getDescription() == null ? View.GONE : View.VISIBLE);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(@NonNull View v) {
            currentState = ((ToggleButton) v).isChecked();
            fireSettingChangedAdapter(self, currentState);
        }
    });

    return settingView;
}
 
Example 11
Source File: EmoticonsKeyBoardPopWindow.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public void showPopupWindow(ToggleButton toggleButton) {
    if (this.isShowing()) {
        this.dismiss();
        toggleButton.setChecked(false);
    } else {
        show();
        toggleButton.setChecked(true);
    }
}
 
Example 12
Source File: ControllerActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mActivity.getLayoutInflater().inflate(R.layout.layout_controller_streamitem_title, parent, false);
    }

    // Tag
    convertView.setTag(groupPosition);

    // UI
    TextView nameTextView = (TextView) convertView.findViewById(R.id.nameTextView);
    String[] names = getResources().getStringArray(R.array.controller_stream_items);
    nameTextView.setText(names[groupPosition]);

    ToggleButton enableToggleButton = (ToggleButton) convertView.findViewById(R.id.enableToggleButton);
    enableToggleButton.setTag(groupPosition);
    enableToggleButton.setChecked(mSensorData[groupPosition].enabled);
    enableToggleButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // Set onclick to action_down to avoid losing state because the button is recreated when notifiydatasetchanged is called and it could be really fast (before the user has time to generate a ACTION_UP event)
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                ToggleButton button = (ToggleButton) view;
                button.setChecked(!button.isChecked());
                onClickToggle(view);
                return true;
            }
            return false;
        }
    });

    return convertView;
}
 
Example 13
Source File: TerminalFragment.java    From SimpleUsbTerminal with MIT License 5 votes vote down vote up
private void toggle(View v) {
    ToggleButton btn = (ToggleButton) v;
    if (connected != Connected.True) {
        btn.setChecked(!btn.isChecked());
        Toast.makeText(getActivity(), "not connected", Toast.LENGTH_SHORT).show();
        return;
    }
    String ctrl = "";
    try {
        if (btn.equals(rtsBtn)) { ctrl = "RTS"; usbSerialPort.setRTS(btn.isChecked()); }
        if (btn.equals(dtrBtn)) { ctrl = "DTR"; usbSerialPort.setDTR(btn.isChecked()); }
    } catch (IOException e) {
        status("set" + ctrl + " failed: " + e.getMessage());
    }
}
 
Example 14
Source File: BinarySwitchCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void build(@NonNull BinarySwitchCard card) {
    super.build(card);
    clickListener = card.getClickListener();

    TextView title = (TextView)this.findViewById(R.id.title);
    title.setText(card.getTitle());
    if(card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView)this.findViewById(R.id.description);
    description.setText(card.getDescription());
    if(card.getTitleColor() != -1) {
        description.setTextColor(card.getTitleColor());
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    ToggleButton button = (ToggleButton) this.findViewById(R.id.toggle);
    if (button != null) {
        button.setOnClickListener(this);
        button.setChecked(card.getToggleChecked());
    }
}
 
Example 15
Source File: LogsFragment.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.logs, container, false);
    tbCall = (ToggleButton) v.findViewById(R.id.calls);
    tbCall.setOnClickListener(this);
    tbSMS = (ToggleButton) v.findViewById(R.id.sms);
    tbSMS.setOnClickListener(this);
    tbMMS = (ToggleButton) v.findViewById(R.id.mms);
    tbMMS.setOnClickListener(this);
    tbData = (ToggleButton) v.findViewById(R.id.data);
    tbData.setOnClickListener(this);
    tbIn = (ToggleButton) v.findViewById(R.id.in);
    tbIn.setOnClickListener(this);
    tbOut = (ToggleButton) v.findViewById(R.id.out);
    tbOut.setOnClickListener(this);
    tbPlan = (ToggleButton) v.findViewById(R.id.plan);
    tbPlan.setOnClickListener(this);
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this
            .getActivity());
    tbCall.setChecked(p.getBoolean(PREF_CALL, true));
    tbSMS.setChecked(p.getBoolean(PREF_SMS, true));
    tbMMS.setChecked(p.getBoolean(PREF_MMS, true));
    tbData.setChecked(p.getBoolean(PREF_DATA, true));
    tbIn.setChecked(p.getBoolean(PREF_IN, true));
    tbOut.setChecked(p.getBoolean(PREF_OUT, true));

    String[] directions = getResources().getStringArray(R.array.direction_calls);
    tbIn.setText(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOn(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOff(directions[DataProvider.DIRECTION_IN]);
    tbOut.setText(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOn(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOff(directions[DataProvider.DIRECTION_OUT]);

    if (planId >= 0L) {
        setPlanId(planId);
    }

    return v;
}
 
Example 16
Source File: RecipeActivity.java    From app-indexing with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
Example 17
Source File: PasswordEditText.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public PasswordEditText(Context context, AttributeSet attrs) {
	super(context, attrs);

	// 方式1获取属性
	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.PasswordEditText);

	hintString = a
			.getString(R.styleable.PasswordEditText_PasswordEditText_hint);

	passwordEditTextToggle = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_toggle);

	hintColor = a.getColor(R.styleable.PasswordEditText_PasswordEditText_hint_color,getContext().getResources().getColor(R.color.gray_half_5));

	passwordEditTextIcon = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_icon);


	passwordEditTextBackground = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_background);

	a.recycle();

	View view = LayoutInflater.from(context).inflate(
			R.layout.password_edittext, null);

	tbPasswordEditTextToggle = (ToggleButton) view
			.findViewById(R.id.tb_password_eidttext_toggle);

	if (passwordEditTextToggle != null)
		tbPasswordEditTextToggle
				.setBackgroundDrawable(passwordEditTextToggle);

	et = (EditText) view.findViewById(R.id.et_password_eidttext_edittext);
	if (!TextUtils.isEmpty(hintString))
		et.setHint(hintString);

	et.setHintTextColor(hintColor);


	rl = (RelativeLayout) view
			.findViewById(R.id.rl);
	if(passwordEditTextBackground !=null)
		rl.setBackgroundDrawable(passwordEditTextBackground);

	ivPasswordEditTextIcon = (ImageView) view.findViewById(R.id.iv_with_del_eidttext_icon);
	if (passwordEditTextIcon != null)
		ivPasswordEditTextIcon
				.setImageDrawable(passwordEditTextIcon);




	tbPasswordEditTextToggle.setChecked(true);

	tbPasswordEditTextToggle
			.setOnCheckedChangeListener(new OnCheckedChangeListener() {

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

					if (!isChecked) {
						et.setTransformationMethod(HideReturnsTransformationMethod
								.getInstance());
					} else {
						et.setTransformationMethod(PasswordTransformationMethod
								.getInstance());
					}
					et.postInvalidate();

					Editable editable = et.getText();
					et.setSelection(editable.length());
				}
			});

	// ivPasswordEditTextToggle.setOnClickListener(new OnClickListener() {
	// @Override
	// public void onClick(View v) {
	//
	// if (tbPasswordEditTextToggle.isChecked()) {
	// et.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
	// } else {
	// et.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);
	// }
	// }
	// });
	// 给编辑框添加文本改变事件
	// et.addTextChangedListener(new MyTextWatcher());

	// 把获得的view加载到这个控件中
	addView(view);
}
 
Example 18
Source File: ThermostatActionEditFragment.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    
    mSettingsSwitch = (ToggleButton) view.findViewById(R.id.toggle);

    mFollowScheduleGroup = (RelativeLayout) view.findViewById(R.id.follow_schedule_group);
    mSettingsContainer = (LinearLayout) view.findViewById(R.id.settings_group);
    mHeatContainer = (LinearLayout) view.findViewById(R.id.high_temp_container);
    mCoolContainer = (LinearLayout) view.findViewById(R.id.cool_temp_container);
    lowTempLabelText = (Version1TextView) view.findViewById(R.id.low_temp_label_text);
    lowTempLabelSubText = (Version1TextView) view.findViewById(R.id.low_temp_label_sub_text);

    mModeText = (Version1TextView) view.findViewById(R.id.mode_text);
    mHighTempText = (Version1TextView) view.findViewById(R.id.high_temp_text);
    mLowTempText = (Version1TextView) view.findViewById(R.id.low_temp_text);
    highTempLabelSubtext = (Version1TextView) view.findViewById(R.id.high_setpoint_copy);
    highTempLabelText = (Version1TextView) view.findViewById(R.id.high_copy);
    modelLabelText = (Version1TextView) view.findViewById(R.id.toggle2);
    scheduleLableText = (Version1TextView) view.findViewById(R.id.title);
    scheduleLableSubtext = (Version1TextView) view.findViewById(R.id.description);
    modeChevron = (ImageView) view.findViewById(R.id.mode_chevron);
    coolChevron = (ImageView) view.findViewById(R.id.cool_chevron);
    heatChevron = (ImageView) view.findViewById(R.id.heat_chevron);

    mSettingsSwitch.setChecked(true);
    mSettingsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mSettingsContainer.setVisibility(View.GONE);
                saveSettings(createThermostatAction());
            } else {
                mSettingsContainer.setVisibility(View.VISIBLE);
                if(thermostatModel!=null){
                    switchThermostatMode(thermostatModel.getMode());
                }
            }
        }
    });

    LinearLayout mModeContainer = (LinearLayout) view.findViewById(R.id.mode_container);
    mModeContainer.setOnClickListener(this);
    mHeatContainer.setOnClickListener(this);
    mCoolContainer.setOnClickListener(this);

    thermostatID = getArguments().getString(TSTAT_ID, "");

    return view;
}
 
Example 19
Source File: RecipeActivity.java    From search-samples with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
Example 20
Source File: PacketListActivity.java    From sniffer154 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Updates the status of the "Capture" button.
 * 
 * The button is checked if a capture is in progress, unchecked otherwise.
 * The button is enabled if a sniffer is attached to the android device,
 * disabled otherwise
 */
private void updateCaptureButton() {
	AppSniffer154 app = (AppSniffer154) getApplication();
	ToggleButton tb = (ToggleButton) findViewById(R.id.toggleCapture);
	tb.setChecked(app.isSniffingInProgress());
	tb.setEnabled(app.isSniffingEnabled());
}