diff options
Diffstat (limited to 'samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models')
6 files changed, 441 insertions, 0 deletions
diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Card.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Card.java new file mode 100644 index 000000000..ccaaf72df --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Card.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import android.content.Context; +import android.graphics.Color; +import android.util.Log; + +import com.google.gson.annotations.SerializedName; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * This is a generic example of a custom data object, containing info we might want to keep with + * each card on the home screen + */ +public class Card { + + @SerializedName("title") private String mTitle = ""; + @SerializedName("description") private String mDescription = ""; + @SerializedName("extraText") private String mExtraText = ""; + @SerializedName("imageUrl") private String mImageUrl; + @SerializedName("footerColor") private String mFooterColor = null; + @SerializedName("selectedColor") private String mSelectedColor = null; + @SerializedName("localImageResource") private String mLocalImageResource = null; + @SerializedName("footerIconLocalImageResource") private String mFooterResource = null; + @SerializedName("type") private Card.Type mType; + @SerializedName("id") private int mId; + @SerializedName("width") private int mWidth; + @SerializedName("height") private int mHeight; + + public String getTitle() { + return mTitle; + } + + public int getWidth() { + return mWidth; + } + + public int getHeight() { + return mHeight; + } + + public int getId() { + return mId; + } + + public Card.Type getType() { + return mType; + } + + public String getDescription() { + return mDescription; + } + + public String getExtraText() { + return mExtraText; + } + + public int getFooterColor() { + if (mFooterColor == null) return -1; + return Color.parseColor(mFooterColor); + } + + public int getSelectedColor() { + if (mSelectedColor == null) return -1; + return Color.parseColor(mSelectedColor); + } + + public String getImageUrl() { + return mImageUrl; + } + + public URI getImageURI() { + if (getImageUrl() == null) return null; + try { + return new URI(getImageUrl()); + } catch (URISyntaxException e) { + Log.d("URI exception: ", getImageUrl()); + return null; + } + } + + public int getLocalImageResourceId(Context context) { + return context.getResources().getIdentifier(getLocalImageResourceName(), "drawable", + context.getPackageName()); + } + + public String getLocalImageResourceName() { + return mLocalImageResource; + } + + public String getFooterLocalImageResourceName() { + return mFooterResource; + } + + public enum Type { + + MOVIE_COMPLETE, + MOVIE, + MOVIE_BASE, + ICON, + SQUARE_BIG, + SINGLE_LINE, + GAME, + SQUARE_SMALL, + DEFAULT, + SIDE_INFO, + SIDE_INFO_TEST_1, + TEXT, + CHARACTER, + GRID_SQUARE + + } + +} diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/CardRow.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/CardRow.java new file mode 100644 index 000000000..932b9b940 --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/CardRow.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + * This class represents a row of cards. In a real world application you might want to store more + * data than in this example. + */ +public class CardRow { + + // Used to determine whether the row shall use shadows when displaying its cards or not. + @SerializedName("shadow") private boolean mShadow = true; + @SerializedName("title") private String mTitle; + @SerializedName("cards") private List<Card> mCards; + + public String getTitle() { + return mTitle; + } + + public boolean useShadow() { + return mShadow; + } + + public List<Card> getCards() { + return mCards; + } + +} diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/DetailedCard.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/DetailedCard.java new file mode 100644 index 000000000..8727a4053 --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/DetailedCard.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import android.content.Context; +import android.support.v17.leanback.supportleanbackshowcase.models.Card; + +import com.google.gson.annotations.SerializedName; + +public class DetailedCard { + + @SerializedName("title") private String mTitle = ""; + @SerializedName("description") private String mDescription = ""; + @SerializedName("text") private String mText = ""; + @SerializedName("localImageResource") private String mLocalImageResource = null; + @SerializedName("price") private String mPrice = null; + @SerializedName("characters") private Card[] mCharacters = null; + @SerializedName("recommended") private Card[] mRecommended = null; + @SerializedName("year") private int mYear = 0; + + + public String getPrice() { + return mPrice; + } + + public int getYear() { + return mYear; + } + + public String getLocalImageResource() { + return mLocalImageResource; + } + + public String getText() { + return mText; + } + + public String getDescription() { + return mDescription; + } + + public String getTitle() { + return mTitle; + } + + public Card[] getCharacters() { + return mCharacters; + } + + public Card[] getRecommended() { + return mRecommended; + } + + public int getLocalImageResourceId(Context context) { + return context.getResources() + .getIdentifier(getLocalImageResource(), "drawable", context.getPackageName()); + } +} diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Movie.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Movie.java new file mode 100644 index 000000000..83912b3a0 --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Movie.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class Movie implements Serializable { + + private static final long serialVersionUID = 133742L; + + @SerializedName("title") + private String mTitle = ""; + @SerializedName("price_hd") + private String mPriceHd = "n/a"; + @SerializedName("price_sd") + private String mPriceSd = "n/a"; + @SerializedName("breadcrump") + private String mBreadcrump = ""; + + public String getTitle() { + return mTitle; + } + + public String getBreadcrump() { + return mBreadcrump; + } + + public String getPriceHd() { + return mPriceHd; + } + + public String getPriceSd() { + return mPriceSd; + } + +} diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Song.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Song.java new file mode 100644 index 000000000..89729be80 --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/Song.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import android.content.Context; +import android.support.v17.leanback.supportleanbackshowcase.R; +import android.support.v17.leanback.widget.Row; +import android.support.v17.leanback.widget.RowPresenter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.google.gson.annotations.SerializedName; + +public class Song extends Row { + + @SerializedName("title") private String mTitle = ""; + @SerializedName("description") private String mDescription = ""; + @SerializedName("text") private String mText = ""; + @SerializedName("image") private String mImage = null; + @SerializedName("file") private String mFile = null; + @SerializedName("duration") private String mDuration = null; + @SerializedName("number") private int mNumber = 0; + + + public String getDuration() { + return mDuration; + } + + public int getNumber() { + return mNumber; + } + + public String getText() { + return mText; + } + + public String getDescription() { + return mDescription; + } + + public String getTitle() { + return mTitle; + } + + public int getFileResource(Context context) { + return context.getResources() + .getIdentifier(mFile, "raw", context.getPackageName()); + } + + public int getImageResource(Context context) { + return context.getResources() + .getIdentifier(mImage, "drawable", context.getPackageName()); + } + + public interface OnSongRowClickListener { + + void onSongRowClicked(Song song); + + } + + public static class Presenter extends RowPresenter implements View.OnClickListener { + + private final Context mContext; + private OnSongRowClickListener mClickListener; + + + public Presenter(Context context) { + mContext = context; + setHeaderPresenter(null); + } + + public void setOnClickListener(OnSongRowClickListener listener) { + mClickListener = listener; + } + + @Override protected ViewHolder createRowViewHolder(ViewGroup parent) { + View view = LayoutInflater.from(mContext).inflate(R.layout.row_song, parent, false); + view.findViewById(R.id.rowContainer).setOnClickListener(this); + return new ViewHolder(view); + } + + @Override public boolean isUsingDefaultSelectEffect() { + return false; + } + + @Override protected void onBindRowViewHolder(ViewHolder vh, Object item) { + super.onBindRowViewHolder(vh, item); + Song song = (Song) item; + ((TextView) vh.view.findViewById(R.id.trackNumber)).setText("" + song.getNumber()); + ((TextView) vh.view.findViewById(R.id.trackDuration)).setText(song.getDuration()); + String text = song.getTitle() + " / " + song.getDescription(); + ((TextView) vh.view.findViewById(R.id.trackName)).setText(text); + vh.view.findViewById(R.id.rowContainer).setTag(item); + } + + @Override public void onClick(View v) { + if (mClickListener == null) return; + mClickListener.onSongRowClicked((Song) v.getTag()); + } + } +} diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/SongList.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/SongList.java new file mode 100644 index 000000000..034ae19b5 --- /dev/null +++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/models/SongList.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package android.support.v17.leanback.supportleanbackshowcase.models; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + */ +public class SongList { + + @SerializedName("songs") private List<Song> mSongs; + + public List<Song> getSongs() { + return mSongs; + } + +} |