android: remodeled Status tab slide show

This commit is contained in:
Joachim Fritzsch 2013-05-18 17:04:12 +02:00
parent 36f2c45412
commit a55f3c7eec
5 changed files with 153 additions and 51 deletions

View File

@ -59,17 +59,38 @@
</LinearLayout>
<ViewFlipper
android:id="@+id/slideshowFrame"
<LinearLayout
android:id="@+id/slideshow_wrapper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:autoStart="false"
android:paddingTop="20dp"
android:paddingBottom="50dp"
android:background="@android:drawable/screen_background_dark"
android:visibility="gone" />
android:visibility="gone"
android:padding="10dp"
android:orientation="vertical">
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/status_image_description"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/image_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/restarting_wrapper"

View File

@ -129,6 +129,7 @@
<string name="status_noproject">Add a project!</string>
<string name="status_closing">Closing&#8230;</string>
<string name="status_benchmarking">Benchmarking&#8230;</string>
<string name="status_image_description">project image</string>
<!-- preferences tab strings -->
<string name="prefs_loading">Reading preferences&#8230;</string>

View File

@ -19,7 +19,10 @@
package edu.berkeley.boinc;
import java.util.ArrayList;
import edu.berkeley.boinc.adapter.GalleryAdapter;
import edu.berkeley.boinc.client.ClientStatus;
import edu.berkeley.boinc.client.ClientStatus.ImageWrapper;
import edu.berkeley.boinc.client.Monitor;
import edu.berkeley.boinc.utils.BOINCDefs;
import android.app.Activity;
@ -41,9 +44,14 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
public class StatusActivity extends Activity implements OnClickListener{
@ -58,32 +66,7 @@ public class StatusActivity extends Activity implements OnClickListener{
private Integer suspendReason = -1;
//slide show
private ViewFlipper imageFrame;
// gesture detection
private final GestureDetector gdt = new GestureDetector(new GestureListener());
private class GestureListener extends SimpleOnGestureListener {
// values taken from example on Stackoverflow. seems appropriate.
private final int SWIPE_MIN_DISTANCE = 120;
private final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//Log.d(TAG, "right to left...");
imageFrame.setInAnimation(getApplicationContext(), R.anim.in_from_right);
imageFrame.setOutAnimation(getApplicationContext(), R.anim.out_to_left);
imageFrame.showNext();
return false;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//Log.d(TAG, "left to right...");
imageFrame.setInAnimation(getApplicationContext(), R.anim.in_from_left);
imageFrame.setOutAnimation(getApplicationContext(), R.anim.out_to_right);
imageFrame.showPrevious();
return false;
}
return false;
}
}
private LinearLayout slideshowWrapper;
private BroadcastReceiver mClientStatusChangeRec = new BroadcastReceiver() {
@Override
@ -173,12 +156,12 @@ public class StatusActivity extends Activity implements OnClickListener{
TextView statusHeader = (TextView) findViewById(R.id.status_header);
ImageView statusImage = (ImageView) findViewById(R.id.status_image);
TextView statusDescriptor = (TextView) findViewById(R.id.status_long);
imageFrame = (ViewFlipper) findViewById(R.id.slideshowFrame);
slideshowWrapper = (LinearLayout) findViewById(R.id.slideshow_wrapper);
// adapt to specific computing status
switch(status.computingStatus) {
case ClientStatus.COMPUTING_STATUS_NEVER:
imageFrame.setVisibility(View.GONE);
slideshowWrapper.setVisibility(View.GONE);
statusHeader.setText(R.string.status_computing_disabled);
statusImage.setImageResource(R.drawable.playw48);
statusImage.setContentDescription(getString(R.string.status_computing_disabled));
@ -187,7 +170,7 @@ public class StatusActivity extends Activity implements OnClickListener{
statusDescriptor.setText(R.string.status_computing_disabled_long);
break;
case ClientStatus.COMPUTING_STATUS_SUSPENDED:
imageFrame.setVisibility(View.GONE);
slideshowWrapper.setVisibility(View.GONE);
statusHeader.setText(R.string.status_paused);
statusImage.setImageResource(R.drawable.pausew48);
statusImage.setContentDescription(getString(R.string.status_paused));
@ -260,7 +243,7 @@ public class StatusActivity extends Activity implements OnClickListener{
suspendReason = status.computingSuspendReason;
break;
case ClientStatus.COMPUTING_STATUS_IDLE:
imageFrame.setVisibility(View.GONE);
slideshowWrapper.setVisibility(View.GONE);
statusHeader.setText(R.string.status_idle);
statusImage.setImageResource(R.drawable.pausew48);
statusImage.setContentDescription(getString(R.string.status_idle));
@ -297,33 +280,49 @@ public class StatusActivity extends Activity implements OnClickListener{
private Boolean loadSlideshow() {
// get slideshow images
ArrayList<Bitmap> images = Monitor.getClientStatus().getSlideshowImages();
final ArrayList<ImageWrapper> images = Monitor.getClientStatus().getSlideshowImages();
if(images == null || images.size() == 0) return false;
// images available, adapt layout
Gallery gallery = (Gallery) findViewById(R.id.gallery);
final ImageView imageView = (ImageView) findViewById(R.id.image_view);
final TextView imageDesc = (TextView)findViewById(R.id.image_description);
imageView.setImageBitmap(images.get(0).image);
imageDesc.setText(images.get(0).projectName);
LinearLayout centerWrapper = (LinearLayout) findViewById(R.id.center_wrapper);
centerWrapper.setVisibility(View.GONE);
imageFrame.setVisibility(View.VISIBLE);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
imageFrame.removeAllViews();
slideshowWrapper.setVisibility(View.VISIBLE);
//gallery.setVisibility(View.GONE);
//setup gallery
gallery.setAdapter(new GalleryAdapter(this,images));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
imageView.setImageBitmap(images.get(position).image);
imageDesc.setText(images.get(position).projectName);
}
});
/*
// create views for all available bitmaps
for (Bitmap image: images) {
ImageView imageView = new ImageView(this);
imageView.setLayoutParams(params);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setImageBitmap(image);
imageFrame.addView(imageView);
}
viewFlipper.addView(imageView);
}*/
/*
// capture click events and pass on to Gesture Detector
imageFrame.setOnTouchListener(new OnTouchListener() {
slideshowWrapper.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
gdt.onTouchEvent(event);
return true;
}
});
});*/
return true;
}

View File

@ -0,0 +1,70 @@
/*******************************************************************************
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 2012 University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* BOINC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package edu.berkeley.boinc.adapter;
import java.util.ArrayList;
import edu.berkeley.boinc.client.ClientStatus.ImageWrapper;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class GalleryAdapter extends BaseAdapter{
int mGalleryItemBackground;
private Context ctx;
private ArrayList<ImageWrapper> images = new ArrayList<ImageWrapper>();
public GalleryAdapter(Context ctx, ArrayList<ImageWrapper> images) {
this.ctx = ctx;
this.images = images;
}
public int getCount() {
return images.size();
}
public ImageWrapper getItem(int position) {
return images.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(ctx);
LayoutParams params = new Gallery.LayoutParams(290, 126);
imageView.setLayoutParams(params);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageBitmap(images.get(position).image);
return imageView;
}
}

View File

@ -233,9 +233,9 @@ public class ClientStatus {
// returns list with slideshow images of all projects
// 126 * 29 pixel from /projects/PNAME/slideshow_appname_n
// not aware of project or application!
public synchronized ArrayList<Bitmap> getSlideshowImages() {
public synchronized ArrayList<ImageWrapper> getSlideshowImages() {
ArrayList<Bitmap> slideshowImages = new ArrayList<Bitmap>();
ArrayList<ImageWrapper> slideshowImages = new ArrayList<ImageWrapper>();
for (Project project: projects) {
// get file paths
@ -262,7 +262,7 @@ public class ClientStatus {
options.inSampleSize = 1;
for (String filePath : filePaths) {
Bitmap tmp = BitmapFactory.decodeFile(filePath, options);
if(tmp!=null) slideshowImages.add(tmp);
if(tmp!=null) slideshowImages.add(new ImageWrapper(tmp,project.project_name));
else Log.d(TAG,"loadSlideshowImagesFromFile(): null for path: " + filePath);
}
}
@ -486,4 +486,15 @@ public class ClientStatus {
return projectDir + "/" + fileName;
}
// Wrapper for slideshow images
public class ImageWrapper {
public Bitmap image;
public String projectName;
public ImageWrapper(Bitmap image, String projectName) {
this.image = image;
this.projectName = projectName;
}
}
}