Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Samsung/GearVRf into stat…
Browse files Browse the repository at this point in the history
…esort
  • Loading branch information
NolaDonato committed Oct 18, 2018
2 parents 2602799 + 4e6a7d2 commit 4258e7d
Show file tree
Hide file tree
Showing 472 changed files with 49,817 additions and 5,745 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,27 +435,27 @@ public boolean replaceCursor(Cursor newCursor, Cursor oldCursor)
private void showSettingsMenu(final Cursor cursor) {
Log.d(TAG, "showSettingsMenu");
enableSettingsCursor(cursor);
context.getActivity().runOnUiThread(new Runnable() {
context.runOnGlThread(new Runnable() {
@Override
public void run() {
new SettingsView(context, scene, CursorManager.this,
settingsCursor.getIoDevice().getCursorControllerId(), cursor, new
SettingsChangeListener() {
@Override
public void onBack(boolean cascading) {
disableSettingsCursor();
}

@Override
public int onDeviceChanged(IoDevice device) {
// we are changing the io device on the settings cursor
removeCursorFromScene(settingsCursor);
IoDevice clickedDevice = getAvailableIoDevice(device);
settingsCursor.setIoDevice(clickedDevice);
addCursorToScene(settingsCursor);
return device.getCursorControllerId();
}
});
settingsCursor.getIoDevice().getCursorControllerId(), cursor, new
SettingsChangeListener() {
@Override
public void onBack(boolean cascading) {
disableSettingsCursor();
}

@Override
public int onDeviceChanged(IoDevice device) {
// we are changing the io device on the settings cursor
removeCursorFromScene(settingsCursor);
IoDevice clickedDevice = getAvailableIoDevice(device);
settingsCursor.setIoDevice(clickedDevice);
addCursorToScene(settingsCursor);
return device.getCursorControllerId();
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

import org.gearvrf.GVRContext;
import org.gearvrf.GVRSceneObject;
import org.gearvrf.animation.GVRAnimation;
import org.gearvrf.animation.GVRAnimationEngine;
import org.gearvrf.animation.GVRAnimator;
import org.gearvrf.animation.GVRRepeatMode;
import org.gearvrf.scene_objects.GVRModelSceneObject;
import org.gearvrf.utility.Log;

import java.io.IOException;
Expand All @@ -34,37 +33,39 @@
class ObjectCursorAsset extends CursorAsset {
private static final String TAG = ObjectCursorAsset.class.getSimpleName();
private final String assetName;
private SparseArray<GVRModelSceneObject> objects;
private SparseArray<GVRSceneObject> objects;
private GVRAnimationEngine animationEngine;
private int LOOP_REPEAT_COUNT = -1;

ObjectCursorAsset(GVRContext context, CursorType type, Action action, String assetName) {
super(context, type, action);
this.assetName = assetName;
objects = new SparseArray<GVRModelSceneObject>();
objects = new SparseArray<GVRSceneObject>();
animationEngine = context.getAnimationEngine();
}

@Override
void set(Cursor cursor) {
super.set(cursor);
GVRModelSceneObject modelSceneObject = objects.get(cursor.getId());
GVRSceneObject modelSceneObject = objects.get(cursor.getId());

if (modelSceneObject == null) {
Log.e(TAG, "Model not found, should not happen");
return;
}
modelSceneObject.setEnable(true);

for (GVRAnimation animation : modelSceneObject.getAnimations()) {
animation.setRepeatMode(GVRRepeatMode.REPEATED);
animation.setRepeatCount(LOOP_REPEAT_COUNT);
animation.start(animationEngine);
GVRAnimator animator = (GVRAnimator) modelSceneObject.getComponent(GVRAnimator.getComponentType());
if (animator != null)
{
animator.setRepeatMode(GVRRepeatMode.REPEATED);
animator.setRepeatCount(LOOP_REPEAT_COUNT);
animator.start();
}
}

private GVRModelSceneObject loadModelSceneObject() {
GVRModelSceneObject modelSceneObject = null;
private GVRSceneObject loadModelSceneObject() {
GVRSceneObject modelSceneObject = null;
try {
modelSceneObject = context.getAssetLoader().loadModel(assetName);
} catch (IOException e) {
Expand All @@ -78,22 +79,22 @@ private GVRModelSceneObject loadModelSceneObject() {
void reset(Cursor cursor) {
super.reset(cursor);

GVRModelSceneObject modelSceneObject = objects.get(cursor.getId());
GVRSceneObject modelSceneObject = objects.get(cursor.getId());

modelSceneObject.setEnable(false);
for (GVRAnimation animation : modelSceneObject.getAnimations()) {
if (animation.isFinished() == false) {
animation.setRepeatMode(GVRRepeatMode.ONCE);
animation.setRepeatCount(0);
animationEngine.stop(animation);
}
GVRAnimator animator = (GVRAnimator) modelSceneObject.getComponent(GVRAnimator.getComponentType());
if (animator != null)
{
animator.setRepeatMode(GVRRepeatMode.ONCE);
animator.setRepeatCount(0);
animator.start();
}
}

@Override
void load(Cursor cursor) {
Integer key = cursor.getId();
GVRModelSceneObject modelSceneObject = objects.get(key);
GVRSceneObject modelSceneObject = objects.get(key);

if (modelSceneObject == null) {
modelSceneObject = loadModelSceneObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.gearvrf.io.cursor3d.settings;

import android.app.Activity;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -25,53 +26,53 @@
import org.gearvrf.GVRActivity;
import org.gearvrf.GVRContext;
import org.gearvrf.GVRScene;
import org.gearvrf.IViewEvents;
import org.gearvrf.scene_objects.GVRViewSceneObject;

abstract class BaseView {
private static final String TAG = BaseView.class.getSimpleName();
private static final float QUAD_X = 10.0f;
private static final float QUAD_Y = 8f;
private static final float DEFAULT_SCALE = 10.0f;
public static final float QUAD_DEPTH = -13f;
private FrameLayout frameLayout;

private float quadHeight;
private float quadWidth;
GVRScene scene;
GVRActivity activity;
GVRContext context;
Activity activity;
private GVRViewSceneObject layoutSceneObject;
private Handler glThreadHandler;
int settingsCursorId;

BaseView(GVRContext context, GVRScene scene, int settingsCursorId, int layoutID) {
this(context, scene, settingsCursorId, layoutID, QUAD_Y, QUAD_X);
this(context, scene, settingsCursorId, layoutID, DEFAULT_SCALE);
}

BaseView(GVRContext context, GVRScene scene, int settingsCursorId, int layoutID, float
quadHeight, float quadWidth) {
BaseView(final GVRContext context, final GVRScene scene,
final int settingsCursorId, final int layoutID, final float scale) {
this.context = context;
this.scene = scene;
this.activity = context.getActivity();
this.settingsCursorId = settingsCursorId;
this.quadHeight = quadHeight;
this.quadWidth = quadWidth;

activity = context.getActivity();
frameLayout = new FrameLayout(activity);
frameLayout.setBackgroundColor(Color.TRANSPARENT);
View.inflate(activity, layoutID, frameLayout);
glThreadHandler = new Handler(Looper.getMainLooper());
}

void render(final float x, final float y, final float z) {
glThreadHandler.post(new Runnable() {
layoutSceneObject = new GVRViewSceneObject(context, layoutID, new IViewEvents() {
@Override
public void onInitView(GVRViewSceneObject gvrViewSceneObject, View view) {
BaseView.this.onInitView(view);
}

@Override
public void run() {
layoutSceneObject = new GVRViewSceneObject(context, frameLayout,
context.createQuad(quadWidth, quadHeight));
layoutSceneObject.getTransform().setPosition(x, y, z);
show();
public void onStartRendering(GVRViewSceneObject gvrViewSceneObject, View view) {
gvrViewSceneObject.getTransform().setScale(scale, scale, 1.0f);
BaseView.this.onStartRendering();
}
});

layoutSceneObject.setTextureBufferSize(1024);
}

abstract protected void onInitView(View view);
abstract protected void onStartRendering();

void render(final float x, final float y, final float z) {
layoutSceneObject.getTransform().setPosition(x, y, z);
show();
}

void show() {
Expand All @@ -90,10 +91,6 @@ void enable() {
scene.addSceneObject(layoutSceneObject);
}

View findViewById(int id) {
return frameLayout.findViewById(id);
}

void setSettingsCursorId(int settingsCursorId) {
this.settingsCursorId = settingsCursorId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.gearvrf.io.cursor3d.settings;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
Expand All @@ -28,7 +29,6 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.gearvrf.GVRActivity;
import org.gearvrf.GVRContext;
import org.gearvrf.GVRScene;
import org.gearvrf.io.GVRTouchPadGestureListener;
Expand Down Expand Up @@ -73,7 +73,7 @@ class CursorConfigView extends BaseView implements View.OnClickListener {
currentCursor, final GVRScene scene, int
settingsCursorId, SettingsChangeListener changeListener) {
super(context, scene, settingsCursorId, R.layout.cursor_configuration_layout);
final GVRActivity activity = context.getActivity();
final Activity activity = context.getActivity();
loadDrawables(activity);
layoutInflater = (LayoutInflater) activity.getSystemService(Context
.LAYOUT_INFLATER_SERVICE);
Expand All @@ -82,28 +82,31 @@ class CursorConfigView extends BaseView implements View.OnClickListener {
this.currentCursor = currentCursor;
this.changeListener = changeListener;
loadThemes();
}

TextView tvCursorName = (TextView) findViewById(R.id.tvCursorName);
@Override
protected void onInitView(View view) {
TextView tvCursorName = (TextView) view.findViewById(R.id.tvCursorName);
tvCursorName.setText(cursor.getName());
TextView tvCursorType = (TextView) findViewById(R.id.tvCursorType);
TextView tvCursorType = (TextView) view.findViewById(R.id.tvCursorType);
if (cursor.getCursorType() == CursorType.LASER) {
tvCursorType.setText(R.string.cursor_type_laser);
} else {
tvCursorType.setText(R.string.cursor_type_object);
}
TextView tvBackButton = (TextView) findViewById(R.id.tvBackButton);
TextView tvBackButton = (TextView) view.findViewById(R.id.tvBackButton);
tvBackButton.setOnClickListener(this);

TextView done = (TextView) findViewById(R.id.done);
TextView done = (TextView) view.findViewById(R.id.done);
done.setOnClickListener(this);

LinearLayout llThemes = (LinearLayout) findViewById(R.id.llThemes);
LinearLayout llThemes = (LinearLayout) view.findViewById(R.id.llThemes);
themeViews = new ArrayList<View>();
for (CursorTheme theme : themes) {
addTheme(theme, llThemes, theme == cursor.getCursorTheme());
}

LinearLayout llIoDevices = (LinearLayout) findViewById(R.id.llIoDevices);
LinearLayout llIoDevices = (LinearLayout) view.findViewById(R.id.llIoDevices);
ioDevicesDisplayed = cursor.getAvailableIoDevices();
availableIoDevices = new HashSet<IoDevice>(ioDevicesDisplayed);
List<IoDevice> usedIoDevices = cursorManager.getUsedIoDevices();
Expand All @@ -118,13 +121,22 @@ class CursorConfigView extends BaseView implements View.OnClickListener {
for (IoDevice ioDevice : ioDevicesDisplayed) {
addIoDevice(ioDevice, llIoDevices, cursorManager.isDeviceActive(ioDevice));
}
}

@Override
protected void onStartRendering() {
render(0.0f, 0.0f, BaseView.QUAD_DEPTH);
}

@Override
void show() {
super.show();
setGestureDetector(new GestureDetector(swipeListener));
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setGestureDetector(new GestureDetector(swipeListener));
}
});
}

private void loadDrawables(Context context) {
Expand Down Expand Up @@ -274,18 +286,23 @@ private void markIoDeviceSelected(int newIoDevicePosition) {
}

private void createIoChangeDialog(final IoDevice ioDevice, final int newIoDevicePosition) {
new IoChangeDialogView(context, scene, settingsCursorId, new IoChangeDialogView
.DialogResultListener() {
context.runOnGlThread(new Runnable() {
@Override
public void onConfirm() {
setSettingsCursorId(changeListener.onDeviceChanged(ioDevice));
markIoDeviceSelected(newIoDevicePosition);
navigateBack(true);
}
public void run() {
new IoChangeDialogView(context, scene, settingsCursorId, new IoChangeDialogView
.DialogResultListener() {
@Override
public void onConfirm() {
setSettingsCursorId(changeListener.onDeviceChanged(ioDevice));
markIoDeviceSelected(newIoDevicePosition);
navigateBack(true);
}

@Override
public void onCancel() {
@Override
public void onCancel() {

}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

class IoChangeDialogView extends BaseView implements View.OnClickListener {
private static final String TAG = IoChangeDialogView.class.getSimpleName();
private static final float DIALOG_HEIGHT = 3f;
private static final float DIALOG_WIDTH = 4.5f;
private static final float DIALOG_SCALE = 4.5f;
private static final float DIALOG_DEPTH_OFFSET = 0.5f;

public interface DialogResultListener {
Expand All @@ -39,15 +38,22 @@ public interface DialogResultListener {

IoChangeDialogView(final GVRContext context, final GVRScene scene, int
settingsCursorId, DialogResultListener dialogResultListener) {
super(context, scene, settingsCursorId, R.layout.iochange_dialog_layout, DIALOG_HEIGHT,
DIALOG_WIDTH);
super(context, scene, settingsCursorId, R.layout.iochange_dialog_layout, DIALOG_SCALE);
this.dialogResultListener = dialogResultListener;
TextView tvConfirm = (TextView) findViewById(R.id.tvConfirm);
TextView tvCancel = (TextView) findViewById(R.id.tvCancel);
this.dialogResultListener = dialogResultListener;
}

@Override
protected void onInitView(View view) {
TextView tvConfirm = (TextView) view.findViewById(R.id.tvConfirm);
TextView tvCancel = (TextView) view.findViewById(R.id.tvCancel);
tvConfirm.setOnClickListener(this);
tvCancel.setOnClickListener(this);
}

@Override
protected void onStartRendering() {
render(0.0f, 0.0f, BaseView.QUAD_DEPTH + DIALOG_DEPTH_OFFSET);
this.dialogResultListener = dialogResultListener;
}

@Override
Expand Down
Loading

0 comments on commit 4258e7d

Please sign in to comment.