Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

done #65

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml → AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<service android:name=".DownloadService"/>

<activity android:name=".InitSplashActivity" >
<intent-filter>
Expand Down
24 changes: 0 additions & 24 deletions app/build.gradle

This file was deleted.

17 changes: 0 additions & 17 deletions app/proguard-rules.pro

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions build.gradle

This file was deleted.

18 changes: 0 additions & 18 deletions gradle.properties

This file was deleted.

6 changes: 0 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties

This file was deleted.

47 changes: 47 additions & 0 deletions java/ru/ifmo/android_2015/homework5/DownloadService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ru.ifmo.android_2015.homework5;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.io.File;
import java.io.IOException;


public class DownloadService extends IntentService {
public DownloadService() {
super("name");
}

@Override
protected void onHandleIntent(Intent intent) {
String url = intent.getStringExtra("url");
try {
downloadFile(this, url, new ProgressCallback() {
@Override
public void onProgressChanged(int progress) {
sendBroadcast(InitSplashActivity.DownloadState.DOWNLOADING, progress);
}
});
sendBroadcast(InitSplashActivity.DownloadState.DONE, 100);
} catch (IOException e) {
Log.e("DownloadService", "Failed to download file");
sendBroadcast(InitSplashActivity.DownloadState.ERROR, 100);
e.printStackTrace();
}
}

private void sendBroadcast(InitSplashActivity.DownloadState state, int progress) {
Intent intent = new Intent("MyFilter");
intent. putExtra("state", state);
intent.putExtra("progress", progress);
sendBroadcast(intent);
}

static void downloadFile(Context context, String url,
ProgressCallback progressCallback) throws IOException {
File destFile = FileUtils.createTempExternalFile(context, "gz");
DownloadUtils.downloadFile(url, destFile, progressCallback);
}
}
Loading