Files
QuestAppLauncher/Assets/Plugins/Android/AppInfo.java
tverona1 3eb5fd2198 Preliminary support for tabs and also fix an issue with scroll view collider
- Added preliminary support for tabs: Added config support for "categoryType" specifying "none" or "auto". None means no tabs. Auto means that we create 3 tabs - Quest, Go/GearVR and 2D. These apps types are distinguished based on package information.
- Added support in UI for showing / hiding 2D apps.
- Fixed an issue with scroll view collider: Looks like Unity UI scroll view object does not interact very well in a VR environment. This one was a doozy. I noticed, although the scroll view masks UI that falls outside its rectangle (as it should), it does not suppress colliders. This means that it's possible to interact with colliders that get scrolled above the scroll view (i.e. like clicking on a cell to launch an app when that cell is outside the scroll view). The bigger problem is that this interfered with the tabs, which are above the scroll view. After contemplating several solutions, I ended up with a simple but effective one:
            // To fix this issue, we cast a ray from current pointer to the scroll view's box collider.
            // If we get a hit, it means we're inside the scroll view - so we enable all the children box
            // colliders, which will behave as expected.
            // If we do not get a hit, it means that we're outside the scroll view - so we disable all the children
            // box colliders, which addresses the issue above.
2019-07-27 16:48:07 -07:00

91 lines
2.8 KiB
Java

package aaa.QuestAppLauncher.App;
import com.unity3d.player.UnityPlayerActivity;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.util.Log;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.LinkedList;
public class AppInfo extends UnityPlayerActivity {
private static final String TAG = "AppInfo";
private List<ApplicationInfo> installedApps;
@Override
protected void onStart() {
super.onStart();
installedApps = new LinkedList<ApplicationInfo>();
for(ApplicationInfo app : this.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA)) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// Skip system app
continue;
}
installedApps.add(app);
}
}
public int getSize() {
return this.installedApps.size();
}
public String getPackageName(int i) {
return this.installedApps.get(i).packageName;
}
public String getAppName(int i) {
return (String)this.getPackageManager().getApplicationLabel(installedApps.get(i));
}
public boolean isQuestApp(int i) {
try {
PackageInfo info = this.getPackageManager().getPackageInfo(getPackageName(i), PackageManager.GET_CONFIGURATIONS);
if (null == info.reqFeatures) {
return false;
}
for (FeatureInfo f : info.reqFeatures) {
if (f.name != null && f.name.equals("android.hardware.vr.headtracking")) {
return true;
}
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return false;
}
public boolean is2DApp(int i)
{
ApplicationInfo app = this.installedApps.get(i);
if (null == app.metaData)
{
return true;
}
String vrAppMode = app.metaData.getString("com.samsung.android.vr.application.mode");
if (null == vrAppMode || !vrAppMode.equals("vr_only")) {
return true;
}
return false;
}
public byte[] getIcon(int i) {
BitmapDrawable icon = (BitmapDrawable)this.getPackageManager().getApplicationIcon(installedApps.get(i));
Bitmap bmp = icon.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
}