Search in sources :

Example 11 with NetworkDevice

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;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice)

Example 12 with NetworkDevice

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;
}
Also used : NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 13 with NetworkDevice

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;
}
Also used : NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice)

Example 14 with NetworkDevice

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;
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Bundle(android.os.Bundle) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) Canvas(android.graphics.Canvas) ArrayList(java.util.ArrayList) SQLQuery(com.genonbeta.android.database.SQLQuery) Bitmap(android.graphics.Bitmap) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) ChooserTarget(android.service.chooser.ChooserTarget)

Example 15 with NetworkDevice

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;
}
Also used : JSONObject(org.json.JSONObject) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) JSONException(org.json.JSONException) ConnectException(java.net.ConnectException)

Aggregations

NetworkDevice (com.genonbeta.TrebleShot.object.NetworkDevice)17 JSONException (org.json.JSONException)5 AccessDatabase (com.genonbeta.TrebleShot.database.AccessDatabase)4 IOException (java.io.IOException)4 ConnectException (java.net.ConnectException)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 TextDrawable (com.amulyakhare.textdrawable.TextDrawable)3 ArrayList (java.util.ArrayList)3 Intent (android.content.Intent)2 ServiceConnection (android.content.ServiceConnection)2 NavigationView (android.support.design.widget.NavigationView)2 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)2 Toolbar (android.support.v7.widget.Toolbar)2 NetworkDeviceListAdapter (com.genonbeta.TrebleShot.adapter.NetworkDeviceListAdapter)2 DeviceInfoDialog (com.genonbeta.TrebleShot.dialog.DeviceInfoDialog)2 WorkerService (com.genonbeta.TrebleShot.service.WorkerService)2 PowerfulActionMode (com.genonbeta.TrebleShot.widget.PowerfulActionMode)2 PendingIntent (android.app.PendingIntent)1