Search in sources :

Example 1 with OnCheckedChangeListener

use of android.widget.RadioGroup.OnCheckedChangeListener in project Anki-Android by Ramblurr.

the class StudyOptionsFragment method formatRGCardType.

/**
     * formatRGCardType
     * Returns: RadioGroup - A radio group that contains the options of All Cards, New, and Due cards,
     * 			for the selection of cards when creating a CUSTOM_STUDY_DECKS based on TAGS.
     * Takes: context, and resources of the App.
     * 
     * This method just creates the RadioGroup required for the dialog to select tags for a new 
     * custom study deck.
     */
private RadioGroup formatRGCardType(Context context, Resources res) {
    RadioGroup rg = new RadioGroup(context);
    final RadioButton[] radioButtonCards = new RadioButton[3];
    rg.setOrientation(RadioGroup.HORIZONTAL);
    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
    int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
    //This array contains "All Cards", "New", and "Due", in that order. 
    String[] text = res.getStringArray(R.array.cards_for_tag_filtered_deck_labels);
    for (int i = 0; i < radioButtonCards.length; i++) {
        radioButtonCards[i] = new RadioButton(context);
        radioButtonCards[i].setClickable(true);
        radioButtonCards[i].setText(text[i]);
        radioButtonCards[i].setHeight(height * 2);
        radioButtonCards[i].setSingleLine();
        radioButtonCards[i].setGravity(Gravity.CENTER_VERTICAL);
        rg.addView(radioButtonCards[i], lp);
    }
    rg.check(0);
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            int checked = arg0.getCheckedRadioButtonId();
            for (int i = 0; i < 3; i++) {
                if (arg0.getChildAt(i).getId() == checked) {
                    mSelectedOption = i;
                    break;
                }
            }
        }
    });
    rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
    return rg;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) RadioButton(android.widget.RadioButton) LinearLayout(android.widget.LinearLayout)

Example 2 with OnCheckedChangeListener

use of android.widget.RadioGroup.OnCheckedChangeListener in project Anki-Android by Ramblurr.

the class ChartBuilder method getStatisticsDialog.

public static StyledDialog getStatisticsDialog(Context context, DialogInterface.OnClickListener listener, boolean showWholeDeckSelection) {
    StyledDialog.Builder builder = new StyledDialog.Builder(context);
    builder.setTitle(context.getString(R.string.statistics_type_title));
    builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
    // set items
    String[] items = new String[3];
    items[0] = context.getResources().getString(R.string.stats_forecast);
    items[1] = context.getResources().getString(R.string.stats_review_count);
    items[2] = context.getResources().getString(R.string.stats_review_time);
    builder.setItems(items, listener);
    // period selection
    final RadioButton[] statisticRadioButtons = new RadioButton[3];
    RadioGroup rg = new RadioGroup(context);
    rg.setOrientation(RadioGroup.HORIZONTAL);
    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
    Resources res = context.getResources();
    String[] text = res.getStringArray(R.array.stats_period);
    int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
    for (int i = 0; i < statisticRadioButtons.length; i++) {
        statisticRadioButtons[i] = new RadioButton(context);
        statisticRadioButtons[i].setClickable(true);
        statisticRadioButtons[i].setText("         " + text[i]);
        statisticRadioButtons[i].setHeight(height * 2);
        statisticRadioButtons[i].setSingleLine();
        statisticRadioButtons[i].setBackgroundDrawable(null);
        statisticRadioButtons[i].setGravity(Gravity.CENTER_VERTICAL);
        rg.addView(statisticRadioButtons[i], lp);
    }
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            int checked = arg0.getCheckedRadioButtonId();
            for (int i = 0; i < 3; i++) {
                if (arg0.getChildAt(i).getId() == checked) {
                    AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("statsType", i).commit();
                    break;
                }
            }
        }
    });
    rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
    statisticRadioButtons[Math.min(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), Stats.TYPE_LIFE)].setChecked(true);
    if (showWholeDeckSelection) {
        // collection/current deck
        final RadioButton[] statisticRadioButtons2 = new RadioButton[2];
        RadioGroup rg2 = new RadioGroup(context);
        rg2.setOrientation(RadioGroup.HORIZONTAL);
        String[] text2 = res.getStringArray(R.array.stats_range);
        for (int i = 0; i < statisticRadioButtons2.length; i++) {
            statisticRadioButtons2[i] = new RadioButton(context);
            statisticRadioButtons2[i].setClickable(true);
            statisticRadioButtons2[i].setText("         " + text2[i]);
            statisticRadioButtons2[i].setHeight(height * 2);
            statisticRadioButtons2[i].setSingleLine();
            statisticRadioButtons2[i].setBackgroundDrawable(null);
            statisticRadioButtons2[i].setGravity(Gravity.CENTER_VERTICAL);
            rg2.addView(statisticRadioButtons2[i], lp);
        }
        rg2.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup arg0, int arg1) {
                AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putBoolean("statsRange", arg0.getCheckedRadioButtonId() == arg0.getChildAt(0).getId()).commit();
            }
        });
        rg2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
        statisticRadioButtons2[AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean("statsRange", true) ? 0 : 1].setChecked(true);
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        ll.addView(rg);
        ll.addView(rg2);
        builder.setView(ll, false, true);
    } else {
        builder.setView(rg, false, true);
    }
    return builder.create();
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) StyledDialog(com.ichi2.themes.StyledDialog) RadioButton(android.widget.RadioButton) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 3 with OnCheckedChangeListener

use of android.widget.RadioGroup.OnCheckedChangeListener 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 4 with OnCheckedChangeListener

use of android.widget.RadioGroup.OnCheckedChangeListener in project SlidingMenu by jfeinstein10.

the class PropertiesActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setSlidingActionBarEnabled(true);
    setContentView(R.layout.properties);
    // left and right modes
    RadioGroup mode = (RadioGroup) findViewById(R.id.mode);
    mode.check(R.id.left);
    mode.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            SlidingMenu sm = getSlidingMenu();
            switch(checkedId) {
                case R.id.left:
                    sm.setMode(SlidingMenu.LEFT);
                    sm.setShadowDrawable(R.drawable.shadow);
                    break;
                case R.id.right:
                    sm.setMode(SlidingMenu.RIGHT);
                    sm.setShadowDrawable(R.drawable.shadowright);
                    break;
                case R.id.left_right:
                    sm.setMode(SlidingMenu.LEFT_RIGHT);
                    sm.setSecondaryMenu(R.layout.menu_frame_two);
                    getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, new SampleListFragment()).commit();
                    sm.setSecondaryShadowDrawable(R.drawable.shadowright);
                    sm.setShadowDrawable(R.drawable.shadow);
            }
        }
    });
    // touch mode stuff
    RadioGroup touchAbove = (RadioGroup) findViewById(R.id.touch_above);
    touchAbove.check(R.id.touch_above_full);
    touchAbove.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch(checkedId) {
                case R.id.touch_above_full:
                    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
                    break;
                case R.id.touch_above_margin:
                    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
                    break;
                case R.id.touch_above_none:
                    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
                    break;
            }
        }
    });
    // scroll scale stuff
    SeekBar scrollScale = (SeekBar) findViewById(R.id.scroll_scale);
    scrollScale.setMax(1000);
    scrollScale.setProgress(333);
    scrollScale.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSlidingMenu().setBehindScrollScale((float) seekBar.getProgress() / seekBar.getMax());
        }
    });
    // behind width stuff
    SeekBar behindWidth = (SeekBar) findViewById(R.id.behind_width);
    behindWidth.setMax(1000);
    behindWidth.setProgress(750);
    behindWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            float percent = (float) seekBar.getProgress() / seekBar.getMax();
            getSlidingMenu().setBehindWidth((int) (percent * getSlidingMenu().getWidth()));
            getSlidingMenu().requestLayout();
        }
    });
    // shadow stuff
    CheckBox shadowEnabled = (CheckBox) findViewById(R.id.shadow_enabled);
    shadowEnabled.setChecked(true);
    shadowEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked)
                getSlidingMenu().setShadowDrawable(getSlidingMenu().getMode() == SlidingMenu.LEFT ? R.drawable.shadow : R.drawable.shadowright);
            else
                getSlidingMenu().setShadowDrawable(null);
        }
    });
    SeekBar shadowWidth = (SeekBar) findViewById(R.id.shadow_width);
    shadowWidth.setMax(1000);
    shadowWidth.setProgress(75);
    shadowWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            float percent = (float) seekBar.getProgress() / (float) seekBar.getMax();
            int width = (int) (percent * (float) getSlidingMenu().getWidth());
            getSlidingMenu().setShadowWidth(width);
            getSlidingMenu().invalidate();
        }
    });
    // fading stuff
    CheckBox fadeEnabled = (CheckBox) findViewById(R.id.fade_enabled);
    fadeEnabled.setChecked(true);
    fadeEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            getSlidingMenu().setFadeEnabled(isChecked);
        }
    });
    SeekBar fadeDeg = (SeekBar) findViewById(R.id.fade_degree);
    fadeDeg.setMax(1000);
    fadeDeg.setProgress(666);
    fadeDeg.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSlidingMenu().setFadeDegree((float) seekBar.getProgress() / seekBar.getMax());
        }
    });
}
Also used : SlidingMenu(com.jeremyfeinstein.slidingmenu.lib.SlidingMenu) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) SeekBar(android.widget.SeekBar) CheckBox(android.widget.CheckBox) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) CompoundButton(android.widget.CompoundButton)

Example 5 with OnCheckedChangeListener

use of android.widget.RadioGroup.OnCheckedChangeListener 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

RadioGroup (android.widget.RadioGroup)13 OnCheckedChangeListener (android.widget.RadioGroup.OnCheckedChangeListener)13 View (android.view.View)5 TextView (android.widget.TextView)5 RadioButton (android.widget.RadioButton)4 Paint (android.graphics.Paint)2 LayoutParams (android.view.ViewGroup.LayoutParams)2 CheckBox (android.widget.CheckBox)2 LinearLayout (android.widget.LinearLayout)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1