Navigation voice changer app for Android
修订版 | e85fb10cd005afaad127e2733e8ece4ed360bcb8 (tree) |
---|---|
时间 | 2013-08-03 01:58:08 |
作者 | HMML <hmml3939@gmai...> |
Commiter | HMML |
Count-up donwload counter.
@@ -4,9 +4,15 @@ import java.io.File; | ||
4 | 4 | import java.io.FileOutputStream; |
5 | 5 | import java.io.IOException; |
6 | 6 | import java.io.InputStream; |
7 | +import java.util.ArrayList; | |
8 | +import java.util.List; | |
7 | 9 | |
8 | 10 | import org.apache.http.HttpResponse; |
11 | +import org.apache.http.NameValuePair; | |
12 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | |
9 | 13 | import org.apache.http.client.methods.HttpGet; |
14 | +import org.apache.http.client.methods.HttpPost; | |
15 | +import org.apache.http.message.BasicNameValuePair; | |
10 | 16 | |
11 | 17 | import android.content.Context; |
12 | 18 | import android.media.MediaPlayer; |
@@ -99,6 +105,11 @@ public class RemoteVoiceData { | ||
99 | 105 | this.downloadFile(this.archive_url, new File(datadir, VoiceData.ARCHIVE_FILENAME)); |
100 | 106 | this.downloadFile(this.preview_url, new File(datadir, VoiceData.PREVIEW_FILESNAME)); |
101 | 107 | 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 | + } | |
102 | 113 | this.setVoiceData(new VoiceData(datadir, context)); |
103 | 114 | } |
104 | 115 |
@@ -108,7 +119,7 @@ public class RemoteVoiceData { | ||
108 | 119 | FileOutputStream os = null; |
109 | 120 | AndroidHttpClient client = AndroidHttpClient.newInstance("NaviVoiceChanger"); |
110 | 121 | try { |
111 | - Log.i(this.getClass().toString(), "Loading URL: "+this.ini_url); | |
122 | + Log.i(this.getClass().toString(), "Loading URL: "+ url); | |
112 | 123 | HttpResponse res; |
113 | 124 | res = client.execute(new HttpGet(url)); |
114 | 125 | if (res.getStatusLine().getStatusCode() != 200) { |
@@ -128,6 +139,31 @@ public class RemoteVoiceData { | ||
128 | 139 | } |
129 | 140 | } |
130 | 141 | |
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 | + | |
131 | 167 | public void delete() { |
132 | 168 | if (!this.isDownloaded()) return; |
133 | 169 | this.getVoiceData().delete(); |