32 |
33 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/NewsCategory.java:
--------------------------------------------------------------------------------
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 | */
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. */
44 | public int getArticleCount() {
45 | return mArticles.length;
46 | }
47 |
48 | /** Gets a particular article by index. */
49 | public NewsArticle getArticle(int index) {
50 | return mArticles[index];
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/newsreader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
21 |
22 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/NewsSource.java:
--------------------------------------------------------------------------------
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. */
35 | public static NewsSource getInstance() {
36 | if (instance == null) {
37 | instance = new NewsSource();
38 | }
39 | return instance;
40 | }
41 |
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. */
51 | public String[] getCategories() {
52 | return CATEGORIES;
53 | }
54 |
55 | /** Returns a category by index. */
56 | public NewsCategory getCategory(int categoryIndex) {
57 | return mCategory[categoryIndex];
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
22 |
23 |
28 |
29 |
30 |
34 |
35 |
40 |
41 |
46 |
47 |
48 |
49 |
54 |
55 |
--------------------------------------------------------------------------------
/newsreader/build/intermediates/manifests/full/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
21 |
22 |
25 |
26 |
31 |
32 |
38 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/NewsArticle.java:
--------------------------------------------------------------------------------
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("
");
44 | sb.append("
" + mHeadline + "
");
45 | int i;
46 | for (i = 0; i < PARAGRAPHS_PER_ARTICLE; i++) {
47 | sb.append("
");
48 | }
49 |
50 | sb.append("");
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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/constraint_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
24 |
25 |
31 |
32 |
38 |
39 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
22 |
23 |
28 |
29 |
30 |
34 |
35 |
40 |
41 |
46 |
47 |
48 |
49 |
55 |
56 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/newsreader/build/generated/source/r/debug/com/example/android/newsreader/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.android.newsreader;
9 |
10 | public final class R {
11 | public static final class bool {
12 | public static final int has_two_panes=0x7f010000;
13 | }
14 | public static final class drawable {
15 | public static final int button_bg=0x7f020000;
16 | public static final int button_normal=0x7f020001;
17 | public static final int button_pressed=0x7f020002;
18 | public static final int icon=0x7f020003;
19 | public static final int logo=0x7f020004;
20 | public static final int tab_bg=0x7f020005;
21 | public static final int tab_bg_normal=0x7f020006;
22 | public static final int tab_bg_selected=0x7f020007;
23 | }
24 | public static final class id {
25 | public static final int article=0x7f030000;
26 | public static final int categorybutton=0x7f030001;
27 | public static final int headlines=0x7f030002;
28 | public static final int imageView1=0x7f030003;
29 | public static final int linearLayout1=0x7f030004;
30 | public static final int view1=0x7f030005;
31 | }
32 | public static final class layout {
33 | public static final int actionbar_list_item=0x7f040000;
34 | public static final int headline_item=0x7f040001;
35 | public static final int main_layout=0x7f040002;
36 | public static final int onepane=0x7f040003;
37 | public static final int onepane_with_bar=0x7f040004;
38 | public static final int twopanes=0x7f040005;
39 | public static final int twopanes_narrow=0x7f040006;
40 | }
41 | public static final class string {
42 | public static final int app_name=0x7f050000;
43 | public static final int hello=0x7f050001;
44 | }
45 | public static final class style {
46 | public static final int CategoryButtonStyle=0x7f060000;
47 | public static final int CustomActionBarTabStyle=0x7f060001;
48 | public static final int CustomActionBarTabTextStyle=0x7f060002;
49 | public static final int NewsReaderStyle=0x7f060003;
50 | public static final int NewsReaderStyle_NoActionBar=0x7f060004;
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout-port/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
22 |
23 |
28 |
29 |
30 |
34 |
35 |
40 |
41 |
46 |
47 |
48 |
49 |
55 |
56 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/newsreader/src/main/res/layout/onepane_with_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
22 |
26 |
33 |
37 |
43 |
44 |
45 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/import-summary.txt:
--------------------------------------------------------------------------------
1 | ECLIPSE ANDROID PROJECT IMPORT SUMMARY
2 | ======================================
3 |
4 | Ignored Files:
5 | --------------
6 | The following files were *not* copied into the new Gradle project; you
7 | should evaluate whether these are still needed in your project and if
8 | so manually move them:
9 |
10 | * _index.html
11 | * proguard.cfg
12 |
13 | Replaced Jars with Dependencies:
14 | --------------------------------
15 | The importer recognized the following .jar files as third party
16 | libraries and replaced them with Gradle dependencies instead. This has
17 | the advantage that more explicit version information is known, and the
18 | libraries can be updated automatically. However, it is possible that
19 | the .jar file in your project was of an older version than the
20 | dependency we picked, which could render the project not compileable.
21 | You can disable the jar replacement in the import wizard and try again:
22 |
23 | android-support-v4.jar => com.android.support:support-v4:18.+
24 |
25 | Moved Files:
26 | ------------
27 | Android Gradle projects use a different directory structure than ADT
28 | Eclipse projects. Here's how the projects were restructured:
29 |
30 | * AndroidManifest.xml => newsreader\src\main\AndroidManifest.xml
31 | * res\ => newsreader\src\main\res\
32 | * src\ => newsreader\src\main\java\
33 |
34 | Missing Android Support Repository:
35 | -----------------------------------
36 | Some useful libraries, such as the Android Support Library, are
37 | installed from a special Maven repository, which should be installed
38 | via the SDK manager.
39 |
40 | It looks like this library is missing from your SDK installation at:
41 | null
42 |
43 | To install it, open the SDK manager, and in the Extras category,
44 | select "Android Support Repository". You may also want to install the
45 | "Google Repository" if you want to use libraries like Google Play
46 | Services.
47 |
48 | Next Steps:
49 | -----------
50 | You can now build the project. The Gradle project needs network
51 | connectivity to download dependencies.
52 |
53 | Bugs:
54 | -----
55 | If for some reason your project does not build, and you determine that
56 | it is due to a bug or limitation of the Eclipse to Gradle importer,
57 | please file a bug at http://b.android.com with category
58 | Component-Tools.
59 |
60 | (This import summary is for your information only, and can be deleted
61 | after import once you are satisfied with the results.)
62 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/ArticleFragment.java:
--------------------------------------------------------------------------------
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 | import android.os.Bundle;
20 | import android.support.v4.app.Fragment;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.webkit.WebView;
25 |
26 | /**
27 | * Fragment that displays a news article.
28 | */
29 | public class ArticleFragment extends Fragment {
30 | // The webview where we display the article (our only view)
31 | WebView mWebView;
32 |
33 | // The article we are to display
34 | NewsArticle mNewsArticle = null;
35 |
36 | // Parameterless constructor is needed by framework
37 | public ArticleFragment() {
38 | super();
39 | }
40 |
41 | /**
42 | * Sets up the UI. It consists if a single WebView.
43 | */
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
46 | mWebView = new WebView(getActivity());
47 | loadWebView();
48 | return mWebView;
49 | }
50 |
51 | /**
52 | * Displays a particular article.
53 | *
54 | * @param article the article to display
55 | */
56 | public void displayArticle(NewsArticle article) {
57 | mNewsArticle = article;
58 | loadWebView();
59 | }
60 |
61 | /**
62 | * Loads article data into the webview.
63 | *
64 | * This method is called internally to update the webview's contents to the appropriate
65 | * article's text.
66 | */
67 | void loadWebView() {
68 | if (mWebView != null) {
69 | mWebView.loadData(mNewsArticle == null ? "" : mNewsArticle.getBody(), "text/html",
70 | "utf-8");
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/ArticleActivity.java:
--------------------------------------------------------------------------------
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 | import android.content.res.Configuration;
20 | import android.os.Bundle;
21 | import android.support.v4.app.FragmentActivity;
22 |
23 | /**
24 | * Activity that displays a particular news article onscreen.
25 | *
26 | * This activity is started only when the screen is not large enough for a two-pane layout, in
27 | * which case this separate activity is shown in order to display the news article. This activity
28 | * kills itself if the display is reconfigured into a shape that allows a two-pane layout, since
29 | * in that case the news article will be displayed by the {@link NewsReaderActivity} and this
30 | * Activity therefore becomes unnecessary.
31 | */
32 | public class ArticleActivity extends FragmentActivity {
33 | // The news category index and the article index for the article we are to display
34 | int mCatIndex, mArtIndex;
35 |
36 | /**
37 | * Sets up the activity.
38 | *
39 | * Setting up the activity means reading the category/article index from the Intent that
40 | * fired this Activity and loading it onto the UI. We also detect if there has been a
41 | * screen configuration change (in particular, a rotation) that makes this activity
42 | * unnecessary, in which case we do the honorable thing and get out of the way.
43 | */
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | mCatIndex = getIntent().getExtras().getInt("catIndex", 0);
48 | mArtIndex = getIntent().getExtras().getInt("artIndex", 0);
49 |
50 | // If we are in two-pane layout mode, this activity is no longer necessary
51 | if (getResources().getBoolean(R.bool.has_two_panes)) {
52 | finish();
53 | return;
54 | }
55 |
56 | // Place an ArticleFragment as our content pane
57 | ArticleFragment f = new ArticleFragment();
58 | getSupportFragmentManager().beginTransaction().add(android.R.id.content, f).commit();
59 |
60 | // Display the correct news article on the fragment
61 | NewsArticle article = NewsSource.getInstance().getCategory(mCatIndex).getArticle(mArtIndex);
62 | f.displayArticle(article);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/CompatActionBarNavHandler.java:
--------------------------------------------------------------------------------
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 | import android.app.ActionBar.OnNavigationListener;
20 | import android.app.ActionBar.Tab;
21 | import android.app.ActionBar.TabListener;
22 | import android.app.FragmentTransaction;
23 |
24 | /**
25 | * Adapter for action bar navigation events.
26 | *
27 | * This class implements an adapter that facilitates handling of action bar navigation events.
28 | * An instance of this class must be installed as a TabListener or OnNavigationListener on an
29 | * Action Bar, and it will relay the navigation events to a configured listener
30 | * (a {@link CompatActionBarNavListener}).
31 | *
32 | * This class should only be instanced and used on Android platforms that support the Action Bar,
33 | * that is, SDK level 11 and above.
34 | */
35 | public class CompatActionBarNavHandler implements TabListener, OnNavigationListener {
36 | // The listener that we notify of navigation events
37 | CompatActionBarNavListener mNavListener;
38 |
39 | /**
40 | * Constructs an instance with the given listener.
41 | *
42 | * @param listener the listener to notify when a navigation event occurs.
43 | */
44 | public CompatActionBarNavHandler(CompatActionBarNavListener listener) {
45 | mNavListener = listener;
46 | }
47 |
48 | /**
49 | * Called by framework when a tab is selected.
50 | *
51 | * This will cause a navigation event to be delivered to the configured listener.
52 | */
53 | @Override
54 | public void onTabSelected(Tab tab, FragmentTransaction ft) {
55 | // TODO Auto-generated method stub
56 | mNavListener.onCategorySelected(tab.getPosition());
57 | }
58 |
59 | /**
60 | * Called by framework when a item on the navigation menu is selected.
61 | *
62 | * This will cause a navigation event to be delivered to the configured listener.
63 | */
64 | @Override
65 | public boolean onNavigationItemSelected(int itemPosition, long itemId) {
66 | mNavListener.onCategorySelected(itemPosition);
67 | return true;
68 | }
69 |
70 |
71 | /**
72 | * Called by framework when a tab is re-selected. That is, it was already selected and is
73 | * tapped on again. This is not used in our app.
74 | */
75 | @Override
76 | public void onTabReselected(Tab tab, FragmentTransaction ft) {
77 | // we don't care
78 | }
79 |
80 | /**
81 | * Called by framework when a tab is unselected. Not used in our app.
82 | */
83 | @Override
84 | public void onTabUnselected(Tab tab, FragmentTransaction ft) {
85 | // we don't care
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/HeadlinesFragment.java:
--------------------------------------------------------------------------------
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 | import android.os.Bundle;
20 | import android.support.v4.app.ListFragment;
21 | import android.view.View;
22 | import android.widget.AdapterView;
23 | import android.widget.AdapterView.OnItemClickListener;
24 | import android.widget.ArrayAdapter;
25 | import android.widget.ListView;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | /**
31 | * Fragment that displays the news headlines for a particular news category.
32 | *
33 | * This Fragment displays a list with the news headlines for a particular news category.
34 | * When an item is selected, it notifies the configured listener that a headlines was selected.
35 | */
36 | public class HeadlinesFragment extends ListFragment implements OnItemClickListener {
37 | // The list of headlines that we are displaying
38 | List mHeadlinesList = new ArrayList();
39 |
40 | // The list adapter for the list we are displaying
41 | ArrayAdapter mListAdapter;
42 |
43 | // The listener we are to notify when a headline is selected
44 | OnHeadlineSelectedListener mHeadlineSelectedListener = null;
45 |
46 | /**
47 | * Represents a listener that will be notified of headline selections.
48 | */
49 | public interface OnHeadlineSelectedListener {
50 | /**
51 | * Called when a given headline is selected.
52 | * @param index the index of the selected headline.
53 | */
54 | public void onHeadlineSelected(int index);
55 | }
56 |
57 | /**
58 | * Default constructor required by framework.
59 | */
60 | public HeadlinesFragment() {
61 | super();
62 | }
63 |
64 | @Override
65 | public void onStart() {
66 | super.onStart();
67 | setListAdapter(mListAdapter);
68 | getListView().setOnItemClickListener(this);
69 | loadCategory(0);
70 | }
71 |
72 | @Override
73 | public void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 | mListAdapter = new ArrayAdapter(getActivity(), R.layout.headline_item,
76 | mHeadlinesList);
77 | }
78 |
79 | /**
80 | * Sets the listener that should be notified of headline selection events.
81 | * @param listener the listener to notify.
82 | */
83 | public void setOnHeadlineSelectedListener(OnHeadlineSelectedListener listener) {
84 | mHeadlineSelectedListener = listener;
85 | }
86 |
87 | /**
88 | * Load and display the headlines for the given news category.
89 | * @param categoryIndex the index of the news category to display.
90 | */
91 | public void loadCategory(int categoryIndex) {
92 | mHeadlinesList.clear();
93 | int i;
94 | NewsCategory cat = NewsSource.getInstance().getCategory(categoryIndex);
95 | for (i = 0; i < cat.getArticleCount(); i++) {
96 | mHeadlinesList.add(cat.getArticle(i).getHeadline());
97 | }
98 | mListAdapter.notifyDataSetChanged();
99 | }
100 |
101 | /**
102 | * Handles a click on a headline.
103 | *
104 | * This causes the configured listener to be notified that a headline was selected.
105 | */
106 | @Override
107 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
108 | if (null != mHeadlineSelectedListener) {
109 | mHeadlineSelectedListener.onHeadlineSelected(position);
110 | }
111 | }
112 |
113 | /** Sets choice mode for the list
114 | *
115 | * @param selectable whether list is to be selectable.
116 | */
117 | public void setSelectable(boolean selectable) {
118 | if (selectable) {
119 | getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
120 | }
121 | else {
122 | getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/newsreader/build/outputs/logs/manifest-merger-debug-report.txt:
--------------------------------------------------------------------------------
1 | -- Merging decision tree log ---
2 | manifest
3 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
4 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
5 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
6 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
7 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
8 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
9 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:1-39:12
10 | package
11 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:18:7-47
12 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
13 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
14 | android:versionName
15 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:20:7-32
16 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
17 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
18 | xmlns:android
19 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:17:11-69
20 | android:versionCode
21 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:19:7-30
22 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
23 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
24 | uses-sdk
25 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:5-73
26 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:5-73
27 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:5-73
28 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:5-73
29 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:5-73
30 | android:targetSdkVersion
31 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:41-70
32 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
33 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
34 | android:minSdkVersion
35 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:21:15-40
36 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
37 | INJECTED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml
38 | supports-screens
39 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:22:5-26:40
40 | android:largeScreens
41 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:25:9-36
42 | android:smallScreens
43 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:23:9-36
44 | android:normalScreens
45 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:24:9-37
46 | android:xlargeScreens
47 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:26:9-37
48 | application
49 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:28:5-38:19
50 | android:label
51 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:28:48-80
52 | android:icon
53 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:28:18-47
54 | android:theme
55 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:29:48-86
56 | android:logo
57 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:29:18-47
58 | activity#com.example.android.newsreader.NewsReaderActivity
59 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:30:9-35:20
60 | android:label
61 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:30:54-86
62 | android:name
63 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:30:19-53
64 | intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER
65 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:31:13-34:29
66 | action#android.intent.action.MAIN
67 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:32:17-69
68 | android:name
69 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:32:25-66
70 | category#android.intent.category.LAUNCHER
71 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:33:17-77
72 | android:name
73 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:33:27-74
74 | activity#com.example.android.newsreader.ArticleActivity
75 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:36:9-37:72
76 | android:theme
77 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:37:19-69
78 | android:name
79 | ADDED from C:\Work\workspace\AndroidStudioProjects\ScreenAdaptDemo\newsreader\src\main\AndroidManifest.xml:36:19-50
80 |
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/NonsenseGenerator.java:
--------------------------------------------------------------------------------
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 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Random;
21 |
22 | /** Generator of random news. More fun than "lorem ipsum", isn't it?
23 | *
24 | * This generator can construct headlines and news articles by randomly composing sentences.
25 | * Any resemblance to actual events (or, actually, any resemblance to anything that makes sense)
26 | * is merely coincidental!
27 | */
28 | public class NonsenseGenerator {
29 | Random mRandom;
30 |
31 | static final String[] THINGS = { "bottle", "bowl", "brick", "building",
32 | "bunny", "cake", "car", "cat", "cup", "desk", "dog", "duck",
33 | "elephant", "engineer", "fork", "glass", "griffon", "hat", "key", "knife", "lawyer",
34 | "llama", "manual", "meat", "monitor", "mouse", "tangerine", "paper", "pear", "pen",
35 | "pencil", "phone", "physicist", "planet", "potato", "road", "salad", "shoe", "slipper",
36 | "soup", "spoon", "star", "steak", "table", "terminal", "treehouse", "truck",
37 | "watermelon", "window" };
38 |
39 | static final String[] ADJECTIVES = { "red", "green", "yellow", "gray", "solid", "fierce",
40 | "friendly", "cowardly", "convenient", "foreign", "national", "tall",
41 | "short", "metallic", "golden", "silver", "sweet", "nationwide", "competitive",
42 | "stable", "municipal", "famous" };
43 |
44 | static final String[] VERBS_PAST = { "accused", "threatened", "warned", "spoke to",
45 | "has met with",
46 | "was seen in the company of", "advanced towards", "collapsed on",
47 | "signed a partnership with", "was converted into", "became", "was authorized to sell",
48 | "sold", "bought", "rented", "allegedly spoke to", "leased", "is now investing on",
49 | "is expected to buy", "is expected to sell", "was reported to have met with",
50 | "will work together with", "plans to cease fire against", "started a war with",
51 | "signed a truce with", "is now managing", "is investigating" };
52 |
53 | static final String[] VERBS_PRESENT = { "accuses", "threatens", "warns", "speaks to",
54 | "meets with",
55 | "seen with", "advances towards", "collapses on",
56 | "signs partnership with", "converts into", "becomes", "is authorized to sell",
57 | "sells", "buys", "rents", "allegedly speaks to", "leases", "invests on",
58 | "expected to buy", "expected to sell", "reported to have met with",
59 | "works together with", "plans cease fire against", "starts war with",
60 | "signs truce with", "now manages" };
61 |
62 | public NonsenseGenerator() {
63 | mRandom = new Random();
64 | }
65 |
66 | /** Produces something that reads like a headline. */
67 | public String makeHeadline() {
68 | return makeSentence(true);
69 | }
70 |
71 | /** Produces a sentence.
72 | *
73 | * @param isHeadline whether the sentence should look like a headline or not.
74 | * @return the generated sentence.
75 | */
76 | public String makeSentence(boolean isHeadline) {
77 | List words = new ArrayList();
78 | generateSentence(words, isHeadline);
79 | words.set(0, String.valueOf(Character.toUpperCase(words.get(0).charAt(0))) +
80 | words.get(0).substring(1));
81 | return joinWords(words);
82 | }
83 |
84 | /** Produces news article text.
85 | *
86 | * @param numSentences how many sentences the text is to contain.
87 | * @return the generated text.
88 | */
89 | public String makeText(int numSentences) {
90 | StringBuilder sb = new StringBuilder();
91 | while (numSentences-- > 0) {
92 | sb.append(makeSentence(false) + ".");
93 | if (numSentences > 0) {
94 | sb.append(" ");
95 | }
96 | }
97 | return sb.toString();
98 | }
99 |
100 | /** Generates a sentence.
101 | *
102 | * @param words the list of words to which the sentence will be appended.
103 | * @param isHeadline whether the sentence must look like a headline or not.
104 | */
105 | private void generateSentence(List words, boolean isHeadline) {
106 | if (!isHeadline && mRandom.nextInt(4) == 0)
107 | generateTimeClause(words, isHeadline);
108 | generateAgent(words, isHeadline);
109 | generatePredicate(words, isHeadline);
110 | }
111 |
112 | private void generateTimeClause(List words, boolean isHeadline) {
113 | if (mRandom.nextInt(2) == 0) {
114 | words.add(pickOneOf("today", "yesterday", "this afternoon", "this morning",
115 | "last evening"));
116 | }
117 | else {
118 | words.add(pickOneOf("this", "last"));
119 | words.add(pickOneOf("Monday", "Tuesday", "Wednesday", "Thursday"));
120 | words.add(pickOneOf("morning", "afternoon", "evening"));
121 | }
122 | }
123 |
124 | private void generateAgent(List words, boolean isHeadline) {
125 | if (!isHeadline) {
126 | words.add(pickOneOf("a", "the"));
127 | }
128 | if (mRandom.nextInt(3) != 0) {
129 | words.add(pickOneOf(ADJECTIVES));
130 | }
131 | words.add(pickOneOf(THINGS));
132 | }
133 |
134 | private void generatePredicate(List words, boolean isHeadline) {
135 | words.add(pickOneOf(isHeadline ? VERBS_PRESENT : VERBS_PAST));
136 | if (!isHeadline)
137 | words.add(pickOneOf("a", "the"));
138 | if (mRandom.nextInt(3) != 0) {
139 | words.add(pickOneOf(ADJECTIVES));
140 | }
141 | words.add(pickOneOf(THINGS));
142 |
143 | if (mRandom.nextInt(3) == 0) {
144 | words.add(isHeadline ? pickOneOf(", claims", ", says") :
145 | pickOneOf(", claimed", ", said", ", reported"));
146 | if (!isHeadline)
147 | words.add(pickOneOf("a", "the"));
148 | if (mRandom.nextInt(3) != 0) {
149 | words.add(pickOneOf(ADJECTIVES));
150 | }
151 | words.add(pickOneOf(THINGS));
152 | }
153 | }
154 |
155 | private String pickOneOf(String ... options) {
156 | return options[mRandom.nextInt(options.length)];
157 | }
158 |
159 | private static String joinWords(List words) {
160 | int i;
161 | if (words.size() == 0) {
162 | return "";
163 | }
164 | StringBuilder sb = new StringBuilder();
165 | sb.append(words.get(0));
166 | for (i = 1; i < words.size(); i++) {
167 | if (!words.get(i).startsWith(",")) {
168 | sb.append(" ");
169 | }
170 | sb.append(words.get(i));
171 | }
172 | return sb.toString();
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/newsreader/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties:
--------------------------------------------------------------------------------
1 | #Sat Dec 09 18:09:34 CST 2017
2 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\tab_bg_selected.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_tab_bg_selected.9.png.flat
3 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\button_pressed.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_button_pressed.9.png.flat
4 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\button_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_button_normal.9.png.flat
5 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-ldpi\\button_pressed.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-ldpi_button_pressed.9.png.flat
6 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\button_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_button_normal.9.png.flat
7 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\button_pressed.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_button_pressed.9.png.flat
8 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-ldpi\\icon.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-ldpi_icon.png.flat
9 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\icon.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_icon.png.flat
10 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\onepane.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_onepane.xml.flat
11 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-ldpi\\tab_bg_selected.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-ldpi_tab_bg_selected.9.png.flat
12 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\onepane_with_bar.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_onepane_with_bar.xml.flat
13 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\tab_bg_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_tab_bg_normal.9.png.flat
14 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable\\tab_bg.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable_tab_bg.xml.flat
15 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\tab_bg_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_tab_bg_normal.9.png.flat
16 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\twopanes.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_twopanes.xml.flat
17 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\tab_bg_selected.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_tab_bg_selected.9.png.flat
18 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\icon.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_icon.png.flat
19 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\tab_bg_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_tab_bg_normal.9.png.flat
20 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\button_pressed.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_button_pressed.9.png.flat
21 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable\\button_bg.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable_button_bg.xml.flat
22 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\icon.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_icon.png.flat
23 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\logo.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_logo.png.flat
24 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-ldpi\\logo.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-ldpi_logo.png.flat
25 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-xhdpi\\button_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi_button_normal.9.png.flat
26 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\actionbar_list_item.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_actionbar_list_item.xml.flat
27 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\twopanes_narrow.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_twopanes_narrow.xml.flat
28 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-mdpi\\logo.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-mdpi_logo.png.flat
29 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-ldpi\\tab_bg_normal.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-ldpi_tab_bg_normal.9.png.flat
30 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\tab_bg_selected.9.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_tab_bg_selected.9.png.flat
31 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\layout\\headline_item.xml=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\layout_headline_item.xml.flat
32 | C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\src\\main\\res\\drawable-hdpi\\logo.png=C\:\\Work\\workspace\\AndroidStudioProjects\\ScreenAdaptDemo\\newsreader\\build\\intermediates\\res\\merged\\debug\\drawable-hdpi_logo.png.flat
33 |
--------------------------------------------------------------------------------
/newsreader/build/intermediates/incremental/mergeDebugResources/merger.xml:
--------------------------------------------------------------------------------
1 |
2 | @layout/onepane_with_barfalseHello World, NewsReaderActivity!NewsReader@layout/twopanestrue@layout/onepanefalse@layout/onepanefalse@layout/twopanestrue@layout/twopanes_narrowtrue
--------------------------------------------------------------------------------
/newsreader/src/main/java/com/example/android/newsreader/NewsReaderActivity.java:
--------------------------------------------------------------------------------
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 | import android.app.AlertDialog;
20 | import android.content.DialogInterface;
21 | import android.content.Intent;
22 | import android.os.Build;
23 | import android.os.Bundle;
24 | import android.support.v4.app.FragmentActivity;
25 | import android.view.View;
26 | import android.view.View.OnClickListener;
27 | import android.widget.ArrayAdapter;
28 | import android.widget.Button;
29 | import android.widget.SpinnerAdapter;
30 |
31 | /**
32 | * Main activity: shows headlines list and articles, if layout permits.
33 | *
34 | * This is the main activity of the application. It can have several different layouts depending
35 | * on the SDK version, screen size and orientation. The configurations are divided in two large
36 | * groups: single-pane layouts and dual-pane layouts.
37 | *
38 | * In single-pane mode, this activity shows a list of headlines using a {@link HeadlinesFragment}.
39 | * When the user clicks on a headline, a separate activity (a {@link ArticleActivity}) is launched
40 | * to show the news article.
41 | *
42 | * In dual-pane mode, this activity shows a {@HeadlinesFragment} on the left side and an
43 | * {@ArticleFragment} on the right side. When the user selects a headline on the left, the
44 | * corresponding article is shown on the right.
45 | *
46 | * If an Action Bar is available (large enough screen and SDK version 11 or up), navigation
47 | * controls are shown in the Action Bar (whether to show tabs or a list depends on the layout).
48 | * If an Action Bar is not available, a regular image and button are shown in the top area of
49 | * the screen, emulating an Action Bar.
50 | */
51 | public class NewsReaderActivity extends FragmentActivity
52 | implements HeadlinesFragment.OnHeadlineSelectedListener,
53 | CompatActionBarNavListener,
54 | OnClickListener {
55 |
56 | // Whether or not we are in dual-pane mode
57 | boolean mIsDualPane = false;
58 |
59 | // The fragment where the headlines are displayed
60 | HeadlinesFragment mHeadlinesFragment;
61 |
62 | // The fragment where the article is displayed (null if absent)
63 | ArticleFragment mArticleFragment;
64 |
65 | // The news category and article index currently being displayed
66 | int mCatIndex = 0;
67 | int mArtIndex = 0;
68 | NewsCategory mCurrentCat;
69 |
70 | // List of category titles
71 | final String CATEGORIES[] = { "Top Stories", "Politics", "Economy", "Technology" };
72 |
73 | @Override
74 | public void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | setContentView(R.layout.main_layout);
77 |
78 | // find our fragments
79 | mHeadlinesFragment = (HeadlinesFragment) getSupportFragmentManager().findFragmentById(
80 | R.id.headlines);
81 | mArticleFragment = (ArticleFragment) getSupportFragmentManager().findFragmentById(
82 | R.id.article);
83 |
84 | // Determine whether we are in single-pane or dual-pane mode by testing the visibility
85 | // of the article view.
86 | View articleView = findViewById(R.id.article);
87 | mIsDualPane = articleView != null && articleView.getVisibility() == View.VISIBLE;
88 |
89 | // Register ourselves as the listener for the headlines fragment events.
90 | mHeadlinesFragment.setOnHeadlineSelectedListener(this);
91 |
92 | // Set up the Action Bar (or not, if one is not available)
93 | int catIndex = savedInstanceState == null ? 0 : savedInstanceState.getInt("catIndex", 0);
94 | setUpActionBar(mIsDualPane, catIndex);
95 |
96 | // Set up headlines fragment
97 | mHeadlinesFragment.setSelectable(mIsDualPane);
98 | restoreSelection(savedInstanceState);
99 |
100 | // Set up the category button (shown if an Action Bar is not available)
101 | Button catButton = (Button) findViewById(R.id.categorybutton);
102 | if (catButton != null) {
103 | catButton.setOnClickListener(this);
104 | }
105 | }
106 |
107 | /** Restore category/article selection from saved state. */
108 | void restoreSelection(Bundle savedInstanceState) {
109 | if (savedInstanceState != null) {
110 | setNewsCategory(savedInstanceState.getInt("catIndex", 0));
111 | if (mIsDualPane) {
112 | int artIndex = savedInstanceState.getInt("artIndex", 0);
113 | mHeadlinesFragment.setSelection(artIndex);
114 | onHeadlineSelected(artIndex);
115 | }
116 | }
117 | }
118 |
119 | @Override
120 | public void onRestoreInstanceState(Bundle savedInstanceState) {
121 | restoreSelection(savedInstanceState);
122 | }
123 |
124 | /** Sets up Action Bar (if present).
125 | *
126 | * @param showTabs whether to show tabs (if false, will show list).
127 | * @param selTab the selected tab or list item.
128 | */
129 | public void setUpActionBar(boolean showTabs, int selTab) {
130 | if (Build.VERSION.SDK_INT < 11) {
131 | // No action bar for you!
132 | // But do not despair. In this case the layout includes a bar across the
133 | // top that looks and feels like an action bar, but is made up of regular views.
134 | return;
135 | }
136 |
137 | android.app.ActionBar actionBar = getActionBar();
138 | actionBar.setDisplayShowTitleEnabled(false);
139 |
140 | // Set up a CompatActionBarNavHandler to deliver us the Action Bar nagivation events
141 | CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this);
142 | if (showTabs) {
143 | actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
144 | int i;
145 | for (i = 0; i < CATEGORIES.length; i++) {
146 | actionBar.addTab(actionBar.newTab().setText(CATEGORIES[i]).setTabListener(handler));
147 | }
148 | actionBar.setSelectedNavigationItem(selTab);
149 | }
150 | else {
151 | actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST);
152 | SpinnerAdapter adap = new ArrayAdapter(this, R.layout.actionbar_list_item,
153 | CATEGORIES);
154 | actionBar.setListNavigationCallbacks(adap, handler);
155 | }
156 |
157 | // Show logo instead of icon+title.
158 | actionBar.setDisplayUseLogoEnabled(true);
159 | }
160 |
161 | @Override
162 | public void onStart() {
163 | super.onStart();
164 | setNewsCategory(0);
165 | }
166 |
167 | /** Sets the displayed news category.
168 | *
169 | * This causes the headlines fragment to be repopulated with the appropriate headlines.
170 | */
171 | void setNewsCategory(int categoryIndex) {
172 | mCatIndex = categoryIndex;
173 | mCurrentCat = NewsSource.getInstance().getCategory(categoryIndex);
174 | mHeadlinesFragment.loadCategory(categoryIndex);
175 |
176 | // If we are displaying the article on the right, we have to update that too
177 | if (mIsDualPane) {
178 | mArticleFragment.displayArticle(mCurrentCat.getArticle(0));
179 | }
180 |
181 | // If we are displaying a "category" button (on the ActionBar-less UI), we have to update
182 | // its text to reflect the current category.
183 | Button catButton = (Button) findViewById(R.id.categorybutton);
184 | if (catButton != null) {
185 | catButton.setText(CATEGORIES[mCatIndex]);
186 | }
187 | }
188 |
189 | /** Called when a headline is selected.
190 | *
191 | * This is called by the HeadlinesFragment (via its listener interface) to notify us that a
192 | * headline was selected in the Action Bar. The way we react depends on whether we are in
193 | * single or dual-pane mode. In single-pane mode, we launch a new activity to display the
194 | * selected article; in dual-pane mode we simply display it on the article fragment.
195 | *
196 | * @param index the index of the selected headline.
197 | */
198 | @Override
199 | public void onHeadlineSelected(int index) {
200 | mArtIndex = index;
201 | if (mIsDualPane) {
202 | // display it on the article fragment
203 | mArticleFragment.displayArticle(mCurrentCat.getArticle(index));
204 | }
205 | else {
206 | // use separate activity
207 | Intent i = new Intent(this, ArticleActivity.class);
208 | i.putExtra("catIndex", mCatIndex);
209 | i.putExtra("artIndex", index);
210 | startActivity(i);
211 | }
212 | }
213 |
214 | /** Called when a news category is selected.
215 | *
216 | * This is called by our CompatActionBarNavHandler in response to the user selecting a
217 | * news category in the Action Bar. We react by loading and displaying the headlines for
218 | * that category.
219 | *
220 | * @param catIndex the index of the selected news category.
221 | */
222 | @Override
223 | public void onCategorySelected(int catIndex) {
224 | setNewsCategory(catIndex);
225 | }
226 |
227 | /** Save instance state. Saves current category/article index. */
228 | @Override
229 | protected void onSaveInstanceState(Bundle outState) {
230 | outState.putInt("catIndex", mCatIndex);
231 | outState.putInt("artIndex", mArtIndex);
232 | super.onSaveInstanceState(outState);
233 | }
234 |
235 | /** Called when news category button is clicked.
236 | *
237 | * This is the button that we display on UIs that don't have an action bar. This button
238 | * calls up a list of news categories and switches to the given category.
239 | */
240 | @Override
241 | public void onClick(View v) {
242 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
243 | builder.setTitle("Select a Category");
244 | builder.setItems(CATEGORIES, new DialogInterface.OnClickListener() {
245 | @Override
246 | public void onClick(DialogInterface dialog, int which) {
247 | setNewsCategory(which);
248 | }
249 | });
250 | AlertDialog d = builder.create();
251 | d.show();
252 | }
253 | }
254 |
--------------------------------------------------------------------------------