@Override
  public void onCreate() {
    super.onCreate();
    long startDate = SystemClock.elapsedRealtime();

    mContext = this;

    ProfilingUtils.start("App Startup");
    // Enable log recording
    AppLog.enableRecording(true);
    AppLog.i(T.UTILS, "WordPress.onCreate");

    if (!PackageUtils.isDebugBuild()) {
      Fabric.with(this, new Crashlytics());
    }

    versionName = PackageUtils.getVersionName(this);
    initWpDb();
    enableHttpResponseCache(mContext);

    // EventBus setup
    EventBus.TAG = "WordPress-EVENT";
    EventBus.builder()
        .logNoSubscriberMessages(false)
        .sendNoSubscriberEvent(false)
        .throwSubscriberException(true)
        .installDefaultEventBus();
    EventBus.getDefault().register(this);

    RestClientUtils.setUserAgent(getUserAgent());

    // Volley networking setup
    setupVolleyQueue();

    AppLockManager.getInstance().enableDefaultAppLockIfAvailable(this);
    if (AppLockManager.getInstance().isAppLockFeatureEnabled()) {
      AppLockManager.getInstance()
          .getCurrentAppLock()
          .setDisabledActivities(
              new String[] {"org.wordpress.android.ui.ShareIntentReceiverActivity"});
    }

    HelpshiftHelper.init(this);

    ApplicationLifecycleMonitor applicationLifecycleMonitor = new ApplicationLifecycleMonitor();
    registerComponentCallbacks(applicationLifecycleMonitor);
    registerActivityLifecycleCallbacks(applicationLifecycleMonitor);

    initAnalytics(SystemClock.elapsedRealtime() - startDate);
  }
  @SuppressWarnings("unused")
  public void onEventMainThread(UserSignedOutCompletely event) {
    try {
      SelfSignedSSLCertsManager.getInstance(getContext()).emptyLocalKeyStoreFile();
    } catch (GeneralSecurityException e) {
      AppLog.e(T.UTILS, "Error while cleaning the Local KeyStore File", e);
    } catch (IOException e) {
      AppLog.e(T.UTILS, "Error while cleaning the Local KeyStore File", e);
    }

    flushHttpCache();

    // Analytics resets
    AnalyticsTracker.endSession(false);
    AnalyticsTracker.clearAllData();

    // disable passcode lock
    AbstractAppLock appLock = AppLockManager.getInstance().getCurrentAppLock();
    if (appLock != null) {
      appLock.setPassword(null);
    }

    // dangerously delete all content!
    wpDB.dangerouslyDeleteAllContent();
  }
  public static void launchVideoLibrary(Fragment fragment) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("video/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);

    AppLockManager.getInstance().setExtendedTimeout();
    fragment.startActivityForResult(
        Intent.createChooser(intent, fragment.getString(R.string.pick_video)),
        RequestCode.ACTIVITY_REQUEST_CODE_PICTURE_LIBRARY);
  }
 public static void launchCamera(Fragment fragment, LaunchCameraCallback callback) {
   String state = android.os.Environment.getExternalStorageState();
   if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
     showSDCardRequiredDialog(fragment.getActivity());
   } else {
     Intent intent = prepareLaunchCameraIntent(callback);
     fragment.startActivityForResult(intent, RequestCode.ACTIVITY_REQUEST_CODE_TAKE_PHOTO);
     AppLockManager.getInstance().setExtendedTimeout();
   }
 }
 @Override
 public void onClick(View v) {
   Uri uri;
   int id = v.getId();
   if (id == R.id.about_url) {
     uri = Uri.parse(URL_AUTOMATTIC);
   } else if (id == R.id.about_tos) {
     uri = Uri.parse(URL_TOS);
   } else if (id == R.id.about_privacy) {
     uri = Uri.parse(URL_AUTOMATTIC + URL_PRIVACY_POLICY);
   } else {
     return;
   }
   AppLockManager.getInstance().setExtendedTimeout();
   startActivity(new Intent(Intent.ACTION_VIEW, uri));
 }
  @Override
  public void onStart() {
    super.onStart();

    Preference togglePref =
        mAppSettingsFragment.findPreference(
            getString(org.wordpress.passcodelock.R.string.pref_key_passcode_toggle));
    Preference changePref =
        mAppSettingsFragment.findPreference(
            getString(org.wordpress.passcodelock.R.string.pref_key_change_passcode));

    if (togglePref != null && changePref != null) {
      mPasscodePreferenceFragment.setPreferences(togglePref, changePref);
      ((SwitchPreference) togglePref)
          .setChecked(AppLockManager.getInstance().getAppLock().isPasswordLocked());
    }
  }
 public static void launchVideoCamera(Fragment fragment) {
   Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
   fragment.startActivityForResult(intent, RequestCode.ACTIVITY_REQUEST_CODE_TAKE_VIDEO);
   AppLockManager.getInstance().setExtendedTimeout();
 }