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  * Source of strange and wonderful news.
21  *
22  * This singleton functions as the repository for the news we display.
23  */
24 public class NewsSource {
25     // the instance
26     static NewsSource instance = null;
27 
28     // the category names
29     final String[] CATEGORIES = { "Top Stories", "US", "Politics", "Economy" };
30 
31     // category objects, representing each category
32     NewsCategory[] mCategory;
33 
34     /** Returns the singleton instance of this class. */
getInstance()35     public static NewsSource getInstance() {
36         if (instance == null) {
37             instance = new NewsSource();
38         }
39         return instance;
40     }
41 
NewsSource()42     public NewsSource() {
43         int i;
44         mCategory = new NewsCategory[CATEGORIES.length];
45         for (i = 0; i < CATEGORIES.length; i++) {
46             mCategory[i] = new NewsCategory();
47         }
48     }
49 
50     /** Returns the list of news categories. */
getCategories()51     public String[] getCategories() {
52         return CATEGORIES;
53     }
54 
55     /** Returns a category by index. */
getCategory(int categoryIndex)56     public NewsCategory getCategory(int categoryIndex) {
57         return mCategory[categoryIndex];
58     }
59 }
60