• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Navigation voice changer app for Android


Commit MetaInfo

修订版e85fb10cd005afaad127e2733e8ece4ed360bcb8 (tree)
时间2013-08-03 01:58:08
作者HMML <hmml3939@gmai...>
CommiterHMML

Log Message

Count-up donwload counter.

更改概述

差异

--- a/src/jp/nekoteki/android/navivoicechanger/RemoteVoiceData.java
+++ b/src/jp/nekoteki/android/navivoicechanger/RemoteVoiceData.java
@@ -4,9 +4,15 @@ import java.io.File;
44 import java.io.FileOutputStream;
55 import java.io.IOException;
66 import java.io.InputStream;
7+import java.util.ArrayList;
8+import java.util.List;
79
810 import org.apache.http.HttpResponse;
11+import org.apache.http.NameValuePair;
12+import org.apache.http.client.entity.UrlEncodedFormEntity;
913 import org.apache.http.client.methods.HttpGet;
14+import org.apache.http.client.methods.HttpPost;
15+import org.apache.http.message.BasicNameValuePair;
1016
1117 import android.content.Context;
1218 import android.media.MediaPlayer;
@@ -99,6 +105,11 @@ public class RemoteVoiceData {
99105 this.downloadFile(this.archive_url, new File(datadir, VoiceData.ARCHIVE_FILENAME));
100106 this.downloadFile(this.preview_url, new File(datadir, VoiceData.PREVIEW_FILESNAME));
101107 this.downloadFile(this.ini_url, new File(datadir, VoiceData.DATA_INI));
108+ try {
109+ this.addDownloadCount(context);
110+ } catch (Exception e) {
111+ // Ignore ALL errors on count up....
112+ }
102113 this.setVoiceData(new VoiceData(datadir, context));
103114 }
104115
@@ -108,7 +119,7 @@ public class RemoteVoiceData {
108119 FileOutputStream os = null;
109120 AndroidHttpClient client = AndroidHttpClient.newInstance("NaviVoiceChanger");
110121 try {
111- Log.i(this.getClass().toString(), "Loading URL: "+this.ini_url);
122+ Log.i(this.getClass().toString(), "Loading URL: "+ url);
112123 HttpResponse res;
113124 res = client.execute(new HttpGet(url));
114125 if (res.getStatusLine().getStatusCode() != 200) {
@@ -128,6 +139,31 @@ public class RemoteVoiceData {
128139 }
129140 }
130141
142+ protected void addDownloadCount(Context context) throws IOException {
143+ AndroidHttpClient client = AndroidHttpClient.newInstance("NaviVoiceChanger");
144+ String url = Config.get(context, "server_url_base")
145+ + "/navi_voices/" + Integer.toString(this.getId()) + "/dl_log_entries.json";
146+
147+ Log.i(this.getClass().toString(), "Loading URL: "+ url);
148+ HttpResponse res;
149+
150+ HttpPost httppost = new HttpPost(url);
151+ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
152+ nameValuePairs.add(new BasicNameValuePair("dl_log_entry[ident]", Config.get(context, "ident")));
153+ httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
154+
155+ try {
156+ res = client.execute(httppost);
157+ } finally {
158+ client.close();
159+ }
160+ if (res.getStatusLine().getStatusCode() != 201) {
161+ String msg = "Server returns bad status code: "+ Integer.toString(res.getStatusLine().getStatusCode());
162+ Log.e(this.getClass().toString(), msg);
163+ throw new IOException(msg);
164+ }
165+ }
166+
131167 public void delete() {
132168 if (!this.isDownloaded()) return;
133169 this.getVoiceData().delete();