-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
build/android/app/src/main/java/com/facebook/igl/sample/NanovgSampleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters