Ticket #1246: HostInfoNCpu.patch
File HostInfoNCpu.patch, 19.7 KB (added by , 11 years ago) |
---|
-
android/BOINC/res/values/strings.xml
From c0a126f532b36737b4076c019bb6ba2a6168c591 Mon Sep 17 00:00:00 2001 From: Keith Uplinger <uplink@us.ibm.com> Date: Tue, 21 May 2013 23:58:35 -0500 Subject: [PATCH] These changes are for having the hostinfo being pulled for preferences to show cpu selector in quantity with max ncpus of the device. --- android/BOINC/res/values/strings.xml | 2 + .../src/edu/berkeley/boinc/PrefsActivity.java | 157 +++++++++++++++----- .../berkeley/boinc/adapter/PrefsListAdapter.java | 18 ++- .../boinc/adapter/PrefsListItemWrapperDouble.java | 6 - .../boinc/adapter/PrefsListItemWrapperInteger.java | 50 +++++++ .../edu/berkeley/boinc/client/ClientStatus.java | 13 +- .../src/edu/berkeley/boinc/client/Monitor.java | 4 +- 7 files changed, 202 insertions(+), 48 deletions(-) create mode 100644 android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperInteger.java diff --git a/android/BOINC/res/values/strings.xml b/android/BOINC/res/values/strings.xml index f906ebe..feb2026 100644
a b 167 167 <string name="prefs_unit_mb">MB</string> 168 168 <string name="prefs_unit_gb">GB</string> 169 169 <string name="prefs_unit_pct">%</string> 170 <string name="prefs_unit_cpu">CPU</string> 171 <string name="prefs_unit_cpus">CPUS</string> 170 172 171 173 <!-- projects tab strings --> 172 174 <string name="projects_loading">Reading projects…</string> -
android/BOINC/src/edu/berkeley/boinc/PrefsActivity.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/PrefsActivity.java b/android/BOINC/src/edu/berkeley/boinc/PrefsActivity.java index f244225..caa9ee6 100644
a b import edu.berkeley.boinc.adapter.PrefsListAdapter; 24 24 import edu.berkeley.boinc.adapter.PrefsListItemWrapper; 25 25 import edu.berkeley.boinc.adapter.PrefsListItemWrapperBool; 26 26 import edu.berkeley.boinc.adapter.PrefsListItemWrapperDouble; 27 import edu.berkeley.boinc.adapter.PrefsListItemWrapperInteger; 27 28 import edu.berkeley.boinc.client.ClientNotification; 28 29 import edu.berkeley.boinc.client.Monitor; 29 30 import edu.berkeley.boinc.rpc.GlobalPreferences; 31 import edu.berkeley.boinc.rpc.HostInfo; 30 32 import android.app.AlertDialog; 31 33 import android.app.Dialog; 32 34 import android.content.ComponentName; … … public class PrefsActivity extends FragmentActivity { 60 62 private ArrayList<PrefsListItemWrapper> data = new ArrayList<PrefsListItemWrapper>(); //Adapter for list data 61 63 private GlobalPreferences clientPrefs = null; //preferences of the client, read on every onResume via RPC 62 64 private AppPreferences appPrefs = null; //Android specific preferences, singleton of monitor 65 private HostInfo hostinfo = null; 63 66 64 67 private Dialog dialog; //Dialog for input on non-Bool preferences 65 68 private PrefsListItemWrapperDouble dialogItem; // saves content of preference Dialog is showing 69 private PrefsListItemWrapperInteger dialogItemInteger; 66 70 67 71 public void onCreate(Bundle savedInstanceState) { 68 72 super.onCreate(savedInstanceState); … … public class PrefsActivity extends FragmentActivity { 112 116 return true; 113 117 } 114 118 119 private Boolean getHostInfo() { 120 hostinfo = Monitor.getClientStatus().getHostInfo(); //Get the hostinfo from client via rpc 121 if(hostinfo == null) { 122 Log.d(TAG, "getHostInfo: null, return false"); 123 return false; 124 } 125 return true; 126 } 127 115 128 private void populateLayout() { 116 129 117 if(!getPrefs() || appPrefs == null ) {130 if(!getPrefs() || appPrefs == null || !getHostInfo()) { 118 131 Log.d(TAG, "populateLayout returns, data is not present"); 119 132 setLayoutLoading(); 120 133 return; … … public class PrefsActivity extends FragmentActivity { 140 153 data.add(new PrefsListItemWrapper(this,R.string.prefs_category_power,true)); 141 154 data.add(new PrefsListItemWrapperBool(this,R.string.prefs_run_on_battery_header,R.string.prefs_category_power,clientPrefs.run_on_batteries)); 142 155 if(advanced) data.add(new PrefsListItemWrapper(this,R.string.prefs_category_cpu,true)); 143 if(advanced) data.add(new PrefsListItemWrapperDouble(this,R.string.prefs_cpu_number_cpus_header,R.string.prefs_category_cpu,clientPrefs.max_ncpus_pct)); 156 Integer ncpus = (int)((double)hostinfo.p_ncpus * (clientPrefs.max_ncpus_pct / 100.0)); 157 if(ncpus.equals(0)) 158 ncpus = 1; 159 if(advanced) data.add(new PrefsListItemWrapperInteger(this,R.string.prefs_cpu_number_cpus_header,R.string.prefs_category_cpu,ncpus)); 144 160 if(advanced) data.add(new PrefsListItemWrapperDouble(this,R.string.prefs_cpu_time_max_header,R.string.prefs_category_cpu,clientPrefs.cpu_usage_limit)); 145 161 if(advanced) data.add(new PrefsListItemWrapperDouble(this,R.string.prefs_cpu_other_load_suspension_header,R.string.prefs_category_cpu,clientPrefs.suspend_cpu_usage)); 146 162 if(advanced) data.add(new PrefsListItemWrapper(this,R.string.prefs_category_storage,true)); … … public class PrefsActivity extends FragmentActivity { 192 208 193 209 // onClick of listview items with PrefsListItemWrapperDouble 194 210 public void onItemClick (View view) { 195 PrefsListItemWrapperDouble listItem = (PrefsListItemWrapperDouble) view.getTag(); 196 Log.d(TAG,"onItemClick " + listItem.ID); 211 if(view.getTag() instanceof PrefsListItemWrapperDouble) { 212 PrefsListItemWrapperDouble listItem = (PrefsListItemWrapperDouble) view.getTag(); 213 Log.d(TAG,"onItemClick Double " + listItem.ID); 197 214 198 AlertDialog.Builder builder = new AlertDialog.Builder(this);199 LayoutInflater inflater = getLayoutInflater();200 final View dialogContent;201 if(listItem.isPct) {202 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog_pct, null);203 TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status);204 sliderProgress.setText(listItem.status.intValue() + " %");205 SeekBar slider = (SeekBar) dialogContent.findViewById(R.id.seekbar);206 slider.setProgress(listItem.status.intValue());207 slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {208 209 210 211 212 213 @Override214 public void onStartTrackingTouch(SeekBar seekBar) {}215 @Override216 public void onStopTrackingTouch(SeekBar seekBar) {}217 218 } else {219 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog, null);220 }221 222 .setView(dialogContent)223 224 225 226 227 228 215 AlertDialog.Builder builder = new AlertDialog.Builder(this); 216 LayoutInflater inflater = getLayoutInflater(); 217 final View dialogContent; 218 if(listItem.isPct) { 219 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog_pct, null); 220 TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status); 221 sliderProgress.setText(listItem.status.intValue() + " %"); 222 SeekBar slider = (SeekBar) dialogContent.findViewById(R.id.seekbar); 223 slider.setProgress(listItem.status.intValue()); 224 slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 225 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){ 226 String progressString = progress + " %"; 227 TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status); 228 sliderProgress.setText(progressString); 229 } 230 @Override 231 public void onStartTrackingTouch(SeekBar seekBar) {} 232 @Override 233 public void onStopTrackingTouch(SeekBar seekBar) {} 234 }); 235 } else { 236 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog, null); 237 } 238 builder.setMessage(listItem.ID) 239 .setView(dialogContent) 240 .setNegativeButton(R.string.prefs_cancel_button, new DialogInterface.OnClickListener() { 241 public void onClick(DialogInterface dialogI, int id) { 242 dialog.cancel(); 243 } 244 }) 245 .setPositiveButton(R.string.prefs_submit_button, new DialogInterface.OnClickListener() { 229 246 public void onClick(DialogInterface dialogI, int id) { 230 247 double value; 231 248 if(dialogItem.isPct) { … … public class PrefsActivity extends FragmentActivity { 241 258 writeDoublePreference(dialogItem.ID, value); 242 259 } 243 260 }); 244 dialog = builder.create(); 245 dialog.show(); 246 dialogItem = listItem; // set dialog content 261 dialog = builder.create(); 262 dialog.show(); 263 dialogItem = listItem; // set dialog content 264 } else if(view.getTag() instanceof PrefsListItemWrapperInteger) { 265 PrefsListItemWrapperInteger listItem = (PrefsListItemWrapperInteger) view.getTag(); 266 Log.d(TAG,"onItemClick Integer " + listItem.ID); 267 268 AlertDialog.Builder builder = new AlertDialog.Builder(this); 269 LayoutInflater inflater = getLayoutInflater(); 270 final View dialogContent; 271 if(listItem.ID.equals(R.string.prefs_cpu_number_cpus_header)) { 272 if(!getHostInfo()) { 273 Log.d(TAG, "onItemClick missing hostInfo"); 274 return; 275 } 276 277 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog_pct, null); 278 TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status); 279 if(listItem.status > 1) { 280 sliderProgress.setText(listItem.status + " CPUS"); 281 } else { 282 sliderProgress.setText(listItem.status + " CPU"); 283 } 284 SeekBar slider = (SeekBar) dialogContent.findViewById(R.id.seekbar); 285 slider.setMax(hostinfo.p_ncpus); 286 slider.setProgress(listItem.status); 287 slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 288 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){ 289 String progressString = String.valueOf(progress); 290 TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status); 291 sliderProgress.setText(progressString); 292 } 293 @Override 294 public void onStartTrackingTouch(SeekBar seekBar) {} 295 @Override 296 public void onStopTrackingTouch(SeekBar seekBar) {} 297 }); 298 } else { 299 dialogContent = inflater.inflate(R.layout.prefs_layout_dialog, null); 300 } 301 builder.setMessage(listItem.ID) 302 .setView(dialogContent) 303 .setNegativeButton(R.string.prefs_cancel_button, new DialogInterface.OnClickListener() { 304 public void onClick(DialogInterface dialogI, int id) { 305 dialog.cancel(); 306 } 307 }) 308 .setPositiveButton(R.string.prefs_submit_button, new DialogInterface.OnClickListener() { 309 public void onClick(DialogInterface dialogI, int id) { 310 int value; 311 SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); 312 value = slider.getProgress(); 313 writeIntegerAsDoublePreference(dialogItemInteger.ID, value, hostinfo.p_ncpus); 314 } 315 }); 316 dialog = builder.create(); 317 dialog.show(); 318 dialogItemInteger = listItem; // set dialog content 319 } 247 320 } 248 321 249 322 @Override … … public class PrefsActivity extends FragmentActivity { 253 326 doUnbindService(); 254 327 } 255 328 329 private void writeIntegerAsDoublePreference(int id, Integer value, Integer max) { 330 switch(id) { 331 case R.string.prefs_cpu_number_cpus_header: 332 clientPrefs.max_ncpus_pct = value.doubleValue() / max.doubleValue(); 333 break; 334 } 335 } 336 256 337 private void writeDoublePreference(int id, double value) { 257 338 // update preferences 258 339 switch (id) { -
android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListAdapter.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListAdapter.java b/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListAdapter.java index 6d4316a..d4720b9 100644
a b public class PrefsListAdapter extends ArrayAdapter<PrefsListItemWrapper>{ 77 77 } 78 78 TextView status = (TextView) v.findViewById(R.id.status); 79 79 status.setText(value + " " + item.unit); 80 } 80 } else if(listItem instanceof PrefsListItemWrapperInteger) { 81 PrefsListItemWrapperInteger item = (PrefsListItemWrapperInteger) listItem; 82 v = vi.inflate(R.layout.prefs_layout_listitem, null); 83 v.setTag(listItem); //set listItem as tag to view, since root layout defines onClick method 84 TextView header = (TextView) v.findViewById(R.id.header); 85 header.setText(item.header); 86 TextView description = (TextView) v.findViewById(R.id.description); 87 description.setText(item.description.toString()); 88 89 String value = item.status.toString(); 90 91 TextView status = (TextView) v.findViewById(R.id.status); 92 if(!item.unit.isEmpty()) { 93 value = value + " " + item.unit; 94 } 95 status.setText(value); 96 } 81 97 } 82 98 83 99 return v; -
android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperDouble.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperDouble.java b/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperDouble.java index d0cb2d5..a56c841 100644
a b public class PrefsListItemWrapperDouble extends PrefsListItemWrapper { 58 58 unit = ctx.getString(R.string.prefs_unit_mb); 59 59 isPct = false; 60 60 break; 61 case R.string.prefs_cpu_number_cpus_header:62 header = ctx.getString(R.string.prefs_cpu_number_cpus_header);63 description = ctx.getString(R.string.prefs_cpu_number_cpus_description);64 unit = ctx.getString(R.string.prefs_unit_pct);65 isPct = true;66 break;67 61 case R.string.prefs_cpu_other_load_suspension_header: 68 62 header = ctx.getString(R.string.prefs_cpu_other_load_suspension_header); 69 63 description = ctx.getString(R.string.prefs_cpu_other_load_suspension_description); -
new file android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperInteger.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperInteger.java b/android/BOINC/src/edu/berkeley/boinc/adapter/PrefsListItemWrapperInteger.java new file mode 100644 index 0000000..36ffe18
- + 1 /******************************************************************************* 2 * This file is part of BOINC. 3 * http://boinc.berkeley.edu 4 * Copyright (C) 2012 University of California 5 * 6 * BOINC is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation, 9 * either version 3 of the License, or (at your option) any later version. 10 * 11 * BOINC is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 * See the GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with BOINC. If not, see <http://www.gnu.org/licenses/>. 18 ******************************************************************************/ 19 package edu.berkeley.boinc.adapter; 20 21 import edu.berkeley.boinc.R; 22 import android.content.Context; 23 import android.util.Log; 24 25 public class PrefsListItemWrapperInteger extends PrefsListItemWrapper { 26 27 private final String TAG = "PrefsListItemWrapperInteger"; 28 29 public String header = ""; 30 public String description = ""; 31 public String unit = ""; 32 public Integer status; 33 34 public PrefsListItemWrapperInteger(Context ctx, Integer ID, Integer categoryID, Integer status) { 35 super(ctx, ID, categoryID); 36 this.status = status; 37 mapStrings(ID); 38 } 39 40 private void mapStrings(Integer id) { 41 switch (id) { 42 case R.string.prefs_cpu_number_cpus_header: 43 header = ctx.getString(R.string.prefs_cpu_number_cpus_header); 44 description = ctx.getString(R.string.prefs_cpu_number_cpus_description); 45 break; 46 default: 47 Log.d(TAG, "map failed!"); 48 } 49 } 50 } -
android/BOINC/src/edu/berkeley/boinc/client/ClientStatus.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/client/ClientStatus.java b/android/BOINC/src/edu/berkeley/boinc/client/ClientStatus.java index 0d77830..7357254 100644
a b import edu.berkeley.boinc.rpc.GlobalPreferences; 43 43 import edu.berkeley.boinc.rpc.Project; 44 44 import edu.berkeley.boinc.rpc.Result; 45 45 import edu.berkeley.boinc.rpc.Transfer; 46 import edu.berkeley.boinc.rpc.HostInfo; 46 47 import edu.berkeley.boinc.utils.BOINCDefs; 47 48 48 49 /* … … public class ClientStatus { 65 66 private ArrayList<Project> projects; 66 67 private ArrayList<Transfer> transfers; 67 68 private GlobalPreferences prefs; 69 private HostInfo hostinfo; 68 70 69 71 // setup status 70 72 public Integer setupStatus = 0; … … public class ClientStatus { 158 160 /* 159 161 * called frequently by Monitor to set the RPC data. These objects are used to determine the client status and parse it in the data model of this class. 160 162 */ 161 public synchronized void setClientStatus(CcStatus status,ArrayList<Result> results,ArrayList<Project> projects, ArrayList<Transfer> transfers ) {163 public synchronized void setClientStatus(CcStatus status,ArrayList<Result> results,ArrayList<Project> projects, ArrayList<Transfer> transfers, HostInfo hostinfo) { 162 164 this.status = status; 163 165 this.results = results; 164 166 this.projects = projects; 165 167 this.transfers = transfers; 168 this.hostinfo = hostinfo; 166 169 parseClientStatus(); 167 170 Log.d(TAG,"setClientStatus: #results:" + results.size() + " #projects:" + projects.size() + " #transfers:" + transfers.size() + " // computing: " + computingParseError + computingStatus + computingSuspendReason + " - network: " + networkParseError + networkStatus + networkSuspendReason); 168 171 if(!computingParseError && !networkParseError && !setupStatusParseError) { … … public class ClientStatus { 229 232 } 230 233 return projects; 231 234 } 235 236 public synchronized HostInfo getHostInfo() { 237 if(hostinfo == null) { 238 Log.d(TAG, "getHostInfo() state is null"); 239 return null; 240 } 241 return hostinfo; 242 } 232 243 233 244 // returns list with slideshow images of all projects 234 245 // 126 * 29 pixel from /projects/PNAME/slideshow_appname_n -
android/BOINC/src/edu/berkeley/boinc/client/Monitor.java
diff --git a/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java b/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java index ea188ed..990f04c 100644
a b public class Monitor extends Service { 943 943 if(showRpcCommands) Log.d(TAG, "getTransers"); 944 944 ArrayList<Transfer> transfers = rpc.getFileTransfers(); 945 945 946 if( (status != null) && (state != null) && (state.results != null) && (state.projects != null) && (transfers != null) ) {947 Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers );946 if( (status != null) && (state != null) && (state.results != null) && (state.projects != null) && (transfers != null) && (state.host_info != null)) { 947 Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers, state.host_info); 948 948 // Update status bar notification 949 949 ClientNotification.getInstance(getApplicationContext()).update(); 950 950 } else {