Im trying to use cardboard view (found example in internet)
private class CardboardOverlayEyeView extends ViewGroup {
private final ImageView imageView;
private final TextView textView;
private float offset;
public CardboardOverlayEyeView(Context context, AttributeSet attrs) {
super(context, attrs);
imageView = new ImageView(context, attrs);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true); // Preserve aspect ratio.
addView(imageView);
textView = new TextView(context, attrs);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setGravity(Gravity.CENTER);
textView.setShadowLayer(3.0f, 0.0f, 0.0f, Color.DKGRAY);
addView(textView);
}
public void setColor(int color) {
imageView.setColorFilter(color);
textView.setTextColor(color);
}
public void setText(String text) {
textView.setText(text);
}
public void setTextViewAlpha(float alpha) {
textView.setAlpha(alpha);
}
public void setOffset(float offset) {
this.offset = offset;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
//bla bla view positions.
}
}
}
I want to add menu here for gamepad (via bluetooth). I just write another layout.xml
with my menu and in CardboardOverlayEyeView
using inflate i add this layout to my current viewGroup. But for correct work - extends ViewGroup
was changed to extends RelativeLayout
.
My menu showing good. There are few buttons like "point 1, point 2, point 3"
when im using controls on joystick (UP/DOWN) its on leftView showing focus (like another color for button)- and its good.But in right view no focus.Also But if im using control on joystic left/right - i can switch from left to right view .
I want to remove switch and if leftView has focused button (with another color) i also want this steps in rightView. Can any one help me? how to do it.
picture
Finnaly i did it. simple part of code . Where we need array of buttons as a copy of main buttons from left and right view.
public void setFocusedButton() {
for(int i=0; i<mLeftView.btns.length;i++){
if(mLeftView.btns[i].isFocused() || mRightView.btns[i].isFocused()) {
mLeftView.btns[i].setBackgroundResource(R.drawable.button_pressed);
mRightView.btns[i].setBackgroundResource(R.drawable.button_pressed);
}else {
mLeftView.btns[i].setBackgroundResource(R.drawable.button);
mRightView.btns[i].setBackgroundResource(R.drawable.button);
}
}
}
its not full focused. But its looks great.