Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions core/src/main/java/in/testpress/fragments/WebViewFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WebViewFragment : Fragment(), EmptyViewListener {
private var allowZoomControl: Boolean = false
private var enableSwipeRefresh: Boolean = false
var session: TestpressSession? = null
var lockToLandscape: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -81,6 +82,7 @@ class WebViewFragment : Fragment(), EmptyViewListener {
arguments?.getBoolean(ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW) ?: false
allowZoomControl = arguments?.getBoolean(ALLOW_ZOOM_CONTROLS) ?: false
enableSwipeRefresh = arguments?.getBoolean(ENABLE_SWIPE_REFRESH) ?: false
lockToLandscape = arguments?.getBoolean(LOCK_TO_LANDSCAPE) ?: false
}

private fun initializedSwipeRefresh(){
Expand Down Expand Up @@ -217,6 +219,7 @@ class WebViewFragment : Fragment(), EmptyViewListener {
const val ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW = "ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW"
const val ALLOW_ZOOM_CONTROLS = "ALLOW_ZOOM_CONTROLS"
const val ENABLE_SWIPE_REFRESH = "ENABLE_SWIPE_REFRESH"
const val LOCK_TO_LANDSCAPE = "LOCK_TO_LANDSCAPE"
}

}
2 changes: 2 additions & 0 deletions core/src/main/java/in/testpress/ui/AbstractWebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ abstract class AbstractWebViewActivity: BaseToolBarActivity(), WebViewFragment.L
this.putString(WebViewFragment.URL_TO_OPEN, urlPath)
this.putBoolean(WebViewFragment.IS_AUTHENTICATION_REQUIRED, isAuthenticationRequired)
this.putBoolean(WebViewFragment.ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW, allowNonInstituteUrl)
this.putBoolean(WebViewFragment.LOCK_TO_LANDSCAPE, intent.getBooleanExtra(LOCK_TO_LANDSCAPE, false))
}
}

Expand All @@ -65,6 +66,7 @@ abstract class AbstractWebViewActivity: BaseToolBarActivity(), WebViewFragment.L
const val URL_TO_OPEN = "URL"
const val IS_AUTHENTICATION_REQUIRED = "IS_AUTHENTICATION_REQUIRED"
const val ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW = "ALLOW_NON_INSTITUTE_URL_IN_WEB_VIEW"
const val LOCK_TO_LANDSCAPE = "LOCK_TO_LANDSCAPE"

fun createIntent(
currentContext: Context,
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/in/testpress/ui/WebViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public class WebViewActivity extends BaseToolBarActivity {
private static final String TAG = WebViewActivity.class.getSimpleName();
public static final String URL_TO_OPEN = "URL";
public static final String ACTIVITY_TITLE = "TITLE";
public static final String LOCK_TO_LANDSCAPE = "LOCK_TO_LANDSCAPE";
private final static int FCR = 1;
WebView webView;
private String mCM;
private ValueCallback<Uri> mUM;
private ValueCallback<Uri[]> mUMA;
private String url;
private boolean lockToLandscape = false;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Expand Down Expand Up @@ -109,6 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setTitle(intent.getExtras().getString(ACTIVITY_TITLE));
}

lockToLandscape = intent.getBooleanExtra(LOCK_TO_LANDSCAPE, false);


if (Build.VERSION.SDK_INT >= 23 && (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ class CustomWebChromeClient(val fragment: WebViewFragment) : WebChromeClient() {
)

// Remember current state and switch to landscape
previousOrientation = fragment.requireActivity().requestedOrientation
fragment.requireActivity().requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE

previousSystemUiVisibility = fragment.requireActivity().window.decorView.systemUiVisibility

if (fragment.lockToLandscape) {
fragment.requireActivity().requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
} else {
fragment.requireActivity().requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_SENSOR
}
previousOrientation = fragment.requireActivity().requestedOrientation
hideSystemUI()

fragment.webView.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ class WebViewWithSSO: BaseToolBarActivity(), EmptyViewListener {
private fun openWebview(ssoLink: SSOUrl?) {
val urlToOpen = intent.getStringExtra(URL_TO_OPEN) ?: ""
val pageTitle = intent.getStringExtra(TITLE) ?: ""
val lockToLandscape = intent.getBooleanExtra(LOCK_TO_LANDSCAPE, false)
val intent = Intent(this, WebViewActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.putExtra(WebViewActivity.ACTIVITY_TITLE, pageTitle)
intent.putExtra(
WebViewActivity.URL_TO_OPEN,
instituteSettings?.baseUrl + ssoLink?.ssoUrl + "&next=$urlToOpen"
)
intent.putExtra(WebViewActivity.LOCK_TO_LANDSCAPE, lockToLandscape)
startActivity(intent)
finish()
}
Expand Down Expand Up @@ -97,12 +99,14 @@ class WebViewWithSSO: BaseToolBarActivity(), EmptyViewListener {
companion object {
const val URL_TO_OPEN = "URL"
const val TITLE = "TITLE"
const val LOCK_TO_LANDSCAPE = "LOCK_TO_LANDSCAPE"

@JvmStatic
fun createIntent(context: Context, url: String, title: String): Intent {
fun createIntent(context: Context, url: String, title: String, lockToLandscape: Boolean = false): Intent {
return Intent(context, WebViewWithSSO::class.java).apply {
putExtra(URL_TO_OPEN, url)
putExtra(TITLE, title)
putExtra(LOCK_TO_LANDSCAPE, lockToLandscape)
}
}
}
Expand Down