formatting for consistancy across Java code

Change-Id: I7bde4c9c024dfe7a18c92a36069433f044fc89bc
This commit is contained in:
Siqi Liu
2015-04-23 12:53:51 +02:00
parent 3c8ad51e35
commit c9baf39df6

View File

@@ -35,7 +35,7 @@ public class FolderIconView extends View{
private File dir; private File dir;
public FolderIconView(Context context ) { public FolderIconView(Context context) {
super(context); super(context);
initialisePaints(); initialisePaints();
} }
@@ -48,86 +48,86 @@ public class FolderIconView extends View{
initialisePaints(); initialisePaints();
} }
private void initialisePaints(){ private void initialisePaints() {
mPaintBlack = new Paint(); mPaintBlack = new Paint();
mPaintBlack.setColor( Color.DKGRAY );//Can also use parseColor( String "#aarrggbb") mPaintBlack.setColor(Color.DKGRAY);//Can also use parseColor(String "#aarrggbb")
mPaintBlack.setAntiAlias( true ); mPaintBlack.setAntiAlias(true);
mPaintGray = new Paint(); mPaintGray = new Paint();
mPaintGray.setColor( Color.GRAY );//Can also use parseColor( String "#aarrggbb") mPaintGray.setColor(Color.GRAY);//Can also use parseColor(String "#aarrggbb")
mPaintGray.setAntiAlias( true ); mPaintGray.setAntiAlias(true);
mPaintShadow = new Paint(); mPaintShadow = new Paint();
mPaintShadow.setColor( Color.parseColor( "#88888888") ); mPaintShadow.setColor(Color.parseColor("#88888888"));
mPaintShadow.setAntiAlias( true ); mPaintShadow.setAntiAlias(true);
} }
public void setDir( File dir ){ public void setDir(File dir) {
this.dir = dir; this.dir = dir;
} }
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
Log.d( TAG, "onDraw"); Log.d(TAG, "onDraw");
//float width = (float)canvas.getWidth(); //float width = (float)canvas.getWidth();
//float height = (float)canvas.getHeight(); //float height = (float)canvas.getHeight();
float width = (float)this.getWidth(); float width = (float) this.getWidth();
float height = (float)this.getHeight(); float height = (float) this.getHeight();
float centerX = width*0.5f;// centered on horz axis float centerX = width*0.5f;// centered on horz axis
float centerY = height*0.5f; float centerY = height*0.5f;
float outerRadius = 0.8f*0.5f* width; float outerRadius = 0.8f*0.5f*width;
float innerRadius = 0.7f*0.5f* width; float innerRadius = 0.7f*0.5f*width;
float thumbHeight = outerRadius*1.25f; float thumbHeight = outerRadius*1.25f;
float thumbWidth = thumbHeight*(float)(1/Math.sqrt(2)); float thumbWidth = thumbHeight*(float)(1/Math.sqrt(2));
float DZx = 0.2f*outerRadius; float DZx = 0.2f*outerRadius;
float DZy = 0.2f*outerRadius; float DZy = 0.2f*outerRadius;
//Bitmap blankPage = BitmapFactory.decodeResource( getResources() , R.drawable.page ); //Bitmap blankPage = BitmapFactory.decodeResource(getResources(), R.drawable.page);
Log.i( TAG , Float.toString( width ) + " X " + Float.toString( height ) ); Log.i(TAG, Float.toString(width) + "x" + Float.toString(height));
canvas.drawCircle( centerX , centerY , outerRadius , mPaintGray ); canvas.drawCircle(centerX, centerY, outerRadius, mPaintGray);
canvas.drawCircle( centerX , centerY , innerRadius , mPaintBlack ); canvas.drawCircle(centerX, centerY, innerRadius, mPaintBlack);
//Either get thumbs from directory or use generic page images //Either get thumbs from directory or use generic page images
//For now just get the first 4 thumbs -> add some checks later //For now just get the first 4 thumbs -> add some checks later
if( dir == null ) if (dir == null)
return;//TODO return;//TODO
File[] contents = dir.listFiles();//TODO consider filtering thumbs to match grid. File[] contents = dir.listFiles();//TODO consider filtering thumbs to match grid.
if( contents == null ) if (contents == null)
// dir is not a directory, // dir is not a directory,
// or user does not have permissions to read it // or user does not have permissions to read it
return; return;
Stack<Bitmap> thumbs = new Stack<Bitmap>(); Stack<Bitmap> thumbs = new Stack<Bitmap>();
BitmapFactory factory = new BitmapFactory(); BitmapFactory factory = new BitmapFactory();
for( File file : contents ){ for (File file : contents) {
if( !FileUtilities.isThumbnail(file) ) if (!FileUtilities.isThumbnail(file))
continue; continue;
thumbs.push( factory.decodeFile( file.getAbsolutePath() ) );//TODO switch to push for semantics thumbs.push(factory.decodeFile(file.getAbsolutePath()));//TODO switch to push for semantics
if( thumbs.size() > 3 ) if (thumbs.size() > 3)
break; break;
} }
/*while( thumbs.size() < 4 ){// padd out with blanks? /*while(thumbs.size() < 4) {// padd out with blanks?
thumbs.push( blankPage ); thumbs.push(blankPage);
}*/ }*/
Log.i( TAG, Integer.toString( thumbs.size() ) ); Log.i(TAG, Integer.toString(thumbs.size()));
//should handle empty folders better //should handle empty folders better
// options: // options:
// don't show? // don't show?
// show generic LO icons for writer etc // show generic LO icons for writer etc
// Show a generic blank page icon // Show a generic blank page icon
if( thumbs.isEmpty() ) if (thumbs.isEmpty())
return; return;
/*float left = centerX ;//+ 0.25f*outerRadius; /*float left = centerX ;//+ 0.25f*outerRadius;
float top = centerY - 0.5f*outerRadius; float top = centerY - 0.5f*outerRadius;
float right = left + thumbs.get(0).getWidth()*0.4f; float right = left + thumbs.get(0).getWidth()*0.4f;
float bottom = top + thumbs.get(0).getHeight()*0.4f; float bottom = top + thumbs.get(0).getHeight()*0.4f;
RectF dest = new RectF( left, top , right , bottom ); RectF dest = new RectF(left, top, right, bottom);
RectF shadowBox = new RectF(dest); RectF shadowBox = new RectF(dest);
shadowBox.inset( -1 , -1 ); shadowBox.inset(-1, -1);
int size = thumbs.size(); int size = thumbs.size();
for( int i = 1 ; i <= size ; i++ ){ for (int i = 1; i <= size; i++) {
canvas.drawRect( shadowBox , mPaintShadow); canvas.drawRect(shadowBox, mPaintShadow);
canvas.drawBitmap( thumbs.pop() , null , dest , null); canvas.drawBitmap(thumbs.pop(), null, dest, null);
dest.offset( -outerRadius*0.2f , outerRadius*0.1f ); dest.offset(-outerRadius*0.2f, outerRadius*0.1f);
shadowBox.offset( -outerRadius*0.2f , outerRadius*0.1f ); shadowBox.offset(-outerRadius*0.2f, outerRadius*0.1f);
}*/ }*/
float left; float left;
float top; float top;
@@ -136,7 +136,7 @@ public class FolderIconView extends View{
RectF dest; RectF dest;
RectF shadowBox; RectF shadowBox;
int size; int size;
switch( thumbs.size() ){ switch(thumbs.size()) {
case 0: case 0:
break; break;
case 1: case 1:
@@ -144,26 +144,26 @@ public class FolderIconView extends View{
top = centerY - 0.5f*thumbHeight; top = centerY - 0.5f*thumbHeight;
right = left + thumbWidth; right = left + thumbWidth;
bottom = top + thumbHeight; bottom = top + thumbHeight;
dest = new RectF( left, top , right , bottom ); dest = new RectF(left, top, right, bottom);
shadowBox = new RectF(dest); shadowBox = new RectF(dest);
shadowBox.inset( -1 , -1 ); shadowBox.inset(-1, -1);
canvas.drawRect( shadowBox , mPaintShadow); canvas.drawRect(shadowBox, mPaintShadow);
canvas.drawBitmap( thumbs.pop() , null , dest , null); canvas.drawBitmap(thumbs.pop(), null, dest, null);
break; break;
case 2: case 2:
left = centerX - 0.5f*thumbWidth + 0.5f*DZx; left = centerX - 0.5f*thumbWidth + 0.5f*DZx;
top = centerY - 0.5f*thumbHeight - 0.5f*DZy; top = centerY - 0.5f*thumbHeight - 0.5f*DZy;
right = left + thumbWidth; right = left + thumbWidth;
bottom = top + thumbHeight; bottom = top + thumbHeight;
dest = new RectF( left, top , right , bottom ); dest = new RectF(left, top, right, bottom);
shadowBox = new RectF(dest); shadowBox = new RectF(dest);
shadowBox.inset( -1 , -1 ); shadowBox.inset(-1, -1);
size = thumbs.size(); size = thumbs.size();
for( int i = 1 ; i <= size ; i++ ){ for (int i = 1; i <= size; i++) {
canvas.drawRect( shadowBox , mPaintShadow); canvas.drawRect(shadowBox, mPaintShadow);
canvas.drawBitmap( thumbs.pop() , null , dest , null); canvas.drawBitmap(thumbs.pop(), null, dest, null);
dest.offset( -DZx , DZy ); dest.offset(-DZx, DZy);
shadowBox.offset( -DZx , DZy ); shadowBox.offset(-DZx, DZy);
} }
break; break;
case 3: case 3:
@@ -171,15 +171,15 @@ public class FolderIconView extends View{
top = centerY - 0.5f*thumbHeight - DZy; top = centerY - 0.5f*thumbHeight - DZy;
right = left + thumbWidth; right = left + thumbWidth;
bottom = top + thumbHeight; bottom = top + thumbHeight;
dest = new RectF( left, top , right , bottom ); dest = new RectF(left, top, right, bottom);
shadowBox = new RectF(dest); shadowBox = new RectF(dest);
shadowBox.inset( -1 , -1 ); shadowBox.inset(-1, -1);
size = thumbs.size(); size = thumbs.size();
for( int i = 1 ; i <= size ; i++ ){ for (int i = 1; i <= size; i++) {
canvas.drawRect( shadowBox , mPaintShadow); canvas.drawRect(shadowBox, mPaintShadow);
canvas.drawBitmap( thumbs.pop() , null , dest , null); canvas.drawBitmap(thumbs.pop(), null, dest, null);
dest.offset( -DZx , DZy ); dest.offset(-DZx, DZy);
shadowBox.offset( -DZx , DZy ); shadowBox.offset(-DZx, DZy);
} }
break; break;
case 4: case 4:
@@ -187,15 +187,15 @@ public class FolderIconView extends View{
top = centerY - 0.5f*thumbHeight - 1.5f*DZy; top = centerY - 0.5f*thumbHeight - 1.5f*DZy;
right = left + thumbWidth; right = left + thumbWidth;
bottom = top + thumbHeight; bottom = top + thumbHeight;
dest = new RectF( left, top , right , bottom ); dest = new RectF(left, top, right, bottom);
shadowBox = new RectF(dest); shadowBox = new RectF(dest);
shadowBox.inset( -1 , -1 ); shadowBox.inset(-1, -1);
size = thumbs.size(); size = thumbs.size();
for( int i = 1 ; i <= size ; i++ ){ for (int i = 1; i <= size; i++) {
canvas.drawRect( shadowBox , mPaintShadow); canvas.drawRect(shadowBox, mPaintShadow);
canvas.drawBitmap( thumbs.pop() , null , dest , null); canvas.drawBitmap(thumbs.pop(), null, dest, null);
dest.offset( -DZx , DZy ); dest.offset(-DZx, DZy);
shadowBox.offset( -DZx , DZy ); shadowBox.offset(-DZx, DZy);
} }
break; break;
default: default: