Skip to content

Commit

Permalink
Avoiding to declare orientation in manifest as that kills review for …
Browse files Browse the repository at this point in the history
…TV. Instead using setRequestedOrientation() programmatically to avoid orientation change while copy dialog is shown, see GH isse #257
  • Loading branch information
wolpi committed May 5, 2024
1 parent 45fc8fa commit cbbd3b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions primitiveFTPd/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
android:theme="@style/PrimFtpdDeviceTheme"
android:name="org.primftpd.share.ReceiveSaveAsActivity"
android:label="@string/saveAs"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
Expand Down Expand Up @@ -220,7 +220,7 @@
android:theme="@style/PrimFtpdDeviceTheme"
android:name="org.primftpd.share.ReceiveQuickShareActivity"
android:label="@string/quickShare"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.primftpd.share;

import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import org.primftpd.services.AbstractServerService;
import org.primftpd.util.FilenameUnique;
Expand All @@ -17,12 +22,32 @@
import java.io.OutputStream;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

public abstract class AbstractReceiveShareActivity extends FragmentActivity {

protected Logger logger = LoggerFactory.getLogger(getClass());

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// if screen orientation changes and copy-dialog is currently shown
// the dialog will be destroyed
// to avoid that we request a specific orientation to prevent it being changed
// check first if we have a landscape or portrait like screen
// re-set after copy is finished
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
boolean isWideScreen = metrics.heightPixels < metrics.widthPixels;
int requestedOrientation = isWideScreen
? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
setRequestedOrientation(requestedOrientation);
}

protected void saveUris(
ProgressDialog progressDialog,
final TargetDir targetDir,
Expand Down Expand Up @@ -145,7 +170,10 @@ protected void onPostExecute(Void result) {
logger.warn("error while releasing wake lock", e);
}

mainThreadHandler.post(() -> activity.onCopyFinished(targetDir));
mainThreadHandler.post(() -> {
activity.onCopyFinished(targetDir);
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
});
}
}

Expand Down

0 comments on commit cbbd3b2

Please sign in to comment.