diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..a4f1e40
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..633e601
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+/bin/
+/proguard/
+/gen/
+/libs/
diff --git a/.project b/.project
new file mode 100644
index 0000000..cf0bcfa
--- /dev/null
+++ b/.project
@@ -0,0 +1,33 @@
+
+
+ DiceGenerator
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..5ee3831
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+#Sat Oct 13 14:01:47 GMT+07:00 2012
+eclipse.preferences.version=1
+encoding//src/com/icystar/dicegenerator/HistoryActivity.java=UTF-8
+encoding//src/com/icystar/dicegenerator/MainActivity.java=UTF-8
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..c02e1ac
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/art/dice-generator-market-qr.gif b/art/dice-generator-market-qr.gif
new file mode 100644
index 0000000..55c9270
Binary files /dev/null and b/art/dice-generator-market-qr.gif differ
diff --git a/art/dice-generator-qr.gif b/art/dice-generator-qr.gif
new file mode 100644
index 0000000..d7af96f
Binary files /dev/null and b/art/dice-generator-qr.gif differ
diff --git a/art/ic_launcher.png b/art/ic_launcher.png
new file mode 100644
index 0000000..8d83b7b
Binary files /dev/null and b/art/ic_launcher.png differ
diff --git a/art/screen1.png b/art/screen1.png
new file mode 100644
index 0000000..ab4088e
Binary files /dev/null and b/art/screen1.png differ
diff --git a/art/screen2.png b/art/screen2.png
new file mode 100644
index 0000000..1d81ed0
Binary files /dev/null and b/art/screen2.png differ
diff --git a/art/screen3.png b/art/screen3.png
new file mode 100644
index 0000000..48ff85c
Binary files /dev/null and b/art/screen3.png differ
diff --git a/art/screens.psd b/art/screens.psd
new file mode 100644
index 0000000..ec46f5d
Binary files /dev/null and b/art/screens.psd differ
diff --git a/ic_button_help-web.png b/ic_button_help-web.png
new file mode 100644
index 0000000..635fb6a
Binary files /dev/null and b/ic_button_help-web.png differ
diff --git a/ic_launcher-web.png b/ic_launcher-web.png
new file mode 100644
index 0000000..c37372a
Binary files /dev/null and b/ic_launcher-web.png differ
diff --git a/lint.xml b/lint.xml
new file mode 100644
index 0000000..ee0eead
--- /dev/null
+++ b/lint.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/proguard-project.txt b/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/project.properties b/project.properties
new file mode 100644
index 0000000..2cab5fb
--- /dev/null
+++ b/project.properties
@@ -0,0 +1,14 @@
+# 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 edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-4
diff --git a/res/drawable-hdpi/ic_action_search.png b/res/drawable-hdpi/ic_action_search.png
new file mode 100644
index 0000000..67de12d
Binary files /dev/null and b/res/drawable-hdpi/ic_action_search.png differ
diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..33255bc
Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ
diff --git a/res/drawable-hdpi/ic_menu_close_clear_cancel.png b/res/drawable-hdpi/ic_menu_close_clear_cancel.png
new file mode 100644
index 0000000..778c7f0
Binary files /dev/null and b/res/drawable-hdpi/ic_menu_close_clear_cancel.png differ
diff --git a/res/drawable-hdpi/ic_menu_info_details.png b/res/drawable-hdpi/ic_menu_info_details.png
new file mode 100644
index 0000000..6a7a1e9
Binary files /dev/null and b/res/drawable-hdpi/ic_menu_info_details.png differ
diff --git a/res/drawable-hdpi/ic_menu_recent_history.png b/res/drawable-hdpi/ic_menu_recent_history.png
new file mode 100644
index 0000000..4101434
Binary files /dev/null and b/res/drawable-hdpi/ic_menu_recent_history.png differ
diff --git a/res/drawable-ldpi/ic_launcher.png b/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 0000000..e004aa7
Binary files /dev/null and b/res/drawable-ldpi/ic_launcher.png differ
diff --git a/res/drawable-ldpi/ic_menu_close_clear_cancel.png b/res/drawable-ldpi/ic_menu_close_clear_cancel.png
new file mode 100644
index 0000000..760b925
Binary files /dev/null and b/res/drawable-ldpi/ic_menu_close_clear_cancel.png differ
diff --git a/res/drawable-ldpi/ic_menu_info_details.png b/res/drawable-ldpi/ic_menu_info_details.png
new file mode 100644
index 0000000..55c57d5
Binary files /dev/null and b/res/drawable-ldpi/ic_menu_info_details.png differ
diff --git a/res/drawable-ldpi/ic_menu_recent_history.png b/res/drawable-ldpi/ic_menu_recent_history.png
new file mode 100644
index 0000000..c75f6e3
Binary files /dev/null and b/res/drawable-ldpi/ic_menu_recent_history.png differ
diff --git a/res/drawable-mdpi/ic_action_search.png b/res/drawable-mdpi/ic_action_search.png
new file mode 100644
index 0000000..134d549
Binary files /dev/null and b/res/drawable-mdpi/ic_action_search.png differ
diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..b3de742
Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ
diff --git a/res/drawable-mdpi/ic_menu_close_clear_cancel.png b/res/drawable-mdpi/ic_menu_close_clear_cancel.png
new file mode 100644
index 0000000..1161a7c
Binary files /dev/null and b/res/drawable-mdpi/ic_menu_close_clear_cancel.png differ
diff --git a/res/drawable-mdpi/ic_menu_info_details.png b/res/drawable-mdpi/ic_menu_info_details.png
new file mode 100644
index 0000000..18b15b5
Binary files /dev/null and b/res/drawable-mdpi/ic_menu_info_details.png differ
diff --git a/res/drawable-mdpi/ic_menu_recent_history.png b/res/drawable-mdpi/ic_menu_recent_history.png
new file mode 100644
index 0000000..e5f8e2d
Binary files /dev/null and b/res/drawable-mdpi/ic_menu_recent_history.png differ
diff --git a/res/drawable-xhdpi/ic_action_search.png b/res/drawable-xhdpi/ic_action_search.png
new file mode 100644
index 0000000..d699c6b
Binary files /dev/null and b/res/drawable-xhdpi/ic_action_search.png differ
diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..fc8724e
Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/res/drawable-xhdpi/ic_menu_close_clear_cancel.png b/res/drawable-xhdpi/ic_menu_close_clear_cancel.png
new file mode 100644
index 0000000..d743d75
Binary files /dev/null and b/res/drawable-xhdpi/ic_menu_close_clear_cancel.png differ
diff --git a/res/drawable-xhdpi/ic_menu_info_details.png b/res/drawable-xhdpi/ic_menu_info_details.png
new file mode 100644
index 0000000..24ea543
Binary files /dev/null and b/res/drawable-xhdpi/ic_menu_info_details.png differ
diff --git a/res/drawable-xhdpi/ic_menu_recent_history.png b/res/drawable-xhdpi/ic_menu_recent_history.png
new file mode 100644
index 0000000..fc5e1fc
Binary files /dev/null and b/res/drawable-xhdpi/ic_menu_recent_history.png differ
diff --git a/res/layout/activity_dices.xml b/res/layout/activity_dices.xml
new file mode 100644
index 0000000..6493d50
--- /dev/null
+++ b/res/layout/activity_dices.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_history.xml b/res/layout/activity_history.xml
new file mode 100644
index 0000000..82fc27b
--- /dev/null
+++ b/res/layout/activity_history.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml
new file mode 100644
index 0000000..17ce9d3
--- /dev/null
+++ b/res/layout/activity_main.xml
@@ -0,0 +1,197 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/template_dices_item.xml b/res/layout/template_dices_item.xml
new file mode 100644
index 0000000..baa3a2b
--- /dev/null
+++ b/res/layout/template_dices_item.xml
@@ -0,0 +1,5 @@
+
+
diff --git a/res/layout/template_history_item.xml b/res/layout/template_history_item.xml
new file mode 100644
index 0000000..5bce29d
--- /dev/null
+++ b/res/layout/template_history_item.xml
@@ -0,0 +1,7 @@
+
+
diff --git a/res/menu/main_menu.xml b/res/menu/main_menu.xml
new file mode 100644
index 0000000..451fb9e
--- /dev/null
+++ b/res/menu/main_menu.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..6e04814
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,30 @@
+
+
+ Dice Generator
+ Hello world!
+ Settings
+ Dice Generator
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 0
+ d
+ ←
+ roll
+ list
+ Rolls history
+ Dices
+ history
+ clear
+ H
+ C
+ back
+ "icystar.com"
+ "http://icystar.com"
+
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
new file mode 100644
index 0000000..a356eea
--- /dev/null
+++ b/res/values/styles.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/icystar/dicegenerator/DicesActivity.java b/src/com/icystar/dicegenerator/DicesActivity.java
new file mode 100644
index 0000000..79d7e5a
--- /dev/null
+++ b/src/com/icystar/dicegenerator/DicesActivity.java
@@ -0,0 +1,35 @@
+package com.icystar.dicegenerator;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+
+public class DicesActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_dices);
+ int index = getIntent().getExtras().getInt("index");
+
+ TextView textView = (TextView)findViewById(R.id.textView1);
+ FlowLayout layout = (FlowLayout)findViewById(R.id.FlowLayout1);
+ synchronized (MainActivity.drops) {
+ if (index >= 0 && index < MainActivity.drops.size()) {
+ MainActivity.Drop drop = MainActivity.drops.get( index );
+ textView.setText(drop.toString(true));
+ for(int dice : drop.dices) {
+ TextView tv = (TextView)getLayoutInflater().inflate(R.layout.template_dices_item, null);
+ tv.setText(Integer.toString(dice));
+ layout.addView(tv);
+ }
+ }
+ }
+ }
+
+ public void onTapScreen(View view) {
+ finish();
+ }
+
+}
diff --git a/src/com/icystar/dicegenerator/FlowLayout.java b/src/com/icystar/dicegenerator/FlowLayout.java
new file mode 100644
index 0000000..ce79cb6
--- /dev/null
+++ b/src/com/icystar/dicegenerator/FlowLayout.java
@@ -0,0 +1,133 @@
+package com.icystar.dicegenerator;
+
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * Left-to-right, then top-to-bottom, layout.
+ *
+ * This layout positions its components similarly to writing text on a (Western)
+ * page. It goes left to right up to a given width, then wraps to the start of
+ * the next line down, and continues. The children get as much space as they ask
+ * for.
+ *
+ * This layout does not know about justification, and does not put space between
+ * children.
+ *
+ * WARNING: This is not a complete, robust class. For example, there's no
+ * concurrency protection. Also, more methods should be overridden, especially
+ * the other addView methods.
+ */
+public class FlowLayout extends ViewGroup {
+ public FlowLayout(Context context) {
+ super(context);
+ }
+
+ public FlowLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Holds all component views, in order.
+ */
+ private final ArrayList childViews = new ArrayList();
+ /**
+ * Holds layout bounds for corresponding child views. This is set in
+ * {@link #onMeasure}, and used in {@link #onLayout}.
+ */
+ private final ArrayList childPositions = new ArrayList();
+
+ /**
+ * Adds a child view to the end of the list of children. Currently 31jan12,
+ * this is the only addView method that should be called.
+ */
+ @Override
+ public void addView(View child) {
+ super.addView(child); // Necessary for event propagation, perhaps other
+ // framework stuff.
+ childViews.add(child);
+ childPositions.add(new Rect());
+ }
+
+ @Override
+ public void removeAllViews() {
+ childViews.clear();
+ childPositions.clear();
+ super.removeAllViews();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // //// Extract incoming constraints
+ int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); // This is
+ // our
+ // line-length
+ // limit.
+ int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ //int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
+ // //// Measure child views
+ int childWidthMode = widthMode == MeasureSpec.EXACTLY ? MeasureSpec.AT_MOST
+ : widthMode;
+ int childHeightMode = heightMode == MeasureSpec.EXACTLY ? MeasureSpec.AT_MOST
+ : heightMode;
+ int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthMode,
+ widthMode);
+ int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
+ childHeightMode, heightMode);
+ for (View childView : childViews) {
+ childView.measure(childWidthMeasureSpec, childHeightMeasureSpec);
+ }
+ // //// Position each child
+ int acrossPosition = 0; // Rightmost edge of last view on this line.
+ int lineTop = 0; // Bottom edge of previous line.
+ int lineHeight = 0; // Bottom edge of this line, so far.
+ int childCount = childViews.size();
+ for (int i = 0; i < childCount; i++) {
+ // //// Get required info
+ View childView = childViews.get(i);
+ Rect childPosition = childPositions.get(i);
+ int childWidth = childView.getMeasuredWidth();
+ int childHeight = childView.getMeasuredHeight();
+ // //// Perhaps start new line
+ if (acrossPosition + childWidth > widthSpecSize) {
+ // Have filled line, start a new one.
+ acrossPosition = 0;
+ lineTop += lineHeight;
+ lineHeight = 0;
+ }
+ // //// Place this child, and update progress variables.
+ int right = acrossPosition + childWidth;
+ childPosition.set(acrossPosition, lineTop, right, lineTop
+ + childHeight);
+ acrossPosition = right;
+ if (childHeight > lineHeight)
+ lineHeight = childHeight;
+ }
+ // //// Set the WritingLayout's measurements.
+ int pageHeight = lineTop + lineHeight;
+ this.setMeasuredDimension(widthSpecSize, pageHeight);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ // Don't know exactly what the 'changed' argument means.
+ int childCount = childViews.size();
+ for (int i = 0; i < childCount; i++) {
+ View childView = childViews.get(i);
+ Rect childPosition = childPositions.get(i);
+ childView.layout(childPosition.left, childPosition.top,
+ childPosition.right, childPosition.bottom);
+ }
+ }
+
+}
diff --git a/src/com/icystar/dicegenerator/HistoryActivity.java b/src/com/icystar/dicegenerator/HistoryActivity.java
new file mode 100644
index 0000000..8815b9a
--- /dev/null
+++ b/src/com/icystar/dicegenerator/HistoryActivity.java
@@ -0,0 +1,78 @@
+package com.icystar.dicegenerator;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import com.icystar.dicegenerator.MainActivity.Mode;
+
+public class HistoryActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_history);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ FlowLayout layout = (FlowLayout)findViewById(R.id.FlowLayout1);
+ layout.removeAllViews();
+
+ synchronized (MainActivity.drops) {
+ for(MainActivity.Drop drop : MainActivity.drops) {
+ if (drop.mode == Mode.SHOW_RESULT) {
+ TextView textView = (TextView)getLayoutInflater().inflate(R.layout.template_history_item, null);
+ textView.setText(drop.toString());
+ layout.addView(textView);
+ }
+ }
+ }
+
+ final ScrollView scrollView = (ScrollView)findViewById(R.id.ScrollView1);
+ final ResizerFrameLayout resizerFrameLayout = (ResizerFrameLayout)findViewById(R.id.ResizerFrameLayout1);
+ resizerFrameLayout.appliedWidth = 0;
+ resizerFrameLayout.appliedHeight = 0;
+ resizerFrameLayout.afterLayout.push(new Runnable() {
+ @Override
+ public void run() {
+ scrollView.post(new Runnable() {
+ @Override
+ public void run() {
+ scrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ }
+ });
+ resizerFrameLayout.requestLayout();
+ }
+
+ public void onText(View view) {
+ FlowLayout layout = (FlowLayout)findViewById(R.id.FlowLayout1);
+ for(int i = 0; i < layout.getChildCount(); i++) {
+ if (layout.getChildAt(i) == view) {
+ Intent intent = new Intent(this, DicesActivity.class);
+ intent.putExtra("index", i);
+ startActivity(intent);
+ break;
+ }
+ }
+ }
+
+ public void onButtonClear(View view) {
+ synchronized (MainActivity.drops) {
+ while(MainActivity.drops.size() > 1)
+ MainActivity.drops.remove(0);
+ }
+ onResume();
+ }
+
+ public void onButtonBack(View view) {
+ finish();
+ }
+
+}
diff --git a/src/com/icystar/dicegenerator/MainActivity.java b/src/com/icystar/dicegenerator/MainActivity.java
new file mode 100644
index 0000000..fff0f5a
--- /dev/null
+++ b/src/com/icystar/dicegenerator/MainActivity.java
@@ -0,0 +1,223 @@
+package com.icystar.dicegenerator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+ public static final int MAX_COUNT_ORDER = 100;
+ public static final int MAX_DICE_ORDER = 100;
+
+ public enum Mode {
+ ENTER_COUNT,
+ ENTER_DICEMAX,
+ SHOW_RESULT
+ }
+
+ public static class Drop {
+ public Mode mode = Mode.ENTER_COUNT;
+ public int count = 0;
+ public int diceMax = 0;
+ public int[] dices = new int[0];
+ public int summ = 0;
+
+ public final static String template = "000d000 → 000000 …";
+ public final static String diceTemplate = "000";
+
+ public String toString(boolean small) {
+ String text = "";
+ switch(mode) {
+ case SHOW_RESULT:
+ if (!small) text = " " + Arrays.toString(dices) + text;
+ text = " → " + Integer.toString(summ) + text;
+ case ENTER_DICEMAX:
+ text = "d" + Integer.toString(diceMax) + text;
+ case ENTER_COUNT:
+ text = Integer.toString(count) + text;
+ }
+ return text;
+ }
+
+ @Override
+ public String toString() {
+ return toString(false);
+ }
+ }
+
+ public static Random random = new Random();
+ public static List drops = new ArrayList(Arrays.asList((new Drop[]{new Drop()})));
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ synchronized(drops) {
+ updateText();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.main_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.item1:
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse(getString(R.string.aboutUri)));
+ startActivity(intent);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ private void resetDices() {
+ drops.add(new Drop());
+ }
+
+ private void resetDices(Drop drop) {
+ Drop newdrop = new Drop();
+ newdrop.count = drop.count;
+ newdrop.diceMax = drop.diceMax;
+ newdrop.dices = new int[newdrop.count];
+ newdrop.summ = 0;
+ drops.add(newdrop);
+ }
+
+ private Drop getCurrent() {
+ return drops.get(drops.size()-1);
+ }
+
+ private void dropDices() {
+ Drop drop = getCurrent();
+
+ drop.dices = new int[drop.count];
+ drop.summ = 0;
+ for(int i = 0; i < drop.count; i++)
+ drop.summ += drop.dices[i] = random.nextInt(drop.diceMax) + 1;
+ }
+
+ private void updateText() {
+ Drop drop = getCurrent();
+ TextView textView = (TextView)findViewById(R.id.textView1);
+ textView.setText(drop.toString());
+ }
+
+ public void onButton(View view) {
+ synchronized (drops) {
+ Drop drop = getCurrent();
+ int numButton = -1;
+ boolean backspaceButton = false;
+ boolean diceButton = false;
+ boolean rollButton = false;
+ boolean historyButton = false;
+
+ switch(view.getId()) {
+ case R.id.button1: numButton = 1; break;
+ case R.id.button2: numButton = 2; break;
+ case R.id.button3: numButton = 3; break;
+ case R.id.button4: numButton = 4; break;
+ case R.id.button5: numButton = 5; break;
+ case R.id.button6: numButton = 6; break;
+ case R.id.button7: numButton = 7; break;
+ case R.id.button8: numButton = 8; break;
+ case R.id.button9: numButton = 9; break;
+ case R.id.button10: numButton = 0; break;
+ case R.id.buttonBackspace: backspaceButton = true; break;
+ case R.id.buttonHistory: historyButton = true; break;
+ case R.id.buttonDice: diceButton = true; break;
+ case R.id.buttonRoll: rollButton = true; break;
+ }
+
+ if (historyButton) {
+ startActivity(new Intent(this, HistoryActivity.class));
+ } else {
+ switch(drop.mode) {
+ case ENTER_COUNT:
+ if (numButton >= 0) {
+ if (drop.count < MAX_COUNT_ORDER)
+ drop.count = drop.count*10 + numButton;
+ } else
+ if (backspaceButton) {
+ drop.count = 0;
+ } else
+ if (diceButton) {
+ if (drop.count == 0) drop.count = 1;
+ drop.mode = Mode.ENTER_DICEMAX;
+ } else
+ if (rollButton) {
+ if (drop.count == 0) drop.count = 1;
+ if (drop.diceMax == 0) drop.diceMax = 6;
+ dropDices();
+ drop.mode = Mode.SHOW_RESULT;
+ }
+ break;
+ case ENTER_DICEMAX:
+ if (numButton >= 0) {
+ if (drop.diceMax < MAX_DICE_ORDER)
+ drop.diceMax = drop.diceMax*10 + numButton;
+ } else
+ if (backspaceButton) {
+ drop.count = 0;
+ drop.diceMax = 0;
+ drop.mode = Mode.ENTER_COUNT;
+ } else
+ if (diceButton) {
+ // do nothing
+ } else
+ if (rollButton) {
+ if (drop.diceMax <= 1) drop.diceMax = 6;
+ dropDices();
+ drop.mode = Mode.SHOW_RESULT;
+ }
+ break;
+ case SHOW_RESULT:
+ if (numButton >= 0) {
+ resetDices();
+ getCurrent().count = numButton;
+ } else
+ if (backspaceButton) {
+ resetDices();
+ } else
+ if (diceButton) {
+ resetDices();
+ getCurrent().count = 1;
+ getCurrent().mode = Mode.ENTER_DICEMAX;
+ } else
+ if (rollButton) {
+ resetDices(drop);
+ dropDices();
+ getCurrent().mode = Mode.SHOW_RESULT;
+ }
+ break;
+ }
+
+ updateText();
+ }
+ }
+ }
+
+ public void onText(View view) {
+ if (getCurrent().mode == Mode.SHOW_RESULT) {
+ Intent intent = new Intent(this, DicesActivity.class);
+ intent.putExtra("index", drops.size()-1);
+ startActivity(intent);
+ }
+ }
+
+}
diff --git a/src/com/icystar/dicegenerator/ResizerFrameLayout.java b/src/com/icystar/dicegenerator/ResizerFrameLayout.java
new file mode 100644
index 0000000..297a3de
--- /dev/null
+++ b/src/com/icystar/dicegenerator/ResizerFrameLayout.java
@@ -0,0 +1,191 @@
+package com.icystar.dicegenerator;
+
+import java.util.Stack;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.text.TextPaint;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.ImageButton;
+import android.widget.ImageView.ScaleType;
+import android.widget.TextView;
+
+import com.icystar.dicegenerator.MainActivity.Drop;
+
+public class ResizerFrameLayout extends FrameLayout {
+
+ public static class Measures {
+ public Typeface typeface;
+ public float indicatorFontSize;
+ public float numberFontSize;
+ public float buttonFontSize;
+ public int indicatorButtonSize;
+ public int historyItemWidth;
+ public int dicesItemWidth;
+ public int padding;
+
+ public float fitText(String text, TextPaint textPaint, int w, int h) {
+ float max = 100.f;
+ float min = 2.f;
+ float precision = 0.5f;
+
+ while (max - min > precision) {
+ float current = (max + min)/2.f;
+ textPaint.setTextSize(current);
+ Rect bounds = new Rect();
+ textPaint.getTextBounds(text, 0, text.length(), bounds);
+ int tw = Math.max(bounds.right, 0) - Math.min(bounds.left, 0);
+ int th = Math.max(bounds.bottom, 0) - Math.min(bounds.top, 0);
+ if (tw >= w || th >= h)
+ max = current;
+ else
+ min = current;
+ }
+
+ return min;
+ }
+
+ public float widthOfText(String text, TextPaint textPaint, float size) {
+ textPaint.setTextSize(size);
+ Rect bounds = new Rect();
+ textPaint.getTextBounds(text, 0, text.length(), bounds);
+ return Math.max(bounds.right, 0) - Math.min(bounds.left, 0);
+ }
+
+ public Measures(int width, int height, TextPaint textPaint) {
+ typeface = textPaint.getTypeface();
+
+ padding = width/40;
+ indicatorButtonSize = Math.min(width/6, height/5);
+
+ int indicatorWidth = width - indicatorButtonSize*2;
+ if (width > height && indicatorWidth > width/2) indicatorWidth = width/2;
+ int indicatorTextWidth = indicatorWidth - padding*2;
+ indicatorFontSize = fitText(Drop.template, textPaint, indicatorTextWidth, indicatorButtonSize/3);
+
+ int buttonWidth = Math.round((float)width/3.f/1.5f);
+ int buttonHeight = Math.round((float)(height-indicatorButtonSize)/4.f/3.f);
+ numberFontSize = fitText("0", textPaint, buttonWidth, buttonHeight);
+ buttonFontSize = fitText("Mmmm", textPaint, buttonWidth, buttonHeight);
+
+ historyItemWidth = Math.round(widthOfText(Drop.template, textPaint, indicatorFontSize)) + 1 + padding*2;
+ historyItemWidth = historyItemWidth > width ? width : width / (width/historyItemWidth) - 1;
+ dicesItemWidth = Math.round(widthOfText(Drop.diceTemplate, textPaint, indicatorFontSize)) + 1 + padding*3;
+ }
+ }
+
+ public int appliedWidth = 0;
+ public int appliedHeight = 0;
+ public boolean needLayout = false;
+ public TextPaint textPaint;
+ public Stack afterLayout = new Stack();
+ public Runnable requestLayoutPost;
+
+ public ResizerFrameLayout(Context context) {
+ super(context);
+ initialize();
+ }
+
+ public ResizerFrameLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initialize();
+ }
+
+ public ResizerFrameLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ initialize();
+ }
+
+ void initialize() {
+ requestLayoutPost = new Runnable() {
+ @Override
+ public void run() {
+ requestLayout();
+ }
+ };
+ TextView textView = new TextView(getContext());
+ textPaint = new TextPaint(textView.getPaint());
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+
+ int w = right - left;
+ int h = bottom - top;
+ if (!isInEditMode() && (appliedWidth != w || appliedHeight != h)) {
+ appliedWidth = w;
+ appliedHeight = h;
+ setMeasures(this, new Measures(appliedWidth, appliedHeight, textPaint));
+
+ if (!isInEditMode()) post(requestLayoutPost);
+ } else {
+ if (!isInEditMode())
+ while (afterLayout.size() > 0)
+ post(afterLayout.pop());
+ }
+ }
+
+ void setMeasures(View view, Measures measures) {
+ String tag = view.getTag() == null ? "" : view.getTag().toString();
+
+ if (view instanceof ImageButton) {
+ ImageButton imageButton = (ImageButton)view;
+ imageButton.setMaxHeight(measures.indicatorButtonSize);
+ imageButton.setMaxWidth(measures.indicatorButtonSize);
+ imageButton.setMinimumWidth(measures.indicatorButtonSize);
+ imageButton.setMinimumHeight(measures.indicatorButtonSize);
+ imageButton.setScaleType(ScaleType.CENTER_INSIDE);
+ ViewGroup.LayoutParams layoutParams = imageButton.getLayoutParams();
+ layoutParams.width = measures.indicatorButtonSize;
+ layoutParams.height = measures.indicatorButtonSize;
+ imageButton.setLayoutParams(layoutParams);
+ } else
+ if (view instanceof Button) {
+ Button button = (Button)view;
+ button.setTypeface(measures.typeface);
+ if (tag.compareTo("historyActivityButton") == 0) {
+ button.setTextSize(TypedValue.COMPLEX_UNIT_PX, measures.indicatorFontSize);
+ } else
+ if (button.getText().length() == 1)
+ button.setTextSize(TypedValue.COMPLEX_UNIT_PX, measures.numberFontSize);
+ else
+ button.setTextSize(TypedValue.COMPLEX_UNIT_PX, measures.buttonFontSize);
+ } else
+ if (view instanceof TextView) {
+ TextView textView = (TextView)view;
+ if (tag.compareTo("indicator") == 0) {
+ textView.setMaxHeight(measures.indicatorButtonSize);
+ textView.setMinHeight(measures.indicatorButtonSize);
+ textView.setHeight(measures.indicatorButtonSize);
+ textView.setLineSpacing(0.f, 100.f);
+ } else
+ if (tag.compareTo("historyItem") == 0) {
+ textView.setMaxWidth(measures.historyItemWidth);
+ textView.setMinWidth(measures.historyItemWidth);
+ textView.setWidth(measures.historyItemWidth);
+ } else
+ if (tag.compareTo("dicesItem") == 0) {
+ textView.setMaxWidth(measures.dicesItemWidth);
+ textView.setMinWidth(measures.dicesItemWidth);
+ textView.setWidth(measures.dicesItemWidth);
+ }
+
+ textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, measures.indicatorFontSize);
+ textView.setPadding(measures.padding, 0, measures.padding, 0);
+ textView.setTypeface(measures.typeface);
+ textView.requestLayout();
+ } else
+ if (view instanceof ViewGroup) {
+ ViewGroup viewGroup = (ViewGroup)view;
+ for(int i = 0; i < viewGroup.getChildCount(); i++)
+ setMeasures(viewGroup.getChildAt(i), measures);
+ }
+ }
+}