0

I have a recyclerview which onClick shows a videoview with fullscreen button..

However when i click the full screen button on the videoview.. My RecyclerView gets displayed (or created) again..

I want to display only the video in the videoview in the fullscreen mode..

The following is my Acticity OnCreate() Method :

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mangal_stuti_activity);
toolbar = findViewById(R.id.toolbar);
toolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
setSupportActionBar(toolbar);
recyclerView = (findViewById(R.id.recycler_view));
mAdapter = new Adapter(this, movieList, this);

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL,16));
recyclerView.setAdapter(mAdapter);
recyclerView.setBackgroundColor(getResources().getColor(R.color.recyclerViewBackground));
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), this.recyclerView, new RecyclerTouchListener.ClickListener()
{
  public void onClick(View view, int position) {
    toolbar.setVisibility(View.GONE);
      playVideo();

  }

  public void onLongClick(View paramAnonymousView, int paramAnonymousInt) {}
}));

prepareMovieData();  // possibly this function is creating the recyclerview again when the fullScreen is called..

mVideoView = findViewById(R.id.videoView);
mYouTuDraggingView = findViewById(R.id.youtube_view);
mYouTuDraggingView.setCallback(this);

controlPanel = new YoutubeControlPanel(this);
controlPanel.setYouTuDraggingView(mYouTuDraggingView);
mVideoView.setControlPanel(controlPanel);
controlPanel.getFullScreenIv().setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    mYouTuDraggingView.fullScreenChange();
  }
});
controlPanel.getDownIv().setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    toolbar.setVisibility(View.VISIBLE);
    mYouTuDraggingView.fullScreenGoMin();
  }
});
}

The fullScreenChange() in YouTuDraggingView class is as below:

void fullScreenChange() {
    if (isLandscape()) {
        isLandscapeToPortrait = true;
        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    } else {
        isPortraitToLandscape = true;
        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }
}

The mangal_stuti_activity.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
tools:context="com.amitabh.dhamma_jaagran.MangalStuti"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/recyclerViewBackground"
android:id="@+id/activity_main"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<include layout="@layout/toolbar_stuti_activities"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>

    <com.amitabh.YouTuDraggingView
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:orientation="vertical"
        android:visibility="invisible"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:id="@+id/footer_text"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimaryDark"
        android:text="@string/copyright_footer"
        android:textAlignment="center"
        android:textColor="@color/white" />


</RelativeLayout>
</LinearLayout>

When i click the fullscreen button on the videoview.. the videoview only should show on the fullscreen.. not the recyclerview...

i think the problem might be in mAdapter = new Adapter(this, movieList, this); where another movieList gets created when the videoview enters fullscreen..

Any help regarding this would be of great help to me.. thanks in advance..

amit jain
  • 55
  • 1
  • 12

3 Answers3

0

can you please share mangal_stuti_activity.xml code.

Make sure that youtube_view width and height is set to match_parent.

  • its set to `match_parent` only.. updated my question with the xml.. I think the problem is in setting the `recyclerview` adapter not the layout file... – amit jain Jan 23 '19 at 17:09
  • you have to set the visibility of recyclerView to gone when you are switching to fullscreen mode and you can make it visible when you are back from fullscreen – mudassar raza Jan 23 '19 at 17:13
0

It looks like you're requesting an orientation change when make your video full screen. When the activity orientation changes, the activity gets destroyed and is recreated. This is part of the Activity Life Cycle. What you're going to have to do save and restore your state of the activity and RecyclerView when this happens.

Here's an example on how to do that:

https://guides.codepath.com/android/Handling-Configuration-Changes#recyclerview

SharpMobileCode
  • 938
  • 5
  • 8
0

I Just added this line to my activity in which the video is being played in the AndroidManifest.xml file

android:configChanges="orientation|screenSize" 

This prevented the activity from being recreated.

Thanks to vignesh-ramachandra for his answer which is provided in here

amit jain
  • 55
  • 1
  • 12