Example usage for android.widget Spinner setSelection

List of usage examples for android.widget Spinner setSelection

Introduction

In this page you can find the example usage for android.widget Spinner setSelection.

Prototype

@Override
    public void setSelection(int position) 

Source Link

Usage

From source file:com.fitme.MainActivity.java

public void onExerciseCreationRequested(final String trainName, final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_exercise_dialog);
    View view = getLayoutInflater().inflate(R.layout.dialog_add_exercise, null);
    builder.setView(view);/*from   w w  w.  j  a  v  a2 s.com*/
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialogEx = builder.create();
    dialogEx.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = dialogEx.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
                    Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
                    NumberPicker numpickRepeats = (NumberPicker) dialogEx
                            .findViewById(R.id.numberpicker_repeats_ex);
                    //Since we decide to have all spinners pre-populated no need to check data
                    Exercise e = new Exercise();
                    e.setName(spinExName.getSelectedItem().toString());
                    e.setMuscleGroup(spinMuscleGroup.getSelectedItem().toString());
                    e.setRepeats(numpickRepeats.getValue());
                    //Identifying program and training
                    long programId = MainActivity.this.getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    long trId = td.getTrainingByName(programId, trainName).getId();
                    e.setTrainId(trId);

                    //Insert new entry to db
                    ExerciseDAO ed = new ExerciseDAO(MainActivity.this);
                    long exId = ed.createExercise(e).getId();
                    e.setId(exId);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_exercise_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addExercise(e, trainName);
                    dialogEx.dismiss();
                }
            });

        }
    });
    dialogEx.show();
    // Populate dialog fields
    NumberPicker np = (NumberPicker) dialogEx.findViewById(R.id.numberpicker_repeats_ex);
    final Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
    final Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
    np.setMaxValue(Exercise.MAX_REPEATS);
    np.setMinValue(Exercise.MIN_REPEATS);

    //Filling muscle groups spinner
    String[] muscleGroups = getResources().getStringArray(R.array.muscle_groups);

    ArrayAdapter<String> mgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            muscleGroups);
    spinMuscleGroup.setAdapter(mgAdapter);

    spinMuscleGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String arrayName = ("exercises_" + spinMuscleGroup.getSelectedItem().toString()).toLowerCase();
            int id = getResources().getIdentifier(arrayName, "array", MainActivity.this.getPackageName());
            String[] exercises = getResources().getStringArray(id);
            ArrayAdapter<String> exAdapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_spinner_item, exercises);
            spinExName.setAdapter(exAdapter);
        }

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

        }
    });
    spinMuscleGroup.setSelection(1);

}

From source file:com.npi.muzeiflickr.ui.activities.SettingsActivity.java

private void populateFooter(View footerView) {
    final View footerButton = footerView.findViewById(R.id.list_footer_button);
    final Spinner footerModeChooser = (Spinner) footerView.findViewById(R.id.mode_chooser);
    final RelativeLayout addItemContainer = (RelativeLayout) footerView.findViewById(R.id.new_item_container);
    final ImageButton footerSearchButton = (ImageButton) footerView.findViewById(R.id.footer_search_button);
    final ProgressBar footerProgress = (ProgressBar) footerView.findViewById(R.id.footer_progress);
    final EditText footerTerm = (EditText) footerView.findViewById(R.id.footer_term);

    footerButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from w  ww .j  av a  2s .c o m
        public boolean onLongClick(View v) {
            int[] pos = new int[2];
            footerButton.getLocationInWindow(pos);

            String contentDesc = footerButton.getContentDescription().toString();
            Toast t = Toast.makeText(SettingsActivity.this, contentDesc, Toast.LENGTH_SHORT);
            t.show();
            t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, pos[1] + (footerButton.getHeight() / 2));

            return true;
        }
    });

    footerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addItemContainer.animate().alpha(1F);
            footerButton.animate().alpha(0F);
        }
    });

    //Mode spinner management
    ArrayAdapter<CharSequence> adapter = new SourceSpinnerAdapter(this, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.modes));

    footerModeChooser.setAdapter(adapter);

    footerSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String searchString = footerTerm.getText().toString();
            switch (footerModeChooser.getSelectedItemPosition()) {
            case 0:

                //It's a search

                //Looking for a same existing search
                List<Search> searchs = Search.listAll(Search.class);
                for (Search search : searchs) {
                    if (search.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.search_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getSearch(searchString, new UserInfoListener<Search>() {
                    @Override
                    public void onSuccess(Search search) {
                        mRequestAdapter.add(search);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });

                break;
            case 1:
                //It's an user

                //Looking for a same existing search
                List<User> users = User.listAll(User.class);
                for (User user : users) {
                    if (user.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.user_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getUserId(searchString, new UserInfoListener<User>() {
                    @Override
                    public void onSuccess(User user) {
                        mRequestAdapter.add(user);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;
            case 2:
                //It's a tag

                //Looking for a same existing search
                List<Tag> tags = Tag.listAll(Tag.class);
                for (Tag tag : tags) {
                    if (tag.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.user_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getTag(searchString, new UserInfoListener<Tag>() {
                    @Override
                    public void onSuccess(Tag tag) {
                        mRequestAdapter.add(tag);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;

            case 3:
                //It's an user

                //Looking for a same existing search
                List<FGroup> groups = FGroup.listAll(FGroup.class);
                for (FGroup group : groups) {
                    if (group.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.group_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getGroupId(searchString, new UserInfoListener<FGroup>() {
                    @Override
                    public void onSuccess(FGroup group) {
                        mRequestAdapter.add(group);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;
            }
        }
    });
}

From source file:com.todoroo.astrid.repeats.RepeatControlSet.java

@Nullable
@Override/*from  w  ww .ja  va2  s.  c  om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (savedInstanceState != null) {
        recurrence = savedInstanceState.getString(EXTRA_RECURRENCE);
        repeatUntilValue = savedInstanceState.getLong(EXTRA_REPEAT_UNTIL);
        repeatAfterCompletion = savedInstanceState.getBoolean(EXTRA_REPEAT_AFTER_COMPLETION);
    }

    dialogView = inflater.inflate(R.layout.control_set_repeat, null);
    value = (Button) dialogView.findViewById(R.id.repeatValue);
    Spinner interval = (Spinner) dialogView.findViewById(R.id.repeatInterval);
    ArrayAdapter<String> intervalAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_interval));
    intervalAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    interval.setAdapter(intervalAdapter);
    Spinner type = (Spinner) dialogView.findViewById(R.id.repeatType);
    ArrayAdapter<String> typeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_type));
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    type.setAdapter(typeAdapter);
    type.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            repeatAfterCompletion = position == TYPE_COMPLETION_DATE;
        }

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

        }
    });
    daysOfWeekContainer = (LinearLayout) dialogView.findViewById(R.id.repeatDayOfWeekContainer);
    repeatUntil = (Spinner) dialogView.findViewById(R.id.repeat_until);
    repeatUntilAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, repeatUntilOptions);
    repeatUntilAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    repeatUntil.setAdapter(repeatUntilAdapter);
    // set up days of week
    DateFormatSymbols dfs = new DateFormatSymbols();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
    CompoundButton[] daysOfWeek = new CompoundButton[7];
    for (int i = 0; i < 7; i++) {
        final int index = i;
        CheckBox checkBox = (CheckBox) daysOfWeekContainer.getChildAt(i);
        checkBox.setOnCheckedChangeListener(
                (buttonView, isChecked1) -> RepeatControlSet.this.isChecked[index] = isChecked1);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        checkBox.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1));
        daysOfWeek[i] = checkBox;
        weekdays[i] = Weekday.values()[dayOfWeek - 1];
        calendar.add(Calendar.DATE, 1);
    }

    // set up listeners
    value.setOnClickListener(v -> repeatValueClick());

    setRepeatValue(1);
    interval.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
            daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE);
            intervalValue = position;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            //
        }
    });

    setRepeatUntilValue(repeatUntilValue);
    repeatUntil.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (repeatUntilOptions.size() == 2) {
                if (i == 0) {
                    setRepeatUntilValue(0);
                } else {
                    repeatUntilClick();
                }
            } else {
                if (i == 1) {
                    setRepeatUntilValue(0);
                } else if (i == 2) {
                    repeatUntilClick();
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            //
        }
    });

    daysOfWeekContainer.setVisibility(View.GONE);
    type.setSelection(repeatAfterCompletion ? TYPE_COMPLETION_DATE : TYPE_DUE_DATE);
    doRepeat = !Strings.isNullOrEmpty(recurrence);
    if (doRepeat) {
        // read recurrence rule
        try {
            RRule rrule = new RRule(recurrence);

            setRepeatValue(rrule.getInterval());

            for (WeekdayNum day : rrule.getByDay()) {
                for (int i = 0; i < 7; i++) {
                    if (weekdays[i].equals(day.wday)) {
                        daysOfWeek[i].setChecked(true);
                    }
                }
            }

            switch (rrule.getFreq()) {
            case DAILY:
                intervalValue = INTERVAL_DAYS;
                break;
            case WEEKLY:
                intervalValue = INTERVAL_WEEKS;
                break;
            case MONTHLY:
                intervalValue = INTERVAL_MONTHS;
                break;
            case HOURLY:
                intervalValue = INTERVAL_HOURS;
                break;
            case MINUTELY:
                intervalValue = INTERVAL_MINUTES;
                break;
            case YEARLY:
                intervalValue = INTERVAL_YEARS;
                break;
            default:
                Timber.e(new Exception("Unhandled rrule frequency: " + recurrence), "repeat-unhandled-rule");
            }
            interval.setSelection(intervalValue);

        } catch (Exception e) {
            // invalid RRULE
            recurrence = ""; //$NON-NLS-1$
            Timber.e(e, e.getMessage());
        }
    }
    refreshDisplayView();
    return view;
}

From source file:org.thoughtland.xlocation.ActivityShare.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;/*ww w  . ja v  a2 s. c  o  m*/

    // 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);

    // 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;
        setTitle(R.string.menu_toggle);
    } else if (action.equals(ACTION_IMPORT)) {
        mActionId = R.string.menu_import;
        setTitle(R.string.menu_import);
    } else if (action.equals(ACTION_EXPORT)) {
        mActionId = R.string.menu_export;
        setTitle(R.string.menu_export);
    } else if (action.equals(ACTION_FETCH)) {
        mActionId = R.string.menu_fetch;
        setTitle(R.string.menu_fetch);
    } else if (action.equals(ACTION_SUBMIT)) {
        mActionId = R.string.menu_submit;
        setTitle(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);
    spAdapter.add(getString(R.string.title_default));
    for (int i = 1; i <= 4; i++)
        spAdapter.add(getString(R.string.title_alternate) + " " + i);
    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.setText(R.string.menu_toggle);
        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) {
        // Enable ok
        // (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());
                }

                // Export
                else 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());
                    }
                }

                // Submit
                else 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();
        }
    });
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java

final static private void editActivityExtraDataItem(final GlobalParameters mGlblParms, final int sel_pos) {
    // ??// ww  w .  j  a v a2 s .c o m
    final Dialog dialog = new Dialog(mGlblParms.context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //      dialog.getWindow().setSoftInputMode(
    //                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    dialog.setContentView(R.layout.edit_activity_extra_data_item_dlg);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_msg);
    //      final TextView dlg_title = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_title);

    //      CommonDialog.setDlgBoxSizeLimit(dialog,true);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_cancel_btn);
    final Button btn_ok = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_ok_btn);

    final EditText et_key = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_key);
    final EditText et_string = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_string);
    final EditText et_int = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_int);
    final CheckBox cb_array = (CheckBox) dialog.findViewById(R.id.edit_activity_extra_data_item_array);
    final Button btn_add_array = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_add_array);
    final ListView lv_array = (ListView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_listview);
    final TextView lv_spacer = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_spacer);

    final Spinner spinnerExtraDataType = (Spinner) dialog
            .findViewById(R.id.edit_activity_extra_data_item_data_type);
    final CustomSpinnerAdapter adapterExtraDataType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterExtraDataType.setTextColor(Color.BLACK);
    setSpinnerExtraDataType(mGlblParms, dialog, spinnerExtraDataType, adapterExtraDataType,
            PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING);

    final Spinner spinnerExtraDataBoolean = (Spinner) dialog
            .findViewById(R.id.edit_activity_extra_data_item_data_boolean);
    final CustomSpinnerAdapter adapterExtraDataBoolean = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterExtraDataBoolean.setTextColor(Color.BLACK);
    setSpinnerExtraDataBoolean(mGlblParms, dialog, spinnerExtraDataBoolean, adapterExtraDataBoolean, "false");

    final Button update_apply = (Button) dialog
            .findViewById(R.id.edit_activity_extra_data_item_data_update_apply);
    final Button update_cancel = (Button) dialog
            .findViewById(R.id.edit_activity_extra_data_item_data_update_cancel);
    update_apply.setVisibility(Button.GONE);
    update_cancel.setVisibility(Button.GONE);
    spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
    et_string.setVisibility(EditText.GONE);
    et_int.setVisibility(EditText.GONE);
    btn_add_array.setVisibility(Button.GONE);
    lv_array.setVisibility(ListView.GONE);
    lv_spacer.setVisibility(TextView.VISIBLE);

    final ArrayList<DataArrayEditListItem> aed_array_list = new ArrayList<DataArrayEditListItem>();
    final AdapterDataArrayEditList aed_array_adapter = new AdapterDataArrayEditList(mGlblParms.context,
            R.layout.data_array_edit_list_item, aed_array_list);
    lv_array.setAdapter(aed_array_adapter);
    setActivityExtraDataEditItemViewVisibility(mGlblParms, dialog, aed_array_adapter, spinnerExtraDataType);

    cb_array.setChecked(false);
    if (sel_pos != -1) {
        et_key.setEnabled(false);
        et_key.setTextColor(Color.WHITE);
        et_key.selectAll();
        et_key.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).key_value);
        if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
            et_string.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value);
            spinnerExtraDataType.setSelection(0);
        } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
            et_int.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value);
            spinnerExtraDataType.setSelection(1);
        } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
            spinnerExtraDataType.setSelection(2);
            if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value.equals("false"))
                spinnerExtraDataBoolean.setSelection(0);
            else
                spinnerExtraDataBoolean.setSelection(1);
        }
        mGlblParms.currentSelectedExtraDataType = spinnerExtraDataType.getSelectedItem().toString();
        if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value_array
                .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES)) {
            cb_array.setChecked(true);
            et_string.setText("");
            et_int.setText("");
            createActivityExtraDataArrayList(aed_array_adapter,
                    mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos));
            aed_array_adapter.notifyDataSetChanged();
            update_apply.setVisibility(Button.GONE);
            update_cancel.setVisibility(Button.GONE);
            spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
            et_string.setVisibility(EditText.GONE);
            et_int.setVisibility(EditText.GONE);
            btn_add_array.setVisibility(Button.VISIBLE);
            lv_array.setVisibility(ListView.VISIBLE);
            lv_spacer.setVisibility(TextView.GONE);
        } else {
            cb_array.setChecked(false);
            update_apply.setVisibility(Button.GONE);
            update_cancel.setVisibility(Button.GONE);
            spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
            et_string.setVisibility(EditText.GONE);
            et_int.setVisibility(EditText.GONE);
            btn_add_array.setVisibility(Button.GONE);
            lv_array.setVisibility(ListView.GONE);
            lv_spacer.setVisibility(TextView.VISIBLE);
            if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                et_string.setVisibility(EditText.VISIBLE);
            } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
                et_int.setVisibility(EditText.VISIBLE);
            } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
                spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE);
            }
        }
    }

    btn_add_array.setOnClickListener(new OnClickListener() {
        @Override
        final public void onClick(View arg0) {
            String n_data = "";
            if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                n_data = "";
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
                n_data = "0";
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
                n_data = "false";
            }
            DataArrayEditListItem aeda_item = new DataArrayEditListItem();
            aeda_item.data_value = n_data;
            aed_array_adapter.add(aeda_item);
            aed_array_adapter.notifyDataSetChanged();
        }
    });

    NotifyEvent ntfy = new NotifyEvent(mGlblParms.context);
    ntfy.setListener(new NotifyEventListener() {
        @Override
        final public void positiveResponse(Context c, Object[] o) {
            spinnerExtraDataType.setEnabled(false);
            String c_data = (String) o[0];
            if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                et_string.setText(c_data);
                spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
                et_string.setVisibility(EditText.VISIBLE);
                et_int.setVisibility(EditText.GONE);
                et_string.requestFocus();
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
                et_int.setText(c_data);
                spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
                et_string.setVisibility(EditText.GONE);
                et_int.setVisibility(EditText.VISIBLE);
                et_int.requestFocus();
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
                if (c_data.equals("false"))
                    spinnerExtraDataBoolean.setSelection(0);
                else
                    spinnerExtraDataBoolean.setSelection(1);
                spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE);
                et_string.setVisibility(EditText.GONE);
                et_int.setVisibility(EditText.GONE);
            }
            update_apply.setVisibility(Button.VISIBLE);
            update_cancel.setVisibility(Button.VISIBLE);
            btn_ok.setEnabled(false);
            btn_cancel.setEnabled(false);
            cb_array.setEnabled(false);
            btn_add_array.setEnabled(false);

        }

        @Override
        final public void negativeResponse(Context c, Object[] o) {
        }
    });
    aed_array_adapter.setEditBtnNotifyListener(ntfy);
    update_apply.setVisibility(Button.GONE);
    update_cancel.setVisibility(Button.GONE);
    update_apply.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType,
                    spinnerExtraDataBoolean);
            if (!no_err)
                return;
            int pos = -1;
            for (int i = 0; i < aed_array_list.size(); i++) {
                if (aed_array_list.get(i).while_edit) {
                    pos = i;
                    break;
                }
            }
            if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                aed_array_list.get(pos).data_value = et_string.getText().toString();
                aed_array_list.get(pos).while_edit = false;
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
                aed_array_list.get(pos).data_value = et_int.getText().toString();
                aed_array_list.get(pos).while_edit = false;
            } else if (spinnerExtraDataType.getSelectedItem()
                    .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
                String n_boolean = "true";
                if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false"))
                    n_boolean = "false";
                aed_array_list.get(pos).data_value = n_boolean;
                aed_array_list.get(pos).while_edit = false;
            }
            et_string.setText("");
            et_int.setText("");
            et_string.setVisibility(EditText.GONE);
            et_int.setVisibility(EditText.GONE);
            spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
            aed_array_adapter.notifyDataSetChanged();
            update_apply.setVisibility(Button.GONE);
            update_cancel.setVisibility(Button.GONE);
            spinnerExtraDataType.setEnabled(true);
            btn_ok.setEnabled(true);
            btn_cancel.setEnabled(true);
            cb_array.setEnabled(true);
            btn_add_array.setEnabled(true);
        }
    });
    update_cancel.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            for (int i = 0; i < aed_array_list.size(); i++) {
                aed_array_list.get(i).while_edit = false;
            }
            et_string.setText("");
            et_int.setText("");
            et_string.setVisibility(EditText.GONE);
            et_int.setVisibility(EditText.GONE);
            spinnerExtraDataBoolean.setVisibility(Spinner.GONE);
            aed_array_adapter.notifyDataSetChanged();
            update_apply.setVisibility(Button.GONE);
            update_cancel.setVisibility(Button.GONE);
            spinnerExtraDataType.setEnabled(true);
            btn_ok.setEnabled(true);
            btn_cancel.setEnabled(true);
            cb_array.setEnabled(true);
            btn_add_array.setEnabled(true);
        }
    });

    // CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // OK?
    btn_ok.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            ActivityExtraDataItem aedi = null;
            if (sel_pos == -1) {//Add item
                if (et_key.getText().toString().equals("")) {
                    dlg_msg.setText(mGlblParms.context
                            .getString(R.string.msgs_edit_profile_action_activity_extra_data_key_name_missing));
                    return;
                }
                aedi = new ActivityExtraDataItem();
            } else {//Edit item
                aedi = mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos);
            }
            aedi.key_value = et_key.getText().toString();
            if (cb_array.isChecked()) {
                if (aed_array_list.size() == 0) {
                    dlg_msg.setText(mGlblParms.context.getString(
                            R.string.msgs_edit_profile_action_activity_extra_data_array_data_missing));
                    return;
                }
                aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES;
                aedi.data_type = spinnerExtraDataType.getSelectedItem().toString();
                aedi.data_value = "";
                //               Log.v("","array size="+aed_array_list.size());
                for (int i = 0; i < aed_array_list.size(); i++) {
                    if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                        //                     aedi.data_value+="\u00a0"+aed_array_list.get(i).array_data_value+"\u0003";
                        aedi.data_value += aed_array_list.get(i).data_value + "\u0003";
                        //                     GeneralUtilities.hexString("String",aed_array_list.get(i).array_data_value.getBytes(),0,aed_array_list.get(i).array_data_value.getBytes().length);
                    } else {
                        aedi.data_value += aed_array_list.get(i).data_value + "\u0003";
                        //                     GeneralUtilities.hexString("int",aed_array_list.get(i).data_value.getBytes(),0,aed_array_list.get(i).data_value.getBytes().length);
                    }
                }
                //               GeneralUtilities.hexString("test",aedi.data_value.getBytes(),0,aedi.data_value.getBytes().length);
                //               Log.v("","dv="+aedi.data_value.replaceAll("\u0003", ";"));
            } else {
                boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType,
                        spinnerExtraDataBoolean);
                if (!no_err)
                    return;
                else {
                    aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_NO;
                    aedi.data_type = spinnerExtraDataType.getSelectedItem().toString();
                    if (spinnerExtraDataType.getSelectedItem().toString()
                            .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) {
                        aedi.data_value = et_string.getText().toString();
                    } else if (spinnerExtraDataType.getSelectedItem().toString()
                            .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) {
                        aedi.data_value = et_int.getText().toString();
                    } else if (spinnerExtraDataType.getSelectedItem().toString()
                            .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) {
                        if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false"))
                            aedi.data_value = "false";
                        else
                            aedi.data_value = "true";
                    }
                }
            }
            if (sel_pos == -1)
                mGlblParms.activityExtraDataEditListAdapter.add(aedi);
            if (mGlblParms.activityExtraDataEditListAdapter.getItem(0).key_value.equals(""))
                mGlblParms.activityExtraDataEditListAdapter.remove(0);
            mGlblParms.activityExtraDataEditListAdapter.notifyDataSetChanged();

            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityShare.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;/* www  .  j  a  va  2 s .  c om*/

    // 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) {
        // Enable ok
        // (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());
                }

                // Export
                else 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());
                    }
                }

                // Submit
                else 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();
        }
    });
}

From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java

public void showRecordingDialog() {
    if (!running || scheduler == null || demodulator == null || source == null) {
        toaster.showLong("Analyzer must be running to start recording");
        return;/* w  w w  .ja  v  a 2s.  c o  m*/
    }
    // Check for the WRITE_EXTERNAL_STORAGE permission:
    if (ContextCompat.checkSelfPermission(this,
            "android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" },
                PERMISSION_REQUEST_RECORDING_WRITE_FILES);
        return; // wait for the permission response (handled in onRequestPermissionResult())
    }

    final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    final int[] supportedSampleRates = rxSampleRate.getSupportedSampleRates();
    final double maxFreqMHz = rxFrequency.getMax() / 1000000f; // max frequency of the source in MHz
    final int sourceType = Integer.parseInt(preferences.getString(getString(R.string.pref_sourceType), "1"));
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);

    // Get references to the GUI components:
    final ScrollView view = (ScrollView) this.getLayoutInflater().inflate(R.layout.start_recording, null);
    final EditText et_filename = (EditText) view.findViewById(R.id.et_recording_filename);
    final EditText et_frequency = (EditText) view.findViewById(R.id.et_recording_frequency);
    final Spinner sp_sampleRate = (Spinner) view.findViewById(R.id.sp_recording_sampleRate);
    final TextView tv_fixedSampleRateHint = (TextView) view.findViewById(R.id.tv_recording_fixedSampleRateHint);
    final CheckBox cb_stopAfter = (CheckBox) view.findViewById(R.id.cb_recording_stopAfter);
    final EditText et_stopAfter = (EditText) view.findViewById(R.id.et_recording_stopAfter);
    final Spinner sp_stopAfter = (Spinner) view.findViewById(R.id.sp_recording_stopAfter);

    // Setup the sample rate spinner:
    final ArrayAdapter<Integer> sampleRateAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1);
    for (int sampR : supportedSampleRates)
        sampleRateAdapter.add(sampR);
    sampleRateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_sampleRate.setAdapter(sampleRateAdapter);

    // Add listener to the frequency textfield, the sample rate spinner and the checkbox:
    et_frequency.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (et_frequency.getText().length() == 0)
                return;
            double freq = Double.parseDouble(et_frequency.getText().toString());
            if (freq < maxFreqMHz)
                freq = freq * 1000000;
            et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_"
                    + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq");
        }
    });
    sp_sampleRate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (et_frequency.getText().length() == 0)
                return;
            double freq = Double.parseDouble(et_frequency.getText().toString());
            if (freq < maxFreqMHz)
                freq = freq * 1000000;
            et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_"
                    + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq");
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    cb_stopAfter.setOnCheckedChangeListener((buttonView, isChecked) -> {
        et_stopAfter.setEnabled(isChecked);
        sp_stopAfter.setEnabled(isChecked);
    });

    // Set default frequency, sample rate and stop after values:
    et_frequency.setText(Long.toString(analyzerSurface.getVirtualFrequency()));
    int sampleRateIndex = 0;
    int lastSampleRate = preferences.getInt(getString(R.string.pref_recordingSampleRate), 1000000);
    for (; sampleRateIndex < supportedSampleRates.length; sampleRateIndex++) {
        if (supportedSampleRates[sampleRateIndex] >= lastSampleRate)
            break;
    }
    if (sampleRateIndex >= supportedSampleRates.length)
        sampleRateIndex = supportedSampleRates.length - 1;
    sp_sampleRate.setSelection(sampleRateIndex);
    cb_stopAfter.toggle(); // just to trigger the listener at least once!
    cb_stopAfter.setChecked(preferences.getBoolean(getString(R.string.pref_recordingStopAfterEnabled), false));
    et_stopAfter.setText(
            Integer.toString(preferences.getInt(getString(R.string.pref_recordingStopAfterValue), 10)));
    sp_stopAfter.setSelection(preferences.getInt(getString(R.string.pref_recordingStopAfterUnit), 0));

    // disable sample rate selection if demodulation is running:
    if (demodulationMode != Demodulator.DEMODULATION_OFF) {
        sampleRateAdapter.add(rxSampleRate.get()); // add the current sample rate in case it's not already in the list
        sp_sampleRate.setSelection(sampleRateAdapter.getPosition(rxSampleRate.get())); // select it
        sp_sampleRate.setEnabled(false); // disable the spinner
        tv_fixedSampleRateHint.setVisibility(View.VISIBLE);
    }

    // Show dialog:
    new AlertDialog.Builder(this).setTitle("Start recording").setView(view)
            .setPositiveButton("Record", (dialog, whichButton) -> {
                String filename = et_filename.getText().toString();
                final int stopAfterUnit = sp_stopAfter.getSelectedItemPosition();
                final int stopAfterValue = Integer.parseInt(et_stopAfter.getText().toString());
                //todo check filename

                // Set the frequency in the source:
                if (et_frequency.getText().length() == 0)
                    return;
                double freq = Double.parseDouble(et_frequency.getText().toString());
                if (freq < maxFreqMHz)
                    freq = freq * 1000000;
                if (freq <= rxFrequency.getMax() && freq >= rxFrequency.getMin())
                    rxFrequency.set((long) freq);
                else {
                    toaster.showLong("Frequency is invalid!");
                    return;
                }

                // Set the sample rate (only if demodulator is off):
                if (demodulationMode == Demodulator.DEMODULATION_OFF)
                    rxSampleRate.set((Integer) sp_sampleRate.getSelectedItem());

                // Open file and start recording:
                recordingFile = new File(externalDir + "/" + RECORDING_DIR + "/" + filename);
                recordingFile.getParentFile().mkdir(); // Create directory if it does not yet exist
                try {
                    scheduler.startRecording(new BufferedOutputStream(new FileOutputStream(recordingFile)));
                } catch (FileNotFoundException e) {
                    Log.e(LOGTAG, "showRecordingDialog: File not found: " + recordingFile.getAbsolutePath());
                }

                // safe preferences:
                SharedPreferences.Editor edit = preferences.edit();
                edit.putInt(getString(R.string.pref_recordingSampleRate),
                        (Integer) sp_sampleRate.getSelectedItem());
                edit.putBoolean(getString(R.string.pref_recordingStopAfterEnabled), cb_stopAfter.isChecked());
                edit.putInt(getString(R.string.pref_recordingStopAfterValue), stopAfterValue);
                edit.putInt(getString(R.string.pref_recordingStopAfterUnit), stopAfterUnit);
                edit.apply();

                analyzerSurface.setRecordingEnabled(true);

                updateActionBar();

                // if stopAfter was selected, start thread to supervise the recording:
                if (cb_stopAfter.isChecked()) {
                    final String recorderSuperviserName = "Supervisor Thread";
                    Thread supervisorThread = new Thread(() -> {
                        Log.i(LOGTAG, "recording_superviser: Supervisor Thread started. (Thread: "
                                + recorderSuperviserName + ")");
                        try {
                            long startTime = System.currentTimeMillis();
                            boolean stop = false;

                            // We check once per half a second if the stop criteria is met:
                            Thread.sleep(500);
                            while (recordingFile != null && !stop) {
                                switch (stopAfterUnit) { // see arrays.xml - recording_stopAfterUnit
                                case 0: /* MB */
                                    if (recordingFile.length() / 1000000 >= stopAfterValue)
                                        stop = true;
                                    break;
                                case 1: /* GB */
                                    if (recordingFile.length() / 1000000000 >= stopAfterValue)
                                        stop = true;
                                    break;
                                case 2: /* sec */
                                    if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000)
                                        stop = true;
                                    break;
                                case 3: /* min */
                                    if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000 * 60)
                                        stop = true;
                                    break;
                                }
                            }
                            // stop recording:
                            stopRecording();
                        } catch (InterruptedException e) {
                            // todo: shouldn't we call stopRecording() here? how about finally{}?
                            Log.e(LOGTAG, "recording_superviser: Interrupted!");
                        } catch (NullPointerException e) {
                            Log.e(LOGTAG, "recording_superviser: Recording file is null!");
                        }
                        Log.i(LOGTAG, "recording_superviser: Supervisor Thread stopped. (Thread: "
                                + recorderSuperviserName + ")");

                    }, recorderSuperviserName);
                    supervisorThread.start();
                }
            }).setNegativeButton("Cancel", (dialog, whichButton) -> {
                // do nothing
            }).show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:info.corne.performancetool.MainActivity.java

/**
 * This function will be triggered when the hardware info
 * is loaded, It will then use that info to fill the view
 * in the activities. /*from   www . ja  v a2s .  c o m*/
 * @param result A array with all the info needed.
 */
public void hardwareInfoLoaded(String[] result) {
    // Get the views
    Spinner governorSpinner = (Spinner) findViewById(R.id.governorSpinner);
    Spinner frequencyCapSpinner = (Spinner) findViewById(R.id.frequencyCapSpinner);
    Spinner suspendCapSpinner = (Spinner) findViewById(R.id.suspendCapSpinner);
    Spinner audioCapSpinner = (Spinner) findViewById(R.id.audioCapSpinner);
    Spinner ioSchedulerSpinner = (Spinner) findViewById(R.id.ioSchedulerSpinner);
    SeekBar maxCpusSeek = (SeekBar) findViewById(R.id.maxCpusSeek);
    Switch ocSwitch = (Switch) findViewById(R.id.overclockSwitch);
    Switch lpOcSwitch = (Switch) findViewById(R.id.lpOverclockSwitch);
    Switch gpuScalingSwitch = (Switch) findViewById(R.id.gpuScalingSwitch);
    Switch gpuQuickOCSwitch = (Switch) findViewById(R.id.gpuOCSwitch);
    TextView gpuOCValues = (TextView) findViewById(R.id.gpuOCValues);
    Spinner a2dpCapSpinner = (Spinner) findViewById(R.id.a2dpCapSpinner);

    // The returned data will be stored in their variables.
    String[] governors = result[0].split(" ");
    String[] freqencies = result[1].split(" ");
    // frequenciesShort will be Disabled + all the frequencies in MHz.
    String[] frequenciesShort = new String[freqencies.length + 1];
    String[] suspendFreqsShort = new String[freqencies.length + 1];
    String[] audioFreqsShort = new String[freqencies.length + 1];
    String[] a2dpFreqShort = new String[freqencies.length + 1];
    Spinner cpqGovernorSpinner = (Spinner) findViewById(R.id.cpqGovernorSpinner);
    String[] cpqGovernors = result[10].split(" ");

    frequenciesShort[0] = getResources().getString(R.string.disabled_string);
    suspendFreqsShort[0] = getResources().getString(R.string.disabled_string);
    audioFreqsShort[0] = getResources().getString(R.string.disabled_string);
    a2dpFreqShort[0] = getResources().getString(R.string.disabled_string);

    ioSchedulers = result[4].split(" ");
    int currentFrequencyPos = freqencies.length - 1;
    int currentSuspendPos = 0;
    int currentAudioPos = 0;
    int currentA2dpPos = 0;
    int currentIOScheduler = ioSchedulers.length - 1;
    // Will loop trough the frequencies and convert them to MHz.
    for (int i = 0; i < freqencies.length; i++) {
        if (result[3].indexOf("000") == -1)
            currentFrequencyPos = 0;
        else if (result[3].compareTo(freqencies[i]) == 0)
            currentFrequencyPos = i + 1;

        if (result[8].indexOf("000") == -1)
            currentSuspendPos = 0;
        else if (result[8].compareTo(freqencies[i]) == 0)
            currentSuspendPos = i + 1;

        if (result[9].equals("Error"))
            audioCapSpinner.setVisibility(View.GONE);
        if (result[9].indexOf("000") == -1)
            currentAudioPos = 0;
        else if (result[9].compareTo(freqencies[i]) == 0)
            currentAudioPos = i + 1;

        if (result[18].equals("Error"))
            a2dpCapSpinner.setVisibility(View.GONE);
        if (result[18].indexOf("000") == -1)
            currentA2dpPos = 0;
        else if (result[18].compareTo(freqencies[i]) == 0)
            currentA2dpPos = i + 1;

        frequenciesShort[i + 1] = freqencies[i].replaceFirst("000", "")
                + getResources().getString(R.string.mhz);
        suspendFreqsShort[i + 1] = freqencies[i].replaceFirst("000", "")
                + getResources().getString(R.string.mhz);
        audioFreqsShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz);
        a2dpFreqShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz);
    }
    // And that will also be stored in the adapter.
    frequencyCapSpinner.setAdapter(generateAdapter(frequenciesShort));
    suspendCapSpinner.setAdapter(generateAdapter(suspendFreqsShort));
    audioCapSpinner.setAdapter(generateAdapter(audioFreqsShort));
    a2dpCapSpinner.setAdapter(generateAdapter(a2dpFreqShort));
    // And the current selected freq will be selected.
    frequencyCapSpinner.setSelection(currentFrequencyPos);
    suspendCapSpinner.setSelection(currentSuspendPos);
    audioCapSpinner.setSelection(currentAudioPos);
    a2dpCapSpinner.setSelection(currentA2dpPos);

    // All the governors will be add to the spinner.
    governorSpinner.setAdapter(generateAdapter(governors));
    // And the current selected governor will be selected
    // in the spinner.
    for (int i = 0; i < governors.length; i++) {
        if (result[2].compareTo(governors[i]) == 0)
            governorSpinner.setSelection(i);
    }

    // Will search for the currently selected IO scheduler.
    for (int i = 0; i < ioSchedulers.length; i++) {
        if (ioSchedulers[i].charAt(0) == '[') {
            currentIOScheduler = i;
            ioSchedulers[i] = ioSchedulers[i].substring(1, ioSchedulers[i].length() - 1);
        }
    }
    // And fill the spinners/set selection
    ioSchedulerSpinner.setAdapter(generateAdapter(ioSchedulers));
    ioSchedulerSpinner.setSelection(currentIOScheduler);

    // If overclock is one turn the switch on.
    if (result[5].equals("1"))
        ocSwitch.setChecked(true);
    else
        ocSwitch.setChecked(false);
    onOverclockSwitchClick(ocSwitch);

    if (!result[6].equals("Error") || !result[7].equals("Error")) {
        if (!result[6].equals("Error")) {
            maxCpusSeek.setProgress((int) Float.parseFloat(result[6]) - 1);
        }
        if (!result[7].equals("Error")) {
            maxCpusSeek.setProgress((int) Float.parseFloat(result[7]) - 1);
        }
    } else {
        maxCpusSeek.setVisibility(View.GONE);
        ((TextView) findViewById(R.id.maxCpusTextView)).setVisibility(View.GONE);
    }

    if (!result[11].equals("Error")) {
        cpqGovernorSpinner.setAdapter(generateAdapter(cpqGovernors));
        for (int i = 0; i < cpqGovernors.length; i++) {
            if (result[11].compareTo(cpqGovernors[i]) == 0)
                cpqGovernorSpinner.setSelection(i);
        }
    } else {
        cpqGovernorSpinner.setVisibility(View.GONE);
        ((TextView) findViewById(R.id.cpqGovernorTextView)).setVisibility(View.GONE);
    }

    if (!result[12].equals("Error")) {
        // If lp overclock is one turn the switch on.
        if (result[12].equals("1"))
            lpOcSwitch.setChecked(true);
        else
            lpOcSwitch.setChecked(false);
        onLpOverclockSwitchClick(lpOcSwitch);
    } else {
        lpOcSwitch.setVisibility(View.GONE);
        ((TextView) findViewById(R.id.lpOverclockInfo)).setVisibility(View.GONE);
    }

    if (!result[13].equals("Error")) {
        if (result[13].equals("1"))
            gpuScalingSwitch.setChecked(true);
        else
            gpuScalingSwitch.setChecked(false);
    } else {
        gpuScalingSwitch.setVisibility(View.GONE);
    }

    if (!result[14].equals("Error")) {
        if (result[14].equals("0")) {
            cpuHotplugging = true;
            updateCpuHotpluggingView(true);
        } else {
            cpuHotplugging = false;
            updateCpuHotpluggingView(true);
        }
    } else {
        cpuHotplugging = true;
        updateCpuHotpluggingView(true);
        ((RadioButton) findViewById(R.id.cpu_hotplug_mode)).setVisibility(View.GONE);
        ((RadioButton) findViewById(R.id.cpu_manual_mode)).setVisibility(View.GONE);
    }

    if (!result[15].equals("Error")) {
        updateActiveCpusView(result[15]);
    }

    if (!result[16].equals("Error")) {
        if (result[16].equals("1"))
            gpuQuickOCSwitch.setChecked(true);
        else
            gpuQuickOCSwitch.setChecked(false);
    } else {
        gpuQuickOCSwitch.setVisibility(View.GONE);
    }

    if (!result[17].equals("Error")) {
        gpuOCValuesString = result[17];
        gpuOCValues.setText(gpuOCValuesString);
    } else {
        gpuOCValues.setVisibility(View.GONE);
    }

    dialog.dismiss();

    updateFromView();
    updatePreferences("");

    refreshProfilesList();
    ListView profilesList = (ListView) findViewById(R.id.profilesListView);
    registerForContextMenu(profilesList);
    profilesList.setOnItemClickListener(this);
}