Пример #1
0
  @SuppressWarnings({"deprecation", "ResourceType"})
  protected void createViews() {
    // Why are we setting a constant as the ID? This should be investigated
    webView.getView().setId(1000);
    RelativeLayout.LayoutParams p =
        new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    webView.getView().setLayoutParams(p);

    if (preferences.contains("BackgroundColor")) {
      int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK);
      // Background of activity:
      webView.getView().setBackgroundColor(backgroundColor);
    }

    webView.getView().requestFocusFromTouch();
  }
Пример #2
0
  protected void init() {
    webView = makeWebView();
    createViews();
    if (!webView.isInitialized()) {
      webView.init(cordovaInterface, pluginEntries, preferences);
    }
    webView.getView().requestFocusFromTouch();
    cordovaInterface.onCordovaInit(webView.getPluginManager());
    // webView.clearCache();
    android.webkit.CookieManager.getInstance().removeAllCookie();

    // Wire the hardware volume controls to control media if desired.
    String volumePref = preferences.getString("DefaultVolumeStream", "");
    if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
      getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }
    BaseActivity activity = (BaseActivity) getActivity();
    activity.hideToolbar(2);
    gestureDetector = new GestureDetector(webView.getContext(), this);
    webView.getView().setOnTouchListener(this);
  }
Пример #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    loadConfig();
    //
    // ((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
    /*
            TODO: it's can be only in activity before adding content and we may need it in Cordova Dapps
            if(!preferences.getBoolean("ShowTitle", false))
            {
                try {
                    getActivity().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                } catch (Exception e) {
                    System.out.print(e);
                }
            }

            if(preferences.getBoolean("SetFullscreen", false))
            {
                preferences.set("Fullscreen", true);
            }
            if(preferences.getBoolean("Fullscreen", false))
            {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                {
                    immersiveMode = true;
                }
                else
                {
                    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
                }
            } else {
                getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            }
    */

    //        view = inflater.inflate(R.layout.fragment_web_view, container, false);

    cordovaInterface = makeCordovaInterface();
    if (savedInstanceState != null) {
      cordovaInterface.restoreInstanceState(savedInstanceState);
    }

    init();

    loadUrl();

    //        return view;
    return webView.getView();
  }
  @Override
  public void setUp() throws Exception {

    if (testResults == null || !testResults.containsKey(jsSuite)) {
      if (testResults == null) {
        testResults = new HashMap<String, Map<String, TestResult>>();
      }

      if (!testResults.containsKey(jsSuite)) {
        testResults.put(jsSuite, new HashMap<String, TestResult>());
      }

      // Wait for app initialization to complete
      EventsListenerQueue eq = new EventsListenerQueue();
      if (!SalesforceSDKManager.hasInstance()) {
        eq.waitForEvent(EventType.AppCreateComplete, 5000);
      }

      // Start main activity
      Instrumentation instrumentation = getInstrumentation();
      final Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setClassName(
          instrumentation.getTargetContext(),
          SalesforceSDKManager.getInstance().getMainActivityClass().getName());
      SalesforceDroidGapActivity activity =
          (SalesforceDroidGapActivity) instrumentation.startActivitySync(intent);

      // Block until the javascript has notified the container that it's ready
      TestRunnerPlugin.readyForTests.take();

      // Now run all the tests and collect the resuts in testResults
      for (String testName : getTestNames()) {
        final String jsCmd =
            "javascript:"
                + "navigator.testrunner.setTestSuite('"
                + jsSuite
                + "');"
                + "navigator.testrunner.startTest('"
                + testName
                + "');";
        final CordovaWebView appView = activity.getAppView();
        if (appView != null) {
          appView
              .getView()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      appView.loadUrl(jsCmd);
                    }
                  });
        }
        Log.i(getClass().getSimpleName(), "running test:" + testName);

        // Block until test completes or times out
        TestResult result = null;
        int timeout = getMaxRuntimeInSecondsForTest(testName);
        try {
          result = TestRunnerPlugin.testResults.poll(timeout, TimeUnit.SECONDS);
          if (result == null) {
            result =
                new TestResult(
                    testName, false, "Timeout (" + timeout + " seconds) exceeded", timeout);
          }
        } catch (Exception e) {
          result = new TestResult(testName, false, "Test failed", timeout);
        }
        Log.i(getClass().getSimpleName(), "done running test:" + testName);

        // Save result
        testResults.get(jsSuite).put(testName, result);
      }

      // Cleanup
      eq.tearDown();
      activity.finish();
    }
  }
 CordovaWebChromeClient(Context context, CordovaWebView view) {
   super((XWalkView) view.getView());
   appView = view;
 }