Search in sources :

Example 26 with CompoundButton

use of android.widget.CompoundButton in project AndroidTraining by mixi-inc.

the class ListMenuItemView method setCheckable.

public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
        return;
    }
    if (mRadioButton == null) {
        insertRadioButton();
    }
    if (mCheckBox == null) {
        insertCheckBox();
    }
    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;
    if (mItemData.isExclusiveCheckable()) {
        compoundButton = mRadioButton;
        otherCompoundButton = mCheckBox;
    } else {
        compoundButton = mCheckBox;
        otherCompoundButton = mRadioButton;
    }
    if (checkable) {
        compoundButton.setChecked(mItemData.isChecked());
        final int newVisibility = checkable ? VISIBLE : GONE;
        if (compoundButton.getVisibility() != newVisibility) {
            compoundButton.setVisibility(newVisibility);
        }
        // Make sure the other compound button isn't visible
        if (otherCompoundButton.getVisibility() != GONE) {
            otherCompoundButton.setVisibility(GONE);
        }
    } else {
        mCheckBox.setVisibility(GONE);
        mRadioButton.setVisibility(GONE);
    }
}
Also used : CompoundButton(android.widget.CompoundButton)

Example 27 with CompoundButton

use of android.widget.CompoundButton in project KeepScore by nolanlawson.

the class SavedGameAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    // view wrapper optimization per Romain Guy
    final Context context = parent.getContext();
    ViewWrapper viewWrapper;
    if (view == null) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.saved_game_item, parent, false);
        viewWrapper = new ViewWrapper(view);
        view.setTag(viewWrapper);
    } else {
        viewWrapper = (ViewWrapper) view.getTag();
    }
    TextView titleTextView = viewWrapper.getTitleTextView();
    TextView numPlayersTextView = viewWrapper.getNumPlayersTextView();
    TextView subtitleTextView = viewWrapper.getSubtitleTextView();
    TextView savedTextView = viewWrapper.getSavedTextView();
    CheckBox checkBox = viewWrapper.getCheckBox();
    final GameSummary game = getItem(position);
    StringBuilder gameTitle = new StringBuilder();
    if (!TextUtils.isEmpty(game.getName())) {
        gameTitle.append(game.getName()).append(" ").append(context.getString(R.string.text_game_name_separator)).append(" ");
    }
    // Player 1, Player 2, Player3 etc.
    gameTitle.append(TextUtils.join(", ", CollectionUtil.transformWithIndices(game.getPlayerNames(), new FunctionWithIndex<String, CharSequence>() {

        @Override
        public CharSequence apply(String playerName, int index) {
            return PlayerScore.toDisplayName(playerName, index, context);
        }
    })));
    titleTextView.setText(gameTitle);
    numPlayersTextView.setText(Integer.toString(game.getPlayerNames().size()));
    numPlayersTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimensionPixelSize(// two
    game.getPlayerNames().size() >= 10 ? // digit
    R.dimen.saved_game_num_players_text_size_two_digits : R.dimen.saved_game_num_players_text_size_one_digit));
    int numRounds = game.getNumRounds();
    int roundsResId = numRounds == 1 ? R.string.text_format_rounds_singular : R.string.text_format_rounds;
    String rounds = String.format(context.getString(roundsResId), numRounds);
    subtitleTextView.setText(rounds);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getContext().getString(R.string.date_format), Locale.getDefault());
    savedTextView.setText(simpleDateFormat.format(new Date(game.getDateSaved())));
    checkBox.setOnCheckedChangeListener(null);
    checkBox.setChecked(checked.contains(game));
    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                checked.add(game);
            } else {
                checked.remove(game);
            }
            if (onCheckChangedRunnable != null) {
                onCheckChangedRunnable.run();
            }
        }
    });
    log.d("saved long is: %s", game.getDateSaved());
    return view;
}
Also used : Context(android.content.Context) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) GameSummary(com.nolanlawson.keepscore.db.GameSummary) Date(java.util.Date) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) SimpleDateFormat(java.text.SimpleDateFormat) CompoundButton(android.widget.CompoundButton)

Example 28 with CompoundButton

use of android.widget.CompoundButton in project bee by orhanobut.

the class SettingsAdapter method createCheckBox.

private View createCheckBox(ViewGroup parent, MethodInfo methodInfo) {
    final Method method = methodInfo.getMethod();
    final Object instance = methodInfo.getInstance();
    final Context context = parent.getContext();
    View view = inflater.inflate(R.layout.item_settings_checkbox, parent, false);
    ((TextView) view.findViewById(R.id.title)).setText(methodInfo.getTitle());
    CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            try {
                method.invoke(instance, isChecked);
            } catch (Exception e) {
                Log.e("Bee", e.getMessage());
            }
            PrefHelper.setBoolean(context, method.getName(), isChecked);
        }
    });
    checkBox.setChecked(PrefHelper.getBoolean(context, method.getName()));
    return view;
}
Also used : Context(android.content.Context) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) Method(java.lang.reflect.Method) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton)

Example 29 with CompoundButton

use of android.widget.CompoundButton in project android by owncloud.

the class EditShareFragment method refreshUiFromState.

/**
     * Updates the UI with the current permissions in the edited {@OCShare}
     *
     * @param editShareView     Root view in the fragment.
     */
private void refreshUiFromState(View editShareView) {
    if (editShareView != null) {
        setPermissionsListening(editShareView, false);
        int sharePermissions = mShare.getPermissions();
        boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType());
        OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mAccount);
        boolean isNotReshareableFederatedSupported = (serverVersion != null && serverVersion.isNotReshareableFederatedSupported());
        CompoundButton compound;
        compound = (CompoundButton) editShareView.findViewById(R.id.canShareSwitch);
        if (isFederated && !isNotReshareableFederatedSupported) {
            compound.setVisibility(View.INVISIBLE);
        }
        compound.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);
        compound = (CompoundButton) editShareView.findViewById(R.id.canEditSwitch);
        int anyUpdatePermission = OCShare.CREATE_PERMISSION_FLAG | OCShare.UPDATE_PERMISSION_FLAG | OCShare.DELETE_PERMISSION_FLAG;
        boolean canEdit = (sharePermissions & anyUpdatePermission) > 0;
        compound.setChecked(canEdit);
        boolean areEditOptionsAvailable = !isFederated || isNotReshareableFederatedSupported;
        if (mFile.isFolder() && areEditOptionsAvailable) {
            /// TODO change areEditOptionsAvailable in order to delete !isFederated
            // from checking when iOS is ready
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditCreateCheckBox);
            compound.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditChangeCheckBox);
            compound.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditDeleteCheckBox);
            compound.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
        }
        setPermissionsListening(editShareView, true);
    }
}
Also used : OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) CompoundButton(android.widget.CompoundButton)

Example 30 with CompoundButton

use of android.widget.CompoundButton in project GalleryFinal by pengjianbo.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mLvPhoto = (HorizontalListView) findViewById(R.id.lv_photo);
    mPhotoList = new ArrayList<>();
    mChoosePhotoListAdapter = new ChoosePhotoListAdapter(this, mPhotoList);
    mLvPhoto.setAdapter(mChoosePhotoListAdapter);
    mOpenGallery = (Button) findViewById(R.id.btn_open_gallery);
    mRbMutiSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlMaxSize.setVisibility(View.VISIBLE);
                mLlForceCrop.setVisibility(View.GONE);
            } else {
                if (mCbEdit.isChecked()) {
                    mLlForceCrop.setVisibility(View.VISIBLE);
                }
                mLlMaxSize.setVisibility(View.GONE);
            }
        }
    });
    mCbEdit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlEdit.setVisibility(View.VISIBLE);
            } else {
                mLlEdit.setVisibility(View.GONE);
            }
        }
    });
    mCbCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlCropSize.setVisibility(View.VISIBLE);
                mCbCropReplaceSource.setVisibility(View.VISIBLE);
                if (mRbSingleSelect.isChecked()) {
                    mLlForceCrop.setVisibility(View.VISIBLE);
                }
            } else {
                mLlCropSize.setVisibility(View.GONE);
                mCbCropReplaceSource.setVisibility(View.INVISIBLE);
                mLlForceCrop.setVisibility(View.GONE);
            }
        }
    });
    mCbRotate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mCbRotateReplaceSource.setVisibility(View.VISIBLE);
            } else {
                mCbRotateReplaceSource.setVisibility(View.INVISIBLE);
            }
        }
    });
    mCbOpenForceCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mCbOpenForceCropEdit.setVisibility(View.VISIBLE);
            } else {
                mCbOpenForceCropEdit.setVisibility(View.INVISIBLE);
            }
        }
    });
    mOpenGallery.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //公共配置都可以在application中配置,这里只是为了代码演示而写在此处
            ThemeConfig themeConfig = null;
            if (mRbThemeDefault.isChecked()) {
                themeConfig = ThemeConfig.DEFAULT;
            } else if (mRbThemeDark.isChecked()) {
                themeConfig = ThemeConfig.DARK;
            } else if (mRbThemeCyan.isChecked()) {
                themeConfig = ThemeConfig.CYAN;
            } else if (mRbThemeOrange.isChecked()) {
                themeConfig = ThemeConfig.ORANGE;
            } else if (mRbThemeGreen.isChecked()) {
                themeConfig = ThemeConfig.GREEN;
            } else if (mRbThemeTeal.isChecked()) {
                themeConfig = ThemeConfig.TEAL;
            } else if (mRbThemeCustom.isChecked()) {
                ThemeConfig theme = new ThemeConfig.Builder().setTitleBarBgColor(Color.rgb(0xFF, 0x57, 0x22)).setTitleBarTextColor(Color.BLACK).setTitleBarIconColor(Color.BLACK).setFabNornalColor(Color.RED).setFabPressedColor(Color.BLUE).setCheckNornalColor(Color.WHITE).setCheckSelectedColor(Color.BLACK).setIconBack(R.mipmap.ic_action_previous_item).setIconRotate(R.mipmap.ic_action_repeat).setIconCrop(R.mipmap.ic_action_crop).setIconCamera(R.mipmap.ic_action_camera).build();
                themeConfig = theme;
            }
            FunctionConfig.Builder functionConfigBuilder = new FunctionConfig.Builder();
            cn.finalteam.galleryfinal.ImageLoader imageLoader;
            PauseOnScrollListener pauseOnScrollListener = null;
            if (mRbUil.isChecked()) {
                imageLoader = new UILImageLoader();
                pauseOnScrollListener = new UILPauseOnScrollListener(false, true);
            } else if (mRbXutils.isChecked()) {
                imageLoader = new XUtils2ImageLoader(MainActivity.this);
            } else if (mRbXutils3.isChecked()) {
                imageLoader = new XUtilsImageLoader();
            } else if (mRbGlide.isChecked()) {
                imageLoader = new GlideImageLoader();
                pauseOnScrollListener = new GlidePauseOnScrollListener(false, true);
            } else if (mRbFresco.isChecked()) {
                imageLoader = new FrescoImageLoader(MainActivity.this);
            } else {
                imageLoader = new PicassoImageLoader();
                pauseOnScrollListener = new PicassoPauseOnScrollListener(false, true);
            }
            boolean muti = false;
            if (mRbSingleSelect.isChecked()) {
                muti = false;
            } else {
                muti = true;
                if (TextUtils.isEmpty(mEtMaxSize.getText().toString())) {
                    Toast.makeText(getApplicationContext(), "请输入MaxSize", Toast.LENGTH_SHORT).show();
                    return;
                }
                int maxSize = Integer.parseInt(mEtMaxSize.getText().toString());
                functionConfigBuilder.setMutiSelectMaxSize(maxSize);
            }
            final boolean mutiSelect = muti;
            if (mCbEdit.isChecked()) {
                functionConfigBuilder.setEnableEdit(true);
            }
            if (mCbRotate.isChecked()) {
                functionConfigBuilder.setEnableRotate(true);
                if (mCbRotateReplaceSource.isChecked()) {
                    functionConfigBuilder.setRotateReplaceSource(true);
                }
            }
            if (mCbCrop.isChecked()) {
                functionConfigBuilder.setEnableCrop(true);
                if (!TextUtils.isEmpty(mEtCropWidth.getText().toString())) {
                    int width = Integer.parseInt(mEtCropWidth.getText().toString());
                    functionConfigBuilder.setCropWidth(width);
                }
                if (!TextUtils.isEmpty(mEtCropHeight.getText().toString())) {
                    int height = Integer.parseInt(mEtCropHeight.getText().toString());
                    functionConfigBuilder.setCropHeight(height);
                }
                if (mCbCropSquare.isChecked()) {
                    functionConfigBuilder.setCropSquare(true);
                }
                if (mCbCropReplaceSource.isChecked()) {
                    functionConfigBuilder.setCropReplaceSource(true);
                }
                if (mCbOpenForceCrop.isChecked() && mRbSingleSelect.isChecked()) {
                    functionConfigBuilder.setForceCrop(true);
                    if (mCbOpenForceCropEdit.isChecked()) {
                        functionConfigBuilder.setForceCropEdit(true);
                    }
                }
            }
            if (mCbShowCamera.isChecked()) {
                functionConfigBuilder.setEnableCamera(true);
            }
            if (mCbPreview.isChecked()) {
                functionConfigBuilder.setEnablePreview(true);
            }
            //添加过滤集合
            functionConfigBuilder.setSelected(mPhotoList);
            final FunctionConfig functionConfig = functionConfigBuilder.build();
            CoreConfig coreConfig = new CoreConfig.Builder(MainActivity.this, imageLoader, themeConfig).setFunctionConfig(functionConfig).setPauseOnScrollListener(pauseOnScrollListener).setNoAnimcation(mCbNoAnimation.isChecked()).build();
            GalleryFinal.init(coreConfig);
            ActionSheet.createBuilder(MainActivity.this, getSupportFragmentManager()).setCancelButtonTitle("取消(Cancel)").setOtherButtonTitles("打开相册(Open Gallery)", "拍照(Camera)", "裁剪(Crop)", "编辑(Edit)").setCancelableOnTouchOutside(true).setListener(new ActionSheet.ActionSheetListener() {

                @Override
                public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
                }

                @Override
                public void onOtherButtonClick(ActionSheet actionSheet, int index) {
                    String path = "/sdcard/pk1-2.jpg";
                    switch(index) {
                        case 0:
                            if (mutiSelect) {
                                GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
                            } else {
                                GalleryFinal.openGallerySingle(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
                            }
                            break;
                        case 1:
                            GalleryFinal.openCamera(REQUEST_CODE_CAMERA, functionConfig, mOnHanlderResultCallback);
                            break;
                        case 2:
                            if (new File(path).exists()) {
                                GalleryFinal.openCrop(REQUEST_CODE_CROP, functionConfig, path, mOnHanlderResultCallback);
                            } else {
                                Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case 3:
                            if (new File(path).exists()) {
                                GalleryFinal.openEdit(REQUEST_CODE_EDIT, functionConfig, path, mOnHanlderResultCallback);
                            } else {
                                Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
                            }
                            break;
                        default:
                            break;
                    }
                }
            }).show();
        }
    });
    initImageLoader(this);
    initFresco();
    x.Ext.init(getApplication());
}
Also used : FunctionConfig(cn.finalteam.galleryfinal.FunctionConfig) CoreConfig(cn.finalteam.galleryfinal.CoreConfig) XUtilsImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtilsImageLoader) ActionSheet(com.baoyz.actionsheet.ActionSheet) PicassoImageLoader(cn.finalteam.galleryfinal.sample.loader.PicassoImageLoader) PicassoPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.PicassoPauseOnScrollListener) GlideImageLoader(cn.finalteam.galleryfinal.sample.loader.GlideImageLoader) Toolbar(android.support.v7.widget.Toolbar) XUtils2ImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtils2ImageLoader) UILPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.UILPauseOnScrollListener) UILImageLoader(cn.finalteam.galleryfinal.sample.loader.UILImageLoader) View(android.view.View) HorizontalListView(cn.finalteam.galleryfinal.widget.HorizontalListView) ThemeConfig(cn.finalteam.galleryfinal.ThemeConfig) UILPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.UILPauseOnScrollListener) PauseOnScrollListener(cn.finalteam.galleryfinal.PauseOnScrollListener) GlidePauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.GlidePauseOnScrollListener) PicassoPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.PicassoPauseOnScrollListener) FrescoImageLoader(cn.finalteam.galleryfinal.sample.loader.FrescoImageLoader) XUtils2ImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtils2ImageLoader) XUtilsImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtilsImageLoader) UILImageLoader(cn.finalteam.galleryfinal.sample.loader.UILImageLoader) GlideImageLoader(cn.finalteam.galleryfinal.sample.loader.GlideImageLoader) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) FrescoImageLoader(cn.finalteam.galleryfinal.sample.loader.FrescoImageLoader) PicassoImageLoader(cn.finalteam.galleryfinal.sample.loader.PicassoImageLoader) GlidePauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.GlidePauseOnScrollListener) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Aggregations

CompoundButton (android.widget.CompoundButton)235 View (android.view.View)118 TextView (android.widget.TextView)95 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)60 ImageView (android.widget.ImageView)48 CheckBox (android.widget.CheckBox)42 AdapterView (android.widget.AdapterView)25 Button (android.widget.Button)22 DialogInterface (android.content.DialogInterface)21 LayoutInflater (android.view.LayoutInflater)20 OnClickListener (android.view.View.OnClickListener)18 Intent (android.content.Intent)17 SeekBar (android.widget.SeekBar)17 Switch (android.widget.Switch)17 SwitchCompat (android.support.v7.widget.SwitchCompat)15 AlertDialog (android.app.AlertDialog)13 ArrayList (java.util.ArrayList)12 Context (android.content.Context)11 OnClickListener (android.content.DialogInterface.OnClickListener)11 Cursor (android.database.Cursor)11