[npr-android-app] r140 committed - - Ensures the banner only shows up every two mins (or time specified i...

2 views
Skip to first unread message

npr-and...@googlecode.com

unread,
Oct 25, 2011, 11:28:00 AM10/25/11
to npr-a...@googlegroups.com
Revision: 140
Author: justinfriberg
Date: Tue Oct 25 08:27:38 2011
Log: - Ensures the banner only shows up every two mins (or time
specified in the conf file)
- For programs - only show story teasers
- For topics - only show full stories
- Minor chrome updates
- Right margin on list item story title 6dp
- Min list item height to size w/ image
http://code.google.com/p/npr-android-app/source/detail?r=140

Added:
/branches/release_2.1/Npr/src/org/npr/api/IPhoneTimersConfProvider.java
Modified:
/branches/release_2.1/Npr/AndroidManifest.xml
/branches/release_2.1/Npr/res/drawable-hdpi/contracted_player_bg.png
/branches/release_2.1/Npr/res/drawable-hdpi/sponsorship_gradient_slice.png
/branches/release_2.1/Npr/res/layout/news_item.xml
/branches/release_2.1/Npr/res/values/styles.xml
/branches/release_2.1/Npr/src/org/npr/android/news/AllProgramsActivity.java
/branches/release_2.1/Npr/src/org/npr/android/news/BannerView.java
/branches/release_2.1/Npr/src/org/npr/android/news/Constants.java
/branches/release_2.1/Npr/src/org/npr/android/news/NewsListActivity.java
/branches/release_2.1/Npr/src/org/npr/android/news/NewsStoryActivity.java
/branches/release_2.1/Npr/src/org/npr/android/news/NewsTopicActivity.java
/branches/release_2.1/Npr/src/org/npr/android/news/PlaylistView.java
/branches/release_2.1/Npr/src/org/npr/api/ApiConstants.java

=======================================
--- /dev/null
+++ /branches/release_2.1/Npr/src/org/npr/api/IPhoneTimersConfProvider.java
Tue Oct 25 08:27:38 2011
@@ -0,0 +1,132 @@
+package org.npr.api;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.net.Uri;
+import android.provider.BaseColumns;
+import android.util.Log;
+import org.npr.android.util.ArrayUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+public class IPhoneTimersConfProvider extends ContentProvider {
+
+ public static final Uri CONTENT_URL =
+ Uri.parse("content://org.npr.apr.IPhoneTimersConf");
+ private static final String CONTENT_TYPE =
+ "vnd.android.cursor.dir/vnd.npr.timers";
+ private static final String CONF_URL =
+ "http://www.npr.org/services/apps/iphone_timers.conf";
+
+ private static final String LOG_TAG =
IPhoneTimersConfProvider.class.getName();
+ private static List<String[]> data;
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projections, String selection,
+ String[] selectionArgs, String sortOrder) {
+ if (selection != null && !selection.equals(Items.NAME + " = ?")) {
+ return null;
+ }
+
+ if (data == null) {
+ data = new ArrayList<String[]>();
+ if (!load()) {
+ return null;
+ }
+ }
+
+ MatrixCursor cursor = new MatrixCursor(Items.COLUMNS);
+ for (String[] row : data) {
+ if (selection == null) {
+ cursor.addRow(row);
+ } else if (row[6].equals(selectionArgs[0])) {
+ cursor.addRow(row);
+ }
+ }
+
+ return cursor;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return CONTENT_TYPE;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues contentValues) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int delete(Uri uri, String s, String[] strings) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues contentValues, String s,
String[] strings) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Parses the CSV data and loads the data member table.
+ * <p/>
+ * TODO: Use a real CSV parser or even better a CSV database
implementation.
+ * e.g. http://sourceforge.net/projects/javacsv/develop
+ * or import into SQLite in-memory?
+ *
+ * @return true on success; false if the stream is null or there is an
+ * exception (which is logged)
+ */
+ private boolean load() {
+ try {
+ InputStream stream = HttpHelper.download(CONF_URL);
+ if (stream == null) {
+ return false;
+ }
+
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(stream),
+ 8192
+ );
+ String buffer;
+ while ((buffer = reader.readLine()) != null) {
+ String[] rowData = buffer.split(",");
+ if (rowData.length > 0) {
+ if (rowData.length < Items.COLUMNS.length) {
+ rowData = ArrayUtils.copyOf(rowData,
Items.COLUMNS.length);
+ }
+ data.add(rowData);
+ }
+ }
+ reader.close();
+ stream.close();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "", e);
+ return false;
+ }
+ return true;
+ }
+
+ public static class Items implements BaseColumns {
+ public static final String NAME = "name";
+ public static final String TIMER_LENGTH = "timer_length";
+
+ public static final String[] COLUMNS = {NAME, TIMER_LENGTH};
+
+ // This class cannot be instantiated
+ private Items() {
+ }
+ }
+}
=======================================
--- /branches/release_2.1/Npr/AndroidManifest.xml Sat Sep 10 15:07:21 2011
+++ /branches/release_2.1/Npr/AndroidManifest.xml Tue Oct 25 08:27:38 2011
@@ -69,6 +69,9 @@
android:name="org.npr.api.IPhoneNewsAppProgramsConfProvider"
android:authorities="org.npr.apr.IPhoneNewsAppProgramsConf"/>
<provider
+ android:name="org.npr.api.IPhoneTimersConfProvider"
+ android:authorities="org.npr.apr.IPhoneTimersConf"/>
+ <provider
android:name="org.npr.android.util.FavoriteStationsProvider"
android:authorities="org.npr.android.util.FavoriteStations"/>

=======================================
--- /branches/release_2.1/Npr/res/drawable-hdpi/contracted_player_bg.png
Sun May 22 12:54:47 2011
+++ /branches/release_2.1/Npr/res/drawable-hdpi/contracted_player_bg.png
Tue Oct 25 08:27:38 2011
Binary file, no diff available.
=======================================
---
/branches/release_2.1/Npr/res/drawable-hdpi/sponsorship_gradient_slice.png
Sat Sep 10 13:37:45 2011
+++
/branches/release_2.1/Npr/res/drawable-hdpi/sponsorship_gradient_slice.png
Tue Oct 25 08:27:38 2011
Binary file, no diff available.
=======================================
--- /branches/release_2.1/Npr/res/layout/news_item.xml Wed Jun 22 17:39:11
2011
+++ /branches/release_2.1/Npr/res/layout/news_item.xml Tue Oct 25 08:27:38
2011
@@ -5,7 +5,7 @@
android:gravity="center_vertical"
android:padding="3dp"
android:orientation="horizontal"
- android:minHeight="?android:attr/listPreferredItemHeight">
+ android:minHeight="81dp">
<ImageView
android:id="@+id/NewsItemIcon"
android:layout_width="35dp"
@@ -25,6 +25,7 @@
android:id="@+id/NewsItemNameText"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
+ android:layout_marginRight="6dp"
android:gravity="center_vertical"
android:textAppearance="@style/NewsItemTitle"/>
</LinearLayout>
=======================================
--- /branches/release_2.1/Npr/res/values/styles.xml Sun Sep 11 10:17:14 2011
+++ /branches/release_2.1/Npr/res/values/styles.xml Tue Oct 25 08:27:38 2011
@@ -22,18 +22,18 @@
</style>

<style name="Banner">
- <item
name="android:background">@drawable/sponsorship_gradient_slice</item>
+ <item name="android:background">@color/black</item>
<item name="android:textAppearance">@style/BannerText</item>
</style>
<style name="ViewTitle">
<item name="android:background">@drawable/title_background</item>
<item name="android:gravity">center_vertical</item>
- <item name="android:layout_height">34dip</item>
+ <item name="android:layout_height">24dip</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:paddingLeft">8dip</item>
<item name="android:paddingRight">8dip</item>
- <item name="android:paddingTop">4dip</item>
- <item name="android:paddingBottom">2dip</item>
+ <item name="android:paddingTop">1dip</item>
+ <item name="android:paddingBottom">1dip</item>
</style>
<style name="ViewTitleText" parent="@android:style/TextAppearance">
<item name="android:textSize">14sp</item>
=======================================
---
/branches/release_2.1/Npr/src/org/npr/android/news/AllProgramsActivity.java
Sun Sep 11 10:17:14 2011
+++
/branches/release_2.1/Npr/src/org/npr/android/news/AllProgramsActivity.java
Tue Oct 25 08:27:38 2011
@@ -144,7 +144,7 @@
}
Intent i = new Intent(this, ProgramStoryListActivity.class);
i.putExtra(Constants.EXTRA_LIVE_STREAM_RSS_URL,
item.getLiveStreamUrl());
-
+ i.putExtra(Constants.EXTRA_TEASER_ONLY, true);

String grouping = getString(type);
String description = item.getTitle();
@@ -171,7 +171,6 @@
i.putExtra(Constants.EXTRA_ON_AIR, true);
}
}
-

i.putExtra(Constants.EXTRA_DESCRIPTION, description);
i.putExtra(Constants.EXTRA_GROUPING, grouping);
=======================================
--- /branches/release_2.1/Npr/src/org/npr/android/news/BannerView.java Sat
Sep 10 13:37:45 2011
+++ /branches/release_2.1/Npr/src/org/npr/android/news/BannerView.java Tue
Oct 25 08:27:38 2011
@@ -15,6 +15,7 @@
package org.npr.android.news;

import android.content.Context;
+import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Handler;
@@ -31,7 +32,7 @@
import android.webkit.WebView;
import android.widget.*;
import org.npr.android.util.DisplayUtils;
-
+import org.npr.api.IPhoneTimersConfProvider;

/**
* Encapsulates the logic and layout of the sponsorship banner
@@ -43,22 +44,25 @@
private static final int FRAME_DURATION = 50;
private static final float ANIMATION_DURATION = 500f;
private static final String LAYOUT =
- "<html>" +
- "<head>" +
- "<meta name=\"viewport\"
content=\"target-densitydpi=device-dpi, " +
- "width=device-width\" />" +
- "<style type=\"text/css\">" +
- "body
{padding:0;margin:0;text-align:center;background-color:#333;}" +
- "p {display:none;}" +
- "</style>" +
- "</head>" +
- "<body>" +
- "<script type=\"text/javascript\"" +
+ "<html>" +
+ "<head>" +
+ "<meta name=\"viewport\" content=\"target-densitydpi=device-dpi, "
+
+ "width=device-width\" />" +
+ "<style type=\"text/css\">" +
+ "body
{padding:0;margin:0;text-align:center;background-color:#333;}" +
+ "p {display:none;}" +
+ "</style>" +
+ "</head>" +
+ "<body>" +
+ "<script type=\"text/javascript\"" +
"src=\"http://ad.doubleclick.net/adj/n6735.NPR.MOBILE/android_npr;"
+
"sz=320x50;ord=%1$d?\">" +
- "</script>" +
- "</body>" +
- "</html>";
+ "</script>" +
+ "</body>" +
+ "</html>";
+
+ private long noBannerUntilSystemTime = 0;
+ private long noBannerTimeIncrement = 120000;

private ImageView animationView;
private int startY;
@@ -155,14 +159,13 @@
handler.removeMessages(MSG_SCROLL_IN);
handler.removeMessages(MSG_SCROLL_OUT);
}
-


/**
* Allows assignment of the play list view so that the
* banner can slide the player drawer down as it scrolls
* off screen.
- *
+ * <p/>
* This enables the drawing cache for the drawer view.
*
* @param playlistView The view to animate down.
@@ -175,6 +178,22 @@
}

void init() {
+ Cursor cursor =
context.getContentResolver().query(IPhoneTimersConfProvider.CONTENT_URL,
null, null, null, null);
+ while (cursor.moveToNext()) {
+ String id =
cursor.getString(cursor.getColumnIndex(IPhoneTimersConfProvider.Items.NAME));
+ if (id.equals("banners")) {
+ noBannerTimeIncrement =
cursor.getInt(cursor.getColumnIndex(IPhoneTimersConfProvider.Items.TIMER_LENGTH))
* 1000;
+ break;
+ }
+ }
+
+ // Don't shown until increment has elapsed
+ if (System.currentTimeMillis() < noBannerUntilSystemTime) {
+ setVisibility(View.GONE);
+ return;
+ }
+ noBannerUntilSystemTime = System.currentTimeMillis() +
noBannerTimeIncrement;
+
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay()
@@ -378,5 +397,4 @@
}
return bitmap;
}
-
-}
+}
=======================================
--- /branches/release_2.1/Npr/src/org/npr/android/news/Constants.java Sun
May 22 12:54:47 2011
+++ /branches/release_2.1/Npr/src/org/npr/android/news/Constants.java Tue
Oct 25 08:27:38 2011
@@ -34,7 +34,7 @@
"mode_for_station_list_activity";
public static final String EXTRA_ON_AIR = "program_is_on_air";
public static final String EXTRA_PODCAST_URL = "podcast_rss_feed_url";
-
+ public static final String EXTRA_TEASER_ONLY = "teaser_only";
private Constants() {
// no instantiation
}
=======================================
---
/branches/release_2.1/Npr/src/org/npr/android/news/NewsListActivity.java
Sun Sep 11 10:17:14 2011
+++
/branches/release_2.1/Npr/src/org/npr/android/news/NewsListActivity.java
Tue Oct 25 08:27:38 2011
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -73,12 +74,10 @@
public void handleMessage(Message msg) {
switch (msg.what) {
case ListItemGestureListener.MSG_LONG_PRESS: {
- lastLongPressPosition = msg.arg1;
-
- // Offset 1 for header
- int storyPosition = msg.arg1 - 1;
-
- Story longPressStory = listAdapter.getItem(storyPosition);
+
+ lastLongPressPosition = msg.arg1;
+
+ Story longPressStory = listAdapter.getItem(msg.arg1);
if (longPressStory != null && longPressStory.getPlayable() !=
null) {
PlaylistRepository playlistRepository =
new PlaylistRepository(getApplicationContext(),
@@ -90,7 +89,7 @@
if (playlistEntry == null) {
addAndPulseIcon(listView.getChildAt(msg.arg1 -
listView.getFirstVisiblePosition()));
- addStory(storyPosition, true);
+ addStory(msg.arg1, true);
} else {
PlaylistEntry activeEntry =
playlistRepository.getPlaylistItemFromId(getActiveId());
@@ -105,10 +104,8 @@
break;

case ListItemGestureListener.MSG_FLING: {
- // Offset 1 for header
- int storyPosition = msg.arg1 - 1;
-
- flungStory = listAdapter.getItem(storyPosition);
+
+ flungStory = listAdapter.getItem(msg.arg1);
if (flungStory != null && flungStory.getPlayable() != null) {
PlaylistRepository playlistRepository =
new PlaylistRepository(getApplicationContext(),
@@ -123,7 +120,7 @@
msg.arg2,
true
);
- addStory(storyPosition, false);
+ addStory(msg.arg1, false);
} else {
animateListItemFling(
listView.getChildAt(msg.arg1 -
@@ -261,6 +258,10 @@
listAdapter.getStoryIdList()
);
i.putExtra(Constants.EXTRA_STORY_ID, s.getId());
+ if (getIntent().hasExtra(Constants.EXTRA_TEASER_ONLY)) {
+ i.putExtra(Constants.EXTRA_TEASER_ONLY,
+ getIntent().getBooleanExtra(Constants.EXTRA_TEASER_ONLY,
false));
+ }
startActivityWithoutAnimation(i);
}
}
=======================================
---
/branches/release_2.1/Npr/src/org/npr/android/news/NewsStoryActivity.java
Wed Jun 15 13:39:57 2011
+++
/branches/release_2.1/Npr/src/org/npr/android/news/NewsStoryActivity.java
Tue Oct 25 08:27:38 2011
@@ -114,13 +114,13 @@
);
layout.setMargins(0, 0, 0, DisplayUtils.convertToDIP(this, 95));
((ViewGroup) findViewById(R.id.TitleContent)).addView(workspace,
layout);
-
+ boolean teaserOnly =
getIntent().getBooleanExtra(Constants.EXTRA_TEASER_ONLY, false);

for (int i = 0; i < storyIds.length; i++) {
String storyId = storyIds[i];
Story story = NewsListActivity.getStoryFromCache(storyId);
stories.add(story);
- layoutStory(story, i, storyIds.length);
+ layoutStory(story, i, storyIds.length, teaserOnly);
if (storyId.equals(currentStoryId)) {
trackerItem = new TrackerItem();
workspace.setCurrentScreen(i);
@@ -166,7 +166,7 @@
super.onStop();
}

- private void layoutStory(Story story, int position, int total) {
+ private void layoutStory(Story story, int position, int total, boolean
teaserOnly) {
if (position >= stories.size()) {
Log.e(LOG_TAG, "Attempt to get story view for position " + position +
" beyond loaded stories");
@@ -251,7 +251,7 @@

TextWithHtml text = story.getTextWithHtml();
String textHtml;
- if (text != null) {
+ if (!teaserOnly && text != null) {
StringBuilder sb = new StringBuilder();
for (String paragraph : text.getParagraphs()) {
sb.append("<p>").append(paragraph).append("</p>");
=======================================
---
/branches/release_2.1/Npr/src/org/npr/android/news/NewsTopicActivity.java
Sun May 22 12:54:47 2011
+++
/branches/release_2.1/Npr/src/org/npr/android/news/NewsTopicActivity.java
Tue Oct 25 08:27:38 2011
@@ -174,6 +174,7 @@
params.put(ApiConstants.PARAM_ID, topicId);
params.put(ApiConstants.PARAM_FIELDS, ApiConstants.STORY_FIELDS);
params.put(ApiConstants.PARAM_SORT, "assigned");
+ params.put(ApiConstants.PARAM_REQUIRED_ASSETS, "text");
String url =
ApiConstants.instance().createUrl(ApiConstants.STORY_PATH, params);

=======================================
--- /branches/release_2.1/Npr/src/org/npr/android/news/PlaylistView.java
Mon Aug 15 16:13:01 2011
+++ /branches/release_2.1/Npr/src/org/npr/android/news/PlaylistView.java
Tue Oct 25 08:27:38 2011
@@ -422,15 +422,15 @@
@Override
public void onReceive(Context context, Intent intent) {
int duration = intent.getIntExtra(PlaybackService.EXTRA_DURATION, 1);
- Log.d(LOG_TAG, "Playback update; duration = " + duration + "
millsecs");
// Drop out if no duration is given (flicker?)
if (duration == 1) {
+ Log.v(LOG_TAG, "Playback update; no duration dropout");
return;
}

int position = intent.getIntExtra(PlaybackService.EXTRA_POSITION, 0);
int downloaded =
intent.getIntExtra(PlaybackService.EXTRA_DOWNLOADED, 1);
- Log.d(LOG_TAG, "Playback update; position = " + position + "
millsecs; " +
+ Log.v(LOG_TAG, "Playback update; position = " + position + "
millsecs; " +
"downloaded = " + duration + " millsecs");
boolean isPlaying = intent.getBooleanExtra(PlaybackService
.EXTRA_IS_PLAYING, false);
=======================================
--- /branches/release_2.1/Npr/src/org/npr/api/ApiConstants.java Wed Jun 22
17:39:11 2011
+++ /branches/release_2.1/Npr/src/org/npr/api/ApiConstants.java Tue Oct 25
08:27:38 2011
@@ -46,6 +46,7 @@
public static final String PARAM_FIELDS = "fields";
public static final String PARAM_SORT = "sort";
public static final String PARAM_DATE = "date";
+ public static final String PARAM_REQUIRED_ASSETS = "requiredAssets";

public static final String STORY_FIELDS
= "titles,teasers,storyDate,byline,text,audio,textWithHtml,image,organization,parent";
private final String apiKey;

Reply all
Reply to author
Forward
0 new messages