/**
   * Copy the database from the old location (v1.4) into the new one (v2.0), set it as the default
   * database, and start using. Does not check for existence. Use legacyDataExists() first.
   *
   * @return boolean indicator if the full operation was successful.
   */
  public boolean migrateLegacyDatabase() {
    boolean result = false;

    String legacyPath = getLegacyDbPath();
    File legacyFile = new File(legacyPath, DEFAULT_DB_FILENAME);

    // copy the legacy database
    String newPath = getV20Path();
    File newFile = new File(newPath, "legacyData.mmb");
    try {
      copy(legacyFile, newFile);
    } catch (IOException e) {
      e.printStackTrace();
      return result;
    }

    // rename the legacy database to .bak
    File backupFile = new File(legacyPath, "data.bak");
    boolean renameSuccessful = legacyFile.renameTo(backupFile);
    if (!renameSuccessful) return result;

    // set the database path preference
    AppSettings settings = new AppSettings(mContext);
    String newFilename = newFile.toString();
    settings.getDatabaseSettings().setDatabasePath(newFilename);

    // open the newly copied database
    // set to restart main activity to reload the db.
    MainActivity.setRestartActivity(true);
    Toast.makeText(mContext, R.string.database_migrate_14_to_20_complete, Toast.LENGTH_LONG).show();

    result = true;
    return result;
  }
  private void updateAppWidget(
      Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    // Construct the RemoteViews object
    //        RemoteViews views = new RemoteViews(context.getPackageName(),
    // R.layout.widget_single_account);
    RemoteViews views = getRemoteViews(context, appWidgetManager, appWidgetId);

    // todo: allow selecting the account from a list.

    // todo: load the configured account id
    AppSettings settings = new AppSettings(context);
    String defaultAccountId = settings.getGeneralSettings().getDefaultAccountId();
    if (StringUtils.isNotEmpty(defaultAccountId)) {
      displayAccountInfo(context, defaultAccountId, views);
    }

    // handle + click -> open the new transaction screen for this account.
    // todo: pass the account id?
    initializeNewTransactionCommand(context, views);

    // handle logo click -> open the app.
    initializeStartAppCommand(context, views);

    // click account name -> refresh the balance.
    initializeRefreshDataCommand(context, views, appWidgetId);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
  }