Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created June 15, 2015 18:23
Show Gist options
  • Select an option

  • Save udacityandroid/47592c621d32450d7dbc to your computer and use it in GitHub Desktop.

Select an option

Save udacityandroid/47592c621d32450d7dbc to your computer and use it in GitHub Desktop.

Revisions

  1. udacityandroid created this gist Jun 15, 2015.
    59 changes: 59 additions & 0 deletions TextView.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    /**
    * Displays text to the user.
    */
    public class TextView extends View {

    // String value
    private String mText;

    // Text color of the text
    private int mTextColor;

    // Context of the app
    private Context mContext;

    /**
    * Constructs a new TextView with initial values for text and text color.
    */
    public TextView(Context context) {
    mText = "";
    mTextColor = 0;
    mContext = context;
    }

    /**
    * Sets the string value in the TextView.
    *
    * @param text is the updated string to be displayed.
    */
    public void setText(String text) {
    mText = text;
    }

    /**
    * Sets the text color of the TextView.
    *
    * @param color of text to be displayed.
    */
    public void setTextColor(int color) {
    mTextColor = color;
    }

    /**
    * Gets the string value in the TextView.
    *
    * @return current text in the TextView.
    */
    public String getText() {
    return mText;
    }

    /**
    * Gets the text color of the TextView.
    *
    * @return current text color.
    */
    public int getTextColor() {
    return mTextColor;
    }
    }