Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android fix dso 14436 [Android] RS Camera viewer restarts the stream when rotating screen. #9662

Merged
merged 5 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public void showPointcloud(boolean showPoints) {
@Override
public void close() {
clear();
mColorizer.close();
if (mColorizer != null) mColorizer.close();
if (mYuyDecoder != null) mYuyDecoder.close();
}
}
3 changes: 3 additions & 0 deletions wrappers/android/tools/camera/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
<activity
android:name=".PreviewActivity"
android:launchMode="singleTop"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SettingsActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".RecordingActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".PlaybackActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".FileBrowserActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
Expand Down Expand Up @@ -43,6 +44,29 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_playback);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

setup_controls();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// handling device orientation changes to avoid interruption during playback

// cleanup previous surface
if(mGLSurfaceView != null) {
mGLSurfaceView.clear();
mGLSurfaceView.close();
}

// setup playback layout landscape or portrait automatically depends on orientation
setContentView(R.layout.activity_playback);

// setup layout controls
setup_controls();
}

private void setup_controls() {
mGLSurfaceView = findViewById(R.id.playbackGlSurfaceView);
m3dButton = findViewById(R.id.playback_3d_button);
m3dButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -52,6 +76,7 @@ public void onClick(View view) {
mGLSurfaceView.clear();
clearLables();
mShow3D = !mShow3D;
mGLSurfaceView.showPointcloud(mShow3D);
m3dButton.setTextColor(mShow3D ? Color.YELLOW : Color.WHITE);
mGLSurfaceView.setVisibility(View.VISIBLE);
SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
Expand Down Expand Up @@ -54,8 +55,7 @@ public class PreviewActivity extends AppCompatActivity {

boolean keepalive = true;

public synchronized void toggleStats(){
statsToggle = !statsToggle;
public synchronized void updateStats(){
if(statsToggle){
mGLSurfaceView.setVisibility(View.GONE);
mStatsView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -83,7 +83,37 @@ protected void onCreate(Bundle savedInstanceState) {

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

setup_controls();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// handling device orientation changes
// upon device orientation change, actitity will not go through default route
// to destroy and recreate the preview activity
// instead to refresh the appropriate layout and control here
// so that device streaming is not interrupted

// cleanup previous surface
if(mGLSurfaceView != null) {
mGLSurfaceView.clear();
mGLSurfaceView.close();
}

// setup preview layout landscape or portrait automatically depends on orientation
setContentView(R.layout.activity_preview);

// update layout controls
setup_controls();
updateStats();
}

private void setup_controls()
{
mGLSurfaceView = findViewById(R.id.glSurfaceView);

mStatsView = findViewById(R.id.streaming_stats_text);
mStartRecordFab = findViewById(R.id.start_record_fab);
mPlaybackButton = findViewById(R.id.preview_playback_button);
Expand Down Expand Up @@ -142,7 +172,8 @@ public void onClick(View view) {
mStatisticsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleStats();
statsToggle = !statsToggle;
updateStats();
}
});
SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -35,17 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_recording);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mGLSurfaceView = findViewById(R.id.recordingGlSurfaceView);

mStopRecordFab = findViewById(R.id.stopRecordFab);
mStopRecordFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(RecordingActivity.this, PreviewActivity.class);
startActivity(intent);
finish();
}
});
setup_controls();

if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PermissionsUtils.PERMISSIONS_REQUEST_WRITE);
Expand All @@ -65,6 +56,39 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
mPermissionsGranted = true;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// handling device orientation changes to avoid interruption during recording

// cleanup previous surface
if(mGLSurfaceView != null) {
mGLSurfaceView.clear();
mGLSurfaceView.close();
}

// setup recording layout landscape or portrait automatically depends on orientation
setContentView(R.layout.activity_recording);

// setup layout controls
setup_controls();
}

private void setup_controls() {
mGLSurfaceView = findViewById(R.id.recordingGlSurfaceView);

mStopRecordFab = findViewById(R.id.stopRecordFab);
mStopRecordFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(RecordingActivity.this, PreviewActivity.class);
startActivity(intent);
finish();
}
});
}

@Override
protected void onResume() {
super.onResume();
Expand Down