@Override
  protected boolean cached(Object[] args) {

    long groupId = (long) args[0];
    String articleId = (String) args[1];
    Locale locale = (Locale) args[2];
    Long templateId = (Long) args[3];

    String id = articleId + (templateId == null || templateId == 0 ? "" : templateId);
    Long userId = SessionContext.getUserId();
    TableCache webContent =
        (TableCache)
            CacheSQL.getInstance()
                .getById(DefaultCachedType.WEB_CONTENT, id, groupId, userId, locale);
    if (webContent != null) {
      onEvent(
          new WebContentDisplayEvent(
              getTargetScreenletId(),
              groupId,
              articleId,
              locale,
              templateId,
              webContent.getContent()));
      return true;
    }
    return false;
  }
 @Override
 protected void storeToCache(WebContentDisplayEvent event, Object... args) {
   String templateString =
       event.getTemplateId() == null || event.getTemplateId() == 0
           ? ""
           : event.getTemplateId().toString();
   String webContentId = event.getArticleId() + templateString;
   CacheSQL.getInstance()
       .set(
           new TableCache(
               webContentId,
               DefaultCachedType.WEB_CONTENT,
               event.getHtml(),
               event.getGroupId(),
               null,
               event.getLocale()));
 }
  @Override
  protected void onHandleIntent(Intent intent) {
    ConnectivityManager cm =
        (ConnectivityManager)
            getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (isConnected && SessionContext.hasSession()) {
      try {
        Cache cache = CacheSQL.getInstance();
        sendPortrait(cache);
        sendDocuments(cache);
        sendRecords(cache);
      } catch (Exception e) {
        LiferayLogger.e("Error syncing resources", e);
      }
    }
    CacheReceiver.completeWakefulIntent(intent);
  }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.ddl_form:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(DDLFormActivity.class));
        break;
      case R.id.ddl_list:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(DDLListActivity.class));
        break;
      case R.id.asset_list:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(SelectAssetActivity.class));
        break;
      case R.id.sign_up:
        DefaultAnimation.startActivityWithAnimation(this, getIntentWithTheme(SignUpActivity.class));
        break;
      case R.id.forgot_password:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(ForgotPasswordActivity.class));
        break;
      case R.id.user_portrait:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(UserPortraitActivity.class));
        break;
      case R.id.web_content_display:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(WebContentDisplayActivity.class));
        break;
      case R.id.add_bookmark:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(AddBookmarkActivity.class));
        break;
      case R.id.journal_article_with_template:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(JournalArticleWithTemplateActivity.class));
        break;
      case R.id.filtered_asset:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(FilteredAssetActivity.class));
        break;
      case R.id.login_full_screenlet:
        DefaultAnimation.startActivityWithAnimation(
            this, getIntentWithTheme(LoginFullActivity.class));
        break;
      case R.id.change_theme:
        finish();
        currentTheme = isDefaultTheme() ? R.style.material_theme : R.style.default_theme;
        startActivity(getIntentWithTheme(MainActivity.class));
        break;
      case R.id.clear_cache_forms:
        int formRows = CacheSQL.getInstance().clear(DefaultCachedType.DDL_FORM);
        int recordRows = CacheSQL.getInstance().clear(DefaultCachedType.DDL_RECORD);
        int listRows = CacheSQL.getInstance().clear(DefaultCachedType.DDL_LIST);
        int countRows = CacheSQL.getInstance().clear(DefaultCachedType.DDL_LIST_COUNT);

        String cacheFormsMessage =
            "Deleted "
                + formRows
                + " forms, "
                + recordRows
                + " records, "
                + listRows
                + " list rows and "
                + countRows
                + " count rows.";

        Snackbar.make(_content, cacheFormsMessage, Snackbar.LENGTH_SHORT).show();
        break;
      case R.id.clear_cache:
        boolean success = CacheSQL.getInstance().clear(this);
        String clearCacheMessage = "Cache cleared: " + (success ? "sucessfully" : "failed");
        Snackbar.make(_content, clearCacheMessage, Snackbar.LENGTH_SHORT).show();
        break;
      case R.id.sync_cache:
        CacheSQL.getInstance().resync();
        Snackbar.make(_content, "Launched resync process", Snackbar.LENGTH_SHORT).show();
        break;
      default:
        DefaultAnimation.startActivityWithAnimation(this, getIntentWithTheme(LoginActivity.class));
    }
  }
 private void store(boolean synced, long userId, String picturePath) {
   TableCache file =
       new TableCache(String.valueOf(userId), DefaultCachedType.USER_PORTRAIT_UPLOAD, picturePath);
   file.setDirty(!synced);
   CacheSQL.getInstance().set(file);
 }