public static String getInternalTempFile(String prefix, String postfix) {
    String externalPath;
    File externalFile = AndroidContext.getContext().getFilesDir();
    if (externalFile == null) {
      externalPath =
          "data/data/".concat(AndroidContext.getContext().getPackageName()).concat("/files");
    } else {
      externalPath = externalFile.getAbsolutePath();
    }

    File dest = new File(externalPath + "/actor/tmp/");
    dest.mkdirs();
    if (!dest.exists()) return null;

    File outputFile = new File(dest, prefix + "_" + Randoms.randomId() + "" + postfix);
    return outputFile.getAbsolutePath();
  }
  public static String getExternalTempFile(String prefix, String postfix) {
    File externalFile = AndroidContext.getContext().getExternalFilesDir(null);
    if (externalFile == null) {
      return null;
    }
    String externalPath = externalFile.getAbsolutePath();

    File dest = new File(externalPath + "/actor/tmp/");
    dest.mkdirs();

    File outputFile = new File(dest, prefix + "_" + Randoms.randomId() + "" + postfix);

    return outputFile.getAbsolutePath();
  }
  public UserSpan(UserVM user, int maxW) {
    this.user = user;
    this.maxW = maxW;
    if (textPaint == null) {
      textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      textPaint.setTextSize(Screen.sp(16));
      textPaint.setColor(AndroidContext.getContext().getResources().getColor(R.color.text_primary));
    }

    int padding = Screen.dp(18);
    int maxWidth = maxW - padding;
    userText =
        TextUtils.ellipsize(user.getName().get(), textPaint, maxWidth, TextUtils.TruncateAt.END)
            .toString();
  }
  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());
  }