Improve SwipeRefreshLayout demos
Adds a nested scrolling, and non-scrolling demo Change-Id: I5ce7e647f3ec976c55553dbc62d42889700ef444
This commit is contained in:
@@ -305,8 +305,8 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".widget.SwipeRefreshLayoutActivity"
|
||||
android:label="@string/swipe"
|
||||
<activity android:name=".widget.SwipeRefreshLayoutActivityList"
|
||||
android:label="@string/swipe_list"
|
||||
android:theme="@style/ThemeHoloLight">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -314,6 +314,25 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".widget.SwipeRefreshLayoutActivityTextView"
|
||||
android:label="@string/swipe_text"
|
||||
android:theme="@style/ThemeHoloLight">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".widget.SwipeRefreshLayoutActivityNestedScrollView"
|
||||
android:label="@string/swipe_nested_sv"
|
||||
android:theme="@style/ThemeHoloLight">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<activity android:name=".widget.ContentLoadingProgressBarActivity"
|
||||
android:label="@string/content_loading_progress_bar">
|
||||
<intent-filter>
|
||||
|
||||
20
samples/Support4Demos/res/drawable/gradient.xml
Normal file
20
samples/Support4Demos/res/drawable/gradient.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient android:startColor="#c8c8ff"
|
||||
android:endColor="#c8ffc8"
|
||||
android:angle="270" />
|
||||
</shape>
|
||||
@@ -18,9 +18,11 @@
|
||||
android:id="@+id/swipe_refresh_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- some full screen pullable view that will be the offsetable content -->
|
||||
<ListView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/content"/>
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe_refresh_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/gradient">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2000dp"
|
||||
android:text="@string/hello_world"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe_refresh_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_world"
|
||||
android:gravity="center"/>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
@@ -172,7 +172,9 @@
|
||||
<string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string>
|
||||
|
||||
<!-- Swipe refresh -->
|
||||
<string name="swipe">Widget/SwipeRefreshLayout</string>
|
||||
<string name="swipe_list">Widget/SwipeRefreshLayout ListView</string>
|
||||
<string name="swipe_text">Widget/SwipeRefreshLayout TextView</string>
|
||||
<string name="swipe_nested_sv">Widget/SwipeRefreshLayout NestedScrollView</string>
|
||||
|
||||
<string name="nested_scroll">Widget/Nested Scrolling</string>
|
||||
|
||||
|
||||
@@ -16,32 +16,27 @@
|
||||
|
||||
package com.example.android.supportv4.widget;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
import com.example.android.supportv4.Shakespeare;
|
||||
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
|
||||
/**
|
||||
* Example of using the SwipeRefreshLayout.
|
||||
*/
|
||||
public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshListener {
|
||||
public static final String[] TITLES =
|
||||
{
|
||||
abstract class BaseSwipeRefreshLayoutActivity extends Activity implements OnRefreshListener {
|
||||
|
||||
public static final String[] TITLES = {
|
||||
"Henry IV (1)",
|
||||
"Henry V",
|
||||
"Henry VIII",
|
||||
@@ -75,41 +70,42 @@ public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshLis
|
||||
"Othello",
|
||||
"King Lear"
|
||||
};
|
||||
|
||||
// Try a SUPER quick refresh to make sure we don't get extra refreshes
|
||||
// while the user's finger is still down.
|
||||
private static final boolean SUPER_QUICK_REFRESH = false;
|
||||
private View mContent;
|
||||
private SwipeRefreshLayout mSwipeRefreshWidget;
|
||||
private ListView mList;
|
||||
private Handler mHandler = new Handler();
|
||||
private final Runnable mRefreshDone = new Runnable() {
|
||||
|
||||
private SwipeRefreshLayout mSwipeRefreshWidget;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
|
||||
private final Runnable mRefreshDone = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshWidget.setRefreshing(false);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.swipe_refresh_widget_sample);
|
||||
setContentView(getLayoutId());
|
||||
|
||||
mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
|
||||
mSwipeRefreshWidget.setColorScheme(R.color.color1, R.color.color2, R.color.color3,
|
||||
mSwipeRefreshWidget.setColorSchemeResources(R.color.color1, R.color.color2, R.color.color3,
|
||||
R.color.color4);
|
||||
mList = (ListView) findViewById(R.id.content);
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_1, android.R.id.text1, TITLES);
|
||||
mList.setAdapter(arrayAdapter);
|
||||
mSwipeRefreshWidget.setOnRefreshListener(this);
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.supportv4.widget;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
|
||||
public class SwipeRefreshLayoutActivityList extends BaseSwipeRefreshLayoutActivity {
|
||||
|
||||
private ListView mList;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
mList = (ListView) findViewById(R.id.content);
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_list_item_1, android.R.id.text1, TITLES);
|
||||
mList.setAdapter(arrayAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.swipe_refresh_widget_listview;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.supportv4.widget;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
|
||||
public class SwipeRefreshLayoutActivityNestedScrollView extends BaseSwipeRefreshLayoutActivity {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.swipe_refresh_widget_nestedscrolling;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.supportv4.widget;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
|
||||
public class SwipeRefreshLayoutActivityTextView extends BaseSwipeRefreshLayoutActivity {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.swipe_refresh_widget_textview;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user