public GovernorFragment( GovernorFragmentCallback callback, IGovernorModel governor, boolean disableScript) { super(callback, governor); this.origThreshUp = governor.getGovernorThresholdUp() + ""; this.origThreshDown = governor.getGovernorThresholdDown() + ""; this.disableScript = disableScript; this.cpuHandler = CpuHandler.getInstance(); this.availCpuGovs = cpuHandler.getAvailCpuGov(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); FragmentActivity act = getActivity(); if (cpuHandler == null) { this.cpuHandler = CpuHandler.getInstance(); this.availCpuGovs = cpuHandler.getAvailCpuGov(); } numberOfCpus = cpuHandler.getNumberOfCpus(); if (cpuHandler instanceof CpuHandlerMulticore) { ArrayAdapter<Integer> cpuAdapter = new ArrayAdapter<Integer>(act, android.R.layout.simple_spinner_item); cpuAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (int i = numberOfCpus; i >= 1; i--) { cpuAdapter.add(i); } spUseCpus.setAdapter(cpuAdapter); spUseCpus.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int num = numberOfCpus - position; getGovernorModel().setUseNumberOfCpus(num); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); } else { llFragmentTop.removeView(act.findViewById(R.id.llUseCpus)); spUseCpus = null; } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(act, android.R.layout.simple_spinner_item, availCpuGovs); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerSetGov.setAdapter(arrayAdapter); spinnerSetGov.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (callback != null) { callback.updateModel(); } String gov = parent.getItemAtPosition(pos).toString(); getGovernorModel().setGov(gov); if (callback != null) { callback.updateView(); } } @Override public void onNothingSelected(AdapterView<?> arg0) { if (callback != null) { callback.updateView(); } } }); OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus && etGovTreshUp.getVisibility() == View.VISIBLE) { String upthresh = etGovTreshUp.getText().toString(); String downthresh = etGovTreshDown.getText().toString(); try { int up = Integer.parseInt(upthresh); int down = 0; if (etGovTreshDown.getVisibility() == View.VISIBLE) { down = Integer.parseInt(downthresh); } if (up > 100 || up < 0) { Toast.makeText( getActivity(), R.string.msg_up_threshhold_has_to_be_between_0_and_100, Toast.LENGTH_LONG) .show(); etGovTreshUp.setText(origThreshUp); } if (down > 100 || down < 0) { Toast.makeText( getActivity(), R.string.msg_down_threshhold_has_to_be_between_0_and_100, Toast.LENGTH_LONG) .show(); etGovTreshDown.setText(origThreshDown); } if (up > down) { // all OK return; } Toast.makeText( getActivity(), R.string.msg_up_threshhold_smaler_than_the_down_threshold, Toast.LENGTH_LONG) .show(); down = up - 10; etGovTreshDown.setText(down + ""); } catch (Exception e) { Toast.makeText(getActivity(), R.string.msg_threshhold_NaN, Toast.LENGTH_LONG) .show(); } } } }; etGovTreshUp.setOnFocusChangeListener(onFocusChangeListener); etGovTreshDown.setOnFocusChangeListener(onFocusChangeListener); }