Exemplo n.º 1
0
 @Provides
 @Singleton
 Picasso providePicasso(
     OkHttpClient client,
     NetworkBehavior behavior,
     @IsMockMode boolean isMockMode,
     Application app) {
   Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttp3Downloader(client));
   if (isMockMode) {
     builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
   }
   builder.listener(
       (picasso, uri, exception) -> {
         Timber.e(exception, "Error while loading image %s", uri);
       });
   return builder.build();
 }
Exemplo n.º 2
0
 @Provides
 @PerApp
 Picasso providePicasso(
     OkHttpClient client,
     NetworkBehavior behavior,
     @IsMockMode boolean isMockMode,
     Application app) {
   Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttpDownloader(client));
   if (isMockMode) {
     builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
   }
   builder.listener(
       new Picasso.Listener() {
         @Override
         public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
           Timber.e(exception, "Error while loading image " + uri);
         }
       });
   return builder.build();
 }
Exemplo n.º 3
0
 protected V8Engine(Application application, String path) {
   if (path != null) {
     scriptPath = path;
   }
   if (application != null) {
     assetManager = application.getAssets();
     final Resources r = application.getResources();
     if (r != null) {
       mDensity = r.getDisplayMetrics().density;
     }
   }
   Locale locale = Locale.getDefault();
   String country = locale.getCountry();
   if (country.isEmpty()) {
     mLocale = locale.getLanguage();
   } else {
     mLocale = locale.getLanguage() + "_" + country;
   }
   mLang = locale.getLanguage();
   mTimeZone = TimeZone.getDefault().getID();
 }
  public static void newDelegateResources(Application application, Resources res, String newPath)
      throws Exception {
    Set<String> assetPaths;

    // above 5.0
    if (!ignoreOpt && Build.VERSION.SDK_INT > 20 && (assetPathsHistory != null)) {
      // not 1st time, just append the path
      AssetManager asset = application.getAssets();
      if (!TextUtils.isEmpty(newPath) && !assetPathsHistory.contains(newPath)) {

        Class<?> paramterTypes[] = {String.class};
        RefInvoke.invokeMethod(asset, "addAssetPath", paramterTypes, newPath);

        assetPathsHistory.add(newPath);

        Log.i(TAG, assetPathsHistory.toString());
      }
      return;
    }

    if ((assetPaths = generateNewAssetPaths(application, newPath)) == null) {
      // Already added, just return
      return;
    }

    AssetManager asset = AssetManager.class.newInstance();
    for (String path : assetPaths) {
      try {
        Class<?> paramterTypes[] = {String.class};
        if (Integer.parseInt(
                (RefInvoke.invokeMethod(asset, "addAssetPath", paramterTypes, path)).toString())
            == 0) {
          // if failed try three times
          int i = 0;
          for (i = 0; i < 3; i++) {
            if (Integer.parseInt(
                    (RefInvoke.invokeMethod(asset, "addAssetPath", paramterTypes, newPath))
                        .toString())
                != 0) {
              break;
            }
          }
        }
      } catch (NumberFormatException e) {
      }
    }

    Resources delegateResources = null;
    // fixed bug in xiaomi3
    if (res != null
        && (res.getClass().getName().equals("android.content.res.MiuiResources"))
        && (Build.VERSION.SDK_INT <= 20)) {
      Class<?> miuiResClass = Class.forName("android.content.res.MiuiResources");
      Constructor<?> miuiCons =
          miuiResClass.getDeclaredConstructor(
              AssetManager.class, DisplayMetrics.class, Configuration.class);
      miuiCons.setAccessible(true);
      delegateResources =
          (Resources) miuiCons.newInstance(asset, res.getDisplayMetrics(), res.getConfiguration());
    } else {
      delegateResources = new DelegateResources(asset, res);
    }

    RuntimeVariable.delegateResources = delegateResources;

    assetPathsHistory = assetPaths;

    Log.i(TAG, assetPathsHistory.toString());
  }
Exemplo n.º 5
0
  private Core(Application application) throws IOException, JSONException {

    AndroidContext.setContext(application);

    // Integrations
    //noinspection ConstantConditions
    JSONObject config =
        new JSONObject(new String(readAll(application.getAssets().open("app.json"))));
    hockeyToken = config.optString("hockeyapp");

    if (config.optString("mint") != null && !config.optString("mint").equals("null")) {
      Mint.disableNetworkMonitoring();
      Mint.initAndStartSession(application, config.getString("mint"));
    }
    Fresco.initialize(application);

    // Keep Alive
    application.startService(new Intent(application, KeepAliveService.class));

    // Helpers
    AppContext.setContext(application);

    this.smileProcessor = new SmileProcessor(application);
    this.smileProcessor.loadEmoji();

    //        AndroidConfigurationBuilder builder = new AndroidConfigurationBuilder(
    //                application.getResources().getString(R.string.app_locale),
    //                application);
    //        builder.setPhoneBookProvider(new AndroidPhoneBook());
    //        builder.setNotificationProvider(new AndroidNotifications(AppContext.getContext()));
    //        JSONArray endpoints = config.getJSONArray("endpoints");
    //        for (int i = 0; i < endpoints.length(); i++) {
    //            builder.addEndpoint(endpoints.getString(i));
    //        }
    //        builder.setEnableContactsLogging(true);
    //        builder.setEnableNetworkLogging(true);
    //        builder.setEnableFilesLogging(true);
    //        //noinspection ConstantConditions
    //        if (config.optString("mixpanel") != null) {
    //            builder.setAnalyticsProvider(new AndroidMixpanelAnalytics(AppContext.getContext(),
    // config.getString("mixpanel")));
    //        }
    //        builder.setDeviceCategory(DeviceCategory.MOBILE);
    //        builder.setAppCategory(AppCategory.ANDROID);
    //
    //        builder.setApiConfiguration(new ApiConfiguration(
    //                BuildConfig.VERSION_TITLE,
    //                API_ID,
    //                API_KEY,
    //                getDeviceName(),
    //                AppContext.getContext().getPackageName() + ":" + Build.SERIAL));
    //
    //        builder.setMaxDelay(MAX_DELAY);

    ConfigurationBuilder builder = new ConfigurationBuilder();
    JSONArray endpoints = config.getJSONArray("endpoints");
    for (int i = 0; i < endpoints.length(); i++) {
      builder.addEndpoint(endpoints.getString(i));
    }
    builder.setPhoneBookProvider(new AndroidPhoneBook());
    builder.setNotificationProvider(new AndroidNotifications(AppContext.getContext()));
    builder.setDeviceCategory(DeviceCategory.MOBILE);
    builder.setAppCategory(AppCategory.ANDROID);
    builder.setApiConfiguration(
        new ApiConfiguration(
            BuildConfig.VERSION_TITLE,
            API_ID,
            API_KEY,
            getDeviceName(),
            AppContext.getContext().getPackageName() + ":" + Build.SERIAL));
    this.messenger = new AndroidMessenger(AppContext.getContext(), builder.build());
  }