public static void loadLibs() {
    if (notLoadAgain) {
      return;
    }
    if (!(DeviceUtils.isRealARMArch() || DeviceUtils.isRealX86Arch())) {
      notLoadAgain = true;
      nativeLibLoaded = false;
      return;
    }
    if (nativeLibLoaded) {
      return;
    }
    try {
      if (android.os.Build.VERSION.SDK_INT >= 11 && android.os.Build.VERSION.SDK_INT < 23) {
        System.loadLibrary("ndkbitmap");
        nativeLibLoaded = true;
      } else {
        notLoadAgain = true;
        nativeLibLoaded = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
      notLoadAgain = true;
      nativeLibLoaded = false;
    } catch (Error e) {
      e.printStackTrace();
      notLoadAgain = true;
      nativeLibLoaded = false;
    }
    if (nativeLibLoaded) {
      boolean libInit = init();
      if (!libInit) {
        release();
        notLoadAgain = true;
        nativeLibLoaded = false;
      } else {
        initField();
        boolean confirm = testLib();
        if (!confirm) {
          // 测试so文件函数是否调用失败
          release();
          notLoadAgain = true;
          nativeLibLoaded = false;
        }
      }
    }

    Log.e("NativeBitmapFactory", "loaded" + nativeLibLoaded);
  }
 public Object resolveArgument(MethodParameter param, NativeWebRequest request) throws Exception {
   if (Device.class.isAssignableFrom(param.getParameterType())) {
     return DeviceUtils.getCurrentDevice(request);
   } else {
     return WebArgumentResolver.UNRESOLVED;
   }
 }
Пример #3
0
 @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
 public static int getBitmapSize(Bitmap bitmap) {
   if (DeviceUtils.hasHoneycombMR1()) {
     return bitmap.getByteCount();
   }
   // Pre HC-MR1
   return bitmap.getRowBytes() * bitmap.getHeight();
 }
Пример #4
0
 /**
  * 动态设置图片宽高
  *
  * @param context
  * @param stander_w
  * @param stander_h
  * @param num
  * @param space_image
  * @param space_left
  * @param space_right
  * @return
  */
 public static int[] setImageWH(
     Context context,
     int stander_w,
     int stander_h,
     int num,
     int space_image,
     int space_left,
     int space_right) {
   int wh[] = new int[2]; // 0:w, 1:h
   wh[0] =
       (DeviceUtils.getScreenWH(context)[0]
               - dp2px(context, space_left + space_right)
               - dp2px(context, space_image * (num - 1)))
           / num;
   wh[1] = wh[0] * stander_h / stander_w;
   return wh;
 }
Пример #5
0
 public static void resetDensity(Context context) {
   if (context != null && null != context.getResources()) {
     DisplayMetrics metrics = context.getResources().getDisplayMetrics();
     sDensity = metrics.density;
     sFontDensity = metrics.scaledDensity;
     sWidthPixels = metrics.widthPixels;
     sHeightPixels = metrics.heightPixels;
     if (DeviceUtils.isTablet(context)) {
       sStatusHeight = getTabletScreenHeight(context) - sHeightPixels;
     }
     final ViewConfiguration configuration = ViewConfiguration.get(context);
     if (null != configuration) {
       sTouchSlop = configuration.getScaledTouchSlop();
     }
     // Log.i("test",">>>>>>>>sDensity = "+sDensity+",sWidthPixels =
     // "+sWidthPixels+",sHeightPixels="+sHeightPixels+",sStatusHeight = "+sStatusHeight+",dpi =
     // "+sDensity*160);
     // Configuration conf = context.getResources().getConfiguration();
     // Log.i("test",
     // ">>conf.screenWidthDp = "+conf.screenWidthDp+",conf.screenHeightDp =
     // "+conf.screenHeightDp);
   }
 }
  @VisibleForTesting
  void prepareToStartBrowserProcess(int maxRendererProcesses) throws ProcessInitException {
    Log.i(TAG, "Initializing chromium process, renderers=" + maxRendererProcesses);

    // Normally Main.java will have kicked this off asynchronously for Chrome. But other
    // ContentView apps like tests also need them so we make sure we've extracted resources
    // here. We can still make it a little async (wait until the library is loaded).
    ResourceExtractor resourceExtractor = ResourceExtractor.get(mContext);
    resourceExtractor.startExtractingResources();

    // Normally Main.java will have already loaded the library asynchronously, we only need
    // to load it here if we arrived via another flow, e.g. bookmark access & sync setup.
    LibraryLoader.ensureInitialized(mContext);

    // TODO(yfriedman): Remove dependency on a command line flag for this.
    DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext);

    Context appContext = mContext.getApplicationContext();
    // Now we really need to have the resources ready.
    resourceExtractor.waitForCompletion();

    nativeSetCommandLineFlags(maxRendererProcesses, nativeIsPluginEnabled() ? getPlugins() : null);
    ContentMain.initApplicationContext(appContext);
  }
Пример #7
0
  private void initialize(Context context) {

    Log.i("Ludei", "***************************");
    Log.i("Ludei", "Initializing Ludei WebView+");
    Log.i("Ludei", "**************************");

    if (!staticInitialization) {
      PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
      ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
      ResourceProvider.registerResources();
      staticInitialization = true;
    }

    this.ctx = context;
    if (mProxyWebView == null) {
      mProxyWebView = new LudeiWebView(context, null, 0, this);
    }
    mBridge =
        new LudeiContentsClientBridge(
            mProxyWebView, new LudeiDefaultWebChromeClient(this.ctx, this));
    mDelegate = new LudeiContentViewDelegate(this, mBridge);

    // Initializing the command line must occur before loading the library.
    if (!CommandLine.isInitialized()) {
      CommandLine.initFromFile(COMMAND_LINE_FILE);
      String[] commandLineParams = null; // getCommandLineParamsFromIntent(getIntent());

      if (commandLineParams != null) {
        CommandLine.getInstance().appendSwitchesAndArguments(commandLineParams);
      }
      CommandLine.getInstance().appendSwitch("allow-file-access-from-files");
      if (!LudeiContentView.REMOTE_DEBUGGING) {
        CommandLine.getInstance().appendSwitch("disable-remote-debugging");
      }
      CommandLine.getInstance().appendSwitch("ignore-gpu-blacklist");
    }
    waitForDebuggerIfNeeded();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(context);
    try {
      org.chromium.base.library_loader.LibraryLoader.ensureInitialized();
    } catch (ProcessInitException e) {
      Log.e(TAG, "ContentView initialization failed.", e);
      // Since the library failed to initialize nothing in the application
      // can work, so kill the whole application not just the activity
      System.exit(-1);
      return;
    }

    mSettings = LudeiWebSettingsProxy.Create(context, (new LudeiWebSettings(context, true, false)));
    shellManager = new ShellManager(context, null, this, mDelegate);

    WindowAndroid mWindowAndroid = new ActivityWindowAndroid((Activity) ctx);
    // mWindowAndroid.restoreInstanceState(savedInstanceState);
    shellManager.setWindow(
        mWindowAndroid,
        new Runnable() {
          @Override
          public void run() {
            LudeiContentView.this.onReadyToRender();
          }
        });

    if (CommandLine.getInstance().hasSwitch(ContentSwitches.DUMP_RENDER_TREE)) {
      try {
        BrowserStartupController.get(context).startBrowserProcessesSync(true);
      } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to load native library.", e);
        System.exit(-1);
      }
    } else {
      try {
        BrowserStartupController.get(context)
            .startBrowserProcessesAsync(
                new BrowserStartupController.StartupCallback() {
                  @Override
                  public void onSuccess(boolean alreadyStarted) {
                    // finishInitialization(savedInstanceState);
                    finishInitialization(null);
                  }

                  @Override
                  public void onFailure() {
                    initializationFailed();
                  }
                });
      } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        System.exit(-1);
      }
    }
  }