CreatePostActivity

public class CreatePostActivity extends AppCompatActivity implements FormatManager.IconUpdateListener

Creates screen the user can use to create a new Post

Fields

content

ListenableEditText content

Field the user uses to type the body of their Post

formatManager

FormatManager formatManager

Handles markup of the body text

networkLabel

TextView networkLabel

Displays the Network the user’s Post will be added to

progressBar

ProgressBar progressBar

Displays progress as the post is being sent over the network

Methods

onCreate

protected void onCreate(Bundle savedInstanceState)

Create the screen from R.layout.activity_create_post, fill CreatePostActivity.networkLabel with a description of the Network from API.Get.network(RequestQueue,long,Response.Listener), setup CreatePostActivity.formatManager, and link a listener to the submission button that sends the Post using API.Post.post(RequestQueue,Post,SharedPreferences,Response.Listener)

Parameters:

onCreateOptionsMenu

public boolean onCreateOptionsMenu(Menu menu)

Populate the options menu with controls to make text bold, italic, or a link

Parameters:
  • menu – Menu to populate with options
Returns:

Always returns true

onOptionsItemSelected

public boolean onOptionsItemSelected(MenuItem item)

This function handles what happens when our format toggle buttons are clicked. We want to update the content formatting when this happens as well with Spannables. Check out https://stackoverflow.com/questions/10828182/spannablestringbuilder-to-create-string-with-multiple-fonts-text-sizes-etc-examp for more info.

Parameters:
  • item – the MenuItem that was tapped.

onStop

public void onStop()

This ensures that we are canceling all network requests if the user is leaving this activity. We use a RequestFilter that accepts all requests (meaning it cancels all requests)

updateIconToggles

public void updateIconToggles(SparseBooleanArray formTogState, SparseArray<int[]> toggleIcons)

This fancy function uses our SparseArray’s to concisely iterate over our toggle icons and update their colors - white if untoggled, black if toggled.