Program: 15191
Project: 15191
Buggy source:
@Override public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  Bundle extras=getIntent().getExtras();
  if (WordPress.wpDB == null)   WordPress.wpDB=new WordPressDB(this);
  if (WordPress.currentBlog == null) {
    try {
      WordPress.currentBlog=new Blog(WordPress.wpDB.getLastBlogID(this),this);
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
  Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
  int width=display.getWidth();
  int height=display.getHeight();
  if (height > width) {
    width=height;
  }
  if (width > 480) {
    isLargeScreen=true;
  }
  categories=new JSONArray();
  String action=getIntent().getAction();
  if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
    isAction=true;
    isNew=true;
    Vector<?> accounts=WordPress.wpDB.getAccounts(this);
    if (accounts.size() > 0) {
      final String blogNames[]=new String[accounts.size()];
      final int accountIDs[]=new int[accounts.size()];
      for (int i=0; i < accounts.size(); i++) {
        HashMap<?,?> curHash=(HashMap<?,?>)accounts.get(i);
        try {
          blogNames[i]=EscapeUtils.unescapeHtml(curHash.get("String_Node_Str").toString());
        }
 catch (        Exception e) {
          blogNames[i]=curHash.get("String_Node_Str").toString();
        }
        accountIDs[i]=(Integer)curHash.get("String_Node_Str");
        try {
          blog=new Blog(accountIDs[i],EditPost.this);
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
          finish();
        }
      }
      if (accounts.size() != 1) {
        AlertDialog.Builder builder=new AlertDialog.Builder(EditPost.this);
        builder.setCancelable(false);
        builder.setTitle(getResources().getText(R.string.select_a_blog));
        builder.setItems(blogNames,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface dialog,          int item){
            id=accountIDs[item];
            try {
              blog=new Blog(id,EditPost.this);
            }
 catch (            Exception e) {
              Toast.makeText(EditPost.this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
              finish();
            }
            WordPress.currentBlog=blog;
            WordPress.wpDB.updateLastBlogID(WordPress.currentBlog.getId());
            accountName=blogNames[item];
            setTitle(EscapeUtils.unescapeHtml(accountName) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
          }
        }
);
        AlertDialog alert=builder.create();
        alert.show();
      }
 else {
        id=accountIDs[0];
        try {
          blog=new Blog(id,EditPost.this);
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
          finish();
        }
        WordPress.currentBlog=blog;
        WordPress.wpDB.updateLastBlogID(WordPress.currentBlog.getId());
        accountName=blogNames[0];
        setTitle(EscapeUtils.unescapeHtml(accountName) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
      }
    }
 else {
      Intent i=new Intent(this,Dashboard.class);
      Toast.makeText(getApplicationContext(),getResources().getText(R.string.no_account),Toast.LENGTH_LONG).show();
      startActivity(i);
      finish();
      return;
    }
  }
 else {
    if (extras != null) {
      id=WordPress.currentBlog.getId();
      try {
        blog=new Blog(id,this);
      }
 catch (      Exception e) {
        Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
        finish();
      }
      accountName=EscapeUtils.unescapeHtml(extras.getString("String_Node_Str"));
      postID=extras.getLong("String_Node_Str");
      localDraft=extras.getBoolean("String_Node_Str",false);
      isPage=extras.getBoolean("String_Node_Str",false);
      isNew=extras.getBoolean("String_Node_Str",false);
      option=extras.getString("String_Node_Str");
      if (extras.getBoolean("String_Node_Str")) {
        id=extras.getInt("String_Node_Str");
        try {
          blog=new Blog(id,this);
          WordPress.currentBlog=blog;
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_LONG).show();
          finish();
          return;
        }
      }
      if (!isNew) {
        try {
          post=new Post(id,postID,isPage,this);
          if (post == null) {
            Toast.makeText(this,getResources().getText(R.string.post_not_found),Toast.LENGTH_LONG).show();
            finish();
            return;
          }
 else {
            WordPress.currentPost=post;
          }
        }
 catch (        Exception e) {
          finish();
        }
      }
    }
    if (isNew) {
      localDraft=true;
      setTitle(EscapeUtils.unescapeHtml(WordPress.currentBlog.getBlogName()) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
    }
 else {
      setTitle(EscapeUtils.unescapeHtml(WordPress.currentBlog.getBlogName()) + "String_Node_Str" + getResources().getText((isPage) ? R.string.edit_page : R.string.edit_post));
    }
  }
  setContentView(R.layout.edit);
  if (isPage) {
    RelativeLayout section3=(RelativeLayout)findViewById(R.id.section3);
    section3.setVisibility(View.GONE);
    RelativeLayout locationWrapper=(RelativeLayout)findViewById(R.id.location_wrapper);
    locationWrapper.setVisibility(View.GONE);
    TextView postFormatLabel=(TextView)findViewById(R.id.postFormatLabel);
    postFormatLabel.setVisibility(View.GONE);
    Spinner postFormatSpinner=(Spinner)findViewById(R.id.postFormat);
    postFormatSpinner.setVisibility(View.GONE);
  }
 else {
    if (blog.getPostFormats().equals("String_Node_Str")) {
      Vector<Object> args=new Vector<Object>();
      args.add(blog);
      args.add(this);
      new ApiHelper.getPostFormatsTask().execute(args);
      postFormatTitles=getResources().getStringArray(R.array.post_formats_array);
      String defaultPostFormatTitles[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      postFormats=defaultPostFormatTitles;
    }
 else {
      try {
        JSONObject jsonPostFormats=new JSONObject(blog.getPostFormats());
        postFormats=new String[jsonPostFormats.length()];
        postFormatTitles=new String[jsonPostFormats.length()];
        Iterator<?> it=jsonPostFormats.keys();
        int i=0;
        while (it.hasNext()) {
          String key=(String)it.next();
          String val=(String)jsonPostFormats.get(key);
          postFormats[i]=key;
          postFormatTitles[i]=val;
          i++;
        }
        java.util.Arrays.sort(postFormats);
        java.util.Arrays.sort(postFormatTitles);
      }
 catch (      JSONException e) {
        e.printStackTrace();
      }
    }
    Spinner pfSpinner=(Spinner)findViewById(R.id.postFormat);
    ArrayAdapter<String> pfAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,postFormatTitles);
    pfAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    pfSpinner.setAdapter(pfAdapter);
    String activePostFormat="String_Node_Str";
    if (!isNew) {
      if (!post.getWP_post_format().equals("String_Node_Str"))       activePostFormat=post.getWP_post_format();
    }
    for (int i=0; i < postFormats.length; i++) {
      if (postFormats[i].equals(activePostFormat))       pfSpinner.setSelection(i);
    }
    if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action))     setContent();
  }
  String[] items=new String[]{getResources().getString(R.string.publish_post),getResources().getString(R.string.draft),getResources().getString(R.string.pending_review),getResources().getString(R.string.post_private),getResources().getString(R.string.local_draft)};
  Spinner spinner=(Spinner)findViewById(R.id.status);
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spinner.setAdapter(adapter);
  spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> arg0,    View arg1,    int arg2,    long arg3){
      evaluateSaveButtonText();
    }
    @Override public void onNothingSelected(    AdapterView<?> arg0){
    }
  }
);
  boolean hasLocationProvider=false;
  LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
  List<String> providers=locationManager.getProviders(true);
  for (  String providerName : providers) {
    if (providerName.equals(LocationManager.GPS_PROVIDER) || providerName.equals(LocationManager.NETWORK_PROVIDER)) {
      hasLocationProvider=true;
    }
  }
  if (hasLocationProvider && blog.isLocation() && !isPage) {
    enableLBSButtons();
  }
  if (isNew) {
    if (option != null) {
      if (option.equals("String_Node_Str"))       launchCamera();
 else       if (option.equals("String_Node_Str"))       launchPictureLibrary();
 else       if (option.equals("String_Node_Str"))       launchVideoCamera();
 else       if (option.equals("String_Node_Str"))       launchVideoLibrary();
      localDraft=extras.getBoolean("String_Node_Str");
    }
  }
 else {
    EditText titleET=(EditText)findViewById(R.id.title);
    WPEditText contentET=(WPEditText)findViewById(R.id.postContent);
    EditText passwordET=(EditText)findViewById(R.id.post_password);
    titleET.setText(post.getTitle());
    if (post.isUploaded()) {
      items=new String[]{getResources().getString(R.string.publish_post),getResources().getString(R.string.draft),getResources().getString(R.string.pending_review),getResources().getString(R.string.post_private)};
      adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
      spinner.setAdapter(adapter);
    }
    String contentHTML;
    if (!post.getMt_text_more().equals("String_Node_Str")) {
      if (post.isLocalDraft())       contentHTML=post.getDescription() + "String_Node_Str" + post.getMt_text_more();
 else       contentHTML=post.getDescription() + "String_Node_Str" + post.getMt_text_more();
    }
 else {
      contentHTML=post.getDescription();
    }
    try {
      if (post.isLocalDraft()) {
        contentET.setText(WPHtml.fromHtml(contentHTML.replaceAll("String_Node_Str","String_Node_Str"),EditPost.this,post));
      }
 else {
        contentET.setText(contentHTML.replaceAll("String_Node_Str","String_Node_Str"));
      }
    }
 catch (    Exception e1) {
      e1.printStackTrace();
    }
    long pubDate=post.getDate_created_gmt();
    if (pubDate != 0) {
      try {
        int flags=0;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_DATE;
        flags|=android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_YEAR;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_TIME;
        String formattedDate=DateUtils.formatDateTime(EditPost.this,pubDate,flags);
        TextView tvPubDate=(TextView)findViewById(R.id.pubDate);
        tvPubDate.setText(formattedDate);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    if (post.getWP_password() != null)     passwordET.setText(post.getWP_password());
    if (post.getPost_status() != null) {
      String status=post.getPost_status();
      if (status.equals("String_Node_Str")) {
        spinner.setSelection(0,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(1,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(2,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(3,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(4,true);
      }
      evaluateSaveButtonText();
    }
    if (!isPage) {
      if (post.getCategories() != null) {
        categories=post.getCategories();
        if (!categories.equals("String_Node_Str")) {
          for (int i=0; i < categories.length(); i++) {
            try {
              selectedCategories.add(categories.getString(i));
            }
 catch (            JSONException e) {
              e.printStackTrace();
            }
          }
          TextView tvCategories=(TextView)findViewById(R.id.selectedCategories);
          tvCategories.setText(getResources().getText(R.string.selected_categories) + "String_Node_Str" + getCategoriesCSV());
        }
      }
      Double latitude=post.getLatitude();
      Double longitude=post.getLongitude();
      if (latitude != 0.0) {
        new getAddressTask().execute(latitude,longitude);
      }
    }
    String tags=post.getMt_keywords();
    if (!tags.equals("String_Node_Str")) {
      EditText tagsET=(EditText)findViewById(R.id.tags);
      tagsET.setText(tags);
    }
  }
  if (!isPage) {
    Button selectCategories=(Button)findViewById(R.id.selectCategories);
    selectCategories.setOnClickListener(new Button.OnClickListener(){
      public void onClick(      View v){
        Bundle bundle=new Bundle();
        bundle.putInt("String_Node_Str",id);
        if (categories.length() > 0) {
          bundle.putString("String_Node_Str",getCategoriesCSV());
        }
        Intent i=new Intent(EditPost.this,SelectCategories.class);
        i.putExtras(bundle);
        startActivityForResult(i,5);
      }
    }
);
  }
  final WPEditText content=(WPEditText)findViewById(R.id.postContent);
  content.setOnFocusChangeListener(new View.OnFocusChangeListener(){
    @Override public void onFocusChange(    View view,    boolean hasFocus){
      if (!isFullScreenEditing && hasFocus)       content.performClick();
    }
  }
);
  content.setOnTouchListener(new View.OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() > 1)       scrollDetected=true;
      if (event.getAction() == 1 && !scrollDetected && isFullScreenEditing) {
        Layout layout=((TextView)v).getLayout();
        int x=(int)event.getX();
        int y=(int)event.getY();
        if (layout != null) {
          int line=layout.getLineForVertical(y);
          int charPosition=layout.getOffsetForHorizontal(line,x);
          final Spannable s=content.getText();
          WPImageSpan[] click_spans=s.getSpans(charPosition,charPosition,WPImageSpan.class);
          if (click_spans.length != 0) {
            final WPImageSpan span=click_spans[0];
            if (!span.isVideo()) {
              LayoutInflater factory=LayoutInflater.from(EditPost.this);
              final View alertView=factory.inflate(R.layout.alert_image_options,null);
              final TextView imageWidthText=(TextView)alertView.findViewById(R.id.imageWidthText);
              final EditText titleText=(EditText)alertView.findViewById(R.id.title);
              final EditText caption=(EditText)alertView.findViewById(R.id.caption);
              final SeekBar seekBar=(SeekBar)alertView.findViewById(R.id.imageWidth);
              final Spinner alignmentSpinner=(Spinner)alertView.findViewById(R.id.alignment_spinner);
              ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(EditPost.this,R.array.alignment_array,android.R.layout.simple_spinner_item);
              adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              alignmentSpinner.setAdapter(adapter);
              imageWidthText.setText(String.valueOf(span.getWidth()) + "String_Node_Str");
              seekBar.setProgress(span.getWidth());
              titleText.setText(span.getTitle());
              caption.setText(span.getCaption());
              alignmentSpinner.setSelection(span.getHorizontalAlignment(),true);
              seekBar.setMax(100);
              if (span.getWidth() != 0)               seekBar.setProgress(span.getWidth() / 10);
              seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
                @Override public void onStopTrackingTouch(                SeekBar seekBar){
                }
                @Override public void onStartTrackingTouch(                SeekBar seekBar){
                }
                @Override public void onProgressChanged(                SeekBar seekBar,                int progress,                boolean fromUser){
                  if (progress == 0)                   progress=1;
                  imageWidthText.setText(progress * 10 + "String_Node_Str");
                }
              }
);
              AlertDialog ad=new AlertDialog.Builder(EditPost.this).setTitle("String_Node_Str").setView(alertView).setPositiveButton("String_Node_Str",new DialogInterface.OnClickListener(){
                public void onClick(                DialogInterface dialog,                int whichButton){
                  span.setTitle(titleText.getText().toString());
                  span.setHorizontalAlignment(alignmentSpinner.getSelectedItemPosition());
                  span.setWidth(seekBar.getProgress() * 10);
                  span.setCaption(caption.getText().toString());
                }
              }
).setNegativeButton("String_Node_Str",new DialogInterface.OnClickListener(){
                public void onClick(                DialogInterface dialog,                int whichButton){
                }
              }
).create();
              ad.show();
              scrollDetected=false;
              return true;
            }
          }
 else {
            content.setMovementMethod(ArrowKeyMovementMethod.getInstance());
            content.setSelection(content.getSelectionStart());
          }
        }
      }
 else       if (event.getAction() == 1) {
        scrollDetected=false;
      }
      return false;
    }
  }
);
  content.setOnClickListener(new EditText.OnClickListener(){
    public void onClick(    View v){
      if (!isFullScreenEditing) {
        isFullScreenEditing=true;
        content.setFocusableInTouchMode(true);
        try {
          LinearLayout smallEditorWrap=(LinearLayout)findViewById(R.id.postContentEditorSmallWrapper);
          smallEditorWrap.removeView(content);
          ScrollView scrollView=(ScrollView)findViewById(R.id.scrollView);
          scrollView.setVisibility(View.GONE);
          LinearLayout contentEditorWrap=(LinearLayout)findViewById(R.id.postContentEditorWrapper);
          contentEditorWrap.addView(content);
          contentEditorWrap.setVisibility(View.VISIBLE);
          RelativeLayout formatBar=(RelativeLayout)findViewById(R.id.formatBar);
          formatBar.setVisibility(View.VISIBLE);
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
        content.requestFocus();
      }
    }
  }
);
  content.setOnEditTextImeBackListener(new WPEditText.EditTextImeBackListener(){
    @Override public void onImeBack(    WPEditText view,    String text){
      finishEditing();
      imeBackPressed=true;
    }
  }
);
  content.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(    Editable s){
      try {
        int position=Selection.getSelectionStart(content.getText());
        if ((isBackspace && position != 1) || lastPosition == position || !localDraft)         return;
        ToggleButton boldButton=(ToggleButton)findViewById(R.id.bold);
        ToggleButton emButton=(ToggleButton)findViewById(R.id.em);
        ToggleButton bquoteButton=(ToggleButton)findViewById(R.id.bquote);
        ToggleButton underlineButton=(ToggleButton)findViewById(R.id.underline);
        ToggleButton strikeButton=(ToggleButton)findViewById(R.id.strike);
        if (position < 0) {
          position=0;
        }
        lastPosition=position;
        if (position > 0) {
          if (styleStart > position) {
            styleStart=position - 1;
          }
          boolean exists=false;
          if (boldButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.BOLD) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (emButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.ITALIC) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (emButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.ITALIC) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (underlineButton.isChecked()) {
            WPUnderlineSpan[] ss=s.getSpans(styleStart,position,WPUnderlineSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new WPUnderlineSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (strikeButton.isChecked()) {
            StrikethroughSpan[] ss=s.getSpans(styleStart,position,StrikethroughSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new StrikethroughSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (bquoteButton.isChecked()) {
            QuoteSpan[] ss=s.getSpans(styleStart,position,QuoteSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new QuoteSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    public void beforeTextChanged(    CharSequence s,    int start,    int count,    int after){
      if ((count - after == 1) || (s.length() == 0))       isBackspace=true;
 else       isBackspace=false;
    }
    public void onTextChanged(    CharSequence s,    int start,    int before,    int count){
    }
  }
);
  final ImageButton addPictureButton=(ImageButton)findViewById(R.id.addPictureButton);
  registerForContextMenu(addPictureButton);
  addPictureButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      addPictureButton.performLongClick();
    }
  }
);
  final Button saveButton=(Button)findViewById(R.id.post);
  saveButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      boolean result=savePost();
      if (result) {
        if (post.isUploaded() || !post.getPost_status().equals("String_Node_Str"))         post.upload();
        finish();
      }
    }
  }
);
  Button pubDate=(Button)findViewById(R.id.pubDateButton);
  pubDate.setOnClickListener(new TextView.OnClickListener(){
    public void onClick(    View v){
      Calendar c=Calendar.getInstance();
      mYear=c.get(Calendar.YEAR);
      mMonth=c.get(Calendar.MONTH);
      mDay=c.get(Calendar.DAY_OF_MONTH);
      mHour=c.get(Calendar.HOUR_OF_DAY);
      mMinute=c.get(Calendar.MINUTE);
      showDialog(ID_DIALOG_DATE);
    }
  }
);
  final ToggleButton boldButton=(ToggleButton)findViewById(R.id.bold);
  boldButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(boldButton,"String_Node_Str");
    }
  }
);
  final Button linkButton=(Button)findViewById(R.id.link);
  linkButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
      selectionStart=contentText.getSelectionStart();
      styleStart=selectionStart;
      selectionEnd=contentText.getSelectionEnd();
      if (selectionStart > selectionEnd) {
        int temp=selectionEnd;
        selectionEnd=selectionStart;
        selectionStart=temp;
      }
      Intent i=new Intent(EditPost.this,Link.class);
      if (selectionEnd > selectionStart) {
        String selectedText=contentText.getText().subSequence(selectionStart,selectionEnd).toString();
        i.putExtra("String_Node_Str",selectedText);
      }
      startActivityForResult(i,4);
    }
  }
);
  final ToggleButton emButton=(ToggleButton)findViewById(R.id.em);
  emButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(emButton,"String_Node_Str");
    }
  }
);
  final ToggleButton underlineButton=(ToggleButton)findViewById(R.id.underline);
  underlineButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(underlineButton,"String_Node_Str");
    }
  }
);
  final ToggleButton strikeButton=(ToggleButton)findViewById(R.id.strike);
  strikeButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(strikeButton,"String_Node_Str");
    }
  }
);
  final ToggleButton bquoteButton=(ToggleButton)findViewById(R.id.bquote);
  bquoteButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(bquoteButton,"String_Node_Str");
    }
  }
);
  final Button moreButton=(Button)findViewById(R.id.more);
  moreButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
      selectionEnd=contentText.getSelectionEnd();
      Editable str=contentText.getText();
      str.insert(selectionEnd,"String_Node_Str");
    }
  }
);
}

Fixed version (ground truth):
@Override public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  Bundle extras=getIntent().getExtras();
  if (WordPress.wpDB == null)   WordPress.wpDB=new WordPressDB(this);
  if (WordPress.currentBlog == null) {
    try {
      WordPress.currentBlog=new Blog(WordPress.wpDB.getLastBlogID(this),this);
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
  Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
  int width=display.getWidth();
  int height=display.getHeight();
  if (height > width) {
    width=height;
  }
  if (width > 480) {
    isLargeScreen=true;
  }
  categories=new JSONArray();
  String action=getIntent().getAction();
  if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
    isAction=true;
    isNew=true;
    Vector<?> accounts=WordPress.wpDB.getAccounts(this);
    if (accounts.size() > 0) {
      final String blogNames[]=new String[accounts.size()];
      final int accountIDs[]=new int[accounts.size()];
      for (int i=0; i < accounts.size(); i++) {
        HashMap<?,?> curHash=(HashMap<?,?>)accounts.get(i);
        try {
          blogNames[i]=EscapeUtils.unescapeHtml(curHash.get("String_Node_Str").toString());
        }
 catch (        Exception e) {
          blogNames[i]=curHash.get("String_Node_Str").toString();
        }
        accountIDs[i]=(Integer)curHash.get("String_Node_Str");
        try {
          blog=new Blog(accountIDs[i],EditPost.this);
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
          finish();
        }
      }
      if (accounts.size() != 1) {
        AlertDialog.Builder builder=new AlertDialog.Builder(EditPost.this);
        builder.setCancelable(false);
        builder.setTitle(getResources().getText(R.string.select_a_blog));
        builder.setItems(blogNames,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface dialog,          int item){
            id=accountIDs[item];
            try {
              blog=new Blog(id,EditPost.this);
            }
 catch (            Exception e) {
              Toast.makeText(EditPost.this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
              finish();
            }
            WordPress.currentBlog=blog;
            WordPress.wpDB.updateLastBlogID(WordPress.currentBlog.getId());
            accountName=blogNames[item];
            setTitle(EscapeUtils.unescapeHtml(accountName) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
          }
        }
);
        AlertDialog alert=builder.create();
        alert.show();
      }
 else {
        id=accountIDs[0];
        try {
          blog=new Blog(id,EditPost.this);
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
          finish();
        }
        WordPress.currentBlog=blog;
        WordPress.wpDB.updateLastBlogID(WordPress.currentBlog.getId());
        accountName=blogNames[0];
        setTitle(EscapeUtils.unescapeHtml(accountName) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
      }
    }
 else {
      Intent i=new Intent(this,Dashboard.class);
      Toast.makeText(getApplicationContext(),getResources().getText(R.string.no_account),Toast.LENGTH_LONG).show();
      startActivity(i);
      finish();
      return;
    }
  }
 else {
    if (extras != null) {
      id=WordPress.currentBlog.getId();
      try {
        blog=new Blog(id,this);
      }
 catch (      Exception e) {
        Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_SHORT).show();
        finish();
      }
      accountName=EscapeUtils.unescapeHtml(extras.getString("String_Node_Str"));
      postID=extras.getLong("String_Node_Str");
      localDraft=extras.getBoolean("String_Node_Str",false);
      isPage=extras.getBoolean("String_Node_Str",false);
      isNew=extras.getBoolean("String_Node_Str",false);
      option=extras.getString("String_Node_Str");
      if (extras.getBoolean("String_Node_Str")) {
        id=extras.getInt("String_Node_Str");
        try {
          blog=new Blog(id,this);
          WordPress.currentBlog=blog;
        }
 catch (        Exception e) {
          Toast.makeText(this,getResources().getText(R.string.blog_not_found),Toast.LENGTH_LONG).show();
          finish();
          return;
        }
      }
      if (!isNew) {
        try {
          post=new Post(id,postID,isPage,this);
          if (post == null) {
            Toast.makeText(this,getResources().getText(R.string.post_not_found),Toast.LENGTH_LONG).show();
            finish();
            return;
          }
 else {
            WordPress.currentPost=post;
          }
        }
 catch (        Exception e) {
          finish();
        }
      }
    }
    if (isNew) {
      localDraft=true;
      setTitle(EscapeUtils.unescapeHtml(WordPress.currentBlog.getBlogName()) + "String_Node_Str" + getResources().getText((isPage) ? R.string.new_page : R.string.new_post));
    }
 else {
      setTitle(EscapeUtils.unescapeHtml(WordPress.currentBlog.getBlogName()) + "String_Node_Str" + getResources().getText((isPage) ? R.string.edit_page : R.string.edit_post));
    }
  }
  setContentView(R.layout.edit);
  if (isPage) {
    RelativeLayout section3=(RelativeLayout)findViewById(R.id.section3);
    section3.setVisibility(View.GONE);
    RelativeLayout locationWrapper=(RelativeLayout)findViewById(R.id.location_wrapper);
    locationWrapper.setVisibility(View.GONE);
    TextView postFormatLabel=(TextView)findViewById(R.id.postFormatLabel);
    postFormatLabel.setVisibility(View.GONE);
    Spinner postFormatSpinner=(Spinner)findViewById(R.id.postFormat);
    postFormatSpinner.setVisibility(View.GONE);
  }
 else {
    if (blog.getPostFormats().equals("String_Node_Str")) {
      Vector<Object> args=new Vector<Object>();
      args.add(blog);
      args.add(this);
      new ApiHelper.getPostFormatsTask().execute(args);
      postFormatTitles=getResources().getStringArray(R.array.post_formats_array);
      String defaultPostFormatTitles[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      postFormats=defaultPostFormatTitles;
    }
 else {
      try {
        JSONObject jsonPostFormats=new JSONObject(blog.getPostFormats());
        postFormats=new String[jsonPostFormats.length()];
        postFormatTitles=new String[jsonPostFormats.length()];
        Iterator<?> it=jsonPostFormats.keys();
        int i=0;
        while (it.hasNext()) {
          String key=(String)it.next();
          String val=(String)jsonPostFormats.get(key);
          postFormats[i]=key;
          postFormatTitles[i]=val;
          i++;
        }
        java.util.Arrays.sort(postFormats);
        java.util.Arrays.sort(postFormatTitles);
      }
 catch (      JSONException e) {
        e.printStackTrace();
      }
    }
    Spinner pfSpinner=(Spinner)findViewById(R.id.postFormat);
    ArrayAdapter<String> pfAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,postFormatTitles);
    pfAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    pfSpinner.setAdapter(pfAdapter);
    String activePostFormat="String_Node_Str";
    if (!isNew) {
      if (!post.getWP_post_format().equals("String_Node_Str"))       activePostFormat=post.getWP_post_format();
    }
    for (int i=0; i < postFormats.length; i++) {
      if (postFormats[i].equals(activePostFormat))       pfSpinner.setSelection(i);
    }
    if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action))     setContent();
  }
  String[] items=new String[]{getResources().getString(R.string.publish_post),getResources().getString(R.string.draft),getResources().getString(R.string.pending_review),getResources().getString(R.string.post_private),getResources().getString(R.string.local_draft)};
  Spinner spinner=(Spinner)findViewById(R.id.status);
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spinner.setAdapter(adapter);
  spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> arg0,    View arg1,    int arg2,    long arg3){
      evaluateSaveButtonText();
    }
    @Override public void onNothingSelected(    AdapterView<?> arg0){
    }
  }
);
  boolean hasLocationProvider=false;
  LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
  List<String> providers=locationManager.getProviders(true);
  for (  String providerName : providers) {
    if (providerName.equals(LocationManager.GPS_PROVIDER) || providerName.equals(LocationManager.NETWORK_PROVIDER)) {
      hasLocationProvider=true;
    }
  }
  if (hasLocationProvider && blog.isLocation() && !isPage) {
    enableLBSButtons();
  }
  if (isNew) {
    if (option != null) {
      if (option.equals("String_Node_Str"))       launchCamera();
 else       if (option.equals("String_Node_Str"))       launchPictureLibrary();
 else       if (option.equals("String_Node_Str"))       launchVideoCamera();
 else       if (option.equals("String_Node_Str"))       launchVideoLibrary();
      localDraft=extras.getBoolean("String_Node_Str");
    }
  }
 else {
    EditText titleET=(EditText)findViewById(R.id.title);
    WPEditText contentET=(WPEditText)findViewById(R.id.postContent);
    EditText passwordET=(EditText)findViewById(R.id.post_password);
    titleET.setText(post.getTitle());
    if (post.isUploaded()) {
      items=new String[]{getResources().getString(R.string.publish_post),getResources().getString(R.string.draft),getResources().getString(R.string.pending_review),getResources().getString(R.string.post_private)};
      adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
      spinner.setAdapter(adapter);
    }
    String contentHTML;
    if (!post.getMt_text_more().equals("String_Node_Str")) {
      if (post.isLocalDraft())       contentHTML=post.getDescription() + "String_Node_Str" + post.getMt_text_more();
 else       contentHTML=post.getDescription() + "String_Node_Str" + post.getMt_text_more();
    }
 else {
      contentHTML=post.getDescription();
    }
    try {
      if (post.isLocalDraft()) {
        contentET.setText(WPHtml.fromHtml(contentHTML.replaceAll("String_Node_Str","String_Node_Str"),EditPost.this,post));
      }
 else {
        contentET.setText(contentHTML.replaceAll("String_Node_Str","String_Node_Str"));
      }
    }
 catch (    Exception e1) {
      e1.printStackTrace();
    }
    long pubDate=post.getDate_created_gmt();
    if (pubDate != 0) {
      try {
        int flags=0;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_DATE;
        flags|=android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_YEAR;
        flags|=android.text.format.DateUtils.FORMAT_SHOW_TIME;
        String formattedDate=DateUtils.formatDateTime(EditPost.this,pubDate,flags);
        TextView tvPubDate=(TextView)findViewById(R.id.pubDate);
        tvPubDate.setText(formattedDate);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    if (post.getWP_password() != null)     passwordET.setText(post.getWP_password());
    if (post.getPost_status() != null) {
      String status=post.getPost_status();
      if (status.equals("String_Node_Str")) {
        spinner.setSelection(0,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(1,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(2,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(3,true);
      }
 else       if (status.equals("String_Node_Str")) {
        spinner.setSelection(4,true);
      }
      evaluateSaveButtonText();
    }
    if (!isPage) {
      if (post.getCategories() != null) {
        categories=post.getCategories();
        if (!categories.equals("String_Node_Str")) {
          for (int i=0; i < categories.length(); i++) {
            try {
              selectedCategories.add(categories.getString(i));
            }
 catch (            JSONException e) {
              e.printStackTrace();
            }
          }
          TextView tvCategories=(TextView)findViewById(R.id.selectedCategories);
          tvCategories.setText(getResources().getText(R.string.selected_categories) + "String_Node_Str" + getCategoriesCSV());
        }
      }
      Double latitude=post.getLatitude();
      Double longitude=post.getLongitude();
      if (latitude != 0.0) {
        new getAddressTask().execute(latitude,longitude);
      }
    }
    String tags=post.getMt_keywords();
    if (!tags.equals("String_Node_Str")) {
      EditText tagsET=(EditText)findViewById(R.id.tags);
      tagsET.setText(tags);
    }
  }
  if (!isPage) {
    Button selectCategories=(Button)findViewById(R.id.selectCategories);
    selectCategories.setOnClickListener(new Button.OnClickListener(){
      public void onClick(      View v){
        Bundle bundle=new Bundle();
        bundle.putInt("String_Node_Str",id);
        if (categories.length() > 0) {
          bundle.putString("String_Node_Str",getCategoriesCSV());
        }
        Intent i=new Intent(EditPost.this,SelectCategories.class);
        i.putExtras(bundle);
        startActivityForResult(i,5);
      }
    }
);
  }
  final WPEditText content=(WPEditText)findViewById(R.id.postContent);
  content.setOnFocusChangeListener(new View.OnFocusChangeListener(){
    @Override public void onFocusChange(    View view,    boolean hasFocus){
      if (!isFullScreenEditing && hasFocus)       content.performClick();
    }
  }
);
  content.setOnTouchListener(new View.OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      float pos=event.getY();
      if (event.getAction() == 0)       lastYPos=pos;
      if (event.getAction() > 1) {
        if (((lastYPos - pos) > 2.0f) || ((pos - lastYPos) > 2.0f))         scrollDetected=true;
      }
      lastYPos=pos;
      if (event.getAction() == 1 && !scrollDetected && isFullScreenEditing) {
        Layout layout=((TextView)v).getLayout();
        int x=(int)event.getX();
        int y=(int)event.getY();
        if (layout != null) {
          int line=layout.getLineForVertical(y);
          int charPosition=layout.getOffsetForHorizontal(line,x);
          final Spannable s=content.getText();
          WPImageSpan[] click_spans=s.getSpans(charPosition,charPosition,WPImageSpan.class);
          if (click_spans.length != 0) {
            final WPImageSpan span=click_spans[0];
            if (!span.isVideo()) {
              LayoutInflater factory=LayoutInflater.from(EditPost.this);
              final View alertView=factory.inflate(R.layout.alert_image_options,null);
              final TextView imageWidthText=(TextView)alertView.findViewById(R.id.imageWidthText);
              final EditText titleText=(EditText)alertView.findViewById(R.id.title);
              final EditText caption=(EditText)alertView.findViewById(R.id.caption);
              final SeekBar seekBar=(SeekBar)alertView.findViewById(R.id.imageWidth);
              final Spinner alignmentSpinner=(Spinner)alertView.findViewById(R.id.alignment_spinner);
              ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(EditPost.this,R.array.alignment_array,android.R.layout.simple_spinner_item);
              adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              alignmentSpinner.setAdapter(adapter);
              imageWidthText.setText(String.valueOf(span.getWidth()) + "String_Node_Str");
              seekBar.setProgress(span.getWidth());
              titleText.setText(span.getTitle());
              caption.setText(span.getCaption());
              alignmentSpinner.setSelection(span.getHorizontalAlignment(),true);
              seekBar.setMax(100);
              if (span.getWidth() != 0)               seekBar.setProgress(span.getWidth() / 10);
              seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
                @Override public void onStopTrackingTouch(                SeekBar seekBar){
                }
                @Override public void onStartTrackingTouch(                SeekBar seekBar){
                }
                @Override public void onProgressChanged(                SeekBar seekBar,                int progress,                boolean fromUser){
                  if (progress == 0)                   progress=1;
                  imageWidthText.setText(progress * 10 + "String_Node_Str");
                }
              }
);
              AlertDialog ad=new AlertDialog.Builder(EditPost.this).setTitle("String_Node_Str").setView(alertView).setPositiveButton("String_Node_Str",new DialogInterface.OnClickListener(){
                public void onClick(                DialogInterface dialog,                int whichButton){
                  span.setTitle(titleText.getText().toString());
                  span.setHorizontalAlignment(alignmentSpinner.getSelectedItemPosition());
                  span.setWidth(seekBar.getProgress() * 10);
                  span.setCaption(caption.getText().toString());
                }
              }
).setNegativeButton("String_Node_Str",new DialogInterface.OnClickListener(){
                public void onClick(                DialogInterface dialog,                int whichButton){
                }
              }
).create();
              ad.show();
              scrollDetected=false;
              return true;
            }
          }
 else {
            content.setMovementMethod(ArrowKeyMovementMethod.getInstance());
            content.setSelection(content.getSelectionStart());
          }
        }
      }
 else       if (event.getAction() == 1) {
        scrollDetected=false;
      }
      return false;
    }
  }
);
  content.setOnSelectionChangedListener(new WPEditText.OnSelectionChangedListener(){
    @Override public void onSelectionChanged(){
      if (!localDraft)       return;
      final Spannable s=content.getText();
      styleStart=content.getSelectionStart();
      Object[] spans=s.getSpans(content.getSelectionStart(),content.getSelectionStart(),Object.class);
      ToggleButton boldButton=(ToggleButton)findViewById(R.id.bold);
      ToggleButton emButton=(ToggleButton)findViewById(R.id.em);
      ToggleButton bquoteButton=(ToggleButton)findViewById(R.id.bquote);
      ToggleButton underlineButton=(ToggleButton)findViewById(R.id.underline);
      ToggleButton strikeButton=(ToggleButton)findViewById(R.id.strike);
      boldButton.setChecked(false);
      emButton.setChecked(false);
      bquoteButton.setChecked(false);
      underlineButton.setChecked(false);
      strikeButton.setChecked(false);
      for (      Object span : spans) {
        if (span instanceof StyleSpan) {
          StyleSpan ss=(StyleSpan)span;
          if (ss.getStyle() == android.graphics.Typeface.BOLD) {
            boldButton.setChecked(true);
          }
          if (ss.getStyle() == android.graphics.Typeface.ITALIC) {
            emButton.setChecked(true);
          }
        }
        if (span instanceof QuoteSpan) {
          bquoteButton.setChecked(true);
        }
        if (span instanceof WPUnderlineSpan) {
          underlineButton.setChecked(true);
        }
        if (span instanceof StrikethroughSpan) {
          strikeButton.setChecked(true);
        }
      }
    }
  }
);
  content.setOnClickListener(new EditText.OnClickListener(){
    public void onClick(    View v){
      if (!isFullScreenEditing) {
        isFullScreenEditing=true;
        content.setFocusableInTouchMode(true);
        try {
          LinearLayout smallEditorWrap=(LinearLayout)findViewById(R.id.postContentEditorSmallWrapper);
          smallEditorWrap.removeView(content);
          ScrollView scrollView=(ScrollView)findViewById(R.id.scrollView);
          scrollView.setVisibility(View.GONE);
          LinearLayout contentEditorWrap=(LinearLayout)findViewById(R.id.postContentEditorWrapper);
          contentEditorWrap.addView(content);
          contentEditorWrap.setVisibility(View.VISIBLE);
          RelativeLayout formatBar=(RelativeLayout)findViewById(R.id.formatBar);
          formatBar.setVisibility(View.VISIBLE);
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
        content.requestFocus();
      }
    }
  }
);
  content.setOnEditTextImeBackListener(new WPEditText.EditTextImeBackListener(){
    @Override public void onImeBack(    WPEditText view,    String text){
      finishEditing();
      imeBackPressed=true;
    }
  }
);
  content.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(    Editable s){
      try {
        int position=Selection.getSelectionStart(content.getText());
        if ((isBackspace && position != 1) || lastPosition == position || !localDraft)         return;
        ToggleButton boldButton=(ToggleButton)findViewById(R.id.bold);
        ToggleButton emButton=(ToggleButton)findViewById(R.id.em);
        ToggleButton bquoteButton=(ToggleButton)findViewById(R.id.bquote);
        ToggleButton underlineButton=(ToggleButton)findViewById(R.id.underline);
        ToggleButton strikeButton=(ToggleButton)findViewById(R.id.strike);
        if (position < 0) {
          position=0;
        }
        lastPosition=position;
        if (position > 0) {
          if (styleStart > position) {
            styleStart=position - 1;
          }
          boolean exists=false;
          if (boldButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.BOLD) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (emButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.ITALIC) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (emButton.isChecked()) {
            StyleSpan[] ss=s.getSpans(styleStart,position,StyleSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              if (ss[i].getStyle() == android.graphics.Typeface.ITALIC) {
                exists=true;
              }
            }
            if (!exists)             s.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (underlineButton.isChecked()) {
            WPUnderlineSpan[] ss=s.getSpans(styleStart,position,WPUnderlineSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new WPUnderlineSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (strikeButton.isChecked()) {
            StrikethroughSpan[] ss=s.getSpans(styleStart,position,StrikethroughSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new StrikethroughSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
          if (bquoteButton.isChecked()) {
            QuoteSpan[] ss=s.getSpans(styleStart,position,QuoteSpan.class);
            exists=false;
            for (int i=0; i < ss.length; i++) {
              exists=true;
            }
            if (!exists)             s.setSpan(new QuoteSpan(),styleStart,position,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
          }
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    public void beforeTextChanged(    CharSequence s,    int start,    int count,    int after){
      if ((count - after == 1) || (s.length() == 0))       isBackspace=true;
 else       isBackspace=false;
    }
    public void onTextChanged(    CharSequence s,    int start,    int before,    int count){
    }
  }
);
  final ImageButton addPictureButton=(ImageButton)findViewById(R.id.addPictureButton);
  registerForContextMenu(addPictureButton);
  addPictureButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      addPictureButton.performLongClick();
    }
  }
);
  final Button saveButton=(Button)findViewById(R.id.post);
  saveButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      boolean result=savePost();
      if (result) {
        if (post.isUploaded() || !post.getPost_status().equals("String_Node_Str"))         post.upload();
        finish();
      }
    }
  }
);
  Button pubDate=(Button)findViewById(R.id.pubDateButton);
  pubDate.setOnClickListener(new TextView.OnClickListener(){
    public void onClick(    View v){
      Calendar c=Calendar.getInstance();
      mYear=c.get(Calendar.YEAR);
      mMonth=c.get(Calendar.MONTH);
      mDay=c.get(Calendar.DAY_OF_MONTH);
      mHour=c.get(Calendar.HOUR_OF_DAY);
      mMinute=c.get(Calendar.MINUTE);
      showDialog(ID_DIALOG_DATE);
    }
  }
);
  final ToggleButton boldButton=(ToggleButton)findViewById(R.id.bold);
  boldButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(boldButton,"String_Node_Str");
    }
  }
);
  final Button linkButton=(Button)findViewById(R.id.link);
  linkButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
      selectionStart=contentText.getSelectionStart();
      styleStart=selectionStart;
      selectionEnd=contentText.getSelectionEnd();
      if (selectionStart > selectionEnd) {
        int temp=selectionEnd;
        selectionEnd=selectionStart;
        selectionStart=temp;
      }
      Intent i=new Intent(EditPost.this,Link.class);
      if (selectionEnd > selectionStart) {
        String selectedText=contentText.getText().subSequence(selectionStart,selectionEnd).toString();
        i.putExtra("String_Node_Str",selectedText);
      }
      startActivityForResult(i,4);
    }
  }
);
  final ToggleButton emButton=(ToggleButton)findViewById(R.id.em);
  emButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(emButton,"String_Node_Str");
    }
  }
);
  final ToggleButton underlineButton=(ToggleButton)findViewById(R.id.underline);
  underlineButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(underlineButton,"String_Node_Str");
    }
  }
);
  final ToggleButton strikeButton=(ToggleButton)findViewById(R.id.strike);
  strikeButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(strikeButton,"String_Node_Str");
    }
  }
);
  final ToggleButton bquoteButton=(ToggleButton)findViewById(R.id.bquote);
  bquoteButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      formatBtnClick(bquoteButton,"String_Node_Str");
    }
  }
);
  final Button moreButton=(Button)findViewById(R.id.more);
  moreButton.setOnClickListener(new Button.OnClickListener(){
    public void onClick(    View v){
      WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
      selectionEnd=contentText.getSelectionEnd();
      Editable str=contentText.getText();
      str.insert(selectionEnd,"String_Node_Str");
    }
  }
);
}