Android: Don't show translucent system UI on top of Qt

On devices by some vendors (Android 4.4+), the default UI theme
will have translucent system UI which is placed on top of the
main activity layout. When this is unexpected, it may lead to
the system UI overlapping with the application's UI on these
devices. By default we tell Android to account for the system UI
in the main activity's layout, so that the window contents are
positioned outside of it. This is done with a new outermost layout
which is just used to size the QtLayout correctly.

Since there is a use case where people explicitly want translucency
on the system UI and have adapted its contents to accommodate for
this, we supply the android.app.allow_overlapping_system_ui setting
which can be set to true in the AndroidManifest.xml to override the
default behavior.

[ChangeLog][Android] On devices with translucent system UI, Qt's
window is now positioned to avoid overlap with this by default.
This behavior can be overridden in the application's
AndroidManifest.xml.

Change-Id: I2b34e948f3bd655f883f30b0419d9c6ba69242be
Task-number: QTBUG-38700
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2015-03-11 11:52:00 +01:00
parent 4add7d236b
commit c9aaa3e2cd
2 changed files with 28 additions and 1 deletions

View File

@ -65,6 +65,7 @@ import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import java.io.BufferedReader;
import java.io.DataOutputStream;
@ -788,7 +789,29 @@ public class QtActivityDelegate
0, 0,
metrics.xdpi, metrics.ydpi, metrics.scaledDensity);
}
ViewGroup layout = null;
m_layout = new QtLayout(m_activity);
if (Build.VERSION.SDK_INT >= 14) {
try {
ActivityInfo activityInfo = m_activity.getPackageManager().getActivityInfo(m_activity.getComponentName(),
PackageManager.GET_META_DATA);
if (activityInfo.metaData == null
|| !activityInfo.metaData.containsKey("android.app.allow_overlapping_system_ui")
|| !activityInfo.metaData.getBoolean("android.app.allow_overlapping_system_ui")) {
layout = new LinearLayout(m_activity);
layout.setFitsSystemWindows(true);
layout.addView(m_layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (layout == null)
layout = m_layout;
m_editText = new QtEditText(m_activity, this);
m_imm = (InputMethodManager)m_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
m_surfaces = new HashMap<Integer, QtSurface>();
@ -811,7 +834,7 @@ public class QtActivityDelegate
Log.w("Qt A11y", "Unknown exception: " + e.toString());
}
m_activity.setContentView(m_layout,
m_activity.setContentView(layout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));

View File

@ -44,6 +44,10 @@
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="false"/>
<!-- Background running -->
<!-- Show translucent UI on top of Qt's surface when system theme mandates it -->
<meta-data android:name="android.app.allow_overlapping_system_ui" android:value="false"/>
<!-- Show translucent UI on top of Qt's surface when system theme mandates it -->
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>