2011-10-26 5 views
1

안녕하세요, 저는 안드로이드 세계에 처음 입문했으며, 아마도 sdcard 또는 다운로드 폴더에 여러 이미지 (아마 지정된 URL)를 다운로드하는 작은 응용 프로그램을 만들려고 생각하고있었습니다. 그리고 그 이미지는 슬라이드 쇼로 볼 수 있습니다 그리고 뒤로). 또한 다운로드가 진행되는 동안 다운로드 진행률을 보여주는 진행률 표시 줄이 있어야합니다. 나는 하나의 이미지에 대해서만 할 수 있지만 복수는 할 수 없다. 여기여러 이미지를 다운로드하고 슬라이드 쇼처럼 표시하는 방법은 무엇입니까?

<?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"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 
    <Button 
     android:text="Start the download here" 
     android:id="@+id/startBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
    </Button> 

    <Button 
     android:text="Show Download Image" 
     android:id="@+id/startBtn1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:onClick="showDownload"> 
    </Button> 

가의 AndroidManifest.xml입니다

여기
import java.io.BufferedInputStream; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.net.URL; 
import java.net.URLConnection; 

import android.app.Activity; 
import android.app.Dialog; 

import android.app.ProgressDialog; 

import android.content.Intent; 
import android.net.Uri; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 


public class lab1_dhruv extends Activity{ 
    public static final int DIALOG_DOWNLOAD_PROGRESS = 0; 
     private Button startBtn; 
     private ProgressDialog mProgressDialog; 


     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
      startBtn = (Button)findViewById(R.id.startBtn); 
      startBtn.setOnClickListener(new OnClickListener(){ 
       public void onClick(View v) { 
        startDownload(); 
       } 
      }); 
     } 

     private void startDownload() { 

      //String url = "http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg"; 
      //new DownloadFileAsync().execute(url); 
      String[] imageList = {"http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg","http://fc03.deviantart.net/fs14/i/2007/086/9/1/Steve_Jobs_portrait_by_tumb.jpg","http://www.buzzreactor.com/sites/default/files/Bill-Gates1.jpg"}; 

      //String url1 = "http://fc03.deviantart.net/fs14/i/2007/086/9/1/Steve_Jobs_portrait_by_tumb.jpg"; 
      new DownloadFileAsync().execute(imageList); 


     } 
     @Override 
     protected Dialog onCreateDialog(int id) { 
      switch (id) { 
      case DIALOG_DOWNLOAD_PROGRESS: 
       mProgressDialog = new ProgressDialog(this); 
       mProgressDialog.setMessage("Downloading file.."); 
       mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
       mProgressDialog.setCancelable(false); 
       mProgressDialog.show(); 
       return mProgressDialog; 
      default: 
       return null; 
      } 
     } 

    class DownloadFileAsync extends AsyncTask<String, String, String> { 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      showDialog(DIALOG_DOWNLOAD_PROGRESS); 
     } 

     @Override 
     protected String doInBackground(String... aurl) { 
      int count; 

     try { 

     URL url = new URL(aurl[0]); 
     URLConnection conexion = url.openConnection(); 
     conexion.connect(); 

     int lenghtOfFile = conexion.getContentLength(); 
     Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile); 

     InputStream input = new BufferedInputStream(url.openStream()); 
     OutputStream output = new FileOutputStream("/sdcard/some_photo_from_gdansk_poland.jpg"); 

     byte data[] = new byte[1024]; 

     long total = 0; 

      while ((count = input.read(data)) != -1) { 
       total += count; 
       publishProgress(""+(int)((total*100)/lenghtOfFile)); 
       output.write(data, 0, count); 
      } 

      output.flush(); 
      output.close(); 
      input.close(); 
     } catch (Exception e) {} 
     return null; 

     } 
     protected void onProgressUpdate(String... progress) { 
      Log.d("ANDRO_ASYNC",progress[0]); 
      mProgressDialog.setProgress(Integer.parseInt(progress[0])); 
     } 

     @Override 
     protected void onPostExecute(String unused) { 
      dismissDialog(DIALOG_DOWNLOAD_PROGRESS); 
     } 
    } 

    public void showDownload(View view) { 
     Intent intent = new Intent(); 
     intent.setAction(android.content.Intent.ACTION_VIEW); 
     File file = new File("/sdcard/some_photo_from_gdansk_poland.jpg"); 
     intent.setDataAndType(Uri.fromFile(file), "image/*"); 
     startActivity(intent); 
     } 
    } 

이 main.xml에 : 다음은 내 코드입니다 -

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="cmpe235.lab1.dhruv.assignment" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="9" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".lab1_dhruv" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 
</manifest> 

내가 참조하거나 할 수있는 수있는 샘플 예제는 있는가 누구든지 내 코드에서 내가해야 할 일을 말해 준다. 나는 안드로이드에 익숙하지 않기 때문에 많이 알지 못합니다. 감사합니다

답변

1

갤러리 위젯을 사용하십시오. 다운로드 한 이미지로 갤러리 위젯을 제공하는 어댑터를 만들어야합니다.

:; 임이 페이지에 또는 Google에 갤러리를 구현하는 방법에 대한 코드를 찾을 수 있는지가)

자동으로 이미지 사이에 뒤집기 여러 가지 방법이 있습니다 당신은 갤러리를 구현 한 후

, 여기에 예입니다 Using the Android Gallery as an automated slideshow

+0

갤러리를 사용하면 나중에 수행 할 작업입니다. 나는 여러 파일을 다운로드하고 그에 따라 읽는 방법에 집착하고있다. 현재 많은 파일을 다운로드 할 수 있지만 sdcard 콘텐츠를 확인하는 방법을 모르겠다. – Dhruv

관련 문제