Skip to content

Instantly share code, notes, and snippets.

@mandric
Created October 14, 2016 02:14
Show Gist options
  • Save mandric/7bf05e750d7ed3b5f907c4fb44abdd8e to your computer and use it in GitHub Desktop.
Save mandric/7bf05e750d7ed3b5f907c4fb44abdd8e to your computer and use it in GitHub Desktop.
Trying to get chromium command line switches to work with crosswalk-21.51.546.6
// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.medicmobile.testcrosswalk;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.view.View;
import android.widget.TextView;
import org.xwalk.app.XWalkRuntimeActivityBase;
import org.xwalk.core.XWalkPreferences;
import org.chromium.base.CommandLine;
public class Testcrosswalk2Activity extends XWalkRuntimeActivityBase {
private final int SYSTEM_UI_OPTIONS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
private final String TAG = this.getClass().getName();
static final String INIT_SWITCHES[] = { "Xwalk", "--user-agent=anonymous" };
//static final String INIT_SWITCHES[] = { "Xwalk", "--unlimited-storage" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
if (!CommandLine.isInitialized()) {
CommandLine.init(INIT_SWITCHES);
Log.w(TAG, "===============================");
Log.w(TAG, "Using command line switches!");
Log.w(TAG, "===============================");
} else {
Log.w(TAG, "===============================");
Log.w(TAG, "Not using command line switches");
Log.w(TAG, "===============================");
}
}
@Override
public void onResume() {
super.onResume();
enterFullscreen();
}
@Override
protected void didTryLoadRuntimeView(View runtimeView) {
if (runtimeView != null) {
getRuntimeView().loadAppFromManifest("file:///android_asset/www/manifest.json");
} else {
TextView msgText = new TextView(this);
msgText.setText("Crosswalk failed to initialize.");
msgText.setTextSize(36);
msgText.setTextColor(Color.BLACK);
setContentView(msgText);
}
}
private void enterFullscreen() {
if (isNewerThanKitkat() && ((getWindow().getAttributes().flags &
WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0)) {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(SYSTEM_UI_OPTIONS);
}
}
public void setIsFullscreen(boolean isFullscreen) {
if (!isFullscreen) return;
if (!isNewerThanKitkat()) {
Log.w(TAG, "setIsFullscreen() should not be called if " +
"android version is older than Kitkat.");
return;
}
setSystemUiVisibilityChangeListener();
}
private void setSystemUiVisibilityChangeListener() {
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(SYSTEM_UI_OPTIONS);
}
}
}
);
}
private boolean isNewerThanKitkat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
}
@mandric
Copy link
Author

mandric commented Oct 14, 2016

I see the "Using command line switches!" in the log which is a good sign but window.navigator.userAgent shows no change in the console. The goal is to get the --unlimited-storage flag to work, but any chromium command line switch I try seems to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment