List of usage examples for android.widget Spinner setSelection
@Override public void setSelection(int position)
From source file:org.eyeseetea.malariacare.LoginActivity.java
private void initDataDownloadPeriodDropdown() { if (!BuildConfig.loginDataDownloadPeriod) { return;/*from w w w . j a va 2 s .c om*/ } ViewGroup loginViewsContainer = (ViewGroup) findViewById(R.id.login_dynamic_views_container); getLayoutInflater().inflate(R.layout.login_spinner, loginViewsContainer, true); //Add left text for the spinner "title" findViewById(R.id.date_spinner_container).setVisibility(View.VISIBLE); TextView textView = (TextView) findViewById(R.id.data_text_view); textView.setText(R.string.download); //add options ArrayList<String> dataLimitOptions = new ArrayList<>(); dataLimitOptions.add(getString(R.string.no_data)); dataLimitOptions.add(getString(R.string.last_6_days)); dataLimitOptions.add(getString(R.string.last_6_weeks)); dataLimitOptions.add(getString(R.string.last_6_months)); final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, dataLimitOptions); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //add spinner Spinner spinner = (Spinner) findViewById(R.id.data_spinner); spinner.setVisibility(View.VISIBLE); spinner.setAdapter(spinnerArrayAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { PreferencesState.getInstance().setDataLimitedByDate(spinnerArrayAdapter.getItem(pos).toString()); } public void onNothingSelected(AdapterView<?> parent) { } }); //select the selected option or default no data option String dateLimit = PreferencesState.getInstance().getDataLimitedByDate(); if (dateLimit.equals("")) { spinner.setSelection(spinnerArrayAdapter.getPosition(getString(R.string.no_data))); } else { spinner.setSelection(spinnerArrayAdapter.getPosition(dateLimit)); } }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateSecondForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title))); EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY); passwordEditText.setTransformationMethod(new PasswordTransformationMethod()); formLayout.addView(passwordEditText); formLayout.addView(createErrorView(PASSWORD_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);// w w w. j a v a2 s .com params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array, android.R.layout.simple_spinner_item); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(GENDER_KEY, adapter.getItem(pos).toString()); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); if (mFormData.get(GENDER_KEY) != null) { spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY))); } formLayout.addView(spinner); }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void ShowTaskDialog(Task task, OnClickListener okListener) { LayoutInflater inflater = this.getLayoutInflater(); View dlgView = inflater.inflate(R.layout.dialog_task, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dlgView);/*from ww w . java 2 s .c om*/ builder.setTitle("Task"); final TextView nameEdit = (TextView) dlgView.findViewById(R.id.task_name_edit); nameEdit.setText(task.mName); final TextView descriptionEdit = (TextView) dlgView.findViewById(R.id.task_description_edit); descriptionEdit.setText(task.mDescription); final TextView dueDateView = (TextView) dlgView.findViewById(R.id.task_due_date); SetFriendlyDueDateText(dueDateView, task.mDueDate); Button dueDateButton = (Button) dlgView.findViewById(R.id.task_due_date_choose); final Calendar dueDate = task.mDueDate; final Task thisTask = task; dueDateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShowDueDateDialog(dueDate, new OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { Dialog dlg = (Dialog) dialogInterface; DatePicker datePicker = (DatePicker) dlg.findViewById(R.id.due_date_calendar); Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); thisTask.mDueDate = calendar; SetFriendlyDueDateText(dueDateView, thisTask.mDueDate); } }); } }); final CheckBox repeatCheck = (CheckBox) dlgView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); } }); Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE; repeatCheck.setChecked(repeat); SetRepeatVisibility(dlgView, repeat); final EditText repeatTimeEdit = (EditText) dlgView.findViewById(R.id.repeat_time); repeatTimeEdit.setText(Integer.toString(task.mRepeatTime)); final Spinner repeatUnitSpinner = (Spinner) dlgView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, repeatUnits)); int repeatUnitPos = 0; switch (task.mRepeatUnit) { case DAYS: repeatUnitPos = 0; break; case WEEKS: repeatUnitPos = 1; break; case MONTHS: repeatUnitPos = 2; break; case YEARS: repeatUnitPos = 3; break; case NONE: repeatUnitPos = 0; } repeatUnitSpinner.setSelection(repeatUnitPos); final RadioButton repeatFromComplete = (RadioButton) dlgView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) dlgView.findViewById(R.id.repeat_from_due); if (task.mRepeatFromComplete) { repeatFromComplete.setChecked(true); } else { repeatFromDue.setChecked(true); } // Here's a trick: We cascade the OnClick listeners so we can extract // the dialog contents into the task before calling the second listener. final OnClickListener userListener = okListener; final Task myTask = task; OnClickListener cascadedListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { myTask.mName = nameEdit.getText().toString(); myTask.mDescription = descriptionEdit.getText().toString(); myTask.mRepeatUnit = Task.RepeatUnit.NONE; if (repeatCheck.isChecked()) { switch (repeatUnitSpinner.getSelectedItemPosition()) { case 0: myTask.mRepeatUnit = Task.RepeatUnit.DAYS; break; case 1: myTask.mRepeatUnit = Task.RepeatUnit.WEEKS; break; case 2: myTask.mRepeatUnit = Task.RepeatUnit.MONTHS; break; case 3: myTask.mRepeatUnit = Task.RepeatUnit.YEARS; break; } myTask.mRepeatTime = Integer.parseInt(repeatTimeEdit.getText().toString()); myTask.mRepeatFromComplete = repeatFromComplete.isChecked(); } userListener.onClick(dialog, which); } }; builder.setNegativeButton("Cancel", null); builder.setPositiveButton("OK", cascadedListener); builder.show(); }
From source file:org.tigase.mobile.muc.JoinMucDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = new Dialog(getActivity()); dialog.setCancelable(true);//w w w. j a va 2s .co m dialog.setCanceledOnTouchOutside(true); dialog.setContentView(R.layout.join_room_dialog); dialog.setTitle(getString(R.string.aboutButton)); ArrayList<String> accounts = new ArrayList<String>(); for (Account account : AccountManager.get(getActivity()).getAccountsByType(Constants.ACCOUNT_TYPE)) { accounts.add(account.name); } final Spinner accountSelector = (Spinner) dialog.findViewById(R.id.muc_accountSelector); final Button joinButton = (Button) dialog.findViewById(R.id.muc_joinButton); final Button cancelButton = (Button) dialog.findViewById(R.id.muc_cancelButton); final TextView name = (TextView) dialog.findViewById(R.id.muc_name); final TextView roomName = (TextView) dialog.findViewById(R.id.muc_roomName); final TextView mucServer = (TextView) dialog.findViewById(R.id.muc_server); final TextView nickname = (TextView) dialog.findViewById(R.id.muc_nickname); final TextView password = (TextView) dialog.findViewById(R.id.muc_password); final CheckBox autojoin = (CheckBox) dialog.findViewById(R.id.muc_autojoin); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, accounts.toArray(new String[] {})); accountSelector.setAdapter(adapter); Bundle data = getArguments(); final boolean editMode = data != null && data.containsKey("editMode") && data.getBoolean("editMode"); final String id = data != null ? data.getString("id") : null; if (data != null) { accountSelector.setSelection(adapter.getPosition(data.getString("account"))); name.setText(data.getString("name")); roomName.setText(data.getString("room")); mucServer.setText(data.getString("server")); nickname.setText(data.getString("nick")); password.setText(data.getString("password")); autojoin.setChecked(data.getBoolean("autojoin")); } if (!editMode) { name.setVisibility(View.GONE); autojoin.setVisibility(View.GONE); } else { joinButton.setText("Save"); } cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); joinButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (editMode) { BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString()); final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()) .getMultiJaxmpp().get(account); Bundle data = new Bundle(); data.putString("id", id); data.putString("account", account.toString()); data.putString("name", name.getText().toString()); data.putString("room", roomName.getText().toString()); data.putString("server", mucServer.getText().toString()); data.putString("nick", nickname.getText().toString()); data.putString("password", password.getText().toString()); data.putBoolean("autojoin", autojoin.isChecked()); ((BookmarksActivity) getActivity()).saveItem(data); dialog.dismiss(); return; } BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString()); final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()) .getMultiJaxmpp().get(account); Runnable r = new Runnable() { @Override public void run() { try { Room room = jaxmpp.getModule(MucModule.class).join( roomName.getEditableText().toString(), mucServer.getEditableText().toString(), nickname.getEditableText().toString(), password.getEditableText().toString()); if (task != null) task.execute(room); } catch (Exception e) { Log.w("MUC", "", e); // TODO Auto-generated catch block e.printStackTrace(); } } }; (new Thread(r)).start(); dialog.dismiss(); } }); return dialog; }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateThirdForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title))); EditText cityEditText = createEditText(mContext.getString(R.string.account_create_city_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY); if (mFormData.get(CITY_KEY) != null) { cityEditText.setText(mFormData.get(CITY_KEY)); }/*from w w w . jav a2s . c om*/ formLayout.addView(cityEditText); formLayout.addView(createErrorView(CITY_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, Countries.COUNTRIES); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); if (mFormData.get(COUNTRY_KEY) != null) { List<String> array = Arrays.asList(Countries.COUNTRY_CODES); spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY))); } formLayout.addView(spinner); }
From source file:com.bai.android.ui.OtherActivity.java
/** Selects a String value in a spinner if the spinner contains that value. */ private void selectSpinnerItem(Spinner targetSpinner, String searchValue) { // if the user doesn't have an assigned value - don't select anything if (searchValue == null) { return;/*from w ww . j a va 2s .c o m*/ } // find the position of the value in the spinner int position = -1; for (int i = 0; i < targetSpinner.getCount(); i++) { if (searchValue.equals(targetSpinner.getItemAtPosition(i))) { position = i; break; } } // select the value in the spinner if (position != -1) { targetSpinner.setSelection(position); } }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override void initConfigurationForm(final FetcherOptionsDialog dialog) { // Disable development permission checkbox if it's not available if (!DEVELOPMENT_PERMISSIONS_SUPPORTED) { dialog.findView(R.id.permission_filter_development).setEnabled(false); }//from www . j a v a2s . c o m // Prepare protection preset spinner { // Find current preset int currentPresetId = PROTECTION_PRESETS.length; // "Custom" if nothing found if (!testWritePermissionForProviders) { for (int i = 0; i < PROTECTION_PRESETS.length; i++) { if (protection == PROTECTION_PRESETS[i]) { currentPresetId = i; dialog.findView(R.id.permission_filter_details).setVisibility(View.GONE); break; } } } // Fill spinner Spinner protectionPresetSpinner = (Spinner) dialog.findView(R.id.permission_filter_spinner); Activity activity = dialog.getActivity(); protectionPresetSpinner .setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, new String[] { activity.getString(R.string.permission_filter_show_all), // 0 activity.getString(R.string.permission_filter_show_exported), // 1 activity.getString(R.string.permission_filter_show_obtainable), // 2 activity.getString(R.string.permission_filter_world_accessible), // 3 activity.getString(R.string.filter_custom) // 4 })); protectionPresetSpinner.setSelection(currentPresetId); // Set up spinner event protectionPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { boolean isCustom = position == PROTECTION_PRESETS.length; if (!isCustom) { int preset = PROTECTION_PRESETS[position]; dialog.setBoxChecked(R.id.permission_filter_world_accessible, (preset & PROTECTION_WORLD_ACCESSIBLE) != 0); dialog.setBoxChecked(R.id.permission_filter_normal, (preset & PROTECTION_NORMAL) != 0); dialog.setBoxChecked(R.id.permission_filter_dangerous, (preset & PROTECTION_DANGEROUS) != 0); dialog.setBoxChecked(R.id.permission_filter_signature, (preset & PROTECTION_SIGNATURE) != 0); dialog.setBoxChecked(R.id.permission_filter_system, (preset & PROTECTION_SYSTEM) != 0); dialog.setBoxChecked(R.id.permission_filter_development, (preset & PROTECTION_DEVELOPMENT) != 0); dialog.setBoxChecked(R.id.permission_filter_unexported, (preset & PROTECTION_UNEXPORTED) != 0); dialog.setBoxChecked(R.id.permission_filter_unknown, (preset & PROTECTION_UNKNOWN) != 0); dialog.setBoxChecked(R.id.read_permission, true); } dialog.findView(R.id.permission_filter_details) .setVisibility(isCustom ? View.VISIBLE : View.GONE); } @Override public void onNothingSelected(AdapterView<?> parent) { // Spinner cannot have nothing selected } }); } // Fill form dialog.setBoxChecked(R.id.system_apps, (appType & APP_TYPE_SYSTEM) != 0); dialog.setBoxChecked(R.id.user_apps, (appType & APP_TYPE_USER) != 0); dialog.setBoxChecked(R.id.activities, (type & PackageManager.GET_ACTIVITIES) != 0); dialog.setBoxChecked(R.id.receivers, (type & PackageManager.GET_RECEIVERS) != 0); dialog.setBoxChecked(R.id.services, (type & PackageManager.GET_SERVICES) != 0); dialog.setBoxChecked(R.id.content_providers, (type & PackageManager.GET_PROVIDERS) != 0); dialog.setBoxChecked(R.id.permission_filter_world_accessible, (protection & PROTECTION_WORLD_ACCESSIBLE) != 0); dialog.setBoxChecked(R.id.permission_filter_normal, (protection & PROTECTION_NORMAL) != 0); dialog.setBoxChecked(R.id.permission_filter_dangerous, (protection & PROTECTION_DANGEROUS) != 0); dialog.setBoxChecked(R.id.permission_filter_signature, (protection & PROTECTION_SIGNATURE) != 0); dialog.setBoxChecked(R.id.permission_filter_system, (protection & PROTECTION_SYSTEM) != 0); dialog.setBoxChecked(R.id.permission_filter_development, (protection & PROTECTION_DEVELOPMENT) != 0); dialog.setBoxChecked(R.id.permission_filter_unexported, (protection & PROTECTION_UNEXPORTED) != 0); dialog.setBoxChecked(R.id.permission_filter_unknown, (protection & PROTECTION_UNKNOWN) != 0); dialog.setBoxChecked(testWritePermissionForProviders ? R.id.write_permission : R.id.read_permission, true); dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, includeOnlyProvidersAllowingPermissionGranting); dialog.setBoxChecked(R.id.metadata, requireMetaDataSubstring != null); dialog.setTextInField(R.id.metadata_substring, requireMetaDataSubstring); // Set up sections showing when their checkboxes are checked dialog.findView(R.id.content_provider_permission_type) .setVisibility(testWritePermissionForProviders ? View.VISIBLE : View.GONE); dialog.findView(R.id.content_provider_options) .setVisibility((type & PackageManager.GET_PROVIDERS) != 0 ? View.VISIBLE : View.GONE); ((CheckBox) dialog.findView(R.id.content_providers)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { dialog.findView(R.id.content_provider_permission_type) .setVisibility(isChecked ? View.VISIBLE : View.GONE); dialog.findView(R.id.content_provider_options) .setVisibility(isChecked ? View.VISIBLE : View.GONE); if (!isChecked) { dialog.setBoxChecked(R.id.read_permission, true); dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, false); } } }); dialog.findView(R.id.metadata_details) .setVisibility(requireMetaDataSubstring != null ? View.VISIBLE : View.GONE); ((CheckBox) dialog.findView(R.id.metadata)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { dialog.findView(R.id.metadata_details).setVisibility(isChecked ? View.VISIBLE : View.GONE); if (!isChecked) { dialog.setTextInField(R.id.metadata_substring, ""); } } }); }
From source file:com.ncode.android.apps.schedo.ui.MyScheduleActivity.java
private void trySetUpActionBarSpinner() { Toolbar toolbar = getActionBarToolbar(); if (mSpinnerConfigured || mSchedMetadata == null || toolbar == null) { // already done it, or not ready yet, or don't need to do LOGD(TAG, "Not configuring Action Bar spinner."); return;/*from w ww. j a va 2s. c o m*/ } LOGD(TAG, "Configuring Action Bar spinner."); mSpinnerConfigured = true; mTopLevelSpinnerAdapter.clear(); mTopLevelSpinnerAdapter.addItem("", getString(R.string.all_events), false, 0); int itemToSelect = -1; Collection<MyScheduleMetadata.MySchedEvent> events = mSchedMetadata.getMyScheduleEvents(); if (events != null) { //mTopLevelSpinnerAdapter.addHeader(categoryTitle); for (MyScheduleMetadata.MySchedEvent e : events) { LOGD(TAG, "Adding item to spinner: " + e.getId() + " --> " + e.getTitle()); int eventColor = e.getColor() > 0 ? e.getColor() : 0; mTopLevelSpinnerAdapter.addItem(e.getId(), e.getTitle(), true, eventColor); if (!TextUtils.isEmpty(mFilterSchedsToRestore) && e.getId().equals(mFilterSchedsToRestore)) { mFilterSchedsToRestore = null; itemToSelect = mTopLevelSpinnerAdapter.getCount() - 1; } } } else { LOGW(TAG, "No events scheduled"); } mFilterSchedsToRestore = null; View spinnerContainer = LayoutInflater.from(this).inflate(R.layout.actionbar_spinner, toolbar, false); ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); toolbar.addView(spinnerContainer, lp); Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.actionbar_spinner); spinner.setAdapter(mTopLevelSpinnerAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> spinner, View view, int position, long itemId) { onTopLevelEventSelected(mTopLevelSpinnerAdapter.getTag(position)); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); if (itemToSelect >= 0) { LOGD(TAG, "Restoring item selection to primary spinner: " + itemToSelect); spinner.setSelection(itemToSelect); } updateHeaderColor(); //showSecondaryFilters(); }
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_tools_cpu_control)); setContentView(R.layout.card_cpu_control); bootPrefs = getSharedPreferences("BOOT_PREFS", 0); graph = (LineGraph) findViewById(R.id.graph); line = new Line(); LinePoint point = new LinePoint(); point.setX(currX);/* ww w.ja va 2 s. c om*/ point.setY(1); line.addPoint(point); line.setColor(Color.parseColor("#FFBB33")); graph.addLine(line); graph.setLineToFill(0); availableFrequencies = new String[0]; String availableFrequenciesLine; mCoresOnline = (TextView) findViewById(R.id.cores_online); mGeneralGovernor = (Spinner) findViewById(R.id.general_governor); mGovernor = (Spinner) findViewById(R.id.governor); mGovernor2 = (Spinner) findViewById(R.id.governor2); mGovernor3 = (Spinner) findViewById(R.id.governor3); mGovernor4 = (Spinner) findViewById(R.id.governor4); Button customizeGov = (Button) findViewById(R.id.governor_customize_btn); customizeGov.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getSupportFragmentManager(); GovernorDialog editNameDialog = new GovernorDialog(); editNameDialog.show(fm, "governor_fragment"); } }); if (Helpers.doesFileExist(STEPS)) { availableFrequenciesLine = CPUHelper.readOneLineNotRoot(STEPS); if (availableFrequenciesLine != null) { availableFrequencies = availableFrequenciesLine.split(" "); Arrays.sort(availableFrequencies, new Comparator<String>() { @Override public int compare(String object1, String object2) { return Integer.valueOf(object1).compareTo(Integer.valueOf(object2)); } }); } } Switch snakeCharmer = (Switch) findViewById(R.id.snake_charmer_switch); if (!Helpers.doesFileExist(SNAKE_CHARMER_MAX_FREQ)) { LinearLayout cardSnakeCharmer = (LinearLayout) findViewById(R.id.card_snake_charmer); cardSnakeCharmer.setVisibility(View.GONE); } else { if (Helpers.doesFileExist(SNAKE_CHARMER_VERSION)) { TextView snakeTitle = (TextView) findViewById(R.id.snake_charmer); String snakeVersion = CPUHelper.readOneLineNotRoot(SNAKE_CHARMER_VERSION); snakeVersion = snakeVersion.replaceAll("version: ", "v"); snakeTitle.setText(snakeTitle.getText() + " " + snakeVersion); if (snakeVersion.equals("v1.2")) { TextView snakeDesc = (TextView) findViewById(R.id.snake_charmer_text); snakeDesc.setText(snakeDesc.getText() + "\n" + getString(R.string.snake_charmer_built_in)); snakeCharmer.setEnabled(false); } } if (bootPrefs.getBoolean("SNAKE_CHARMER", true)) { snakeCharmer.setChecked(true); snakeCharmerEnabled = true; } snakeCharmer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isOn) { snakeCharmerEnabled = isOn; } }); } int frequenciesNum = availableFrequencies.length - 1; Switch thermalControl = (Switch) findViewById(R.id.msm_thermal_switch); if (Helpers.doesFileExist(MSM_THERMAL)) { String thermal = CPUHelper.readOneLineNotRoot(MSM_THERMAL); if (thermal.equals("Y")) thermalControl.setChecked(true); else thermalControl.setChecked(false); thermalControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) Helpers.CMDProcessorWrapper.runSuCommand("echo Y > " + MSM_THERMAL); else Helpers.CMDProcessorWrapper.runSuCommand("echo N > " + MSM_THERMAL); bootPrefs.edit().putBoolean("MSM_THERMAL", isChecked).commit(); } }); } thermalControl.setChecked(bootPrefs.getBoolean("MSM_THERMAL", true)); perCoreGovernor = (Switch) findViewById(R.id.per_core_governors_switch); perCoreGovernor.setChecked(bootPrefs.getBoolean("PER_CORE_GOV", true)); if (perCoreGovernor.isChecked()) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); } perCoreGovernor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); handleGovernors(); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); handleGovernors(); } bootPrefs.edit().putBoolean("PER_CORE_GOV", isChecked).commit(); } }); String currentIo = ""; if (Helpers.doesFileExist(IO_SCHEDULER)) currentIo = CPUHelper.getIOScheduler(); String currentTcp = ""; if (Helpers.doesFileExist(CURR_TCP_ALGORITHM)) currentTcp = Helpers.getCurrentTcpAlgorithm(); String curMaxSpeed = "NaN"; if (Helpers.doesFileExist(MAX_FREQ_ALL_CORES)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MAX_FREQ)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ); String curMinSpeed = "NaN"; if (Helpers.doesFileExist(MIN_FREQ_ALL_CORES)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MIN_FREQ)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ); if (mIsTegra3) { String curTegraMaxSpeed = "NaN"; if (Helpers.doesFileExist(TEGRA_MAX_FREQ)) { curTegraMaxSpeed = CPUHelper.readOneLineNotRoot(TEGRA_MAX_FREQ); int curTegraMax = 0; try { curTegraMax = Integer.parseInt(curTegraMaxSpeed); if (curTegraMax > 0) { curMaxSpeed = Integer.toString(curTegraMax); } } catch (NumberFormatException ex) { curTegraMax = 0; } } } if (Helpers.doesFileExist(NUM_OF_CPUS)) mNumOfCpus = Helpers.getNumOfCpus(); mCurFreq = (TextView) findViewById(R.id.currspeed); mMaxSlider = (SeekBar) findViewById(R.id.max_slider); mMaxSlider.setMax(frequenciesNum); mMaxSpeedText = (TextView) findViewById(R.id.max_speed_text); mMaxSpeedText.setText(toMHz(curMaxSpeed)); mMaxSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMaxSpeed)); mMaxSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMaxSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MAX_FREQ", mMaxFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMaxFreqSetting + " > " + MAX_FREQ.replace("cpu0", "cpu" + i)); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } if (mIsTegra3) { if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + TEGRA_MAX_FREQ); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); mMinSlider = (SeekBar) findViewById(R.id.min_slider); mMinSlider.setMax(frequenciesNum); mMinSpeedText = (TextView) findViewById(R.id.min_speed_text); mMinSpeedText.setText(toMHz(curMinSpeed)); mMinSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMinSpeed)); mMinSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMinSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMinFreqSetting != null && !mMinFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MIN_FREQ", mMinFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMinFreqSetting + " > " + MIN_FREQ.replace("cpu0", "cpu" + i)); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); handleGovernors(); /** TCP Congestion Spinner */ Spinner mTcp = (Spinner) findViewById(R.id.tcp); ArrayAdapter<CharSequence> tcpAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); tcpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayList<String> algorithms = Helpers.getTcpAlgorithms(); for (String algorithm : algorithms) tcpAdapter.add(algorithm); mTcp.setAdapter(tcpAdapter); mTcp.setSelection(algorithms.indexOf(currentTcp)); mTcp.setOnItemSelectedListener(new TCPListener()); onlineCoresPolling(); }