@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_GALLERY && resultCode == Activity.RESULT_OK) {
      tempAvatarPath = AppContext.getInternalTempFile("avatar", "jpg");
      Crop.of(data.getData(), Uri.fromFile(new File(tempAvatarPath))).asSquare().start(this);

      return;
    } else if (requestCode == REQUEST_PHOTO && resultCode == Activity.RESULT_OK) {
      tempAvatarPath = AppContext.getInternalTempFile("avatar", "jpg");
      Crop.of(Uri.fromFile(new File(externalFile)), Uri.fromFile(new File(tempAvatarPath)))
          .asSquare()
          .start(this);
      return;
    } else if (requestCode == Crop.REQUEST_CROP && resultCode == Activity.RESULT_OK) {
      setResult(
          RESULT_OK,
          new Intent()
              .putExtra(Intents.EXTRA_RESULT, Intents.RESULT_IMAGE)
              .putExtra(Intents.EXTRA_IMAGE, tempAvatarPath));
      finish();
      return;
    }

    setResult(RESULT_CANCELED);
    finish();
  }
 public MentionSpan(String url, boolean hideUrlStyle) {
   super(url, hideUrlStyle);
   colors =
       new int[] {
         AppContext.getContext().getResources().getColor(R.color.placeholder_0),
         AppContext.getContext().getResources().getColor(R.color.placeholder_1),
         AppContext.getContext().getResources().getColor(R.color.placeholder_2),
         AppContext.getContext().getResources().getColor(R.color.placeholder_3),
         AppContext.getContext().getResources().getColor(R.color.placeholder_4),
         AppContext.getContext().getResources().getColor(R.color.placeholder_5),
         AppContext.getContext().getResources().getColor(R.color.placeholder_6),
       };
 }
  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());
  }