Skip to content

Commit

Permalink
Finished SimpleDownload
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrique Diaz committed Jul 7, 2011
1 parent 230c65c commit 7b064d2
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.androidtitlan.itam.simpledownload;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpResponseException;
import org.apache.http.util.EntityUtils;

public class ByteArrayResponseHandler implements ResponseHandler<byte[]> {
public byte[] handleResponse(final HttpResponse response)
throws IOException, HttpResponseException {
StatusLine statusLine=response.getStatusLine();

if (statusLine.getStatusCode()>=300) {
throw new HttpResponseException(statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}

HttpEntity entity=response.getEntity();

if (entity==null) {
return(null);
}

return(EntityUtils.toByteArray(entity));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.androidtitlan.itam.simpledownload;

import android.app.Activity;
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.os.Messenger;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class Downloader extends IntentService {
public static final String EXTRA_MESSENGER="com.commonsware.android.downloader.EXTRA_MESSENGER";
private HttpClient client=null;

public Downloader() {
super("Downloader");
}

@Override
public void onCreate() {
super.onCreate();
client=new DefaultHttpClient();
}

@Override
public void onDestroy() {
super.onDestroy();
client.getConnectionManager().shutdown();
}

@Override
public void onHandleIntent(Intent i) {
HttpGet getMethod=new HttpGet(i.getData().toString());
int result=Activity.RESULT_CANCELED;

try {
ResponseHandler<byte[]> responseHandler=new ByteArrayResponseHandler();
byte[] responseBody=client.execute(getMethod, responseHandler);
File output=new File(Environment.getExternalStorageDirectory(),
i.getData().getLastPathSegment());

if (output.exists()) {
output.delete();
}

FileOutputStream fos=new FileOutputStream(output.getPath());

fos.write(responseBody);
fos.close();
result=Activity.RESULT_OK;
}
catch (IOException e2) {
Log.e(getClass().getName(), "Exception in download", e2);
}

Bundle extras=i.getExtras();

if (extras!=null) {
Messenger messenger=(Messenger)extras.get(EXTRA_MESSENGER);
Message msg=Message.obtain();

msg.arg1=result;

try {
messenger.send(msg);
}
catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap
Binary file not shown.
Binary file not shown.
Binary file modified .metadata/.plugins/org.eclipse.core.resources/.snap
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Thu Jul 07 04:16:46 CDT 2011
#Thu Jul 07 05:15:11 CDT 2011
eclipse.preferences.version=1
internalWebBrowserHistory=http\://commonsware.com/Android/excerpt.pdf|*|
internalWebBrowserHistory=file\:/Users/spy/Android%20Development/android-sdk-mac/docs/reference/android/os/Message.html|*|http\://commonsware.com/Android/excerpt.pdf|*|
Binary file modified .metadata/.plugins/org.eclipse.jdt.core/2821513307.index
Binary file not shown.
Binary file added AndroidScreenCapture-1.1.zip
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/AShot-1.1.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions AndroidScreenCapture_1.1/ashot.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
2011-07-07 05:42:06,529 TRACE [pool-1-thread-1] c.m.a.AndroDemon [AndroDemon.java:124] initBridge
2011-07-07 05:42:06,565 TRACE [pool-1-thread-1] c.m.a.AndroDemon [AndroDemon.java:126] create bridge
2011-07-07 05:42:06,882 TRACE [pool-1-thread-1] c.m.a.AndroDemon [AndroDemon.java:129] bridge is created
2011-07-07 05:42:06,902 INFO [Device List Monitor] c.m.a.AndroDemon [AndroDemon.java:135] deviceConnected: 0403889903011014
2011-07-07 05:42:06,993 TRACE [Device List Monitor] c.m.a.AndroDemon [AndroDemon.java:147] deviceChanged: 0403889903011014 - 4
2011-07-07 05:42:14,156 DEBUG [AWT-EventQueue-0] c.m.a.Mediator [Mediator.java:171] Full screen: true
2011-07-07 05:42:33,302 DEBUG [AWT-EventQueue-0] c.m.a.Mediator [Mediator.java:171] Full screen: false
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/bsaf-1.9.jar
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/commons-io-1.4.jar
Binary file not shown.
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/ddmlib-1.0.jar
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/javaws.jar
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/junit-4.8.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added AndroidScreenCapture_1.1/libs/slf4j-api-1.6.1.jar
Binary file not shown.
36 changes: 36 additions & 0 deletions AndroidScreenCapture_1.1/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
===================================================
Android Screenshots and Screen Capture 1.1
===================================================

Before you begin, please make sure you have installed:

- JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html

- Android SDK
http://developer.android.com/sdk/index.html

Remark: it is enough to complete "Prepare your development computer"
and "Download and install the SDK starter package" steps
from Android SDK Quick Start.

- (Windows Only): Install USB driver
http://developer.android.com/sdk/win-usb.html

===================================================
Launching application
===================================================

To start taking screenshots of your Android phone launch the
following file which can be found in the same folder as this
readme file:

AShot-1.0.jar

and provide the path to Android SDK in File -> Android SDK path...

You are all set!

For more details please visit:

http://www.mightypocket.com/2010/08/android-screenshots-screen-capture-screen-cast/
Binary file modified AndroidTitlan.key
Binary file not shown.
Binary file modified SimpleDownload/bin/SimpleDownload.apk
Binary file not shown.
Binary file modified SimpleDownload/bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ByteArrayResponseHandler implements ResponseHandler<byte[]> {
public byte[] handleResponse(final HttpResponse response)
throws IOException, HttpResponseException {
StatusLine statusLine=response.getStatusLine();
StatusLine statusLine = response.getStatusLine();

if (statusLine.getStatusCode()>=300) {
throw new HttpResponseException(statusLine.getStatusCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.apache.http.impl.client.DefaultHttpClient;

public class Downloader extends IntentService {
public static final String EXTRA_MESSENGER="com.commonsware.android.downloader.EXTRA_MESSENGER";
public static final String EXTRA_MESSENGER="org.androidtitlan.itam.simpledownload.EXTRA_MESSENGER";
private HttpClient client=null;

public Downloader() {
Expand Down
170 changes: 101 additions & 69 deletions scriptCursoITAM.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,3 @@
##SimpleCall-----------------------------

package org.androidtitlan.motodev.simpledialer;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SimpleDialer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void dial(View v){
EditText number = (EditText)findViewById(R.id.number);
String toDial = "tel:"+number.getText().toString();
// startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(toDial)));
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(toDial)));
}
}
## XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number to dial:" />

<EditText
android:id="@+id/number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="true"
android:editable="true"
android:singleLine="true"
/>
</LinearLayout>
<Button
android:id="@+id/dial"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dial It!"
android:onClick="dial"
/>
</LinearLayout>

##End XML

##End SimpleCall---------------------


##SimpleService ---------

SimpleService.java
Expand Down Expand Up @@ -167,4 +99,104 @@ XML



End SimpleService------------
End SimpleService------------



------
SimpleDownloader

XML
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Do the Download"
android:onClick="doTheDownload"
/>




Downloader.java------

import android.app.Activity;
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.os.Messenger;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class Downloader extends IntentService {
public static final String EXTRA_MESSENGER="org.androidtitlan.itam.simpledownload.EXTRA_MESSENGER";
private HttpClient client=null;

public Downloader() {
super("Downloader");
}

@Override
public void onCreate() {
super.onCreate();
client=new DefaultHttpClient();
}

@Override
public void onDestroy() {
super.onDestroy();
client.getConnectionManager().shutdown();
}

@Override
public void onHandleIntent(Intent i) {
HttpGet getMethod=new HttpGet(i.getData().toString());
int result=Activity.RESULT_CANCELED;

try {
ResponseHandler<byte[]> responseHandler=new ByteArrayResponseHandler();
byte[] responseBody=client.execute(getMethod, responseHandler);
File output=new File(Environment.getExternalStorageDirectory(),
i.getData().getLastPathSegment());

if (output.exists()) {
output.delete();
}

FileOutputStream fos=new FileOutputStream(output.getPath());

fos.write(responseBody);
fos.close();
result=Activity.RESULT_OK;
}
catch (IOException e2) {
Log.e(getClass().getName(), "Exception in download", e2);
}

Bundle extras=i.getExtras();

if (extras!=null) {
Messenger messenger=(Messenger)extras.get(EXTRA_MESSENGER);
Message msg=Message.obtain();

msg.arg1=result;

try {
messenger.send(msg);
}
catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
}
}
Binary file added simpledownload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7b064d2

Please sign in to comment.