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 category (collection of articles). 21 */ 22 public class NewsCategory { 23 // how many articles? 24 final int ARTICLES_PER_CATEGORY = 20; 25 26 // array of our articles 27 NewsArticle[] mArticles; 28 29 /** 30 * Create a news category. 31 * 32 * The articles are dynamically generated with fun and random nonsense. 33 */ NewsCategory()34 public NewsCategory() { 35 NonsenseGenerator ngen = new NonsenseGenerator(); 36 mArticles = new NewsArticle[ARTICLES_PER_CATEGORY]; 37 int i; 38 for (i = 0; i < mArticles.length; i++) { 39 mArticles[i] = new NewsArticle(ngen); 40 } 41 } 42 43 /** Returns how many articles exist in this category. */ getArticleCount()44 public int getArticleCount() { 45 return mArticles.length; 46 } 47 48 /** Gets a particular article by index. */ getArticle(int index)49 public NewsArticle getArticle(int index) { 50 return mArticles[index]; 51 } 52 } 53