Cleanup and added icon
|
@ -2,7 +2,6 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="max.music_cyclon" >
|
package="max.music_cyclon" >
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
android:label="@string/title_activity_settings" >
|
android:label="Music Cyclon" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
@ -31,15 +30,6 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name=".ControlWidget" >
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.appwidget.provider"
|
|
||||||
android:resource="@xml/control_widget_info" />
|
|
||||||
</receiver>
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
package max.music_cyclon;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.appwidget.AppWidgetProvider;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.widget.RemoteViews;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ControlWidget extends AppWidgetProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
||||||
for (int appWidgetId : appWidgetIds) {
|
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
|
|
||||||
int appWidgetId) {
|
|
||||||
|
|
||||||
CharSequence widgetText = context.getString(R.string.control_button);
|
|
||||||
|
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.control_widget);
|
|
||||||
views.setTextViewText(R.id.control_button, widgetText);
|
|
||||||
|
|
||||||
Intent intent = new Intent(context, LibraryService.class);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
|
||||||
views.setOnClickPendingIntent(R.id.control_button, pendingIntent);
|
|
||||||
|
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,13 +10,17 @@ import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.util.JsonReader;
|
import android.util.JsonReader;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -42,11 +46,20 @@ public class LibraryService extends IntentService {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> fetchRandom(int amount) throws IOException {
|
public List<String> fetchRandom(String address, int amount) throws IOException {
|
||||||
URL url = new URL("http", host, port, "/random/" + amount);
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||||
InputStream in = url.openStream();
|
|
||||||
|
|
||||||
JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(in, "UTF-8")));
|
HttpGet httpGet = new HttpGet(address + "/random/" + amount);
|
||||||
|
|
||||||
|
|
||||||
|
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() != 200) {
|
||||||
|
Log.e("ERROR", "Server returned HTTP " + response.getStatusLine().getStatusCode());
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")));
|
||||||
|
|
||||||
ArrayList<String> items = new ArrayList<>();
|
ArrayList<String> items = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -75,6 +88,8 @@ public class LibraryService extends IntentService {
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(Integer.parseInt(settings.getString("threads", "2")));
|
ExecutorService executor = Executors.newFixedThreadPool(Integer.parseInt(settings.getString("threads", "2")));
|
||||||
|
|
||||||
|
String address = settings.getString("address", "127.0.0.1");
|
||||||
|
|
||||||
|
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
||||||
NotificationCompat.Builder builder = progressNotificationBuilder().setContentTitle("Aktualisiere Musik");
|
NotificationCompat.Builder builder = progressNotificationBuilder().setContentTitle("Aktualisiere Musik");
|
||||||
|
@ -94,7 +109,7 @@ public class LibraryService extends IntentService {
|
||||||
try {
|
try {
|
||||||
builder.setContentTitle("Fetching music information");
|
builder.setContentTitle("Fetching music information");
|
||||||
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
||||||
items = fetchRandom(Integer.parseInt(settings.getString("download", "10")));
|
items = fetchRandom(address, Integer.parseInt(settings.getString("download", "10")));
|
||||||
|
|
||||||
builder.setContentTitle("Cleaning library");
|
builder.setContentTitle("Cleaning library");
|
||||||
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
||||||
|
@ -119,7 +134,7 @@ public class LibraryService extends IntentService {
|
||||||
CountDownLatch latch = new CountDownLatch(items.size());
|
CountDownLatch latch = new CountDownLatch(items.size());
|
||||||
|
|
||||||
for (int i = 0, size = items.size(); i < size; i++) {
|
for (int i = 0, size = items.size(); i < size; i++) {
|
||||||
executor.submit(new ProcessTask(latch, items.get(i), tracker,
|
executor.submit(new ProcessTask(address, latch, items.get(i), tracker,
|
||||||
current, items.size(), builder, notificationManager));
|
current, items.size(), builder, notificationManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class PowerConnectionReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean start = Boolean.parseBoolean(settings.getString("start_charging", "false"));
|
boolean start = settings.getBoolean("start_charging", false);
|
||||||
|
|
||||||
if (!start) {
|
if (!start) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.zip.Adler32;
|
||||||
|
|
||||||
public class ProcessTask implements Runnable {
|
public class ProcessTask implements Runnable {
|
||||||
|
|
||||||
|
private String address;
|
||||||
private final CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
|
|
||||||
private final String item;
|
private final String item;
|
||||||
|
@ -32,8 +33,9 @@ public class ProcessTask implements Runnable {
|
||||||
private final NotificationCompat.Builder builder;
|
private final NotificationCompat.Builder builder;
|
||||||
private final NotificationManagerCompat notificationManager;
|
private final NotificationManagerCompat notificationManager;
|
||||||
|
|
||||||
public ProcessTask(CountDownLatch latch, String item, FileTracker tracker,
|
public ProcessTask(String address, CountDownLatch latch, String item, FileTracker tracker,
|
||||||
AtomicInteger current, int maximum,NotificationCompat.Builder builder, NotificationManagerCompat notificationCompat) {
|
AtomicInteger current, int maximum, NotificationCompat.Builder builder, NotificationManagerCompat notificationCompat) {
|
||||||
|
this.address = address;
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
|
|
||||||
|
@ -48,28 +50,30 @@ public class ProcessTask implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
File root = new File(Environment.getExternalStorageDirectory(), "library");
|
File root = new File(Environment.getExternalStorageDirectory(), "library");
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File target = new File(root, item);
|
File target = new File(root, item);
|
||||||
Adler32 checksum = new Adler32();
|
Adler32 checksum = new Adler32();
|
||||||
|
|
||||||
InputStream input = prepareConnection(item);
|
InputStream input = prepareConnection(address, item);
|
||||||
|
|
||||||
if (input == null) {
|
if (input != null) {
|
||||||
return;
|
|
||||||
|
FileOutputStream output = FileUtils.openOutputStream(target);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[4 * 1024];
|
||||||
|
int n;
|
||||||
|
while (-1 != (n = input.read(buffer))) {
|
||||||
|
output.write(buffer, 0, n);
|
||||||
|
checksum.update(buffer, 0, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.flush();
|
||||||
|
output.close();
|
||||||
|
input.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOutputStream output = FileUtils.openOutputStream(target);
|
// todo else error
|
||||||
|
|
||||||
byte[] buffer = new byte[4 * 1024];
|
|
||||||
int n;
|
|
||||||
while (-1 != (n = input.read(buffer))) {
|
|
||||||
output.write(buffer, 0, n);
|
|
||||||
checksum.update(buffer, 0, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.flush();
|
|
||||||
output.close();
|
|
||||||
input.close();
|
|
||||||
|
|
||||||
tracker.track(target, checksum.getValue());
|
tracker.track(target, checksum.getValue());
|
||||||
|
|
||||||
|
@ -84,26 +88,10 @@ public class ProcessTask implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream prepareConnection(String item) throws IOException {
|
public InputStream prepareConnection(String address, String item) throws IOException {
|
||||||
// URL url = new URL("http", "max-arch", 5785, "/get");
|
|
||||||
//
|
|
||||||
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
// connection.setRequestMethod("POST");
|
|
||||||
// connection.setDoOutput(true);
|
|
||||||
//
|
|
||||||
// PrintWriter output = new PrintWriter(connection.getOutputStream());
|
|
||||||
// output.write(item);
|
|
||||||
// output.flush();
|
|
||||||
//
|
|
||||||
// if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
||||||
// Log.e("ERROR", "Server returned HTTP " + connection.getResponseCode()
|
|
||||||
// + " " + connection.getResponseMessage());
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost("http://max-arch:5785/get");
|
HttpPost httpPost = new HttpPost(address + "/get");
|
||||||
|
|
||||||
httpPost.setEntity(new ByteArrayEntity(item.getBytes("UTF-8")));
|
httpPost.setEntity(new ByteArrayEntity(item.getBytes("UTF-8")));
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
|
|
||||||
public class SettingsActivity extends PreferenceActivity {
|
public class SettingsActivity extends PreferenceActivity {
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
|
||||||
tools:context="max.music_cyclon.SettingsActivity">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Music"
|
|
||||||
android:id="@+id/button"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="118dp" />
|
|
||||||
</RelativeLayout>
|
|
|
@ -1,21 +0,0 @@
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="#09C"
|
|
||||||
android:padding="@dimen/widget_margin">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/control_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_margin="8dp"
|
|
||||||
android:background="#09C"
|
|
||||||
android:contentDescription="@string/control_button"
|
|
||||||
android:text="@string/control_button"
|
|
||||||
android:textColor="#ffffff"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:textStyle="bold|italic" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 16 KiB |
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Refer to App Widget Documentation for margin information
|
|
||||||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
|
|
||||||
-->
|
|
||||||
<dimen name="widget_margin">0dp</dimen>
|
|
||||||
|
|
||||||
</resources>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<resources>
|
|
||||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
|
||||||
(such as screen margins) for screens with more than 820dp of available width. This
|
|
||||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
|
||||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
|
||||||
</resources>
|
|
|
@ -1,13 +0,0 @@
|
||||||
<resources>
|
|
||||||
<string-array name="listArray">
|
|
||||||
<item>Headings</item>
|
|
||||||
<item>Headings and Details</item>
|
|
||||||
<item>All Data</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="listValues">
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>3</item>
|
|
||||||
</string-array>
|
|
||||||
</resources>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<resources>
|
|
||||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
|
||||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
|
||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Refer to App Widget Documentation for margin information
|
|
||||||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
|
|
||||||
-->
|
|
||||||
<dimen name="widget_margin">8dp</dimen>
|
|
||||||
</resources>
|
|
|
@ -1,6 +1,3 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">music-cyclon</string>
|
<string name="app_name">music-cyclon</string>
|
||||||
|
|
||||||
<string name="control_button">MUSIC</string>
|
|
||||||
<string name="title_activity_settings">Title</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:initialKeyguardLayout="@layout/control_widget"
|
|
||||||
android:initialLayout="@layout/control_widget"
|
|
||||||
android:minHeight="40dp"
|
|
||||||
android:minWidth="40dp"
|
|
||||||
android:previewImage="@drawable/example_appwidget_preview"
|
|
||||||
android:resizeMode="horizontal|vertical"
|
|
||||||
android:updatePeriodMillis="86400000"
|
|
||||||
android:widgetCategory="home_screen" />
|
|
|
@ -6,6 +6,14 @@
|
||||||
android:summary="Starts the download"
|
android:summary="Starts the download"
|
||||||
android:title="Start Service" />
|
android:title="Start Service" />
|
||||||
|
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="http://localhost:5785"
|
||||||
|
android:inputType="text"
|
||||||
|
android:key="address"
|
||||||
|
android:summary="Address of the synchronisation server"
|
||||||
|
android:title="Address" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="2"
|
android:defaultValue="2"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
|
|