Skip to content

Commit

Permalink
android : Add NanovgSampleActivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsentli committed Dec 22, 2024
1 parent 5a7eaf2 commit 8e85c44
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// @fb-only

package com.facebook.igl.shell;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class NanovgSampleActivity extends SampleActivity implements View.OnClickListener {
private static String TAG = "NanovgSampleActivity";

@Override
protected void onCreate(Bundle icicle) {
mEnableStencilBuffer = true;

super.onCreate(icicle);

boolean hasCopy = getSharedPreferences("data", Context.MODE_PRIVATE).getBoolean("HasCopyAssets", false);

if (!hasCopy) {
copyAssetsDirToSDCard(this, "", getFilesDir().getAbsolutePath());

SharedPreferences.Editor editor = getSharedPreferences("data", Context.MODE_PRIVATE).edit();
editor.putBoolean("HasCopyAssets",true);
editor.commit();
}
}

public static void copyAssetsDirToSDCard(Context context, String assetsDirName, String sdCardPath) {
Log.d(TAG, "copyAssetsDirToSDCard() called with: context = [" + context + "], assetsDirName = [" + assetsDirName + "], sdCardPath = [" + sdCardPath + "]");
try {
String list[] = context.getAssets().list(assetsDirName);
if (list.length == 0) {
InputStream inputStream = context.getAssets().open(assetsDirName);
byte[] mByte = new byte[1024];
int bt = 0;
File file = new File(sdCardPath + File.separator
+ assetsDirName);
if (!file.exists()) {
file.createNewFile();
} else {
return;
}
FileOutputStream fos = new FileOutputStream(file);
while ((bt = inputStream.read(mByte)) != -1) {
fos.write(mByte, 0, bt);
}
fos.flush();
inputStream.close();
fos.close();
} else {
String subDirName = assetsDirName;
if (assetsDirName.contains("/")) {
subDirName = assetsDirName.substring(assetsDirName.lastIndexOf('/') + 1);
}
sdCardPath = sdCardPath + File.separator + subDirName;
File file = new File(sdCardPath);
if (!file.exists())
file.mkdirs();
for (String s : list) {
String fileName = assetsDirName.length() > 0 ? assetsDirName + File.separator + s : s;
copyAssetsDirToSDCard(context, fileName , sdCardPath);
}
}
} catch (
Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SampleActivity extends Activity implements View.OnClickListener {
private final int selectedTabColor = Color.BLUE;
private final int unSelectedTabColor = Color.GRAY;

protected boolean mEnableStencilBuffer = false;

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Expand Down Expand Up @@ -69,7 +71,7 @@ protected void onCreate(Bundle icicle) {
} else if (mConfigs[i].version.flavor == SampleLib.BackendFlavor.OpenGL_ES) {
backendView =
new SampleView(
getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat);
getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat, mEnableStencilBuffer);
((SampleView) backendView).onPause();
}

Expand Down
27 changes: 27 additions & 0 deletions build/android/nanovg/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="IGLNanovg"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.IGL"
tools:targetApi="33">
<activity
android:name=".NanovgSampleActivity"
android:configChanges="orientation|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
2 changes: 1 addition & 1 deletion build/android/nanovg/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ android {

sourceSets {
main {
manifest.srcFile '../app/src/main/AndroidManifest.xml'
manifest.srcFile 'AndroidManifest.xml'
res.srcDir '../app/src/main/res/'

java.srcDir 'java'
Expand Down

0 comments on commit 8e85c44

Please sign in to comment.