use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class AppUtils method getLocalDevice.
public static NetworkDevice getLocalDevice(Context context) {
NetworkDevice device = new NetworkDevice(getDeviceSerial(context));
device.brand = Build.BRAND;
device.model = Build.MODEL;
device.nickname = AppUtils.getLocalDeviceName(context);
device.isRestricted = false;
device.isLocalAddress = true;
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName, 0);
device.versionNumber = packageInfo.versionCode;
device.versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return device;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class CommunicationNotificationHelper method notifyFileTransaction.
public DynamicNotification notifyFileTransaction(CommunicationService.ProcessHolder processHolder) throws Exception {
if (processHolder.notification == null) {
NetworkDevice device = new NetworkDevice(processHolder.group.deviceId);
getUtils().getDatabase().reconstruct(device);
boolean isIncoming = TransactionObject.Type.INCOMING.equals(processHolder.transactionObject.type);
processHolder.notification = getUtils().buildDynamicNotification(processHolder.transactionObject.groupId, NotificationUtils.NOTIFICATION_CHANNEL_LOW);
Intent cancelIntent = new Intent(getContext(), CommunicationService.class);
cancelIntent.setAction(CommunicationService.ACTION_CANCEL_JOB);
cancelIntent.putExtra(CommunicationService.EXTRA_REQUEST_ID, processHolder.transactionObject.requestId);
cancelIntent.putExtra(CommunicationService.EXTRA_GROUP_ID, processHolder.transactionObject.groupId);
cancelIntent.putExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, processHolder.notification.getNotificationId());
processHolder.notification.setSmallIcon(isIncoming ? android.R.drawable.stat_sys_download : android.R.drawable.stat_sys_upload).setContentText(getContext().getString(isIncoming ? R.string.text_receiving : R.string.text_sending)).setContentInfo(device.nickname).setContentIntent(PendingIntent.getActivity(getContext(), AppUtils.getUniqueNumber(), new Intent(getContext(), TransactionActivity.class).setAction(TransactionActivity.ACTION_LIST_TRANSFERS).putExtra(TransactionActivity.EXTRA_GROUP_ID, processHolder.transactionObject.groupId), 0)).setOngoing(true).addAction(R.drawable.ic_clear_white_24dp, getContext().getString(isIncoming ? R.string.butn_cancelReceiving : R.string.butn_cancelSending), PendingIntent.getService(getContext(), AppUtils.getUniqueNumber(), cancelIntent, 0));
}
processHolder.notification.setContentTitle(processHolder.transactionObject.friendlyName);
return processHolder.notification;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class TransactionGroupListAdapter method onLoad.
@Override
public ArrayList<PreloadedGroup> onLoad() {
ArrayList<PreloadedGroup> list = mDatabase.castQuery(getSelect(), PreloadedGroup.class);
Collections.sort(list, getDefaultComparator());
for (PreloadedGroup group : list) {
try {
NetworkDevice device = new NetworkDevice(group.deviceId);
mDatabase.reconstruct(device);
group.deviceName = device.nickname;
} catch (Exception e) {
group.deviceName = "-";
}
mDatabase.calculateTransactionSize(group.groupId, group.index);
group.totalCount = group.index.incomingCount + group.index.outgoingCount;
group.totalBytes = group.index.incoming + group.index.outgoing;
group.totalFiles = getContext().getResources().getQuantityString(R.plurals.text_files, group.totalCount, group.totalCount);
group.totalSize = FileUtils.sizeExpression(group.totalBytes, false);
}
return list;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class DeviceChooserService method onGetChooserTargets.
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
AccessDatabase database = new AccessDatabase(getApplicationContext());
ArrayList<ChooserTarget> list = new ArrayList<>();
for (NetworkDevice device : database.castQuery(new SQLQuery.Select(AccessDatabase.TABLE_DEVICES), NetworkDevice.class)) {
if (device.isLocalAddress)
continue;
Bundle bundle = new Bundle();
bundle.putString(ShareActivity.EXTRA_DEVICE_ID, device.deviceId);
String firstLetters = TextUtils.getFirstLetters(device.nickname, 1);
TextDrawable textImage = TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(this, R.color.networkDeviceRipple), 100);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
textImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
textImage.draw(canvas);
float result = (float) device.lastUsageTime / (float) System.currentTimeMillis();
list.add(new ChooserTarget(device.nickname, Icon.createWithBitmap(bitmap), result, targetActivityName, bundle));
}
return list;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class NetworkDeviceLoader method loadFrom.
public static NetworkDevice loadFrom(AccessDatabase database, JSONObject object) throws JSONException {
JSONObject deviceInfo = object.getJSONObject(Keyword.DEVICE_INFO);
JSONObject appInfo = object.getJSONObject(Keyword.APP_INFO);
NetworkDevice device = new NetworkDevice(deviceInfo.getString(Keyword.DEVICE_INFO_SERIAL));
try {
database.reconstruct(device);
} catch (Exception e) {
}
device.brand = deviceInfo.getString(Keyword.DEVICE_INFO_BRAND);
device.model = deviceInfo.getString(Keyword.DEVICE_INFO_MODEL);
device.nickname = deviceInfo.getString(Keyword.DEVICE_INFO_USER);
device.lastUsageTime = System.currentTimeMillis();
device.versionNumber = appInfo.getInt(Keyword.APP_INFO_VERSION_CODE);
device.versionName = appInfo.getString(Keyword.APP_INFO_VERSION_NAME);
if (device.nickname.length() > AppConfig.NICKNAME_LENGTH_MAX)
device.nickname = device.nickname.substring(0, AppConfig.NICKNAME_LENGTH_MAX - 1);
return device;
}
Aggregations