Add demo for OnboardingFragment
Change-Id: I538ea409fc1cb1c1e6a60fb744b53cbeb4fb9bc1
This commit is contained in:
@@ -123,5 +123,13 @@
|
||||
android:theme="@style/Theme.Example.Leanback.GuidedStep"
|
||||
android:exported="true" />
|
||||
|
||||
<activity android:name=".OnboardingActivity"
|
||||
android:theme="@style/Theme.Example.Leanback.Onboarding"
|
||||
android:exported="true" />
|
||||
|
||||
<activity android:name=".OnboardingSupportActivity"
|
||||
android:theme="@style/Theme.Example.Leanback.Onboarding"
|
||||
android:exported="true" />
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -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()
|
||||
|
||||
28
samples/SupportLeanbackDemos/res/layout/onboarding.xml
Normal file
28
samples/SupportLeanbackDemos/res/layout/onboarding.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:name="com.example.android.leanback.OnboardingDemoFragment"
|
||||
android:id="@+id/main_onboarding_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</FrameLayout>
|
||||
23
samples/SupportLeanbackDemos/res/layout/onboarding_image.xml
Normal file
23
samples/SupportLeanbackDemos/res/layout/onboarding_image.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/bg"/>
|
||||
33
samples/SupportLeanbackDemos/res/values/arrays.xml
Normal file
33
samples/SupportLeanbackDemos/res/values/arrays.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Titles in the onboarding page. -->
|
||||
<string-array name="onboarding_page_titles">
|
||||
<item>Onboarding</item>
|
||||
<item>Easy to implement</item>
|
||||
<item>Customize your contents</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Descriptions in the onboarding page. -->
|
||||
<string-array name="onboarding_page_descriptions">
|
||||
<item>Announce your new features.</item>
|
||||
<item>Just override OnbaordingFragment and provide the messages and images.</item>
|
||||
<item>Customize your own logo image, splash animation and the contents animations.</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -16,4 +16,5 @@
|
||||
<resources>
|
||||
<color name="icon_background">#4A4F51</color>
|
||||
<color name="icon_alt_background">#2A2F51</color>
|
||||
<color name="page_indicator_dot">#80FFFFFF</color>
|
||||
</resources>
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
<string name="detail_presenter_options_description">Choose Presenter for Details</string>
|
||||
<string name="legacydetails_off">Use New DetailsPresenter</string>
|
||||
<string name="legacydetails_on">Use Legacy DetailsPresenter</string>
|
||||
<string name="onboarding">Onboarding</string>
|
||||
<string name="onboarding_description">Show onboarding activity.</string>
|
||||
<string name="onboarding_support">Onboarding(support version)</string>
|
||||
|
||||
<!-- Strings related to guided sequence activity -->
|
||||
<string name="guidedstep_first_title">First</string>
|
||||
|
||||
@@ -47,4 +47,8 @@
|
||||
<item name="imageCardViewTitleStyle">@style/MyImageCardViewTitleStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Example.Leanback.OnboardingLogoStyle" parent="Widget.Leanback.OnboardingLogoStyle">
|
||||
<item name="android:layout_width">192dp</item>
|
||||
<item name="android:layout_height">192dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -37,4 +37,8 @@
|
||||
</style>
|
||||
<style name="Theme.Example.Leanback.GuidedStep.Half" parent="Theme.Leanback.GuidedStep.Half">
|
||||
</style>
|
||||
<style name="Theme.Example.Leanback.Onboarding" parent="Theme.Leanback.Onboarding">
|
||||
<item name="onboardingLogoStyle">@style/Widget.Example.Leanback.OnboardingLogoStyle</item>
|
||||
<item name="onboardingNavigatorDotBgColor">@color/page_indicator_dot</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -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<GuidedAction> actions, Class cls, int titleRes, int descRes) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<Animator> 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<Animator> 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();
|
||||
}
|
||||
}
|
||||
@@ -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<Animator> 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<Animator> 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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user