Merge pull request #2444 from moneytoo/rotate
Handle (auto)rotation changes during activity lifecycle
This commit is contained in:
commit
4d8f66f28e
|
@ -24,11 +24,13 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
|
@ -113,6 +115,8 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
private boolean isInMultiWindow;
|
private boolean isInMultiWindow;
|
||||||
private boolean isBackPressed;
|
private boolean isBackPressed;
|
||||||
|
|
||||||
|
private ContentObserver rotationObserver;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Activity LifeCycle
|
// Activity LifeCycle
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -147,6 +151,23 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
Toast.makeText(this, R.string.general_error, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.general_error, Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rotationObserver = new ContentObserver(new Handler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
super.onChange(selfChange);
|
||||||
|
if (globalScreenOrientationLocked()) {
|
||||||
|
final boolean lastOrientationWasLandscape = defaultPreferences.getBoolean(
|
||||||
|
getString(R.string.last_orientation_landscape_key), false);
|
||||||
|
setLandscape(lastOrientationWasLandscape);
|
||||||
|
} else {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getContentResolver().registerContentObserver(
|
||||||
|
Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
|
||||||
|
false, rotationObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -239,6 +260,9 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
playerState = createPlayerState();
|
playerState = createPlayerState();
|
||||||
playerImpl.destroy();
|
playerImpl.destroy();
|
||||||
|
|
||||||
|
if (rotationObserver != null)
|
||||||
|
getContentResolver().unregisterContentObserver(rotationObserver);
|
||||||
|
|
||||||
isInMultiWindow = false;
|
isInMultiWindow = false;
|
||||||
isBackPressed = false;
|
isBackPressed = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue