Search in sources :

Example 6 with RadioButton

use of android.widget.RadioButton in project XPrivacy by M66B.

the class ActivityShare method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;
    // Get data
    int userId = Util.getUserId(Process.myUid());
    final Bundle extras = getIntent().getExtras();
    final String action = getIntent().getAction();
    final int[] uids = (extras != null && extras.containsKey(cUidList) ? extras.getIntArray(cUidList) : new int[0]);
    final String restrictionName = (extras != null ? extras.getString(cRestriction) : null);
    int choice = (extras != null && extras.containsKey(cChoice) ? extras.getInt(cChoice) : -1);
    if (action.equals(ACTION_EXPORT))
        mFileName = (extras != null && extras.containsKey(cFileName) ? extras.getString(cFileName) : null);
    // License check
    if (action.equals(ACTION_IMPORT) || action.equals(ACTION_EXPORT)) {
        if (!Util.isProEnabled() && Util.hasProLicense(this) == null) {
            Util.viewUri(this, ActivityMain.cProUri);
            finish();
            return;
        }
    } else if (action.equals(ACTION_FETCH) || (action.equals(ACTION_TOGGLE) && uids.length > 1)) {
        if (Util.hasProLicense(this) == null) {
            Util.viewUri(this, ActivityMain.cProUri);
            finish();
            return;
        }
    }
    // Registration check
    if (action.equals(ACTION_SUBMIT) && !registerDevice(this)) {
        finish();
        return;
    }
    // Check whether we need a user interface
    if (extras != null && extras.containsKey(cInteractive) && extras.getBoolean(cInteractive, false))
        mInteractive = true;
    // Set layout
    setContentView(R.layout.sharelist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    // Reference controls
    final TextView tvDescription = (TextView) findViewById(R.id.tvDescription);
    final ScrollView svToggle = (ScrollView) findViewById(R.id.svToggle);
    final RadioGroup rgToggle = (RadioGroup) findViewById(R.id.rgToggle);
    final Spinner spRestriction = (Spinner) findViewById(R.id.spRestriction);
    RadioButton rbClear = (RadioButton) findViewById(R.id.rbClear);
    RadioButton rbTemplateFull = (RadioButton) findViewById(R.id.rbTemplateFull);
    RadioButton rbODEnable = (RadioButton) findViewById(R.id.rbEnableOndemand);
    RadioButton rbODDisable = (RadioButton) findViewById(R.id.rbDisableOndemand);
    final Spinner spTemplate = (Spinner) findViewById(R.id.spTemplate);
    final CheckBox cbClear = (CheckBox) findViewById(R.id.cbClear);
    final Button btnOk = (Button) findViewById(R.id.btnOk);
    final Button btnCancel = (Button) findViewById(R.id.btnCancel);
    // Set title
    if (action.equals(ACTION_TOGGLE)) {
        mActionId = R.string.menu_toggle;
        getSupportActionBar().setSubtitle(R.string.menu_toggle);
    } else if (action.equals(ACTION_IMPORT)) {
        mActionId = R.string.menu_import;
        getSupportActionBar().setSubtitle(R.string.menu_import);
    } else if (action.equals(ACTION_EXPORT)) {
        mActionId = R.string.menu_export;
        getSupportActionBar().setSubtitle(R.string.menu_export);
    } else if (action.equals(ACTION_FETCH)) {
        mActionId = R.string.menu_fetch;
        getSupportActionBar().setSubtitle(R.string.menu_fetch);
    } else if (action.equals(ACTION_SUBMIT)) {
        mActionId = R.string.menu_submit;
        getSupportActionBar().setSubtitle(R.string.menu_submit);
    } else {
        finish();
        return;
    }
    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));
    // Build restriction adapter
    SpinnerAdapter saRestriction = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    saRestriction.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    saRestriction.addAll(listRestrictionName);
    // Setup restriction spinner
    int pos = 0;
    if (restrictionName != null)
        for (String restriction : PrivacyManager.getRestrictions(this).values()) {
            pos++;
            if (restrictionName.equals(restriction))
                break;
        }
    spRestriction.setAdapter(saRestriction);
    spRestriction.setSelection(pos);
    // Build template adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0", getString(R.string.title_default));
    spAdapter.add(defaultName);
    for (int i = 1; i <= 4; i++) {
        String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i), getString(R.string.title_alternate) + " " + i);
        spAdapter.add(alternateName);
    }
    spTemplate.setAdapter(spAdapter);
    // Build application list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, uids);
    // Import/export filename
    if (action.equals(ACTION_EXPORT) || action.equals(ACTION_IMPORT)) {
        // Check for availability of sharing intent
        Intent file = new Intent(Intent.ACTION_GET_CONTENT);
        file.setType("file/*");
        boolean hasIntent = Util.isIntentAvailable(ActivityShare.this, file);
        // Get file name
        if (mFileName == null)
            if (action.equals(ACTION_EXPORT)) {
                String packageName = null;
                if (uids.length == 1)
                    try {
                        ApplicationInfoEx appInfo = new ApplicationInfoEx(this, uids[0]);
                        packageName = appInfo.getPackageName().get(0);
                    } catch (Throwable ex) {
                        Util.bug(null, ex);
                    }
                mFileName = getFileName(this, hasIntent, packageName);
            } else
                mFileName = (hasIntent ? null : getFileName(this, false, null));
        if (mFileName == null)
            fileChooser();
        else
            showFileName();
        if (action.equals(ACTION_IMPORT))
            cbClear.setVisibility(View.VISIBLE);
    } else if (action.equals(ACTION_FETCH)) {
        tvDescription.setText(getBaseURL());
        cbClear.setVisibility(View.VISIBLE);
    } else if (action.equals(ACTION_TOGGLE)) {
        tvDescription.setVisibility(View.GONE);
        spRestriction.setVisibility(View.VISIBLE);
        svToggle.setVisibility(View.VISIBLE);
        // Listen for radio button
        rgToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                btnOk.setEnabled(checkedId >= 0);
                spRestriction.setVisibility(checkedId == R.id.rbEnableOndemand || checkedId == R.id.rbDisableOndemand ? View.GONE : View.VISIBLE);
                spTemplate.setVisibility(checkedId == R.id.rbTemplateCategory || checkedId == R.id.rbTemplateFull || checkedId == R.id.rbTemplateMergeSet || checkedId == R.id.rbTemplateMergeReset ? View.VISIBLE : View.GONE);
            }
        });
        boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);
        rbODEnable.setVisibility(ondemand ? View.VISIBLE : View.GONE);
        rbODDisable.setVisibility(ondemand ? View.VISIBLE : View.GONE);
        if (choice == CHOICE_CLEAR)
            rbClear.setChecked(true);
        else if (choice == CHOICE_TEMPLATE)
            rbTemplateFull.setChecked(true);
    } else
        tvDescription.setText(getBaseURL());
    if (mInteractive) {
        // (showFileName does this for export/import)
        if (action.equals(ACTION_SUBMIT) || action.equals(ACTION_FETCH))
            btnOk.setEnabled(true);
        // Listen for ok
        btnOk.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                btnOk.setEnabled(false);
                // Toggle
                if (action.equals(ACTION_TOGGLE)) {
                    mRunning = true;
                    for (int i = 0; i < rgToggle.getChildCount(); i++) ((RadioButton) rgToggle.getChildAt(i)).setEnabled(false);
                    int pos = spRestriction.getSelectedItemPosition();
                    String restrictionName = (pos == 0 ? null : (String) PrivacyManager.getRestrictions(ActivityShare.this).values().toArray()[pos - 1]);
                    new ToggleTask().executeOnExecutor(mExecutor, restrictionName);
                // Import
                } else if (action.equals(ACTION_IMPORT)) {
                    mRunning = true;
                    cbClear.setEnabled(false);
                    new ImportTask().executeOnExecutor(mExecutor, new File(mFileName), cbClear.isChecked());
                } else // Export
                if (action.equals(ACTION_EXPORT)) {
                    mRunning = true;
                    new ExportTask().executeOnExecutor(mExecutor, new File(mFileName));
                // Fetch
                } else if (action.equals(ACTION_FETCH)) {
                    if (uids.length > 0) {
                        mRunning = true;
                        cbClear.setEnabled(false);
                        new FetchTask().executeOnExecutor(mExecutor, cbClear.isChecked());
                    }
                } else // Submit
                if (action.equals(ACTION_SUBMIT)) {
                    if (uids.length > 0) {
                        if (uids.length <= cSubmitLimit) {
                            mRunning = true;
                            new SubmitTask().executeOnExecutor(mExecutor);
                        } else {
                            String message = getString(R.string.msg_limit, cSubmitLimit + 1);
                            Toast.makeText(ActivityShare.this, message, Toast.LENGTH_LONG).show();
                            btnOk.setEnabled(false);
                        }
                    }
                }
            }
        });
    } else
        btnOk.setEnabled(false);
    // Listen for cancel
    btnCancel.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mRunning) {
                mAbort = true;
                Toast.makeText(ActivityShare.this, getString(R.string.msg_abort), Toast.LENGTH_LONG).show();
            } else
                finish();
        }
    });
}
Also used : RadioGroup(android.widget.RadioGroup) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) RadioButton(android.widget.RadioButton) Button(android.widget.Button) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) CheckBox(android.widget.CheckBox) File(java.io.File)

Example 7 with RadioButton

use of android.widget.RadioButton in project material-dialogs by afollestad.

the class MaterialDialog method onItemSelected.

@Override
public boolean onItemSelected(MaterialDialog dialog, View view, int position, CharSequence text, boolean longPress) {
    if (!view.isEnabled()) {
        return false;
    }
    if (listType == null || listType == ListType.REGULAR) {
        // Default adapter, non choice mode
        if (builder.autoDismiss) {
            // If auto dismiss is enabled, dismiss the dialog when a list item is selected
            dismiss();
        }
        if (!longPress && builder.listCallback != null) {
            builder.listCallback.onSelection(this, view, position, builder.items.get(position));
        }
        if (longPress && builder.listLongCallback != null) {
            return builder.listLongCallback.onLongSelection(this, view, position, builder.items.get(position));
        }
    } else {
        // Default adapter, choice mode
        if (listType == ListType.MULTI) {
            final CheckBox cb = (CheckBox) view.findViewById(R.id.md_control);
            if (!cb.isEnabled()) {
                return false;
            }
            final boolean shouldBeChecked = !selectedIndicesList.contains(position);
            if (shouldBeChecked) {
                // Add the selection to the states first so the callback includes it (when alwaysCallMultiChoiceCallback)
                selectedIndicesList.add(position);
                if (builder.alwaysCallMultiChoiceCallback) {
                    // If the checkbox wasn't previously selected, and the callback returns true, add it to the states and check it
                    if (sendMultiChoiceCallback()) {
                        cb.setChecked(true);
                    } else {
                        // The callback cancelled selection, remove it from the states
                        selectedIndicesList.remove(Integer.valueOf(position));
                    }
                } else {
                    // The callback was not used to check if selection is allowed, just select it
                    cb.setChecked(true);
                }
            } else {
                // Remove the selection from the states first so the callback does not include it (when alwaysCallMultiChoiceCallback)
                selectedIndicesList.remove(Integer.valueOf(position));
                if (builder.alwaysCallMultiChoiceCallback) {
                    // If the checkbox was previously selected, and the callback returns true, remove it from the states and uncheck it
                    if (sendMultiChoiceCallback()) {
                        cb.setChecked(false);
                    } else {
                        // The callback cancelled unselection, re-add it to the states
                        selectedIndicesList.add(position);
                    }
                } else {
                    // The callback was not used to check if the unselection is allowed, just uncheck it
                    cb.setChecked(false);
                }
            }
        } else if (listType == ListType.SINGLE) {
            final RadioButton radio = (RadioButton) view.findViewById(R.id.md_control);
            if (!radio.isEnabled()) {
                return false;
            }
            boolean allowSelection = true;
            final int oldSelected = builder.selectedIndex;
            if (builder.autoDismiss && builder.positiveText == null) {
                // If auto dismiss is enabled, and no action button is visible to approve the selection, dismiss the dialog
                dismiss();
                // Don't allow the selection to be updated since the dialog is being dismissed anyways
                allowSelection = false;
                // Update selected index and send callback
                builder.selectedIndex = position;
                sendSingleChoiceCallback(view);
            } else if (builder.alwaysCallSingleChoiceCallback) {
                // Temporarily set the new index so the callback uses the right one
                builder.selectedIndex = position;
                // Only allow the radio button to be checked if the callback returns true
                allowSelection = sendSingleChoiceCallback(view);
                // Restore the old selected index, so the state is updated below
                builder.selectedIndex = oldSelected;
            }
            // Update the checked states
            if (allowSelection) {
                builder.selectedIndex = position;
                radio.setChecked(true);
                builder.adapter.notifyItemChanged(oldSelected);
                builder.adapter.notifyItemChanged(position);
            }
        }
    }
    return true;
}
Also used : CheckBox(android.widget.CheckBox) RadioButton(android.widget.RadioButton)

Example 8 with RadioButton

use of android.widget.RadioButton in project StatusBarCompat by niorgai.

the class MainActivity method changeButtonStatus.

private void changeButtonStatus(int index, boolean check) {
    RadioButton button;
    switch(index) {
        case PAGE_COMMON:
            button = mCommon;
            break;
        case PAGE_TRANSLUCENT:
            button = mTranslucent;
            break;
        case PAGE_COORDINATOR:
            button = mCoordinator;
            break;
        case PAGE_COLLAPSING_TOOLBAR:
            button = mCollapsingToolbar;
            break;
        default:
            button = mCommon;
    }
    button.setOnCheckedChangeListener(null);
    button.setChecked(check);
    button.setOnCheckedChangeListener(this);
    if (check) {
        button.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
    } else {
        button.setTextColor(ContextCompat.getColor(this, R.color.colorBlack));
    }
}
Also used : RadioButton(android.widget.RadioButton)

Example 9 with RadioButton

use of android.widget.RadioButton in project PocketHub by pockethub.

the class EditIssuesFilterActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_issues_filter_edit);
    labelsText = finder.find(R.id.tv_labels);
    milestoneText = finder.find(R.id.tv_milestone);
    assigneeText = finder.find(R.id.tv_assignee);
    avatarView = finder.find(R.id.iv_avatar);
    if (savedInstanceState != null) {
        filter = savedInstanceState.getParcelable(EXTRA_ISSUE_FILTER);
    }
    if (filter == null) {
        filter = getIntent().getParcelableExtra(EXTRA_ISSUE_FILTER);
    }
    final Repository repository = filter.getRepository();
    setSupportActionBar((android.support.v7.widget.Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(R.string.filter_issues_title);
    actionBar.setSubtitle(InfoUtils.createRepoId(repository));
    avatars.bind(actionBar, repository.owner());
    OnClickListener assigneeListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (assigneeDialog == null) {
                assigneeDialog = new AssigneeDialog(EditIssuesFilterActivity.this, REQUEST_ASSIGNEE, repository);
            }
            assigneeDialog.show(filter.getAssignee());
        }
    };
    findViewById(R.id.tv_assignee_label).setOnClickListener(assigneeListener);
    assigneeText.setOnClickListener(assigneeListener);
    OnClickListener milestoneListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (milestoneDialog == null) {
                milestoneDialog = new MilestoneDialog(EditIssuesFilterActivity.this, REQUEST_MILESTONE, repository);
            }
            milestoneDialog.show(filter.getMilestone());
        }
    };
    findViewById(R.id.tv_milestone_label).setOnClickListener(milestoneListener);
    milestoneText.setOnClickListener(milestoneListener);
    OnClickListener labelsListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (labelsDialog == null) {
                labelsDialog = new LabelsDialog(EditIssuesFilterActivity.this, REQUEST_LABELS, repository);
            }
            labelsDialog.show(filter.getLabels());
        }
    };
    findViewById(R.id.tv_labels_label).setOnClickListener(labelsListener);
    labelsText.setOnClickListener(labelsListener);
    updateAssignee();
    updateMilestone();
    updateLabels();
    RadioButton openButton = (RadioButton) findViewById(R.id.rb_open);
    openButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                filter.setOpen(true);
            }
        }
    });
    RadioButton closedButton = (RadioButton) findViewById(R.id.rb_closed);
    closedButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                filter.setOpen(false);
            }
        }
    });
    if (filter.isOpen()) {
        openButton.setChecked(true);
    } else {
        closedButton.setChecked(true);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Repository(com.meisolsson.githubsdk.model.Repository) OnClickListener(android.view.View.OnClickListener) ActionBar(android.support.v7.app.ActionBar) CompoundButton(android.widget.CompoundButton)

Example 10 with RadioButton

use of android.widget.RadioButton in project JamsMusicPlayer by psaravan.

the class GooglePlayMusicFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;
    View rootView = (View) inflater.inflate(R.layout.fragment_welcome_screen_5, null);
    welcomeHeader = (TextView) rootView.findViewById(R.id.welcome_header);
    welcomeHeader.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Light"));
    welcomeText1 = (TextView) rootView.findViewById(R.id.welcome_text_1);
    welcomeText1.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));
    googlePlayMusicDisclaimer = (TextView) rootView.findViewById(R.id.google_play_music_disclaimer);
    googlePlayMusicDisclaimer.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));
    radioGroup = (RadioGroup) rootView.findViewById(R.id.google_play_music_radio_group);
    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    //We're adding 1 here to account (no pun intended) for the extra "Don't use Google Play Music" option.
    final int size = accounts.length + 1;
    final RadioButton[] radioButton = new RadioButton[size];
    //Add a new radio button the group for each username.
    for (int i = 0; i < size; i++) {
        radioButton[i] = new RadioButton(getActivity());
        radioGroup.addView(radioButton[i]);
        //The first radio button will always be "Don't use Google Play Music".
        if (i == 0) {
            radioButton[i].setChecked(true);
            radioButton[i].setText(R.string.dont_use_google_play_music);
        } else {
            radioButton[i].setText(accounts[i - 1].name);
        }
        radioButton[i].setTag(i);
        radioButton[i].setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    }
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int radioButtonID = group.getCheckedRadioButtonId();
            View radioButton = group.findViewById(radioButtonID);
            int index = group.indexOfChild(radioButton);
            if (index != 0) {
                account = accounts[index - 1];
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit();
                AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, getActivity(), true, account.name);
                task.execute();
            } else {
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit();
                mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit();
            }
        }
    });
    return rootView;
}
Also used : Account(android.accounts.Account) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) AsyncGoogleMusicAuthenticationTask(com.jams.music.player.AsyncTasks.AsyncGoogleMusicAuthenticationTask) AccountManager(android.accounts.AccountManager) RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) Paint(android.graphics.Paint)

Aggregations

RadioButton (android.widget.RadioButton)82 View (android.view.View)43 TextView (android.widget.TextView)30 Button (android.widget.Button)16 CheckBox (android.widget.CheckBox)15 RadioGroup (android.widget.RadioGroup)14 Intent (android.content.Intent)11 EditText (android.widget.EditText)11 Bundle (android.os.Bundle)10 ViewGroup (android.view.ViewGroup)8 CompoundButton (android.widget.CompoundButton)8 ImageView (android.widget.ImageView)7 ScrollView (android.widget.ScrollView)7 RemoteException (android.os.RemoteException)6 AdapterView (android.widget.AdapterView)6 Test (org.junit.Test)6 LayoutInflater (android.view.LayoutInflater)5 SeekBar (android.widget.SeekBar)5 OnClickListener (android.view.View.OnClickListener)4 OnCheckedChangeListener (android.widget.RadioGroup.OnCheckedChangeListener)4