Example usage for android.widget RadioButton setChecked

List of usage examples for android.widget RadioButton setChecked

Introduction

In this page you can find the example usage for android.widget RadioButton setChecked.

Prototype

@Override
public void setChecked(boolean checked) 

Source Link

Document

Changes the checked state of this button.

Usage

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

public void setRadioGroupInLayout(View layout) {
    RadioGroup radioGroup = (RadioGroup) layout.findViewById(R.id.radiogroup);
    RadioButton radioButtonTop = (RadioButton) layout.findViewById(R.id.radiobutton_top);
    RadioButton radioButtonCenter = (RadioButton) layout.findViewById(R.id.radiobutton_center);
    RadioButton radioButtonButton = (RadioButton) layout.findViewById(R.id.radiobutton_bottom);
    switch (mToastPosition) {
    case Gravity.TOP:
        radioButtonTop.setChecked(true);
        break;/*from  w  ww  .  j  a  va  2s .c o m*/
    case Gravity.CENTER:
        radioButtonCenter.setChecked(true);
        break;
    case Gravity.BOTTOM:
        radioButtonButton.setChecked(true);
        break;
    }

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.radiobutton_top:
                mToastPosition = Gravity.TOP;
                break;
            case R.id.radiobutton_center:
                mToastPosition = Gravity.CENTER;
                if (mAlertService != null) {
                    mAlertService.setToastPosition(Gravity.CENTER);
                }
                break;
            case R.id.radiobutton_bottom:
                mToastPosition = Gravity.BOTTOM;
                break;
            }
            if (mAlertService != null && mAlertService.isBoundService()) {
                mAlertService.setToastPosition(mToastPosition);
            }
        }
    });
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

private void showDialogTimkiem() {
    int i, j = 0, n;
    int k = 0;/*  w ww . j  a v  a 2 s  .  com*/
    final List<String[]> tile = readCsv(context);
    final ViewFragmentType fage = this.mCurrentFragmentType;
    for (n = 0; n < tile.size(); n++) {
        if ("filter".equals(tile.get(n)[0])) {
            j++;
        }
    }
    String[] name = new String[j];
    final Dialog dialog = new Dialog(context);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    View layout = inflater.inflate(R.layout.dialog_sapxep, null);
    dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    dialog.setContentView(R.layout.dialog_sapxep);
    final ListView lv = (ListView) dialog.findViewById(R.id.list_oder);
    TextView title = (TextView) dialog.findViewById(R.id.title);
    title.setText("L?c theo trng thi");
    for (i = 0; i < tile.size(); i++) {
        if ("filter".equals(tile.get(i)[0])) {
            name[k] = tile.get(i)[1].toString();
            k++;
        }
    }
    List<Model> list = new ArrayList<Model>();
    for (String elementKey : name) {
        list.add(new Model(elementKey));

    }

    if (position_check >= 0) {

        Model m = new Model(name[position_check], true);
        list.set(position_check, m);
    }
    adapter = new Adapter(this, list);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            RadioButton checkbox = (RadioButton) view.getTag(R.id.radioBT);
            checkbox.setChecked(true);
            Model model = (Model) (lv.getItemAtPosition(position));
            String selectedFromList = model.getName();
            for (int n = 0; n < tile.size(); n++) {
                if (selectedFromList.equals(tile.get(n)[1])) {
                    String mj = tile.get(n)[2].toString();
                    Intent intent = getIntent();
                    StringBuilder s = new StringBuilder();
                    s.append(mj);
                    intent.putExtra("timkiem", s.toString());
                    intent.putExtra("vitri", String.valueOf(position));
                    intent.putExtra("all", "0");
                    switch (fage) {
                    case SPREADSHEET:
                        intent.putExtra("page", "SPREADSHEET");
                        break;
                    case LIST:
                        intent.putExtra("page", "LIST");
                        break;
                    case MAP:
                        intent.putExtra("page", "MAP");
                        break;
                    case DETAIL:
                        intent.putExtra("page", "DETAIL");
                        break;
                    default:
                        break;
                    }
                    finish();
                    startActivity(intent);

                }
            }

        }

    });
    dialog.show();

}

From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    RadioButton satellite;
    RadioButton regular;//from   w w w.  java  2 s.  c  o m
    switch (id) {
    case DIALOG_LAYERS:
        satellite = (RadioButton) dialog.findViewById(R.id.layer_google_satellite);
        regular = (RadioButton) dialog.findViewById(R.id.layer_google_regular);
        satellite.setChecked(mSharedPreferences.getBoolean(Constants.SATELLITE, false));
        regular.setChecked(!mSharedPreferences.getBoolean(Constants.SATELLITE, false));

        mTraffic.setChecked(mSharedPreferences.getBoolean(Constants.TRAFFIC, false));
        mSpeed.setChecked(mSharedPreferences.getBoolean(Constants.SPEED, false));
        mAltitude.setChecked(mSharedPreferences.getBoolean(Constants.ALTITUDE, false));
        mDistance.setChecked(mSharedPreferences.getBoolean(Constants.DISTANCE, false));
        mCompass.setChecked(mSharedPreferences.getBoolean(Constants.COMPASS, false));
        mLocation.setChecked(mSharedPreferences.getBoolean(Constants.LOCATION, false));
        break;
    case DIALOG_URIS:
        mGallery.setAdapter(mMediaAdapter);
    default:
        break;
    }
    super.onPrepareDialog(id, dialog);
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

public void optimizeLayout() throws NullPointerException {

    try {/*from  w  ww  . ja  va 2 s . c  o m*/
        if (mDevice.isRecoverySupported() || mDevice.isKernelSupported()) {
            /** If device is supported start setting up layout */
            if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
                /** Setting layout for flashing over external App for example File Browser */
                setContentView(R.layout.flash_as);
                RelativeLayout FlashAsLayout = (RelativeLayout) findViewById(R.layout.flash_as);
                String path;
                if ((path = getIntent().getData().getPath()) != null) {
                    final File IMG = new File(path);
                    if (IMG.exists()) {
                        TextView tvFlashAs = (TextView) findViewById(R.id.tvFlashAs);
                        tvFlashAs.setText(String.format(getString(R.string.flash_as), IMG.getName()));
                    } else {
                        exit();
                    }
                    RadioButton optAsRecovery = (RadioButton) findViewById(R.id.optAsRecovery);
                    RadioButton optAsKernel = (RadioButton) findViewById(R.id.optAsKernel);

                    if (!mDevice.isRecoverySupported()) {
                        FlashAsLayout.removeView(optAsRecovery);
                        optAsKernel.setChecked(true);
                    }
                    if (!mDevice.isKernelSupported()) {
                        FlashAsLayout.removeView((optAsKernel));
                    }
                } else {
                    exit();
                }
            } else {
                setContentView(R.layout.recovery_tools);

                mRecoveryToolsLayout = (DrawerLayout) findViewById(R.id.RecoveryToolsLayout);
                mSwipeUpdater = (SwipeRefreshLayout) findViewById(R.id.swipe_updater);
                mSwipeUpdater.setColorScheme(R.color.custom_green, android.R.color.black, R.color.custom_green,
                        android.R.color.darker_gray);
                mSwipeUpdater.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        Downloader updater = new Downloader(mContext, "http://dslnexus.de/Android/", "img_sums",
                                RecoveryCollectionFile, new Runnable() {
                                    @Override
                                    public void run() {
                                        mDevice = new Device(mContext);
                                    }
                                });
                        updater.setOverrideFile(true);
                        updater.setRetry(true);
                        updater.setHidden(true);
                        Toast.makeText(mContext, "Refreshing recovery list", Toast.LENGTH_SHORT).show();
                        updater.setAfterDownload(new Runnable() {
                            @Override
                            public void run() {
                                mSwipeUpdater.setRefreshing(false);
                                Toast.makeText(mContext, "Update finished", Toast.LENGTH_SHORT).show();
                                mDevice.loadRecoveryList();
                            }
                        });
                        updater.execute();
                    }
                });
                LayoutInflater layoutInflater = getLayoutInflater();

                DrawerLayout mMenuDrawer = (DrawerLayout) layoutInflater.inflate(R.layout.menu_drawer,
                        mRecoveryToolsLayout, true);
                DrawerLayout mBackupDrawer = (DrawerLayout) layoutInflater.inflate(R.layout.backup_drawer,
                        mRecoveryToolsLayout, true);
                mRecoveryToolsLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
                ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(mActivity, mRecoveryToolsLayout,
                        R.drawable.ic_drawer, R.string.settings, R.string.app_name);
                mRecoveryToolsLayout.setDrawerListener(mDrawerToggle);
                mDrawerToggle.syncState();
                mDrawerToggle.setDrawerIndicatorEnabled(true);
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setHomeButtonEnabled(true);

                String Styles[] = getResources().getStringArray(R.array.styles);
                if (mMenuDrawer != null) {
                    Spinner spStyle = (Spinner) mMenuDrawer.findViewById(R.id.spStyle);
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity,
                            R.layout.custom_list_item, Styles);
                    adapter.setDropDownViewResource(R.layout.custom_list_item);

                    spStyle.setAdapter(adapter);
                    spStyle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            switch (position) {
                            case 1:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE,
                                        APPCOMPAT_LIGHT_DARK_BAR);
                                restartActivity();
                                break;
                            case 2:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE, APPCOMPAT_LIGHT);
                                restartActivity();
                                break;
                            case 3:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE, APPCOMPAT_DARK);
                                restartActivity();
                                break;
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {

                        }
                    });
                    CheckBox cbShowAds = (CheckBox) mMenuDrawer.findViewById(R.id.cbShowAds);
                    CheckBox cbLog = (CheckBox) mMenuDrawer.findViewById(R.id.cbLog);

                    cbShowAds.setChecked(Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS));
                    cbLog.setChecked(Common.getBooleanPref(mContext, Shell.PREF_NAME, Shell.PREF_LOG));
                    if (cbLog.isChecked()) {
                        findViewById(R.id.bShowLogs).setVisibility(View.VISIBLE);
                    } else {
                        findViewById(R.id.bShowLogs).setVisibility(View.INVISIBLE);
                    }
                    cbShowAds.setChecked(Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS));

                }

                final TextView RecoveryVersion = (TextView) findViewById(R.id.tvVersion);
                RecoveryVersion.setText(mDevice.getRecoveryVersion() + "\n" + mDevice.getKernelVersion());
                loadBackupDrawer();

                AdView adView = (AdView) findViewById(R.id.adView);
                ViewGroup MainParent = (ViewGroup) adView.getParent();
                /** Removing ads if user has turned off */
                if (!Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS)) {
                    if (adView != null && MainParent != null) {
                        MainParent.removeView(adView);
                    }
                }

                if (MainParent != null) {
                    if (!mDevice.isKernelSupported()) {
                        /** If Kernel flashing is not supported remove flash options */
                        MainParent.removeView(findViewById(R.id.bFlashKernel));
                    }
                    if (!mDevice.isRecoverySupported()) {
                        /** If Recovery flashing is not supported remove flash options */
                        MainParent.removeView(findViewById(R.id.bFlashRecovery));
                    }
                }

                if (mBackupDrawer != null) {
                    ViewGroup BackupDrawerParent = (ViewGroup) mBackupDrawer.getParent();
                    if (mDevice.isRecoveryOverRecovery()) {
                        BackupDrawerParent.removeView(mBackupDrawer);
                    } else {
                        View createKernelBackup = findViewById(R.id.bCreateKernelBackup);
                        View kernelBackups = findViewById(R.id.lvKernelBackups);
                        View createRecoveryBackup = findViewById(R.id.bCreateRecoveryBackup);
                        View recoveryBackups = findViewById(R.id.lvRecoveryBackups);
                        if (!mDevice.isKernelSupported()) {
                            /** If Kernel flashing is not supported remove backup views */
                            ((ViewGroup) createKernelBackup.getParent()).removeView(createKernelBackup);
                            ((ViewGroup) kernelBackups.getParent()).removeView(kernelBackups);
                        }
                        if (!mDevice.isRecoverySupported()) {
                            /** If Recovery flashing is not supported remove backup views */
                            ((ViewGroup) createRecoveryBackup.getParent()).removeView(createRecoveryBackup);
                            ((ViewGroup) recoveryBackups.getParent()).removeView(recoveryBackups);
                        }
                    }
                }
            }
        }

    } catch (NullPointerException e) {
        throw new NullPointerException("Error while setting up Layout " + e.getMessage());
    }
}

From source file:net.zorgblub.typhon.fragment.LibraryFragment.java

private void showImportDialog() {
    AlertDialog.Builder builder;//from   www.j  av a 2 s . c o m

    LayoutInflater inflater = PlatformUtil.getLayoutInflater(getActivity());
    final View layout = inflater.inflate(R.layout.import_dialog, null);
    final RadioButton scanSpecific = (RadioButton) layout.findViewById(R.id.radioScanFolder);
    final TextView folder = (TextView) layout.findViewById(R.id.folderToScan);
    final CheckBox copyToLibrary = (CheckBox) layout.findViewById(R.id.copyToLib);
    final Button browseButton = (Button) layout.findViewById(R.id.browseButton);

    Option<File> storageBase = config.getStorageBase();
    if (isEmpty(storageBase)) {
        return;
    }

    folder.setOnClickListener(v -> scanSpecific.setChecked(true));

    // Copy scan settings from the prefs
    copyToLibrary.setChecked(config.getCopyToLibraryOnScan());
    scanSpecific.setChecked(config.getUseCustomScanFolder());
    folder.setText(config.getScanFolder());

    builder = new AlertDialog.Builder(getActivity());
    builder.setView(layout);

    this.intentCallBack = (int resultCode, Intent data) -> {
        if (resultCode == Activity.RESULT_OK && data != null) {
            folder.setText(data.getData().getPath());
        }
    };

    browseButton.setOnClickListener(v -> {
        scanSpecific.setChecked(true);
        Intent intent = new Intent(getActivity(), FileBrowseActivity.class);
        intent.setData(Uri.parse(folder.getText().toString()));
        startActivityForResult(intent, 0);
    });

    builder.setTitle(R.string.import_books);

    builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
        dialog.dismiss();

        /* Update settings */
        config.setUseCustomScanFolder(scanSpecific.isChecked());
        config.setCopyToLibraryOnScan(copyToLibrary.isChecked());

        File folderToScan;
        if (scanSpecific.isChecked()) {
            String path = folder.getText().toString();
            folderToScan = new File(path);
            config.setScanFolder(path); /* update custom path only if used */
        } else {
            File default_storage = storageBase.unsafeGet();
            folderToScan = new File(default_storage.getAbsolutePath());
        }

        startImport(folderToScan, copyToLibrary.isChecked());
    });

    builder.setNegativeButton(android.R.string.cancel, null);

    builder.show();
}

From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java

/**
 * Dynamically creates radio buttons/* w ww.j av a2s  .  c  om*/
 *
 * @param open311Attribute contains the open311 attributes
 */
private void createSingleValueList(Open311Attribute open311Attribute) {
    ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues();
    if (values != null && values.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_single_value_list_item,
                null, false);
        layout.setSaveEnabled(true);
        ((ImageView) layout.findViewById(R.id.ri_ic_radio))
                .setColorFilter(getResources().getColor(R.color.material_gray));

        Spannable word = new SpannableString(open311Attribute.getDescription());
        ((TextView) layout.findViewById(R.id.risvli_textView)).setText(word);

        if (open311Attribute.getRequired()) {
            Spannable wordTwo = new SpannableString(" *Required");
            wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ((TextView) layout.findViewById(R.id.risvli_textView)).append(wordTwo);
        }

        RadioGroup rg = (RadioGroup) layout.findViewById(R.id.risvli_radioGroup);
        rg.setOrientation(RadioGroup.VERTICAL);

        // Restore view state from attribute result hash map
        AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode());
        String entryValue = null;
        if (av != null) {
            entryValue = av.getSingleValue();
        }

        for (int i = 0; i < values.size(); i++) {
            LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i);
            RadioButton rb = new RadioButton(getActivity());
            rg.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout
            String attributeKey = "";
            String attributeValue = "";
            for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) {
                if (Open311Attribute.NAME.equals(entry.getKey())) {
                    rb.setText(entry.getValue());
                    if (entryValue != null && entryValue.equalsIgnoreCase(entry.getValue())) {
                        rb.setChecked(true);
                    }
                    attributeKey = open311Attribute.getCode() + entry.getValue();
                } else if (Open311Attribute.KEY.equals(entry.getKey())) {
                    attributeValue = entry.getValue();
                }
            }
            mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue);
        }

        mInfoLayout.addView(layout);
        mDynamicAttributeUIMap.put(open311Attribute.getCode(), rg);
    }
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void processOnClickListenerForKey(final int key) {

    if (IMAGE_BUTTON_TEXT == key) {

    } else if (IMAGE_BUTTON_BUTTONS == key) {
        hideKeyboard();/*from ww w .ja  v  a  2 s.  c o  m*/
        try {
            Intent intent = new Intent(mActivity, SendMessageButtonActivity.class);
            intent.putExtra(SendMessageButtonActivity.CANNED_BUTTONS,
                    Pickler.getPickleFromObject(mCannedButtons));
            long[] primitiveLongArray = new long[mButtons.size()];
            Long[] longArray = mButtons.toArray(new Long[mButtons.size()]);
            for (int i = 0; i < longArray.length; i++) {
                primitiveLongArray[i] = longArray[i].longValue();
            }
            intent.putExtra(SendMessageButtonActivity.BUTTONS, primitiveLongArray);
            mActivity.startActivityForResult(intent, PICK_BUTTON);
        } catch (Exception e) {
            L.bug(e);
        }
    } else if (IMAGE_BUTTON_PICTURE == key) {
        hideKeyboard();
        getNewPicture();
    } else if (IMAGE_BUTTON_VIDEO == key) {
        hideKeyboard();
        getNewVideo();

    } else if (IMAGE_BUTTON_PRIORITY == key) {
        hideKeyboard();

        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_priority_picker, null);

        final RadioButton priorityNormalBtn = ((RadioButton) dialog.findViewById(R.id.priority_normal));
        final RadioButton priorityHighBtn = ((RadioButton) dialog.findViewById(R.id.priority_high));
        final RadioButton priorityUrgentBtn = ((RadioButton) dialog.findViewById(R.id.priority_urgent));
        final RadioButton priorityUrgentWithAlarmBtn = ((RadioButton) dialog
                .findViewById(R.id.priority_urgent_with_alarm));

        priorityNormalBtn.setChecked(false);
        priorityHighBtn.setChecked(false);
        priorityUrgentBtn.setChecked(false);
        priorityUrgentWithAlarmBtn.setChecked(false);

        if (mPriority == Message.PRIORITY_HIGH) {
            priorityHighBtn.setChecked(true);
        } else if (mPriority == Message.PRIORITY_URGENT) {
            priorityUrgentBtn.setChecked(true);
        } else if (mPriority == Message.PRIORITY_URGENT_WITH_ALARM) {
            priorityUrgentWithAlarmBtn.setChecked(true);
        } else {
            priorityNormalBtn.setChecked(true);
        }

        String title = mActivity.getString(R.string.priority);
        SafeDialogClick onPositiveClick = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface di, int id) {
                if (priorityHighBtn.isChecked()) {
                    mPriority = Message.PRIORITY_HIGH;
                } else if (priorityUrgentBtn.isChecked()) {
                    mPriority = Message.PRIORITY_URGENT;
                } else if (priorityUrgentWithAlarmBtn.isChecked()) {
                    mPriority = Message.PRIORITY_URGENT_WITH_ALARM;
                } else {
                    mPriority = Message.PRIORITY_NORMAL;
                }
                initImageButtonsNavigation();
            }
        };
        UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog);

    } else if (IMAGE_BUTTON_STICKY == key) {
        hideKeyboard();
        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_sticky_picker, null);

        final RadioButton stickyDisabled = ((RadioButton) dialog.findViewById(R.id.sticky_disabled));
        final RadioButton stickyEnabled = ((RadioButton) dialog.findViewById(R.id.sticky_enabled));
        stickyEnabled.setChecked(mIsSticky);
        stickyDisabled.setChecked(!mIsSticky);

        String title = mActivity.getString(R.string.sticky);
        SafeDialogClick onPositiveClick = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface di, int id) {
                mIsSticky = stickyEnabled.isChecked();
                initImageButtonsNavigation();
            }
        };
        UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog);

    } else if (IMAGE_BUTTON_MORE == key) {
        hideKeyboard();
        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_more_picker, null);
        final ListView pickMsgMore = (ListView) dialog.findViewById(R.id.pick_msg_more);

        List<PickMoreItem> items = new ArrayList<>();
        for (int i = mMaxImageButtonsOnScreen - 1; i < mImageButtons.size(); i++) {
            int k = mImageButtons.get(i);
            String t = "";
            if (k == IMAGE_BUTTON_TEXT) {
                t = mActivity.getString(R.string.title_message);
            } else if (k == IMAGE_BUTTON_BUTTONS) {
                t = mActivity.getString(R.string.title_buttons);
            } else if (k == IMAGE_BUTTON_PICTURE) {
                t = mActivity.getString(R.string.title_new_message_image);
            } else if (k == IMAGE_BUTTON_VIDEO) {
                t = mActivity.getString(R.string.title_new_message_video);
            } else if (k == IMAGE_BUTTON_PRIORITY) {
                t = mActivity.getString(R.string.priority);
            } else if (k == IMAGE_BUTTON_STICKY) {
                t = mActivity.getString(R.string.sticky);
            } else {
                L.d("Could not find more text for key: " + key);
            }

            items.add(new PickMoreItem(k, getImageResourceForKey(k), t));
        }
        pickMsgMore.setAdapter(new ListAdapter(mActivity, items));
        String title = mActivity.getString(R.string.more);
        String negativeCaption = mActivity.getString(R.string.cancel);
        final AlertDialog alertDialog = UIUtils.showDialog(mActivity, title, null, null, null, negativeCaption,
                null, dialog);

        pickMsgMore.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                    final long id) {
                alertDialog.dismiss();
                PickMoreItem item = (PickMoreItem) view.getTag();
                processOnClickListenerForKey(item.imageButtonKey);
            }
        });
    } else {
        L.d("Could not find processOnClickListener for key: " + key);
    }
}

From source file:com.tortel.deploytrack.CreateActivity.java

@SuppressLint("SimpleDateFormat")
@Override//from w w  w .ja v  a  2 s .  co  m
public void onCreate(Bundle savedInstanceState) {
    // Check for light theme
    Prefs.load(this);
    if (Prefs.useLightTheme()) {
        setTheme(R.style.Theme_DeployThemeLight);
    }

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_create);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    mDateFormat = new SimpleDateFormat("MMM dd, yyyy");

    mNameEdit = (EditText) findViewById(R.id.name);
    mNameEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
            // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            // Clear errors on text change
            try {
                mNameWrapper.setErrorEnabled(false);
            } catch (Exception e) {
                // Ignore
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            // Do nothing
        }
    });
    mNameWrapper = (TextInputLayout) findViewById(R.id.name_wraper);

    mStartInput = (EditText) findViewById(R.id.button_start);
    mStartInput.setOnClickListener(this);
    mStartInput.setOnFocusChangeListener(this);
    mStartWrapper = (TextInputLayout) findViewById(R.id.start_wrapper);

    mEndInput = (EditText) findViewById(R.id.button_end);
    mEndInput.setOnClickListener(this);
    mEndInput.setOnFocusChangeListener(this);
    mEndWrapper = (TextInputLayout) findViewById(R.id.end_wrapper);

    mBarButton = (RadioButton) findViewById(R.id.layout_bar);
    RadioButton circleButton = (RadioButton) findViewById(R.id.layout_circle);

    //Color pickers
    ColorPicker completedPicker = (ColorPicker) findViewById(R.id.picker_completed);
    ColorPicker remainingPicker = (ColorPicker) findViewById(R.id.picker_remain);

    SVBar completedBar = (SVBar) findViewById(R.id.sv_completed);
    SVBar remainingBar = (SVBar) findViewById(R.id.sv_remain);

    String id = getIntent().getStringExtra("id");
    if (id != null) {
        //Starting in edit mode, load the old data
        mDeployment = DatabaseManager.getInstance(this).getDeployment(id);

        //Set the colors
        mCompletedColor = mDeployment.getCompletedColor();
        mRemainingColor = mDeployment.getRemainingColor();

        //Set the dates
        mStartDate = Calendar.getInstance();
        mEndDate = Calendar.getInstance();

        mStartDate.setTimeInMillis(mDeployment.getStartDate().getTime());
        mEndDate.setTimeInMillis(mDeployment.getEndDate().getTime());

        //Set the buttons
        mStartInput.setText(mDateFormat.format(mStartDate.getTime()));
        mEndInput.setText(mDateFormat.format(mEndDate.getTime()));

        // Set circle/bar selected
        if (mDeployment.getDisplayType() == Deployment.DISPLAY_BAR) {
            mBarButton.setChecked(true);
        } else {
            circleButton.setChecked(true);
        }

        //Set the name
        mNameEdit.setText(mDeployment.getName());

        getSupportActionBar().setTitle(R.string.edit);
    } else {
        mDeployment = new Deployment();

        mStartDate = Calendar.getInstance();
        mEndDate = (Calendar) mStartDate.clone();

        mCompletedColor = Color.GREEN;
        mRemainingColor = Color.RED;

        getSupportActionBar().setTitle(R.string.add_new);
    }

    //If restore from rotation
    if (savedInstanceState != null) {
        mStartDate.setTimeInMillis(savedInstanceState.getLong(KEY_TIME_START));
        mEndDate.setTimeInMillis(savedInstanceState.getLong(KEY_TIME_END));

        mNameEdit.setText(savedInstanceState.getString(KEY_NAME));

        mCompletedColor = savedInstanceState.getInt(KEY_COLOR_COMPLETED);
        mRemainingColor = savedInstanceState.getInt(KEY_COLOR_REMAINING);

        //Set the date buttons, if set
        if (mStartDate != null) {
            mStartInput.setText(mDateFormat.format(mStartDate.getTime()));
        }

        if (mStartDate != null && mEndDate != null && mEndDate.after(mStartDate)) {
            mEndInput.setText(mDateFormat.format(mEndDate.getTime()));
        }

        int viewType = savedInstanceState.getInt(KEY_DISPLAY_TYPE, Deployment.DISPLAY_CIRCLE);
        if (viewType == Deployment.DISPLAY_BAR) {
            mBarButton.setChecked(true);
        } else {
            circleButton.setChecked(true);
        }
    }

    remainingPicker.setOldCenterColor(mRemainingColor);
    remainingPicker.setNewCenterColor(mRemainingColor);
    remainingPicker.addSVBar(remainingBar);
    remainingPicker.setColor(mRemainingColor);
    remainingPicker.setShowOldCenterColor(false);
    remainingPicker.setOnColorChangedListener(new RemainingColorChangeListener());

    completedPicker.setOldCenterColor(mCompletedColor);
    completedPicker.setNewCenterColor(mCompletedColor);
    completedPicker.addSVBar(completedBar);
    completedPicker.setColor(mCompletedColor);
    completedPicker.setShowOldCenterColor(false);
    completedPicker.setOnColorChangedListener(new CompletedColorChangeListener());

    // Register for date changes
    LocalBroadcastManager.getInstance(this).registerReceiver(mDateChangeReceiver,
            new IntentFilter(SingleDatePickerDialog.ACTION_DATE_SELECTED));
}

From source file:com.wanikani.androidnotifier.ItemsFragment.java

public void setFilter(FilterType filter, int level) {
    SharedPreferences prefs;//www  .j a va 2  s  .  c om
    RadioButton btn;
    String s;

    filterType = filter;

    try {
        prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        s = prefs.getString(PREF_ORDER + filterType.name(), filterType.getDefaultOrder().name());
        order = SortOrder.valueOf(s);
    } catch (Throwable t) {
        order = filterType.getDefaultOrder();
    }

    if (parent != null) {
        order.apply(parent, iad);

        btn = (RadioButton) parent.findViewById(filter.getId());
        btn.setChecked(true);

        fmap.get(filter).select(meter(), main.getConnection(), level);
        iview.setSelection(0);
    }

    filterChanged();
}

From source file:org.glucosio.android.activity.MainActivity.java

public void showExportCsvDialog() {
    final Dialog exportDialog = new Dialog(MainActivity.this, R.style.GlucosioTheme);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(exportDialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    exportDialog.setContentView(R.layout.dialog_export);
    exportDialog.getWindow().setAttributes(lp);
    exportDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    exportDialog.getWindow().setDimAmount(0.5f);
    exportDialog.show();/* ww  w .  jav  a  2 s. co m*/

    exportDialogDateFrom = (TextView) exportDialog.findViewById(R.id.activity_export_date_from);
    exportDialogDateTo = (TextView) exportDialog.findViewById(R.id.activity_export_date_to);
    exportRangeButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_range);
    final RadioButton exportAllButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_all);
    final TextView exportButton = (TextView) exportDialog.findViewById(R.id.dialog_export_add);
    final TextView cancelButton = (TextView) exportDialog.findViewById(R.id.dialog_export_cancel);

    exportRangeButton.setChecked(true);

    exportDialogDateFrom.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar now = Calendar.getInstance();
            DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR),
                    now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
            dpd.show(getFragmentManager(), "fromDateDialog");
            dpd.setMaxDate(now);
        }
    });

    exportDialogDateTo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar now = Calendar.getInstance();
            DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR),
                    now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
            dpd.show(getFragmentManager(), "toDateDialog");
            dpd.setMaxDate(now);
        }
    });

    exportRangeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean isChecked = exportRangeButton.isChecked();
            exportDialogDateFrom.setEnabled(true);
            exportDialogDateTo.setEnabled(true);
            exportAllButton.setChecked(!isChecked);
        }
    });

    exportAllButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean isChecked = exportAllButton.isChecked();
            exportDialogDateFrom.setEnabled(false);
            exportDialogDateTo.setEnabled(false);
            exportRangeButton.setChecked(!isChecked);
            exportButton.setEnabled(true);
        }
    });

    exportButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (validateExportDialog()) {
                exportPresenter.onExportClicked(exportAllButton.isChecked());
                exportDialog.dismiss();
            } else {
                showSnackBar(getResources().getString(R.string.dialog_error), Snackbar.LENGTH_LONG);
            }
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            exportDialog.dismiss();
        }
    });

}