Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolm Smith committed Jan 7, 2018
1 parent d614765 commit 67d0333
Show file tree
Hide file tree
Showing 29 changed files with 340 additions and 256 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
This file only records changes to the demo app. For changes to Chaquopy itself, see
https://chaquo.com/chaquopy/doc/current/changelog.html.

## 1.2.0 (2018-01-07)

* Provide separate icons for Python 2 and Python 3.
* Upgrade Python 2 version to 2.7.14.
* Fix font in API level 21.
* Make ConsoleActivity easier to reuse ([chaquopy-hello
#2](https://github.com/chaquo/chaquopy-hello/issues/2)).
* Don't paste formatting into Python console input box.
* Unit test cleanups and performance improvements.

## 1.1.0 (2017-12-22)

* Now available for Python 3 (search "Chaquopy Python 3" on Google Play).
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdkVersion 15
targetSdkVersion 23

def appVersion = "1.1.0"
def appVersion = "1.2.0"
versionName appVersion
def verParsed = appVersion.split(/\./).collect { Integer.parseInt(it) }
versionCode ((verParsed[0] * 1000000) + (verParsed[1] * 1000) + (verParsed[2] * 10) + 1)
Expand Down Expand Up @@ -62,7 +62,7 @@ android {
py2 {
dimension "pyVersion"
applicationId "com.chaquo.python.demo"
python { version "2.7.10" }
python { version "2.7.14" }
}
py3 {
dimension "pyVersion"
Expand Down
203 changes: 107 additions & 96 deletions app/src/main/java/com/chaquo/python/TestBasics.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,61 @@ public boolean methodParamsZBCSIJFD(boolean x1, byte x2, char x3, short x4,
}

// === Instance ==========================================================
//
// Fields are all initialized to a value different from any value used in the tests.

public final boolean fieldFinalZ = false;
public boolean fieldZ;
public byte fieldB;
public char fieldC;
public short fieldS;
public int fieldI;
public long fieldJ;
public float fieldF;
public double fieldD;

public Object fieldObject;

public Number fieldNumber;
public Byte fieldByte;
public Short fieldShort;
public Integer fieldInteger;
public Long fieldLong;
public Float fieldFloat;
public Double fieldDouble;

public Boolean fieldBoolean;
public Character fieldCharacter;

public CharSequence fieldCharSequence;
public String fieldString;

public Class fieldKlass;

public boolean[] fieldZArray;
public byte[] fieldBArray;
public char[] fieldCArray;
public short[] fieldSArray;
public int[] fieldIArray;
public long[] fieldJArray;
public float[] fieldFArray;
public double[] fieldDArray;
public Object[] fieldObjectArray;
public Number[] fieldNumberArray;
public Byte[] fieldByteArray;
public Short[] fieldShortArray;
public Integer[] fieldIntegerArray;
public Long[] fieldLongArray;
public Float[] fieldFloatArray;
public Double[] fieldDoubleArray;
public Boolean[] fieldBooleanArray;
public Character[] fieldCharacterArray;
public CharSequence[] fieldCharSequenceArray;
public String[] fieldStringArray;
public Class[] fieldKlassArray;
public boolean fieldZ = false;
public byte fieldB = 42;
public char fieldC = 42;
public short fieldS = 42;
public int fieldI = 42;
public long fieldJ = 42;
public float fieldF = 42;
public double fieldD = 42;

public Object fieldObject = "42";

public Number fieldNumber = 42;
public Byte fieldByte = 42;
public Short fieldShort = 42;
public Integer fieldInteger = 42;
public Long fieldLong = 42L;
public Float fieldFloat = 42f;
public Double fieldDouble = 42d;
public Boolean fieldBoolean = false;
public Character fieldCharacter = 42;

public CharSequence fieldCharSequence = "42";
public String fieldString = "42";

public Class fieldKlass = TestBasics.class;

public boolean[] fieldZArray = {false, false};
public byte[] fieldBArray = {42};
public char[] fieldCArray = {42};
public short[] fieldSArray = {42};
public int[] fieldIArray = {42};
public long[] fieldJArray = {42};
public float[] fieldFArray = {42};
public double[] fieldDArray = {42};

public Object[] fieldObjectArray = {"42"};

public Number[] fieldNumberArray = {42};
public Byte[] fieldByteArray = {42};
public Short[] fieldShortArray = {42};
public Integer[] fieldIntegerArray = {42};
public Long[] fieldLongArray = {42L};
public Float[] fieldFloatArray = {42f};
public Double[] fieldDoubleArray = {42d};
public Boolean[] fieldBooleanArray = {false, false};
public Character[] fieldCharacterArray = {42};

public CharSequence[] fieldCharSequenceArray = {"42"};
public String[] fieldStringArray = {"42"};

public Class[] fieldKlassArray = {TestBasics.class};


public void noArgs() {}
Expand Down Expand Up @@ -408,57 +413,63 @@ public void setKlassArray(Class[] fieldKlassArray) {
this.fieldKlassArray = fieldKlassArray;
}


// === Static ============================================================
//
// Fields are all initialized to a value different from any value used in the tests.

public static final boolean fieldStaticFinalZ = false;
public static boolean fieldStaticZ;
public static byte fieldStaticB;
public static char fieldStaticC;
public static short fieldStaticS;
public static int fieldStaticI;
public static long fieldStaticJ;
public static float fieldStaticF;
public static double fieldStaticD;

public static Object fieldStaticObject;

public static Number fieldStaticNumber;
public static Byte fieldStaticByte;
public static Short fieldStaticShort;
public static Integer fieldStaticInteger;
public static Long fieldStaticLong;
public static Float fieldStaticFloat;
public static Double fieldStaticDouble;

public static Boolean fieldStaticBoolean;
public static Character fieldStaticCharacter;

public static CharSequence fieldStaticCharSequence;
public static String fieldStaticString;

public static Class fieldStaticKlass;

public static boolean[] fieldStaticZArray;
public static byte[] fieldStaticBArray;
public static char[] fieldStaticCArray;
public static short[] fieldStaticSArray;
public static int[] fieldStaticIArray;
public static long[] fieldStaticJArray;
public static float[] fieldStaticFArray;
public static double[] fieldStaticDArray;
public static Object[] fieldStaticObjectArray;
public static Number[] fieldStaticNumberArray;
public static Byte[] fieldStaticByteArray;
public static Short[] fieldStaticShortArray;
public static Integer[] fieldStaticIntegerArray;
public static Long[] fieldStaticLongArray;
public static Float[] fieldStaticFloatArray;
public static Double[] fieldStaticDoubleArray;
public static Boolean[] fieldStaticBooleanArray;
public static Character[] fieldStaticCharacterArray;
public static CharSequence[] fieldStaticCharSequenceArray;
public static String[] fieldStaticStringArray;
public static Class[] fieldStaticKlassArray;
public static boolean fieldStaticZ = false;
public static byte fieldStaticB = 42;
public static char fieldStaticC = 42;
public static short fieldStaticS = 42;
public static int fieldStaticI = 42;
public static long fieldStaticJ = 42;
public static float fieldStaticF = 42;
public static double fieldStaticD = 42;

public static Object fieldStaticObject = "42";

public static Number fieldStaticNumber = 42;
public static Byte fieldStaticByte = 42;
public static Short fieldStaticShort = 42;
public static Integer fieldStaticInteger = 42;
public static Long fieldStaticLong = 42L;
public static Float fieldStaticFloat = 42f;
public static Double fieldStaticDouble = 42d;
public static Boolean fieldStaticBoolean = false;
public static Character fieldStaticCharacter = 42;

public static CharSequence fieldStaticCharSequence = "42";
public static String fieldStaticString = "42";

public static Class fieldStaticKlass = TestBasics.class;

public static boolean[] fieldStaticZArray = {false, false};
public static byte[] fieldStaticBArray = {42};
public static char[] fieldStaticCArray = {42};
public static short[] fieldStaticSArray = {42};
public static int[] fieldStaticIArray = {42};
public static long[] fieldStaticJArray = {42};
public static float[] fieldStaticFArray = {42};
public static double[] fieldStaticDArray = {42};

public static Object[] fieldStaticObjectArray = {"42"};

public static Number[] fieldStaticNumberArray = {42};
public static Byte[] fieldStaticByteArray = {42};
public static Short[] fieldStaticShortArray = {42};
public static Integer[] fieldStaticIntegerArray = {42};
public static Long[] fieldStaticLongArray = {42L};
public static Float[] fieldStaticFloatArray = {42f};
public static Double[] fieldStaticDoubleArray = {42d};
public static Boolean[] fieldStaticBooleanArray = {false, false};
public static Character[] fieldStaticCharacterArray = {42};

public static CharSequence[] fieldStaticCharSequenceArray = {"42"};
public static String[] fieldStaticStringArray = {"42"};

public static Class[] fieldStaticKlassArray = {TestBasics.class};


public static void staticNoArgs() {}
Expand Down
38 changes: 28 additions & 10 deletions app/src/main/java/com/chaquo/python/TestOverload.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public String resolve_Short_L(long a) {
return "long " + a;
}

public String resolve_Integer_Long(Integer a) {
return "Integer " + a;
public String resolve_Short_Long(Short a) {
return "Short " + a;
}
public String resolve_Integer_Long(Long a) {
public String resolve_Short_Long(Long a) {
return "Long " + a;
}

Expand All @@ -155,22 +155,40 @@ public String resolve_Float_Double(Double a) {


public static class TestString {
public String resolve_String_C_Character(String a) {
public String resolve_C_Character(char a) {
return "char " + a;
}
public String resolve_C_Character(Character a) {
return "Character " + a;
}

public String resolve_C_String(char a) {
return "char " + a;
}
public String resolve_C_String(String a) {
return "String " + a;
}
public String resolve_String_C_Character(char a) {

public String resolve_C_Object(char a) {
return "char " + a;
}
public String resolve_String_C_Character(Character a) {
return "Character " + a;
public String resolve_C_Object(Object a) {
return "Object " + a;
}

public String resolve_Z_Character(boolean a) {
return "boolean " + a;
public String resolve_Character_String(Character a) {
return "Character " + a;
}
public String resolve_Z_Character(Character a) {
public String resolve_Character_String(String a) {
return "String " + a;
}

public String resolve_Character_Object(Character a) {
return "Character " + a;
}
public String resolve_Character_Object(Object a) {
return "Object " + a;
}
}


Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/chaquo/python/demo/ConsoleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.chaquo.python.*;
import java.util.*;

public class ConsoleActivity extends AppCompatActivity {
public abstract class ConsoleActivity extends AppCompatActivity {

protected Python py = Python.getInstance();
protected Python py;
protected ScrollView svBuffer;
protected TextView tvBuffer;

Expand All @@ -26,6 +26,7 @@ protected static class State {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
py = Python.getInstance();
svBuffer = (ScrollView) findViewById(R.id.svBuffer);
tvBuffer = (TextView) findViewById(R.id.tvBuffer);
if (Build.VERSION.SDK_INT >= 23) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/chaquo/python/demo/PythonTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ public class PythonTestActivity extends UnitTestActivity {

@Override
protected void runTests() {
Python python = Python.getInstance();
PyObject unittest = python.getModule("unittest");
PyObject suite = python.getModule("chaquopy.test");
PyObject stream = python.getModule("sys").get("stdout");
Python py = Python.getInstance();
PyObject unittest = py.getModule("unittest");
PyObject stream = py.getModule("sys").get("stdout"); // https://bugs.python.org/issue10786
PyObject runner = unittest.callAttr("TextTestRunner",
new Kwarg("stream", stream),
new Kwarg("verbosity", 2));
PyObject loader = unittest.get("defaultTestLoader");
runner.callAttr("run", loader.callAttr("loadTestsFromModule", suite));
PyObject suite = loader.callAttr("loadTestsFromModule", py.getModule("chaquopy.test"));
runner.callAttr("run", suite);
}

}
12 changes: 12 additions & 0 deletions app/src/main/java/com/chaquo/python/demo/ReplActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ protected void onCreate(Bundle savedInstanceState) {

etInput = (EditText) findViewById(R.id.etInput);
etInput.setHint(getPrompt());
etInput.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}

// Strip formatting from pasted text.
@Override
public void afterTextChanged(Editable e) {
for (CharacterStyle cs : e.getSpans(0, e.length(), CharacterStyle.class)) {
e.removeSpan(cs);
}
}
});
etInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.chaquo.python.*;

@SuppressWarnings("deprecation")
public class WrongExtends extends Exception implements StaticProxy {
public PyObject _chaquopyGetDict() { return null; }
public void _chaquopySetDict(PyObject dict) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.chaquo.python.*;

@SuppressWarnings("deprecation")
public class WrongLoadOrder implements StaticProxy {
public PyObject _chaquopyGetDict() { return null; }
public void _chaquopySetDict(PyObject dict) {}
Expand Down
Loading

0 comments on commit 67d0333

Please sign in to comment.