@Override
    protected Spanned doInBackground(Void... params) {
      Spanned contentSpannable;

      if (mActivity == null || mActivity.getPost() == null) {
        return null;
      }

      Post post = mActivity.getPost();

      String postTitle = "<h1>" + post.getTitle() + "</h1>";
      String postContent = postTitle + post.getDescription() + "\n\n" + post.getMoreText();

      if (post.isLocalDraft()) {
        contentSpannable =
            WPHtml.fromHtml(
                postContent.replaceAll("\uFFFC", ""),
                mActivity,
                post,
                Math.min(mTextView.getWidth(), mTextView.getHeight()));
      } else {
        String htmlText =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"webview.css\" /></head><body><div id=\"container\">%s</div></body></html>";
        htmlText = String.format(htmlText, StringUtils.addPTags(postContent));
        contentSpannable = new SpannableString(htmlText);
      }

      return contentSpannable;
    }
  private static void authorizeUser(Simperium simperium, String token) {
    User user = simperium.getUser();

    String tokenFormat = "WPCC/%s/%s";
    String wpccToken =
        String.format(tokenFormat, BuildConfig.SIMPERIUM_APP_SECRET, StringUtils.notNullStr(token));

    user.setAccessToken(wpccToken);

    // we'll assume the user is AUTHORIZED, and catch NOT_AUTHORIZED if something goes wrong.
    user.setStatus(User.Status.AUTHORIZED);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.blog_preferences);

    Integer id = getIntent().getIntExtra("id", -1);
    blog = WordPress.getBlog(id);

    if (blog == null) {
      Toast.makeText(this, getString(R.string.blog_not_found), Toast.LENGTH_SHORT).show();
      finish();
      return;
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(StringUtils.unescapeHTML(blog.getBlogName()));
    actionBar.setDisplayHomeAsUpEnabled(true);

    mUsernameET = (EditText) findViewById(R.id.username);
    mPasswordET = (EditText) findViewById(R.id.password);
    mHttpUsernameET = (EditText) findViewById(R.id.httpuser);
    mHttpPasswordET = (EditText) findViewById(R.id.httppassword);
    mScaledImageWidthET = (EditText) findViewById(R.id.scaledImageWidth);
    mFullSizeCB = (CheckBox) findViewById(R.id.fullSizeImage);
    mScaledCB = (CheckBox) findViewById(R.id.scaledImage);
    mLocationCB = (CheckBox) findViewById(R.id.location);
    mImageWidthSpinner = (Spinner) findViewById(R.id.maxImageWidth);

    if (blog.isDotcomFlag()) {
      // Hide credentials section
      RelativeLayout credentialsRL = (RelativeLayout) findViewById(R.id.sectionContent);
      credentialsRL.setVisibility(View.GONE);
    }

    loadSettingsForBlog();
  }
 protected String getCurrentTagName() {
   if (!hasCurrentTag()) return "";
   return StringUtils.notNullStr(mCurrentTag);
 }
  private void refreshViews(Cursor cursor) {
    if (!cursor.moveToFirst()) return;

    // check whether or not to show the edit button
    String state = cursor.getString(cursor.getColumnIndex("uploadState"));
    mIsLocal = MediaUtils.isLocalFile(state);
    if (mIsLocal && getActivity() != null) {
      getActivity().invalidateOptionsMenu();
    }

    // title
    mTitleView.setText(cursor.getString(cursor.getColumnIndex("title")));

    // caption
    String caption = cursor.getString(cursor.getColumnIndex("caption"));
    if (caption == null || caption.length() == 0) {
      mCaptionView.setVisibility(View.GONE);
    } else {
      mCaptionView.setText(caption);
      mCaptionView.setVisibility(View.VISIBLE);
    }

    // description
    String desc = cursor.getString(cursor.getColumnIndex("description"));
    if (desc == null || desc.length() == 0) {
      mDescriptionView.setVisibility(View.GONE);
    } else {
      mDescriptionView.setText(desc);
      mDescriptionView.setVisibility(View.VISIBLE);
    }

    // added / upload date
    String date = MediaUtils.getDate(cursor.getLong(cursor.getColumnIndex("date_created_gmt")));
    if (mIsLocal) {
      mDateView.setText("Added on: " + date);
    } else {
      mDateView.setText("Uploaded on: " + date);
    }

    // file name
    String fileName = cursor.getString(cursor.getColumnIndex("fileName"));
    mFileNameView.setText("File name: " + fileName);

    // get the file extension from the fileURL
    String fileURL = cursor.getString(cursor.getColumnIndex("fileURL"));
    if (fileURL != null) {
      String fileType = fileURL.replaceAll(".*\\.(\\w+)$", "$1").toUpperCase();
      mFileTypeView.setText("File type: " + fileType);
      mFileTypeView.setVisibility(View.VISIBLE);
    } else {
      mFileTypeView.setVisibility(View.GONE);
    }

    String imageUri = cursor.getString(cursor.getColumnIndex("fileURL"));
    if (imageUri == null) imageUri = cursor.getString(cursor.getColumnIndex("filePath"));

    inflateImageView();

    // image and dimensions
    if (MediaUtils.isValidImage(imageUri)) {
      int width = cursor.getInt(cursor.getColumnIndex("width"));
      int height = cursor.getInt(cursor.getColumnIndex("height"));

      float screenWidth;

      View parentView = (View) mImageView.getParent();

      // differentiating between tablet and phone
      if (this.isInLayout()) {
        screenWidth = parentView.getMeasuredWidth();
      } else {
        screenWidth = getActivity().getResources().getDisplayMetrics().widthPixels;
      }
      float screenHeight = getActivity().getResources().getDisplayMetrics().heightPixels;

      if (width > 0 && height > 0) {
        String dimensions = width + "x" + height;
        mDimensionsView.setText("Dimensions: " + dimensions);
        mDimensionsView.setVisibility(View.VISIBLE);
      } else {
        mDimensionsView.setVisibility(View.GONE);
      }

      if (width > screenWidth) {
        height = (int) (height / (width / screenWidth));
        width = (int) screenWidth;
      } else if (height > screenHeight) {
        width = (int) (width / (height / screenHeight));
        height = (int) screenHeight;
      }

      if (mIsLocal) {
        final String filePath = cursor.getString(cursor.getColumnIndex("filePath"));
        loadLocalImage(mImageView, filePath, width, height);
      } else {
        // Allow non-private wp.com and Jetpack blogs to use photon to get a higher res thumbnail
        if (WordPress.getCurrentBlog() != null && WordPress.getCurrentBlog().isPhotonCapable()) {
          String thumbnailURL = StringUtils.getPhotonUrl(imageUri, (int) screenWidth);
          ((NetworkImageView) mImageView).setImageUrl(thumbnailURL, mImageLoader);
        } else {
          ((NetworkImageView) mImageView).setImageUrl(imageUri + "?w=" + screenWidth, mImageLoader);
        }
      }
      mImageView.setVisibility(View.VISIBLE);

      mImageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));

    } else {
      mImageView.setVisibility(View.GONE);
      mDimensionsView.setVisibility(View.GONE);
    }
  }