Skip to content
Browse files

Version 1.0.1

  • Loading branch information...
0 parents commit 00bbdd8ed8904592e1c96eba8f9ef671028cdb44 David Byrne committed Jan 17, 2010
Showing with 801 additions and 0 deletions.
  1. +20 −0 AndroidManifest.xml
  2. BIN android.keystore
  3. BIN bin/classes.dex
  4. BIN bin/classes/byrne/fractal/Eula$1.class
  5. BIN bin/classes/byrne/fractal/Eula$2.class
  6. BIN bin/classes/byrne/fractal/Eula$3.class
  7. BIN bin/classes/byrne/fractal/Eula.class
  8. BIN bin/classes/byrne/fractal/FractalConstants.class
  9. BIN bin/classes/byrne/fractal/FractalParameters.class
  10. BIN bin/classes/byrne/fractal/FractalView.class
  11. BIN bin/classes/byrne/fractal/Fractoid.class
  12. BIN bin/classes/byrne/fractal/GenerateFractalTask.class
  13. BIN bin/classes/byrne/fractal/R$attr.class
  14. BIN bin/classes/byrne/fractal/R$drawable.class
  15. BIN bin/classes/byrne/fractal/R$raw.class
  16. BIN bin/classes/byrne/fractal/R$string.class
  17. BIN bin/classes/byrne/fractal/R.class
  18. BIN bin/fractoid-debug-unaligned.apk
  19. BIN bin/fractoid-debug.apk
  20. BIN bin/fractoid-release.apk
  21. BIN bin/fractoid-unaligned.apk
  22. BIN bin/fractoid-unsigned.apk
  23. BIN bin/fractoid.ap_
  24. +19 −0 build.properties
  25. +67 −0 build.xml
  26. +11 −0 default.properties
  27. +25 −0 gen/byrne/fractal/R.java
  28. +10 −0 local.properties
  29. BIN res/drawable-hdpi/icon.png
  30. BIN res/drawable-ldpi/icon.png
  31. BIN res/drawable-mdpi/icon.png
  32. +36 −0 res/raw/eula
  33. +36 −0 res/raw/eula~
  34. +7 −0 res/values/strings.xml
  35. +112 −0 src/byrne/fractal/Eula.java
  36. +13 −0 src/byrne/fractal/FractalConstants.java
  37. +45 −0 src/byrne/fractal/FractalParameters.java
  38. +178 −0 src/byrne/fractal/FractalView.java
  39. +80 −0 src/byrne/fractal/Fractoid.java
  40. +142 −0 src/byrne/fractal/GenerateFractalTask.java
20 AndroidManifest.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="byrne.fractal"
+ android:versionCode="2"
+ android:versionName="1.0.1">
+ <uses-sdk android:minSdkVersion="6"/>
+ <uses-permission android:name="android.permission.SET_WALLPAPER" />
+
+ <application android:label="@string/app_name" android:icon="@drawable/icon">
+ <activity android:name="Fractoid"
+ android:label="@string/app_name"
+ android:screenOrientation="landscape"
+ android:configChanges="orientation|keyboard|keyboardHidden">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
BIN android.keystore
Binary file not shown.
BIN bin/classes.dex
Binary file not shown.
BIN bin/classes/byrne/fractal/Eula$1.class
Binary file not shown.
BIN bin/classes/byrne/fractal/Eula$2.class
Binary file not shown.
BIN bin/classes/byrne/fractal/Eula$3.class
Binary file not shown.
BIN bin/classes/byrne/fractal/Eula.class
Binary file not shown.
BIN bin/classes/byrne/fractal/FractalConstants.class
Binary file not shown.
BIN bin/classes/byrne/fractal/FractalParameters.class
Binary file not shown.
BIN bin/classes/byrne/fractal/FractalView.class
Binary file not shown.
BIN bin/classes/byrne/fractal/Fractoid.class
Binary file not shown.
BIN bin/classes/byrne/fractal/GenerateFractalTask.class
Binary file not shown.
BIN bin/classes/byrne/fractal/R$attr.class
Binary file not shown.
BIN bin/classes/byrne/fractal/R$drawable.class
Binary file not shown.
BIN bin/classes/byrne/fractal/R$raw.class
Binary file not shown.
BIN bin/classes/byrne/fractal/R$string.class
Binary file not shown.
BIN bin/classes/byrne/fractal/R.class
Binary file not shown.
BIN bin/fractoid-debug-unaligned.apk
Binary file not shown.
BIN bin/fractoid-debug.apk
Binary file not shown.
BIN bin/fractoid-release.apk
Binary file not shown.
BIN bin/fractoid-unaligned.apk
Binary file not shown.
BIN bin/fractoid-unsigned.apk
Binary file not shown.
BIN bin/fractoid.ap_
Binary file not shown.
19 build.properties
@@ -0,0 +1,19 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
+key.store=/home/dbyrne/Fractoid/android.keystore
+key.alias=android_dev_key
67 build.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="fractoid" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contains the path to the SDK. It should *NOT* be checked in in Version
+ Control Systems. -->
+ <property file="local.properties" />
+
+ <!-- The build.properties file can be created by you and is never touched
+ by the 'android' tool. This is the place to change some of the default property values
+ used by the Ant rules.
+ Here are some properties you may want to change/update:
+
+ application.package
+ the name of your application package as defined in the manifest. Used by the
+ 'uninstall' rule.
+ source.dir
+ the name of the source directory. Default is 'src'.
+ out.dir
+ the name of the output directory. Default is 'bin'.
+
+ Properties related to the SDK location or the project target should be updated
+ using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems.
+
+ -->
+ <property file="build.properties" />
+
+ <!-- The default.properties file is created and updated by the 'android' tool, as well
+ as ADT.
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems. -->
+ <property file="default.properties" />
+
+ <!-- Custom Android task to deal with the project target, and import the proper rules.
+ This requires ant 1.6.0 or above. -->
+ <path id="android.antlibs">
+ <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
+ </path>
+
+ <taskdef name="setup"
+ classname="com.android.ant.SetupTask"
+ classpathref="android.antlibs" />
+
+ <!-- Execute the Android Setup task that will setup some properties specific to the target,
+ and import the build rules files.
+
+ The rules file is imported from
+ <SDK>/platforms/<target_platform>/templates/android_rules.xml
+
+ To customize some build steps for your project:
+ - copy the content of the main node <project> from android_rules.xml
+ - paste it in this build.xml below the <setup /> task.
+ - disable the import by changing the setup task below to <setup import="false" />
+
+ This will ensure that the properties are setup correctly but that your customized
+ build steps are used.
+ -->
+ <setup />
+
+</project>
11 default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-6
25 gen/byrne/fractal/R.java
@@ -0,0 +1,25 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package byrne.fractal;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int icon=0x7f020000;
+ }
+ public static final class raw {
+ public static final int eula=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040000;
+ public static final int eula_accept=0x7f040002;
+ public static final int eula_refuse=0x7f040003;
+ public static final int eula_title=0x7f040001;
+ }
+}
10 local.properties
@@ -0,0 +1,10 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must *NOT* be checked in Version Control Systems,
+# as it contains information specific to your local configuration.
+
+# location of the SDK. This is only used by Ant
+# For customization when using a Version Control System, please read the
+# header note.
+sdk.dir=/home/dbyrne/android-sdk-linux_86
BIN res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 res/raw/eula
@@ -0,0 +1,36 @@
+END-USER LICENSE AGREEMENT FOR FRACTOID IMPORTANT PLEASE READ THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT CAREFULLY BEFORE CONTINUING: David Byrne's End-User License Agreement ("EULA") is a legal agreement between you (either an individual or a single entity) and David Byrne. For David Byrne's software product(s) identified above which may include associated software components, media, printed materials, and "online" or electronic documentation ("SOFTWARE PRODUCT"). By installing, copying, or otherwise using the SOFTWARE PRODUCT, you agree to be bound by the terms of this EULA. This license agreement represents the entire agreement concerning the program between you and David Byrne, (referred to as "licenser"), and it supersedes any prior proposal, representation, or understanding between the parties. If you do not agree to the terms of this EULA, do not install or use the SOFTWARE PRODUCT.
+
+The SOFTWARE PRODUCT is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. The SOFTWARE PRODUCT is licensed, not sold.
+
+1. GRANT OF LICENSE.
+The SOFTWARE PRODUCT is licensed as follows:
+(a) Installation and Use.
+David Byrne grants you the right to install and use copies of the SOFTWARE PRODUCT on your computer running a validly licensed copy of the operating system for which the SOFTWARE PRODUCT was designed [e.g., Windows 95, Windows NT, Windows 98, Windows 2000, Windows 2003, Windows XP, Windows ME, Windows Vista].
+(b) Backup Copies.
+You may also make copies of the SOFTWARE PRODUCT as may be necessary for backup and archival purposes.
+
+2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS.
+(a) Maintenance of Copyright Notices.
+You must not remove or alter any copyright notices on any and all copies of the SOFTWARE PRODUCT.
+(b) Distribution.
+You may not distribute registered copies of the SOFTWARE PRODUCT to third parties. Evaluation versions available for download from David Byrne's websites may be freely distributed.
+(c) Prohibition on Reverse Engineering, Decompilation, and Disassembly.
+You may not reverse engineer, decompile, or disassemble the SOFTWARE PRODUCT, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.
+(d) Rental.
+You may not rent, lease, or lend the SOFTWARE PRODUCT.
+(e) Support Services.
+David Byrne may provide you with support services related to the SOFTWARE PRODUCT ("Support Services"). Any supplemental software code provided to you as part of the Support Services shall be considered part of the SOFTWARE PRODUCT and subject to the terms and conditions of this EULA.
+(f) Compliance with Applicable Laws.
+You must comply with all applicable laws regarding use of the SOFTWARE PRODUCT.
+
+3. TERMINATION
+Without prejudice to any other rights, David Byrne may terminate this EULA if you fail to comply with the terms and conditions of this EULA. In such event, you must destroy all copies of the SOFTWARE PRODUCT in your possession.
+
+4. COPYRIGHT
+All title, including but not limited to copyrights, in and to the SOFTWARE PRODUCT and any copies thereof are owned by David Byrne or its suppliers. All title and intellectual property rights in and to the content which may be accessed through use of the SOFTWARE PRODUCT is the property of the respective content owner and may be protected by applicable copyright or other intellectual property laws and treaties. This EULA grants you no rights to use such content. All rights not expressly granted are reserved by David Byrne.
+
+5. NO WARRANTIES
+David Byrne expressly disclaims any warranty for the SOFTWARE PRODUCT. The SOFTWARE PRODUCT is provided 'As Is' without any express or implied warranty of any kind, including but not limited to any warranties of merchantability, noninfringement, or fitness of a particular purpose. David Byrne does not warrant or assume responsibility for the accuracy or completeness of any information, text, graphics, links or other items contained within the SOFTWARE PRODUCT. David Byrne makes no warranties respecting any harm that may be caused by the transmission of a computer virus, worm, time bomb, logic bomb, or other such computer program. David Byrne further expressly disclaims any warranty or representation to Authorized Users or to any third party.
+
+6. LIMITATION OF LIABILITY
+In no event shall David Byrne be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of 'Authorized Users' use of or inability to use the SOFTWARE PRODUCT, even if David Byrne has been advised of the possibility of such damages. In no event will David Byrne be liable for loss of data or for indirect, special, incidental, consequential (including lost profit), or other damages based in contract, tort or otherwise. David Byrne shall have no liability with respect to the content of the SOFTWARE PRODUCT or any part thereof, including but not limited to errors or omissions contained therein, libel, infringements of rights of publicity, privacy, trademark rights, business interruption, personal injury, loss of privacy, moral rights or the disclosure of confidential information.
36 res/raw/eula~
@@ -0,0 +1,36 @@
+END-USER LICENSE AGREEMENT FOR FRACTOID IMPORTANT PLEASE READ THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT CAREFULLY BEFORE CONTINUING WITH THIS PROGRAM INSTALL: {INSERT COMPANY NAME's } End-User License Agreement ("EULA") is a legal agreement between you (either an individual or a single entity) and David Byrne. for the David Byrne software product(s) identified above which may include associated software components, media, printed materials, and "online" or electronic documentation ("SOFTWARE PRODUCT"). By installing, copying, or otherwise using the SOFTWARE PRODUCT, you agree to be bound by the terms of this EULA. This license agreement represents the entire agreement concerning the program between you and David Byrne, (referred to as "licenser"), and it supersedes any prior proposal, representation, or understanding between the parties. If you do not agree to the terms of this EULA, do not install or use the SOFTWARE PRODUCT.
+
+The SOFTWARE PRODUCT is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. The SOFTWARE PRODUCT is licensed, not sold.
+
+1. GRANT OF LICENSE.
+The SOFTWARE PRODUCT is licensed as follows:
+(a) Installation and Use.
+David Byrne grants you the right to install and use copies of the SOFTWARE PRODUCT on your computer running a validly licensed copy of the operating system for which the SOFTWARE PRODUCT was designed [e.g., Windows 95, Windows NT, Windows 98, Windows 2000, Windows 2003, Windows XP, Windows ME, Windows Vista].
+(b) Backup Copies.
+You may also make copies of the SOFTWARE PRODUCT as may be necessary for backup and archival purposes.
+
+2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS.
+(a) Maintenance of Copyright Notices.
+You must not remove or alter any copyright notices on any and all copies of the SOFTWARE PRODUCT.
+(b) Distribution.
+You may not distribute registered copies of the SOFTWARE PRODUCT to third parties. Evaluation versions available for download from David Byrne's websites may be freely distributed.
+(c) Prohibition on Reverse Engineering, Decompilation, and Disassembly.
+You may not reverse engineer, decompile, or disassemble the SOFTWARE PRODUCT, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.
+(d) Rental.
+You may not rent, lease, or lend the SOFTWARE PRODUCT.
+(e) Support Services.
+David Byrne may provide you with support services related to the SOFTWARE PRODUCT ("Support Services"). Any supplemental software code provided to you as part of the Support Services shall be considered part of the SOFTWARE PRODUCT and subject to the terms and conditions of this EULA.
+(f) Compliance with Applicable Laws.
+You must comply with all applicable laws regarding use of the SOFTWARE PRODUCT.
+
+3. TERMINATION
+Without prejudice to any other rights, David Byrne may terminate this EULA if you fail to comply with the terms and conditions of this EULA. In such event, you must destroy all copies of the SOFTWARE PRODUCT in your possession.
+
+4. COPYRIGHT
+All title, including but not limited to copyrights, in and to the SOFTWARE PRODUCT and any copies thereof are owned by David Byrne or its suppliers. All title and intellectual property rights in and to the content which may be accessed through use of the SOFTWARE PRODUCT is the property of the respective content owner and may be protected by applicable copyright or other intellectual property laws and treaties. This EULA grants you no rights to use such content. All rights not expressly granted are reserved by David Byrne.
+
+5. NO WARRANTIES
+David Byrne expressly disclaims any warranty for the SOFTWARE PRODUCT. The SOFTWARE PRODUCT is provided 'As Is' without any express or implied warranty of any kind, including but not limited to any warranties of merchantability, noninfringement, or fitness of a particular purpose. David Byrne does not warrant or assume responsibility for the accuracy or completeness of any information, text, graphics, links or other items contained within the SOFTWARE PRODUCT. David Byrne makes no warranties respecting any harm that may be caused by the transmission of a computer virus, worm, time bomb, logic bomb, or other such computer program. David Byrne further expressly disclaims any warranty or representation to Authorized Users or to any third party.
+
+6. LIMITATION OF LIABILITY
+In no event shall David Byrne be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of 'Authorized Users' use of or inability to use the SOFTWARE PRODUCT, even if David Byrne has been advised of the possibility of such damages. In no event will David Byrne be liable for loss of data or for indirect, special, incidental, consequential (including lost profit), or other damages based in contract, tort or otherwise. David Byrne shall have no liability with respect to the content of the SOFTWARE PRODUCT or any part thereof, including but not limited to errors or omissions contained therein, libel, infringements of rights of publicity, privacy, trademark rights, business interruption, personal injury, loss of privacy, moral rights or the disclosure of confidential information.
7 res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Fractoid</string>
+ <string name="eula_title">License</string>
+ <string name="eula_accept">Accept</string>
+ <string name="eula_refuse">Refuse</string>
+</resources>
112 src/byrne/fractal/Eula.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package byrne.fractal;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.InputStreamReader;
+
+/**
+ * Displays an EULA ("End User License Agreement") that the user has to accept before
+ * using the application. Your application should call {@link Eula#showEula(android.app.Activity)}
+ * in the onCreate() method of the first activity. If the user accepts the EULA, it will never
+ * be shown again. If the user refuses, {@link android.app.Activity#finish()} is invoked
+ * on your activity.
+ */
+class Eula {
+ private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted";
+ private static final String PREFERENCES_EULA = "eula";
+
+ /**
+ * Displays the EULA if necessary. This method should be called from the onCreate()
+ * method of your main Activity.
+ *
+ * @param activity The Activity to finish if the user rejects the EULA.
+ */
+ static void showEula(final Activity activity) {
+ final SharedPreferences preferences = activity.getSharedPreferences(PREFERENCES_EULA,
+ Activity.MODE_PRIVATE);
+ if (!preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setTitle(R.string.eula_title);
+ builder.setCancelable(true);
+ builder.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ accept(preferences);
+ }
+ });
+ builder.setNegativeButton(R.string.eula_refuse, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ refuse(activity);
+ }
+ });
+ builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ refuse(activity);
+ }
+ });
+ // UNCOMMENT TO ENABLE EULA
+ builder.setMessage(readFile(activity, R.raw.eula));
+ builder.create().show();
+ }
+ }
+
+ private static void accept(SharedPreferences preferences) {
+ preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit();
+ }
+
+ private static void refuse(Activity activity) {
+ activity.finish();
+ }
+
+ private static CharSequence readFile(Activity activity, int id) {
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new InputStreamReader(
+ activity.getResources().openRawResource(id)));
+ String line;
+ StringBuilder buffer = new StringBuilder();
+ while ((line = in.readLine()) != null) buffer.append(line).append('\n');
+ return buffer;
+ } catch (IOException e) {
+ return "";
+ } finally {
+ closeStream(in);
+ }
+ }
+
+ /**
+ * Closes the specified stream.
+ *
+ * @param stream The stream to close.
+ */
+ private static void closeStream(Closeable stream) {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+}
13 src/byrne/fractal/FractalConstants.java
@@ -0,0 +1,13 @@
+package byrne.fractal;
+
+public class FractalConstants {
+
+ final static int RESET_IMAGE = 1;
+ final static int JULIA_MODE = 2;
+ final static int SET_WALLPAPER = 3;
+ final static int MANDELBROT_MODE = 4;
+ final static int SAVE_IMAGE = 5;
+
+ final static int STARTING_MAX_ITERATIONS = 35;
+
+}
45 src/byrne/fractal/FractalParameters.java
@@ -0,0 +1,45 @@
+package byrne.fractal;
+
+public class FractalParameters {
+
+ private int maxIterations;
+ public void setMaxIterations(int i) {maxIterations = i;}
+ public int getMaxIterations() {return maxIterations;}
+
+ private int xres;
+ public int getXRes() {return xres;}
+ public void setXRes(int xr) {xres = xr;}
+
+ private int yres;
+ public int getYRes() {return yres;}
+ public void setYRes(int yr) {yres = yr;}
+
+ public double getResRatio() {return (double)xres/yres;}
+
+ private int mode;
+ public int getMode() {return mode;}
+ public void setMode(int m) {mode = m;}
+
+ private double shiftFactor;
+ public double getShiftFactor() {return shiftFactor;}
+ public void randomizeShiftFactor() {shiftFactor = Math.random()*2;}
+
+ private double realmax,realmin,imagmax,imagmin;
+ public void setCoords(double rmin, double rmax, double imin, double imax) {
+ realmin = rmin;
+ realmax = rmax;
+ imagmin = imin;
+ imagmax = imax;
+ }
+ public double getRealMin() {return realmin;}
+ public double getRealMax() {return realmax;}
+ public double getImagMin() {return imagmin;}
+ public double getImagMax() {return imagmax;}
+
+ private double P=-1,Q=-1;
+ public double getP() {return P;}
+ public double getQ() {return Q;}
+ public void setP(double p) {P=p;}
+ public void setQ(double q) {Q=q;}
+
+}
178 src/byrne/fractal/FractalView.java
@@ -0,0 +1,178 @@
+package byrne.fractal;
+
+import android.view.View;
+import android.graphics.*;
+import android.view.MotionEvent;
+import android.content.Context;
+
+public class FractalView extends View {
+
+ private double minY,maxY,minX,maxX;
+ private Bitmap fractalBitmap;
+ private RectF selection;
+ private boolean zoom;
+ private double touched_x=-1, touched_y=-1;
+
+ FractalParameters params;
+
+ public FractalView(Context context){
+ super(context);
+ zoom = true;
+ params = new FractalParameters();
+ params.setMaxIterations(FractalConstants.STARTING_MAX_ITERATIONS);
+ }
+
+ public void setZoom(boolean z) {
+ zoom = z;
+ }
+
+ public void setMode(int m) {
+ params.setMode(m);
+ }
+ public Bitmap getFractal() {
+ return fractalBitmap;
+ }
+
+ public void setFractal(Bitmap fa) {
+ fractalBitmap = fa;
+ }
+
+ protected void resetCoords() {
+
+ double imagmax = 1.4;
+ double imagmin = -1.4;
+
+ double r_y = Math.abs(imagmax - imagmin);
+ double realmax = params.getResRatio()*r_y/2;
+ double realmin = params.getResRatio()*r_y/2*-1;
+
+ params.randomizeShiftFactor();
+ params.setCoords(realmin,realmax,imagmin,imagmax);
+ params.setMode(FractalConstants.MANDELBROT_MODE);
+ params.setMaxIterations(FractalConstants.STARTING_MAX_ITERATIONS);
+
+ new GenerateFractalTask(params,this).execute();
+ }
+
+ @Override protected void onSizeChanged(int width, int height, int oldw, int oldh) {
+ params.setXRes(width);
+ params.setYRes(height);
+ }
+
+ @Override public boolean onTouchEvent (MotionEvent event) {
+
+ double realmax = params.getRealMax();
+ double realmin = params.getRealMin();
+ double imagmin = params.getImagMin();
+ double imagmax = params.getImagMax();
+
+ if (zoom) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ touched_x = event.getX();
+ touched_y = event.getY();
+ } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
+
+ if (event.getY() > touched_y) {
+ maxY=event.getY();
+ minY=(double)touched_y;
+ } else {
+ maxY=(double)touched_y;
+ minY=event.getY();
+ }
+ if (event.getX() > touched_x) {
+ maxX=event.getX();
+ minX=(double)touched_x;
+ } else {
+ maxX=(double)touched_x;
+ minX=event.getX();
+ }
+ double x_range = Math.abs(maxX-minX);
+ double y_range = Math.abs(maxY-minY);
+ double inv_ratio = (double)params.getYRes()/params.getXRes();
+ double sel_ratio = x_range/y_range;
+
+ if (params.getResRatio() > sel_ratio) {
+ if (maxX == event.getX()) {
+ maxX = minX+(params.getResRatio()*y_range);
+ } else {
+ minX = maxX-(params.getResRatio()*y_range);
+ }
+ } else {
+ if (maxY == event.getY()) {
+ maxY = minY+(inv_ratio*x_range);
+ } else {
+ minY = maxY-(inv_ratio*x_range);
+ }
+ }
+
+ selection = new RectF((float)minX,(float)maxY,(float)maxX,(float)minY);
+ postInvalidate();
+
+ } else if (event.getAction() == MotionEvent.ACTION_UP) {
+
+ double x_range = (double)Math.abs(realmax-realmin);
+ double y_range = (double)Math.abs(imagmax-imagmin);
+
+ realmax = realmin + (maxX/params.getXRes()) * x_range;
+ realmin = realmin + (minX/params.getXRes()) * x_range;
+ imagmin = imagmax - (maxY/params.getYRes()) * y_range;
+ imagmax = imagmax - (minY/params.getYRes()) * y_range;
+ selection = null;
+
+ params.setCoords(realmin,realmax,imagmin,imagmax);
+ params.setMaxIterations(params.getMaxIterations() + 15);
+ new GenerateFractalTask(params,this).execute();
+ }
+ } else if (!zoom) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+
+ double x_range = (double)Math.abs(realmax-realmin);
+ double y_range = (double)Math.abs(imagmax-imagmin);
+ touched_x = event.getX();
+ touched_y = event.getY();
+ params.setP(realmin + ((touched_x/params.getXRes())*x_range));
+ params.setQ(imagmax - ((touched_y/params.getYRes())*y_range));
+
+ imagmax = 1.4;
+ imagmin = -1.4;
+ y_range = (double)Math.abs(imagmax-imagmin);
+ realmax = (params.getResRatio())*y_range/2;
+ realmin = (params.getResRatio())*y_range/2*-1;
+
+ params.setCoords(realmin,realmax,imagmin,imagmax);
+ params.setMaxIterations(FractalConstants.STARTING_MAX_ITERATIONS);
+ new GenerateFractalTask(params,this).execute();
+ }
+ }
+ return true;
+ }
+
+ @Override protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (fractalBitmap != null) {
+ canvas.drawBitmap(fractalBitmap,0,0,null);
+
+ Paint p = new Paint();
+ p.setColor(Color.WHITE);
+ p.setTextSize(20);
+
+ if (selection != null) {
+ p.setStyle(Paint.Style.STROKE);
+ p.setStrokeWidth(2);
+ canvas.drawRect(selection,p);
+ }
+ p.setStyle(Paint.Style.FILL_AND_STROKE);
+ p.setStrokeWidth(1);
+ if (zoom) {
+ canvas.drawText("Drag to zoom",(params.getXRes()/2)-50,params.getYRes()-5,p);
+ }
+ else {
+ canvas.drawText("Touch Screen to Generate Julia Set",(params.getXRes()/2)-125,params.getYRes()-5,p);
+ }
+ String maxIterString = "MaxIter: " + params.getMaxIterations();
+ canvas.drawText(maxIterString,5,params.getYRes()-5,p);
+ } else {
+ resetCoords();
+ }
+ }
+}
80 src/byrne/fractal/Fractoid.java
@@ -0,0 +1,80 @@
+package byrne.fractal;
+
+import java.io.OutputStream;
+import android.net.Uri;
+import android.app.Activity;
+import android.app.WallpaperManager;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
+import android.os.Bundle;
+import android.view.Window;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.provider.MediaStore.Images.Media;
+import android.content.ContentValues;
+
+public class Fractoid extends Activity {
+
+ FractalView fractalView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ fractalView = new FractalView(this);
+ setContentView(fractalView);
+ Eula.showEula(this);
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(0, FractalConstants.RESET_IMAGE, 0, "Reset");
+ menu.add(0, FractalConstants.JULIA_MODE, 0, "Julia Set Mode");
+ menu.add(0, FractalConstants.SAVE_IMAGE, 0, "Save Image");
+ menu.add(0, FractalConstants.SET_WALLPAPER, 0, "Set As Wallpaper");
+ return true;
+ }
+
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case FractalConstants.RESET_IMAGE:
+ fractalView.resetCoords();
+ return true;
+
+ case FractalConstants.JULIA_MODE:
+ fractalView.setMode(FractalConstants.JULIA_MODE);
+ fractalView.setZoom(false);
+ fractalView.postInvalidate();
+ return true;
+
+ case FractalConstants.SAVE_IMAGE:
+ try {
+ ContentValues values = new ContentValues(3);
+ values.put(Media.DISPLAY_NAME, "Fractal");
+ values.put(Media.DESCRIPTION, "Generated using Fractoid");
+ values.put(Media.MIME_TYPE, "image/png");
+ Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
+ OutputStream os = getContentResolver().openOutputStream(uri);
+ fractalView.getFractal().compress(CompressFormat.PNG, 100, os);
+ os.flush();
+ os.close();
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ return true;
+
+ case FractalConstants.SET_WALLPAPER:
+ WallpaperManager wm = WallpaperManager.getInstance(this);
+ try {
+ wm.setBitmap(fractalView.getFractal());
+ } catch (Exception e) {
+ System.out.println("IOException: " + e);
+ }
+ return true;
+ }
+ return false;
+ }
+}
142 src/byrne/fractal/GenerateFractalTask.java
@@ -0,0 +1,142 @@
+package byrne.fractal;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.AsyncTask;
+import android.graphics.*;
+
+public class GenerateFractalTask extends AsyncTask<Void, Integer, Bitmap> {
+
+ ProgressDialog myProgressDialog;
+ FractalParameters params;
+ FractalView fractalView;
+
+ public GenerateFractalTask(FractalParameters p, FractalView fv) {
+ params = p;
+ fractalView = fv;
+ }
+
+ private int[] calculateColors() {
+ double red, green, blue;
+
+ double shiftFactor = params.getShiftFactor();
+
+ final int numberOfColors = params.getMaxIterations()*100;
+ int[] colorIntegers = new int[numberOfColors];
+
+ for (int x = 0; x < numberOfColors; x++) {
+ double data = x;
+ data = 2*Math.PI*(data/5000);
+ red = Math.sin(data + Math.PI*shiftFactor);
+ green = Math.cos(data + Math.PI*shiftFactor);
+ blue = -((red + green)*.707);
+ red = (red*127.0) + 127.0;
+ green = (green*127.0) + 127.0;
+ blue = (blue*127.0) + 127.0;
+ colorIntegers[x] = Color.rgb((int)red, (int)green, (int)blue);
+ }
+
+ return colorIntegers;
+
+ }
+
+ private Bitmap createBitmap() {
+
+ double realmin = params.getRealMin();
+ double realmax = params.getRealMax();
+ double imagmin = params.getImagMin();
+ double imagmax = params.getImagMax();
+
+ double P = params.getP();
+ double Q = params.getQ();
+
+ int xres = params.getXRes();
+ int yres = params.getYRes();
+ int mode = params.getMode();
+
+ Bitmap b = Bitmap.createBitmap(xres, yres, Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(b);
+
+ Paint paint = new Paint();
+ paint.setStyle(Paint.Style.FILL_AND_STROKE);
+ paint.setStrokeWidth(1);
+
+ int[] colorIntegers = calculateColors();
+
+ double x=-1, y=-1, xsq, ysq, mu = 1;
+ int index;
+ boolean lessThanMax;
+
+ double deltaP = (realmax - realmin)/xres;
+ double deltaQ = (imagmax - imagmin)/yres;
+
+ final int max = params.getMaxIterations();
+
+ for (int row=0; row < yres; row++) {
+ if (row % 4 == 0) {
+ this.publishProgress((int)Math.round(100*((double)row/yres)));
+ }
+ if (mode == FractalConstants.MANDELBROT_MODE) {
+ Q = imagmax - row*deltaQ;
+ }
+ for (int col=0; col < xres; col++) {
+ if (mode == FractalConstants.MANDELBROT_MODE) {
+ x = y = 0.0;
+ } else if (mode == FractalConstants.JULIA_MODE) {
+
+ x = realmin + (double)col * deltaP;
+ y = imagmax - (double)row * deltaQ;
+ }
+ lessThanMax = false;
+
+ for (index = 0; index < max; index++) {
+ xsq = x*x;
+ ysq = y*y;
+
+ if (xsq + ysq > 4) {
+ lessThanMax = true;
+ mu = index - Math.log(Math.log(Math.sqrt(xsq + ysq)))/ Math.log(2.0);
+ break;
+ }
+ y=2*x*y + Q;
+ if (mode == FractalConstants.MANDELBROT_MODE) {
+ x = xsq - ysq + realmin + col * deltaP;
+ } else if (mode == FractalConstants.JULIA_MODE) {
+ x = xsq - ysq + P;
+
+ }
+ }
+ if (lessThanMax) {
+ int colorIndex = Math.max(0,((int)Math.round(mu*100)-1));
+ paint.setColor(colorIntegers[colorIndex]);
+ } else {
+ paint.setColor(Color.BLACK);
+ }
+ c.drawPoint(col,row,paint);
+ }
+ }
+ return b;
+ }
+
+ @Override protected void onPreExecute() {
+ myProgressDialog = new ProgressDialog(fractalView.getContext());
+ myProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ myProgressDialog.setMessage("Generating Fractal...");
+ myProgressDialog.setCancelable(false);
+ myProgressDialog.show();
+ }
+ @Override protected Bitmap doInBackground(Void... unused) {
+ return createBitmap();
+ }
+
+ @Override protected void onProgressUpdate(Integer... progress) {
+ myProgressDialog.setProgress(progress[0]);
+ }
+
+ @Override protected void onPostExecute(Bitmap bitmap) {
+ fractalView.setZoom(true);
+ fractalView.setFractal(bitmap);
+ fractalView.invalidate();
+ myProgressDialog.dismiss();
+ }
+}

0 comments on commit 00bbdd8

Please sign in to comment.
Something went wrong with that request. Please try again.