am 279ed15a: am fd2db1be: Merge "Swiperefresh sample" into klp-ub-dev

* commit '279ed15a7f654e358ff572538c160fe7f896be42':
  Swiperefresh sample
This commit is contained in:
Mindy Pereira
2013-11-19 17:28:24 -08:00
committed by Android Git Automerger
11 changed files with 215 additions and 2 deletions

View File

@@ -305,6 +305,15 @@
</intent-filter>
</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"
android:label="@string/content_loading_progress_bar">
<intent-filter>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -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>

View 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>

View File

@@ -19,6 +19,10 @@
<style name="ThemeHolo" parent="android:Theme.Holo">
</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. -->
<style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge">
</style>

View File

@@ -18,5 +18,9 @@
<drawable name="red">#7f00</drawable>
<drawable name="blue">#770000ff</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>

View File

@@ -176,4 +176,6 @@
<!-- ContentLoadingProgressBar -->
<string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string>
<!-- Swipe refresh -->
<string name="swipe">Widget/SwipeRefreshLayout</string>
</resources>

View File

@@ -21,7 +21,14 @@
selected when the holographic theme is available. -->
<style name="ThemeHolo" parent="android:Theme">
</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
our own wrapper theme that uses it only when running on the appropriate
platform version. On older platforms, we always use the generic

View File

@@ -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);
}
}