summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt5/android
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2020-09-29 11:48:04 +0300
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2020-10-03 11:22:35 +0300
commit1907599bfd817e00c7f42b8cb941ebf93a098e7f (patch)
tree643210622dc9ef0c218210453d7f8bd98aa60599 /src/android/jar/src/org/qtproject/qt5/android
parent4e675cb85e81b67f36473914f5822dd6e626ddf0 (diff)
Android: rename Android's package name for Qt 6
Rename Android package name org.qtproject.qt5.android to org.qtproject.qt.android to avoid inconsistency with Qt 6 name. Also, we include the major version number in the jar target. Task-number: QTBUG-86969 Change-Id: Ibb68947289be1079911b34ea157bf089cc52c47f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java221
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/EditContextView.java123
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/EditPopupMenu.java186
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java2036
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java1307
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtEditText.java110
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java272
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtLayout.java278
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java388
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNative.java1390
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNativeLibrariesDir.java60
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtServiceDelegate.java202
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtSurface.java121
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtThread.java112
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java422
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/accessibility/QtNativeAccessibility.java58
16 files changed, 0 insertions, 7286 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java
deleted file mode 100644
index 38cc695c37..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.util.DisplayMetrics;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.ImageView;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.view.MotionEvent;
-import android.widget.PopupWindow;
-import android.app.Activity;
-import android.util.TypedValue;
-import android.view.ViewTreeObserver;
-
-/* This view represents one of the handle (selection or cursor handle) */
-class CursorView extends ImageView
-{
- private CursorHandle mHandle;
- // The coordinare which where clicked
- private float m_offsetX;
- private float m_offsetY;
- private boolean m_pressed = false;
-
- CursorView (Context context, CursorHandle handle) {
- super(context);
- mHandle = handle;
- }
-
- // Called when the handle was moved programatically , with the delta amount in pixels
- public void adjusted(int dx, int dy) {
- m_offsetX += dx;
- m_offsetY += dy;
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- switch (ev.getActionMasked()) {
- case MotionEvent.ACTION_DOWN: {
- m_offsetX = ev.getRawX();
- m_offsetY = ev.getRawY() + getHeight() / 2;
- m_pressed = true;
- break;
- }
-
- case MotionEvent.ACTION_MOVE: {
- if (!m_pressed)
- return false;
- mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
- Math.round(ev.getRawY() - m_offsetY));
- break;
- }
-
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- m_pressed = false;
- break;
- }
- return true;
- }
-
-}
-
-// Helper class that manages a cursor or selection handle
-public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
-{
- private View m_layout = null;
- private CursorView m_cursorView = null;
- private PopupWindow m_popup = null;
- private int m_id;
- private int m_attr;
- private Activity m_activity;
- private int m_posX = 0;
- private int m_posY = 0;
- private int m_lastX;
- private int m_lastY;
- int tolerance;
- private boolean m_rtl;
- int m_yShift;
-
- public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
- m_activity = activity;
- m_id = id;
- m_attr = attr;
- m_layout = layout;
- DisplayMetrics metrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1f, metrics);
- tolerance = Math.min(1, (int)(m_yShift / 2f));
- m_lastX = m_lastY = -1 - tolerance;
- m_rtl = rtl;
- }
-
- private boolean initOverlay(){
- if (m_popup == null){
-
- Context context = m_layout.getContext();
- int[] attrs = {m_attr};
- TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
- Drawable drawable = a.getDrawable(0);
-
- m_cursorView = new CursorView(context, this);
- m_cursorView.setImageDrawable(drawable);
-
- m_popup = new PopupWindow(context, null, android.R.attr.textSelectHandleWindowStyle);
- m_popup.setSplitTouchEnabled(true);
- m_popup.setClippingEnabled(false);
- m_popup.setContentView(m_cursorView);
- m_popup.setWidth(drawable.getIntrinsicWidth());
- m_popup.setHeight(drawable.getIntrinsicHeight());
-
- m_layout.getViewTreeObserver().addOnPreDrawListener(this);
- }
- return true;
- }
-
- // Show the handle at a given position (or move it if it is already shown)
- public void setPosition(final int x, final int y){
- initOverlay();
-
- final int[] location = new int[2];
- m_layout.getLocationOnScreen(location);
-
- int x2 = x + location[0];
- int y2 = y + location[1] + m_yShift;
-
- if (m_id == QtNative.IdCursorHandle) {
- x2 -= m_popup.getWidth() / 2 ;
- } else if ((m_id == QtNative.IdLeftHandle && !m_rtl) || (m_id == QtNative.IdRightHandle && m_rtl)) {
- x2 -= m_popup.getWidth() * 3 / 4;
- } else {
- x2 -= m_popup.getWidth() / 4;
- }
-
- if (m_popup.isShowing()) {
- m_popup.update(x2, y2, -1, -1);
- m_cursorView.adjusted(x - m_posX, y - m_posY);
- } else {
- m_popup.showAtLocation(m_layout, 0, x2, y2);
- }
-
- m_posX = x;
- m_posY = y;
- }
-
- public int bottom()
- {
- initOverlay();
- final int[] location = new int[2];
- m_cursorView.getLocationOnScreen(location);
- return location[1] + m_cursorView.getHeight();
- }
-
- public void hide() {
- if (m_popup != null) {
- m_popup.dismiss();
- }
- }
-
- // The handle was dragged by a given relative position
- public void updatePosition(int x, int y) {
- y -= m_yShift;
- if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
- QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
- m_lastX = x;
- m_lastY = y;
- }
- }
-
- @Override
- public boolean onPreDraw() {
- // This hook is called when the view location is changed
- // For example if the keyboard appears.
- // Adjust the position of the handle accordingly
- if (m_popup != null && m_popup.isShowing())
- setPosition(m_posX, m_posY);
-
- return true;
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/EditContextView.java b/src/android/jar/src/org/qtproject/qt5/android/EditContextView.java
deleted file mode 100644
index 104132934d..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/EditContextView.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 BogDan Vatra <bogdan@kde.org>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-
-import android.content.Context;
-import android.text.TextUtils;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.R;
-
-import java.util.HashMap;
-
-public class EditContextView extends LinearLayout implements View.OnClickListener
-{
- public static final int CUT_BUTTON = 1 << 0;
- public static final int COPY_BUTTON = 1 << 1;
- public static final int PASTE_BUTTON = 1 << 2;
- public static final int SALL_BUTTON = 1 << 3;
-
- HashMap<Integer, ContextButton> m_buttons = new HashMap<Integer, ContextButton>(4);
- OnClickListener m_onClickListener;
-
- public interface OnClickListener
- {
- void contextButtonClicked(int buttonId);
- }
-
- private class ContextButton extends TextView
- {
- public int m_buttonId;
- public ContextButton(Context context, int stringId) {
- super(context);
- m_buttonId = stringId;
- setText(stringId);
- setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT, 1));
- setGravity(Gravity.CENTER);
- setTextColor(getResources().getColor(R.color.widget_edittext_dark));
- EditContextView.this.setBackground(getResources().getDrawable(R.drawable.editbox_background_normal));
- float scale = getResources().getDisplayMetrics().density;
- int hPadding = (int)(16 * scale + 0.5f);
- int vPadding = (int)(8 * scale + 0.5f);
- setPadding(hPadding, vPadding, hPadding, vPadding);
- setSingleLine();
- setEllipsize(TextUtils.TruncateAt.END);
- setOnClickListener(EditContextView.this);
- }
- }
-
- @Override
- public void onClick(View v)
- {
- ContextButton button = (ContextButton)v;
- m_onClickListener.contextButtonClicked(button.m_buttonId);
- }
-
- void addButton(int id)
- {
- ContextButton button = new ContextButton(getContext(), id);
- m_buttons.put(id, button);
- addView(button);
- }
-
- public void updateButtons(int buttonsLayout)
- {
- m_buttons.get(R.string.cut).setVisibility((buttonsLayout & CUT_BUTTON) != 0 ? View.VISIBLE : View.GONE);
- m_buttons.get(R.string.copy).setVisibility((buttonsLayout & COPY_BUTTON) != 0 ? View.VISIBLE : View.GONE);
- m_buttons.get(R.string.paste).setVisibility((buttonsLayout & PASTE_BUTTON) != 0 ? View.VISIBLE : View.GONE);
- m_buttons.get(R.string.selectAll).setVisibility((buttonsLayout & SALL_BUTTON) != 0 ? View.VISIBLE : View.GONE);
- }
-
- public EditContextView(Context context, OnClickListener onClickListener) {
- super(context);
- m_onClickListener = onClickListener;
- setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
-
- addButton(R.string.cut);
- addButton(R.string.copy);
- addButton(R.string.paste);
- addButton(R.string.selectAll);
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/EditPopupMenu.java b/src/android/jar/src/org/qtproject/qt5/android/EditPopupMenu.java
deleted file mode 100644
index 18a8b36273..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/EditPopupMenu.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.ImageView;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.view.MotionEvent;
-import android.widget.PopupWindow;
-import android.app.Activity;
-import android.view.ViewTreeObserver;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup.LayoutParams;
-import android.view.ViewGroup;
-import android.R;
-
-// Helper class that manages a cursor or selection handle
-public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayoutChangeListener,
- EditContextView.OnClickListener
-{
- private View m_layout = null;
- private EditContextView m_view = null;
- private PopupWindow m_popup = null;
- private int m_posX;
- private int m_posY;
- private int m_buttons;
- private CursorHandle m_cursorHandle;
- private CursorHandle m_leftSelectionHandle;
- private CursorHandle m_rightSelectionHandle;
-
- public EditPopupMenu(Activity activity, View layout)
- {
- m_view = new EditContextView(activity, this);
- m_view.addOnLayoutChangeListener(this);
-
- m_layout = layout;
- }
-
- private void initOverlay()
- {
- if (m_popup != null)
- return;
-
- Context context = m_layout.getContext();
- m_popup = new PopupWindow(context, null, android.R.attr.textSelectHandleWindowStyle);
- m_popup.setSplitTouchEnabled(true);
- m_popup.setClippingEnabled(false);
- m_popup.setContentView(m_view);
- m_popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
- m_popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
-
- m_layout.getViewTreeObserver().addOnPreDrawListener(this);
- }
-
- // Show the handle at a given position (or move it if it is already shown)
- public void setPosition(final int x, final int y, final int buttons,
- CursorHandle cursorHandle, CursorHandle leftSelectionHandle, CursorHandle rightSelectionHandle)
- {
- initOverlay();
-
- m_view.updateButtons(buttons);
- final int[] location = new int[2];
- m_layout.getLocationOnScreen(location);
-
- int x2 = x + location[0];
- int y2 = y + location[1];
-
- x2 -= m_view.getWidth() / 2 ;
-
- y2 -= m_view.getHeight();
- if (y2 < 0) {
- if (cursorHandle != null)
- y2 = cursorHandle.bottom();
- else if (leftSelectionHandle != null && rightSelectionHandle != null)
- y2 = Math.max(leftSelectionHandle.bottom(), rightSelectionHandle.bottom());
- }
-
- if (m_layout.getWidth() < x + m_view.getWidth() / 2)
- x2 = m_layout.getWidth() - m_view.getWidth();
-
- if (x2 < 0)
- x2 = 0;
-
- if (m_popup.isShowing())
- m_popup.update(x2, y2, -1, -1);
- else
- m_popup.showAtLocation(m_layout, 0, x2, y2);
-
- m_posX = x;
- m_posY = y;
- m_buttons = buttons;
- m_cursorHandle = cursorHandle;
- m_leftSelectionHandle = leftSelectionHandle;
- m_rightSelectionHandle = rightSelectionHandle;
- }
-
- public void hide() {
- if (m_popup != null) {
- m_popup.dismiss();
- m_popup = null;
- }
- }
-
- @Override
- public boolean onPreDraw() {
- // This hook is called when the view location is changed
- // For example if the keyboard appears.
- // Adjust the position of the handle accordingly
- if (m_popup != null && m_popup.isShowing())
- setPosition(m_posX, m_posY, m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
-
- return true;
- }
-
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom)
- {
- if ((right - left != oldRight - oldLeft || bottom - top != oldBottom - oldTop) &&
- m_popup != null && m_popup.isShowing())
- setPosition(m_posX, m_posY, m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
- }
-
- @Override
- public void contextButtonClicked(int buttonId) {
- switch (buttonId) {
- case R.string.cut:
- QtNativeInputConnection.cut();
- break;
- case R.string.copy:
- QtNativeInputConnection.copy();
- break;
- case R.string.paste:
- QtNativeInputConnection.paste();
- break;
- case R.string.selectAll:
- QtNativeInputConnection.selectAll();
- break;
- }
- hide();
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java b/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java
deleted file mode 100644
index ae06506c96..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java
+++ /dev/null
@@ -1,2036 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.xmlpull.v1.XmlPullParser;
-
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
-import android.graphics.Canvas;
-import android.graphics.NinePatch;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.AnimationDrawable;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.ClipDrawable;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.GradientDrawable;
-import android.graphics.drawable.GradientDrawable.Orientation;
-import android.graphics.drawable.InsetDrawable;
-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;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Xml;
-import android.view.inputmethod.EditorInfo;
-
-
-public class ExtractStyle {
-
- native static int[] extractChunkInfo20(byte[] chunkData);
- native static int[] extractNativeChunkInfo20(long nativeChunk);
-
- Class<?> styleableClass = getClass("android.R$styleable");
- Class<?> rippleDrawableClass = getClass("android.graphics.drawable.RippleDrawable");
- Class<?> animatedStateListDrawableClass = getClass("android.graphics.drawable.AnimatedStateListDrawable");
- Class<?> vectorDrawableClass = getClass("android.graphics.drawable.VectorDrawable");
-
- final int[] EMPTY_STATE_SET = {};
- final int[] ENABLED_STATE_SET = {android.R.attr.state_enabled};
- final int[] FOCUSED_STATE_SET = {android.R.attr.state_focused};
- final int[] SELECTED_STATE_SET = {android.R.attr.state_selected};
- final int[] PRESSED_STATE_SET = {android.R.attr.state_pressed};
- final int[] WINDOW_FOCUSED_STATE_SET = {android.R.attr.state_window_focused};
- final int[] ENABLED_FOCUSED_STATE_SET = stateSetUnion(ENABLED_STATE_SET, FOCUSED_STATE_SET);
- final int[] ENABLED_SELECTED_STATE_SET = stateSetUnion(ENABLED_STATE_SET, SELECTED_STATE_SET);
- final int[] ENABLED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(ENABLED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] FOCUSED_SELECTED_STATE_SET = stateSetUnion(FOCUSED_STATE_SET, SELECTED_STATE_SET);
- final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] ENABLED_FOCUSED_SELECTED_STATE_SET = stateSetUnion(ENABLED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
- final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(ENABLED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(ENABLED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(ENABLED_FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_SELECTED_STATE_SET = stateSetUnion(PRESSED_STATE_SET, SELECTED_STATE_SET);
- final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_FOCUSED_STATE_SET = stateSetUnion(PRESSED_STATE_SET, FOCUSED_STATE_SET);
- final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_FOCUSED_SELECTED_STATE_SET = stateSetUnion(PRESSED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
- final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_ENABLED_STATE_SET = stateSetUnion(PRESSED_STATE_SET, ENABLED_STATE_SET);
- final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_ENABLED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_ENABLED_SELECTED_STATE_SET = stateSetUnion(PRESSED_ENABLED_STATE_SET, SELECTED_STATE_SET);
- final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_ENABLED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_ENABLED_FOCUSED_STATE_SET = stateSetUnion(PRESSED_ENABLED_STATE_SET, FOCUSED_STATE_SET);
- final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_ENABLED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
- final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = stateSetUnion(PRESSED_ENABLED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
- final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = stateSetUnion(PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
-
- final int View_background = getField(styleableClass,"View_background");
- final int View_padding = getField(styleableClass,"View_padding");
- final int View_paddingLeft = getField(styleableClass,"View_paddingLeft");
- final int View_paddingTop = getField(styleableClass,"View_paddingTop");
- final int View_paddingRight = getField(styleableClass,"View_paddingRight");
- final int View_paddingBottom = getField(styleableClass,"View_paddingBottom");
- final int View_scrollX = getField(styleableClass,"View_scrollX");
- final int View_scrollY = getField(styleableClass,"View_scrollY");
- final int View_id = getField(styleableClass,"View_id");
- final int View_tag = getField(styleableClass,"View_tag");
- final int View_fitsSystemWindows = getField(styleableClass,"View_fitsSystemWindows");
- final int View_focusable = getField(styleableClass,"View_focusable");
- final int View_focusableInTouchMode = getField(styleableClass,"View_focusableInTouchMode");
- final int View_clickable = getField(styleableClass,"View_clickable");
- final int View_longClickable = getField(styleableClass,"View_longClickable");
- final int View_saveEnabled = getField(styleableClass,"View_saveEnabled");
- final int View_duplicateParentState = getField(styleableClass,"View_duplicateParentState");
- final int View_visibility = getField(styleableClass,"View_visibility");
- final int View_drawingCacheQuality = getField(styleableClass,"View_drawingCacheQuality");
- final int View_contentDescription = getField(styleableClass,"View_contentDescription");
- final int View_soundEffectsEnabled = getField(styleableClass,"View_soundEffectsEnabled");
- final int View_hapticFeedbackEnabled = getField(styleableClass,"View_hapticFeedbackEnabled");
- final int View_scrollbars = getField(styleableClass,"View_scrollbars");
- final int View_fadingEdge = getField(styleableClass,"View_fadingEdge");
- final int View_scrollbarStyle = getField(styleableClass,"View_scrollbarStyle");
- final int View_scrollbarFadeDuration = getField(styleableClass,"View_scrollbarFadeDuration");
- final int View_scrollbarDefaultDelayBeforeFade = getField(styleableClass,"View_scrollbarDefaultDelayBeforeFade");
- final int View_scrollbarSize = getField(styleableClass,"View_scrollbarSize");
- final int View_scrollbarThumbHorizontal = getField(styleableClass,"View_scrollbarThumbHorizontal");
- final int View_scrollbarThumbVertical = getField(styleableClass,"View_scrollbarThumbVertical");
- final int View_scrollbarTrackHorizontal = getField(styleableClass,"View_scrollbarTrackHorizontal");
- final int View_scrollbarTrackVertical = getField(styleableClass,"View_scrollbarTrackVertical");
- final int View_isScrollContainer = getField(styleableClass,"View_isScrollContainer");
- final int View_keepScreenOn = getField(styleableClass,"View_keepScreenOn");
- final int View_filterTouchesWhenObscured = getField(styleableClass,"View_filterTouchesWhenObscured");
- final int View_nextFocusLeft = getField(styleableClass,"View_nextFocusLeft");
- final int View_nextFocusRight = getField(styleableClass,"View_nextFocusRight");
- final int View_nextFocusUp = getField(styleableClass,"View_nextFocusUp");
- final int View_nextFocusDown = getField(styleableClass,"View_nextFocusDown");
- final int View_minWidth = getField(styleableClass,"View_minWidth");
- final int View_minHeight = getField(styleableClass,"View_minHeight");
- final int View_onClick = getField(styleableClass,"View_onClick");
- final int View_overScrollMode = getField(styleableClass,"View_overScrollMode");
- final int View_paddingStart = getField(styleableClass,"View_paddingStart");
- final int View_paddingEnd = getField(styleableClass,"View_paddingEnd");
-
- final int TextAppearance_textColorHighlight = getField(styleableClass,"TextAppearance_textColorHighlight");
- final int TextAppearance_textColor = getField(styleableClass,"TextAppearance_textColor");
- final int TextAppearance_textColorHint = getField(styleableClass,"TextAppearance_textColorHint");
- final int TextAppearance_textColorLink = getField(styleableClass,"TextAppearance_textColorLink");
- final int TextAppearance_textSize = getField(styleableClass,"TextAppearance_textSize");
- final int TextAppearance_typeface = getField(styleableClass,"TextAppearance_typeface");
- final int TextAppearance_textStyle = getField(styleableClass,"TextAppearance_textStyle");
- final int TextAppearance_textAllCaps = getField(styleableClass,"TextAppearance_textAllCaps");
- final int TextView_editable = getField(styleableClass,"TextView_editable");
- final int TextView_inputMethod = getField(styleableClass,"TextView_inputMethod");
- final int TextView_numeric = getField(styleableClass,"TextView_numeric");
- final int TextView_digits = getField(styleableClass,"TextView_digits");
- final int TextView_phoneNumber = getField(styleableClass,"TextView_phoneNumber");
- final int TextView_autoText = getField(styleableClass,"TextView_autoText");
- final int TextView_capitalize = getField(styleableClass,"TextView_capitalize");
- final int TextView_bufferType = getField(styleableClass,"TextView_bufferType");
- final int TextView_selectAllOnFocus = getField(styleableClass,"TextView_selectAllOnFocus");
- final int TextView_autoLink = getField(styleableClass,"TextView_autoLink");
- final int TextView_linksClickable = getField(styleableClass,"TextView_linksClickable");
- final int TextView_drawableLeft = getField(styleableClass,"TextView_drawableLeft");
- final int TextView_drawableTop = getField(styleableClass,"TextView_drawableTop");
- final int TextView_drawableRight = getField(styleableClass,"TextView_drawableRight");
- final int TextView_drawableBottom = getField(styleableClass,"TextView_drawableBottom");
- final int TextView_drawableStart = getField(styleableClass,"TextView_drawableStart");
- final int TextView_drawableEnd = getField(styleableClass,"TextView_drawableEnd");
- final int TextView_drawablePadding = getField(styleableClass,"TextView_drawablePadding");
- final int TextView_textCursorDrawable = getField(styleableClass,"TextView_textCursorDrawable");
- final int TextView_maxLines = getField(styleableClass,"TextView_maxLines");
- final int TextView_maxHeight = getField(styleableClass,"TextView_maxHeight");
- final int TextView_lines = getField(styleableClass,"TextView_lines");
- final int TextView_height = getField(styleableClass,"TextView_height");
- final int TextView_minLines = getField(styleableClass,"TextView_minLines");
- final int TextView_minHeight = getField(styleableClass,"TextView_minHeight");
- final int TextView_maxEms = getField(styleableClass,"TextView_maxEms");
- final int TextView_maxWidth = getField(styleableClass,"TextView_maxWidth");
- final int TextView_ems = getField(styleableClass,"TextView_ems");
- final int TextView_width = getField(styleableClass,"TextView_width");
- final int TextView_minEms = getField(styleableClass,"TextView_minEms");
- final int TextView_minWidth = getField(styleableClass,"TextView_minWidth");
- final int TextView_gravity = getField(styleableClass,"TextView_gravity");
- final int TextView_hint = getField(styleableClass,"TextView_hint");
- final int TextView_text = getField(styleableClass,"TextView_text");
- final int TextView_scrollHorizontally = getField(styleableClass,"TextView_scrollHorizontally");
- final int TextView_singleLine = getField(styleableClass,"TextView_singleLine");
- final int TextView_ellipsize = getField(styleableClass,"TextView_ellipsize");
- final int TextView_marqueeRepeatLimit = getField(styleableClass,"TextView_marqueeRepeatLimit");
- final int TextView_includeFontPadding = getField(styleableClass,"TextView_includeFontPadding");
- final int TextView_cursorVisible = getField(styleableClass,"TextView_cursorVisible");
- final int TextView_maxLength = getField(styleableClass,"TextView_maxLength");
- final int TextView_textScaleX = getField(styleableClass,"TextView_textScaleX");
- final int TextView_freezesText = getField(styleableClass,"TextView_freezesText");
- final int TextView_shadowColor = getField(styleableClass,"TextView_shadowColor");
- final int TextView_shadowDx = getField(styleableClass,"TextView_shadowDx");
- final int TextView_shadowDy = getField(styleableClass,"TextView_shadowDy");
- final int TextView_shadowRadius = getField(styleableClass,"TextView_shadowRadius");
- final int TextView_enabled = getField(styleableClass,"TextView_enabled");
- final int TextView_textColorHighlight = getField(styleableClass,"TextView_textColorHighlight");
- final int TextView_textColor = getField(styleableClass,"TextView_textColor");
- final int TextView_textColorHint = getField(styleableClass,"TextView_textColorHint");
- final int TextView_textColorLink = getField(styleableClass,"TextView_textColorLink");
- final int TextView_textSize = getField(styleableClass,"TextView_textSize");
- final int TextView_typeface = getField(styleableClass,"TextView_typeface");
- final int TextView_textStyle = getField(styleableClass,"TextView_textStyle");
- final int TextView_password = getField(styleableClass,"TextView_password");
- final int TextView_lineSpacingExtra = getField(styleableClass,"TextView_lineSpacingExtra");
- final int TextView_lineSpacingMultiplier = getField(styleableClass,"TextView_lineSpacingMultiplier");
- final int TextView_inputType = getField(styleableClass,"TextView_inputType");
- final int TextView_imeOptions = getField(styleableClass,"TextView_imeOptions");
- final int TextView_imeActionLabel = getField(styleableClass,"TextView_imeActionLabel");
- final int TextView_imeActionId = getField(styleableClass,"TextView_imeActionId");
- final int TextView_privateImeOptions = getField(styleableClass,"TextView_privateImeOptions");
- final int TextView_textSelectHandleLeft = getField(styleableClass,"TextView_textSelectHandleLeft");
- final int TextView_textSelectHandleRight = getField(styleableClass,"TextView_textSelectHandleRight");
- final int TextView_textSelectHandle = getField(styleableClass,"TextView_textSelectHandle");
- final int TextView_textIsSelectable = getField(styleableClass,"TextView_textIsSelectable");
- final int TextView_textAllCaps = getField(styleableClass,"TextView_textAllCaps");
-
- final int ImageView_src = getField(styleableClass,"ImageView_src");
- final int ImageView_baselineAlignBottom = getField(styleableClass,"ImageView_baselineAlignBottom");
- final int ImageView_adjustViewBounds = getField(styleableClass,"ImageView_adjustViewBounds");
- final int ImageView_maxWidth = getField(styleableClass,"ImageView_maxWidth");
- final int ImageView_maxHeight = getField(styleableClass,"ImageView_maxHeight");
- final int ImageView_scaleType = getField(styleableClass,"ImageView_scaleType");
- final int ImageView_tint = getField(styleableClass,"ImageView_tint");
- final int ImageView_cropToPadding = getField(styleableClass,"ImageView_cropToPadding");
-
- final Resources.Theme m_theme;
- final String m_extractPath;
- Context m_context;
- final int defaultBackgroundColor;
- final int defaultTextColor;
- final boolean m_minimal;
-
- class SimpleJsonWriter
- {
- private OutputStreamWriter m_writer;
- private boolean m_addComma = false;
- private int m_indentLevel = 0;
- public SimpleJsonWriter(String filePath) throws FileNotFoundException
- {
- m_writer = new OutputStreamWriter(new FileOutputStream(filePath));
- }
-
- public void close() throws IOException
- {
- m_writer.close();
- }
-
- private void writeIndent() throws IOException
- {
- m_writer.write(" ", 0, m_indentLevel);
- }
-
- SimpleJsonWriter beginObject() throws IOException
- {
- writeIndent();
- m_writer.write("{\n");
- ++m_indentLevel;
- m_addComma = false;
- return this;
- }
-
- SimpleJsonWriter endObject() throws IOException
- {
- m_writer.write("\n");
- writeIndent();
- m_writer.write("}\n");
- --m_indentLevel;
- m_addComma = false;
- return this;
- }
-
- SimpleJsonWriter name(String name) throws IOException
- {
- if (m_addComma) {
- m_writer.write(",\n");
- }
- writeIndent();
- m_writer.write(JSONObject.quote(name) + ": ");
- m_addComma = true;
- return this;
- }
-
- SimpleJsonWriter value(JSONObject value) throws IOException
- {
- m_writer.write(value.toString());
- return this;
- }
- }
-
- class FakeCanvas extends Canvas {
- int[] chunkData = null;
- class Size {
- public int s,e;
- Size(int start, int end)
- {
- s=start;
- e=end;
- }
- }
-
- public boolean isHardwareAccelerated() {
- return true;
- }
-
- public void drawPatch(Bitmap bmp, byte[] chunks, RectF dst, Paint paint) {
- chunkData = extractChunkInfo20(chunks);
- }
- }
-
-
-
- private int[] stateSetUnion(final int[] stateSet1, final int[] stateSet2)
- {
- try
- {
- final int stateSet1Length = stateSet1.length;
- final int stateSet2Length = stateSet2.length;
- final int[] newSet = new int[stateSet1Length + stateSet2Length];
- int k = 0;
- int i = 0;
- int j = 0;
- // This is a merge of the two input state sets and assumes that the
- // input sets are sorted by the order imposed by ViewDrawableStates.
- int[] viewDrawableStatesState=(int[]) styleableClass.getDeclaredField("ViewDrawableStates").get(null);
- for (int viewState : viewDrawableStatesState)
- {
- if (i < stateSet1Length && stateSet1[i] == viewState)
- {
- newSet[k++] = viewState;
- i++;
- } else if (j < stateSet2Length && stateSet2[j] == viewState) {
- newSet[k++] = viewState;
- j++;
- }
- if (k > 1) {
- assert(newSet[k - 1] > newSet[k - 2]);
- }
- }
- return newSet;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
-
- private Class<?> getClass(String className) {
- try {
- return Class.forName(className);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- Field getAccessibleField(Class<?> clazz, String fieldName) {
- try {
- Field f = clazz.getDeclaredField(fieldName);
- f.setAccessible(true);
- return f;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- Field tryGetAccessibleField(Class<?> clazz, String fieldName) {
- if (clazz == null)
- return null;
-
- try {
- Field f = clazz.getDeclaredField(fieldName);
- f.setAccessible(true);
- return f;
- } catch (Exception e) {
- for (Class<?> c : clazz.getInterfaces()) {
- Field f = tryGetAccessibleField(c, fieldName);
- if (f != null)
- return f;
- }
- }
- return tryGetAccessibleField(clazz.getSuperclass(), fieldName);
- }
-
- int getField(Class<?> clazz, String fieldName)
- {
- try {
- return clazz.getDeclaredField(fieldName).getInt(null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -1;
- }
-
- JSONObject getColorStateList(ColorStateList colorList)
- {
- JSONObject json = new JSONObject();
- try
- {
- json.put("EMPTY_STATE_SET", colorList.getColorForState(EMPTY_STATE_SET, 0));
- json.put("WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(WINDOW_FOCUSED_STATE_SET, 0));
- json.put("SELECTED_STATE_SET", colorList.getColorForState(SELECTED_STATE_SET, 0));
- json.put("SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("FOCUSED_STATE_SET", colorList.getColorForState(FOCUSED_STATE_SET, 0));
- json.put("FOCUSED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(FOCUSED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("FOCUSED_SELECTED_STATE_SET", colorList.getColorForState(FOCUSED_SELECTED_STATE_SET, 0));
- json.put("FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("ENABLED_STATE_SET", colorList.getColorForState(ENABLED_STATE_SET, 0));
- json.put("ENABLED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(ENABLED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("ENABLED_SELECTED_STATE_SET", colorList.getColorForState(ENABLED_SELECTED_STATE_SET, 0));
- json.put("ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("ENABLED_FOCUSED_STATE_SET", colorList.getColorForState(ENABLED_FOCUSED_STATE_SET, 0));
- json.put("ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("ENABLED_FOCUSED_SELECTED_STATE_SET", colorList.getColorForState(ENABLED_FOCUSED_SELECTED_STATE_SET, 0));
- json.put("ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_STATE_SET", colorList.getColorForState(PRESSED_STATE_SET, 0));
- json.put("PRESSED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_SELECTED_STATE_SET", colorList.getColorForState(PRESSED_SELECTED_STATE_SET, 0));
- json.put("PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_FOCUSED_SELECTED_STATE_SET", colorList.getColorForState(PRESSED_FOCUSED_SELECTED_STATE_SET, 0));
- json.put("PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_SELECTED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_SELECTED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, 0));
- json.put("PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET", colorList.getColorForState(PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, 0));
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
- return json;
- }
-
- final int [] DrawableStates ={android.R.attr.state_active, android.R.attr.state_checked
- , android.R.attr.state_enabled, android.R.attr.state_focused
- , android.R.attr.state_pressed, android.R.attr.state_selected
- , android.R.attr.state_window_focused, 16908288, 16843597, 16843518, 16843547};
- final String[] DrawableStatesLabels = {"active", "checked", "enabled", "focused", "pressed", "selected", "window_focused", "background", "multiline", "activated", "accelerated"};
- final String[] DisableDrawableStatesLabels = {"inactive", "unchecked", "disabled", "not_focused", "no_pressed", "unselected", "window_not_focused", "background", "multiline", "activated", "accelerated"};
-
- String getFileName(String file, String[] states)
- {
- for (String state: states)
- file+="__"+state;
- return file;
- }
-
- String getStatesName(String[] states)
- {
- String statesName="";
- for (String state: states)
- {
- if (statesName.length()>0)
- statesName+="__";
- statesName += state;
- }
- return statesName;
- }
-
- void addDrawableItemIfNotExists(JSONObject json, ArrayList<Integer> list, Drawable item, String[] states, String filename)
- {
- for (Integer it : list)
- {
- if (it.equals(item.hashCode()))
- return;
- }
- list.add(item.hashCode());
- try {
- json.put(getStatesName(states), getDrawable(item, getFileName(filename, states), null));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
-
- void addSolution(String filename, JSONObject json, int c, Drawable drawable, ArrayList<Integer> drawableList, int u)
- {
- int pos=0;
- int states[] = new int[c];
- String [] statesText = new String[c];
-
- for (int n= 0;u > 0;++n, u>>= 1)
- if ((u & 1) > 0)
- {
- statesText[pos]=DrawableStatesLabels[n];
- states[pos++]=DrawableStates[n];
- }
- drawable.setState(states);
- addDrawableItemIfNotExists(json, drawableList, drawable.getCurrent(), statesText, filename);
- }
-
- int bitCount(int u)
- {
- int n;
- for (n= 0;u > 0;++n, u&= (u - 1));
- return n;
- }
-
- JSONObject getStatesList(int [] states) throws JSONException
- {
- JSONObject json = new JSONObject();
- for (int s : states)
- {
- boolean found=false;
- for (int d = 0;d<DrawableStates.length;d++)
- {
- if (s==DrawableStates[d])
- {
- json.put(DrawableStatesLabels[d], true);
- found=true;
- break;
- }
- else if (s==-DrawableStates[d])
- {
- json.put(DrawableStatesLabels[d], false);
-
- found=true;
- break;
- }
- }
- if (!found)
- {
- json.put("unhandled_state_"+s,s>0);
- }
- }
- return json;
- }
-
- String getStatesName(int [] states)
- {
- String statesName="";
- for (int s : states)
- {
- boolean found=false;
- for (int d = 0;d<DrawableStates.length;d++)
- {
- if (s==DrawableStates[d])
- {
- if (statesName.length()>0)
- statesName+="__";
- statesName+=DrawableStatesLabels[d];
- found=true;
- break;
- }
- else if (s==-DrawableStates[d])
- {
- if (statesName.length()>0)
- statesName+="__";
- statesName+=DisableDrawableStatesLabels[d];
- found=true;
- break;
- }
- }
- if (!found)
- {
- if (statesName.length()>0)
- statesName+=";";
- statesName+=s;
- }
- }
- if (statesName.length()>0)
- return statesName;
- return "empty";
- }
-
- private JSONObject getLayerDrawable(Object drawable, String filename)
- {
- JSONObject json = new JSONObject();
- LayerDrawable layers = (LayerDrawable) drawable;
- final int nr=layers.getNumberOfLayers();
- try {
- JSONArray array =new JSONArray();
- for (int i = 0; i < nr; i++)
- {
- int id = layers.getId(i);
- if (id == -1)
- id = i;
- JSONObject layerJsonObject=getDrawable(layers.getDrawable(i), filename+"__"+id, null);
- layerJsonObject.put("id", id);
- array.put(layerJsonObject);
- }
- json.put("type", "layer");
- Rect padding = new Rect();
- if (layers.getPadding(padding))
- json.put("padding", getJsonRect(padding));
- json.put("layers", array);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject getStateListDrawable(Object drawable, String filename)
- {
- JSONObject json = new JSONObject();
- try {
- StateListDrawable stateList = (StateListDrawable) drawable;
- final int numStates = (Integer) StateListDrawable.class.getMethod("getStateCount").invoke(stateList);
- JSONArray array =new JSONArray();
- for (int i = 0; i < numStates; i++)
- {
- JSONObject stateJson = new JSONObject();
- final Drawable d = (Drawable) StateListDrawable.class.getMethod("getStateDrawable", Integer.TYPE).invoke(stateList, i);
- final int [] states = (int[]) StateListDrawable.class.getMethod("getStateSet", Integer.TYPE).invoke(stateList, i);
- if (states != null)
- stateJson.put("states", getStatesList(states));
- stateJson.put("drawable", getDrawable(d, filename+"__" + (states != null ? getStatesName(states) : ("state_pos_" + i)), null));
- array.put(stateJson);
- }
- json.put("type", "stateslist");
- Rect padding = new Rect();
- if (stateList.getPadding(padding))
- json.put("padding", getJsonRect(padding));
- json.put("stateslist", array);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject getGradientDrawable(GradientDrawable drawable) {
- JSONObject json = new JSONObject();
- try {
- json.put("type", "gradient");
- Object obj=drawable.getConstantState();
- Class<?> gradientStateClass=obj.getClass();
- json.put("shape",gradientStateClass.getField("mShape").getInt(obj));
- json.put("gradient",gradientStateClass.getField("mGradient").getInt(obj));
- GradientDrawable.Orientation orientation=(Orientation) gradientStateClass.getField("mOrientation").get(obj);
- json.put("orientation",orientation.name());
- int [] intArray=(int[]) gradientStateClass.getField("mGradientColors").get(obj);
- if (intArray != null)
- json.put("colors",getJsonArray(intArray, 0, intArray.length));
- json.put("positions",getJsonArray((float[]) gradientStateClass.getField("mPositions").get(obj)));
- json.put("strokeWidth",gradientStateClass.getField("mStrokeWidth").getInt(obj));
- json.put("strokeDashWidth",gradientStateClass.getField("mStrokeDashWidth").getFloat(obj));
- json.put("strokeDashGap",gradientStateClass.getField("mStrokeDashGap").getFloat(obj));
- json.put("radius",gradientStateClass.getField("mRadius").getFloat(obj));
- float [] floatArray=(float[]) gradientStateClass.getField("mRadiusArray").get(obj);
- if (floatArray!=null)
- json.put("radiusArray",getJsonArray(floatArray));
- Rect rc= (Rect) gradientStateClass.getField("mPadding").get(obj);
- if (rc!=null)
- json.put("padding",getJsonRect(rc));
- json.put("width",gradientStateClass.getField("mWidth").getInt(obj));
- json.put("height",gradientStateClass.getField("mHeight").getInt(obj));
- json.put("innerRadiusRatio",gradientStateClass.getField("mInnerRadiusRatio").getFloat(obj));
- json.put("thicknessRatio",gradientStateClass.getField("mThicknessRatio").getFloat(obj));
- json.put("innerRadius",gradientStateClass.getField("mInnerRadius").getInt(obj));
- json.put("thickness",gradientStateClass.getField("mThickness").getInt(obj));
- } catch (Exception e) {
- e.printStackTrace();
- }
- 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();
- if (Build.VERSION.SDK_INT < 23)
- json.put("drawable", getDrawable(getAccessibleField(rotateStateClass, "mDrawable").get(obj), filename, null));
- else
- json.put("drawable", getDrawable(drawable.getClass().getMethod("getDrawable").invoke(drawable), filename, null));
- json.put("pivotX", getAccessibleField(rotateStateClass, "mPivotX").getFloat(obj));
- json.put("pivotXRel", getAccessibleField(rotateStateClass, "mPivotXRel").getBoolean(obj));
- json.put("pivotY", getAccessibleField(rotateStateClass, "mPivotY").getFloat(obj));
- json.put("pivotYRel", getAccessibleField(rotateStateClass, "mPivotYRel").getBoolean(obj));
- json.put("fromDegrees", getAccessibleField(rotateStateClass, "mFromDegrees").getFloat(obj));
- json.put("toDegrees", getAccessibleField(rotateStateClass, "mToDegrees").getFloat(obj));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject getAnimationDrawable(AnimationDrawable drawable, String filename) {
- JSONObject json = new JSONObject();
- try {
- json.put("type", "animation");
- json.put("oneshot", drawable.isOneShot());
- final int count = drawable.getNumberOfFrames();
- JSONArray frames = new JSONArray();
- for (int i = 0; i < count; ++i)
- {
- JSONObject frame = new JSONObject();
- frame.put("duration", drawable.getDuration(i));
- frame.put("drawable", getDrawable(drawable.getFrame(i), filename+"__"+i, null));
- frames.put(frame);
- }
- json.put("frames", frames);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject getJsonRect(Rect rect) throws JSONException
- {
- JSONObject jsonRect = new JSONObject();
- jsonRect.put("left", rect.left);
- jsonRect.put("top", rect.top);
- jsonRect.put("right", rect.right);
- jsonRect.put("bottom", rect.bottom);
- return jsonRect;
-
- }
-
- private JSONArray getJsonArray(int[] array, int pos, int len)
- {
- JSONArray a = new JSONArray();
- final int l = pos+len;
- for (int i=pos; i<l;i++)
- a.put(array[i]);
- return a;
- }
-
- private JSONArray getJsonArray(float[] array) throws JSONException
- {
- JSONArray a = new JSONArray();
- if (array != null)
- for (float val: array)
- a.put(val);
- return a;
- }
-
- private JSONObject getJsonChunkInfo(int[] chunkData) throws JSONException
- {
- JSONObject jsonRect = new JSONObject();
- if (chunkData == null)
- return jsonRect;
-
- jsonRect.put("xdivs", getJsonArray(chunkData, 3, chunkData[0]));
- jsonRect.put("ydivs", getJsonArray(chunkData, 3 + chunkData[0], chunkData[1]));
- jsonRect.put("colors", getJsonArray(chunkData, 3 + chunkData[0] + chunkData[1], chunkData[2]));
- return jsonRect;
- }
-
- private JSONObject findPatchesMarings(Drawable d) throws JSONException, NoSuchFieldException, IllegalAccessException
- {
- NinePatch np;
- Field f = tryGetAccessibleField(NinePatchDrawable.class, "mNinePatch");
- if (f != null) {
- np = (NinePatch) f.get(d);
- } else {
- Object state = getAccessibleField(NinePatchDrawable.class, "mNinePatchState").get(d);
- np = (NinePatch) getAccessibleField(state.getClass(), "mNinePatch").get(state);
- }
- return getJsonChunkInfo(extractNativeChunkInfo20(getAccessibleField(np.getClass(), "mNativeChunk").getLong(np)));
- }
-
- class DrawableCache
- {
- public DrawableCache(JSONObject json, Object drawable)
- {
- object = json;
- this.drawable = drawable;
- }
- JSONObject object;
- Object drawable;
- }
- private HashMap<String, DrawableCache> m_drawableCache = new HashMap<String, DrawableCache>();
-
- private JSONObject getRippleDrawable(Object drawable, String filename, Rect padding)
- {
- JSONObject json = getLayerDrawable(drawable, filename);
- JSONObject ripple = new JSONObject();
- try {
- final Object mState = getAccessibleField(rippleDrawableClass, "mState").get(drawable);
- ripple.put("mask", getDrawable((Drawable)getAccessibleField(rippleDrawableClass, "mMask").get(drawable), filename, padding));
- ripple.put("maxRadius", getAccessibleField(mState.getClass(), "mMaxRadius").getInt(mState));
- ripple.put("color", getColorStateList((ColorStateList)getAccessibleField(mState.getClass(), "mColor").get(mState)));
- json.put("ripple", ripple);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private HashMap<Long, Long> getStateTransitions(Object sa) throws Exception
- {
- HashMap<Long, Long> transitions = new HashMap<Long, Long>();
- final int sz = getAccessibleField(sa.getClass(), "mSize").getInt(sa);
- long[] keys = (long[]) getAccessibleField(sa.getClass(), "mKeys").get(sa);
- long[] values = (long[]) getAccessibleField(sa.getClass(), "mValues").get(sa);
- for (int i = 0; i < sz; i++) {
- transitions.put(keys[i], values[i]);
- }
- return transitions;
- }
-
- private HashMap<Integer, Integer> getStateIds(Object sa) throws Exception
- {
- HashMap<Integer, Integer> states = new HashMap<Integer, Integer>();
- final int sz = getAccessibleField(sa.getClass(), "mSize").getInt(sa);
- int[] keys = (int[]) getAccessibleField(sa.getClass(), "mKeys").get(sa);
- int[] values = (int[]) getAccessibleField(sa.getClass(), "mValues").get(sa);
- for (int i = 0; i < sz; i++) {
- states.put(keys[i], values[i]);
- }
- return states;
- }
-
- private int findStateIndex(int id, HashMap<Integer, Integer> stateIds)
- {
- for (Map.Entry<Integer, Integer> s : stateIds.entrySet()) {
- if (id == s.getValue())
- return s.getKey();
- }
- return -1;
- }
-
- private JSONObject getAnimatedStateListDrawable(Object drawable, String filename)
- {
- JSONObject json = getStateListDrawable(drawable, filename);
- try {
- Object state = getAccessibleField(animatedStateListDrawableClass, "mState").get(drawable);
-
- HashMap<Integer, Integer> stateIds = getStateIds(getAccessibleField(state.getClass(), "mStateIds").get(state));
- HashMap<Long, Long> transitions = getStateTransitions(getAccessibleField(state.getClass(), "mTransitions").get(state));
-
- for (Map.Entry<Long, Long> t : transitions.entrySet()) {
- final int toState = findStateIndex(t.getKey().intValue(), stateIds);
- final int fromState = findStateIndex((int) (t.getKey() >> 32), stateIds);
-
- JSONObject transition = new JSONObject();
- transition.put("from", fromState);
- transition.put("to", toState);
- transition.put("reverse", (t.getValue() >> 32) != 0);
-
- JSONArray stateslist = json.getJSONArray("stateslist");
- JSONObject stateobj = stateslist.getJSONObject(t.getValue().intValue());
- stateobj.put("transition", transition);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject getVPath(Object path) throws Exception
- {
- JSONObject json = new JSONObject();
- final Class<?> pathClass = path.getClass();
- json.put("type", "path");
- json.put("name", tryGetAccessibleField(pathClass, "mPathName").get(path));
- Object[] mNodes = (Object[]) tryGetAccessibleField(pathClass, "mNodes").get(path);
- JSONArray nodes = new JSONArray();
- for (Object n: mNodes) {
- JSONObject node = new JSONObject();
- node.put("type", String.valueOf(getAccessibleField(n.getClass(), "mType").getChar(n)));
- node.put("params", getJsonArray((float[])getAccessibleField(n.getClass(), "mParams").get(n)));
- nodes.put(node);
- }
- json.put("nodes", nodes);
- json.put("isClip", (Boolean) pathClass.getMethod("isClipPath").invoke(path));
-
- if (tryGetAccessibleField(pathClass, "mStrokeColor") == null)
- return json; // not VFullPath
-
- json.put("strokeColor", getAccessibleField(pathClass, "mStrokeColor").getInt(path));
- json.put("strokeWidth", getAccessibleField(pathClass, "mStrokeWidth").getFloat(path));
- json.put("fillColor", getAccessibleField(pathClass, "mFillColor").getInt(path));
- json.put("strokeAlpha", getAccessibleField(pathClass, "mStrokeAlpha").getFloat(path));
- json.put("fillRule", getAccessibleField(pathClass, "mFillRule").getInt(path));
- json.put("fillAlpha", getAccessibleField(pathClass, "mFillAlpha").getFloat(path));
- json.put("trimPathStart", getAccessibleField(pathClass, "mTrimPathStart").getFloat(path));
- json.put("trimPathEnd", getAccessibleField(pathClass, "mTrimPathEnd").getFloat(path));
- json.put("trimPathOffset", getAccessibleField(pathClass, "mTrimPathOffset").getFloat(path));
- json.put("strokeLineCap", (Paint.Cap) getAccessibleField(pathClass, "mStrokeLineCap").get(path));
- json.put("strokeLineJoin", (Paint.Join) getAccessibleField(pathClass, "mStrokeLineJoin").get(path));
- json.put("strokeMiterlimit", getAccessibleField(pathClass, "mStrokeMiterlimit").getFloat(path));
- return json;
- }
-
- @SuppressWarnings("unchecked")
- private JSONObject getVGroup(Object group) throws Exception
- {
- JSONObject json = new JSONObject();
- json.put("type", "group");
- final Class<?> groupClass = group.getClass();
- json.put("name", getAccessibleField(groupClass, "mGroupName").get(group));
- json.put("rotate", getAccessibleField(groupClass, "mRotate").getFloat(group));
- json.put("pivotX", getAccessibleField(groupClass, "mPivotX").getFloat(group));
- json.put("pivotY", getAccessibleField(groupClass, "mPivotY").getFloat(group));
- json.put("scaleX", getAccessibleField(groupClass, "mScaleX").getFloat(group));
- json.put("scaleY", getAccessibleField(groupClass, "mScaleY").getFloat(group));
- json.put("translateX", getAccessibleField(groupClass, "mTranslateX").getFloat(group));
- json.put("translateY", getAccessibleField(groupClass, "mTranslateY").getFloat(group));
-
- ArrayList<Object> mChildren = (ArrayList<Object>) getAccessibleField(groupClass, "mChildren").get(group);
- JSONArray children = new JSONArray();
- for (Object c: mChildren) {
- if (groupClass.isInstance(c))
- children.put(getVGroup(c));
- else
- children.put(getVPath(c));
- }
- json.put("children", children);
- return json;
- }
-
- private JSONObject getVectorDrawable(Object drawable, String filename, Rect padding)
- {
- JSONObject json = new JSONObject();
- try {
- json.put("type", "vector");
- final Object state = getAccessibleField(vectorDrawableClass, "mVectorState").get(drawable);
- final Class<?> stateClass = state.getClass();
- final ColorStateList mTint = (ColorStateList) getAccessibleField(stateClass, "mTint").get(state);
- if (mTint != null) {
- json.put("tintList", getColorStateList(mTint));
- json.put("tintMode", (PorterDuff.Mode) getAccessibleField(stateClass, "mTintMode").get(state));
- }
- final Object mVPathRenderer = getAccessibleField(stateClass, "mVPathRenderer").get(state);
- final Class<?> VPathRendererClass = mVPathRenderer.getClass();
- json.put("baseWidth", getAccessibleField(VPathRendererClass, "mBaseWidth").getFloat(mVPathRenderer));
- json.put("baseHeight", getAccessibleField(VPathRendererClass, "mBaseHeight").getFloat(mVPathRenderer));
- json.put("viewportWidth", getAccessibleField(VPathRendererClass, "mViewportWidth").getFloat(mVPathRenderer));
- json.put("viewportHeight", getAccessibleField(VPathRendererClass, "mViewportHeight").getFloat(mVPathRenderer));
- json.put("rootAlpha", getAccessibleField(VPathRendererClass, "mRootAlpha").getInt(mVPathRenderer));
- json.put("rootName", getAccessibleField(VPathRendererClass, "mRootName").get(mVPathRenderer));
- json.put("rootGroup", getVGroup(getAccessibleField(mVPathRenderer.getClass(), "mRootGroup").get(mVPathRenderer)));
- } catch(Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- public JSONObject getDrawable(Object drawable, String filename, Rect padding)
- {
- if (drawable == null || m_minimal)
- return null;
-
- DrawableCache dc = m_drawableCache.get(filename);
- if (dc != null)
- {
- if (dc.drawable.equals(drawable))
- return dc.object;
- else
- Log.e(QtNative.QtTAG, "Different drawable objects points to the same file name \"" + filename +"\"");
- }
- JSONObject json = new JSONObject();
- Bitmap bmp = null;
- if (drawable instanceof Bitmap)
- bmp = (Bitmap) drawable;
- else
- {
- if (drawable instanceof BitmapDrawable) {
- BitmapDrawable bitmapDrawable = (BitmapDrawable)drawable;
- bmp = bitmapDrawable.getBitmap();
- try {
- json.put("gravity", bitmapDrawable.getGravity());
- json.put("tileModeX", bitmapDrawable.getTileModeX());
- json.put("tileModeY", bitmapDrawable.getTileModeY());
- json.put("antialias", (Boolean) BitmapDrawable.class.getMethod("hasAntiAlias").invoke(bitmapDrawable));
- json.put("mipMap", (Boolean) BitmapDrawable.class.getMethod("hasMipMap").invoke(bitmapDrawable));
- json.put("tintMode", (PorterDuff.Mode) BitmapDrawable.class.getMethod("getTintMode").invoke(bitmapDrawable));
- ColorStateList tintList = (ColorStateList) BitmapDrawable.class.getMethod("getTint").invoke(bitmapDrawable);
- if (tintList != null)
- json.put("tintList", getColorStateList(tintList));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- else
- {
-
- if (rippleDrawableClass != null && rippleDrawableClass.isInstance(drawable))
- return getRippleDrawable(drawable, filename, padding);
-
- if (animatedStateListDrawableClass != null && animatedStateListDrawableClass.isInstance(drawable))
- return getAnimatedStateListDrawable(drawable, filename);
-
- if (vectorDrawableClass != null && vectorDrawableClass.isInstance(drawable))
- return getVectorDrawable(drawable, filename, padding);
-
- if (drawable instanceof ScaleDrawable)
- {
- return getDrawable(((ScaleDrawable)drawable).getDrawable(), filename, null);
- }
- if (drawable instanceof LayerDrawable)
- {
- return getLayerDrawable(drawable, filename);
- }
- if (drawable instanceof StateListDrawable)
- {
- return getStateListDrawable(drawable, filename);
- }
- if (drawable instanceof GradientDrawable)
- {
- return getGradientDrawable((GradientDrawable) drawable);
- }
- if (drawable instanceof RotateDrawable)
- {
- return getRotateDrawable((RotateDrawable) drawable, filename);
- }
- if (drawable instanceof AnimationDrawable)
- {
- return getAnimationDrawable((AnimationDrawable) drawable, filename);
- }
- if (drawable instanceof ClipDrawable)
- {
- try {
- json.put("type", "clipDrawable");
- Drawable.ConstantState dcs = ((ClipDrawable)drawable).getConstantState();
- json.put("drawable", getDrawable(getAccessibleField(dcs.getClass(), "mDrawable").get(dcs), filename, null));
- if (null != padding)
- json.put("padding", getJsonRect(padding));
- else {
- Rect _padding = new Rect();
- if (((Drawable) drawable).getPadding(_padding))
- json.put("padding", getJsonRect(_padding));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
- if (drawable instanceof ColorDrawable)
- {
- bmp = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
- Drawable d = (Drawable) drawable;
- d.setBounds(0, 0, 1, 1);
- d.draw(new Canvas(bmp));
- try {
- json.put("type", "color");
- json.put("color", bmp.getPixel(0, 0));
- if (null != padding)
- json.put("padding", getJsonRect(padding));
- else {
- Rect _padding = new Rect();
- if (d.getPadding(_padding))
- json.put("padding", getJsonRect(_padding));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return json;
- }
- if (drawable instanceof InsetDrawable)
- {
- try {
- InsetDrawable d = (InsetDrawable)drawable;
- Object mInsetStateObject = getAccessibleField(InsetDrawable.class, "mState").get(d);
- Rect _padding = new Rect();
- boolean hasPadding = d.getPadding(_padding);
- return getDrawable(getAccessibleField(mInsetStateObject.getClass(), "mDrawable").get(mInsetStateObject), filename, hasPadding ? _padding : null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- else
- {
- Drawable d = (Drawable) drawable;
- int w=d.getIntrinsicWidth();
- int h=d.getIntrinsicHeight();
- d.setLevel(10000);
- if (w<1 || h< 1)
- {
- w=100;
- h=100;
- }
- bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
- d.setBounds(0, 0, w, h);
- d.draw(new Canvas(bmp));
- if (drawable instanceof NinePatchDrawable)
- {
- NinePatchDrawable npd = (NinePatchDrawable) drawable;
- try {
- json.put("type", "9patch");
- json.put("drawable", getDrawable(bmp, filename, null));
- if (padding != null)
- json.put("padding", getJsonRect(padding));
- else {
- Rect _padding = new Rect();
- if (npd.getPadding(_padding))
- json.put("padding", getJsonRect(_padding));
- }
-
- json.put("chunkInfo", findPatchesMarings(d));
- return json;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- FileOutputStream out;
- try {
- filename = m_extractPath+filename+".png";
- out = new FileOutputStream(filename);
- bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- json.put("type", "image");
- json.put("path", filename);
- json.put("width", bmp.getWidth());
- json.put("height", bmp.getHeight());
- m_drawableCache.put(filename, new DrawableCache(json, drawable));
-// MinistroActivity.nativeChmode(filename, 0644);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return json;
- }
-
- public void extractViewInformations(String styleName, int styleId, JSONObject json, String qtClassName, AttributeSet attribSet)
- {
- try {
- int[] viewAttrs;
- viewAttrs = (int[]) styleableClass.getDeclaredField("View").get(null);
- TypedArray a =m_theme.obtainStyledAttributes(attribSet, viewAttrs, styleId, 0);
-
- if (null != qtClassName)
- json.put("qtClass", qtClassName);
- json.put("defaultBackgroundColor", defaultBackgroundColor);
- json.put("defaultTextColorPrimary", defaultTextColor);
- final int N = a.getIndexCount();
- for (int i = 0; i < N; i++) {
- int attr = a.getIndex(i);
- if (attr == View_background)
- json.put("View_background", getDrawable(a.getDrawable(attr), styleName + "_View_background", null));
- else if (attr == View_padding)
- json.put("View_padding", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_paddingLeft)
- json.put("View_paddingLeft", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_paddingTop)
- json.put("View_paddingTop", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_paddingRight)
- json.put("View_paddingRight", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_paddingBottom)
- json.put("View_paddingBottom", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_scrollX)
- json.put("View_paddingBottom", a.getDimensionPixelOffset(attr, 0));
- else if (attr == View_scrollY)
- json.put("View_scrollY", a.getDimensionPixelOffset(attr, 0));
- else if (attr == View_id)
- json.put("View_id", a.getResourceId(attr, -1));
- else if (attr == View_tag)
- json.put("View_tag", a.getText(attr));
- else if (attr == View_fitsSystemWindows)
- json.put("View_fitsSystemWindows", a.getBoolean(attr, false));
- else if (attr == View_focusable)
- json.put("View_focusable", a.getBoolean(attr, false));
- else if (attr == View_focusableInTouchMode)
- json.put("View_focusableInTouchMode", a.getBoolean(attr, false));
- else if (attr == View_clickable)
- json.put("View_clickable", a.getBoolean(attr, false));
- else if (attr == View_longClickable)
- json.put("View_longClickable", a.getBoolean(attr, false));
- else if (attr == View_saveEnabled)
- json.put("View_saveEnabled", a.getBoolean(attr, true));
- else if (attr == View_duplicateParentState)
- json.put("View_duplicateParentState", a.getBoolean(attr, false));
- else if (attr == View_visibility)
- json.put("View_visibility", a.getInt(attr, 0));
- else if (attr == View_drawingCacheQuality)
- json.put("View_drawingCacheQuality", a.getInt(attr, 0));
- else if (attr == View_drawingCacheQuality)
- json.put("View_contentDescription", a.getString(attr));
- else if (attr == View_soundEffectsEnabled)
- json.put("View_soundEffectsEnabled", a.getBoolean(attr, true));
- else if (attr == View_hapticFeedbackEnabled)
- json.put("View_hapticFeedbackEnabled", a.getBoolean(attr, true));
- else if (attr == View_scrollbars)
- json.put("View_scrollbars", a.getInt(attr, 0));
- else if (attr == View_fadingEdge)
- json.put("View_fadingEdge", a.getInt(attr, 0));
- else if (attr == View_scrollbarStyle)
- json.put("View_scrollbarStyle", a.getInt(attr, 0));
- else if (attr == View_scrollbarFadeDuration)
- json.put("View_scrollbarFadeDuration", a.getInt(attr, 0));
- else if (attr == View_scrollbarDefaultDelayBeforeFade)
- json.put("View_scrollbarDefaultDelayBeforeFade", a.getInt(attr, 0));
- else if (attr == View_scrollbarSize)
- json.put("View_scrollbarSize", a.getDimensionPixelSize(attr, -1));
- else if (attr == View_scrollbarThumbHorizontal)
- json.put("View_scrollbarThumbHorizontal", getDrawable(a.getDrawable(attr), styleName + "_View_scrollbarThumbHorizontal", null));
- else if (attr == View_scrollbarThumbVertical)
- json.put("View_scrollbarThumbVertical", getDrawable(a.getDrawable(attr), styleName + "_View_scrollbarThumbVertical", null));
- else if (attr == View_scrollbarTrackHorizontal)
- json.put("View_scrollbarTrackHorizontal", getDrawable(a.getDrawable(attr), styleName + "_View_scrollbarTrackHorizontal", null));
- else if (attr == View_scrollbarTrackVertical)
- json.put("View_scrollbarTrackVertical", getDrawable(a.getDrawable(attr), styleName + "_View_scrollbarTrackVertical", null));
- else if (attr == View_isScrollContainer)
- json.put("View_isScrollContainer", a.getBoolean(attr, false));
- else if (attr == View_keepScreenOn)
- json.put("View_keepScreenOn", a.getBoolean(attr, false));
- else if (attr == View_filterTouchesWhenObscured)
- json.put("View_filterTouchesWhenObscured", a.getBoolean(attr, false));
- else if (attr == View_nextFocusLeft)
- json.put("View_nextFocusLeft", a.getResourceId(attr, -1));
- else if (attr == View_nextFocusRight)
- json.put("View_nextFocusRight", a.getResourceId(attr, -1));
- else if (attr == View_nextFocusUp)
- json.put("View_nextFocusUp", a.getResourceId(attr, -1));
- else if (attr == View_nextFocusDown)
- json.put("View_nextFocusDown", a.getResourceId(attr, -1));
- else if (attr == View_minWidth)
- json.put("View_minWidth", a.getDimensionPixelSize(attr, 0));
- else if (attr == View_minHeight)
- json.put("View_minHeight", a.getDimensionPixelSize(attr, 0));
- else if (attr == View_onClick)
- json.put("View_onClick", a.getString(attr));
- else if (attr == View_overScrollMode)
- json.put("View_overScrollMode", a.getInt(attr, 1));
- else if (attr == View_paddingStart)
- json.put("View_paddingStart", a.getDimensionPixelSize(attr, 0));
- else if (attr == View_paddingEnd)
- json.put("View_paddingEnd", a.getDimensionPixelSize(attr, 0));
- }
- a.recycle();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public JSONObject extractTextAppearance(int styleId)
- {
- JSONObject json = new JSONObject();
- try
- {
- TypedArray a = m_theme.obtainStyledAttributes(styleId, (int[]) styleableClass.getDeclaredField("TextAppearance").get(null));
- int n = a.getIndexCount();
- for (int i = 0; i < n; i++)
- {
- int attr = a.getIndex(i);
- if (attr == TextAppearance_textColorHighlight)
- json.put("TextAppearance_textColorHighlight", a.getColor(attr, 0));
- else if (attr == TextAppearance_textColor)
- json.put("TextAppearance_textColor", getColorStateList(a.getColorStateList(attr)));
- else if (attr == TextAppearance_textColorHint)
- json.put("TextAppearance_textColorHint", getColorStateList(a.getColorStateList(attr)));
- else if (attr == TextAppearance_textColorLink)
- json.put("TextAppearance_textColorLink", getColorStateList(a.getColorStateList(attr)));
- else if (attr == TextAppearance_textSize)
- json.put("TextAppearance_textSize", a.getDimensionPixelSize(attr, 15));
- else if (attr == TextAppearance_typeface)
- json.put("TextAppearance_typeface", a.getInt(attr, -1));
- else if (attr == TextAppearance_textStyle)
- json.put("TextAppearance_textStyle", a.getInt(attr, -1));
- else if (attr == TextAppearance_textAllCaps)
- json.put("TextAppearance_textAllCaps", a.getBoolean(attr, false));
- }
- a.recycle();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return json;
- }
-
- public JSONObject extractTextAppearanceInformations(String styleName, String qtClass, AttributeSet attribSet, int textAppearance)
- {
- JSONObject json = new JSONObject();
- try
- {
- int textColorHighlight = 0; //
- ColorStateList textColor = null; //
- ColorStateList textColorHint = null; //
- ColorStateList textColorLink = null; //
- int textSize = 15; //
- int typefaceIndex = -1; //
- int styleIndex = -1;
- boolean allCaps = false;
-
- Class<?> attrClass= Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- extractViewInformations(styleName, styleId, json, qtClass, attribSet);
-
- int[] textViewAttrs=(int[]) styleableClass.getDeclaredField("TextView").get(null);
- TypedArray a =m_theme.obtainStyledAttributes(null, textViewAttrs, styleId, 0);
-
- TypedArray appearance = null;
- if (-1==textAppearance)
- textAppearance = a.getResourceId(styleableClass.getDeclaredField("TextView_textAppearance").getInt(null), -1);
-
- if (textAppearance != -1)
- appearance = m_theme.obtainStyledAttributes(textAppearance, (int[]) styleableClass.getDeclaredField("TextAppearance").get(null));
-
- if (appearance != null)
- {
- int n = appearance.getIndexCount();
- for (int i = 0; i < n; i++)
- {
- int attr = appearance.getIndex(i);
- if (attr == TextAppearance_textColorHighlight)
- textColorHighlight = appearance.getColor(attr, textColorHighlight);
- else if (attr == TextAppearance_textColor)
- textColor = appearance.getColorStateList(attr);
- else if (attr == TextAppearance_textColorHint)
- textColorHint = appearance.getColorStateList(attr);
- else if (attr == TextAppearance_textColorLink)
- textColorLink = appearance.getColorStateList(attr);
- else if (attr == TextAppearance_textSize)
- textSize = appearance.getDimensionPixelSize(attr, textSize);
- else if (attr == TextAppearance_typeface)
- typefaceIndex = appearance.getInt(attr, -1);
- else if (attr == TextAppearance_textStyle)
- styleIndex = appearance.getInt(attr, -1);
- else if (attr == TextAppearance_textAllCaps)
- allCaps = appearance.getBoolean(attr, false);
- }
- appearance.recycle();
- }
-
- int n = a.getIndexCount();
-
- for (int i = 0; i < n; i++) {
- int attr = a.getIndex(i);
-
- if (attr == TextView_editable)
- json.put("TextView_editable", a.getBoolean(attr, false));
- else if (attr == TextView_inputMethod)
- json.put("TextView_inputMethod", a.getText(attr));
- else if (attr == TextView_numeric)
- json.put("TextView_numeric", a.getInt(attr, 0));
- else if (attr == TextView_digits)
- json.put("TextView_digits", a.getText(attr));
- else if (attr == TextView_phoneNumber)
- json.put("TextView_phoneNumber", a.getBoolean(attr, false));
- else if (attr == TextView_autoText)
- json.put("TextView_autoText", a.getBoolean(attr, false));
- else if (attr == TextView_capitalize)
- json.put("TextView_capitalize", a.getInt(attr, -1));
- else if (attr == TextView_bufferType)
- json.put("TextView_bufferType", a.getInt(attr, 0));
- else if (attr == TextView_selectAllOnFocus)
- json.put("TextView_selectAllOnFocus", a.getBoolean(attr, false));
- else if (attr == TextView_autoLink)
- json.put("TextView_autoLink", a.getInt(attr, 0));
- else if (attr == TextView_linksClickable)
- json.put("TextView_linksClickable", a.getBoolean(attr, true));
- else if (attr == TextView_linksClickable)
- json.put("TextView_linksClickable", a.getBoolean(attr, true));
- else if (attr == TextView_drawableLeft)
- json.put("TextView_drawableLeft", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableLeft", null));
- else if (attr == TextView_drawableTop)
- json.put("TextView_drawableTop", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableTop", null));
- else if (attr == TextView_drawableRight)
- json.put("TextView_drawableRight", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableRight", null));
- else if (attr == TextView_drawableBottom)
- json.put("TextView_drawableBottom", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableBottom", null));
- else if (attr == TextView_drawableStart)
- json.put("TextView_drawableStart", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableStart", null));
- else if (attr == TextView_drawableEnd)
- json.put("TextView_drawableEnd", getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableEnd", null));
- else if (attr == TextView_drawablePadding)
- json.put("TextView_drawablePadding", a.getDimensionPixelSize(attr, 0));
- else if (attr == TextView_textCursorDrawable) {
- try {
- json.put("TextView_textCursorDrawable", getDrawable(a.getDrawable(attr), styleName + "_TextView_textCursorDrawable", null));
- } catch (Exception e_) {
- try {
- json.put("TextView_textCursorDrawable", getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)), styleName + "_TextView_textCursorDrawable", null));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }else if (attr == TextView_maxLines)
- json.put("TextView_maxLines", a.getInt(attr, -1));
- else if (attr == TextView_maxHeight)
- json.put("TextView_maxHeight", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_lines)
- json.put("TextView_lines", a.getInt(attr, -1));
- else if (attr == TextView_height)
- json.put("TextView_height", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_minLines)
- json.put("TextView_minLines", a.getInt(attr, -1));
- else if (attr == TextView_minHeight)
- json.put("TextView_minHeight", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_maxEms)
- json.put("TextView_maxEms", a.getInt(attr, -1));
- else if (attr == TextView_maxWidth)
- json.put("TextView_maxWidth", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_ems)
- json.put("TextView_ems", a.getInt(attr, -1));
- else if (attr == TextView_width)
- json.put("TextView_width", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_minEms)
- json.put("TextView_minEms", a.getInt(attr, -1));
- else if (attr == TextView_minWidth)
- json.put("TextView_minWidth", a.getDimensionPixelSize(attr, -1));
- else if (attr == TextView_gravity)
- json.put("TextView_gravity", a.getInt(attr, -1));
- else if (attr == TextView_hint)
- json.put("TextView_hint", a.getText(attr));
- else if (attr == TextView_text)
- json.put("TextView_text", a.getText(attr));
- else if (attr == TextView_scrollHorizontally)
- json.put("TextView_scrollHorizontally", a.getBoolean(attr, false));
- else if (attr == TextView_singleLine)
- json.put("TextView_singleLine", a.getBoolean(attr, false));
- else if (attr == TextView_ellipsize)
- json.put("TextView_ellipsize", a.getInt(attr, -1));
- else if (attr == TextView_marqueeRepeatLimit)
- json.put("TextView_marqueeRepeatLimit", a.getInt(attr, 3));
- else if (attr == TextView_includeFontPadding)
- json.put("TextView_includeFontPadding", a.getBoolean(attr, true));
- else if (attr == TextView_cursorVisible)
- json.put("TextView_cursorVisible", a.getBoolean(attr, true));
- else if (attr == TextView_maxLength)
- json.put("TextView_maxLength", a.getInt(attr, -1));
- else if (attr == TextView_textScaleX)
- json.put("TextView_textScaleX", a.getFloat(attr, 1.0f));
- else if (attr == TextView_freezesText)
- json.put("TextView_freezesText", a.getBoolean(attr, false));
- else if (attr == TextView_shadowColor)
- json.put("TextView_shadowColor", a.getInt(attr, 0));
- else if (attr == TextView_shadowDx)
- json.put("TextView_shadowDx", a.getFloat(attr, 0));
- else if (attr == TextView_shadowDy)
- json.put("TextView_shadowDy", a.getFloat(attr, 0));
- else if (attr == TextView_shadowRadius)
- json.put("TextView_shadowRadius", a.getFloat(attr, 0));
- else if (attr == TextView_enabled)
- json.put("TextView_enabled", a.getBoolean(attr,true));
- else if (attr == TextView_textColorHighlight)
- textColorHighlight = a.getColor(attr, textColorHighlight);
- else if (attr == TextView_textColor)
- textColor = a.getColorStateList(attr);
- else if (attr == TextView_textColorHint)
- textColorHint = a.getColorStateList(attr);
- else if (attr == TextView_textColorLink)
- textColorLink = a.getColorStateList(attr);
- else if (attr == TextView_textSize)
- textSize = a.getDimensionPixelSize(attr, textSize);
- else if (attr == TextView_typeface)
- typefaceIndex = a.getInt(attr, typefaceIndex);
- else if (attr == TextView_textStyle)
- styleIndex = a.getInt(attr, styleIndex);
- else if (attr == TextView_password)
- json.put("TextView_password", a.getBoolean(attr,false));
- else if (attr == TextView_lineSpacingExtra)
- json.put("TextView_lineSpacingExtra", a.getDimensionPixelSize(attr, 0));
- else if (attr == TextView_lineSpacingMultiplier)
- json.put("TextView_lineSpacingMultiplier", a.getFloat(attr, 1.0f));
- else if (attr == TextView_inputType)
- json.put("TextView_inputType", a.getInt(attr, EditorInfo.TYPE_NULL));
- else if (attr == TextView_imeOptions)
- json.put("TextView_imeOptions", a.getInt(attr, EditorInfo.IME_NULL));
- else if (attr == TextView_imeActionLabel)
- json.put("TextView_imeActionLabel", a.getText(attr));
- else if (attr == TextView_imeActionId)
- json.put("TextView_imeActionId", a.getInt(attr,0));
- else if (attr == TextView_privateImeOptions)
- json.put("TextView_privateImeOptions", a.getString(attr));
- else if (attr == TextView_textSelectHandleLeft && styleName.equals("textViewStyle")) {
- try {
- json.put("TextView_textSelectHandleLeft", getDrawable(a.getDrawable(attr), styleName + "_TextView_textSelectHandleLeft", null));
- } catch (Exception _e) {
- try {
- json.put("TextView_textSelectHandleLeft", getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)), styleName + "_TextView_textSelectHandleLeft", null));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } else if (attr == TextView_textSelectHandleRight && styleName.equals("textViewStyle")) {
- try {
- json.put("TextView_textSelectHandleRight", getDrawable(a.getDrawable(attr), styleName + "_TextView_textSelectHandleRight", null));
- } catch (Exception _e) {
- try {
- json.put("TextView_textSelectHandleRight", getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)), styleName + "_TextView_textSelectHandleRight", null));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } else if (attr == TextView_textSelectHandle && styleName.equals("textViewStyle")) {
- try {
- json.put("TextView_textSelectHandle", getDrawable(a.getDrawable(attr), styleName + "_TextView_textSelectHandle", null));
- } catch (Exception _e) {
- try {
- json.put("TextView_textSelectHandle", getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)), styleName + "_TextView_textSelectHandle", null));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } else if (attr == TextView_textIsSelectable)
- json.put("TextView_textIsSelectable", a.getBoolean(attr, false));
- else if (attr == TextView_textAllCaps)
- allCaps = a.getBoolean(attr, false);
- }
- a.recycle();
-
- json.put("TextAppearance_textColorHighlight",textColorHighlight);
- json.put("TextAppearance_textColor", getColorStateList(textColor));
- json.put("TextAppearance_textColorHint", getColorStateList(textColorHint));
- json.put("TextAppearance_textColorLink", getColorStateList(textColorLink));
- json.put("TextAppearance_textSize",textSize);
- json.put("TextAppearance_typeface",typefaceIndex);
- json.put("TextAppearance_textStyle",styleIndex);
- json.put("TextAppearance_textAllCaps",allCaps);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return json;
- }
-
- final String[] sScaleTypeArray = {
- "MATRIX",
- "FIT_XY",
- "FIT_START",
- "FIT_CENTER",
- "FIT_END",
- "CENTER",
- "CENTER_CROP",
- "CENTER_INSIDE"
- };
-
- public JSONObject extractImageViewInformations(String styleName, String qtClassName )
- {
- JSONObject json = new JSONObject();
- try
- {
- Class<?> attrClass= Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- extractViewInformations(styleName, styleId, json, qtClassName, null);
-
- int[] imageViewAttrs=(int[]) styleableClass.getDeclaredField("ImageView").get(null);
- TypedArray a =m_theme.obtainStyledAttributes(null, imageViewAttrs, styleId, 0);
- Drawable d = a.getDrawable(ImageView_src);
- if (d != null)
- json.put("ImageView_src", getDrawable(d, styleName + "_ImageView_src", null));
-
- json.put("ImageView_baselineAlignBottom", a.getBoolean(ImageView_baselineAlignBottom, false));
- json.put("ImageView_adjustViewBounds", a.getBoolean(ImageView_adjustViewBounds, false));
- json.put("ImageView_maxWidth", a.getDimensionPixelSize(ImageView_maxWidth, Integer.MAX_VALUE));
- json.put("ImageView_maxHeight", a.getDimensionPixelSize(ImageView_maxHeight, Integer.MAX_VALUE));
- int index = a.getInt(ImageView_scaleType, -1);
- if (index >= 0)
- json.put("ImageView_scaleType", sScaleTypeArray[index]);
-
- int tint = a.getInt(ImageView_tint, 0);
- if (tint != 0)
- json.put("ImageView_tint", tint);
-
-
- json.put("ImageView_cropToPadding",a.getBoolean(ImageView_cropToPadding, false));
- a.recycle();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return json;
-
- }
-
- void extractCompoundButton(SimpleJsonWriter jsonWriter, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- Class<?> attrClass;
- try {
- attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
- int[] compoundButtonAttrs=(int[]) styleableClass.getDeclaredField("CompoundButton").get(null);
-
- TypedArray a = m_theme.obtainStyledAttributes(
- null, compoundButtonAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"CompoundButton_button"));
- if (d != null)
- json.put("CompoundButton_button", getDrawable(d, styleName + "_CompoundButton_button", null));
-
- a.recycle();
- jsonWriter.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractProgressBarInfo(JSONObject json, String styleName)
- {
- Class<?> attrClass;
- try {
- attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
- int[] progressBarAttrs=(int[]) styleableClass.getDeclaredField("ProgressBar").get(null);
-
- TypedArray a = m_theme.obtainStyledAttributes(null, progressBarAttrs, styleId, 0);
- int mMinWidth = 24;
- int mMaxWidth = 48;
- int mMinHeight = 24;
- int mMaxHeight = 48;
- mMinWidth = a.getDimensionPixelSize(getField(styleableClass, "ProgressBar_minWidth"), mMinWidth);
- mMaxWidth = a.getDimensionPixelSize(getField(styleableClass, "ProgressBar_maxWidth"), mMaxWidth);
- mMinHeight = a.getDimensionPixelSize(getField(styleableClass, "ProgressBar_minHeight"), mMinHeight);
- mMaxHeight = a.getDimensionPixelSize(getField(styleableClass, "ProgressBar_maxHeight"), mMaxHeight);
-
- json.put("ProgressBar_indeterminateDuration", a.getInt(getField(styleableClass, "ProgressBar_indeterminateDuration"), 4000));
- json.put("ProgressBar_minWidth", mMinWidth);
- json.put("ProgressBar_maxWidth", mMaxWidth);
- json.put("ProgressBar_minHeight", mMinHeight);
- json.put("ProgressBar_maxHeight", mMaxHeight);
- json.put("ProgressBar_progress_id", android.R.id.progress);
- json.put("ProgressBar_secondaryProgress_id", android.R.id.secondaryProgress);
-
- Drawable d = a.getDrawable(getField(styleableClass,"ProgressBar_progressDrawable"));
- if (d != null)
- json.put("ProgressBar_progressDrawable", getDrawable(d, styleName + "_ProgressBar_progressDrawable", null));
-
- d = a.getDrawable(getField(styleableClass,"ProgressBar_indeterminateDrawable"));
- if (d != null)
- json.put("ProgressBar_indeterminateDrawable", getDrawable(d, styleName + "_ProgressBar_indeterminateDrawable", null));
-
- a.recycle();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractProgressBar(SimpleJsonWriter writer, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- try {
- extractProgressBarInfo(json, styleName);
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractAbsSeekBar(SimpleJsonWriter jsonWriter, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- extractProgressBarInfo(json, styleName);
- Class<?> attrClass;
- try {
- attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
- int[] compoundButtonAttrs=(int[]) styleableClass.getDeclaredField("SeekBar").get(null);
-
- TypedArray a = m_theme.obtainStyledAttributes(
- null, compoundButtonAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"SeekBar_thumb"));
- if (d != null)
- json.put("SeekBar_thumb", getDrawable(d, styleName + "_SeekBar_thumb", null));
-
- try {
- json.put("SeekBar_thumbOffset", styleableClass.getDeclaredField("SeekBar_thumbOffset").getInt(null));
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- a.recycle();
- jsonWriter.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractSwitch(SimpleJsonWriter jsonWriter, String styleName, String qtClass)
- {
- JSONObject json = new JSONObject();
- try {
- Class<?> attrClass = Class.forName("com.android.internal.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- int[] switchAttrs = (int[]) styleableClass.getDeclaredField("Switch").get(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, switchAttrs, styleId, 0);
-
- Drawable thumb = a.getDrawable(getField(styleableClass,"Switch_thumb"));
- if (thumb != null)
- json.put("Switch_thumb", getDrawable(thumb, styleName + "_Switch_thumb", null));
-
- Drawable track = a.getDrawable(getField(styleableClass,"Switch_track"));
- if (track != null)
- json.put("Switch_track", getDrawable(track, styleName + "_Switch_track", null));
-
- int textAppearance = a.getResourceId(styleableClass.getDeclaredField("Switch_switchTextAppearance").getInt(null), -1);
- json.put("Switch_switchTextAppearance", extractTextAppearance(textAppearance));
-
- json.put("Switch_textOn", a.getText(getField(styleableClass, "Switch_textOn")));
- json.put("Switch_textOff", a.getText(getField(styleableClass, "Switch_textOff")));
- json.put("Switch_switchMinWidth", a.getDimensionPixelSize(getField(styleableClass, "Switch_switchMinWidth"), 0));
- json.put("Switch_switchPadding", a.getDimensionPixelSize(getField(styleableClass, "Switch_switchPadding"), 0));
- json.put("Switch_thumbTextPadding", a.getDimensionPixelSize(getField(styleableClass, "Switch_thumbTextPadding"), 0));
-
- json.put("Switch_showText", a.getBoolean(getField(styleableClass, "Switch_showText"), true));
- json.put("Switch_splitTrack", a.getBoolean(getField(styleableClass, "Switch_splitTrack"), false));
-
- a.recycle();
- jsonWriter.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- JSONObject extractCheckedTextView(AttributeSet attribSet, String itemName)
- {
- JSONObject json = extractTextAppearanceInformations("textViewStyle", itemName, attribSet, -1);
- try {
- Class<?> attrClass= Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField("textViewStyle").getInt(null);
- int[] compoundButtonAttrs=(int[]) styleableClass.getDeclaredField("CheckedTextView").get(null);
-
- TypedArray a = m_theme.obtainStyledAttributes(attribSet, compoundButtonAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"CheckedTextView_checkMark"));
- if (d != null)
- json.put("CheckedTextView_checkMark", getDrawable(d, itemName+"_CheckedTextView_checkMark", null));
-
- a.recycle();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
-
- private JSONObject extractItemStyle(int resourceId, String itemName, int textAppearance) {
- try
- {
- XmlResourceParser parser = m_context.getResources().getLayout(resourceId);
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG &&
- type != XmlPullParser.END_DOCUMENT) {
- // Empty
- }
-
- if (type != XmlPullParser.START_TAG) {
- return null;
- }
-
- AttributeSet attributes = Xml.asAttributeSet(parser);
- String name = parser.getName();
- if (name.equals("TextView"))
- return extractTextAppearanceInformations("textViewStyle", itemName, attributes, textAppearance);
- if (name.equals("CheckedTextView"))
- return extractCheckedTextView(attributes, itemName);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void extractItemsStyle(SimpleJsonWriter jsonWriter) {
- try
- {
- jsonWriter.name("simple_list_item").value(extractItemStyle(android.R.layout.simple_list_item_1, "simple_list_item", android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_list_item_checked").value(extractItemStyle(android.R.layout.simple_list_item_checked, "simple_list_item_checked", android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_list_item_multiple_choice").value(extractItemStyle(android.R.layout.simple_list_item_multiple_choice, "simple_list_item_multiple_choice", android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_list_item_single_choice").value(extractItemStyle(android.R.layout.simple_list_item_single_choice, "simple_list_item_single_choice", android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_spinner_item").value(extractItemStyle(android.R.layout.simple_spinner_item, "simple_spinner_item", -1));
- jsonWriter.name("simple_spinner_dropdown_item").value(extractItemStyle(android.R.layout.simple_spinner_dropdown_item, "simple_spinner_dropdown_item",android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_dropdown_item_1line").value(extractItemStyle(android.R.layout.simple_dropdown_item_1line, "simple_dropdown_item_1line",android.R.style.TextAppearance_Large));
- jsonWriter.name("simple_selectable_list_item").value(extractItemStyle(android.R.layout.simple_selectable_list_item, "simple_selectable_list_item",android.R.style.TextAppearance_Large));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractListView(SimpleJsonWriter writer, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- try {
- Class<?> attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- int[] styleAttrs = (int[]) styleableClass.getDeclaredField("ListView").get(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, styleAttrs, styleId, 0);
-
- Drawable divider = a.getDrawable(getField(styleableClass,"ListView_divider"));
- if (divider != null)
- json.put("ListView_divider", getDrawable(divider, styleName + "_ListView_divider", null));
-
- json.put("ListView_dividerHeight", a.getDimensionPixelSize(getField(styleableClass, "ListView_dividerHeight"), 0));
-
- a.recycle();
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractCalendar(SimpleJsonWriter writer, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- try {
- Class<?> attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- int[] styleAttrs = (int[]) styleableClass.getDeclaredField("CalendarView").get(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, styleAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"CalendarView_selectedDateVerticalBar"));
- if (d != null)
- json.put("CalendarView_selectedDateVerticalBar", getDrawable(d, styleName + "_CalendarView_selectedDateVerticalBar", null));
-
- int dateTextAppearance = a.getResourceId(styleableClass.getDeclaredField("CalendarView_dateTextAppearance").getInt(null), -1);
- json.put("CalendarView_dateTextAppearance", extractTextAppearance(dateTextAppearance));
-
- int weekDayTextAppearance = a.getResourceId(styleableClass.getDeclaredField("CalendarView_weekDayTextAppearance").getInt(null), -1);
- json.put("CalendarView_weekDayTextAppearance", extractTextAppearance(weekDayTextAppearance));
-
- json.put("CalendarView_firstDayOfWeek", a.getInt(getField(styleableClass, "CalendarView_firstDayOfWeek"), 0));
- json.put("CalendarView_focusedMonthDateColor", a.getColor(getField(styleableClass, "CalendarView_focusedMonthDateColor"), 0));
- json.put("CalendarView_selectedWeekBackgroundColor", a.getColor(getField(styleableClass, "CalendarView_selectedWeekBackgroundColor"), 0));
- json.put("CalendarView_showWeekNumber", a.getBoolean(getField(styleableClass, "CalendarView_showWeekNumber"), true));
- json.put("CalendarView_shownWeekCount", a.getInt(getField(styleableClass, "CalendarView_shownWeekCount"), 6));
- json.put("CalendarView_unfocusedMonthDateColor", a.getColor(getField(styleableClass, "CalendarView_unfocusedMonthDateColor"), 0));
- json.put("CalendarView_weekNumberColor", a.getColor(getField(styleableClass, "CalendarView_weekNumberColor"), 0));
- json.put("CalendarView_weekSeparatorLineColor", a.getColor(getField(styleableClass, "CalendarView_weekSeparatorLineColor"), 0));
-
- a.recycle();
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractToolBar(SimpleJsonWriter writer, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- try {
- Class<?> attrClass = Class.forName("com.android.internal.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- int[] styleAttrs = (int[]) styleableClass.getDeclaredField("ActionBar").get(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, styleAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"ActionBar_background"));
- if (d != null)
- json.put("ActionBar_background", getDrawable(d, styleName + "_ActionBar_background", null));
-
- d = a.getDrawable(getField(styleableClass,"ActionBar_backgroundStacked"));
- if (d != null)
- json.put("ActionBar_backgroundStacked", getDrawable(d, styleName + "_ActionBar_backgroundStacked", null));
-
- d = a.getDrawable(getField(styleableClass,"ActionBar_backgroundSplit"));
- if (d != null)
- json.put("ActionBar_backgroundSplit", getDrawable(d, styleName + "_ActionBar_backgroundSplit", null));
-
- d = a.getDrawable(getField(styleableClass,"ActionBar_divider"));
- if (d != null)
- json.put("ActionBar_divider", getDrawable(d, styleName + "_ActionBar_divider", null));
-
- json.put("ActionBar_itemPadding", a.getDimensionPixelSize(getField(styleableClass, "ActionBar_itemPadding"), 0));
-
- a.recycle();
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void extractTabBar(SimpleJsonWriter writer, String styleName, String qtClass)
- {
- JSONObject json = extractTextAppearanceInformations(styleName, qtClass, null, -1);
- try {
- Class<?> attrClass = Class.forName("android.R$attr");
- int styleId = attrClass.getDeclaredField(styleName).getInt(null);
-
- int[] styleAttrs = (int[]) styleableClass.getDeclaredField("LinearLayout").get(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, styleAttrs, styleId, 0);
-
- Drawable d = a.getDrawable(getField(styleableClass,"LinearLayout_divider"));
- if (d != null)
- json.put("LinearLayout_divider", getDrawable(d, styleName + "_LinearLayout_divider", null));
- json.put("LinearLayout_showDividers", a.getInt(getField(styleableClass, "LinearLayout_showDividers"), 0));
- json.put("LinearLayout_dividerPadding", a.getDimensionPixelSize(getField(styleableClass, "LinearLayout_dividerPadding"), 0));
-
- a.recycle();
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void extractWindow(SimpleJsonWriter writer, String styleName) {
- JSONObject json = new JSONObject();
- try
- {
- Class<?> attrClass = Class.forName("android.R$attr");
- int[] windowAttrs = (int[]) styleableClass.getDeclaredField("Window").get(null);
-
- int backgroundId = attrClass.getDeclaredField("windowBackground").getInt(null);
- TypedArray a = m_theme.obtainStyledAttributes(null, windowAttrs, backgroundId, 0);
- Drawable background = a.getDrawable(getField(styleableClass, "Window_windowBackground"));
- if (background != null)
- json.put("Window_windowBackground", getDrawable(background, styleName + "_Window_windowBackground", null));
- a.recycle();
-
- int frameId = attrClass.getDeclaredField("windowFrame").getInt(null);
- a = m_theme.obtainStyledAttributes(null, windowAttrs, frameId, 0);
- Drawable frame = a.getDrawable(getField(styleableClass, "Window_windowFrame"));
- if (frame != null)
- json.put("Window_windowFrame", getDrawable(frame, styleName + "_Window_windowFrame", null));
- a.recycle();
-
- writer.name(styleName).value(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private JSONObject extractDefaultPalette()
- {
- TypedArray array = m_theme.obtainStyledAttributes(new int[]{
- android.R.attr.textAppearance
- });
- int pos = 0;
- JSONObject json = extractTextAppearance(array.getResourceId(pos++, -1));
- try {
- json.put("defaultBackgroundColor", defaultBackgroundColor);
- json.put("defaultTextColorPrimary", defaultTextColor);
- } catch (Exception e) {
- e.printStackTrace();
- }
- array.recycle();
- return json;
- }
-
- public ExtractStyle(Context context, String extractPath, boolean minimal)
- {
-// Log.i(MinistroService.TAG, "Extract " + extractPath);
- m_minimal = minimal;
- m_extractPath = extractPath + "/";
- new File(m_extractPath).mkdirs();
-// MinistroActivity.nativeChmode(m_extractPath, 0755);
- m_context = context;
- m_theme = context.getTheme();
- TypedArray array = m_theme.obtainStyledAttributes(new int[]{
- android.R.attr.colorBackground,
- android.R.attr.textColorPrimary,
- android.R.attr.textColor
- });
- defaultBackgroundColor = array.getColor(0, 0);
- int textColor = array.getColor(1, 0xFFFFFF);
- if (textColor == 0xFFFFFF)
- textColor = array.getColor(2, 0xFFFFFF);
- defaultTextColor = textColor;
- array.recycle();
-
- try
- {
- SimpleJsonWriter jsonWriter = new SimpleJsonWriter(m_extractPath+"style.json");
- jsonWriter.beginObject();
- try {
- jsonWriter.name("defaultStyle").value(extractDefaultPalette());
- extractWindow(jsonWriter, "windowStyle");
- jsonWriter.name("buttonStyle").value(extractTextAppearanceInformations("buttonStyle", "QPushButton", null, -1));
- jsonWriter.name("spinnerStyle").value(extractTextAppearanceInformations("spinnerStyle", "QComboBox", null, -1));
- extractProgressBar(jsonWriter, "progressBarStyleHorizontal", "QProgressBar");
- extractProgressBar(jsonWriter, "progressBarStyleLarge", null);
- extractProgressBar(jsonWriter, "progressBarStyleSmall", null);
- extractProgressBar(jsonWriter, "progressBarStyle", null);
- extractAbsSeekBar(jsonWriter, "seekBarStyle", "QSlider");
- extractSwitch(jsonWriter, "switchStyle", null);
- extractCompoundButton(jsonWriter, "checkboxStyle", "QCheckBox");
- jsonWriter.name("editTextStyle").value(extractTextAppearanceInformations("editTextStyle", "QLineEdit", null, -1));
- extractCompoundButton(jsonWriter, "radioButtonStyle", "QRadioButton");
- jsonWriter.name("textViewStyle").value(extractTextAppearanceInformations("textViewStyle", "QWidget", null, -1));
- jsonWriter.name("scrollViewStyle").value(extractTextAppearanceInformations("scrollViewStyle", "QAbstractScrollArea", null, -1));
- extractListView(jsonWriter, "listViewStyle", "QListView");
- jsonWriter.name("listSeparatorTextViewStyle").value(extractTextAppearanceInformations("listSeparatorTextViewStyle", null, null, -1));
- extractItemsStyle(jsonWriter);
- extractCompoundButton(jsonWriter, "buttonStyleToggle", null);
- extractCalendar(jsonWriter, "calendarViewStyle", "QCalendarWidget");
- extractToolBar(jsonWriter, "actionBarStyle", "QToolBar");
- jsonWriter.name("actionButtonStyle").value(extractTextAppearanceInformations("actionButtonStyle", "QToolButton", null, -1));
- jsonWriter.name("actionBarTabTextStyle").value(extractTextAppearanceInformations("actionBarTabTextStyle", null, null, -1));
- jsonWriter.name("actionBarTabStyle").value(extractTextAppearanceInformations("actionBarTabStyle", null, null, -1));
- jsonWriter.name("actionOverflowButtonStyle").value(extractImageViewInformations("actionOverflowButtonStyle", null));
- extractTabBar(jsonWriter, "actionBarTabBarStyle", "QTabBar");
- } catch (Exception e) {
- e.printStackTrace();
- }
- jsonWriter.endObject();
- jsonWriter.close();
-// MinistroActivity.nativeChmode(m_extractPath+"style.json", 0644);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
deleted file mode 100644
index 92d9c46043..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ /dev/null
@@ -1,1307 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.AssetManager;
-import android.content.res.Configuration;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.Rect;
-import android.net.LocalServerSocket;
-import android.net.LocalSocket;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.ResultReceiver;
-import android.text.method.MetaKeyKeyListener;
-import android.util.Base64;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.util.TypedValue;
-import android.view.animation.AccelerateInterpolator;
-import android.view.animation.AlphaAnimation;
-import android.view.animation.Animation;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.KeyCharacterMap;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.Surface;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
-import android.view.ViewTreeObserver;
-import android.widget.ImageView;
-import android.widget.PopupMenu;
-import android.hardware.display.DisplayManager;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate;
-
-public class QtActivityDelegate
-{
- private Activity m_activity = null;
- private Method m_super_dispatchKeyEvent = null;
- private Method m_super_onRestoreInstanceState = null;
- private Method m_super_onRetainNonConfigurationInstance = null;
- private Method m_super_onSaveInstanceState = null;
- private Method m_super_onKeyDown = null;
- private Method m_super_onKeyUp = null;
- private Method m_super_onConfigurationChanged = null;
- private Method m_super_onActivityResult = null;
- private Method m_super_dispatchGenericMotionEvent = null;
- private Method m_super_onWindowFocusChanged = null;
-
- private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
- private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
- private static final String MAIN_LIBRARY_KEY = "main.library";
- private static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
- private static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
- private static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
- private static final String NECESSITAS_API_LEVEL_KEY = "necessitas.api.level";
- private static final String EXTRACT_STYLE_KEY = "extract.android.style";
- private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
-
- public static final int SYSTEM_UI_VISIBILITY_NORMAL = 0;
- public static final int SYSTEM_UI_VISIBILITY_FULLSCREEN = 1;
- public static final int SYSTEM_UI_VISIBILITY_TRANSLUCENT = 2;
-
- private static String m_environmentVariables = null;
- private static String m_applicationParameters = null;
-
- private int m_currentRotation = -1; // undefined
- private int m_nativeOrientation = Configuration.ORIENTATION_UNDEFINED;
-
- private String m_mainLib;
- private long m_metaState;
- private int m_lastChar = 0;
- private int m_softInputMode = 0;
- private int m_systemUiVisibility = SYSTEM_UI_VISIBILITY_NORMAL;
- private boolean m_started = false;
- private HashMap<Integer, QtSurface> m_surfaces = null;
- private HashMap<Integer, View> m_nativeViews = null;
- private QtLayout m_layout = null;
- private ImageView m_splashScreen = null;
- private boolean m_splashScreenSticky = false;
- private QtEditText m_editText = null;
- private InputMethodManager m_imm = null;
- private boolean m_quitApp = true;
- private View m_dummyView = null;
- private boolean m_keyboardIsVisible = false;
- public boolean m_backKeyPressedSent = false;
- private long m_showHideTimeStamp = System.nanoTime();
- private int m_portraitKeyboardHeight = 0;
- private int m_landscapeKeyboardHeight = 0;
- private int m_probeKeyboardHeightDelay = 50; // ms
- private CursorHandle m_cursorHandle;
- private CursorHandle m_leftSelectionHandle;
- private CursorHandle m_rightSelectionHandle;
- private EditPopupMenu m_editPopupMenu;
-
-
- public void setSystemUiVisibility(int systemUiVisibility)
- {
- if (m_systemUiVisibility == systemUiVisibility)
- return;
-
- m_systemUiVisibility = systemUiVisibility;
-
- int systemUiVisibilityFlags = 0;
- switch (m_systemUiVisibility) {
- case SYSTEM_UI_VISIBILITY_NORMAL:
- m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
- m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_VISIBLE;
- break;
- case SYSTEM_UI_VISIBILITY_FULLSCREEN:
- m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
- systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
- | View.INVISIBLE;
- break;
- case SYSTEM_UI_VISIBILITY_TRANSLUCENT:
- m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
- | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
- | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_VISIBLE;
- break;
- };
-
- m_activity.getWindow().getDecorView().setSystemUiVisibility(systemUiVisibilityFlags);
-
- m_layout.requestLayout();
- }
-
- public void updateFullScreen()
- {
- if (m_systemUiVisibility == SYSTEM_UI_VISIBILITY_FULLSCREEN) {
- m_systemUiVisibility = SYSTEM_UI_VISIBILITY_NORMAL;
- setSystemUiVisibility(SYSTEM_UI_VISIBILITY_FULLSCREEN);
- }
- }
-
- // input method hints - must be kept in sync with QTDIR/src/corelib/global/qnamespace.h
- private final int ImhHiddenText = 0x1;
- private final int ImhSensitiveData = 0x2;
- private final int ImhNoAutoUppercase = 0x4;
- private final int ImhPreferNumbers = 0x8;
- private final int ImhPreferUppercase = 0x10;
- private final int ImhPreferLowercase = 0x20;
- private final int ImhNoPredictiveText = 0x40;
-
- private final int ImhDate = 0x80;
- private final int ImhTime = 0x100;
-
- private final int ImhPreferLatin = 0x200;
-
- private final int ImhMultiLine = 0x400;
-
- private final int ImhDigitsOnly = 0x10000;
- private final int ImhFormattedNumbersOnly = 0x20000;
- private final int ImhUppercaseOnly = 0x40000;
- private final int ImhLowercaseOnly = 0x80000;
- private final int ImhDialableCharactersOnly = 0x100000;
- private final int ImhEmailCharactersOnly = 0x200000;
- private final int ImhUrlCharactersOnly = 0x400000;
- private final int ImhLatinOnly = 0x800000;
-
- // enter key type - must be kept in sync with QTDIR/src/corelib/global/qnamespace.h
- private final int EnterKeyDefault = 0;
- private final int EnterKeyReturn = 1;
- private final int EnterKeyDone = 2;
- private final int EnterKeyGo = 3;
- private final int EnterKeySend = 4;
- private final int EnterKeySearch = 5;
- private final int EnterKeyNext = 6;
- private final int EnterKeyPrevious = 7;
-
- // application state
- public static final int ApplicationSuspended = 0x0;
- public static final int ApplicationHidden = 0x1;
- public static final int ApplicationInactive = 0x2;
- public static final int ApplicationActive = 0x4;
-
-
- public boolean setKeyboardVisibility(boolean visibility, long timeStamp)
- {
- if (m_showHideTimeStamp > timeStamp)
- return false;
- m_showHideTimeStamp = timeStamp;
-
- if (m_keyboardIsVisible == visibility)
- return false;
- m_keyboardIsVisible = visibility;
- QtNative.keyboardVisibilityChanged(m_keyboardIsVisible);
-
- if (visibility == false)
- updateFullScreen(); // Hiding the keyboard clears the immersive mode, so we need to set it again.
-
- return true;
- }
- public void resetSoftwareKeyboard()
- {
- if (m_imm == null)
- return;
- m_editText.postDelayed(new Runnable() {
- @Override
- public void run() {
- m_imm.restartInput(m_editText);
- m_editText.m_optionsChanged = false;
- }
- }, 5);
- }
-
- public void showSoftwareKeyboard(final int x, final int y, final int width, final int height, final int inputHints, final int enterKeyType)
- {
- if (m_imm == null)
- return;
-
- DisplayMetrics metrics = new DisplayMetrics();
- m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
-
- // If the screen is in portrait mode than we estimate that keyboard height will not be higher than 2/5 of the screen.
- // else than we estimate that keyboard height will not be higher than 2/3 of the screen
- final int visibleHeight;
- if (metrics.widthPixels < metrics.heightPixels)
- visibleHeight = m_portraitKeyboardHeight != 0 ? m_portraitKeyboardHeight : metrics.heightPixels * 3 / 5;
- else
- visibleHeight = m_landscapeKeyboardHeight != 0 ? m_landscapeKeyboardHeight : metrics.heightPixels / 3;
-
- if (m_softInputMode != 0) {
- m_activity.getWindow().setSoftInputMode(m_softInputMode);
- final boolean softInputIsHidden = (m_softInputMode & WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) != 0;
- if (softInputIsHidden)
- return;
- } else {
- if (height > visibleHeight)
- m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- else
- m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
- }
-
- int initialCapsMode = 0;
-
- int imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
-
- switch (enterKeyType) {
- case EnterKeyReturn:
- imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION;
- break;
- case EnterKeyGo:
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO;
- break;
- case EnterKeySend:
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEND;
- break;
- case EnterKeySearch:
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH;
- break;
- case EnterKeyNext:
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_NEXT;
- break;
- case EnterKeyPrevious:
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS;
- break;
- }
-
- int inputType = android.text.InputType.TYPE_CLASS_TEXT;
-
- if ((inputHints & (ImhPreferNumbers | ImhDigitsOnly | ImhFormattedNumbersOnly)) != 0) {
- inputType = android.text.InputType.TYPE_CLASS_NUMBER;
- if ((inputHints & ImhFormattedNumbersOnly) != 0) {
- inputType |= (android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL
- | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED);
- }
-
- if ((inputHints & ImhHiddenText) != 0)
- inputType |= 0x10 /* TYPE_NUMBER_VARIATION_PASSWORD */;
- } else if ((inputHints & ImhDialableCharactersOnly) != 0) {
- inputType = android.text.InputType.TYPE_CLASS_PHONE;
- } else if ((inputHints & (ImhDate | ImhTime)) != 0) {
- inputType = android.text.InputType.TYPE_CLASS_DATETIME;
- if ((inputHints & (ImhDate | ImhTime)) != (ImhDate | ImhTime)) {
- if ((inputHints & ImhDate) != 0)
- inputType |= android.text.InputType.TYPE_DATETIME_VARIATION_DATE;
- if ((inputHints & ImhTime) != 0)
- inputType |= android.text.InputType.TYPE_DATETIME_VARIATION_TIME;
- } // else { TYPE_DATETIME_VARIATION_NORMAL(0) }
- } else { // CLASS_TEXT
- if ((inputHints & (ImhEmailCharactersOnly | ImhUrlCharactersOnly)) != 0) {
- if ((inputHints & ImhUrlCharactersOnly) != 0) {
- inputType |= android.text.InputType.TYPE_TEXT_VARIATION_URI;
-
- if (enterKeyType == 0) // not explicitly overridden
- imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO;
- } else if ((inputHints & ImhEmailCharactersOnly) != 0) {
- inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
- }
- } else if ((inputHints & ImhHiddenText) != 0) {
- inputType |= android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
- } else if ((inputHints & ImhSensitiveData) != 0 ||
- ((inputHints & ImhNoPredictiveText) != 0 &&
- System.getenv("QT_ANDROID_ENABLE_WORKAROUND_TO_DISABLE_PREDICTIVE_TEXT") != null)) {
- inputType |= android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
- }
-
- if ((inputHints & ImhMultiLine) != 0)
- inputType |= android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE;
-
- if ((inputHints & ImhUppercaseOnly) != 0) {
- initialCapsMode |= android.text.TextUtils.CAP_MODE_CHARACTERS;
- inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
- } else if ((inputHints & ImhLowercaseOnly) == 0 && (inputHints & ImhNoAutoUppercase) == 0) {
- initialCapsMode |= android.text.TextUtils.CAP_MODE_SENTENCES;
- inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
- }
-
- if ((inputHints & ImhNoPredictiveText) != 0 || (inputHints & ImhSensitiveData) != 0
- || (inputHints & ImhHiddenText) != 0) {
- inputType |= android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
- }
- }
-
- if (enterKeyType == 0 && (inputHints & ImhMultiLine) != 0)
- imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION;
-
- m_editText.setInitialCapsMode(initialCapsMode);
- m_editText.setImeOptions(imeOptions);
- m_editText.setInputType(inputType);
-
- m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(width, height, x, y), false);
- m_editText.requestFocus();
- m_editText.postDelayed(new Runnable() {
- @Override
- public void run() {
- m_imm.showSoftInput(m_editText, 0, new ResultReceiver(new Handler()) {
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- switch (resultCode) {
- case InputMethodManager.RESULT_SHOWN:
- QtNativeInputConnection.updateCursorPosition();
- //FALLTHROUGH
- case InputMethodManager.RESULT_UNCHANGED_SHOWN:
- setKeyboardVisibility(true, System.nanoTime());
- if (m_softInputMode == 0) {
- // probe for real keyboard height
- m_layout.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (!m_keyboardIsVisible)
- return;
- DisplayMetrics metrics = new DisplayMetrics();
- m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- Rect r = new Rect();
- m_activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
- if (metrics.heightPixels != r.bottom) {
- if (metrics.widthPixels > metrics.heightPixels) { // landscape
- if (m_landscapeKeyboardHeight != r.bottom) {
- m_landscapeKeyboardHeight = r.bottom;
- showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
- }
- } else {
- if (m_portraitKeyboardHeight != r.bottom) {
- m_portraitKeyboardHeight = r.bottom;
- showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
- }
- }
- } else {
- // no luck ?
- // maybe the delay was too short, so let's make it longer
- if (m_probeKeyboardHeightDelay < 1000)
- m_probeKeyboardHeightDelay *= 2;
- }
- }
- }, m_probeKeyboardHeightDelay);
- }
- break;
- case InputMethodManager.RESULT_HIDDEN:
- case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
- setKeyboardVisibility(false, System.nanoTime());
- break;
- }
- }
- });
- if (m_editText.m_optionsChanged) {
- m_imm.restartInput(m_editText);
- m_editText.m_optionsChanged = false;
- }
- }
- }, 15);
- }
-
- public void hideSoftwareKeyboard()
- {
- if (m_imm == null)
- return;
- m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver(new Handler()) {
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- switch (resultCode) {
- case InputMethodManager.RESULT_SHOWN:
- case InputMethodManager.RESULT_UNCHANGED_SHOWN:
- setKeyboardVisibility(true, System.nanoTime());
- break;
- case InputMethodManager.RESULT_HIDDEN:
- case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
- setKeyboardVisibility(false, System.nanoTime());
- break;
- }
- }
- });
- }
-
- String getAppIconSize(Activity a)
- {
- int size = a.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
- if (size < 36 || size > 512) { // check size sanity
- DisplayMetrics metrics = new DisplayMetrics();
- a.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- size = metrics.densityDpi / 10 * 3;
- if (size < 36)
- size = 36;
-
- if (size > 512)
- size = 512;
- }
- return "\tQT_ANDROID_APP_ICON_SIZE=" + size;
- }
-
- public void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)
- {
- if (m_imm == null)
- return;
-
- m_imm.updateSelection(m_editText, selStart, selEnd, candidatesStart, candidatesEnd);
- }
-
- // Values coming from QAndroidInputContext::CursorHandleShowMode
- private static final int CursorHandleNotShown = 0;
- private static final int CursorHandleShowNormal = 1;
- private static final int CursorHandleShowSelection = 2;
- private static final int CursorHandleShowEdit = 0x100;
-
- /* called from the C++ code when the position of the cursor or selection handles needs to
- be adjusted.
- mode is one of QAndroidInputContext::CursorHandleShowMode
- */
- public void updateHandles(int mode, int editX, int editY, int editButtons, int x1, int y1, int x2, int y2, boolean rtl)
- {
- switch (mode & 0xff)
- {
- case CursorHandleNotShown:
- if (m_cursorHandle != null) {
- m_cursorHandle.hide();
- m_cursorHandle = null;
- }
- if (m_rightSelectionHandle != null) {
- m_rightSelectionHandle.hide();
- m_leftSelectionHandle.hide();
- m_rightSelectionHandle = null;
- m_leftSelectionHandle = null;
- }
- if (m_editPopupMenu != null)
- m_editPopupMenu.hide();
- break;
-
- case CursorHandleShowNormal:
- if (m_cursorHandle == null) {
- m_cursorHandle = new CursorHandle(m_activity, m_layout, QtNative.IdCursorHandle,
- android.R.attr.textSelectHandle, false);
- }
- m_cursorHandle.setPosition(x1, y1);
- if (m_rightSelectionHandle != null) {
- m_rightSelectionHandle.hide();
- m_leftSelectionHandle.hide();
- m_rightSelectionHandle = null;
- m_leftSelectionHandle = null;
- }
- break;
-
- case CursorHandleShowSelection:
- if (m_rightSelectionHandle == null) {
- m_leftSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdLeftHandle,
- !rtl ? android.R.attr.textSelectHandleLeft :
- android.R.attr.textSelectHandleRight,
- rtl);
- m_rightSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdRightHandle,
- !rtl ? android.R.attr.textSelectHandleRight :
- android.R.attr.textSelectHandleLeft,
- rtl);
- }
- m_leftSelectionHandle.setPosition(x1,y1);
- m_rightSelectionHandle.setPosition(x2,y2);
- if (m_cursorHandle != null) {
- m_cursorHandle.hide();
- m_cursorHandle = null;
- }
- mode |= CursorHandleShowEdit;
- break;
- }
-
- if (QtNative.hasClipboardText())
- editButtons |= EditContextView.PASTE_BUTTON;
- else
- editButtons &= ~EditContextView.PASTE_BUTTON;
-
- if ((mode & CursorHandleShowEdit) == CursorHandleShowEdit && editButtons != 0) {
- m_editPopupMenu.setPosition(editX, editY, editButtons, m_cursorHandle, m_leftSelectionHandle,
- m_rightSelectionHandle);
- } else {
- if (m_editPopupMenu != null)
- m_editPopupMenu.hide();
- }
- }
-
- public boolean loadApplication(Activity activity, ClassLoader classLoader, Bundle loaderParams)
- {
- /// check parameters integrity
- if (!loaderParams.containsKey(NATIVE_LIBRARIES_KEY)
- || !loaderParams.containsKey(BUNDLED_LIBRARIES_KEY)
- || !loaderParams.containsKey(ENVIRONMENT_VARIABLES_KEY)) {
- return false;
- }
-
- m_activity = activity;
- setActionBarVisibility(false);
- QtNative.setActivity(m_activity, this);
- QtNative.setClassLoader(classLoader);
- if (loaderParams.containsKey(STATIC_INIT_CLASSES_KEY)) {
- for (String className: loaderParams.getStringArray(STATIC_INIT_CLASSES_KEY)) {
- if (className.length() == 0)
- continue;
-
- try {
- Class<?> initClass = classLoader.loadClass(className);
- Object staticInitDataObject = initClass.newInstance(); // create an instance
- try {
- Method m = initClass.getMethod("setActivity", Activity.class, Object.class);
- m.invoke(staticInitDataObject, m_activity, this);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- try {
- Method m = initClass.getMethod("setContext", Context.class);
- m.invoke(staticInitDataObject, (Context)m_activity);
- } catch (Exception e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- QtNative.loadQtLibraries(loaderParams.getStringArrayList(NATIVE_LIBRARIES_KEY));
- ArrayList<String> libraries = loaderParams.getStringArrayList(BUNDLED_LIBRARIES_KEY);
- String nativeLibsDir = QtNativeLibrariesDir.nativeLibrariesDir(m_activity);
- QtNative.loadBundledLibraries(libraries, nativeLibsDir);
- m_mainLib = loaderParams.getString(MAIN_LIBRARY_KEY);
- // older apps provide the main library as the last bundled library; look for this if the main library isn't provided
- if (null == m_mainLib && libraries.size() > 0) {
- m_mainLib = libraries.get(libraries.size() - 1);
- libraries.remove(libraries.size() - 1);
- }
-
- if (loaderParams.containsKey(EXTRACT_STYLE_KEY)) {
- String path = loaderParams.getString(EXTRACT_STYLE_KEY);
- new ExtractStyle(m_activity, path, loaderParams.containsKey(EXTRACT_STYLE_MINIMAL_KEY) &&
- loaderParams.getBoolean(EXTRACT_STYLE_MINIMAL_KEY));
- }
-
- try {
- m_super_dispatchKeyEvent = m_activity.getClass().getMethod("super_dispatchKeyEvent", KeyEvent.class);
- m_super_onRestoreInstanceState = m_activity.getClass().getMethod("super_onRestoreInstanceState", Bundle.class);
- m_super_onRetainNonConfigurationInstance = m_activity.getClass().getMethod("super_onRetainNonConfigurationInstance");
- m_super_onSaveInstanceState = m_activity.getClass().getMethod("super_onSaveInstanceState", Bundle.class);
- m_super_onKeyDown = m_activity.getClass().getMethod("super_onKeyDown", Integer.TYPE, KeyEvent.class);
- m_super_onKeyUp = m_activity.getClass().getMethod("super_onKeyUp", Integer.TYPE, KeyEvent.class);
- m_super_onConfigurationChanged = m_activity.getClass().getMethod("super_onConfigurationChanged", Configuration.class);
- m_super_onActivityResult = m_activity.getClass().getMethod("super_onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class);
- m_super_onWindowFocusChanged = m_activity.getClass().getMethod("super_onWindowFocusChanged", Boolean.TYPE);
- m_super_dispatchGenericMotionEvent = m_activity.getClass().getMethod("super_dispatchGenericMotionEvent", MotionEvent.class);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
- int necessitasApiLevel = 1;
- if (loaderParams.containsKey(NECESSITAS_API_LEVEL_KEY))
- necessitasApiLevel = loaderParams.getInt(NECESSITAS_API_LEVEL_KEY);
-
- m_environmentVariables = loaderParams.getString(ENVIRONMENT_VARIABLES_KEY);
- String additionalEnvironmentVariables = "QT_ANDROID_FONTS_MONOSPACE=Droid Sans Mono;Droid Sans;Droid Sans Fallback"
- + "\tQT_ANDROID_FONTS_SERIF=Droid Serif"
- + "\tNECESSITAS_API_LEVEL=" + necessitasApiLevel
- + "\tHOME=" + m_activity.getFilesDir().getAbsolutePath()
- + "\tTMPDIR=" + m_activity.getFilesDir().getAbsolutePath();
-
- additionalEnvironmentVariables += "\tQT_ANDROID_FONTS=Roboto;Droid Sans;Droid Sans Fallback";
-
- additionalEnvironmentVariables += getAppIconSize(activity);
-
- if (m_environmentVariables != null && m_environmentVariables.length() > 0)
- m_environmentVariables = additionalEnvironmentVariables + "\t" + m_environmentVariables;
- else
- m_environmentVariables = additionalEnvironmentVariables;
-
- if (loaderParams.containsKey(APPLICATION_PARAMETERS_KEY))
- m_applicationParameters = loaderParams.getString(APPLICATION_PARAMETERS_KEY);
- else
- m_applicationParameters = "";
-
- try {
- m_softInputMode = m_activity.getPackageManager().getActivityInfo(m_activity.getComponentName(), 0).softInputMode;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener() {
- @Override
- public void onDisplayAdded(int displayId) { }
-
- @Override
- public void onDisplayChanged(int displayId) {
- m_currentRotation = m_activity.getWindowManager().getDefaultDisplay().getRotation();
- QtNative.handleOrientationChanged(m_currentRotation, m_nativeOrientation);
- }
-
- @Override
- public void onDisplayRemoved(int displayId) { }
- };
-
- try {
- DisplayManager displayManager = (DisplayManager) m_activity.getSystemService(Context.DISPLAY_SERVICE);
- displayManager.registerDisplayListener(displayListener, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- m_mainLib = QtNative.loadMainLibrary(m_mainLib, nativeLibsDir);
- return m_mainLib != null;
- }
-
- public boolean startApplication()
- {
- // start application
- try {
-
- Bundle extras = m_activity.getIntent().getExtras();
- if (extras != null) {
- try {
- final boolean isDebuggable = (m_activity.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
- if (!isDebuggable)
- throw new Exception();
-
- if (extras.containsKey("extraenvvars")) {
- try {
- m_environmentVariables += "\t" + new String(Base64.decode(extras.getString("extraenvvars"), Base64.DEFAULT), "UTF-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- if (extras.containsKey("extraappparams")) {
- try {
- m_applicationParameters += "\t" + new String(Base64.decode(extras.getString("extraappparams"), Base64.DEFAULT), "UTF-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- Log.e(QtNative.QtTAG, "Not in debug mode! It is not allowed to use " +
- "extra arguments in non-debug mode.");
- // This is not an error, so keep it silent
- // e.printStackTrace();
- }
- } // extras != null
-
- if (null == m_surfaces)
- onCreate(null);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public void onTerminate()
- {
- QtNative.terminateQt();
- QtNative.m_qtThread.exit();
- }
-
- public void onCreate(Bundle savedInstanceState)
- {
- m_quitApp = true;
- Runnable startApplication = null;
- if (null == savedInstanceState) {
- startApplication = new Runnable() {
- @Override
- public void run() {
- try {
- QtNative.startApplication(m_applicationParameters, m_environmentVariables, m_mainLib);
- m_started = true;
- } catch (Exception e) {
- e.printStackTrace();
- m_activity.finish();
- }
- }
- };
- }
- m_layout = new QtLayout(m_activity, startApplication);
-
- int orientation = m_activity.getResources().getConfiguration().orientation;
-
- try {
- ActivityInfo info = m_activity.getPackageManager().getActivityInfo(m_activity.getComponentName(), PackageManager.GET_META_DATA);
-
- String splashScreenKey = "android.app.splash_screen_drawable_"
- + (orientation == Configuration.ORIENTATION_LANDSCAPE ? "landscape" : "portrait");
- if (!info.metaData.containsKey(splashScreenKey))
- splashScreenKey = "android.app.splash_screen_drawable";
-
- if (info.metaData.containsKey(splashScreenKey)) {
- m_splashScreenSticky = info.metaData.containsKey("android.app.splash_screen_sticky") && info.metaData.getBoolean("android.app.splash_screen_sticky");
- int id = info.metaData.getInt(splashScreenKey);
- m_splashScreen = new ImageView(m_activity);
- m_splashScreen.setImageDrawable(m_activity.getResources().getDrawable(id));
- m_splashScreen.setScaleType(ImageView.ScaleType.FIT_XY);
- m_splashScreen.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
- m_layout.addView(m_splashScreen);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- m_editText = new QtEditText(m_activity, this);
- m_imm = (InputMethodManager)m_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- m_surfaces = new HashMap<Integer, QtSurface>();
- m_nativeViews = new HashMap<Integer, View>();
- m_activity.registerForContextMenu(m_layout);
- m_activity.setContentView(m_layout,
- new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT));
-
- int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation();
- boolean rot90 = (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270);
- boolean currentlyLandscape = (orientation == Configuration.ORIENTATION_LANDSCAPE);
- if ((currentlyLandscape && !rot90) || (!currentlyLandscape && rot90))
- m_nativeOrientation = Configuration.ORIENTATION_LANDSCAPE;
- else
- m_nativeOrientation = Configuration.ORIENTATION_PORTRAIT;
-
- QtNative.handleOrientationChanged(rotation, m_nativeOrientation);
- m_currentRotation = rotation;
-
- m_layout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
- @Override
- public boolean onPreDraw() {
- if (!m_keyboardIsVisible)
- return true;
-
- Rect r = new Rect();
- m_activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
- DisplayMetrics metrics = new DisplayMetrics();
- m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- final int kbHeight = metrics.heightPixels - r.bottom;
- final int[] location = new int[2];
- m_layout.getLocationOnScreen(location);
- QtNative.keyboardGeometryChanged(location[0], r.bottom - location[1],
- r.width(), kbHeight);
- return true;
- }
- });
- m_editPopupMenu = new EditPopupMenu(m_activity, m_layout);
- }
-
- public void hideSplashScreen()
- {
- hideSplashScreen(0);
- }
-
- public void hideSplashScreen(final int duration)
- {
- if (m_splashScreen == null)
- return;
-
- if (duration <= 0) {
- m_layout.removeView(m_splashScreen);
- m_splashScreen = null;
- return;
- }
-
- final Animation fadeOut = new AlphaAnimation(1, 0);
- fadeOut.setInterpolator(new AccelerateInterpolator());
- fadeOut.setDuration(duration);
-
- fadeOut.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationEnd(Animation animation) { hideSplashScreen(0); }
-
- @Override
- public void onAnimationRepeat(Animation animation) {}
-
- @Override
- public void onAnimationStart(Animation animation) {}
- });
-
- m_splashScreen.startAnimation(fadeOut);
- }
-
-
- public void initializeAccessibility()
- {
- new QtAccessibilityDelegate(m_activity, m_layout, this);
- }
-
- public void onWindowFocusChanged(boolean hasFocus) {
- try {
- m_super_onWindowFocusChanged.invoke(m_activity, hasFocus);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (hasFocus)
- updateFullScreen();
- }
-
- public void onConfigurationChanged(Configuration configuration)
- {
- try {
- m_super_onConfigurationChanged.invoke(m_activity, configuration);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void onDestroy()
- {
- if (m_quitApp) {
- QtNative.terminateQt();
- QtNative.setActivity(null, null);
- QtNative.m_qtThread.exit();
- System.exit(0);
- }
- }
-
- public void onPause()
- {
- if (Build.VERSION.SDK_INT < 24 || !m_activity.isInMultiWindowMode())
- QtNative.setApplicationState(ApplicationInactive);
- }
-
- public void onResume()
- {
- QtNative.setApplicationState(ApplicationActive);
- if (m_started) {
- QtNative.updateWindow();
- updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again.
- }
- }
-
- public void onNewIntent(Intent data)
- {
- QtNative.onNewIntent(data);
- }
-
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- try {
- m_super_onActivityResult.invoke(m_activity, requestCode, resultCode, data);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- QtNative.onActivityResult(requestCode, resultCode, data);
- }
-
-
- public void onStop()
- {
- QtNative.setApplicationState(ApplicationSuspended);
- }
-
- public Object onRetainNonConfigurationInstance()
- {
- try {
- m_super_onRetainNonConfigurationInstance.invoke(m_activity);
- } catch (Exception e) {
- e.printStackTrace();
- }
- m_quitApp = false;
- return true;
- }
-
- public void onSaveInstanceState(Bundle outState) {
- try {
- m_super_onSaveInstanceState.invoke(m_activity, outState);
- } catch (Exception e) {
- e.printStackTrace();
- }
- outState.putInt("SystemUiVisibility", m_systemUiVisibility);
- outState.putBoolean("Started", m_started);
- // It should never
- }
-
- public void onRestoreInstanceState(Bundle savedInstanceState)
- {
- try {
- m_super_onRestoreInstanceState.invoke(m_activity, savedInstanceState);
- } catch (Exception e) {
- e.printStackTrace();
- }
- m_started = savedInstanceState.getBoolean("Started");
- // FIXME restore all surfaces
-
- }
-
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (!m_started)
- return false;
-
- m_metaState = MetaKeyKeyListener.handleKeyDown(m_metaState, keyCode, event);
- int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(m_metaState) | event.getMetaState());
- int lc = c;
- m_metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(m_metaState);
-
- if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
- c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
- int composed = KeyEvent.getDeadChar(m_lastChar, c);
- c = composed;
- }
-
- if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP
- || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
- || keyCode == KeyEvent.KEYCODE_MUTE)
- && System.getenv("QT_ANDROID_VOLUME_KEYS") == null) {
- return false;
- }
-
- m_lastChar = lc;
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- m_backKeyPressedSent = !m_keyboardIsVisible;
- if (!m_backKeyPressedSent)
- return true;
- }
- QtNative.keyDown(keyCode, c, event.getMetaState(), event.getRepeatCount() > 0);
-
- return true;
- }
-
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
- if (!m_started)
- return false;
-
- if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP
- || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
- || keyCode == KeyEvent.KEYCODE_MUTE)
- && System.getenv("QT_ANDROID_VOLUME_KEYS") == null) {
- return false;
- }
-
- if (keyCode == KeyEvent.KEYCODE_BACK && !m_backKeyPressedSent) {
- hideSoftwareKeyboard();
- setKeyboardVisibility(false, System.nanoTime());
- return true;
- }
-
- m_metaState = MetaKeyKeyListener.handleKeyUp(m_metaState, keyCode, event);
- QtNative.keyUp(keyCode, event.getUnicodeChar(), event.getMetaState(), event.getRepeatCount() > 0);
- return true;
- }
-
- public boolean dispatchKeyEvent(KeyEvent event)
- {
- if (m_started
- && event.getAction() == KeyEvent.ACTION_MULTIPLE
- && event.getCharacters() != null
- && event.getCharacters().length() == 1
- && event.getKeyCode() == 0) {
- QtNative.keyDown(0, event.getCharacters().charAt(0), event.getMetaState(), event.getRepeatCount() > 0);
- QtNative.keyUp(0, event.getCharacters().charAt(0), event.getMetaState(), event.getRepeatCount() > 0);
- }
-
- if (QtNative.dispatchKeyEvent(event))
- return true;
-
- try {
- return (Boolean) m_super_dispatchKeyEvent.invoke(m_activity, event);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
-
- private boolean m_optionsMenuIsVisible = false;
- public boolean onCreateOptionsMenu(Menu menu)
- {
- menu.clear();
- return true;
- }
- public boolean onPrepareOptionsMenu(Menu menu)
- {
- m_optionsMenuIsVisible = true;
- boolean res = QtNative.onPrepareOptionsMenu(menu);
- setActionBarVisibility(res && menu.size() > 0);
- return res;
- }
-
- public boolean onOptionsItemSelected(MenuItem item)
- {
- return QtNative.onOptionsItemSelected(item.getItemId(), item.isChecked());
- }
-
- public void onOptionsMenuClosed(Menu menu)
- {
- m_optionsMenuIsVisible = false;
- QtNative.onOptionsMenuClosed(menu);
- }
-
- public void resetOptionsMenu()
- {
- m_activity.invalidateOptionsMenu();
- }
-
- private boolean m_contextMenuVisible = false;
- public void onCreateContextMenu(ContextMenu menu,
- View v,
- ContextMenuInfo menuInfo)
- {
- menu.clearHeader();
- QtNative.onCreateContextMenu(menu);
- m_contextMenuVisible = true;
- }
-
- public void onCreatePopupMenu(Menu menu)
- {
- QtNative.fillContextMenu(menu);
- m_contextMenuVisible = true;
- }
-
- public void onContextMenuClosed(Menu menu)
- {
- if (!m_contextMenuVisible)
- return;
- m_contextMenuVisible = false;
- QtNative.onContextMenuClosed(menu);
- }
-
- public boolean onContextItemSelected(MenuItem item)
- {
- m_contextMenuVisible = false;
- return QtNative.onContextItemSelected(item.getItemId(), item.isChecked());
- }
-
- public void openContextMenu(final int x, final int y, final int w, final int h)
- {
- m_layout.postDelayed(new Runnable() {
- @Override
- public void run() {
- m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(w, h, x, y), false);
- PopupMenu popup = new PopupMenu(m_activity, m_editText);
- QtActivityDelegate.this.onCreatePopupMenu(popup.getMenu());
- popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem menuItem) {
- return QtActivityDelegate.this.onContextItemSelected(menuItem);
- }
- });
- popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
- @Override
- public void onDismiss(PopupMenu popupMenu) {
- QtActivityDelegate.this.onContextMenuClosed(popupMenu.getMenu());
- }
- });
- popup.show();
- }
- }, 100);
- }
-
- public void closeContextMenu()
- {
- m_activity.closeContextMenu();
- }
-
- private void setActionBarVisibility(boolean visible)
- {
- if (m_activity.getActionBar() == null)
- return;
- if (ViewConfiguration.get(m_activity).hasPermanentMenuKey() || !visible)
- m_activity.getActionBar().hide();
- else
- m_activity.getActionBar().show();
- }
-
- public void insertNativeView(int id, View view, int x, int y, int w, int h) {
- if (m_dummyView != null) {
- m_layout.removeView(m_dummyView);
- m_dummyView = null;
- }
-
- if (m_nativeViews.containsKey(id))
- m_layout.removeView(m_nativeViews.remove(id));
-
- if (w < 0 || h < 0) {
- view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT));
- } else {
- view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
- }
-
- view.setId(id);
- m_layout.addView(view);
- m_nativeViews.put(id, view);
- }
-
- public void createSurface(int id, boolean onTop, int x, int y, int w, int h, int imageDepth) {
- if (m_surfaces.size() == 0) {
- TypedValue attr = new TypedValue();
- m_activity.getTheme().resolveAttribute(android.R.attr.windowBackground, attr, true);
- if (attr.type >= TypedValue.TYPE_FIRST_COLOR_INT && attr.type <= TypedValue.TYPE_LAST_COLOR_INT) {
- m_activity.getWindow().setBackgroundDrawable(new ColorDrawable(attr.data));
- } else {
- m_activity.getWindow().setBackgroundDrawable(m_activity.getResources().getDrawable(attr.resourceId));
- }
- if (m_dummyView != null) {
- m_layout.removeView(m_dummyView);
- m_dummyView = null;
- }
- }
-
- if (m_surfaces.containsKey(id))
- m_layout.removeView(m_surfaces.remove(id));
-
- QtSurface surface = new QtSurface(m_activity, id, onTop, imageDepth);
- if (w < 0 || h < 0) {
- surface.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT));
- } else {
- surface.setLayoutParams( new QtLayout.LayoutParams(w, h, x, y));
- }
-
- // Native views are always inserted in the end of the stack (i.e., on top).
- // All other views are stacked based on the order they are created.
- final int surfaceCount = getSurfaceCount();
- m_layout.addView(surface, surfaceCount);
-
- m_surfaces.put(id, surface);
- if (!m_splashScreenSticky)
- hideSplashScreen();
- }
-
- public void setSurfaceGeometry(int id, int x, int y, int w, int h) {
- if (m_surfaces.containsKey(id)) {
- QtSurface surface = m_surfaces.get(id);
- surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
- } else if (m_nativeViews.containsKey(id)) {
- View view = m_nativeViews.get(id);
- view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
- } else {
- Log.e(QtNative.QtTAG, "Surface " + id +" not found!");
- return;
- }
- }
-
- public void destroySurface(int id) {
- View view = null;
-
- if (m_surfaces.containsKey(id)) {
- view = m_surfaces.remove(id);
- } else if (m_nativeViews.containsKey(id)) {
- view = m_nativeViews.remove(id);
- } else {
- Log.e(QtNative.QtTAG, "Surface " + id +" not found!");
- }
-
- if (view == null)
- return;
-
- // Keep last frame in stack until it is replaced to get correct
- // shutdown transition
- if (m_surfaces.size() == 0 && m_nativeViews.size() == 0) {
- m_dummyView = view;
- } else {
- m_layout.removeView(view);
- }
- }
-
- public int getSurfaceCount()
- {
- return m_surfaces.size();
- }
-
- public void bringChildToFront(int id)
- {
- View view = m_surfaces.get(id);
- if (view != null) {
- final int surfaceCount = getSurfaceCount();
- if (surfaceCount > 0)
- m_layout.moveChild(view, surfaceCount - 1);
- return;
- }
-
- view = m_nativeViews.get(id);
- if (view != null)
- m_layout.moveChild(view, -1);
- }
-
- public void bringChildToBack(int id)
- {
- View view = m_surfaces.get(id);
- if (view != null) {
- m_layout.moveChild(view, 0);
- return;
- }
-
- view = m_nativeViews.get(id);
- if (view != null) {
- final int index = getSurfaceCount();
- m_layout.moveChild(view, index);
- }
- }
-
- public boolean dispatchGenericMotionEvent (MotionEvent ev)
- {
- if (m_started && QtNative.dispatchGenericMotionEvent(ev))
- return true;
-
- try {
- return (Boolean) m_super_dispatchGenericMotionEvent.invoke(m_activity, ev);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
-
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
- {
- QtNative.sendRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtEditText.java b/src/android/jar/src/org/qtproject/qt5/android/QtEditText.java
deleted file mode 100644
index e6da5482ca..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtEditText.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.content.Context;
-import android.text.InputType;
-import android.view.View;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputConnection;
-
-public class QtEditText extends View
-{
- int m_initialCapsMode = 0;
- int m_imeOptions = 0;
- int m_inputType = InputType.TYPE_CLASS_TEXT;
- boolean m_optionsChanged = false;
- QtActivityDelegate m_activityDelegate;
-
- public void setImeOptions(int m_imeOptions)
- {
- if (m_imeOptions == this.m_imeOptions)
- return;
- this.m_imeOptions = m_imeOptions;
- m_optionsChanged = true;
- }
-
- public void setInitialCapsMode(int m_initialCapsMode)
- {
- if (m_initialCapsMode == this.m_initialCapsMode)
- return;
- this.m_initialCapsMode = m_initialCapsMode;
- m_optionsChanged = true;
- }
-
-
- public void setInputType(int m_inputType)
- {
- if (m_inputType == this.m_inputType)
- return;
- this.m_inputType = m_inputType;
- m_optionsChanged = true;
- }
-
- public QtEditText(Context context, QtActivityDelegate activityDelegate)
- {
- super(context);
- setFocusable(true);
- setFocusableInTouchMode(true);
- m_activityDelegate = activityDelegate;
- }
- public QtActivityDelegate getActivityDelegate()
- {
- return m_activityDelegate;
- }
-
- @Override
- public InputConnection onCreateInputConnection(EditorInfo outAttrs)
- {
- outAttrs.inputType = m_inputType;
- outAttrs.imeOptions = m_imeOptions;
- outAttrs.initialCapsMode = m_initialCapsMode;
- outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
- return new QtInputConnection(this);
- }
-
-// // DEBUG CODE
-// @Override
-// protected void onDraw(Canvas canvas) {
-// canvas.drawARGB(127, 255, 0, 255);
-// super.onDraw(canvas);
-// }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java b/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java
deleted file mode 100644
index 7c621a11e2..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.content.Context;
-import android.view.inputmethod.BaseInputConnection;
-import android.view.inputmethod.CompletionInfo;
-import android.view.inputmethod.ExtractedText;
-import android.view.inputmethod.ExtractedTextRequest;
-import android.view.inputmethod.InputMethodManager;
-import android.graphics.Rect;
-import android.app.Activity;
-import android.util.DisplayMetrics;
-
-class QtExtractedText
-{
- public int partialEndOffset;
- public int partialStartOffset;
- public int selectionEnd;
- public int selectionStart;
- public int startOffset;
- public String text;
-}
-
-class QtNativeInputConnection
-{
- static native boolean beginBatchEdit();
- static native boolean endBatchEdit();
- static native boolean commitText(String text, int newCursorPosition);
- static native boolean commitCompletion(String text, int position);
- static native boolean deleteSurroundingText(int leftLength, int rightLength);
- static native boolean finishComposingText();
- static native int getCursorCapsMode(int reqModes);
- static native QtExtractedText getExtractedText(int hintMaxChars, int hintMaxLines, int flags);
- static native String getSelectedText(int flags);
- static native String getTextAfterCursor(int length, int flags);
- static native String getTextBeforeCursor(int length, int flags);
- static native boolean setComposingText(String text, int newCursorPosition);
- static native boolean setComposingRegion(int start, int end);
- static native boolean setSelection(int start, int end);
- static native boolean selectAll();
- static native boolean cut();
- static native boolean copy();
- static native boolean copyURL();
- static native boolean paste();
- static native boolean updateCursorPosition();
-}
-
-class HideKeyboardRunnable implements Runnable {
- private long m_hideTimeStamp = System.nanoTime();
-
- @Override
- public void run() {
- // Check that the keyboard is really no longer there.
- Activity activity = QtNative.activity();
- Rect r = new Rect();
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
- DisplayMetrics metrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- final int kbHeight = metrics.heightPixels - r.bottom;
- if (kbHeight < 100)
- QtNative.activityDelegate().setKeyboardVisibility(false, m_hideTimeStamp);
- }
-}
-
-public class QtInputConnection extends BaseInputConnection
-{
- private static final int ID_SELECT_ALL = android.R.id.selectAll;
- private static final int ID_CUT = android.R.id.cut;
- private static final int ID_COPY = android.R.id.copy;
- private static final int ID_PASTE = android.R.id.paste;
- private static final int ID_COPY_URL = android.R.id.copyUrl;
- private static final int ID_SWITCH_INPUT_METHOD = android.R.id.switchInputMethod;
- private static final int ID_ADD_TO_DICTIONARY = android.R.id.addToDictionary;
-
- private QtEditText m_view = null;
-
- private void setClosing(boolean closing)
- {
- if (closing) {
- m_view.postDelayed(new HideKeyboardRunnable(), 100);
- } else {
- QtNative.activityDelegate().setKeyboardVisibility(true, System.nanoTime());
- }
- }
-
- public QtInputConnection(QtEditText targetView)
- {
- super(targetView, true);
- m_view = targetView;
- }
-
- @Override
- public boolean beginBatchEdit()
- {
- setClosing(false);
- return QtNativeInputConnection.beginBatchEdit();
- }
-
- @Override
- public boolean endBatchEdit()
- {
- setClosing(false);
- return QtNativeInputConnection.endBatchEdit();
- }
-
- @Override
- public boolean commitCompletion(CompletionInfo text)
- {
- setClosing(false);
- return QtNativeInputConnection.commitCompletion(text.getText().toString(), text.getPosition());
- }
-
- @Override
- public boolean commitText(CharSequence text, int newCursorPosition)
- {
- setClosing(false);
- return QtNativeInputConnection.commitText(text.toString(), newCursorPosition);
- }
-
- @Override
- public boolean deleteSurroundingText(int leftLength, int rightLength)
- {
- setClosing(false);
- return QtNativeInputConnection.deleteSurroundingText(leftLength, rightLength);
- }
-
- @Override
- public boolean finishComposingText()
- {
- // on some/all android devices hide event is not coming, but instead finishComposingText() is called twice
- setClosing(true);
- return QtNativeInputConnection.finishComposingText();
- }
-
- @Override
- public int getCursorCapsMode(int reqModes)
- {
- return QtNativeInputConnection.getCursorCapsMode(reqModes);
- }
-
- @Override
- public ExtractedText getExtractedText(ExtractedTextRequest request, int flags)
- {
- QtExtractedText qExtractedText = QtNativeInputConnection.getExtractedText(request.hintMaxChars,
- request.hintMaxLines,
- flags);
- if (qExtractedText == null)
- return null;
-
- ExtractedText extractedText = new ExtractedText();
- extractedText.partialEndOffset = qExtractedText.partialEndOffset;
- extractedText.partialStartOffset = qExtractedText.partialStartOffset;
- extractedText.selectionEnd = qExtractedText.selectionEnd;
- extractedText.selectionStart = qExtractedText.selectionStart;
- extractedText.startOffset = qExtractedText.startOffset;
- extractedText.text = qExtractedText.text;
- return extractedText;
- }
-
- public CharSequence getSelectedText(int flags)
- {
- return QtNativeInputConnection.getSelectedText(flags);
- }
-
- @Override
- public CharSequence getTextAfterCursor(int length, int flags)
- {
- return QtNativeInputConnection.getTextAfterCursor(length, flags);
- }
-
- @Override
- public CharSequence getTextBeforeCursor(int length, int flags)
- {
- return QtNativeInputConnection.getTextBeforeCursor(length, flags);
- }
-
- @Override
- public boolean performContextMenuAction(int id)
- {
- switch (id) {
- case ID_SELECT_ALL:
- return QtNativeInputConnection.selectAll();
- case ID_COPY:
- return QtNativeInputConnection.copy();
- case ID_COPY_URL:
- return QtNativeInputConnection.copyURL();
- case ID_CUT:
- return QtNativeInputConnection.cut();
- case ID_PASTE:
- return QtNativeInputConnection.paste();
-
- case ID_SWITCH_INPUT_METHOD:
- InputMethodManager imm = (InputMethodManager)m_view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null)
- imm.showInputMethodPicker();
-
- return true;
-
- case ID_ADD_TO_DICTIONARY:
-// TODO
-// String word = m_editable.subSequence(0, m_editable.length()).toString();
-// if (word != null) {
-// Intent i = new Intent("com.android.settings.USER_DICTIONARY_INSERT");
-// i.putExtra("word", word);
-// i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
-// m_view.getContext().startActivity(i);
-// }
- return true;
- }
- return super.performContextMenuAction(id);
- }
-
- @Override
- public boolean setComposingText(CharSequence text, int newCursorPosition)
- {
- setClosing(false);
- return QtNativeInputConnection.setComposingText(text.toString(), newCursorPosition);
- }
-
- @Override
- public boolean setComposingRegion(int start, int end)
- {
- setClosing(false);
- return QtNativeInputConnection.setComposingRegion(start, end);
- }
-
- @Override
- public boolean setSelection(int start, int end)
- {
- setClosing(false);
- return QtNativeInputConnection.setSelection(start, end);
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java b/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java
deleted file mode 100644
index 63993f81b5..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.app.Activity;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowInsets;
-
-public class QtLayout extends ViewGroup
-{
- private Runnable m_startApplicationRunnable;
- public QtLayout(Context context, Runnable startRunnable)
- {
- super(context);
- m_startApplicationRunnable = startRunnable;
- }
-
- public QtLayout(Context context, AttributeSet attrs)
- {
- super(context, attrs);
- }
-
- public QtLayout(Context context, AttributeSet attrs, int defStyle)
- {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected void onSizeChanged (int w, int h, int oldw, int oldh)
- {
- WindowInsets insets = getRootWindowInsets();
-
- DisplayMetrics realMetrics = new DisplayMetrics();
- ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRealMetrics(realMetrics);
-
- boolean isFullScreenView = h == realMetrics.heightPixels;
-
- int insetLeft = isFullScreenView ? insets.getSystemWindowInsetLeft() : 0;
- int insetTop = isFullScreenView ? insets.getSystemWindowInsetTop() : 0;
- int insetRight = isFullScreenView ? insets.getSystemWindowInsetRight() : 0;
- int insetBottom = isFullScreenView ? insets.getSystemWindowInsetBottom() : 0;
-
- int usableAreaWidth = w - insetLeft - insetRight;
- int usableAreaHeight = h - insetTop - insetBottom;
-
- QtNative.setApplicationDisplayMetrics(realMetrics.widthPixels,
- realMetrics.heightPixels,
- insetLeft,
- insetTop,
- usableAreaWidth,
- usableAreaHeight,
- realMetrics.xdpi,
- realMetrics.ydpi,
- realMetrics.scaledDensity,
- realMetrics.density);
-
- if (m_startApplicationRunnable != null) {
- m_startApplicationRunnable.run();
- m_startApplicationRunnable = null;
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
- {
- int count = getChildCount();
-
- int maxHeight = 0;
- int maxWidth = 0;
-
- // Find out how big everyone wants to be
- measureChildren(widthMeasureSpec, heightMeasureSpec);
-
- // Find rightmost and bottom-most child
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() != GONE) {
- int childRight;
- int childBottom;
-
- QtLayout.LayoutParams lp
- = (QtLayout.LayoutParams) child.getLayoutParams();
-
- childRight = lp.x + child.getMeasuredWidth();
- childBottom = lp.y + child.getMeasuredHeight();
-
- maxWidth = Math.max(maxWidth, childRight);
- maxHeight = Math.max(maxHeight, childBottom);
- }
- }
-
- // Check against minimum height and width
- maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
- maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
-
- setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
- resolveSize(maxHeight, heightMeasureSpec));
- }
-
- /**
- * Returns a set of layout parameters with a width of
- * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT},
- * a height of {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}
- * and with the coordinates (0, 0).
- */
- @Override
- protected ViewGroup.LayoutParams generateDefaultLayoutParams()
- {
- return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
- android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
- 0,
- 0);
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b)
- {
- int count = getChildCount();
-
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() != GONE) {
- QtLayout.LayoutParams lp =
- (QtLayout.LayoutParams) child.getLayoutParams();
-
- int childLeft = lp.x;
- int childTop = lp.y;
- child.layout(childLeft, childTop,
- childLeft + child.getMeasuredWidth(),
- childTop + child.getMeasuredHeight());
-
- }
- }
- }
-
- // Override to allow type-checking of LayoutParams.
- @Override
- protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
- {
- return p instanceof QtLayout.LayoutParams;
- }
-
- @Override
- protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
- {
- return new LayoutParams(p);
- }
-
- /**
- * Per-child layout information associated with AbsoluteLayout.
- * See
- * {@link android.R.styleable#AbsoluteLayout_Layout Absolute Layout Attributes}
- * for a list of all child view attributes that this class supports.
- */
- public static class LayoutParams extends ViewGroup.LayoutParams
- {
- /**
- * The horizontal, or X, location of the child within the view group.
- */
- public int x;
- /**
- * The vertical, or Y, location of the child within the view group.
- */
- public int y;
-
- /**
- * Creates a new set of layout parameters with the specified width,
- * height and location.
- *
- * @param width the width, either {@link #FILL_PARENT},
- {@link #WRAP_CONTENT} or a fixed size in pixels
- * @param height the height, either {@link #FILL_PARENT},
- {@link #WRAP_CONTENT} or a fixed size in pixels
- * @param x the X location of the child
- * @param y the Y location of the child
- */
- public LayoutParams(int width, int height, int x, int y)
- {
- super(width, height);
- this.x = x;
- this.y = y;
- }
-
- /**
- * {@inheritDoc}
- */
- public LayoutParams(ViewGroup.LayoutParams source)
- {
- super(source);
- }
- }
-
- public void moveChild(View view, int index)
- {
- if (view == null)
- return;
-
- if (indexOfChild(view) == -1)
- return;
-
- detachViewFromParent(view);
- requestLayout();
- invalidate();
- attachViewToParent(view, index, view.getLayoutParams());
- }
-
- /**
- * set the layout params on a child view.
- *
- * Note: This function adds the child view if it's not in the
- * layout already.
- */
- public void setLayoutParams(final View childView,
- final ViewGroup.LayoutParams params,
- final boolean forceRedraw)
- {
- // Invalid view
- if (childView == null)
- return;
-
- // Invalid params
- if (!checkLayoutParams(params))
- return;
-
- // View is already in the layout and can therefore be updated
- final boolean canUpdate = (this == childView.getParent());
-
- if (canUpdate) {
- childView.setLayoutParams(params);
- if (forceRedraw)
- invalidate();
- } else {
- addView(childView, params);
- }
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java b/src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java
deleted file mode 100644
index a3bbff4e1a..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2016 BogDan Vatra <bogdan@kde.org>
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the Android port of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-
-package org.qtproject.qt5.android;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-import android.text.ClipboardManager;
-import android.text.Html;
-import android.text.Spanned;
-import android.util.TypedValue;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
-import android.widget.ScrollView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.util.ArrayList;
-
-class QtNativeDialogHelper
-{
- static native void dialogResult(long handler, int buttonID);
-}
-
-class ButtonStruct implements View.OnClickListener
-{
- ButtonStruct(QtMessageDialogHelper dialog, int id, String text)
- {
- m_dialog = dialog;
- m_id = id;
- m_text = Html.fromHtml(text);
- }
- QtMessageDialogHelper m_dialog;
- private int m_id;
- Spanned m_text;
-
- @Override
- public void onClick(View view) {
- QtNativeDialogHelper.dialogResult(m_dialog.handler(), m_id);
- }
-}
-
-public class QtMessageDialogHelper
-{
-
- public QtMessageDialogHelper(Activity activity)
- {
- m_activity = activity;
- }
-
-
- public void setIcon(int icon)
- {
- m_icon = icon;
-
- }
-
- private Drawable getIconDrawable()
- {
- if (m_icon == 0)
- return null;
-
- try {
- TypedValue typedValue = new TypedValue();
- m_theme.resolveAttribute(android.R.attr.alertDialogIcon, typedValue, true);
- return m_activity.getResources().getDrawable(typedValue.resourceId);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- // Information, Warning, Critical, Question
- switch (m_icon)
- {
- case 1: // Information
- try {
- return m_activity.getResources().getDrawable(android.R.drawable.ic_dialog_info);
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case 2: // Warning
-// try {
-// return Class.forName("android.R$drawable").getDeclaredField("stat_sys_warning").getInt(null);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// break;
- case 3: // Critical
- try {
- return m_activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert);
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case 4: // Question
- try {
- return m_activity.getResources().getDrawable(android.R.drawable.ic_menu_help);
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- }
- return null;
- }
-
- public void setTile(String title)
- {
- m_title = Html.fromHtml(title);
- }
-
- public void setText(String text)
- {
- m_text = Html.fromHtml(text);
- }
-
- public void setInformativeText(String informativeText)
- {
- m_informativeText = Html.fromHtml(informativeText);
- }
-
- public void setDetailedText(String text)
- {
- m_detailedText = Html.fromHtml(text);
- }
-
- public void addButton(int id, String text)
- {
- if (m_buttonsList == null)
- m_buttonsList = new ArrayList<ButtonStruct>();
- m_buttonsList.add(new ButtonStruct(this, id, text));
- }
-
- private Drawable getStyledDrawable(String drawable) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
- {
- int[] attrs = {Class.forName("android.R$attr").getDeclaredField(drawable).getInt(null)};
- final TypedArray a = m_theme.obtainStyledAttributes(attrs);
- Drawable d = a.getDrawable(0);
- a.recycle();
- return d;
- }
-
-
- public void show(long handler)
- {
- m_handler = handler;
- m_activity.runOnUiThread( new Runnable() {
- @Override
- public void run() {
- if (m_dialog != null && m_dialog.isShowing())
- m_dialog.dismiss();
-
- m_dialog = new AlertDialog.Builder(m_activity).create();
- m_theme = m_dialog.getWindow().getContext().getTheme();
-
- if (m_title != null)
- m_dialog.setTitle(m_title);
- m_dialog.setOnCancelListener( new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialogInterface) {
- QtNativeDialogHelper.dialogResult(handler(), -1);
- }
- });
- m_dialog.setCancelable(m_buttonsList == null);
- m_dialog.setCanceledOnTouchOutside(m_buttonsList == null);
- m_dialog.setIcon(getIconDrawable());
- ScrollView scrollView = new ScrollView(m_activity);
- RelativeLayout dialogLayout = new RelativeLayout(m_activity);
- int id = 1;
- View lastView = null;
- View.OnLongClickListener copyText = new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View view) {
- TextView tv = (TextView)view;
- if (tv != null) {
- ClipboardManager cm = (android.text.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
- cm.setText(tv.getText());
- }
- return true;
- }
- };
- if (m_text != null)
- {
- TextView view = new TextView(m_activity);
- view.setId(id++);
- view.setOnLongClickListener(copyText);
- view.setLongClickable(true);
-
- view.setText(m_text);
- view.setTextAppearance(m_activity, android.R.style.TextAppearance_Medium);
-
- RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- layout.setMargins(16, 8, 16, 8);
- layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- dialogLayout.addView(view, layout);
- lastView = view;
- }
-
- if (m_informativeText != null)
- {
- TextView view= new TextView(m_activity);
- view.setId(id++);
- view.setOnLongClickListener(copyText);
- view.setLongClickable(true);
-
- view.setText(m_informativeText);
- view.setTextAppearance(m_activity, android.R.style.TextAppearance_Medium);
-
- RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- layout.setMargins(16, 8, 16, 8);
- if (lastView != null)
- layout.addRule(RelativeLayout.BELOW, lastView.getId());
- else
- layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- dialogLayout.addView(view, layout);
- lastView = view;
- }
-
- if (m_detailedText != null)
- {
- TextView view= new TextView(m_activity);
- view.setId(id++);
- view.setOnLongClickListener(copyText);
- view.setLongClickable(true);
-
- view.setText(m_detailedText);
- view.setTextAppearance(m_activity, android.R.style.TextAppearance_Small);
-
- RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- layout.setMargins(16, 8, 16, 8);
- if (lastView != null)
- layout.addRule(RelativeLayout.BELOW, lastView.getId());
- else
- layout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- dialogLayout.addView(view, layout);
- lastView = view;
- }
-
- if (m_buttonsList != null)
- {
- LinearLayout buttonsLayout = new LinearLayout(m_activity);
- buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);
- buttonsLayout.setId(id++);
- boolean firstButton = true;
- for (ButtonStruct button: m_buttonsList)
- {
- Button bv;
- try {
- bv = new Button(m_activity, null, Class.forName("android.R$attr").getDeclaredField("borderlessButtonStyle").getInt(null));
- } catch (Exception e) {
- bv = new Button(m_activity);
- e.printStackTrace();
- }
-
- bv.setText(button.m_text);
- bv.setOnClickListener(button);
- if (!firstButton) // first button
- {
- LinearLayout.LayoutParams layout = null;
- View spacer = new View(m_activity);
- try {
- layout = new LinearLayout.LayoutParams(1, RelativeLayout.LayoutParams.MATCH_PARENT);
- spacer.setBackgroundDrawable(getStyledDrawable("dividerVertical"));
- buttonsLayout.addView(spacer, layout);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- LinearLayout.LayoutParams layout = null;
- layout = new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT, 1.0f);
- buttonsLayout.addView(bv, layout);
- firstButton = false;
- }
-
- try {
- View horizontalDevider = new View(m_activity);
- horizontalDevider.setId(id++);
- horizontalDevider.setBackgroundDrawable(getStyledDrawable("dividerHorizontal"));
- RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 1);
- relativeParams.setMargins(0, 10, 0, 0);
- if (lastView != null) {
- relativeParams.addRule(RelativeLayout.BELOW, lastView.getId());
- }
- else
- relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- dialogLayout.addView(horizontalDevider, relativeParams);
- lastView = horizontalDevider;
- } catch (Exception e) {
- e.printStackTrace();
- }
- RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- if (lastView != null) {
- relativeParams.addRule(RelativeLayout.BELOW, lastView.getId());
- }
- else
- relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- relativeParams.setMargins(2, 0, 2, 0);
- dialogLayout.addView(buttonsLayout, relativeParams);
- }
- scrollView.addView(dialogLayout);
- m_dialog.setView(scrollView);
- m_dialog.show();
- }
- });
- }
-
- public void hide()
- {
- m_activity.runOnUiThread( new Runnable() {
- @Override
- public void run() {
- if (m_dialog != null && m_dialog.isShowing())
- m_dialog.dismiss();
- reset();
- }
- });
- }
-
- public long handler()
- {
- return m_handler;
- }
-
- public void reset()
- {
- m_icon = 0;
- m_title = null;
- m_text = null;
- m_informativeText = null;
- m_detailedText = null;
- m_buttonsList = null;
- m_dialog = null;
- m_handler = 0;
- }
-
- private Activity m_activity;
- private int m_icon = 0;
- private Spanned m_title, m_text, m_informativeText, m_detailedText;
- private ArrayList<ButtonStruct> m_buttonsList;
- private AlertDialog m_dialog;
- private long m_handler = 0;
- private Resources.Theme m_theme;
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
deleted file mode 100644
index 6fd6a9ca98..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ /dev/null
@@ -1,1390 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-import java.io.IOException;
-import java.util.HashMap;
-
-import android.app.Activity;
-import android.app.Service;
-import android.content.ActivityNotFoundException;
-import android.content.Context;
-import android.content.ContentResolver;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ApplicationInfo;
-import android.content.UriPermission;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.content.ClipboardManager;
-import android.content.ClipboardManager.OnPrimaryClipChangedListener;
-import android.content.ClipData;
-import android.os.ParcelFileDescriptor;
-import android.util.Log;
-import android.view.ContextMenu;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.InputDevice;
-import android.database.Cursor;
-import android.provider.DocumentsContract;
-
-import java.lang.reflect.Method;
-import java.security.KeyStore;
-import java.security.cert.X509Certificate;
-import java.util.Iterator;
-import java.util.List;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-public class QtNative
-{
- private static Activity m_activity = null;
- private static boolean m_activityPaused = false;
- private static Service m_service = null;
- private static QtActivityDelegate m_activityDelegate = null;
- private static QtServiceDelegate m_serviceDelegate = null;
- public static Object m_mainActivityMutex = new Object(); // mutex used to synchronize runnable operations
-
- public static final String QtTAG = "Qt JAVA"; // string used for Log.x
- private static ArrayList<Runnable> m_lostActions = new ArrayList<Runnable>(); // a list containing all actions which could not be performed (e.g. the main activity is destroyed, etc.)
- private static boolean m_started = false;
- private static int m_displayMetricsScreenWidthPixels = 0;
- private static int m_displayMetricsScreenHeightPixels = 0;
- private static int m_displayMetricsAvailableLeftPixels = 0;
- private static int m_displayMetricsAvailableTopPixels = 0;
- private static int m_displayMetricsAvailableWidthPixels = 0;
- private static int m_displayMetricsAvailableHeightPixels = 0;
- private static double m_displayMetricsXDpi = .0;
- private static double m_displayMetricsYDpi = .0;
- private static double m_displayMetricsScaledDensity = 1.0;
- private static double m_displayMetricsDensity = 1.0;
- private static int m_oldx, m_oldy;
- private static final int m_moveThreshold = 0;
- private static ClipboardManager m_clipboardManager = null;
- private static Method m_checkSelfPermissionMethod = null;
- private static Boolean m_tabletEventSupported = null;
- private static boolean m_usePrimaryClip = false;
- public static QtThread m_qtThread = new QtThread();
- private static Method m_addItemMethod = null;
- private static HashMap<String, Uri> m_cachedUris = new HashMap<String, Uri>();
- private static ArrayList<String> m_knownDirs = new ArrayList<String>();
-
- private static final Runnable runPendingCppRunnablesRunnable = new Runnable() {
- @Override
- public void run() {
- runPendingCppRunnables();
- }
- };
-
- private static ClassLoader m_classLoader = null;
- public static ClassLoader classLoader()
- {
- return m_classLoader;
- }
-
- public static void setClassLoader(ClassLoader classLoader)
- {
- m_classLoader = classLoader;
- }
-
- public static Activity activity()
- {
- synchronized (m_mainActivityMutex) {
- return m_activity;
- }
- }
-
- public static Service service()
- {
- synchronized (m_mainActivityMutex) {
- return m_service;
- }
- }
-
-
- public static QtActivityDelegate activityDelegate()
- {
- synchronized (m_mainActivityMutex) {
- return m_activityDelegate;
- }
- }
-
- public static QtServiceDelegate serviceDelegate()
- {
- synchronized (m_mainActivityMutex) {
- return m_serviceDelegate;
- }
- }
-
- public static String[] getStringArray(String joinedString)
- {
- return joinedString.split(",");
- }
-
- private static Uri getUriWithValidPermission(Context context, String uri, String openMode)
- {
- try {
- Uri parsedUri = Uri.parse(uri);
- String scheme = parsedUri.getScheme();
-
- // We only want to check permissions for content Uris
- if (scheme.compareTo("content") != 0)
- return parsedUri;
-
- List<UriPermission> permissions = context.getContentResolver().getPersistedUriPermissions();
- String uriStr = parsedUri.getPath();
-
- for (int i = 0; i < permissions.size(); ++i) {
- Uri iterUri = permissions.get(i).getUri();
- boolean isRightPermission = permissions.get(i).isReadPermission();
-
- if (!openMode.equals("r"))
- isRightPermission = permissions.get(i).isWritePermission();
-
- if (iterUri.getPath().equals(uriStr) && isRightPermission)
- return iterUri;
- }
-
- // Android 6 and earlier could still manage to open the file so we can return the
- // parsed uri here
- if (Build.VERSION.SDK_INT < 24)
- return parsedUri;
- return null;
- } catch (SecurityException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static boolean openURL(Context context, String url, String mime)
- {
- Uri uri = getUriWithValidPermission(context, url, "r");
-
- if (uri == null) {
- Log.e(QtTAG, "openURL(): No permissions to open Uri");
- return false;
- }
-
- try {
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- if (!mime.isEmpty())
- intent.setDataAndType(uri, mime);
-
- activity().startActivity(intent);
-
- return true;
- } catch (IllegalArgumentException e) {
- Log.e(QtTAG, "openURL(): Invalid Uri");
- e.printStackTrace();
- return false;
- } catch (UnsupportedOperationException e) {
- Log.e(QtTAG, "openURL(): Unsupported operation for given Uri");
- e.printStackTrace();
- return false;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public static int openFdForContentUrl(Context context, String contentUrl, String openMode)
- {
- Uri uri = m_cachedUris.get(contentUrl);
- if (uri == null)
- uri = getUriWithValidPermission(context, contentUrl, openMode);
- int error = -1;
-
- if (uri == null) {
- Log.e(QtTAG, "openFdForContentUrl(): No permissions to open Uri");
- return error;
- }
-
- try {
- ContentResolver resolver = context.getContentResolver();
- ParcelFileDescriptor fdDesc = resolver.openFileDescriptor(uri, openMode);
- return fdDesc.detachFd();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return error;
- } catch (IllegalArgumentException e) {
- Log.e(QtTAG, "openFdForContentUrl(): Invalid Uri");
- e.printStackTrace();
- return error;
- }
- }
-
- public static long getSize(Context context, String contentUrl)
- {
- long size = -1;
- Uri uri = m_cachedUris.get(contentUrl);
- if (uri == null)
- uri = getUriWithValidPermission(context, contentUrl, "r");
-
- if (uri == null) {
- Log.e(QtTAG, "getSize(): No permissions to open Uri");
- return size;
- } else {
- m_cachedUris.putIfAbsent(contentUrl, uri);
- }
-
- try {
- ContentResolver resolver = context.getContentResolver();
- Cursor cur = resolver.query(uri, new String[] { DocumentsContract.Document.COLUMN_SIZE }, null, null, null);
- if (cur != null) {
- if (cur.moveToFirst())
- size = cur.getLong(0);
- cur.close();
- }
- return size;
- } catch (IllegalArgumentException e) {
- Log.e(QtTAG, "getSize(): Invalid Uri");
- e.printStackTrace();
- return size;
- } catch (UnsupportedOperationException e) {
- Log.e(QtTAG, "getSize(): Unsupported operation for given Uri");
- e.printStackTrace();
- return size;
- }
- }
-
- public static boolean checkFileExists(Context context, String contentUrl)
- {
- boolean exists = false;
- Uri uri = m_cachedUris.get(contentUrl);
- if (uri == null)
- uri = getUriWithValidPermission(context, contentUrl, "r");
- if (uri == null) {
- Log.e(QtTAG, "checkFileExists(): No permissions to open Uri");
- return exists;
- } else {
- if (!m_cachedUris.containsKey(contentUrl))
- m_cachedUris.put(contentUrl, uri);
- }
-
- try {
- ContentResolver resolver = context.getContentResolver();
- Cursor cur = resolver.query(uri, null, null, null, null);
- if (cur != null) {
- exists = true;
- cur.close();
- }
- return exists;
- } catch (IllegalArgumentException e) {
- Log.e(QtTAG, "checkFileExists(): Invalid Uri");
- e.printStackTrace();
- return exists;
- } catch (UnsupportedOperationException e) {
- Log.e(QtTAG, "checkFileExists(): Unsupported operation for given Uri");
- e.printStackTrace();
- return false;
- }
- }
-
- public static boolean checkIfDir(Context context, String contentUrl)
- {
- boolean isDir = false;
- Uri uri = m_cachedUris.get(contentUrl);
- if (m_knownDirs.contains(contentUrl))
- return true;
- if (uri == null) {
- uri = getUriWithValidPermission(context, contentUrl, "r");
- }
- if (uri == null) {
- Log.e(QtTAG, "isDir(): No permissions to open Uri");
- return isDir;
- } else {
- if (!m_cachedUris.containsKey(contentUrl))
- m_cachedUris.put(contentUrl, uri);
- }
-
- try {
- final List<String> paths = uri.getPathSegments();
- // getTreeDocumentId will throw an exception if it is not a directory so check manually
- if (!paths.get(0).equals("tree"))
- return false;
- ContentResolver resolver = context.getContentResolver();
- Uri docUri = DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri));
- if (!docUri.toString().startsWith(uri.toString()))
- return false;
- Cursor cur = resolver.query(docUri, new String[] { DocumentsContract.Document.COLUMN_MIME_TYPE }, null, null, null);
- if (cur != null) {
- if (cur.moveToFirst()) {
- final String dirStr = new String(DocumentsContract.Document.MIME_TYPE_DIR);
- isDir = cur.getString(0).equals(dirStr);
- if (isDir)
- m_knownDirs.add(contentUrl);
- }
- cur.close();
- }
- return isDir;
- } catch (IllegalArgumentException e) {
- Log.e(QtTAG, "checkIfDir(): Invalid Uri");
- e.printStackTrace();
- return false;
- } catch (UnsupportedOperationException e) {
- Log.e(QtTAG, "checkIfDir(): Unsupported operation for given Uri");
- e.printStackTrace();
- return false;
- }
- }
- public static String[] listContentsFromTreeUri(Context context, String contentUrl)
- {
- Uri treeUri = Uri.parse(contentUrl);
- final ArrayList<String> results = new ArrayList<String>();
- if (treeUri == null) {
- Log.e(QtTAG, "listContentsFromTreeUri(): Invalid uri");
- return results.toArray(new String[results.size()]);
- }
- final ContentResolver resolver = context.getContentResolver();
- final Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
- DocumentsContract.getTreeDocumentId(treeUri));
- final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(docUri,
- DocumentsContract.getDocumentId(docUri));
- Cursor c = null;
- final String dirStr = new String(DocumentsContract.Document.MIME_TYPE_DIR);
- try {
- c = resolver.query(childrenUri, new String[] {
- DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE }, null, null, null);
- while (c.moveToNext()) {
- final String fileString = c.getString(1);
- if (!m_cachedUris.containsKey(contentUrl + "/" + fileString)) {
- m_cachedUris.put(contentUrl + "/" + fileString,
- DocumentsContract.buildDocumentUriUsingTree(treeUri, c.getString(0)));
- }
- results.add(fileString);
- if (c.getString(2).equals(dirStr))
- m_knownDirs.add(contentUrl + "/" + fileString);
- }
- c.close();
- } catch (Exception e) {
- Log.w(QtTAG, "Failed query: " + e);
- return results.toArray(new String[results.size()]);
- }
- return results.toArray(new String[results.size()]);
- }
- // this method loads full path libs
- public static void loadQtLibraries(final ArrayList<String> libraries)
- {
- m_qtThread.run(new Runnable() {
- @Override
- public void run() {
- if (libraries == null)
- return;
- for (String libName : libraries) {
- try {
- File f = new File(libName);
- if (f.exists())
- System.load(libName);
- else
- Log.i(QtTAG, "Can't find '" + libName + "'");
- } catch (SecurityException e) {
- Log.i(QtTAG, "Can't load '" + libName + "'", e);
- } catch (Exception e) {
- Log.i(QtTAG, "Can't load '" + libName + "'", e);
- }
- }
- }
- });
- }
-
- // this method loads bundled libs by name.
- public static void loadBundledLibraries(final ArrayList<String> libraries, final String nativeLibraryDir)
- {
- m_qtThread.run(new Runnable() {
- @Override
- public void run() {
- if (libraries == null)
- return;
-
- for (String libName : libraries) {
- try {
- String libNameTemplate = "lib" + libName + ".so";
- File f = new File(nativeLibraryDir + libNameTemplate);
- if (!f.exists()) {
- Log.i(QtTAG, "Can't find '" + f.getAbsolutePath());
- try {
- ApplicationInfo info = getContext().getApplicationContext().getPackageManager()
- .getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
- String systemLibraryDir = QtNativeLibrariesDir.systemLibrariesDir;
- if (info.metaData.containsKey("android.app.system_libs_prefix"))
- systemLibraryDir = info.metaData.getString("android.app.system_libs_prefix");
- f = new File(systemLibraryDir + libNameTemplate);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- if (f.exists())
- System.load(f.getAbsolutePath());
- else
- Log.i(QtTAG, "Can't find '" + f.getAbsolutePath());
- } catch (Exception e) {
- Log.i(QtTAG, "Can't load '" + libName + "'", e);
- }
- }
- }
- });
- }
-
- public static String loadMainLibrary(final String mainLibrary, final String nativeLibraryDir)
- {
- final String[] res = new String[1];
- res[0] = null;
- m_qtThread.run(new Runnable() {
- @Override
- public void run() {
- try {
- String mainLibNameTemplate = "lib" + mainLibrary + ".so";
- File f = new File(nativeLibraryDir + mainLibNameTemplate);
- if (!f.exists()) {
- try {
- ApplicationInfo info = getContext().getApplicationContext().getPackageManager()
- .getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
- String systemLibraryDir = QtNativeLibrariesDir.systemLibrariesDir;
- if (info.metaData.containsKey("android.app.system_libs_prefix"))
- systemLibraryDir = info.metaData.getString("android.app.system_libs_prefix");
- f = new File(systemLibraryDir + mainLibNameTemplate);
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- }
- if (!f.exists())
- return;
- System.load(f.getAbsolutePath());
- res[0] = f.getAbsolutePath();
- } catch (Exception e) {
- Log.e(QtTAG, "Can't load '" + mainLibrary + "'", e);
- }
- }
- });
- return res[0];
- }
-
- public static void setActivity(Activity qtMainActivity, QtActivityDelegate qtActivityDelegate)
- {
- synchronized (m_mainActivityMutex) {
- m_activity = qtMainActivity;
- m_activityDelegate = qtActivityDelegate;
- }
- }
-
- public static void setService(Service qtMainService, QtServiceDelegate qtServiceDelegate)
- {
- synchronized (m_mainActivityMutex) {
- m_service = qtMainService;
- m_serviceDelegate = qtServiceDelegate;
- }
- }
-
- public static void setApplicationState(int state)
- {
- synchronized (m_mainActivityMutex) {
- switch (state) {
- case QtActivityDelegate.ApplicationActive:
- m_activityPaused = false;
- Iterator<Runnable> itr = m_lostActions.iterator();
- while (itr.hasNext())
- runAction(itr.next());
- m_lostActions.clear();
- break;
- default:
- m_activityPaused = true;
- break;
- }
- }
- updateApplicationState(state);
- }
-
- private static void runAction(Runnable action)
- {
- synchronized (m_mainActivityMutex) {
- final Looper mainLooper = Looper.getMainLooper();
- final Handler handler = new Handler(mainLooper);
- final boolean actionIsQueued = !m_activityPaused && m_activity != null && mainLooper != null && handler.post(action);
- if (!actionIsQueued)
- m_lostActions.add(action);
- }
- }
-
- private static void runPendingCppRunnablesOnAndroidThread()
- {
- synchronized (m_mainActivityMutex) {
- if (m_activity != null) {
- if (!m_activityPaused)
- m_activity.runOnUiThread(runPendingCppRunnablesRunnable);
- else
- runAction(runPendingCppRunnablesRunnable);
- } else {
- final Looper mainLooper = Looper.getMainLooper();
- final Thread looperThread = mainLooper.getThread();
- if (looperThread.equals(Thread.currentThread())) {
- runPendingCppRunnablesRunnable.run();
- } else {
- final Handler handler = new Handler(mainLooper);
- handler.post(runPendingCppRunnablesRunnable);
- }
- }
- }
- }
-
- private static void setViewVisibility(final View view, final boolean visible)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- view.setVisibility(visible ? View.VISIBLE : View.GONE);
- }
- });
- }
-
- public static boolean startApplication(String params, final String environment, String mainLib) throws Exception
- {
- if (params == null)
- params = "-platform\tandroid";
-
- final boolean[] res = new boolean[1];
- res[0] = false;
- synchronized (m_mainActivityMutex) {
- if (params.length() > 0 && !params.startsWith("\t"))
- params = "\t" + params;
- final String qtParams = mainLib + params;
- m_qtThread.run(new Runnable() {
- @Override
- public void run() {
- res[0] = startQtAndroidPlugin(qtParams, environment);
- setDisplayMetrics(m_displayMetricsScreenWidthPixels,
- m_displayMetricsScreenHeightPixels,
- m_displayMetricsAvailableLeftPixels,
- m_displayMetricsAvailableTopPixels,
- m_displayMetricsAvailableWidthPixels,
- m_displayMetricsAvailableHeightPixels,
- m_displayMetricsXDpi,
- m_displayMetricsYDpi,
- m_displayMetricsScaledDensity,
- m_displayMetricsDensity);
- }
- });
- m_qtThread.post(new Runnable() {
- @Override
- public void run() {
- startQtApplication();
- }
- });
- waitForServiceSetup();
- m_started = true;
- }
- return res[0];
- }
-
- public static void setApplicationDisplayMetrics(int screenWidthPixels,
- int screenHeightPixels,
- int availableLeftPixels,
- int availableTopPixels,
- int availableWidthPixels,
- int availableHeightPixels,
- double XDpi,
- double YDpi,
- double scaledDensity,
- double density)
- {
- /* Fix buggy dpi report */
- if (XDpi < android.util.DisplayMetrics.DENSITY_LOW)
- XDpi = android.util.DisplayMetrics.DENSITY_LOW;
- if (YDpi < android.util.DisplayMetrics.DENSITY_LOW)
- YDpi = android.util.DisplayMetrics.DENSITY_LOW;
-
- synchronized (m_mainActivityMutex) {
- if (m_started) {
- setDisplayMetrics(screenWidthPixels,
- screenHeightPixels,
- availableLeftPixels,
- availableTopPixels,
- availableWidthPixels,
- availableHeightPixels,
- XDpi,
- YDpi,
- scaledDensity,
- density);
- } else {
- m_displayMetricsScreenWidthPixels = screenWidthPixels;
- m_displayMetricsScreenHeightPixels = screenHeightPixels;
- m_displayMetricsAvailableLeftPixels = availableLeftPixels;
- m_displayMetricsAvailableTopPixels = availableTopPixels;
- m_displayMetricsAvailableWidthPixels = availableWidthPixels;
- m_displayMetricsAvailableHeightPixels = availableHeightPixels;
- m_displayMetricsXDpi = XDpi;
- m_displayMetricsYDpi = YDpi;
- m_displayMetricsScaledDensity = scaledDensity;
- m_displayMetricsDensity = density;
- }
- }
- }
-
-
-
- // application methods
- public static native boolean startQtAndroidPlugin(String params, String env);
- public static native void startQtApplication();
- public static native void waitForServiceSetup();
- public static native void quitQtCoreApplication();
- public static native void quitQtAndroidPlugin();
- public static native void terminateQt();
- // application methods
-
- private static void quitApp()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- quitQtAndroidPlugin();
- if (m_activity != null)
- m_activity.finish();
- if (m_service != null)
- m_service.stopSelf();
- }
- });
- }
-
- //@ANDROID-9
- static private int getAction(int index, MotionEvent event)
- {
- int action = event.getActionMasked();
- if (action == MotionEvent.ACTION_MOVE) {
- int hsz = event.getHistorySize();
- if (hsz > 0) {
- float x = event.getX(index);
- float y = event.getY(index);
- for (int h = 0; h < hsz; ++h) {
- if ( event.getHistoricalX(index, h) != x ||
- event.getHistoricalY(index, h) != y )
- return 1;
- }
- return 2;
- }
- return 1;
- }
- if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN && index == event.getActionIndex()) {
- return 0;
- } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP && index == event.getActionIndex()) {
- return 3;
- }
- return 2;
- }
- //@ANDROID-9
-
- static public void sendTouchEvent(MotionEvent event, int id)
- {
- int pointerType = 0;
-
- if (m_tabletEventSupported == null)
- m_tabletEventSupported = isTabletEventSupported();
-
- switch (event.getToolType(0)) {
- case MotionEvent.TOOL_TYPE_STYLUS:
- pointerType = 1; // QTabletEvent::Pen
- break;
- case MotionEvent.TOOL_TYPE_ERASER:
- pointerType = 3; // QTabletEvent::Eraser
- break;
- }
-
- if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
- sendMouseEvent(event, id);
- } else if (m_tabletEventSupported && pointerType != 0) {
- tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getAction(), pointerType,
- event.getButtonState(), event.getX(), event.getY(), event.getPressure());
- } else {
- touchBegin(id);
- for (int i = 0; i < event.getPointerCount(); ++i) {
- touchAdd(id,
- event.getPointerId(i),
- getAction(i, event),
- i == 0,
- (int)event.getX(i),
- (int)event.getY(i),
- event.getTouchMajor(i),
- event.getTouchMinor(i),
- event.getOrientation(i),
- event.getPressure(i));
- }
-
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- touchEnd(id, 0);
- break;
-
- case MotionEvent.ACTION_UP:
- touchEnd(id, 2);
- break;
-
- default:
- touchEnd(id, 1);
- }
- }
- }
-
- static public void sendTrackballEvent(MotionEvent event, int id)
- {
- sendMouseEvent(event,id);
- }
-
- static public boolean sendGenericMotionEvent(MotionEvent event, int id)
- {
- if (((event.getAction() & (MotionEvent.ACTION_SCROLL | MotionEvent.ACTION_HOVER_MOVE)) == 0)
- || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != InputDevice.SOURCE_CLASS_POINTER) {
- return false;
- }
-
- return sendMouseEvent(event, id);
- }
-
- static public boolean sendMouseEvent(MotionEvent event, int id)
- {
- switch (event.getActionMasked()) {
- case MotionEvent.ACTION_UP:
- mouseUp(id, (int) event.getX(), (int) event.getY());
- break;
-
- case MotionEvent.ACTION_DOWN:
- mouseDown(id, (int) event.getX(), (int) event.getY());
- m_oldx = (int) event.getX();
- m_oldy = (int) event.getY();
- break;
- case MotionEvent.ACTION_HOVER_MOVE:
- case MotionEvent.ACTION_MOVE:
- if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
- mouseMove(id, (int) event.getX(), (int) event.getY());
- } else {
- int dx = (int) (event.getX() - m_oldx);
- int dy = (int) (event.getY() - m_oldy);
- if (Math.abs(dx) > 5 || Math.abs(dy) > 5) {
- mouseMove(id, (int) event.getX(), (int) event.getY());
- m_oldx = (int) event.getX();
- m_oldy = (int) event.getY();
- }
- }
- break;
- case MotionEvent.ACTION_SCROLL:
- mouseWheel(id, (int) event.getX(), (int) event.getY(),
- event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
- break;
- default:
- return false;
- }
- return true;
- }
-
- public static Context getContext() {
- if (m_activity != null)
- return m_activity;
- return m_service;
- }
-
- public static int checkSelfPermission(String permission)
- {
- int perm = PackageManager.PERMISSION_DENIED;
- synchronized (m_mainActivityMutex) {
- Context context = getContext();
- try {
- if (m_checkSelfPermissionMethod == null)
- m_checkSelfPermissionMethod = Context.class.getMethod("checkSelfPermission", String.class);
- perm = (Integer)m_checkSelfPermissionMethod.invoke(context, permission);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- return perm;
- }
-
- private static void updateSelection(final int selStart,
- final int selEnd,
- final int candidatesStart,
- final int candidatesEnd)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.updateSelection(selStart, selEnd, candidatesStart, candidatesEnd);
- }
- });
- }
-
- private static void updateHandles(final int mode,
- final int editX,
- final int editY,
- final int editButtons,
- final int x1,
- final int y1,
- final int x2,
- final int y2,
- final boolean rtl)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- m_activityDelegate.updateHandles(mode, editX, editY, editButtons, x1, y1, x2, y2, rtl);
- }
- });
- }
-
- private static void showSoftwareKeyboard(final int x,
- final int y,
- final int width,
- final int height,
- final int inputHints,
- final int enterKeyType)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
- }
- });
- }
-
- private static void resetSoftwareKeyboard()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.resetSoftwareKeyboard();
- }
- });
- }
-
- private static void hideSoftwareKeyboard()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.hideSoftwareKeyboard();
- }
- });
- }
-
- private static void setSystemUiVisibility(final int systemUiVisibility)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null) {
- m_activityDelegate.setSystemUiVisibility(systemUiVisibility);
- }
- updateWindow();
- }
- });
- }
-
- private static void registerClipboardManager()
- {
- if (m_service == null || m_activity != null) { // Avoid freezing if only service
- final Semaphore semaphore = new Semaphore(0);
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activity != null)
- m_clipboardManager = (android.content.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
- if (m_clipboardManager != null) {
- m_clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
- public void onPrimaryClipChanged() {
- onClipboardDataChanged();
- }
- });
- }
- semaphore.release();
- }
- });
- try {
- semaphore.acquire();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- private static void clearClipData()
- {
- if (Build.VERSION.SDK_INT >= 28 && m_clipboardManager != null && m_usePrimaryClip)
- m_clipboardManager.clearPrimaryClip();
- m_usePrimaryClip = false;
- }
- private static void setClipboardText(String text)
- {
- if (m_clipboardManager != null) {
- ClipData clipData = ClipData.newPlainText("text/plain", text);
- updatePrimaryClip(clipData);
- }
- }
-
- public static boolean hasClipboardText()
- {
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getText() != null)
- return true;
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- return false;
- }
-
- private static String getClipboardText()
- {
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getText() != null)
- return primaryClip.getItemAt(i).getText().toString();
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- return "";
- }
-
- private static void updatePrimaryClip(ClipData clipData)
- {
- try {
- if (m_usePrimaryClip) {
- ClipData clip = m_clipboardManager.getPrimaryClip();
- if (Build.VERSION.SDK_INT >= 26) {
- if (m_addItemMethod == null) {
- Class[] cArg = new Class[2];
- cArg[0] = ContentResolver.class;
- cArg[1] = ClipData.Item.class;
- try {
- m_addItemMethod = m_clipboardManager.getClass().getMethod("addItem", cArg);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- if (m_addItemMethod != null) {
- try {
- m_addItemMethod.invoke(m_activity.getContentResolver(), clipData.getItemAt(0));
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- clip.addItem(clipData.getItemAt(0));
- }
- m_clipboardManager.setPrimaryClip(clip);
- } else {
- m_clipboardManager.setPrimaryClip(clipData);
- m_usePrimaryClip = true;
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to set clipboard data", e);
- }
- }
-
- private static void setClipboardHtml(String text, String html)
- {
- if (m_clipboardManager != null) {
- ClipData clipData = ClipData.newHtmlText("text/html", text, html);
- updatePrimaryClip(clipData);
- }
- }
-
- public static boolean hasClipboardHtml()
- {
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getHtmlText() != null)
- return true;
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- return false;
- }
-
- private static String getClipboardHtml()
- {
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getHtmlText() != null)
- return primaryClip.getItemAt(i).getHtmlText().toString();
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- return "";
- }
-
- private static void setClipboardUri(String uriString)
- {
- if (m_clipboardManager != null) {
- ClipData clipData = ClipData.newUri(m_activity.getContentResolver(), "text/uri-list",
- Uri.parse(uriString));
- updatePrimaryClip(clipData);
- }
- }
-
- public static boolean hasClipboardUri()
- {
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getUri() != null)
- return true;
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- return false;
- }
-
- private static String[] getClipboardUris()
- {
- ArrayList<String> uris = new ArrayList<String>();
- try {
- if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
- ClipData primaryClip = m_clipboardManager.getPrimaryClip();
- for (int i = 0; i < primaryClip.getItemCount(); ++i)
- if (primaryClip.getItemAt(i).getUri() != null)
- uris.add(primaryClip.getItemAt(i).getUri().toString());
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get clipboard data", e);
- }
- String[] strings = new String[uris.size()];
- strings = uris.toArray(strings);
- return strings;
- }
-
- private static void openContextMenu(final int x, final int y, final int w, final int h)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.openContextMenu(x, y, w, h);
- }
- });
- }
-
- private static void closeContextMenu()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.closeContextMenu();
- }
- });
- }
-
- private static void resetOptionsMenu()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.resetOptionsMenu();
- }
- });
- }
-
- private static void openOptionsMenu()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activity != null)
- m_activity.openOptionsMenu();
- }
- });
- }
-
- private static byte[][] getSSLCertificates()
- {
- ArrayList<byte[]> certificateList = new ArrayList<byte[]>();
-
- try {
- TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- factory.init((KeyStore) null);
-
- for (TrustManager manager : factory.getTrustManagers()) {
- if (manager instanceof X509TrustManager) {
- X509TrustManager trustManager = (X509TrustManager) manager;
-
- for (X509Certificate certificate : trustManager.getAcceptedIssuers()) {
- byte buffer[] = certificate.getEncoded();
- certificateList.add(buffer);
- }
- }
- }
- } catch (Exception e) {
- Log.e(QtTAG, "Failed to get certificates", e);
- }
-
- byte[][] certificateArray = new byte[certificateList.size()][];
- certificateArray = certificateList.toArray(certificateArray);
- return certificateArray;
- }
-
- private static void createSurface(final int id, final boolean onTop, final int x, final int y, final int w, final int h, final int imageDepth)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.createSurface(id, onTop, x, y, w, h, imageDepth);
- }
- });
- }
-
- private static void insertNativeView(final int id, final View view, final int x, final int y, final int w, final int h)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.insertNativeView(id, view, x, y, w, h);
- }
- });
- }
-
- private static void setSurfaceGeometry(final int id, final int x, final int y, final int w, final int h)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.setSurfaceGeometry(id, x, y, w, h);
- }
- });
- }
-
- private static void bringChildToFront(final int id)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.bringChildToFront(id);
- }
- });
- }
-
- private static void bringChildToBack(final int id)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.bringChildToBack(id);
- }
- });
- }
-
- private static void destroySurface(final int id)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.destroySurface(id);
- }
- });
- }
-
- private static void initializeAccessibility()
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- m_activityDelegate.initializeAccessibility();
- }
- });
- }
-
- private static void hideSplashScreen(final int duration)
- {
- runAction(new Runnable() {
- @Override
- public void run() {
- if (m_activityDelegate != null)
- m_activityDelegate.hideSplashScreen(duration);
- }
- });
- }
-
- private static String[] listAssetContent(android.content.res.AssetManager asset, String path) {
- String [] list;
- ArrayList<String> res = new ArrayList<String>();
- try {
- list = asset.list(path);
- if (list.length > 0) {
- for (String file : list) {
- try {
- String[] isDir = asset.list(path.length() > 0 ? path + "/" + file : file);
- if (isDir != null && isDir.length > 0)
- file += "/";
- res.add(file);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return res.toArray(new String[res.size()]);
- }
-
- // screen methods
- public static native void setDisplayMetrics(int screenWidthPixels,
- int screenHeightPixels,
- int availableLeftPixels,
- int availableTopPixels,
- int availableWidthPixels,
- int availableHeightPixels,
- double XDpi,
- double YDpi,
- double scaledDensity,
- double density);
- public static native void handleOrientationChanged(int newRotation, int nativeOrientation);
- // screen methods
-
- // pointer methods
- public static native void mouseDown(int winId, int x, int y);
- public static native void mouseUp(int winId, int x, int y);
- public static native void mouseMove(int winId, int x, int y);
- public static native void mouseWheel(int winId, int x, int y, float hdelta, float vdelta);
- public static native void touchBegin(int winId);
- public static native void touchAdd(int winId, int pointerId, int action, boolean primary, int x, int y, float major, float minor, float rotation, float pressure);
- public static native void touchEnd(int winId, int action);
- public static native void longPress(int winId, int x, int y);
- // pointer methods
-
- // tablet methods
- public static native boolean isTabletEventSupported();
- public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure);
- // tablet methods
-
- // keyboard methods
- public static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat);
- public static native void keyUp(int key, int unicode, int modifier, boolean autoRepeat);
- public static native void keyboardVisibilityChanged(boolean visibility);
- public static native void keyboardGeometryChanged(int x, int y, int width, int height);
- // keyboard methods
-
- // handle methods
- public static final int IdCursorHandle = 1;
- public static final int IdLeftHandle = 2;
- public static final int IdRightHandle = 3;
- public static native void handleLocationChanged(int id, int x, int y);
- // handle methods
-
- // dispatch events methods
- public static native boolean dispatchGenericMotionEvent(MotionEvent ev);
- public static native boolean dispatchKeyEvent(KeyEvent event);
- // dispatch events methods
-
- // surface methods
- public static native void setSurface(int id, Object surface, int w, int h);
- // surface methods
-
- // window methods
- public static native void updateWindow();
- // window methods
-
- // application methods
- public static native void updateApplicationState(int state);
-
- // menu methods
- public static native boolean onPrepareOptionsMenu(Menu menu);
- public static native boolean onOptionsItemSelected(int itemId, boolean checked);
- public static native void onOptionsMenuClosed(Menu menu);
-
- public static native void onCreateContextMenu(ContextMenu menu);
- public static native void fillContextMenu(Menu menu);
- public static native boolean onContextItemSelected(int itemId, boolean checked);
- public static native void onContextMenuClosed(Menu menu);
- // menu methods
-
- // clipboard methods
- public static native void onClipboardDataChanged();
- // clipboard methods
-
- // activity methods
- public static native void onActivityResult(int requestCode, int resultCode, Intent data);
- public static native void onNewIntent(Intent data);
-
- public static native void runPendingCppRunnables();
-
- public static native void sendRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
-
- private static native void setNativeActivity(Activity activity);
- private static native void setNativeService(Service service);
- // activity methods
-
- // service methods
- public static native IBinder onBind(Intent intent);
- // service methods
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNativeLibrariesDir.java b/src/android/jar/src/org/qtproject/qt5/android/QtNativeLibrariesDir.java
deleted file mode 100644
index 4a732f7f7f..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNativeLibrariesDir.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-
-public class QtNativeLibrariesDir {
- public static final String systemLibrariesDir = "/system/lib/";
- public static String nativeLibrariesDir(Context context)
- {
- String m_nativeLibraryDir = null;
- try {
- ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
- m_nativeLibraryDir = ai.nativeLibraryDir + "/";
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- }
- return m_nativeLibraryDir;
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtServiceDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtServiceDelegate.java
deleted file mode 100644
index 6e75eafeab..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtServiceDelegate.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Configuration;
-import android.graphics.drawable.ColorDrawable;
-import android.net.LocalServerSocket;
-import android.net.LocalSocket;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.ResultReceiver;
-import android.text.method.MetaKeyKeyListener;
-import android.util.Base64;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.util.TypedValue;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.KeyCharacterMap;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.Surface;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-public class QtServiceDelegate
-{
- private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
- private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
- private static final String MAIN_LIBRARY_KEY = "main.library";
- private static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
- private static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
- private static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
- private static final String APP_DISPLAY_METRIC_SCREEN_DESKTOP_KEY = "display.screen.desktop";
- private static final String APP_DISPLAY_METRIC_SCREEN_XDPI_KEY = "display.screen.dpi.x";
- private static final String APP_DISPLAY_METRIC_SCREEN_YDPI_KEY = "display.screen.dpi.y";
- private static final String APP_DISPLAY_METRIC_SCREEN_DENSITY_KEY = "display.screen.density";
-
- private String m_mainLib = null;
- private Service m_service = null;
- private static String m_environmentVariables = null;
- private static String m_applicationParameters = null;
-
- public boolean loadApplication(Service service, ClassLoader classLoader, Bundle loaderParams)
- {
- /// check parameters integrity
- if (!loaderParams.containsKey(NATIVE_LIBRARIES_KEY)
- || !loaderParams.containsKey(BUNDLED_LIBRARIES_KEY)) {
- return false;
- }
-
- m_service = service;
- QtNative.setService(m_service, this);
- QtNative.setClassLoader(classLoader);
-
- QtNative.setApplicationDisplayMetrics(10, 10, 0, 0, 10, 10, 120, 120, 1.0, 1.0);
-
- if (loaderParams.containsKey(STATIC_INIT_CLASSES_KEY)) {
- for (String className: loaderParams.getStringArray(STATIC_INIT_CLASSES_KEY)) {
- if (className.length() == 0)
- continue;
- try {
- Class<?> initClass = classLoader.loadClass(className);
- Object staticInitDataObject = initClass.newInstance(); // create an instance
- try {
- Method m = initClass.getMethod("setService", Service.class, Object.class);
- m.invoke(staticInitDataObject, m_service, this);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- try {
- Method m = initClass.getMethod("setContext", Context.class);
- m.invoke(staticInitDataObject, (Context)m_service);
- } catch (Exception e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- QtNative.loadQtLibraries(loaderParams.getStringArrayList(NATIVE_LIBRARIES_KEY));
- ArrayList<String> libraries = loaderParams.getStringArrayList(BUNDLED_LIBRARIES_KEY);
- String nativeLibsDir = QtNativeLibrariesDir.nativeLibrariesDir(m_service);
- QtNative.loadBundledLibraries(libraries, nativeLibsDir);
- m_mainLib = loaderParams.getString(MAIN_LIBRARY_KEY);
- m_environmentVariables = loaderParams.getString(ENVIRONMENT_VARIABLES_KEY);
- String additionalEnvironmentVariables = "QT_ANDROID_FONTS_MONOSPACE=Droid Sans Mono;Droid Sans;Droid Sans Fallback"
- + "\tQT_ANDROID_FONTS_SERIF=Droid Serif"
- + "\tHOME=" + m_service.getFilesDir().getAbsolutePath()
- + "\tTMPDIR=" + m_service.getFilesDir().getAbsolutePath();
- if (Build.VERSION.SDK_INT < 14)
- additionalEnvironmentVariables += "\tQT_ANDROID_FONTS=Droid Sans;Droid Sans Fallback";
- else
- additionalEnvironmentVariables += "\tQT_ANDROID_FONTS=Roboto;Droid Sans;Droid Sans Fallback";
-
- if (m_environmentVariables != null && m_environmentVariables.length() > 0)
- m_environmentVariables = additionalEnvironmentVariables + "\t" + m_environmentVariables;
- else
- m_environmentVariables = additionalEnvironmentVariables;
-
- if (loaderParams.containsKey(APPLICATION_PARAMETERS_KEY))
- m_applicationParameters = loaderParams.getString(APPLICATION_PARAMETERS_KEY);
- else
- m_applicationParameters = "";
-
- m_mainLib = QtNative.loadMainLibrary(m_mainLib, nativeLibsDir);
- return m_mainLib != null;
- }
-
- public boolean startApplication()
- {
- // start application
- try {
- String nativeLibraryDir = QtNativeLibrariesDir.nativeLibrariesDir(m_service);
- QtNative.startApplication(m_applicationParameters, m_environmentVariables, m_mainLib);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public void onDestroy()
- {
- QtNative.quitQtCoreApplication();
- QtNative.terminateQt();
- QtNative.setService(null, null);
- QtNative.m_qtThread.exit();
- System.exit(0);
- }
-
- public IBinder onBind(Intent intent)
- {
- synchronized (this) {
- return QtNative.onBind(intent);
- }
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java
deleted file mode 100644
index 08b5a80f7e..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import android.app.Activity;
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.view.GestureDetector;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-
-public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
-{
- private GestureDetector m_gestureDetector;
- private Object m_accessibilityDelegate = null;
-
- public QtSurface(Context context, int id, boolean onTop, int imageDepth)
- {
- super(context);
- setFocusable(false);
- setFocusableInTouchMode(false);
- setZOrderMediaOverlay(onTop);
- getHolder().addCallback(this);
- if (imageDepth == 16)
- getHolder().setFormat(PixelFormat.RGB_565);
- else
- getHolder().setFormat(PixelFormat.RGBA_8888);
-
- setId(id);
- m_gestureDetector =
- new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
- public void onLongPress(MotionEvent event) {
- QtNative.longPress(getId(), (int) event.getX(), (int) event.getY());
- }
- });
- m_gestureDetector.setIsLongpressEnabled(true);
- }
-
- @Override
- public void surfaceCreated(SurfaceHolder holder)
- {
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
- {
- if (width < 1 || height < 1)
- return;
-
- QtNative.setSurface(getId(), holder.getSurface(), width, height);
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder)
- {
- QtNative.setSurface(getId(), null, 0, 0);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event)
- {
- QtNative.sendTouchEvent(event, getId());
- m_gestureDetector.onTouchEvent(event);
- return true;
- }
-
- @Override
- public boolean onTrackballEvent(MotionEvent event)
- {
- QtNative.sendTrackballEvent(event, getId());
- return true;
- }
-
- @Override
- public boolean onGenericMotionEvent(MotionEvent event)
- {
- return QtNative.sendGenericMotionEvent(event, getId());
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtThread.java b/src/android/jar/src/org/qtproject/qt5/android/QtThread.java
deleted file mode 100644
index 975e787345..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/QtThread.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 BogDan Vatra <bogdan@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android;
-
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-public class QtThread {
- private ArrayList<Runnable> m_pendingRunnables = new ArrayList<Runnable>();
- private boolean m_exit = false;
- private Thread m_qtThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (!m_exit) {
- try {
- ArrayList<Runnable> pendingRunnables;
- synchronized (m_qtThread) {
- if (m_pendingRunnables.size() == 0)
- m_qtThread.wait();
- pendingRunnables = new ArrayList<Runnable>(m_pendingRunnables);
- m_pendingRunnables.clear();
- }
- for (Runnable runnable : pendingRunnables)
- runnable.run();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- });
-
- QtThread() {
- m_qtThread.setName("qtMainLoopThread");
- m_qtThread.start();
- }
-
- public void post(final Runnable runnable) {
- synchronized (m_qtThread) {
- m_pendingRunnables.add(runnable);
- m_qtThread.notify();
- }
- }
-
- public void run(final Runnable runnable) {
- final Semaphore sem = new Semaphore(0);
- synchronized (m_qtThread) {
- m_pendingRunnables.add(new Runnable() {
- @Override
- public void run() {
- runnable.run();
- sem.release();
- }
- });
- m_qtThread.notify();
- }
- try {
- sem.acquire();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- public void exit()
- {
- m_exit = true;
- synchronized (m_qtThread) {
- m_qtThread.notify();
- }
- try {
- m_qtThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java
deleted file mode 100644
index 79caaf318e..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-package org.qtproject.qt5.android.accessibility;
-
-import android.accessibilityservice.AccessibilityService;
-import android.app.Activity;
-import android.graphics.Rect;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewParent;
-import android.text.TextUtils;
-
-import android.view.accessibility.*;
-import android.view.MotionEvent;
-import android.view.View.OnHoverListener;
-
-import android.content.Context;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.qtproject.qt5.android.QtActivityDelegate;
-
-public class QtAccessibilityDelegate extends View.AccessibilityDelegate
-{
- private static final String TAG = "Qt A11Y";
-
- // Qt uses the upper half of the unsiged integers
- // all low positive ints should be fine.
- public static final int INVALID_ID = 333; // half evil
-
- // The platform might ask for the class implementing the "view".
- // Pretend to be an inner class of the QtSurface.
- private static final String DEFAULT_CLASS_NAME = "$VirtualChild";
-
- private View m_view = null;
- private AccessibilityManager m_manager;
- private QtActivityDelegate m_activityDelegate;
- private Activity m_activity;
- private ViewGroup m_layout;
-
- // The accessible object that currently has the "accessibility focus"
- // usually indicated by a yellow rectangle on screen.
- private int m_focusedVirtualViewId = INVALID_ID;
- // When exploring the screen by touch, the item "hovered" by the finger.
- private int m_hoveredVirtualViewId = INVALID_ID;
-
- // Cache coordinates of the view to know the global offset
- // this is because the Android platform window does not take
- // the offset of the view on screen into account (eg status bar on top)
- private final int[] m_globalOffset = new int[2];
-
- private class HoverEventListener implements View.OnHoverListener
- {
- @Override
- public boolean onHover(View v, MotionEvent event)
- {
- return dispatchHoverEvent(event);
- }
- }
-
- public QtAccessibilityDelegate(Activity activity, ViewGroup layout, QtActivityDelegate activityDelegate)
- {
- m_activity = activity;
- m_layout = layout;
- m_activityDelegate = activityDelegate;
-
- m_manager = (AccessibilityManager) m_activity.getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (m_manager != null) {
- AccessibilityManagerListener accServiceListener = new AccessibilityManagerListener();
- if (!m_manager.addAccessibilityStateChangeListener(accServiceListener))
- Log.w("Qt A11y", "Could not register a11y state change listener");
- if (m_manager.isEnabled())
- accServiceListener.onAccessibilityStateChanged(true);
- }
- }
-
- private class AccessibilityManagerListener implements AccessibilityManager.AccessibilityStateChangeListener
- {
- @Override
- public void onAccessibilityStateChanged(boolean enabled)
- {
- if (enabled) {
- try {
- View view = m_view;
- if (view == null) {
- view = new View(m_activity);
- view.setId(View.NO_ID);
- }
-
- // ### Keep this for debugging for a while. It allows us to visually see that our View
- // ### is on top of the surface(s)
- // ColorDrawable color = new ColorDrawable(0x80ff8080); //0xAARRGGBB
- // view.setBackground(color);
- view.setAccessibilityDelegate(QtAccessibilityDelegate.this);
-
- // if all is fine, add it to the layout
- if (m_view == null) {
- //m_layout.addAccessibilityView(view);
- m_layout.addView(view, m_activityDelegate.getSurfaceCount(),
- new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
- }
- m_view = view;
-
- m_view.setOnHoverListener(new HoverEventListener());
- } catch (Exception e) {
- // Unknown exception means something went wrong.
- Log.w("Qt A11y", "Unknown exception: " + e.toString());
- }
- } else {
- if (m_view != null) {
- m_layout.removeView(m_view);
- m_view = null;
- }
- }
-
- QtNativeAccessibility.setActive(enabled);
- }
- }
-
-
- @Override
- public AccessibilityNodeProvider getAccessibilityNodeProvider(View host)
- {
- return m_nodeProvider;
- }
-
- // For "explore by touch" we need all movement events here first
- // (user moves finger over screen to discover items on screen).
- private boolean dispatchHoverEvent(MotionEvent event)
- {
- if (!m_manager.isTouchExplorationEnabled()) {
- return false;
- }
-
- int virtualViewId = QtNativeAccessibility.hitTest(event.getX(), event.getY());
- if (virtualViewId == INVALID_ID) {
- virtualViewId = View.NO_ID;
- }
-
- switch (event.getAction()) {
- case MotionEvent.ACTION_HOVER_ENTER:
- case MotionEvent.ACTION_HOVER_MOVE:
- setHoveredVirtualViewId(virtualViewId);
- break;
- case MotionEvent.ACTION_HOVER_EXIT:
- setHoveredVirtualViewId(virtualViewId);
- break;
- }
-
- return true;
- }
-
- public boolean sendEventForVirtualViewId(int virtualViewId, int eventType)
- {
- if ((virtualViewId == INVALID_ID) || !m_manager.isEnabled()) {
- Log.w(TAG, "sendEventForVirtualViewId for invalid view");
- return false;
- }
-
- final ViewGroup group = (ViewGroup) m_view.getParent();
- if (group == null) {
- Log.w(TAG, "Could not send AccessibilityEvent because group was null. This should really not happen.");
- return false;
- }
-
- final AccessibilityEvent event;
- event = getEventForVirtualViewId(virtualViewId, eventType);
- return group.requestSendAccessibilityEvent(m_view, event);
- }
-
- public void invalidateVirtualViewId(int virtualViewId)
- {
- sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
- }
-
- private void setHoveredVirtualViewId(int virtualViewId)
- {
- if (m_hoveredVirtualViewId == virtualViewId) {
- return;
- }
-
- final int previousVirtualViewId = m_hoveredVirtualViewId;
- m_hoveredVirtualViewId = virtualViewId;
- sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
- sendEventForVirtualViewId(previousVirtualViewId, AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
- }
-
- private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType)
- {
- final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
-
- event.setEnabled(true);
- event.setClassName(m_view.getClass().getName() + DEFAULT_CLASS_NAME);
-
- event.setContentDescription(QtNativeAccessibility.descriptionForAccessibleObject(virtualViewId));
- if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription()))
- Log.w(TAG, "AccessibilityEvent with empty description");
-
- event.setPackageName(m_view.getContext().getPackageName());
- event.setSource(m_view, virtualViewId);
- return event;
- }
-
- private void dumpNodes(int parentId)
- {
- Log.i(TAG, "A11Y hierarchy: " + parentId + " parent: " + QtNativeAccessibility.parentId(parentId));
- Log.i(TAG, " desc: " + QtNativeAccessibility.descriptionForAccessibleObject(parentId) + " rect: " + QtNativeAccessibility.screenRect(parentId));
- Log.i(TAG, " NODE: " + getNodeForVirtualViewId(parentId));
- int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(parentId);
- for (int i = 0; i < ids.length; ++i) {
- Log.i(TAG, parentId + " has child: " + ids[i]);
- dumpNodes(ids[i]);
- }
- }
-
- private AccessibilityNodeInfo getNodeForView()
- {
- // Since we don't want the parent to be focusable, but we can't remove
- // actions from a node, copy over the necessary fields.
- final AccessibilityNodeInfo result = AccessibilityNodeInfo.obtain(m_view);
- final AccessibilityNodeInfo source = AccessibilityNodeInfo.obtain(m_view);
- m_view.onInitializeAccessibilityNodeInfo(source);
-
- // Get the actual position on screen, taking the status bar into account.
- m_view.getLocationOnScreen(m_globalOffset);
- final int offsetX = m_globalOffset[0];
- final int offsetY = m_globalOffset[1];
-
- // Copy over parent and screen bounds.
- final Rect m_tempParentRect = new Rect();
- source.getBoundsInParent(m_tempParentRect);
- result.setBoundsInParent(m_tempParentRect);
-
- final Rect m_tempScreenRect = new Rect();
- source.getBoundsInScreen(m_tempScreenRect);
- m_tempScreenRect.offset(offsetX, offsetY);
- result.setBoundsInScreen(m_tempScreenRect);
-
- // Set up the parent view, if applicable.
- final ViewParent parent = m_view.getParent();
- if (parent instanceof View) {
- result.setParent((View) parent);
- }
-
- result.setVisibleToUser(source.isVisibleToUser());
- result.setPackageName(source.getPackageName());
- result.setClassName(source.getClassName());
-
-// Spit out the entire hierarchy for debugging purposes
-// dumpNodes(-1);
-
- int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(-1);
- for (int i = 0; i < ids.length; ++i)
- result.addChild(m_view, ids[i]);
-
- return result;
- }
-
- private AccessibilityNodeInfo getNodeForVirtualViewId(int virtualViewId)
- {
- final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
-
- node.setClassName(m_view.getClass().getName() + DEFAULT_CLASS_NAME);
- node.setPackageName(m_view.getContext().getPackageName());
-
- if (!QtNativeAccessibility.populateNode(virtualViewId, node))
- return node;
-
- // set only if valid, otherwise we return a node that is invalid and will crash when accessed
- node.setSource(m_view, virtualViewId);
-
- if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription()))
- Log.w(TAG, "AccessibilityNodeInfo with empty contentDescription: " + virtualViewId);
-
- int parentId = QtNativeAccessibility.parentId(virtualViewId);
- node.setParent(m_view, parentId);
-
- Rect screenRect = QtNativeAccessibility.screenRect(virtualViewId);
- final int offsetX = m_globalOffset[0];
- final int offsetY = m_globalOffset[1];
- screenRect.offset(offsetX, offsetY);
- node.setBoundsInScreen(screenRect);
-
- Rect rectInParent = screenRect;
- Rect parentScreenRect = QtNativeAccessibility.screenRect(parentId);
- rectInParent.offset(-parentScreenRect.left, -parentScreenRect.top);
- node.setBoundsInParent(rectInParent);
-
- // Manage internal accessibility focus state.
- if (m_focusedVirtualViewId == virtualViewId) {
- node.setAccessibilityFocused(true);
- node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
- } else {
- node.setAccessibilityFocused(false);
- node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
- }
-
- int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(virtualViewId);
- for (int i = 0; i < ids.length; ++i)
- node.addChild(m_view, ids[i]);
- return node;
- }
-
- private AccessibilityNodeProvider m_nodeProvider = new AccessibilityNodeProvider()
- {
- @Override
- public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId)
- {
- if (virtualViewId == View.NO_ID) {
- return getNodeForView();
- }
- return getNodeForVirtualViewId(virtualViewId);
- }
-
- @Override
- public boolean performAction(int virtualViewId, int action, Bundle arguments)
- {
- boolean handled = false;
- //Log.i(TAG, "PERFORM ACTION: " + action + " on " + virtualViewId);
- switch (action) {
- case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
- // Only handle the FOCUS action if it's placing focus on
- // a different view that was previously focused.
- if (m_focusedVirtualViewId != virtualViewId) {
- m_focusedVirtualViewId = virtualViewId;
- m_view.invalidate();
- sendEventForVirtualViewId(virtualViewId,
- AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
- handled = true;
- }
- break;
- case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
- if (m_focusedVirtualViewId == virtualViewId) {
- m_focusedVirtualViewId = INVALID_ID;
- }
- // Since we're managing focus at the parent level, we are
- // likely to receive a FOCUS action before a CLEAR_FOCUS
- // action. We'll give the benefit of the doubt to the
- // framework and always handle FOCUS_CLEARED.
- m_view.invalidate();
- sendEventForVirtualViewId(virtualViewId,
- AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
- handled = true;
- break;
- default:
- // Let the node provider handle focus for the view node.
- if (virtualViewId == View.NO_ID) {
- return m_view.performAccessibilityAction(action, arguments);
- }
- }
- handled |= performActionForVirtualViewId(virtualViewId, action, arguments);
-
- return handled;
- }
- };
-
- protected boolean performActionForVirtualViewId(int virtualViewId, int action, Bundle arguments)
- {
-// Log.i(TAG, "ACTION " + action + " on " + virtualViewId);
-// dumpNodes(virtualViewId);
- boolean success = false;
- switch (action) {
- case AccessibilityNodeInfo.ACTION_CLICK:
- success = QtNativeAccessibility.clickAction(virtualViewId);
- if (success)
- sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_CLICKED);
- break;
- case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
- success = QtNativeAccessibility.scrollForward(virtualViewId);
- if (success)
- sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_SCROLLED);
- break;
- case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
- success = QtNativeAccessibility.scrollBackward(virtualViewId);
- if (success)
- sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_SCROLLED);
- break;
- }
- return success;
- }
-}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtNativeAccessibility.java b/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtNativeAccessibility.java
deleted file mode 100644
index a83174377d..0000000000
--- a/src/android/jar/src/org/qtproject/qt5/android/accessibility/QtNativeAccessibility.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt5.android.accessibility;
-
-import android.graphics.Rect;
-import android.view.accessibility.AccessibilityNodeInfo;
-
-class QtNativeAccessibility
-{
- static native void setActive(boolean enable);
- static native int[] childIdListForAccessibleObject(int objectId);
- static native int parentId(int objectId);
- static native String descriptionForAccessibleObject(int objectId);
- static native Rect screenRect(int objectId);
- static native int hitTest(float x, float y);
- static native boolean clickAction(int objectId);
- static native boolean scrollForward(int objectId);
- static native boolean scrollBackward(int objectId);
-
- static native boolean populateNode(int objectId, AccessibilityNodeInfo node);
-}