am fd2db1be: Merge "Swiperefresh sample" into klp-ub-dev
* commit 'fd2db1bef161e8bc7eda014f3924009330a9ab44': Swiperefresh sample
This commit is contained in:
@@ -305,6 +305,15 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".widget.SwipeRefreshLayoutActivity"
|
||||||
|
android:label="@string/swipe"
|
||||||
|
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"
|
<activity android:name=".widget.ContentLoadingProgressBarActivity"
|
||||||
android:label="@string/content_loading_progress_bar">
|
android:label="@string/content_loading_progress_bar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
BIN
samples/Support4Demos/res/drawable-hdpi/refresh.png
Normal file
BIN
samples/Support4Demos/res/drawable-hdpi/refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
samples/Support4Demos/res/drawable-mdpi/refresh.png
Normal file
BIN
samples/Support4Demos/res/drawable-mdpi/refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
samples/Support4Demos/res/drawable-xhdpi/refresh.png
Normal file
BIN
samples/Support4Demos/res/drawable-xhdpi/refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2013 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">
|
||||||
|
<!-- some full screen pullable view that will be the offsetable content -->
|
||||||
|
<ListView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/content"/>
|
||||||
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
22
samples/Support4Demos/res/menu/swipe_refresh_menu.xml
Normal file
22
samples/Support4Demos/res/menu/swipe_refresh_menu.xml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2013 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/force_refresh"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:icon="@drawable/refresh"
|
||||||
|
android:title="Refresh" />
|
||||||
|
</menu>
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
<style name="ThemeHolo" parent="android:Theme.Holo">
|
<style name="ThemeHolo" parent="android:Theme.Holo">
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- For API level 11 or later, the Holo theme is available and we prefer that. -->
|
||||||
|
<style name="ThemeHoloLight" parent="android:Theme.Holo.Light">
|
||||||
|
</style>
|
||||||
|
|
||||||
<!-- For API level 11 or later, we can use the magical DialogWhenLarge theme. -->
|
<!-- For API level 11 or later, we can use the magical DialogWhenLarge theme. -->
|
||||||
<style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge">
|
<style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge">
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -18,5 +18,9 @@
|
|||||||
<drawable name="red">#7f00</drawable>
|
<drawable name="red">#7f00</drawable>
|
||||||
<drawable name="blue">#770000ff</drawable>
|
<drawable name="blue">#770000ff</drawable>
|
||||||
<drawable name="green">#7700ff00</drawable>
|
<drawable name="green">#7700ff00</drawable>
|
||||||
<drawable name="yellow">#77ffff00</drawable>
|
<drawable name="yellow">#77ffff00</drawable>
|
||||||
|
<color name="color1">#ff0f9d58</color>
|
||||||
|
<color name="color2">#ffdb4437</color>
|
||||||
|
<color name="color3">#ff4285f4</color>
|
||||||
|
<color name="color4">#fff4b400</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -176,4 +176,6 @@
|
|||||||
<!-- ContentLoadingProgressBar -->
|
<!-- ContentLoadingProgressBar -->
|
||||||
<string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string>
|
<string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string>
|
||||||
|
|
||||||
|
<!-- Swipe refresh -->
|
||||||
|
<string name="swipe">Widget/SwipeRefreshLayout</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -21,7 +21,14 @@
|
|||||||
selected when the holographic theme is available. -->
|
selected when the holographic theme is available. -->
|
||||||
<style name="ThemeHolo" parent="android:Theme">
|
<style name="ThemeHolo" parent="android:Theme">
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- This is a theme that will adjust itself depending on the API version.
|
||||||
|
The default definition is the safe one, using a theme that has always
|
||||||
|
been defined. Look at values-11/styles.xml for a variation that is
|
||||||
|
selected when the holographic theme is available. -->
|
||||||
|
<style name="ThemeHoloLight" parent="android:Theme.Light">
|
||||||
|
</style>
|
||||||
|
|
||||||
<!-- Older platforms don't have Theme.Holo.DialogWhenLarge; we will define
|
<!-- Older platforms don't have Theme.Holo.DialogWhenLarge; we will define
|
||||||
our own wrapper theme that uses it only when running on the appropriate
|
our own wrapper theme that uses it only when running on the appropriate
|
||||||
platform version. On older platforms, we always use the generic
|
platform version. On older platforms, we always use the generic
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 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 android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
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 =
|
||||||
|
{
|
||||||
|
"Henry IV (1)",
|
||||||
|
"Henry V",
|
||||||
|
"Henry VIII",
|
||||||
|
"Richard II",
|
||||||
|
"Richard III",
|
||||||
|
"Merchant of Venice",
|
||||||
|
"Othello",
|
||||||
|
"King Lear",
|
||||||
|
"Henry IV (1)",
|
||||||
|
"Henry V",
|
||||||
|
"Henry VIII",
|
||||||
|
"Richard II",
|
||||||
|
"Richard III",
|
||||||
|
"Merchant of Venice",
|
||||||
|
"Othello",
|
||||||
|
"King Lear",
|
||||||
|
"Henry IV (1)",
|
||||||
|
"Henry V",
|
||||||
|
"Henry VIII",
|
||||||
|
"Richard II",
|
||||||
|
"Richard III",
|
||||||
|
"Merchant of Venice",
|
||||||
|
"Othello",
|
||||||
|
"King Lear",
|
||||||
|
"Henry IV (1)",
|
||||||
|
"Henry V",
|
||||||
|
"Henry VIII",
|
||||||
|
"Richard II",
|
||||||
|
"Richard III",
|
||||||
|
"Merchant of Venice",
|
||||||
|
"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() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mSwipeRefreshWidget.setRefreshing(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
setContentView(R.layout.swipe_refresh_widget_sample);
|
||||||
|
mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
|
||||||
|
mSwipeRefreshWidget.setColorScheme(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.swipe_refresh_menu, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click handler for the menu item to force a refresh.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
final int id = item.getItemId();
|
||||||
|
switch(id) {
|
||||||
|
case R.id.force_refresh:
|
||||||
|
mSwipeRefreshWidget.setRefreshing(true);
|
||||||
|
refresh();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh() {
|
||||||
|
mHandler.removeCallbacks(mRefreshDone);
|
||||||
|
mHandler.postDelayed(mRefreshDone, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user