Android: add support for extracting RotateDrawable

The rotation attributes are required for implementing BusyIndicator.

Task-number: QTBUG-39215
Change-Id: Ief51bf921f61b3b030f26d377b4bfd13913af6c1
Reviewed-by: BogDan Vatra <bogdan@kde.org>
bb10
J-P Nurmi 2014-05-23 12:04:31 +02:00 committed by The Qt Project
parent 0c789184c7
commit 3c04a2fbff
1 changed files with 38 additions and 0 deletions

View File

@ -74,6 +74,7 @@ import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.NinePatchDrawable;
import android.graphics.drawable.RotateDrawable;
import android.graphics.drawable.ScaleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
@ -610,6 +611,39 @@ public class ExtractStyle {
return json;
}
private JSONObject getRotateDrawable(RotateDrawable drawable, String filename) {
JSONObject json = new JSONObject();
try {
json.put("type", "rotate");
Object obj = drawable.getConstantState();
Class<?> rotateStateClass = obj.getClass();
Field f = rotateStateClass.getDeclaredField("mDrawable");
f.setAccessible(true);
json.put("drawable", getDrawable(f.get(obj), filename));
f = rotateStateClass.getDeclaredField("mPivotX");
f.setAccessible(true);
json.put("pivotX", f.getFloat(obj));
f = rotateStateClass.getDeclaredField("mPivotXRel");
f.setAccessible(true);
json.put("pivotXRel", f.getBoolean(obj));
f = rotateStateClass.getDeclaredField("mPivotY");
f.setAccessible(true);
json.put("pivotY", f.getFloat(obj));
f = rotateStateClass.getDeclaredField("mPivotYRel");
f.setAccessible(true);
json.put("pivotYRel", f.getBoolean(obj));
f = rotateStateClass.getDeclaredField("mFromDegrees");
f.setAccessible(true);
json.put("fromDegrees", f.getFloat(obj));
f = rotateStateClass.getDeclaredField("mToDegrees");
f.setAccessible(true);
json.put("toDegrees", f.getFloat(obj));
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
private JSONObject getJsonRect(Rect rect) throws JSONException
{
JSONObject jsonRect = new JSONObject();
@ -695,6 +729,10 @@ public class ExtractStyle {
{
return getGradientDrawable((GradientDrawable) drawable);
}
if (drawable instanceof RotateDrawable)
{
return getRotateDrawable((RotateDrawable) drawable, filename);
}
if (drawable instanceof ClipDrawable)
{
try {