Skip to content

Commit

Permalink
Added Canceling by TAG sample, Closing android-async-http#754
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Jul 16, 2015
1 parent 8b1243c commit 90b69cf
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Updated RequestParams documentation on handling arrays, sets and maps, along with new RequestParamsDebug sample
- Added BlackholeHttpResponseHandler implementation, which discards all response contents and silents all various log messages (see #416)
- Added LogInterface, it's default implementation and interface option to disable/enable logging library-wide and set logging verbosity
- Added option to TAG RequestHandle and cancel all requests matching specified TAG through `AsyncHttpClient.cancelRequestsByTAG(Object TAG)`

## 1.4.7 (released 9. 5. 2015)

Expand Down
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<activity android:name=".Redirect302Sample" />
<activity android:name=".ThreadingTimeoutSample" />
<activity android:name=".CancelAllRequestsSample" />
<activity android:name=".CancelRequestByTagSample" />
<activity android:name=".CancelRequestHandleSample" />
<activity android:name=".SynchronousClientSample" />
<activity android:name=".IntentServiceSample" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Android Asynchronous Http Client Sample
Copyright (c) 2014 Marek Sebera <[email protected]>
http://loopj.com
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.loopj.android.http.sample;

import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestHandle;
import com.loopj.android.http.ResponseHandlerInterface;

import org.apache.http.Header;
import org.apache.http.HttpEntity;

public class CancelRequestByTagSample extends ThreadingTimeoutSample {

private static final String LOG_TAG = "CancelRequestByTagSample";
private static final Integer REQUEST_TAG = 132435;

@Override
public int getSampleTitle() {
return R.string.title_cancel_tag;
}

@Override
public void onCancelButtonPressed() {
Log.d(LOG_TAG, "Canceling requests by TAG: " + REQUEST_TAG);
getAsyncHttpClient().cancelRequestsByTAG(REQUEST_TAG, false);
}

@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
return client.get(this, URL, headers, null, responseHandler).setTag(REQUEST_TAG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class CancelRequestHandleSample extends ThreadingTimeoutSample {

private static final String LOG_TAG = "ThreadingTimeoutSample";
private static final String LOG_TAG = "CancelRequestHandleSample";

@Override
public int getSampleTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class FilesSample extends PostSample {

public static final String LOG_TAG = "PostFilesSample";
public static final String LOG_TAG = "FilesSample";

@Override
public int getSampleTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
public class Http401AuthSample extends GetSample {

private static final String LOG_TAG = "Http401Auth";
private static final String LOG_TAG = "Http401AuthSample";
private static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
private static final String HEADER_AUTHORIZATION = "Authorization";
private static final String HEADER_REALM_PREFIX = "realm=";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class WaypointsActivity extends ListActivity {
new SampleConfig(R.string.title_threading_timeout, ThreadingTimeoutSample.class),
new SampleConfig(R.string.title_cancel_all, CancelAllRequestsSample.class),
new SampleConfig(R.string.title_cancel_handle, CancelRequestHandleSample.class),
new SampleConfig(R.string.title_cancel_tag, CancelRequestByTagSample.class),
new SampleConfig(R.string.title_synchronous, SynchronousClientSample.class),
new SampleConfig(R.string.title_intent_service_sample, IntentServiceSample.class),
new SampleConfig(R.string.title_post_files, FilesSample.class),
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<string name="title_cancel_all">Cancel all requests</string>
<string name="title_sax_example">SAX Example</string>
<string name="title_cancel_handle">Cancel request handle</string>
<string name="title_cancel_tag">Cancel by TAG</string>
<string name="title_synchronous">Synchronous GET request</string>
<string name="title_threading_timeout">Threading timeouts</string>
<string name="title_gzip_sample">GET Gzipped JSON and parse it</string>
Expand Down

0 comments on commit 90b69cf

Please sign in to comment.