2014-11-16 23:14:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Albert Vaca Cintora <albertvaka@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-21 19:59:31 -08:00
|
|
|
package org.kde.kdeconnect.Plugins.SharePlugin;
|
2013-09-18 17:31:56 +02:00
|
|
|
|
2015-01-15 22:57:06 -08:00
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationManager;
|
2013-09-18 17:31:56 +02:00
|
|
|
import android.content.ContentResolver;
|
2015-01-15 22:57:06 -08:00
|
|
|
import android.content.Context;
|
2013-09-18 17:31:56 +02:00
|
|
|
import android.content.Intent;
|
2015-01-15 22:57:06 -08:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Resources;
|
2013-09-20 15:57:44 +02:00
|
|
|
import android.database.Cursor;
|
2013-09-18 17:31:56 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2015-01-15 22:57:06 -08:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.preference.PreferenceManager;
|
2013-09-20 15:57:44 +02:00
|
|
|
import android.provider.MediaStore;
|
2015-01-15 22:57:06 -08:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2013-09-20 19:05:04 +02:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2013-09-18 17:31:56 +02:00
|
|
|
import android.util.Log;
|
2013-09-20 19:05:04 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2013-09-20 15:57:44 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
2013-09-18 17:31:56 +02:00
|
|
|
|
2013-09-20 15:57:44 +02:00
|
|
|
import org.kde.kdeconnect.BackgroundService;
|
|
|
|
import org.kde.kdeconnect.Device;
|
|
|
|
import org.kde.kdeconnect.NetworkPackage;
|
|
|
|
import org.kde.kdeconnect.UserInterface.List.EntryItem;
|
|
|
|
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
|
|
|
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
|
|
|
import org.kde.kdeconnect_tp.R;
|
2013-09-18 17:31:56 +02:00
|
|
|
|
2013-10-14 18:32:33 +02:00
|
|
|
import java.io.File;
|
2013-09-18 17:31:56 +02:00
|
|
|
import java.io.InputStream;
|
2013-09-27 02:58:16 +02:00
|
|
|
import java.net.URL;
|
2013-09-20 15:57:44 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
2013-09-18 17:31:56 +02:00
|
|
|
|
|
|
|
|
2015-01-31 00:16:06 -08:00
|
|
|
public class ShareActivity extends ActionBarActivity {
|
2013-09-20 15:57:44 +02:00
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
private MenuItem menuProgress;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.main, menu);
|
|
|
|
menuProgress = menu.findItem(R.id.menu_progress);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_refresh:
|
|
|
|
updateComputerList();
|
2015-01-31 00:16:06 -08:00
|
|
|
BackgroundService.RunCommand(ShareActivity.this, new BackgroundService.InstanceCallback() {
|
2013-09-20 19:05:04 +02:00
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
|
|
|
service.onNetworkChange();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
item.setVisible(false);
|
|
|
|
menuProgress.setVisible(true);
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try { Thread.sleep(1500); } catch (InterruptedException e) { }
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
menuProgress.setVisible(false);
|
|
|
|
item.setVisible(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateComputerList() {
|
2013-09-20 15:57:44 +02:00
|
|
|
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
String action = intent.getAction();
|
|
|
|
if (!Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
2013-09-20 15:57:44 +02:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(final BackgroundService service) {
|
|
|
|
|
|
|
|
Collection<Device> devices = service.getDevices().values();
|
|
|
|
final ArrayList<Device> devicesList = new ArrayList<Device>();
|
|
|
|
final ArrayList<ListAdapter.Item> items = new ArrayList<ListAdapter.Item>();
|
|
|
|
|
|
|
|
items.add(new SectionItem(getString(R.string.share_to)));
|
|
|
|
|
|
|
|
for (Device d : devices) {
|
|
|
|
if (d.isReachable() && d.isPaired()) {
|
|
|
|
devicesList.add(d);
|
|
|
|
items.add(new EntryItem(d.getName()));
|
|
|
|
}
|
2013-09-18 17:31:56 +02:00
|
|
|
}
|
|
|
|
|
2013-09-20 15:57:44 +02:00
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ListView list = (ListView) findViewById(R.id.listView1);
|
2015-01-31 00:16:06 -08:00
|
|
|
list.setAdapter(new ListAdapter(ShareActivity.this, items));
|
2013-09-20 15:57:44 +02:00
|
|
|
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
Device device = devicesList.get(i-1); //NOTE: -1 because of the title!
|
2013-09-20 15:57:44 +02:00
|
|
|
|
|
|
|
Bundle extras = intent.getExtras();
|
|
|
|
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
try {
|
2013-09-20 15:57:44 +02:00
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
ArrayList<Uri> uriList;
|
|
|
|
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
|
|
|
|
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
|
|
} else {
|
|
|
|
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
|
|
|
uriList = new ArrayList<Uri>();
|
|
|
|
uriList.add(uri);
|
|
|
|
}
|
2013-09-20 15:57:44 +02:00
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
queuedSendUriList(device, uriList);
|
2013-09-20 15:57:44 +02:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Exception");
|
2015-01-22 21:30:32 -08:00
|
|
|
e.printStackTrace();
|
2013-09-20 15:57:44 +02:00
|
|
|
}
|
2013-09-27 02:58:16 +02:00
|
|
|
|
2013-09-20 15:57:44 +02:00
|
|
|
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
|
2013-09-27 02:58:16 +02:00
|
|
|
String text = extras.getString(Intent.EXTRA_TEXT);
|
2014-12-21 20:31:29 -08:00
|
|
|
String subject = extras.getString(Intent.EXTRA_SUBJECT);
|
|
|
|
|
2014-12-21 20:32:12 -08:00
|
|
|
//Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
|
2014-12-21 20:31:29 -08:00
|
|
|
if (subject != null && subject.endsWith("YouTube")) {
|
|
|
|
int index = text.indexOf(": http://youtu.be/");
|
|
|
|
if (index > 0) {
|
|
|
|
text = text.substring(index+2); //Skip ": "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
boolean isUrl;
|
|
|
|
try {
|
|
|
|
new URL(text);
|
|
|
|
isUrl = true;
|
|
|
|
} catch(Exception e) {
|
|
|
|
isUrl = false;
|
|
|
|
}
|
2013-10-01 03:25:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
2013-09-27 02:58:16 +02:00
|
|
|
if (isUrl) {
|
|
|
|
np.set("url", text);
|
|
|
|
} else {
|
|
|
|
np.set("text", text);
|
|
|
|
}
|
|
|
|
device.sendPackage(np);
|
2013-09-20 15:57:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
|
2013-09-20 15:57:44 +02:00
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
finish();
|
2013-09-20 15:57:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-18 17:31:56 +02:00
|
|
|
}
|
2013-09-20 15:57:44 +02:00
|
|
|
});
|
2013-09-20 19:05:04 +02:00
|
|
|
}
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
private void queuedSendUriList(final Device device, final ArrayList<Uri> uriList) {
|
|
|
|
try {
|
|
|
|
Uri uri = uriList.remove(0);
|
|
|
|
ContentResolver cr = getContentResolver();
|
|
|
|
InputStream inputStream = cr.openInputStream(uri);
|
|
|
|
|
2013-10-01 03:25:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
2015-01-22 21:24:01 -08:00
|
|
|
long size = -1;
|
2013-09-27 02:58:16 +02:00
|
|
|
|
2015-01-15 22:57:06 -08:00
|
|
|
final NotificationManager notificationManager = (NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
final int notificationId = (int)System.currentTimeMillis();
|
|
|
|
final NotificationCompat.Builder builder ;
|
|
|
|
Resources res = getApplicationContext().getResources();
|
|
|
|
builder = new NotificationCompat.Builder(getApplicationContext())
|
|
|
|
.setContentTitle(res.getString(R.string.outgoing_file_title, device.getName()))
|
|
|
|
.setTicker(res.getString(R.string.outgoing_file_title, device.getName()))
|
|
|
|
.setSmallIcon(android.R.drawable.stat_sys_upload)
|
|
|
|
.setAutoCancel(true)
|
|
|
|
.setOngoing(true)
|
|
|
|
.setProgress(100,0,true);
|
|
|
|
notificationManager.notify(notificationId,builder.build());
|
|
|
|
|
|
|
|
final Handler progressBarHandler = new Handler(Looper.getMainLooper());
|
|
|
|
|
2013-10-14 18:32:33 +02:00
|
|
|
if (uri.getScheme().equals("file")) {
|
|
|
|
// file:// is a non media uri, so we cannot query the ContentProvider
|
2013-11-23 01:29:22 +01:00
|
|
|
|
|
|
|
np.set("filename", uri.getLastPathSegment());
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
try {
|
2015-01-22 21:24:01 -08:00
|
|
|
size = new File(uri.getPath()).length();
|
2013-10-14 18:32:33 +02:00
|
|
|
} catch(Exception e) {
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Could not obtain file size");
|
2015-01-22 21:30:32 -08:00
|
|
|
e.printStackTrace();
|
2013-10-14 18:32:33 +02:00
|
|
|
}
|
2013-09-27 02:58:16 +02:00
|
|
|
|
2015-04-04 13:53:46 -07:00
|
|
|
np.setPayload(inputStream, size);
|
|
|
|
|
2013-10-14 18:32:33 +02:00
|
|
|
}else{
|
|
|
|
// Probably a content:// uri, so we query the Media content provider
|
|
|
|
|
2013-11-23 01:29:22 +01:00
|
|
|
Cursor cursor = null;
|
2013-10-14 18:32:33 +02:00
|
|
|
try {
|
2013-11-23 01:29:22 +01:00
|
|
|
String[] proj = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DISPLAY_NAME };
|
|
|
|
cursor = getContentResolver().query(uri, proj, null, null, null);
|
2013-10-14 18:32:33 +02:00
|
|
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
|
|
|
|
cursor.moveToFirst();
|
|
|
|
String path = cursor.getString(column_index);
|
|
|
|
np.set("filename", Uri.parse(path).getLastPathSegment());
|
2015-01-22 21:24:01 -08:00
|
|
|
size = new File(path).length();
|
2014-10-18 20:22:39 -07:00
|
|
|
} catch(Exception unused) {
|
2013-11-23 01:29:22 +01:00
|
|
|
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Could not resolve media to a file, trying to get info as media");
|
2013-11-23 01:29:22 +01:00
|
|
|
|
2013-10-14 18:32:33 +02:00
|
|
|
try {
|
|
|
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
|
|
|
|
cursor.moveToFirst();
|
|
|
|
String name = cursor.getString(column_index);
|
|
|
|
np.set("filename", name);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Could not obtain file name");
|
2013-10-14 18:32:33 +02:00
|
|
|
}
|
2013-11-23 01:29:22 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);
|
|
|
|
cursor.moveToFirst();
|
|
|
|
//For some reason this size can differ from the actual file size!
|
|
|
|
size = cursor.getInt(column_index);
|
|
|
|
} catch(Exception e) {
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Could not obtain file size");
|
2015-01-22 21:30:32 -08:00
|
|
|
e.printStackTrace();
|
2013-11-23 01:29:22 +01:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
cursor.close();
|
2013-10-14 18:32:33 +02:00
|
|
|
}
|
|
|
|
|
2013-11-23 01:29:22 +01:00
|
|
|
np.setPayload(inputStream, size);
|
|
|
|
|
2013-10-14 18:32:33 +02:00
|
|
|
}
|
2013-10-05 17:23:27 +02:00
|
|
|
|
2015-01-15 22:57:06 -08:00
|
|
|
final String filename = np.getString("filename");
|
|
|
|
|
|
|
|
builder.setContentText(res.getString(R.string.outgoing_file_text,filename));
|
|
|
|
notificationManager.notify(notificationId,builder.build());
|
|
|
|
|
|
|
|
device.sendPackage(np, new Device.SendPackageStatusCallback() {
|
|
|
|
|
2015-01-29 23:57:58 -08:00
|
|
|
int prevProgress = 0;
|
2015-01-15 22:57:06 -08:00
|
|
|
|
|
|
|
@Override
|
2015-01-29 23:57:58 -08:00
|
|
|
public void onProgressChanged(final int progress) {
|
|
|
|
if (progress != prevProgress) {
|
|
|
|
prevProgress = progress;
|
2015-01-15 22:57:06 -08:00
|
|
|
progressBarHandler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-01-29 23:57:58 -08:00
|
|
|
builder.setProgress(100, progress, false);
|
2015-01-15 22:57:06 -08:00
|
|
|
notificationManager.notify(notificationId, builder.build());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
@Override
|
2015-01-29 23:57:58 -08:00
|
|
|
public void onSuccess() {
|
2015-01-15 22:57:06 -08:00
|
|
|
progressBarHandler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Resources res = getApplicationContext().getResources();
|
|
|
|
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(getApplicationContext())
|
|
|
|
.setContentTitle(res.getString(R.string.sent_file_title, device.getName()))
|
|
|
|
.setContentText(res.getString(R.string.sent_file_text, filename))
|
|
|
|
.setTicker(res.getString(R.string.sent_file_title, device.getName()))
|
|
|
|
.setSmallIcon(android.R.drawable.stat_sys_upload_done)
|
|
|
|
.setOngoing(false)
|
|
|
|
.setAutoCancel(true);
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
if (prefs.getBoolean("share_notification_preference", true)) {
|
|
|
|
builder1.setDefaults(Notification.DEFAULT_ALL);
|
|
|
|
}
|
|
|
|
notificationManager.notify(notificationId, builder1.build());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
if (!uriList.isEmpty()) queuedSendUriList(device, uriList);
|
2015-01-31 00:16:06 -08:00
|
|
|
else Log.i("ShareActivity", "All files sent");
|
2013-09-27 02:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-29 23:57:58 -08:00
|
|
|
public void onFailure(Throwable e) {
|
2015-01-15 22:57:06 -08:00
|
|
|
progressBarHandler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Resources res = getApplicationContext().getResources();
|
|
|
|
NotificationCompat.Builder builder2 = new NotificationCompat.Builder(getApplicationContext())
|
|
|
|
.setContentTitle(res.getString(R.string.sent_file_failed_title, device.getName()))
|
|
|
|
.setContentText(res.getString(R.string.sent_file_failed_text, filename))
|
|
|
|
.setTicker(res.getString(R.string.sent_file_title, device.getName()))
|
|
|
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
|
|
|
.setOngoing(false)
|
|
|
|
.setAutoCancel(true);
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
if (prefs.getBoolean("share_notification_preference", true)) {
|
|
|
|
builder2.setDefaults(Notification.DEFAULT_ALL);
|
|
|
|
}
|
|
|
|
notificationManager.notify(notificationId, builder2.build());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Failed to send file");
|
2013-09-27 02:58:16 +02:00
|
|
|
}
|
|
|
|
});
|
2013-10-14 18:32:33 +02:00
|
|
|
|
2013-09-27 02:58:16 +02:00
|
|
|
} catch (Exception e) {
|
2015-01-31 00:16:06 -08:00
|
|
|
Log.e("ShareActivity", "Exception sending files");
|
2015-01-22 21:30:32 -08:00
|
|
|
e.printStackTrace();
|
2013-09-27 02:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-12-21 19:59:31 -08:00
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
|
|
|
service.onNetworkChange();
|
|
|
|
service.setDeviceListChangedCallback(new BackgroundService.DeviceListChangedCallback() {
|
|
|
|
@Override
|
|
|
|
public void onDeviceListChanged() {
|
|
|
|
updateComputerList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-09-20 15:57:44 +02:00
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
|
|
|
service.setDeviceListChangedCallback(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
super.onStop();
|
|
|
|
}
|
2013-09-18 17:31:56 +02:00
|
|
|
|
2013-09-20 19:05:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
updateComputerList();
|
2013-09-18 17:31:56 +02:00
|
|
|
}
|
2014-12-21 19:59:31 -08:00
|
|
|
|
2013-09-18 17:31:56 +02:00
|
|
|
}
|