Generate support version of leanback fragment tests

Include all leanback support version of fragment except
PlaybackOverlayFragment missing a support version of PlaybackControlHelper.

Change-Id: Icb5c99e8677630e8541b22b009051dd3908d4f35
This commit is contained in:
Dake Gu
2015-09-29 15:32:42 -07:00
parent 6b73c45db3
commit 48b4a134a4
28 changed files with 1890 additions and 21 deletions

View File

@@ -25,6 +25,10 @@
android:theme="@style/Theme.Example.Leanback.Browse"
android:exported="true" />
<activity android:name="BrowseSupportActivity"
android:theme="@style/Theme.Example.Leanback.Browse"
android:exported="true" />
<activity android:name="BrowseAnimationActivity"
android:exported="true" >
</activity>
@@ -33,14 +37,26 @@
android:theme="@style/Theme.Example.Leanback.Details"
android:exported="true" />
<activity android:name="DetailsSupportActivity"
android:theme="@style/Theme.Example.Leanback.Details"
android:exported="true" />
<activity android:name="SearchDetailsActivity"
android:theme="@style/Theme.Example.Leanback.SearchDetails"
android:exported="true" />
<activity android:name="SearchDetailsSupportActivity"
android:theme="@style/Theme.Example.Leanback.SearchDetails"
android:exported="true" />
<activity android:name="RowsActivity"
android:theme="@style/Theme.Example.Leanback.Rows"
android:exported="true" />
<activity android:name="RowsSupportActivity"
android:theme="@style/Theme.Example.Leanback.Rows"
android:exported="true" />
<activity android:name="PlaybackOverlayActivity"
android:exported="true" />
@@ -48,13 +64,24 @@
android:theme="@style/Theme.Example.Leanback.VerticalGrid"
android:exported="true" />
<activity android:name="VerticalGridSupportActivity"
android:theme="@style/Theme.Example.Leanback.VerticalGrid"
android:exported="true" />
<activity android:name="SearchActivity"
android:exported="true" />
<activity android:name="SearchSupportActivity"
android:exported="true" />
<activity android:name="BrowseErrorActivity"
android:theme="@style/Theme.Example.Leanback.Browse"
android:exported="true" />
<activity android:name="BrowseErrorSupportActivity"
android:theme="@style/Theme.Example.Leanback.Browse"
android:exported="true" />
<activity android:name="HorizontalGridTestActivity"
android:exported="true" />

View File

@@ -17,18 +17,260 @@
import os
import sys
def write_java_head(tofile, name):
tofile.write("/* This file is auto-generated from {}.java. DO NOT MODIFY. */\n\n".format(name))
def replace_xml_head(line, name):
return line.replace('<?xml version="1.0" encoding="utf-8"?>', '<?xml version="1.0" encoding="utf-8"?>\n<!-- This file is auto-generated from {}.xml. DO NOT MODIFY. -->\n'.format(name))
file = open('src/com/example/android/leanback/GuidedStepActivity.java', 'r')
outfile = open('src/com/example/android/leanback/GuidedStepSupportActivity.java', 'w')
outfile.write("/* This file is auto-generated from GuidedStepActivity. DO NOT MODIFY. */\n\n")
write_java_head(outfile, "GuidedStepActivity")
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('GuidedStepFragment', 'GuidedStepSupportFragment')
line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('Activity activity', 'FragmentActivity activity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/BrowseFragment.java', 'r')
outfile = open('src/com/example/android/leanback/BrowseSupportFragment.java', 'w')
write_java_head(outfile, "BrowseFragment")
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('BrowseFragment', 'BrowseSupportFragment')
line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment')
line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity')
line = line.replace('BrowseActivity', 'BrowseSupportActivity')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
line = line.replace('SearchActivity', 'SearchSupportActivity')
line = line.replace('RowsActivity', 'RowsSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/BrowseActivity.java', 'r')
outfile = open('src/com/example/android/leanback/BrowseSupportActivity.java', 'w')
write_java_head(outfile, "BrowseActivity")
for line in file:
line = line.replace('BrowseActivity', 'BrowseSupportActivity')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.browse', 'R.layout.browse_support')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/browse.xml', 'r')
outfile = open('res/layout/browse_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "browse")
line = line.replace('com.example.android.leanback.BrowseFragment', 'com.example.android.leanback.BrowseSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/DetailsFragment.java', 'r')
outfile = open('src/com/example/android/leanback/DetailsSupportFragment.java', 'w')
write_java_head(outfile, "DetailsFragment")
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('DetailsFragment', 'DetailsSupportFragment')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
line = line.replace('SearchActivity', 'SearchSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/NewDetailsFragment.java', 'r')
outfile = open('src/com/example/android/leanback/NewDetailsSupportFragment.java', 'w')
write_java_head(outfile, "NewDetailsFragment")
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('DetailsFragment', 'DetailsSupportFragment')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
line = line.replace('SearchActivity', 'SearchSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/DetailsActivity.java', 'r')
outfile = open('src/com/example/android/leanback/DetailsSupportActivity.java', 'w')
write_java_head(outfile, "DetailsActivity")
for line in file:
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.details', 'R.layout.details_support')
line = line.replace('R.layout.legacy_details', 'R.layout.legacy_details_support')
line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
line = line.replace('DetailsFragment', 'DetailsSupportFragment')
line = line.replace('NewDetailsFragment', 'NewDetailsSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/details.xml', 'r')
outfile = open('res/layout/details_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "details")
line = line.replace('com.example.android.leanback.NewDetailsFragment', 'com.example.android.leanback.NewDetailsSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/legacy_details.xml', 'r')
outfile = open('res/layout/legacy_details_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "legacy_details")
line = line.replace('com.example.android.leanback.DetailsFragment', 'com.example.android.leanback.DetailsSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r')
outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w')
write_java_head(outfile, "SearchDetailsActivity")
for line in file:
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/SearchFragment.java', 'r')
outfile = open('src/com/example/android/leanback/SearchSupportFragment.java', 'w')
write_java_head(outfile, "SearchFragment")
for line in file:
line = line.replace('SearchFragment', 'SearchSupportFragment')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/SearchActivity.java', 'r')
outfile = open('src/com/example/android/leanback/SearchSupportActivity.java', 'w')
write_java_head(outfile, "SearchActivity")
for line in file:
line = line.replace('SearchActivity', 'SearchSupportActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.search', 'R.layout.search_support')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
line = line.replace('SearchFragment', 'SearchSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/search.xml', 'r')
outfile = open('res/layout/search_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "search")
line = line.replace('com.example.android.leanback.SearchFragment', 'com.example.android.leanback.SearchSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/VerticalGridFragment.java', 'r')
outfile = open('src/com/example/android/leanback/VerticalGridSupportFragment.java', 'w')
outfile.write("/* This file is auto-generated from VerticalGridFragment. DO NOT MODIFY. */\n\n")
for line in file:
line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
line = line.replace('SearchActivity', 'SearchSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/VerticalGridActivity.java', 'r')
outfile = open('src/com/example/android/leanback/VerticalGridSupportActivity.java', 'w')
write_java_head(outfile, "VerticalGridActivity")
for line in file:
line = line.replace('VerticalGridActivity', 'VerticalGridSupportActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.vertical_grid', 'R.layout.vertical_grid_support')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/vertical_grid.xml', 'r')
outfile = open('res/layout/vertical_grid_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "vertical_grid")
line = line.replace('com.example.android.leanback.VerticalGridFragment', 'com.example.android.leanback.VerticalGridSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/ErrorFragment.java', 'r')
outfile = open('src/com/example/android/leanback/ErrorSupportFragment.java', 'w')
write_java_head(outfile, "ErrorFragment")
for line in file:
line = line.replace('ErrorFragment', 'ErrorSupportFragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/BrowseErrorActivity.java', 'r')
outfile = open('src/com/example/android/leanback/BrowseErrorSupportActivity.java', 'w')
write_java_head(outfile, "BrowseErrorActivity")
for line in file:
line = line.replace('BrowseErrorActivity', 'BrowseErrorSupportActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.browse', 'R.layout.browse_support')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
line = line.replace('ErrorFragment', 'ErrorSupportFragment')
line = line.replace('SpinnerFragment', 'SpinnerSupportFragment')
line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/RowsFragment.java', 'r')
outfile = open('src/com/example/android/leanback/RowsSupportFragment.java', 'w')
write_java_head(outfile, "RowsFragment")
for line in file:
line = line.replace('RowsFragment', 'RowsSupportFragment')
line = line.replace('DetailsActivity', 'DetailsSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('src/com/example/android/leanback/RowsActivity.java', 'r')
outfile = open('src/com/example/android/leanback/RowsSupportActivity.java', 'w')
write_java_head(outfile, "RowsActivity")
for line in file:
line = line.replace('RowsActivity', 'RowsSupportActivity')
line = line.replace('extends Activity', 'extends FragmentActivity')
line = line.replace('R.layout.rows', 'R.layout.rows_support')
line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
line = line.replace('RowsFragment', 'RowsSupportFragment')
line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
line = line.replace('SearchActivity', 'SearchSupportActivity')
outfile.write(line)
file.close()
outfile.close()
file = open('res/layout/rows.xml', 'r')
outfile = open('res/layout/rows_support.xml', 'w')
for line in file:
line = replace_xml_head(line, "rows")
line = line.replace('com.example.android.leanback.RowsFragment', 'com.example.android.leanback.RowsSupportFragment')
outfile.write(line)
file.close()
outfile.close()

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from browse.xml. 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:name="com.example.android.leanback.BrowseSupportFragment"
android:id="@+id/main_browse_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- container for hosting GuidedStepFragment background -->
<FrameLayout android:id="@+id/lb_guidedstep_background"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from details.xml. 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.
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.example.android.leanback.NewDetailsSupportFragment"
android:id="@+id/details_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from legacy_details.xml. 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.
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.example.android.leanback.DetailsSupportFragment"
android:id="@+id/details_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from rows.xml. 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.
-->
<android.support.v17.leanback.widget.BrowseFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rows_frame"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:name="com.example.android.leanback.RowsSupportFragment"
android:id="@+id/main_rows_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v17.leanback.widget.TitleView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v17.leanback.widget.BrowseFrameLayout>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from search.xml. 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.
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.example.android.leanback.SearchSupportFragment"
android:id="@+id/search_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated from vertical_grid.xml. 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.
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.example.android.leanback.VerticalGridSupportFragment"
android:id="@+id/vertical_grid_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@@ -21,24 +21,36 @@
<string name="main_title">Activities</string>
<string name="browse">Browse</string>
<string name="browse_description">BrowseFragment test</string>
<string name="browse_support">Browse(support version)</string>
<string name="browse_support_description">BrowseSupportFragment test</string>
<string name="search">Search</string>
<string name="search_description">SearchFragment test</string>
<string name="search_support">Search(support version)</string>
<string name="search_support_description">SearchSupportFragment test</string>
<string name="details">Details</string>
<string name="details_description">DetailsFragment test</string>
<string name="details_support">Details(support version)</string>
<string name="details_support_description">DetailsSupportFragment test</string>
<string name="search_details">Search Details</string>
<string name="search_details_description">Search style DetailsFragment test</string>
<string name="search_details_support">Search Details(support version)</string>
<string name="search_details_support_description">Search style DetailsSupportFragment test</string>
<string name="playback">Playback</string>
<string name="playback_description">PlaybackOverlay test</string>
<string name="playback_description">PlaybackOverlayFragment test</string>
<string name="hgrid">Horizontal Grid</string>
<string name="hgrid_description">HorizontalGridView test</string>
<string name="vgrid">Vertical Grid</string>
<string name="vgrid_description">VerticalGridView test</string>
<string name="vgrid_description">VerticalGridFragment test</string>
<string name="vgrid_support">Vertical Grid(support version)</string>
<string name="vgrid_support_description">VerticalGridSupportFragment test</string>
<string name="guidedstep">Guided Step</string>
<string name="guidedstep_description">GuidedStepFragment test</string>
<string name="guidedstepsupport">Guided Step(support version)</string>
<string name="guidedstepsupport_description">GuidedStepSupportFragment test</string>
<string name="browseerror">Browse Error</string>
<string name="browseerror_description">BrowseError test</string>
<string name="browseerror_support">Browse ErrorFragment(support version)</string>
<string name="browseerror_support_description">Browse ErrorSupportFragment test</string>
<string name="detail_presenter_options">Choose Presenter for Details</string>
<string name="detail_presenter_options_description">Choose Presenter for Details</string>
<string name="legacydetails_off">Use New DetailsPresenter</string>

View File

@@ -0,0 +1,88 @@
/* This file is auto-generated from BrowseErrorActivity.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.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
public class BrowseErrorSupportActivity extends FragmentActivity
{
private ErrorSupportFragment mErrorSupportFragment;
private SpinnerSupportFragment mSpinnerSupportFragment;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.browse_support);
testError();
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
BackgroundHelper.attach(this);
}
@Override
public void onStop() {
BackgroundHelper.release(this);
super.onStop();
}
private void testError() {
mErrorSupportFragment = new ErrorSupportFragment();
getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mErrorSupportFragment).commit();
mSpinnerSupportFragment = new SpinnerSupportFragment();
getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerSupportFragment).commit();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (getSupportFragmentManager().isDestroyed()) {
return;
}
getSupportFragmentManager().beginTransaction().remove(mSpinnerSupportFragment).commit();
mErrorSupportFragment.setErrorContent(getResources());
}
}, 3000);
}
static public class SpinnerSupportFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ProgressBar progressBar = new ProgressBar(container.getContext());
if (container instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100, Gravity.CENTER);
progressBar.setLayoutParams(layoutParams);
}
return progressBar;
}
}
}

View File

@@ -0,0 +1,40 @@
/* This file is auto-generated from BrowseActivity.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.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class BrowseSupportActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse_support);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
BackgroundHelper.attach(this);
}
@Override
public void onStop() {
BackgroundHelper.release(this);
super.onStop();
}
}

View File

@@ -0,0 +1,162 @@
/* This file is auto-generated from BrowseFragment.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.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.app.GuidedStepSupportFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
public class BrowseSupportFragment extends android.support.v17.leanback.app.BrowseSupportFragment {
private static final String TAG = "leanback.BrowseSupportFragment";
private static final boolean TEST_ENTRANCE_TRANSITION = true;
private static final int NUM_ROWS = 10;
// Row heights default to wrap content
private static final boolean USE_FIXED_ROW_HEIGHT = false;
private ArrayObjectAdapter mRowsAdapter;
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
// For good performance, it's important to use a single instance of
// a card presenter for all rows using that presenter.
final static CardPresenter sCardPresenter = new CardPresenter();
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
setTitle("Leanback Sample App");
setHeadersState(HEADERS_ENABLED);
setOnSearchClickedListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
startActivity(intent);
}
});
setupRows();
setOnItemViewClickedListener(new ItemViewClickedListener());
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemSelected: " + item + " row " + row);
if (isShowingHeaders()) {
mBackgroundHelper.setBackground(getActivity(), null);
}
else if (item instanceof PhotoItem) {
mBackgroundHelper.setBackground(
getActivity(), ((PhotoItem) item).getImageResourceId());
}
}
});
if (TEST_ENTRANCE_TRANSITION) {
// don't run entrance transition if fragment is restored.
if (savedInstanceState == null) {
prepareEntranceTransition();
}
}
// simulates in a real world use case data being loaded two seconds later
new Handler().postDelayed(new Runnable() {
public void run() {
loadData();
startEntranceTransition();
}
}, 2000);
}
private void setupRows() {
ListRowPresenter lrp = new ListRowPresenter();
if (USE_FIXED_ROW_HEIGHT) {
lrp.setRowHeight(CardPresenter.getRowHeight(getActivity()));
lrp.setExpandedRowHeight(CardPresenter.getExpandedRowHeight(getActivity()));
}
mRowsAdapter = new ArrayObjectAdapter(lrp);
setAdapter(mRowsAdapter);
}
private void loadData() {
for (int i = 0; i < NUM_ROWS; ++i) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(sCardPresenter);
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", "Only a test", R.drawable.gallery_photo_2));
listRowAdapter.add(new PhotoItem("Android TV", "by Google", R.drawable.gallery_photo_3));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_5));
listRowAdapter.add(new PhotoItem("This is a test", "Open GuidedStepSupportFragment", R.drawable.gallery_photo_6));
listRowAdapter.add(new PhotoItem("Android TV", "open RowsSupportActivity", R.drawable.gallery_photo_7));
listRowAdapter.add(new PhotoItem("Leanback", "open BrowseSupportActivity", R.drawable.gallery_photo_8));
HeaderItem header = new HeaderItem(i, "Row " + i);
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
}
private final class ItemViewClickedListener implements OnItemViewClickedListener {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Intent intent;
Bundle bundle;
if (((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_6) {
GuidedStepSupportFragment.add(getFragmentManager(),
new GuidedStepSupportActivity.FirstStepFragment(),
android.R.id.content);
return;
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_8) {
intent = new Intent(getActivity(), BrowseSupportActivity.class);
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
.toBundle();
} else if ( ((PhotoItem) item).getImageResourceId() == R.drawable.gallery_photo_7) {
intent = new Intent(getActivity(), RowsSupportActivity.class);
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity())
.toBundle();
} else {
intent = new Intent(getActivity(), DetailsSupportActivity.class);
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView)itemViewHolder.view).getMainImageView(),
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
}
getActivity().startActivity(intent, bundle);
}
}
}

View File

@@ -21,10 +21,9 @@ public class DetailsActivity extends Activity
public static final String EXTRA_ITEM = "item";
public static final String SHARED_ELEMENT_NAME = "hero";
public static boolean USE_LEGACY_PRESENTER = false;
private boolean useLegacyFragment() {
return (USE_LEGACY_PRESENTER && !(this instanceof SearchDetailsActivity));
return (DetailsPresenterSelectionActivity.USE_LEGACY_PRESENTER
&& !(this instanceof SearchDetailsActivity));
}
/** Called when the activity is first created. */

View File

@@ -40,6 +40,7 @@ public class DetailsPresenterSelectionActivity extends Activity {
private static final long ACTION_ID_SWITCH_LEGACY_ON = 10000;
private static final long ACTION_ID_SWITCH_LEGACY_OFF = 10001;
public static boolean USE_LEGACY_PRESENTER = false;
private static final String[] OPTION_NAMES = { "Use new details presenter", "Use legacy details presenter" };
private static final String[] OPTION_DESCRIPTIONS = { "Use new details presenter",
@@ -97,11 +98,11 @@ public class DetailsPresenterSelectionActivity extends Activity {
for (int i = 0; i < OPTION_NAMES.length; i++) {
boolean checked = false;
if (OPTION_IDS[i] == ACTION_ID_SWITCH_LEGACY_ON) {
if (DetailsActivity.USE_LEGACY_PRESENTER) {
if (USE_LEGACY_PRESENTER) {
checked = true;
}
} else if (OPTION_IDS[i] == ACTION_ID_SWITCH_LEGACY_OFF) {
if (!DetailsActivity.USE_LEGACY_PRESENTER) {
if (!USE_LEGACY_PRESENTER) {
checked = true;
}
}
@@ -113,9 +114,9 @@ public class DetailsPresenterSelectionActivity extends Activity {
@Override
public void onGuidedActionClicked(GuidedAction action) {
if (action.getId() == ACTION_ID_SWITCH_LEGACY_ON) {
DetailsActivity.USE_LEGACY_PRESENTER = action.isChecked();
USE_LEGACY_PRESENTER = action.isChecked();
} else if (action.getId() == ACTION_ID_SWITCH_LEGACY_OFF) {
DetailsActivity.USE_LEGACY_PRESENTER = !action.isChecked();
USE_LEGACY_PRESENTER = !action.isChecked();
}
getActivity().finish();
}

View File

@@ -0,0 +1,61 @@
/* This file is auto-generated from DetailsActivity.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.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class DetailsSupportActivity extends FragmentActivity
{
public static final String EXTRA_ITEM = "item";
public static final String SHARED_ELEMENT_NAME = "hero";
private boolean useLegacyFragment() {
return (DetailsPresenterSelectionActivity.USE_LEGACY_PRESENTER
&& !(this instanceof SearchDetailsSupportActivity));
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(useLegacyFragment() ? R.layout.legacy_details_support : R.layout.details_support);
if (savedInstanceState == null) {
// Only pass object to fragment when activity is first time created,
// later object is modified and persisted with fragment state.
if (useLegacyFragment()) {
((DetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
} else {
((NewDetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
}
}
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
BackgroundHelper.attach(this);
}
@Override
public void onStop() {
BackgroundHelper.release(this);
super.onStop();
}
}

View File

@@ -0,0 +1,218 @@
/* This file is auto-generated from DetailsFragment.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.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ClassPresenterSelector;
import android.support.v17.leanback.widget.DetailsOverviewRow;
import android.support.v17.leanback.widget.DetailsOverviewRowPresenter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnActionClickedListener;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
public class DetailsSupportFragment extends android.support.v17.leanback.app.DetailsSupportFragment {
private static final String TAG = "leanback.DetailsSupportFragment";
private static final String ITEM = "item";
private static final int NUM_ROWS = 3;
private ArrayObjectAdapter mRowsAdapter;
private PhotoItem mPhotoItem;
final CardPresenter cardPresenter = new CardPresenter();
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
private static final int ACTION_PLAY = 1;
private static final int ACTION_RENT = 2;
private static final int ACTION_BUY = 3;
private static final boolean TEST_SHARED_ELEMENT_TRANSITION = true;
private static final boolean TEST_ENTRANCE_TRANSITION = true;
private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
private Action mActionPlay;
private Action mActionRent;
private Action mActionBuy;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
setTitle("Leanback Sample App");
setOnSearchClickedListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
startActivity(intent);
}
});
mActionPlay = new Action(ACTION_PLAY, "Play");
mActionRent = new Action(ACTION_RENT, "Rent", "$3.99",
getResources().getDrawable(R.drawable.ic_action_a));
mActionBuy = new Action(ACTION_BUY, "Buy $9.99");
ClassPresenterSelector ps = new ClassPresenterSelector();
DetailsOverviewRowPresenter dorPresenter =
new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
DetailsOverviewRow dor = (DetailsOverviewRow) mRowsAdapter.get(0);
if (action.getId() == ACTION_BUY) {
// on the UI thread, we can modify actions adapter directly
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
dor.getActionsAdapter();
actions.set(ACTION_PLAY, mActionPlay);
actions.clear(ACTION_RENT);
actions.clear(ACTION_BUY);
dor.setItem(mPhotoItem.getTitle() + "(Owned)");
dor.setImageDrawable(getResources().getDrawable(R.drawable.details_img_16x9));
} else if (action.getId() == ACTION_RENT) {
// on the UI thread, we can modify actions adapter directly
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
dor.getActionsAdapter();
actions.set(ACTION_PLAY, mActionPlay);
actions.clear(ACTION_RENT);
dor.setItem(mPhotoItem.getTitle() + "(Rented)");
} else if (action.getId() == ACTION_PLAY) {
Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class);
getActivity().startActivity(intent);
}
}
});
ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
mRowsAdapter = new ArrayObjectAdapter(ps);
PhotoItem item = (PhotoItem) (savedInstanceState != null ?
savedInstanceState.getParcelable(ITEM) : null);
if (item != null) {
setItem(item);
}
setOnItemViewClickedListener(new OnItemViewClickedListener() {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemClicked: " + item + " row " + row);
if (item instanceof PhotoItem){
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView)itemViewHolder.view).getMainImageView(),
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
}
});
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemSelected: " + item + " row " + row);
}
});
if (TEST_SHARED_ELEMENT_TRANSITION) {
dorPresenter.setSharedElementEnterTransition(getActivity(),
DetailsSupportActivity.SHARED_ELEMENT_NAME);
}
if (TEST_ENTRANCE_TRANSITION) {
// don't run entrance transition if Activity is restored.
if (savedInstanceState == null) {
prepareEntranceTransition();
}
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(ITEM, mPhotoItem);
}
public void setItem(PhotoItem photoItem) {
mPhotoItem = photoItem;
mRowsAdapter.clear();
new Handler().postDelayed(new Runnable() {
public void run() {
Resources res = getActivity().getResources();
DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle());
dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId()));
SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
adapter.set(ACTION_RENT, mActionRent);
adapter.set(ACTION_BUY, mActionBuy);
dor.setActionsAdapter(adapter);
mRowsAdapter.add(0, dor);
setSelectedPosition(0, false);
}
}, TIME_TO_LOAD_OVERVIEW_ROW_MS);
new Handler().postDelayed(new Runnable() {
public void run() {
for (int i = 0; i < NUM_ROWS; ++i) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
HeaderItem header = new HeaderItem(i, "Row " + i);
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
if (TEST_ENTRANCE_TRANSITION) {
startEntranceTransition();
}
}
}, TIME_TO_LOAD_RELATED_ROWS_MS);
setAdapter(mRowsAdapter);
}
@Override
public void onStart() {
super.onStart();
if (mPhotoItem != null) {
mBackgroundHelper.setBackground(
getActivity(), mPhotoItem.getImageResourceId());
}
}
}

View File

@@ -0,0 +1,56 @@
/* This file is auto-generated from ErrorFragment.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.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.SearchOrbView;
import android.util.Log;
import android.view.View;
public class ErrorSupportFragment extends android.support.v17.leanback.app.ErrorSupportFragment {
private static final String TAG = "leanback.ErrorSupportFragment";
private static final boolean TRANSLUCENT = true;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
setTitle("Leanback Sample App");
}
void setErrorContent(Resources resources) {
setImageDrawable(resources.getDrawable(R.drawable.lb_ic_sad_cloud));
setMessage("An error occurred.");
setDefaultBackground(TRANSLUCENT);
setButtonText("Dismiss");
setButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.i(TAG, "button clicked");
getFragmentManager().beginTransaction().remove(ErrorSupportFragment.this).commit();
}
});
}
}

View File

@@ -1,4 +1,4 @@
/* This file is auto-generated from GuidedStepActivity. DO NOT MODIFY. */
/* This file is auto-generated from GuidedStepActivity.java. DO NOT MODIFY. */
/*
* Copyright (C) 2014 The Android Open Source Project

View File

@@ -57,26 +57,40 @@ public class MainActivity extends Activity {
@Override
public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
addAction(actions, BrowseActivity.class, R.string.browse, R.string.browse_description);
addAction(actions, BrowseSupportActivity.class, R.string.browse_support,
R.string.browse_support_description);
addAction(actions, SearchActivity.class, R.string.search, R.string.search_description);
addAction(actions, SearchSupportActivity.class, R.string.search_support, R.string.search_support_description);
addAction(actions, DetailsActivity.class, R.string.details, R.string.details_description);
actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
addAction(actions, DetailsSupportActivity.class, R.string.details_support, R.string.details_support_description);
actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
addAction(actions, SearchDetailsActivity.class, R.string.search_details,
R.string.search_details_description);
actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM,
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
addAction(actions, SearchDetailsSupportActivity.class, R.string.search_details_support,
R.string.search_details_support_description);
actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsSupportActivity.EXTRA_ITEM,
new PhotoItem("Hello world", R.drawable.gallery_photo_1));
addAction(actions, PlaybackOverlayActivity.class, R.string.playback,
R.string.playback_description);
addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid,
R.string.hgrid_description);
addAction(actions, VerticalGridActivity.class, R.string.vgrid,
R.string.vgrid_description);
addAction(actions, VerticalGridSupportActivity.class, R.string.vgrid_support,
R.string.vgrid_support_description);
addAction(actions, GuidedStepActivity.class, R.string.guidedstep,
R.string.guidedstep_description);
addAction(actions, GuidedStepSupportActivity.class, R.string.guidedstepsupport,
R.string.guidedstepsupport_description);
addAction(actions, BrowseErrorActivity.class, R.string.browseerror,
R.string.browseerror_description);
addAction(actions, BrowseErrorSupportActivity.class, R.string.browseerror_support,
R.string.browseerror_support_description);
addAction(actions, PlaybackOverlayActivity.class, R.string.playback,
R.string.playback_description);
addAction(actions, HorizontalGridTestActivity.class, R.string.hgrid,
R.string.hgrid_description);
addAction(actions, DetailsPresenterSelectionActivity.class,
R.string.detail_presenter_options,
R.string.detail_presenter_options_description);

View File

@@ -68,8 +68,7 @@ public class NewDetailsFragment extends android.support.v17.leanback.app.Details
private FullWidthDetailsOverviewSharedElementHelper mHelper;
private void initializeTest() {
Activity activity = getActivity();
TEST_SHARED_ELEMENT_TRANSITION = null != activity.getWindow().getSharedElementEnterTransition();
TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow().getSharedElementEnterTransition();
TEST_OVERVIEW_ROW_ON_SECOND = !TEST_SHARED_ELEMENT_TRANSITION;
TEST_ENTRANCE_TRANSITION = true;
}

View File

@@ -0,0 +1,255 @@
/* This file is auto-generated from NewDetailsFragment.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.support.v4.app.FragmentActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ClassPresenterSelector;
import android.support.v17.leanback.widget.DetailsOverviewRow;
import android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter;
import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElementHelper;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnActionClickedListener;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
public class NewDetailsSupportFragment extends android.support.v17.leanback.app.DetailsSupportFragment {
private static final String TAG = "leanback.DetailsSupportFragment";
private static final String ITEM = "item";
private static final int NUM_ROWS = 3;
private ArrayObjectAdapter mRowsAdapter;
private PhotoItem mPhotoItem;
final CardPresenter cardPresenter = new CardPresenter();
private BackgroundHelper mBackgroundHelper = new BackgroundHelper();
private static final int ACTION_PLAY = 1;
private static final int ACTION_RENT = 2;
private static final int ACTION_BUY = 3;
private boolean TEST_OVERVIEW_ROW_ON_SECOND;
private boolean TEST_SHARED_ELEMENT_TRANSITION;
private boolean TEST_ENTRANCE_TRANSITION;
private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
private Action mActionPlay;
private Action mActionRent;
private Action mActionBuy;
private FullWidthDetailsOverviewSharedElementHelper mHelper;
private void initializeTest() {
TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow().getSharedElementEnterTransition();
TEST_OVERVIEW_ROW_ON_SECOND = !TEST_SHARED_ELEMENT_TRANSITION;
TEST_ENTRANCE_TRANSITION = true;
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
initializeTest();
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
setTitle("Leanback Sample App");
setOnSearchClickedListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
startActivity(intent);
}
});
mActionPlay = new Action(ACTION_PLAY, "Play");
mActionRent = new Action(ACTION_RENT, "Rent", "$3.99",
getResources().getDrawable(R.drawable.ic_action_a));
mActionBuy = new Action(ACTION_BUY, "Buy $9.99");
ClassPresenterSelector ps = new ClassPresenterSelector();
FullWidthDetailsOverviewRowPresenter dorPresenter =
new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
int indexOfOverviewRow = TEST_OVERVIEW_ROW_ON_SECOND ? 1 : 0;
DetailsOverviewRow dor = (DetailsOverviewRow) mRowsAdapter.get(indexOfOverviewRow);
if (action.getId() == ACTION_BUY) {
// on the UI thread, we can modify actions adapter directly
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
dor.getActionsAdapter();
actions.set(ACTION_PLAY, mActionPlay);
actions.clear(ACTION_RENT);
actions.clear(ACTION_BUY);
dor.setItem(mPhotoItem.getTitle() + "(Owned)");
dor.setImageDrawable(getResources().getDrawable(R.drawable.details_img_16x9));
} else if (action.getId() == ACTION_RENT) {
// on the UI thread, we can modify actions adapter directly
SparseArrayObjectAdapter actions = (SparseArrayObjectAdapter)
dor.getActionsAdapter();
actions.set(ACTION_PLAY, mActionPlay);
actions.clear(ACTION_RENT);
dor.setItem(mPhotoItem.getTitle() + "(Rented)");
} else if (action.getId() == ACTION_PLAY) {
Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class);
getActivity().startActivity(intent);
}
}
});
if (TEST_OVERVIEW_ROW_ON_SECOND) {
dorPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_SMALL);
}
ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
mRowsAdapter = new ArrayObjectAdapter(ps);
PhotoItem item = (PhotoItem) (savedInstanceState != null ?
savedInstanceState.getParcelable(ITEM) : null);
if (item != null) {
setItem(item);
}
setOnItemViewClickedListener(new OnItemViewClickedListener() {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemClicked: " + item + " row " + row);
if (item instanceof PhotoItem){
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView)itemViewHolder.view).getMainImageView(),
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
}
});
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemSelected: " + item + " row " + row);
}
});
if (TEST_SHARED_ELEMENT_TRANSITION) {
mHelper = new FullWidthDetailsOverviewSharedElementHelper();
mHelper.setSharedElementEnterTransition(getActivity(),
DetailsSupportActivity.SHARED_ELEMENT_NAME);
dorPresenter.setListener(mHelper);
dorPresenter.setParticipatingEntranceTransition(false);
} else {
dorPresenter.setParticipatingEntranceTransition(true);
}
if (TEST_ENTRANCE_TRANSITION) {
// don't run entrance transition if Activity is restored.
if (savedInstanceState == null) {
prepareEntranceTransition();
}
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(ITEM, mPhotoItem);
}
public void setItem(PhotoItem photoItem) {
mPhotoItem = photoItem;
mRowsAdapter.clear();
new Handler().postDelayed(new Runnable() {
public void run() {
if (TEST_OVERVIEW_ROW_ON_SECOND) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
HeaderItem header = new HeaderItem(0, "Search Result");
mRowsAdapter.add(0, new ListRow(header, listRowAdapter));
}
Resources res = getActivity().getResources();
DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle());
dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId()));
SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
adapter.set(ACTION_RENT, mActionRent);
adapter.set(ACTION_BUY, mActionBuy);
dor.setActionsAdapter(adapter);
int indexOfOverviewRow = TEST_OVERVIEW_ROW_ON_SECOND ? 1 : 0;
mRowsAdapter.add(indexOfOverviewRow, dor);
setSelectedPosition(0, true);
if (TEST_SHARED_ELEMENT_TRANSITION) {
if (mHelper != null && !mHelper.getAutoStartSharedElementTransition()) {
mHelper.startPostponedEnterTransition();
}
}
}
}, TIME_TO_LOAD_OVERVIEW_ROW_MS);
new Handler().postDelayed(new Runnable() {
public void run() {
for (int i = 0; i < NUM_ROWS; ++i) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
HeaderItem header = new HeaderItem(i, "Row " + i);
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
if (TEST_ENTRANCE_TRANSITION) {
startEntranceTransition();
}
}
}, TIME_TO_LOAD_RELATED_ROWS_MS);
setAdapter(mRowsAdapter);
}
@Override
public void onStart() {
super.onStart();
if (mPhotoItem != null) {
mBackgroundHelper.setBackground(
getActivity(), mPhotoItem.getImageResourceId());
}
}
}

View File

@@ -0,0 +1,60 @@
/* This file is auto-generated from RowsActivity.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.support.v4.app.FragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v17.leanback.R;
import android.support.v17.leanback.widget.BrowseFrameLayout;
import android.support.v17.leanback.widget.TitleHelper;
import android.support.v17.leanback.widget.TitleView;
import android.view.View;
public class RowsSupportActivity extends FragmentActivity
{
private RowsSupportFragment mRowsSupportFragment;
private TitleHelper mTitleHelper;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rows_support);
mRowsSupportFragment = (RowsSupportFragment) getSupportFragmentManager().findFragmentById(
R.id.main_rows_fragment);
setupTitleFragment();
}
private void setupTitleFragment() {
TitleView titleView = (TitleView) findViewById(R.id.title);
titleView.setTitle("RowsSupportFragment");
titleView.setOnSearchClickedListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(RowsSupportActivity.this, SearchSupportActivity.class);
startActivity(intent);
}
});
BrowseFrameLayout frameLayout = (BrowseFrameLayout) findViewById(R.id.rows_frame);
mTitleHelper = new TitleHelper(frameLayout, titleView);
frameLayout.setOnFocusSearchListener(mTitleHelper.getOnFocusSearchListener());
mRowsSupportFragment.setTitleHelper(mTitleHelper);
}
}

View File

@@ -0,0 +1,120 @@
/* This file is auto-generated from RowsFragment.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.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v17.leanback.widget.TitleHelper;
import android.support.v17.leanback.widget.TitleView;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.R;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class RowsSupportFragment extends android.support.v17.leanback.app.RowsSupportFragment {
private static final String TAG = "leanback.RowsSupportFragment";
private static final int NUM_ROWS = 10;
// Row heights default to wrap content
private static final boolean USE_FIXED_ROW_HEIGHT = false;
private ArrayObjectAdapter mRowsAdapter;
private TitleHelper mTitleHelper;
public void setTitleHelper(TitleHelper titleHelper) {
mTitleHelper = titleHelper;
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
setupRows();
setOnItemViewClickedListener(new ItemViewClickedListener());
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemSelected: " + item + " row " + row);
if (mTitleHelper != null) {
mTitleHelper.showTitle(getAdapter() == null || getAdapter().size() == 0 ||
getAdapter().get(0) == row);
}
}
});
}
private void setupRows() {
ListRowPresenter lrp = new ListRowPresenter();
if (USE_FIXED_ROW_HEIGHT) {
lrp.setRowHeight(CardPresenter.getRowHeight(getActivity()));
lrp.setExpandedRowHeight(CardPresenter.getExpandedRowHeight(getActivity()));
}
mRowsAdapter = new ArrayObjectAdapter(lrp);
// For good performance, it's important to use a single instance of
// a card presenter for all rows using that presenter.
final CardPresenter cardPresenter = new CardPresenter();
for (int i = 0; i < NUM_ROWS; ++i) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_5));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_6));
listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_7));
listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_8));
HeaderItem header = new HeaderItem(i, "Row " + i);
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
setAdapter(mRowsAdapter);
}
private final class ItemViewClickedListener implements OnItemViewClickedListener {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView)itemViewHolder.view).getMainImageView(),
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
}
}

View File

@@ -0,0 +1,23 @@
/* This file is auto-generated from SearchDetailsActivity.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;
/**
* Same implementation as DetailsSupportActivity for different entries in AndroidManifest.
*/
public class SearchDetailsSupportActivity extends DetailsSupportActivity
{
}

View File

@@ -0,0 +1,67 @@
/* This file is auto-generated from SearchActivity.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.support.v4.app.FragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v17.leanback.app.SearchSupportFragment;
import android.support.v17.leanback.widget.SpeechRecognitionCallback;
import android.util.Log;
public class SearchSupportActivity extends FragmentActivity
{
private static final String TAG = "SearchSupportActivity";
private static boolean DEBUG = true;
/** If using internal speech recognizer, you must have RECORD_AUDIO permission */
private static boolean USE_INTERNAL_SPEECH_RECOGNIZER = false;
private static final int REQUEST_SPEECH = 1;
private SearchSupportFragment mFragment;
private SpeechRecognitionCallback mSpeechRecognitionCallback;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_support);
mFragment = (SearchSupportFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment);
if (!USE_INTERNAL_SPEECH_RECOGNIZER) {
mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
@Override
public void recognizeSpeech() {
if (DEBUG) Log.v(TAG, "recognizeSpeech");
startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
}
};
mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (DEBUG) Log.v(TAG, "onActivityResult requestCode=" + requestCode +
" resultCode=" + resultCode +
" data=" + data);
if (requestCode == REQUEST_SPEECH && resultCode == RESULT_OK) {
mFragment.setSearchQuery(data, true);
}
}
}

View File

@@ -0,0 +1,104 @@
/* This file is auto-generated from SearchFragment.java. DO NOT MODIFY. */
package com.example.android.leanback;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.ObjectAdapter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.text.TextUtils;
import android.util.Log;
public class SearchSupportFragment extends android.support.v17.leanback.app.SearchSupportFragment
implements android.support.v17.leanback.app.SearchSupportFragment.SearchResultProvider {
private static final String TAG = "leanback.SearchSupportFragment";
private static final int NUM_ROWS = 3;
private static final int SEARCH_DELAY_MS = 1000;
private ArrayObjectAdapter mRowsAdapter;
private Handler mHandler = new Handler();
private String mQuery;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
setTitle("Leanback Sample App");
setSearchResultProvider(this);
setOnItemViewClickedListener(new ItemViewClickedListener());
}
@Override
public ObjectAdapter getResultsAdapter() {
return mRowsAdapter;
}
@Override
public boolean onQueryTextChange(String newQuery) {
Log.i(TAG, String.format("Search Query Text Change %s", newQuery));
mRowsAdapter.clear();
loadQuery(newQuery);
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
Log.i(TAG, String.format("Search Query Text Submit %s", query));
mRowsAdapter.clear();
loadQuery(query);
return true;
}
private void loadQuery(String query) {
mQuery = query;
mHandler.removeCallbacks(mDelayedLoad);
if (!TextUtils.isEmpty(query) && !query.equals("nil")) {
mHandler.postDelayed(mDelayedLoad, SEARCH_DELAY_MS);
}
}
private void loadRows() {
for (int i = 0; i < NUM_ROWS; ++i) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
HeaderItem header = new HeaderItem(i, mQuery + " results row " + i);
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
}
private Runnable mDelayedLoad = new Runnable() {
@Override
public void run() {
loadRows();
}
};
private final class ItemViewClickedListener implements OnItemViewClickedListener {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Intent intent = new Intent(getActivity(), DetailsSupportActivity.class);
intent.putExtra(DetailsSupportActivity.EXTRA_ITEM, (PhotoItem) item);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView)itemViewHolder.view).getMainImageView(),
DetailsSupportActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
}
}

View File

@@ -0,0 +1,32 @@
/* This file is auto-generated from VerticalGridActivity.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.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class VerticalGridSupportActivity extends FragmentActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.vertical_grid_support);
// TODO: use BackgroundManager here
getWindow().setBackgroundDrawableResource(R.drawable.bg);
}
}

View File

@@ -0,0 +1,114 @@
/* This file is auto-generated from VerticalGridFragment. 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.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v17.leanback.widget.VerticalGridPresenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class VerticalGridSupportFragment extends android.support.v17.leanback.app.VerticalGridSupportFragment {
private static final String TAG = "leanback.VerticalGridSupportFragment";
private static final int NUM_COLUMNS = 3;
private static final int NUM_ITEMS = 50;
private static final int HEIGHT = 200;
private static final boolean TEST_ENTRANCE_TRANSITION = true;
private static class Adapter extends ArrayObjectAdapter {
public Adapter(StringPresenter presenter) {
super(presenter);
}
public void callNotifyChanged() {
super.notifyChanged();
}
}
private Adapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
setBadgeDrawable(getActivity().getResources().getDrawable(R.drawable.ic_title));
setTitle("Leanback Vertical Grid Demo");
setupFragment();
if (TEST_ENTRANCE_TRANSITION) {
// don't run entrance transition if fragment is restored.
if (savedInstanceState == null) {
prepareEntranceTransition();
}
}
// simulates in a real world use case data being loaded two seconds later
new Handler().postDelayed(new Runnable() {
public void run() {
loadData();
startEntranceTransition();
}
}, 2000);
}
private void loadData() {
for (int i = 0; i < NUM_ITEMS; i++) {
mAdapter.add(Integer.toString(i));
}
}
private void setupFragment() {
VerticalGridPresenter gridPresenter = new VerticalGridPresenter();
gridPresenter.setNumberOfColumns(NUM_COLUMNS);
setGridPresenter(gridPresenter);
mAdapter = new Adapter(new StringPresenter());
setAdapter(mAdapter);
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemSelected: " + item + " row " + row);
}
});
setOnItemViewClickedListener(new OnItemViewClickedListener() {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
Log.i(TAG, "onItemClicked: " + item + " row " + row);
mAdapter.callNotifyChanged();
}
});
setOnSearchClickedListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
startActivity(intent);
}
});
}
}