diff --git a/samples/SupportLeanbackDemos/AndroidManifest.xml b/samples/SupportLeanbackDemos/AndroidManifest.xml index 31e90ba1e..48d638d10 100644 --- a/samples/SupportLeanbackDemos/AndroidManifest.xml +++ b/samples/SupportLeanbackDemos/AndroidManifest.xml @@ -123,5 +123,13 @@ android:theme="@style/Theme.Example.Leanback.GuidedStep" android:exported="true" /> + + + + diff --git a/samples/SupportLeanbackDemos/generatev4.py b/samples/SupportLeanbackDemos/generatev4.py index c0490a0c3..9a2bdda73 100755 --- a/samples/SupportLeanbackDemos/generatev4.py +++ b/samples/SupportLeanbackDemos/generatev4.py @@ -336,3 +336,30 @@ for line in file: outfile.write(line) file.close() outfile.close() + +file = open('src/com/example/android/leanback/OnboardingActivity.java', 'r') +outfile = open('src/com/example/android/leanback/OnboardingSupportActivity.java', 'w') +write_java_head(outfile, "OnboardingActivity") +for line in file: + line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') + line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') + line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') + line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') + line = line.replace('extends Activity', 'extends FragmentActivity') + line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') + outfile.write(line) +file.close() +outfile.close() + +file = open('src/com/example/android/leanback/OnboardingDemoFragment.java', 'r') +outfile = open('src/com/example/android/leanback/OnboardingDemoSupportFragment.java', 'w') +write_java_head(outfile, "OnboardingDemoFragment") +for line in file: + line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') + line = line.replace('import android.app.Activity', 'import android.support.v4.app.FragmentActivity') + line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') + line = line.replace('OnboardingFragment', 'OnboardingSupportFragment') + line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') + outfile.write(line) +file.close() +outfile.close() diff --git a/samples/SupportLeanbackDemos/res/layout/onboarding.xml b/samples/SupportLeanbackDemos/res/layout/onboarding.xml new file mode 100644 index 000000000..3645422cc --- /dev/null +++ b/samples/SupportLeanbackDemos/res/layout/onboarding.xml @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/samples/SupportLeanbackDemos/res/layout/onboarding_image.xml b/samples/SupportLeanbackDemos/res/layout/onboarding_image.xml new file mode 100644 index 000000000..69206453f --- /dev/null +++ b/samples/SupportLeanbackDemos/res/layout/onboarding_image.xml @@ -0,0 +1,23 @@ + + + + diff --git a/samples/SupportLeanbackDemos/res/values/arrays.xml b/samples/SupportLeanbackDemos/res/values/arrays.xml new file mode 100644 index 000000000..dd524765b --- /dev/null +++ b/samples/SupportLeanbackDemos/res/values/arrays.xml @@ -0,0 +1,33 @@ + + + + + + + + Onboarding + Easy to implement + Customize your contents + + + + + Announce your new features. + Just override OnbaordingFragment and provide the messages and images. + Customize your own logo image, splash animation and the contents animations. + + diff --git a/samples/SupportLeanbackDemos/res/values/colors.xml b/samples/SupportLeanbackDemos/res/values/colors.xml index 705ce0187..1fdeb874c 100644 --- a/samples/SupportLeanbackDemos/res/values/colors.xml +++ b/samples/SupportLeanbackDemos/res/values/colors.xml @@ -16,4 +16,5 @@ #4A4F51 #2A2F51 + #80FFFFFF diff --git a/samples/SupportLeanbackDemos/res/values/strings.xml b/samples/SupportLeanbackDemos/res/values/strings.xml index 34a0b5f99..0a3ead428 100644 --- a/samples/SupportLeanbackDemos/res/values/strings.xml +++ b/samples/SupportLeanbackDemos/res/values/strings.xml @@ -59,6 +59,9 @@ Choose Presenter for Details Use New DetailsPresenter Use Legacy DetailsPresenter + Onboarding + Show onboarding activity. + Onboarding(support version) First diff --git a/samples/SupportLeanbackDemos/res/values/styles.xml b/samples/SupportLeanbackDemos/res/values/styles.xml index 2d6a23469..98130eff0 100644 --- a/samples/SupportLeanbackDemos/res/values/styles.xml +++ b/samples/SupportLeanbackDemos/res/values/styles.xml @@ -47,4 +47,8 @@ @style/MyImageCardViewTitleStyle + \ No newline at end of file diff --git a/samples/SupportLeanbackDemos/res/values/themes.xml b/samples/SupportLeanbackDemos/res/values/themes.xml index 1a87f9492..8b46f2e03 100644 --- a/samples/SupportLeanbackDemos/res/values/themes.xml +++ b/samples/SupportLeanbackDemos/res/values/themes.xml @@ -37,4 +37,8 @@ + diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java index b26ebd536..298ef705b 100644 --- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java @@ -104,6 +104,12 @@ public class MainActivity extends Activity { addAction(actions, DetailsPresenterSelectionActivity.class, R.string.detail_presenter_options, R.string.detail_presenter_options_description); + addAction(actions, OnboardingActivity.class, + R.string.onboarding, + R.string.onboarding_description); + addAction(actions, OnboardingSupportActivity.class, + R.string.onboarding_support, + R.string.onboarding_description); } private void addAction(List actions, Class cls, int titleRes, int descRes) { diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingActivity.java new file mode 100644 index 000000000..2fe9bb9a1 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingActivity.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 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 com.example.android.leanback; + +import android.app.Activity; +import android.os.Bundle; +import android.view.ViewTreeObserver; + +public class OnboardingActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.onboarding); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoFragment.java new file mode 100644 index 000000000..4a5abdcff --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoFragment.java @@ -0,0 +1,135 @@ +/* + * 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 com.example.android.leanback; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.support.v17.leanback.app.OnboardingFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.MarginLayoutParams; +import android.widget.ImageView; + +import java.util.ArrayList; + +public class OnboardingDemoFragment extends OnboardingFragment { + private static final long ANIMATION_DURATION = 1000; + + private static final int[] CONTENT_IMAGES = { + R.drawable.gallery_photo_1, + R.drawable.gallery_photo_2, + R.drawable.gallery_photo_3 + }; + private String[] mTitles; + private String[] mDescriptions; + + private View mBackgroundView; + private ImageView mContentView; + private ImageView mImage1; + private ImageView mImage2; + + private Animator mContentAnimator; + + @Override + public void onAttach(android.app.Activity activity) { + super.onAttach(activity); + mTitles = getResources().getStringArray(R.array.onboarding_page_titles); + mDescriptions = getResources().getStringArray(R.array.onboarding_page_descriptions); + } + + @Override + protected int getPageCount() { + return mTitles.length; + } + + @Override + protected CharSequence getPageTitle(int i) { + return mTitles[i]; + } + + @Override + protected CharSequence getPageDescription(int i) { + return mDescriptions[i]; + } + + @Override + protected View onCreateBackgroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + mBackgroundView = layoutInflater.inflate(R.layout.onboarding_image, viewGroup, false); + return mBackgroundView; + } + + @Override + protected View onCreateContentView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + mContentView = (ImageView) layoutInflater.inflate(R.layout.onboarding_image, viewGroup, + false); + MarginLayoutParams layoutParams = ((MarginLayoutParams) mContentView.getLayoutParams()); + layoutParams.topMargin = 30; + layoutParams.bottomMargin = 60; + return mContentView; + } + + @Override + protected View onCreateForegroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return null; + } + + @Override + protected Animator onCreateEnterAnimation() { + ArrayList animators = new ArrayList<>(); + animators.add(createFadeInAnimator(mBackgroundView)); + mContentView.setImageResource(CONTENT_IMAGES[0]); + mContentAnimator = createFadeInAnimator(mContentView); + animators.add(mContentAnimator); + AnimatorSet set = new AnimatorSet(); + set.playTogether(animators); + return set; + } + + @Override + protected void onPageChanged(final int newPage, int previousPage) { + if (mContentAnimator != null) { + mContentAnimator.end(); + } + ArrayList animators = new ArrayList<>(); + Animator fadeOut = createFadeOutAnimator(mContentView); + fadeOut.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mContentView.setImageResource(CONTENT_IMAGES[newPage]); + } + }); + animators.add(fadeOut); + animators.add(createFadeInAnimator(mContentView)); + AnimatorSet set = new AnimatorSet(); + set.playSequentially(animators); + set.start(); + mContentAnimator = set; + } + + private Animator createFadeInAnimator(View view) { + return ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f).setDuration(ANIMATION_DURATION); + } + + private Animator createFadeOutAnimator(View view) { + return ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f).setDuration(ANIMATION_DURATION); + } + + @Override + protected void onFinishFragment() { + getActivity().finish(); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoSupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoSupportFragment.java new file mode 100644 index 000000000..42e85f485 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingDemoSupportFragment.java @@ -0,0 +1,137 @@ +/* This file is auto-generated from OnboardingDemoFragment.java. DO NOT MODIFY. */ + +/* + * 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 com.example.android.leanback; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.support.v17.leanback.app.OnboardingSupportFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.MarginLayoutParams; +import android.widget.ImageView; + +import java.util.ArrayList; + +public class OnboardingDemoSupportFragment extends OnboardingSupportFragment { + private static final long ANIMATION_DURATION = 1000; + + private static final int[] CONTENT_IMAGES = { + R.drawable.gallery_photo_1, + R.drawable.gallery_photo_2, + R.drawable.gallery_photo_3 + }; + private String[] mTitles; + private String[] mDescriptions; + + private View mBackgroundView; + private ImageView mContentView; + private ImageView mImage1; + private ImageView mImage2; + + private Animator mContentAnimator; + + @Override + public void onAttach(android.app.Activity activity) { + super.onAttach(activity); + mTitles = getResources().getStringArray(R.array.onboarding_page_titles); + mDescriptions = getResources().getStringArray(R.array.onboarding_page_descriptions); + } + + @Override + protected int getPageCount() { + return mTitles.length; + } + + @Override + protected CharSequence getPageTitle(int i) { + return mTitles[i]; + } + + @Override + protected CharSequence getPageDescription(int i) { + return mDescriptions[i]; + } + + @Override + protected View onCreateBackgroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + mBackgroundView = layoutInflater.inflate(R.layout.onboarding_image, viewGroup, false); + return mBackgroundView; + } + + @Override + protected View onCreateContentView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + mContentView = (ImageView) layoutInflater.inflate(R.layout.onboarding_image, viewGroup, + false); + MarginLayoutParams layoutParams = ((MarginLayoutParams) mContentView.getLayoutParams()); + layoutParams.topMargin = 30; + layoutParams.bottomMargin = 60; + return mContentView; + } + + @Override + protected View onCreateForegroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return null; + } + + @Override + protected Animator onCreateEnterAnimation() { + ArrayList animators = new ArrayList<>(); + animators.add(createFadeInAnimator(mBackgroundView)); + mContentView.setImageResource(CONTENT_IMAGES[0]); + mContentAnimator = createFadeInAnimator(mContentView); + animators.add(mContentAnimator); + AnimatorSet set = new AnimatorSet(); + set.playTogether(animators); + return set; + } + + @Override + protected void onPageChanged(final int newPage, int previousPage) { + if (mContentAnimator != null) { + mContentAnimator.end(); + } + ArrayList animators = new ArrayList<>(); + Animator fadeOut = createFadeOutAnimator(mContentView); + fadeOut.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mContentView.setImageResource(CONTENT_IMAGES[newPage]); + } + }); + animators.add(fadeOut); + animators.add(createFadeInAnimator(mContentView)); + AnimatorSet set = new AnimatorSet(); + set.playSequentially(animators); + set.start(); + mContentAnimator = set; + } + + private Animator createFadeInAnimator(View view) { + return ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f).setDuration(ANIMATION_DURATION); + } + + private Animator createFadeOutAnimator(View view) { + return ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f).setDuration(ANIMATION_DURATION); + } + + @Override + protected void onFinishFragment() { + getActivity().finish(); + } +} diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingSupportActivity.java new file mode 100644 index 000000000..e23a7e6e7 --- /dev/null +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/OnboardingSupportActivity.java @@ -0,0 +1,28 @@ +/* This file is auto-generated from OnboardingActivity.java. DO NOT MODIFY. */ + +/* + * Copyright (C) 2016 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 com.example.android.leanback; + +import android.support.v4.app.FragmentActivity; +import android.os.Bundle; +import android.view.ViewTreeObserver; + +public class OnboardingSupportActivity extends FragmentActivity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.onboarding); + } +}