android: new Tasks tab icon

android: moved run mode control from Status tab into menu
This commit is contained in:
Joachim Fritzsch 2013-05-18 14:20:59 +02:00
parent 6a98db4c74
commit 36f2c45412
20 changed files with 88 additions and 103 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -19,8 +19,8 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- when selected use dark icons -->
<item android:drawable="@drawable/chartb"
<item android:drawable="@drawable/cogsb"
android:state_selected="true"></item>
<!-- when not selected, use white -->
<item android:drawable="@drawable/chartw"></item>
<item android:drawable="@drawable/cogsw"></item>
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -45,6 +45,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:contentDescription="@string/status_paused"
android:src="@drawable/pausew48" />
@ -94,36 +95,5 @@
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<RelativeLayout
android:id="@+id/bottow_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/status_change_runmode_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dip"
android:contentDescription="@string/status_paused"
android:clickable="true"
android:onClick="onClick"
android:src="@drawable/stopw24" />
<TextView
android:id="@+id/status_change_runmode_long"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/status_change_runmode_image"
android:layout_marginLeft="10dip"
android:clickable="true"
android:onClick="onClick"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>

View File

@ -5,5 +5,7 @@
android:visible="true"
android:title="@string/menu_exit"
android:icon="@drawable/offw"></item>
<item android:id="@+id/run_mode"
android:enabled="true"
android:visible="true"></item>
</menu>

View File

@ -123,14 +123,12 @@
<string name="status_paused_long">Computation suspended.</string>
<string name="status_idle">Nothing to do</string>
<string name="status_idle_long">Waiting for tasks&#8230;</string>
<string name="status_computing_disabled">Stopped</string>
<string name="status_computing_disabled_long">Allow computation to continue!</string>
<string name="status_computing_disabled">Disabled</string>
<string name="status_computing_disabled_long">Press play!</string>
<string name="status_launching">Starting&#8230;</string>
<string name="status_noproject">Add a project!</string>
<string name="status_closing">Closing&#8230;</string>
<string name="status_benchmarking">Benchmarking&#8230;</string>
<string name="disable_computation">Stop computation</string>
<string name="enable_computation">Allow computation</string>
<!-- preferences tab strings -->
<string name="prefs_loading">Reading preferences&#8230;</string>
@ -276,5 +274,7 @@
<string name="email_to">Email to&#8230;</string>
<string name="send_mail">Send mail&#8230;</string>
<string name="menu_exit">Exit BOINC</string>
<string name="menu_run_mode_disable">Stop</string>
<string name="menu_run_mode_enable">Continue</string>
</resources>

View File

@ -20,6 +20,7 @@ package edu.berkeley.boinc;
import edu.berkeley.boinc.client.ClientStatus;
import edu.berkeley.boinc.client.Monitor;
import edu.berkeley.boinc.utils.BOINCDefs;
import android.app.Service;
import android.app.TabActivity;
import android.content.BroadcastReceiver;
@ -292,10 +293,28 @@ public class BOINCActivity extends TabActivity {
Log.d(TAG, "onCreateOptionsMenu()");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.status_menu, menu);
inflater.inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
//customize run mode menu, according to current status
MenuItem item = menu.findItem(R.id.run_mode);
if(Monitor.getClientStatus().computingStatus == ClientStatus.COMPUTING_STATUS_NEVER) {
// display play button
item.setTitle(R.string.menu_run_mode_enable);
item.setIcon(R.drawable.playw);
} else {
// display stop button
item.setTitle(R.string.menu_run_mode_disable);
item.setIcon(R.drawable.stopw);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -306,11 +325,20 @@ public class BOINCActivity extends TabActivity {
Log.d(TAG,"exit BOINC");
new QuitClientAsync().execute();
return true;
case R.id.run_mode:
if(item.getTitle().equals(getApplication().getString(R.string.menu_run_mode_disable))) {
Log.d(TAG,"run mode: disable");
new WriteClientRunModeAsync().execute(BOINCDefs.RUN_MODE_NEVER);
} else if (item.getTitle().equals(getApplication().getString(R.string.menu_run_mode_enable))) {
Log.d(TAG,"run mode: enable");
new WriteClientRunModeAsync().execute(BOINCDefs.RUN_MODE_AUTO);
} else Log.d(TAG,"run mode: unrecognized command");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
// monitor.quitClient is blocking (Thread.sleep)
// execute in AsyncTask to maintain UI responsiveness
private final class QuitClientAsync extends AsyncTask<Void, Void, Void> {
@ -321,4 +349,20 @@ public class BOINCActivity extends TabActivity {
return null;
}
}
private final class WriteClientRunModeAsync extends AsyncTask<Integer, Void, Boolean> {
private final String TAG = "WriteClientRunModeAsync";
@Override
protected Boolean doInBackground(Integer... params) {
return monitor.setRunMode(params[0]);
}
@Override
protected void onPostExecute(Boolean success) {
if(success) monitor.forceRefresh();
else Log.w(TAG,"setting run mode failed");
}
}
}

View File

@ -30,6 +30,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
@ -37,6 +38,7 @@ import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
@ -44,7 +46,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class StatusActivity extends Activity {
public class StatusActivity extends Activity implements OnClickListener{
private final String TAG = "BOINC StatusActivity";
@ -171,8 +173,6 @@ public class StatusActivity extends Activity {
TextView statusHeader = (TextView) findViewById(R.id.status_header);
ImageView statusImage = (ImageView) findViewById(R.id.status_image);
TextView statusDescriptor = (TextView) findViewById(R.id.status_long);
ImageView changeRunmodeImage = (ImageView) findViewById(R.id.status_change_runmode_image);
TextView changeRunmodeDescriptor = (TextView) findViewById(R.id.status_change_runmode_long);
imageFrame = (ViewFlipper) findViewById(R.id.slideshowFrame);
// adapt to specific computing status
@ -180,25 +180,18 @@ public class StatusActivity extends Activity {
case ClientStatus.COMPUTING_STATUS_NEVER:
imageFrame.setVisibility(View.GONE);
statusHeader.setText(R.string.status_computing_disabled);
statusImage.setImageResource(R.drawable.stopw48);
statusImage.setImageResource(R.drawable.playw48);
statusImage.setContentDescription(getString(R.string.status_computing_disabled));
statusImage.setClickable(true);
statusImage.setOnClickListener(this);
statusDescriptor.setText(R.string.status_computing_disabled_long);
changeRunmodeImage.setImageResource(R.drawable.playw24);
changeRunmodeImage.setContentDescription(getString(R.string.enable_computation));
changeRunmodeImage.setTag(true);
changeRunmodeDescriptor.setText(R.string.enable_computation);
changeRunmodeDescriptor.setTag(true);
break;
case ClientStatus.COMPUTING_STATUS_SUSPENDED:
imageFrame.setVisibility(View.GONE);
statusHeader.setText(R.string.status_paused);
statusImage.setImageResource(R.drawable.pausew48);
statusImage.setContentDescription(getString(R.string.status_paused));
changeRunmodeImage.setImageResource(R.drawable.stopw24);
changeRunmodeImage.setContentDescription(getString(R.string.disable_computation));
changeRunmodeImage.setTag(false);
changeRunmodeDescriptor.setText(R.string.disable_computation);
changeRunmodeDescriptor.setTag(false);
statusImage.setClickable(false);
switch(status.computingSuspendReason) {
case BOINCDefs.SUSPEND_REASON_BATTERIES:
statusDescriptor.setText(R.string.suspend_batteries);
@ -271,11 +264,7 @@ public class StatusActivity extends Activity {
statusHeader.setText(R.string.status_idle);
statusImage.setImageResource(R.drawable.pausew48);
statusImage.setContentDescription(getString(R.string.status_idle));
changeRunmodeImage.setImageResource(R.drawable.stopw24);
changeRunmodeImage.setContentDescription(getString(R.string.disable_computation));
changeRunmodeImage.setTag(false);
changeRunmodeDescriptor.setText(R.string.disable_computation);
changeRunmodeDescriptor.setTag(false);
statusImage.setClickable(false);
Integer networkState = 0;
try{
networkState = status.networkSuspendReason;
@ -292,15 +281,10 @@ public class StatusActivity extends Activity {
if(!loadSlideshow()) {
Log.d(TAG, "slideshow not available, load plain old status instead...");
statusHeader.setText(R.string.status_running);
statusImage.setImageResource(R.drawable.playw48);
statusImage.setImageResource(R.drawable.cogsw48);
statusImage.setContentDescription(getString(R.string.status_running));
statusDescriptor.setText(R.string.status_running_long);
}
changeRunmodeImage.setImageResource(R.drawable.stopw24);
changeRunmodeImage.setContentDescription(getString(R.string.disable_computation));
changeRunmodeImage.setTag(false);
changeRunmodeDescriptor.setText(R.string.disable_computation);
changeRunmodeDescriptor.setTag(false);
break;
}
computingStatus = status.computingStatus; //save new computing status
@ -311,19 +295,6 @@ public class StatusActivity extends Activity {
}
}
public void onClick (View v) {
Log.d(TAG,"onClick");
if(!mIsBound) {Log.w(TAG,"not bound");return;}
try {
Boolean enable = (Boolean) v.getTag();
if(enable) {
monitor.setRunMode(BOINCDefs.RUN_MODE_AUTO);
} else {
monitor.setRunMode(BOINCDefs.RUN_MODE_NEVER);
}
} catch (Exception e) {Log.e(TAG, "could not map status tag", e);}
}
private Boolean loadSlideshow() {
// get slideshow images
ArrayList<Bitmap> images = Monitor.getClientStatus().getSlideshowImages();
@ -356,4 +327,25 @@ public class StatusActivity extends Activity {
return true;
}
@Override
public void onClick(View v) {
new WriteClientRunModeAsync().execute(BOINCDefs.RUN_MODE_AUTO);
}
private final class WriteClientRunModeAsync extends AsyncTask<Integer, Void, Boolean> {
private final String TAG = "WriteClientRunModeAsync";
@Override
protected Boolean doInBackground(Integer... params) {
return monitor.setRunMode(params[0]);
}
@Override
protected void onPostExecute(Boolean success) {
if(success) monitor.forceRefresh();
else Log.w(TAG,"setting run mode failed");
}
}
}

View File

@ -594,9 +594,8 @@ public class Monitor extends Service {
stopSelf();
}
public void setRunMode(Integer mode) {
//execute in different thread, in order to avoid network communication in main thread and therefore ANR errors
(new WriteClientRunModeAsync()).execute(mode);
public Boolean setRunMode(Integer mode) {
return rpc.setRunMode(mode, 0);
}
// writes the given GlobalPreferences via RPC to the client
@ -1089,26 +1088,4 @@ public class Monitor extends Service {
Log.d(TAG, "onProgressUpdate - " + arg0[0]);
}
}
private final class WriteClientRunModeAsync extends AsyncTask<Integer, String, Boolean> {
private final String TAG = "WriteClientRunModeAsync";
@Override
protected Boolean doInBackground(Integer... params) {
Boolean success = rpc.setRunMode(params[0], 0);
publishProgress("run mode set to " + params[0] + " returned " + success);
return success;
}
@Override
protected void onPostExecute(Boolean success) {
forceRefresh();
}
@Override
protected void onProgressUpdate(String... arg0) {
Log.d(TAG, "onProgressUpdate - " + arg0[0]);
}
}
}