diff --git a/calculatorpp/AndroidManifest.xml b/calculatorpp/AndroidManifest.xml
index 990f129a..96e8dccc 100644
--- a/calculatorpp/AndroidManifest.xml
+++ b/calculatorpp/AndroidManifest.xml
@@ -6,7 +6,10 @@
-
+
+
+
+
@@ -125,8 +128,8 @@
-
-
+
+
diff --git a/calculatorpp/misc/other/prepare_avds.sh b/calculatorpp/misc/other/prepare_avds.sh
new file mode 100755
index 00000000..3ef46858
--- /dev/null
+++ b/calculatorpp/misc/other/prepare_avds.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+
+declare -a skins=("WVGA854" "WQVGA400" "HVGA" "WQVGA432" "WVGA800" "QVGA")
+declare -a targets=("android-16")
+
+for target in ${targets[@]}
+do
+ for skin in ${skins[@]}
+ do
+ $ANDROID_HOME/tools/android -s create avd -n AVD_$skin -t $target -b x86 -s $skin --force
+ done
+done
+
+for target in ${targets[@]}
+do
+ for skin in ${skins[@]}
+ do
+ avdDeviceName=AVD_$skin
+ $ANDROID_HOME/tools/emulator -avd $avdDeviceName &
+ $ANDROID_HOME/tools/monkeyrunner ./wait_device.py
+ $ANDROID_HOME/platform-tools/adb -s emulator-5554 emu kill
+ done
+done
+
+
diff --git a/calculatorpp/misc/other/remove_avds.sh b/calculatorpp/misc/other/remove_avds.sh
new file mode 100755
index 00000000..68395351
--- /dev/null
+++ b/calculatorpp/misc/other/remove_avds.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+
+declare -a skins=("WVGA854" "WQVGA400" "HVGA" "WQVGA432" "WVGA800" "QVGA")
+declare -a targets=("android-16")
+
+for target in ${targets[@]}
+do
+ for skin in ${skins[@]}
+ do
+ $ANDROID_HOME/tools/android -s delete avd -n AVD_$skin
+ done
+done
+
+
diff --git a/calculatorpp/misc/other/take_screenshots.py b/calculatorpp/misc/other/take_screenshots.py
new file mode 100644
index 00000000..bdcebbb9
--- /dev/null
+++ b/calculatorpp/misc/other/take_screenshots.py
@@ -0,0 +1,58 @@
+from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
+import time
+
+import sys
+
+outFolder = sys.argv[1]
+outFilename = sys.argv[2]
+
+print ''
+print 'Screenshot will be located in ' + outFolder + ' with name ' + outFilename;
+
+apk = '/home/serso/projects/java/android/calculatorpp/calculatorpp/target/calculatorpp-1.5.2-SNAPSHOT.apk'
+package = 'org.solovyev.android.calculator'
+activity = 'org.solovyev.android.calculator.CalculatorActivity'
+deviceName = 'emulator-5554'
+
+def takeScreenshot (folder, filename):
+ screenshot = device.takeSnapshot()
+ screenshot.writeToFile(folder + '/' + filename + '.png','png')
+ return
+
+print 'Waiting for device ' + deviceName + '...'
+device = MonkeyRunner.waitForConnection(30, deviceName)
+
+if device:
+ # unlock device
+ device.wake()
+ device.drag((130, 620), (500, 620), 1.0, 120)
+
+ print 'Device found, removing application if any ' + package + '...'
+ device.removePackage(package)
+
+ print 'Installing apk ' + apk + '...'
+ device.installPackage(apk)
+
+ runComponent = package + '/' + activity
+
+ print 'Starting activity ' + runComponent + '...'
+ device.startActivity(component=runComponent)
+
+ # close all dialogs
+ device.shell('input keyevent 4')
+
+ # sleep while application will be loaded
+ MonkeyRunner.sleep(2);
+
+ print 'Taking screenshot...'
+ takeScreenshot(outFolder, outFilename + '_' + str(time.time()) );
+
+ print 'Changing orientation...'
+
+ print '#########'
+ print 'Finished!'
+ print '#########'
+else:
+ print '#########'
+ print 'Failure!'
+ print '#########'
diff --git a/calculatorpp/misc/other/take_screenshots.sh b/calculatorpp/misc/other/take_screenshots.sh
new file mode 100755
index 00000000..e5edcb49
--- /dev/null
+++ b/calculatorpp/misc/other/take_screenshots.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+declare -a skins=("WVGA854" "WQVGA400" "HVGA" "WQVGA432" "WVGA800" "QVGA")
+declare -a targets=("android-16")
+
+for target in ${targets[@]}
+do
+ for skin in ${skins[@]}
+ do
+ avdDeviceName=AVD_$skin
+ $ANDROID_HOME/tools/emulator -avd $avdDeviceName &
+ $ANDROID_HOME/tools/monkeyrunner ./take_screenshots.py ~/projects/java/android/calculatorpp/calculatorpp/misc/aux/tmp $avdDeviceName
+ $ANDROID_HOME/platform-tools/adb -s emulator-5554 emu kill
+ done
+done
\ No newline at end of file
diff --git a/calculatorpp/misc/other/take_screenshots2.sh b/calculatorpp/misc/other/take_screenshots2.sh
new file mode 100755
index 00000000..b2bbb8e2
--- /dev/null
+++ b/calculatorpp/misc/other/take_screenshots2.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# "AVD_4.1_x86_6" "AVD_4.0.3_x86" "AVD_4.1_x86" "Default" "AVD_4.0.3_x86_7" "AVD_4.1_x86_7" "AVD_4.1_x86_9.5" "Galaxy_Tab" "AVD_4.1_x86_4"
+# "AVD_4.1_x86_6" "AVD_4.1_x86_7" "AVD_4.1_x86_9.5" "AVD_4.1_x86_4"
+
+declare -a names=("AVD_4.1_x86_4")
+
+for name in ${names[@]}
+do
+ $ANDROID_HOME/tools/emulator -avd $name &
+ $ANDROID_HOME/tools/monkeyrunner ./take_screenshots.py ~/projects/java/android/calculatorpp/calculatorpp/misc/aux/tmp $name
+ $ANDROID_HOME/platform-tools/adb -s emulator-5554 emu kill
+done
\ No newline at end of file
diff --git a/calculatorpp/misc/other/wait_device.py b/calculatorpp/misc/other/wait_device.py
new file mode 100644
index 00000000..38b8f73e
--- /dev/null
+++ b/calculatorpp/misc/other/wait_device.py
@@ -0,0 +1,10 @@
+from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
+
+print 'Waiting for device...'
+device = MonkeyRunner.waitForConnection(100, 'emulator-5554')
+print 'Finished'
+if device :
+ print 'Success'
+else :
+ print 'Failure'
+
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
index 3b09241b..c2131f4a 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
@@ -1,7 +1,12 @@
package org.solovyev.android.calculator;
+import android.*;
+import android.Manifest;
import android.app.Activity;
+import android.app.KeyguardManager;
+import android.content.Context;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -60,6 +65,14 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
+
+ // let's disable locking of screen for monkeyrunner
+ // NOTE: this code is only for monkeyrunner
+ final String permission = Manifest.permission.DISABLE_KEYGUARD;
+ if (activity.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
+ final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
+ km.newKeyguardLock(activity.getClass().getName()).disableKeyguard();
+ }
}
public void logDebug(@NotNull String message) {
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
index 4ec0afc9..26da3639 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
@@ -13,6 +13,7 @@ import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
+import org.solovyev.android.calculator.widget.CalculatorWidgetHelper;
/**
* User: serso