I'm developing a VR App using Google VR for Android.
When I switch to Binocular mode (clicking the headset button), appears the following screen:
How can I avoid this screen?
It is possible switch to binocular mode programmatically?
Thanks,
Christian
Yesterday I was working to achieve the same result as you are seeking now. So, I made a workaround for this, I don't know whether its perfect or not but its working at my end.
All you need to do is to get all the child views of the VrVideoView, so that you can customize accordingly.
VrVideoView videoWidgetView = (VrVideoView) findViewById(R.id.video_view);
View framelayout = ((ViewGroup) videoWidgetView).getChildAt(0);
ArrayList<View> list = getAllChildren(framelayout);
for(final View view : list) {
if(view.getId() == R.id.transition_frame){
//set visiblity gone for that cardboard information screen
view.setVisibility(View.GONE);
}
else if(view.getId() == R.id.transition_icon){
//perform click action of the same screen's icon which can
//redirect you to cardboard vr screen directly(binocular mode)
view.performClick();
}
}
Recursive method to get all the child views :
private ArrayList<View> getAllChildren(View v) {
if (!(v instanceof ViewGroup)) {
ArrayList<View> viewArrayList = new ArrayList<View>();
viewArrayList.add(v);
return viewArrayList;
}
ArrayList<View> result = new ArrayList<View>();
ViewGroup viewGroup = (ViewGroup) v;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
ArrayList<View> viewArrayList = new ArrayList<View>();
viewArrayList.add(v);
viewArrayList.addAll(getAllChildren(child));
result.addAll(viewArrayList);
}
return result;
}
I hope this might solve your problem. Additionally you can direct jump in to fullscreen mode as well by calling respective views.
You can try setTransitionViewEnabled(boolean enabled): https://developers.google.com/vr/android/reference/com/google/vr/sdk/base/GvrView.html#setTransitionViewEnabled(boolean)
For switching between mono and vr mode, setVRModeEnabled(boolean enabled): https://developers.google.com/vr/android/reference/com/google/vr/sdk/base/GvrView.html#setVRModeEnabled(boolean)
Related
What I'm trying to do is make a video full screen from RecyclerView and while the video is playing, on pressing the minimize button to put it back into the list. Note that the state of the video is still on play after I minimize it.
Sometimes I get null object from position using .findViewHolderForAdapterPosition
My code:
LinearLayout mAdapterRow = null;
mAdapterRow = (LinearLayout) ((ViewHolder_Article_Video) mList.findViewHolderForAdapterPosition(mVideoPosition)).itemView;
if (mAdapterRow instanceof ViewGroup) {
ViewGroup v = (ViewGroup) nVideoFullScreenLayout.getChildAt(0);
if (v.getParent() != null )
((ViewGroup)v.getParent()).removeView(v); // <- fix
((ViewGroup) mAdapterRow).addView(v);
((ImageView) v.findViewById(R.id.mFullScreen)).setVisibility(View.VISIBLE);
((ImageView) v.findViewById(R.id.mExitFullScreen)).setVisibility(View.GONE);
nVideoFullScreenLayout.removeAllViews();
nVideoFullScreenLayout.setVisibility(View.GONE);
if (nVideoFullScreenLayout.getParent() != null)
((ViewGroup) nVideoFullScreenLayout.getParent()).removeView(nVideoFullScreenLayout);
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(uiOptions);
mHeader.setVisibility(View.VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mVideoFullScreen = false;
} else {
Log.d("dasdasdas","remove nu: "+ mAdapterRow.getTag());
}
Previously.
When I make the full screen video layout, I'm taking the layout with the video instance from inside the list(RecyclerView) and put it in a new dynamic LinearLayout with the MATCH_PARENT params and set SCREEN_ORIENTATION_LANDSCAPE.
Now the idea was to take the layout with the video instance (full screen) that is over the RecyclerView and put it back into his position.
For some reason findViewHolderForAdapterPosition doesn't always return the layout at the position of where I got the video in the first place.
Also I can see the item at position in list data adapter is not null.
Any idea is appreciated. Thanks in advance.
Finally found a solution that works for me. (this helped https://www.creospiders.com/2016/04/how-to-access-each-view-of-item-by.html , better than a post delay)
Setted the full screen layout on GONE at the beginning of the method so I can have no other view over the reycler, used getViewTreeObserver().addOnGlobalLayoutListener on recycler list to wait for the views to build and setted a boolean value that allows or not to cycle my view in onBindViewHolder (in case the video layout is at limit of being out of screen)
nVideoFullScreenLayout.setVisibility(View.GONE);
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(uiOptions);
mHeader.setVisibility(View.VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mVideoFullScreen = false;
mAdapter.setCyclingVideoItem(false);
final LinearLayout[] mAdapterRow = {null};
mList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
mList.getViewTreeObserver().removeOnGlobalLayoutListener(this);
mAdapterRow[0] = (LinearLayout) ((ViewHolder_Article_Video) mList.findViewHolderForAdapterPosition(mVideoPosition)).itemView;
setAndCleanLayouts(mAdapterRow[0]);
mAdapter.setCyclingVideoItem(true);
}
});
I am applying images to my ImageButtons in code, but I'm wondering if there is a better way than shown in my example. I definitely know that it's not the correct way to do it as it can take way too much time with large numbers of views.
btn1.setImageResource(R.drawable.plus);
btn2.setImageResource(R.drawable.plus);
btn3.setImageResource(R.drawable.plus);
btn4.setImageResource(R.drawable.plus);
btn5.setImageResource(R.drawable.plus);
btn1.setAdjustViewBounds(true);
btn1.setPadding(0,0,0,0);
btn2.setAdjustViewBounds(true);
btn2.setPadding(0,0,0,0);
btn3.setAdjustViewBounds(true);
btn3.setPadding(0,0,0,0);
btn4.setAdjustViewBounds(true);
btn4.setPadding(0,0,0,0);
btn5.setAdjustViewBounds(true);
btn5.setPadding(0,0,0,0);
you need to get the root view in the activity, cast it to ViewGroup, get all children, check their type and update accordingly. Namely as follows,
ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
int children = rootView.getChildCount();
for (int i = 0; i < children; i++) {
View view = rootView.getChildAt(i);
if (view instanceof ImageButton) {
((ImageButton) view).setImageResource(R.drawable.plus);
((ImageButton) view).setAdjustViewBounds(true);
((ImageButton) view).setPadding(0,0,0,0);
}
}
I am having so many views to in a relative layout which is able to zoom and rotate. what I am trying to achieve is, when I long click a view it should able to send that particular view to last .
what I do is
private void moveToBack(View currentView) {
ViewGroup vg = ((ViewGroup) currentView.getParent());
for (int i = 0; i < vg.getChildCount(); i++) {
View v = vg.getChildAt(i);
if (!v.equals(currentView)) {
vg.bringChildToFront(v);
break;
}
}
}
This will set the another view above the selected view I need to send that particular view to last. MIn sdk is 17 and I can't change that.
We don't have something like bringToback() method so only we could modify the order of childviews. I tried once to achieve it using tricky way :
public void sendViewToBack(View child) {
final ViewGroup mParent = (ViewGroup)child.getParent();
if (null != mParent) {
mParent.removeView(child);
mParent.addView(child, 0);
}
}
I have a long scroll view where it contains Text views,edit texts,radio buttons,check boxes,Sliders etc..
I want to show the preview of the scroll view and the contents whatever the user had entered and which should be non editable.
Is there any possibility in android that we can do this?.
I have two suggestions
1.Disabling the scroll view from entering inputs and
2.Showing the preview of the scroll view.
is there any possibilities of these two or else some other methods to achieve this in android.
need help, thanks in advance..
This method helped to disable the views.
private static void setViewAndChildrenEnabled(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
setViewAndChildrenEnabled(child, enabled);
}
}
}
hope this will help some one else.check this
This only happens on Android 2.x. If you put a GoogleMapFragment on a screen that scrolls when the software keyboard is shown, part of your other widgets will be overlaid with black rectangles.
This seems to be related with https://code.google.com/p/android/issues/detail?id=11676. As far as I know, the new V2 GoogleMap uses SurfaceView to draw, but we do not have access to the SurfaceView directly.
P.S. Actually this is a variation of Android's EditText is hidden when the virtual keyboard is shown and a SurfaceView is involved. I post this here to increase visibility, since this is a common Google Map V2 problem. If you think this should be a community question, please let me know or just change it.
You can traverse the view hierarchy and look for the view that is instance of SurfaceView. This worked for me.
If you are going to use the below code, call traverse() at the end of onCreate or any time the Google Map fragment has been added to your activity.
void traverse() {
View root = findViewById(android.R.id.content);
traverse(root, 0);
}
void traverse(View v, int depth) {
if (v instanceof SurfaceView) {
SurfaceView sv = (SurfaceView) v;
sv.setBackgroundColor(Color.TRANSPARENT);
}
if (v instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) v;
for (int i = 0, len = vg.getChildCount(); i < len; i++) {
traverse(vg.getChildAt(i), depth+1);
}
}
}