1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.newsreader; 18 19 /** 20 * A news article. 21 * 22 * An article consists of a headline and a body. In this example app, article text is dynamically 23 * generated nonsense. 24 */ 25 public class NewsArticle { 26 // How many sentences in each paragraph? 27 final int SENTENCES_PER_PARAGRAPH = 20; 28 29 // How many paragraphs in each article? 30 final int PARAGRAPHS_PER_ARTICLE = 5; 31 32 // Headline and body 33 String mHeadline, mBody; 34 35 /** 36 * Create a news article with randomly generated text. 37 * @param ngen the nonsense generator to use. 38 */ 39 public NewsArticle(NonsenseGenerator ngen) { 40 mHeadline = ngen.makeHeadline(); 41 42 StringBuilder sb = new StringBuilder(); 43 sb.append("<html><body>"); 44 sb.append("<h1>" + mHeadline + "</h1>"); 45 int i; 46 for (i = 0; i < PARAGRAPHS_PER_ARTICLE; i++) { 47 sb.append("<p>").append(ngen.makeText(SENTENCES_PER_PARAGRAPH)).append("</p>"); 48 } 49 50 sb.append("</body></html>"); 51 mBody = sb.toString(); 52 } 53 54 /** Returns the headline. */ 55 public String getHeadline() { 56 return mHeadline; 57 } 58 59 /** Returns the article body (HTML)*/ 60 public String getBody() { 61 return mBody; 62 } 63 } 64