Search in sources :

Example 1 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project cropper by edmodo.

the class MainActivity method onCreate.

// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    // Initialize Views.
    final ToggleButton fixedAspectRatioToggleButton = (ToggleButton) findViewById(R.id.fixedAspectRatioToggle);
    final TextView aspectRatioXTextView = (TextView) findViewById(R.id.aspectRatioX);
    final SeekBar aspectRatioXSeekBar = (SeekBar) findViewById(R.id.aspectRatioXSeek);
    final TextView aspectRatioYTextView = (TextView) findViewById(R.id.aspectRatioY);
    final SeekBar aspectRatioYSeekBar = (SeekBar) findViewById(R.id.aspectRatioYSeek);
    final Spinner guidelinesSpinner = (Spinner) findViewById(R.id.showGuidelinesSpin);
    final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
    final ImageView croppedImageView = (ImageView) findViewById(R.id.croppedImageView);
    final Button cropButton = (Button) findViewById(R.id.Button_crop);
    // Initializes fixedAspectRatio toggle button.
    fixedAspectRatioToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            cropImageView.setFixedAspectRatio(isChecked);
            cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
            aspectRatioXSeekBar.setEnabled(isChecked);
            aspectRatioYSeekBar.setEnabled(isChecked);
        }
    });
    // Set seek bars to be disabled until toggle button is checked.
    aspectRatioXSeekBar.setEnabled(false);
    aspectRatioYSeekBar.setEnabled(false);
    aspectRatioXTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));
    aspectRatioYTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));
    // Initialize aspect ratio X SeekBar.
    aspectRatioXSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar aspectRatioXSeekBar, int progress, boolean fromUser) {
            if (progress < 1) {
                aspectRatioXSeekBar.setProgress(1);
            }
            cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
            aspectRatioXTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }
    });
    // Initialize aspect ratio Y SeekBar.
    aspectRatioYSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar aspectRatioYSeekBar, int progress, boolean fromUser) {
            if (progress < 1) {
                aspectRatioYSeekBar.setProgress(1);
            }
            cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
            aspectRatioYTextView.setText(String.valueOf(aspectRatioYSeekBar.getProgress()));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }
    });
    // Set up the Guidelines Spinner.
    guidelinesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            cropImageView.setGuidelines(i);
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
        // Do nothing.
        }
    });
    guidelinesSpinner.setSelection(GUIDELINES_ON_TOUCH);
    // Initialize the Crop button.
    cropButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Bitmap croppedImage = cropImageView.getCroppedImage();
            croppedImageView.setImageBitmap(croppedImage);
        }
    });
}
Also used : ToggleButton(android.widget.ToggleButton) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) Spinner(android.widget.Spinner) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) CropImageView(com.edmodo.cropper.CropImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) Bitmap(android.graphics.Bitmap) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) CropImageView(com.edmodo.cropper.CropImageView) ImageView(android.widget.ImageView) CropImageView(com.edmodo.cropper.CropImageView) CompoundButton(android.widget.CompoundButton)

Example 2 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project k-9 by k9mail.

the class AccountSetupBasics method initializeViewListeners.

private void initializeViewListeners() {
    mEmailView.addTextChangedListener(this);
    mPasswordView.addTextChangedListener(this);
    mClientCertificateCheckBox.setOnCheckedChangeListener(this);
    mClientCertificateSpinner.setOnClientCertificateChangedListener(this);
    mShowPasswordCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            showPassword(isChecked);
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CompoundButton(android.widget.CompoundButton)

Example 3 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project SeriesGuide by UweTrottmann.

the class DataLiberationFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_data_liberation, container, false);
    unbinder = ButterKnife.bind(this, v);
    progressBar.setVisibility(View.GONE);
    // setup listeners
    buttonExport.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryDataLiberationAction(REQUEST_CODE_EXPORT);
        }
    });
    checkBoxImportWarning.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateImportButtonEnabledState();
        }
    });
    checkBoxShows.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateImportButtonEnabledState();
        }
    });
    checkBoxLists.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateImportButtonEnabledState();
        }
    });
    checkBoxMovies.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateImportButtonEnabledState();
        }
    });
    buttonImport.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryDataLiberationAction(REQUEST_CODE_IMPORT);
        }
    });
    // as we use Storage Access Framework in this case
    if (AndroidUtils.isKitKatOrHigher()) {
        buttonShowsExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(DataLiberationFragment.this, JsonExportTask.EXPORT_JSON_FILE_SHOWS, REQUEST_CODE_SHOWS_EXPORT_URI);
            }
        });
        buttonShowsImportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectImportFile(DataLiberationFragment.this, REQUEST_CODE_SHOWS_IMPORT_URI);
            }
        });
        buttonListsExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(DataLiberationFragment.this, JsonExportTask.EXPORT_JSON_FILE_LISTS, REQUEST_CODE_LISTS_EXPORT_URI);
            }
        });
        buttonListsImportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectImportFile(DataLiberationFragment.this, REQUEST_CODE_LISTS_IMPORT_URI);
            }
        });
        buttonMoviesExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(DataLiberationFragment.this, JsonExportTask.EXPORT_JSON_FILE_MOVIES, REQUEST_CODE_MOVIES_EXPORT_URI);
            }
        });
        buttonMoviesImportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectImportFile(DataLiberationFragment.this, REQUEST_CODE_MOVIES_IMPORT_URI);
            }
        });
    } else {
        buttonShowsExportFile.setVisibility(View.GONE);
        buttonShowsImportFile.setVisibility(View.GONE);
        buttonListsExportFile.setVisibility(View.GONE);
        buttonListsImportFile.setVisibility(View.GONE);
        buttonMoviesExportFile.setVisibility(View.GONE);
        buttonMoviesImportFile.setVisibility(View.GONE);
    }
    updateFileViews();
    return v;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OnClickListener(android.view.View.OnClickListener) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 4 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android_frameworks_base by ParanoidAndroid.

the class InputMethodManagerService method showInputMethodMenuInternal.

private void showInputMethodMenuInternal(boolean showSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu");
    final Context context = getUiContext();
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mImListManager.getSortedInputMethodAndSubtypeList(showSubtypes, mInputShown, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final TypedArray a = context.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        mDialogBuilder = new AlertDialog.Builder(context).setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        }).setIcon(a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogTitle));
        a.recycle();
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerService.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = ((Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch));
        hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mWindowManagerService.setHardKeyboardEnabled(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, com.android.internal.R.layout.simple_list_item_2_single_choice, imList, checkedItem);
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if ((subtypeId < 0) || (subtypeId >= im.getSubtypeCount())) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        });
        if (showSubtypes && !isScreenLocked) {
            mDialogBuilder.setPositiveButton(com.android.internal.R.string.configure_input_methods, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    showConfigureInputMethods();
                }
            });
        }
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        mSwitchingDialog.show();
    }
}
Also used : IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) AlertDialog(android.app.AlertDialog) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) DialogInterface(android.content.DialogInterface) View(android.view.View) TextView(android.widget.TextView) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Switch(android.widget.Switch) TypedArray(android.content.res.TypedArray) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) List(java.util.List) CompoundButton(android.widget.CompoundButton) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 5 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project BlurEffectForAndroidDesign by PomepuyN.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    // Get the screen width
    final int screenWidth = ImageUtils.getScreenWidth(this);
    // Find the view
    mBlurredImage = (ImageView) findViewById(R.id.blurred_image);
    mNormalImage = (ImageView) findViewById(R.id.normal_image);
    mBlurredImageHeader = (ScrollableImageView) findViewById(R.id.blurred_image_header);
    mSwitch = (Switch) findViewById(R.id.background_switch);
    mList = (ListView) findViewById(R.id.list);
    // prepare the header ScrollableImageView
    mBlurredImageHeader.setScreenWidth(screenWidth);
    // Action for the switch
    mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mBlurredImage.setAlpha(alpha);
            } else {
                mBlurredImage.setAlpha(0f);
            }
        }
    });
    // Try to find the blurred image
    final File blurredImage = new File(getFilesDir() + BLURRED_IMG_PATH);
    if (!blurredImage.exists()) {
        // launch the progressbar in ActionBar
        setProgressBarIndeterminateVisibility(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                // No image found => let's generate it!
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 2;
                Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.image, options);
                Bitmap newImg = Blur.fastblur(MainActivity.this, image, 12);
                ImageUtils.storeImage(newImg, blurredImage);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        updateView(screenWidth);
                        // And finally stop the progressbar
                        setProgressBarIndeterminateVisibility(false);
                    }
                });
            }
        }).start();
    } else {
        // The image has been found. Let's update the view
        updateView(screenWidth);
    }
    String[] strings = getResources().getStringArray(R.array.list_content);
    // Prepare the header view for our list
    headerView = new View(this);
    headerView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, TOP_HEIGHT));
    mList.addHeaderView(headerView);
    mList.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, strings));
    mList.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        /**
			 * Listen to the list scroll. This is where magic happens ;)
			 */
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Calculate the ratio between the scroll amount and the list
            // header weight to determinate the top picture alpha
            alpha = (float) -headerView.getTop() / (float) TOP_HEIGHT;
            // Apply a ceil
            if (alpha > 1) {
                alpha = 1;
            }
            // Apply on the ImageView if needed
            if (mSwitch.isChecked()) {
                mBlurredImage.setAlpha(alpha);
            }
            // Parallax effect : we apply half the scroll amount to our
            // three views
            mBlurredImage.setTop(headerView.getTop() / 2);
            mNormalImage.setTop(headerView.getTop() / 2);
            mBlurredImageHeader.handleScroll(headerView.getTop() / 2);
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.widget.AbsListView.LayoutParams) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) ListView(android.widget.ListView) Bitmap(android.graphics.Bitmap) OnScrollListener(android.widget.AbsListView.OnScrollListener) BitmapFactory(android.graphics.BitmapFactory) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Aggregations

OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)101 CompoundButton (android.widget.CompoundButton)98 View (android.view.View)78 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)40 OnClickListener (android.view.View.OnClickListener)31 CheckBox (android.widget.CheckBox)30 DialogInterface (android.content.DialogInterface)27 AdapterView (android.widget.AdapterView)24 AlertDialog (android.app.AlertDialog)23 ListView (android.widget.ListView)20 Button (android.widget.Button)19 LayoutInflater (android.view.LayoutInflater)17 ArrayList (java.util.ArrayList)17 List (java.util.List)15 OnClickListener (android.content.DialogInterface.OnClickListener)12 SuppressLint (android.annotation.SuppressLint)11 Intent (android.content.Intent)11 ViewGroup (android.view.ViewGroup)10 Cursor (android.database.Cursor)9