gt:         if (providers != null) {
context: package org.wordpress.android.ui.posts;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.Fragment;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.location.Address;
  import android.location.Location;
  import android.location.LocationManager;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.Html;
  import android.text.TextUtils;
  import android.text.TextWatcher;
  import android.text.format.DateFormat;
  import android.text.format.DateUtils;
  import android.view.KeyEvent;
  import android.view.LayoutInflater;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewStub;
  import android.view.animation.Animation;
  import android.view.animation.AnimationUtils;
  import android.view.inputmethod.EditorInfo;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.TimePicker;
  import android.widget.Toast;
  
  import com.google.gson.Gson;
  import com.google.gson.reflect.TypeToken;
  
  import org.apache.commons.lang.StringEscapeUtils;
  import org.json.JSONArray;
  import org.wordpress.android.R;
  import org.wordpress.android.WordPress;
  import org.wordpress.android.models.Post;
  import org.wordpress.android.models.PostLocation;
  import org.wordpress.android.models.PostStatus;
  import org.wordpress.android.ui.RequestCodes;
  import org.wordpress.android.util.AppLog;
  import org.wordpress.android.util.AppLog.T;
  import org.wordpress.android.util.EditTextUtils;
  import org.wordpress.android.util.GeocoderUtils;
  import org.wordpress.android.util.JSONUtils;
  import org.wordpress.android.util.helpers.LocationHelper;
  import org.xmlrpc.android.ApiHelper;
  
  import java.lang.reflect.Type;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  
  public class EditPostSettingsFragment extends Fragment
          implements View.OnClickListener, TextView.OnEditorActionListener {
      private static final int ACTIVITY_REQUEST_CODE_SELECT_CATEGORIES = 5;
  
      private static final String CATEGORY_PREFIX_TAG = "category-";
  
      private Post mPost;
  
      private Spinner mStatusSpinner, mPostFormatSpinner;
      private EditText mPasswordEditText, mTagsEditText, mExcerptEditText;
      private TextView mPubDateText;
      private ViewGroup mSectionCategories;
  
      private ArrayList<String> mCategories;
  
      private PostLocation mPostLocation;
      private LocationHelper mLocationHelper;
  
      private int mYear, mMonth, mDay, mHour, mMinute;
      private long mCustomPubDate = 0;
      private boolean mIsCustomPubDate;
  
      private String[] mPostFormats;
      private String[] mPostFormatTitles;
  
      private static enum LocationStatus {NONE, FOUND, NOT_FOUND, SEARCHING}
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          mPost = ((EditPostActivity) getActivity()).getPost();
          ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.edit_post_settings_fragment, container, false);
  
          if (rootView == null || mPost == null) {
              return null;
          }
  
          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);
          mCategories = new ArrayList<String>();
  
          mExcerptEditText = (EditText) rootView.findViewById(R.id.postExcerpt);
          mPasswordEditText = (EditText) rootView.findViewById(R.id.post_password);
          mPubDateText = (TextView) rootView.findViewById(R.id.pubDate);
          mPubDateText.setOnClickListener(this);
          mStatusSpinner = (Spinner) rootView.findViewById(R.id.status);
          mStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                  updatePostSettingsAndSaveButton();
              }
  
              @Override
              public void onNothingSelected(AdapterView<?> parent) {
  
              }
          });
          mTagsEditText = (EditText) rootView.findViewById(R.id.tags);
          mSectionCategories = ((ViewGroup) rootView.findViewById(R.id.sectionCategories));
  
          if (mPost.isPage()) { // remove post specific views
              mExcerptEditText.setVisibility(View.GONE);
              (rootView.findViewById(R.id.sectionTags)).setVisibility(View.GONE);
              (rootView.findViewById(R.id.sectionCategories)).setVisibility(View.GONE);
              (rootView.findViewById(R.id.postFormatLabel)).setVisibility(View.GONE);
              (rootView.findViewById(R.id.postFormat)).setVisibility(View.GONE);
          } else {
              mPostFormatTitles = getResources().getStringArray(R.array.post_formats_array);
              mPostFormats =
                      new String[]{"aside", "audio", "chat", "gallery", "image", "link", "quote", "standard", "status",
                                   "video"};
              if (WordPress.getCurrentBlog().getPostFormats().equals("")) {
                  new ApiHelper.GetPostFormatsTask().execute(WordPress.getCurrentBlog());
              } else {
                  try {
                      Gson gson = new Gson();
                      Type type = new TypeToken<Map<String, String>>() {}.getType();
                      Map<String, String> jsonPostFormats = gson.fromJson(WordPress.getCurrentBlog().getPostFormats(),
                              type);
                      mPostFormats = new String[jsonPostFormats.size()];
                      mPostFormatTitles = new String[jsonPostFormats.size()];
                      int i = 0;
                      for (Map.Entry<String, String> entry : jsonPostFormats.entrySet()) {
                          String key = entry.getKey();
                          String val = entry.getValue();
                          mPostFormats[i] = key;
                          mPostFormatTitles[i] = StringEscapeUtils.unescapeHtml(val);
                          i++;
                      }
                  } catch (RuntimeException e) {
                      AppLog.e(T.POSTS, e);
                  }
              }
              mPostFormatSpinner = (Spinner) rootView.findViewById(R.id.postFormat);
              ArrayAdapter<String> pfAdapter = new ArrayAdapter<>(getActivity(), R.layout.simple_spinner_item,
                      mPostFormatTitles);
              pfAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              mPostFormatSpinner.setAdapter(pfAdapter);
              String activePostFormat = "standard";
  
              if (!TextUtils.isEmpty(mPost.getPostFormat())) {
                  activePostFormat = mPost.getPostFormat();
              }
  
              for (int i = 0; i < mPostFormats.length; i++) {
                  if (mPostFormats[i].equals(activePostFormat))
                      mPostFormatSpinner.setSelection(i);
              }
  
              mPostFormatSpinner.setOnTouchListener(
                      new View.OnTouchListener() {
                          @Override
                          public boolean onTouch(View view, MotionEvent motionEvent) {
                              return false;
                          }
                      }
              );
          }
  
          initSettingsFields();
          populateSelectedCategories();
          initLocation(rootView);
  
          return rootView;
      }
  
      private void initSettingsFields() {
          mExcerptEditText.setText(mPost.getPostExcerpt());
  
          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) };
  
          ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, items);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          mStatusSpinner.setAdapter(adapter);
          mStatusSpinner.setOnTouchListener(
                  new View.OnTouchListener() {
                      @Override
                      public boolean onTouch(View view, MotionEvent motionEvent) {
                          return false;
                      }
                  }
          );
  
          long pubDate = mPost.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(getActivity(), pubDate,
                          flags);
                  mPubDateText.setText(formattedDate);
              } catch (RuntimeException e) {
                  AppLog.e(T.POSTS, e);
              }
          }
  
          if (!TextUtils.isEmpty(mPost.getPassword())) {
              mPasswordEditText.setText(mPost.getPassword());
          }
  
          switch (mPost.getStatusEnum()) {
              case PUBLISHED:
              case SCHEDULED:
              case UNKNOWN:
                  mStatusSpinner.setSelection(0, true);
                  break;
              case DRAFT:
                  mStatusSpinner.setSelection(1, true);
                  break;
              case PENDING:
                  mStatusSpinner.setSelection(2, true);
                  break;
              case PRIVATE:
                  mStatusSpinner.setSelection(3, true);
                  break;
          }
  
          if (!mPost.isPage()) {
              if (mPost.getJSONCategories() != null) {
                  mCategories = JSONUtils.fromJSONArrayToStringList(mPost.getJSONCategories());
              }
          }
          String tags = mPost.getKeywords();
          if (!tags.equals("")) {
              mTagsEditText.setText(tags);
          }
      }
  
      private String getPostStatusForSpinnerPosition(int position) {
          switch (position) {
              case 0:
                  return PostStatus.toString(PostStatus.PUBLISHED);
              case 1:
                  return PostStatus.toString(PostStatus.DRAFT);
              case 2:
                  return PostStatus.toString(PostStatus.PENDING);
              case 3:
                  return PostStatus.toString(PostStatus.PRIVATE);
              default:
                  return PostStatus.toString(PostStatus.UNKNOWN);
          }
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (data != null || ((requestCode == RequestCodes.TAKE_PHOTO ||
                  requestCode == RequestCodes.TAKE_VIDEO))) {
              Bundle extras;
  
              switch (requestCode) {
                  case ACTIVITY_REQUEST_CODE_SELECT_CATEGORIES:
                      extras = data.getExtras();
                      if (extras != null && extras.containsKey("selectedCategories")) {
                          mCategories = (ArrayList<String>) extras.getSerializable("selectedCategories");
                          populateSelectedCategories();
                      }
                      break;
              }
          }
      }
  
      @Override
      public void onClick(View v) {
          int id = v.getId();
          if (id == R.id.pubDate) {
              showPostDateSelectionDialog();
          } else if (id == R.id.selectCategories) {
              Bundle bundle = new Bundle();
              bundle.putInt("id", WordPress.getCurrentBlog().getLocalTableBlogId());
              if (mCategories.size() > 0) {
                  bundle.putSerializable("categories", new HashSet<String>(mCategories));
              }
              Intent categoriesIntent = new Intent(getActivity(), SelectCategoriesActivity.class);
              categoriesIntent.putExtras(bundle);
              startActivityForResult(categoriesIntent, ACTIVITY_REQUEST_CODE_SELECT_CATEGORIES);
          } else if (id == R.id.categoryButton) {
              onCategoryButtonClick(v);
          } else if (id == R.id.locationText) {
              viewLocation();
          } else if (id == R.id.updateLocation) {
              showLocationSearch();
          } else if (id == R.id.removeLocation) {
              removeLocation();
              showLocationAdd();
          } else if (id == R.id.addLocation) {
              showLocationSearch();
          } else if (id == R.id.searchLocation) {
              searchLocation();
          }
      }
  
      @Override
      public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
          boolean handled = false;
          int id = view.getId();
          if (id == R.id.searchLocationText && actionId == EditorInfo.IME_ACTION_SEARCH) {
              searchLocation();
              handled = true;
          }
          return handled;
      }
  
      private void showPostDateSelectionDialog() {
          final DatePicker datePicker = new DatePicker(getActivity());
          datePicker.init(mYear, mMonth, mDay, null);
          datePicker.setCalendarViewShown(false);
  
          new AlertDialog.Builder(getActivity())
                  .setTitle(R.string.select_date)
                  .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          mYear = datePicker.getYear();
                          mMonth = datePicker.getMonth();
                          mDay = datePicker.getDayOfMonth();
                          showPostTimeSelectionDialog();
                      }
                  })
                  .setNeutralButton(getResources().getText(R.string.immediately),
                          new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialogInterface,
                                                  int i) {
                                  mIsCustomPubDate = true;
                                  mPubDateText.setText(R.string.immediately);
                                  updatePostSettingsAndSaveButton();
                              }
                          })
                  .setNegativeButton(android.R.string.cancel,
                          new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog,
                                                  int which) {
                              }
                          }
                  ).setView(datePicker).show();
  
      }
  
      private void showPostTimeSelectionDialog() {
          final TimePicker timePicker = new TimePicker(getActivity());
          timePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));
          timePicker.setCurrentHour(mHour);
          timePicker.setCurrentMinute(mMinute);
  
          new AlertDialog.Builder(getActivity())
                  .setTitle(R.string.select_time)
                  .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          mHour = timePicker.getCurrentHour();
                          mMinute = timePicker.getCurrentMinute();
  
                          Date d = new Date(mYear - 1900, mMonth, mDay, mHour, mMinute);
                          long timestamp = d.getTime();
  
                          try {
                              int flags = 0;
                              flags |= DateUtils.FORMAT_SHOW_DATE;
                              flags |= DateUtils.FORMAT_ABBREV_MONTH;
                              flags |= DateUtils.FORMAT_SHOW_YEAR;
                              flags |= DateUtils.FORMAT_SHOW_TIME;
                              String formattedDate = DateUtils.formatDateTime(getActivity(), timestamp, flags);
                              mCustomPubDate = timestamp;
                              mPubDateText.setText(formattedDate);
                              mIsCustomPubDate = true;
  
                              updatePostSettingsAndSaveButton();
                          } catch (RuntimeException e) {
                              AppLog.e(T.POSTS, e);
                          }
                      }
                  })
                  .setNegativeButton(android.R.string.cancel,
                          new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog,
                                                  int which) {
                              }
                          }).setView(timePicker).show();
      }
  
      /**
       * Updates post object with content of this fragment
       */
      public void updatePostSettings() {
          if (!isAdded() || mPost == null) {
              return;
          }
  
          String password = EditTextUtils.getText(mPasswordEditText);
          String pubDate = EditTextUtils.getText(mPubDateText);
          String excerpt = EditTextUtils.getText(mExcerptEditText);
  
          long pubDateTimestamp = 0;
          if (mIsCustomPubDate && pubDate.equals(getText(R.string.immediately)) && !mPost.isLocalDraft()) {
              Date d = new Date();
              pubDateTimestamp = d.getTime();
          } else if (!pubDate.equals(getText(R.string.immediately))) {
              if (mIsCustomPubDate)
                  pubDateTimestamp = mCustomPubDate;
              else if (mPost.getDate_created_gmt() > 0)
                  pubDateTimestamp = mPost.getDate_created_gmt();
          } else if (pubDate.equals(getText(R.string.immediately)) && mPost.isLocalDraft()) {
              mPost.setDate_created_gmt(0);
              mPost.setDateCreated(0);
          }
  
          String tags = "", postFormat = "";
          if (!mPost.isPage()) {
              tags = EditTextUtils.getText(mTagsEditText);
  
              // post format
              if (mPostFormats != null && mPostFormatSpinner != null &&
                  mPostFormatSpinner.getSelectedItemPosition() < mPostFormats.length) {
                  postFormat = mPostFormats[mPostFormatSpinner.getSelectedItemPosition()];
              }
          }
  
          String status;
          if (mStatusSpinner != null) {
              status = getPostStatusForSpinnerPosition(mStatusSpinner.getSelectedItemPosition());
          } else {
              status = mPost.getPostStatus();
          }
  
          // We want to flag this post as having changed statuses from draft to published so that we
          // properly track stats we care about for when users first publish posts.
          if (!mPost.isLocalDraft() && mPost.getPostStatus().equals(PostStatus.toString(PostStatus.DRAFT))
                  && status.equals(PostStatus.toString(PostStatus.PUBLISHED))) {
              mPost.setChangedFromDraftToPublished(true);
          }
  
          if (mPost.supportsLocation()) {
              mPost.setLocation(mPostLocation);
          }
  
          mPost.setPostExcerpt(excerpt);
          mPost.setDate_created_gmt(pubDateTimestamp);
          mPost.setJSONCategories(new JSONArray(mCategories));
          mPost.setKeywords(tags);
          mPost.setPostStatus(status);
          mPost.setPassword(password);
          mPost.setPostFormat(postFormat);
      }
  
      /*
       * Saves settings to post object and updates save button text in the ActionBar
       */
      private void updatePostSettingsAndSaveButton() {
          if (isAdded()) {
              updatePostSettings();
              getActivity().invalidateOptionsMenu();
          }
      }
  
      /**
       * Location methods
       */
  
      /*
       * retrieves and displays the friendly address for a lat/long location
       */
      private class GetAddressTask extends AsyncTask<Double, Void, Address> {
          double latitude;
          double longitude;
  
          @Override
          protected void onPreExecute() {
              setLocationStatus(LocationStatus.SEARCHING);
              showLocationView();
          }
  
          @Override
          protected Address doInBackground(Double... args) {
              // args will be the latitude, longitude to look up
              latitude = args[0];
              longitude = args[1];
  
              return GeocoderUtils.getAddressFromCoords(getActivity(), latitude, longitude);
          }
  
          protected void onPostExecute(Address address) {
              setLocationStatus(LocationStatus.FOUND);
              if (address == null) {
                  // show lat/long when Geocoder fails (ugly, but better than not showing anything
                  // or showing an error since the location has been assigned to the post already)
                  updateLocationText(Double.toString(latitude) + ", " + Double.toString(longitude));
              } else {
                  String locationName = GeocoderUtils.getLocationNameFromAddress(address);
                  updateLocationText(locationName);
              }
          }
      }
  
      private class GetCoordsTask extends AsyncTask<String, Void, Address> {
          @Override
          protected void onPreExecute() {
              setLocationStatus(LocationStatus.SEARCHING);
              showLocationView();
          }
  
          @Override
          protected Address doInBackground(String... args) {
              String locationName = args[0];
  
              return GeocoderUtils.getAddressFromLocationName(getActivity(), locationName);
          }
  
          @Override
          protected void onPostExecute(Address address) {
              setLocationStatus(LocationStatus.FOUND);
              showLocationView();
  
              if (address != null) {
                  double[] coordinates = GeocoderUtils.getCoordsFromAddress(address);
                  setLocation(coordinates[0], coordinates[1]);
  
                  String locationName = GeocoderUtils.getLocationNameFromAddress(address);
                  updateLocationText(locationName);
              } else {
                  showLocationNotAvailableError();
                  showLocationSearch();
              }
          }
      }
  
      private LocationHelper.LocationResult locationResult = new LocationHelper.LocationResult() {
          @Override
          public void gotLocation(final Location location) {
              if (getActivity() == null)
                  return;
              // note that location will be null when requesting location fails
              getActivity().runOnUiThread(new Runnable() {
                  public void run() {
                      setLocation(location);
                  }
              });
          }
      };
  
      private View mLocationAddSection;
      private View mLocationSearchSection;
      private View mLocationViewSection;
      private TextView mLocationText;
      private EditText mLocationEditText;
      private Button mButtonSearchLocation;
  
      private TextWatcher mLocationEditTextWatcher = new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
  
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) { }
  
          @Override
          public void afterTextChanged(Editable s) {
              String buttonText;
              if (s.length() > 0) {
                  buttonText = getResources().getString(R.string.search_location);
              } else {
                  buttonText = getResources().getString(R.string.search_current_location);
              }
              mButtonSearchLocation.setText(buttonText);
          }
      };
  
      /*
       * called when activity is created to initialize the location provider, show views related
       * to location if enabled for this blog, and retrieve the current location if necessary
       */
      private void initLocation(ViewGroup rootView) {
          // show the location views if a provider was found and this is a post on a blog that has location enabled
          if (hasLocationProvider() && mPost.supportsLocation()) {
              View locationRootView = ((ViewStub) rootView.findViewById(R.id.stub_post_location_settings)).inflate();
  
              TextView locationLabel = ((TextView) locationRootView.findViewById(R.id.locationLabel));
              locationLabel.setText(getResources().getString(R.string.location).toUpperCase());
  
              mLocationText = (TextView) locationRootView.findViewById(R.id.locationText);
              mLocationText.setOnClickListener(this);
  
              mLocationAddSection = locationRootView.findViewById(R.id.sectionLocationAdd);
              mLocationSearchSection = locationRootView.findViewById(R.id.sectionLocationSearch);
              mLocationViewSection = locationRootView.findViewById(R.id.sectionLocationView);
  
              Button addLocation = (Button) locationRootView.findViewById(R.id.addLocation);
              addLocation.setOnClickListener(this);
  
              mButtonSearchLocation = (Button) locationRootView.findViewById(R.id.searchLocation);
              mButtonSearchLocation.setOnClickListener(this);
  
              mLocationEditText = (EditText) locationRootView.findViewById(R.id.searchLocationText);
              mLocationEditText.setOnEditorActionListener(this);
              mLocationEditText.addTextChangedListener(mLocationEditTextWatcher);
  
              Button updateLocation = (Button) locationRootView.findViewById(R.id.updateLocation);
              Button removeLocation = (Button) locationRootView.findViewById(R.id.removeLocation);
              updateLocation.setOnClickListener(this);
              removeLocation.setOnClickListener(this);
  
              // if this post has location attached to it, look up the location address
              if (mPost.hasLocation()) {
                  showLocationView();
  
                  PostLocation location = mPost.getLocation();
                  setLocation(location.getLatitude(), location.getLongitude());
              } else {
                  showLocationAdd();
              }
          }
      }
  
      private boolean hasLocationProvider() {
          if (!isAdded()) {
              return false;
          }
          boolean hasLocationProvider = false;
          LocationManager locationManager = (LocationManager) getActivity().getSystemService(Activity.LOCATION_SERVICE);
          List<String> providers = locationManager.getProviders(true);
  