Skip to content

Instantly share code, notes, and snippets.

Avatar

< B@!uS /> BALUSANGEM

View GitHub Profile
View SimpleDelay.kt
class MainActivity : AppCompatActivity() {
val TAG = MainActivity::class.java.simpleName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val handler = Handler(Looper.getMainLooper())
Log.d(TAG, "Before post delayed:${System.currentTimeMillis()}")
handler.postDelayed(
{
@BALUSANGEM
BALUSANGEM / ViewRenderer.java
Created Jun 14, 2018
This class renders video in ARCore, So you can use this gist to play Videos inside ARCore Scene
View ViewRenderer.java
public class VideoRenderer implements SurfaceTexture.OnFrameAvailableListener {
private SurfaceTexture videoTexture;
private int mTextureId;
private static final int TEXCOORDS_PER_VERTEX = 2;
private static final int COORDS_PER_VERTEX = 3;
private String TAG = VideoRenderer.class.getSimpleName();
private int mQuadProgram;
private final Object lock = new Object();
View ImageDecoder_PostProcessor_CircularDrawable.kt
val source = ImageDecoder.createSource(assets, "image.jpg")
val listener = ImageDecoder.OnHeaderDecodedListener { decoder, info, src ->
decoder.setPostProcessor { canvas ->
// This will create rounded corners.
val path = Path()
path.fillType = Path.FillType.INVERSE_EVEN_ODD
val width = canvas.width
val height = canvas.height
path.addRoundRect(0f, 0f, width.toFloat(), height.toFloat(), width / 2.toFloat(), height / 2.toFloat(), Path.Direction.CW)
val paint = Paint()
View ImageDecoder_OnHeaderDecodedListener_Into.kt
val listener = ImageDecoder.OnHeaderDecodedListener { decoder, imageinfo, source ->
decoder.setTargetSize(100, 100)
//you can use setTargetSampleSize(2) to create a image with half of original height and width
}
val drawable = ImageDecoder.decodeDrawable(source, listener);
@BALUSANGEM
BALUSANGEM / HelloARActivity_modifiedforVideo.java
Last active Jun 14, 2018
Using this activity and ViewRenderer.java you can play video in ARCore scene
View HelloARActivity_modifiedforVideo.java
public class HelloArActivity extends AppCompatActivity implements GLSurfaceView.Renderer {
private static final String TAG = HelloArActivity.class.getSimpleName();
// Rendering. The Renderers are created here, and initialized when the GL surface is created.
private GLSurfaceView surfaceView;
private boolean installRequested;
private final VideoRenderer videoRenderer = new VideoRenderer();
View VideoRenderer_createOnGlThread().java
public void createOnGlThread() {
// 1 texture to hold the video frame.
int textures[] = new int[1];
GLES20.glGenTextures(1, textures, 0);
mTextureId = textures[0];
int mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES;
GLES20.glBindTexture(mTextureTarget, mTextureId);
GLES20.glTexParameteri(mTextureTarget, GLES20.GL_TEXTURE_MIN_FILTER,
View VideoRenderer_update().java
public void update(float[] modelMatrix) {
float[] scaleMatrix = new float[16];
Matrix.setIdentityM(scaleMatrix, 0);
float SCALE_FACTOR = 1f;
scaleMatrix[0] = SCALE_FACTOR;
scaleMatrix[5] = SCALE_FACTOR;
scaleMatrix[10] = SCALE_FACTOR;
Matrix.multiplyMM(this.mModelMatrix, 0, modelMatrix, 0, scaleMatrix, 0);
}
View ViewRenderer_draw().java
public void draw(float[] cameraView, float[] cameraPerspective) {
if (done || !prepared) {
return;
}
synchronized (this) {
if (frameAvailable) {
videoTexture.updateTexImage();
frameAvailable = false;
if (videoTexture != null) {
View LauncherSecondActivity.java
public class AppsListActivity extends Activity {
private PackageManager manager;
private ArrayList<AppDetail> apps;
private ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apps_list);
View STACK_ACTIVITY
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
goto_main_screen_button.setOnClickListener {
gotoMainScreen()
}
}
private fun gotoMainScreen() {