Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Throw photos at startup.

  • Loading branch information...
commit e5403c60f0c2d10900a0155f4373d7f78410123e 1 parent fa24b86
@rickardlindberg rickardlindberg authored
View
24 photobox/src/com/photobox/app/PhotoView.java
@@ -43,10 +43,10 @@ public PhotoView(Context context, AttributeSet attrs) {
public PhotoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mapping = new WorldMapping(extractScreenCenter(context));
+ mapping = new WorldMapping(extractScreenCenter());
collection = new PhotoCollection();
debugger = new GraphicalDebugger(mapping);
- bitmapCache = new BitmapCache(getScreenSize(context).max());
+ bitmapCache = new BitmapCache(getScreenSize().max());
renderer = new Renderer(debugger, mapping, collection, bitmapCache);
inputState = new InputState(context, mapping);
inputActor = new InputActor(mapping, collection, bitmapCache);
@@ -70,25 +70,33 @@ protected void onDraw(Canvas canvas) {
public void loadDemoPhotos() {
ImportHandler importHandler = new ImportHandler(bitmapCache);
importHandler.importDemoPhotos(collection, getResources());
+ throwPhotos();
}
public void loadPhotosFromDir(File photoDir) {
ImportHandler importHandler = new ImportHandler(bitmapCache);
importHandler.importPhotosFromDir(collection, photoDir);
+ throwPhotos();
}
- private Point extractScreenCenter(Context context) {
- DisplayMetrics metrics = getDisplayMetrics(context);
+ private void throwPhotos() {
+ BitmapSize screenSize = getScreenSize();
+ int throwBoxSize = (int)Math.round((float)screenSize.min()/mapping.scaleFactor/2);
+ collection.throwPhotos(throwBoxSize);
+ }
+
+ private Point extractScreenCenter() {
+ DisplayMetrics metrics = getDisplayMetrics();
return new Point(metrics.widthPixels / 2, metrics.heightPixels / 2);
}
- private BitmapSize getScreenSize(Context context) {
- DisplayMetrics metrics = getDisplayMetrics(context);
+ private BitmapSize getScreenSize() {
+ DisplayMetrics metrics = getDisplayMetrics();
return new BitmapSize(metrics.widthPixels, metrics.heightPixels);
}
- private DisplayMetrics getDisplayMetrics(Context context) {
- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ private DisplayMetrics getDisplayMetrics() {
+ WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
View
4 photobox/src/com/photobox/files/BitmapSize.java
@@ -20,4 +20,8 @@ public int max() {
return Math.max(width, height);
}
+ public int min() {
+ return Math.min(width, height);
+ }
+
}
View
11 photobox/src/com/photobox/world/PhotoCollection.java
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
public class PhotoCollection {
@@ -20,6 +21,16 @@ public Photo getActive() {
return active;
}
+ public void throwPhotos(int throwBoxSize) {
+ Random rnd = new Random();
+ for (Photo p : photos) {
+ float x = (float)rnd.nextInt(throwBoxSize)-throwBoxSize/2;
+ float y = (float)rnd.nextInt(throwBoxSize)-throwBoxSize/2;
+ p.centerX = x;
+ p.centerY = y;
+ }
+ }
+
public void fingerDown(Point p) {
active = findPhotoAt(p);
if (active != null) {
Please sign in to comment.
Something went wrong with that request. Please try again.