Search in sources :

Example 6 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase 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 7 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class CommunicationService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mNotificationHelper = new CommunicationNotificationHelper(this);
    mDatabase = new AccessDatabase(this);
    mNsdDiscovery = new NsdDiscovery(getApplicationContext(), getDatabase());
    mMediaScanner = new MediaScannerConnection(this, null);
    mHotspotUtils = HotspotUtils.getInstance(this);
    mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE)).createWifiLock(TAG);
    mReceive.setNotifyDelay(AppConfig.DEFAULT_NOTIFICATION_DELAY);
    mReceive.setBlockingObject(mBlockingObject);
    mSend.setNotifyDelay(AppConfig.DEFAULT_NOTIFICATION_DELAY);
    mSend.setBlockingObject(mBlockingObject);
    mMediaScanner.connect();
    mNsdDiscovery.registerService();
    if (getWifiLock() != null)
        getWifiLock().acquire();
    updateServiceState(getPreferences().getBoolean("trust_always", false));
    if (!AppUtils.checkRunningConditions(this) || !mCommunicationServer.start() || !mSeamlessServer.start())
        stopSelf();
    if (getHotspotUtils() instanceof HotspotUtils.OreoAPI && Build.VERSION.SDK_INT >= 26)
        ((HotspotUtils.OreoAPI) getHotspotUtils()).setSecondaryCallback(new WifiManager.LocalOnlyHotspotCallback() {

            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
                super.onStarted(reservation);
                sendHotspotStatus(reservation.getWifiConfiguration());
                if (getPreferences().getBoolean("hotspot_trust", false))
                    updateServiceState(true);
            }
        });
}
Also used : HotspotUtils(com.genonbeta.TrebleShot.util.HotspotUtils) NsdDiscovery(com.genonbeta.TrebleShot.util.NsdDiscovery) CommunicationNotificationHelper(com.genonbeta.TrebleShot.util.CommunicationNotificationHelper) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) MediaScannerConnection(android.media.MediaScannerConnection)

Example 8 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class TransactionGroupListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mDatabase = new AccessDatabase(getActivity());
    mFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
    if (getSelect() == null)
        setSelect(new SQLQuery.Select(AccessDatabase.TABLE_TRANSFERGROUP));
}
Also used : AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Example 9 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class TransactionListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mDatabase = new AccessDatabase(getActivity());
    mFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
}
Also used : AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Example 10 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class FileExplorerFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_fileexplorer, container, false);
    mDatabase = new AccessDatabase(getActivity());
    mPathView = view.findViewById(R.id.fragment_fileexplorer_pathresolver);
    mHomeButton = view.findViewById(R.id.fragment_fileexplorer_pathresolver_home);
    mLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    mPathAdapter = new FilePathResolverRecyclerAdapter();
    mFileListFragment = (FileListFragment) getChildFragmentManager().findFragmentById(R.id.fragment_fileexplorer_fragment_files);
    mPathAdapter.setOnClickListener(new PathResolverRecyclerAdapter.OnClickListener<DocumentFile>() {

        @Override
        public void onClick(PathResolverRecyclerAdapter.Holder<DocumentFile> holder) {
            requestPath(holder.index.object);
        }
    });
    mHomeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            requestPath(null);
        }
    });
    mFileListFragment.setOnPathChangedListener(new FileListFragment.OnPathChangedListener() {

        @Override
        public void onPathChanged(DocumentFile file) {
            mPathAdapter.goTo(file);
            mPathAdapter.notifyDataSetChanged();
            if (mPathAdapter.getItemCount() > 0)
                mPathView.smoothScrollToPosition(mPathAdapter.getItemCount() - 1);
        }
    });
    mPathView.setHasFixedSize(true);
    mPathView.setLayoutManager(mLayoutManager);
    mLayoutManager.setStackFromEnd(true);
    mPathView.setAdapter(mPathAdapter);
    return view;
}
Also used : DocumentFile(com.genonbeta.TrebleShot.io.DocumentFile) PathResolverRecyclerAdapter(com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Nullable(android.support.annotation.Nullable)

Aggregations

AccessDatabase (com.genonbeta.TrebleShot.database.AccessDatabase)11 View (android.view.View)4 NetworkDevice (com.genonbeta.TrebleShot.object.NetworkDevice)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 TextDrawable (com.amulyakhare.textdrawable.TextDrawable)2 PathResolverRecyclerAdapter (com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter)2 WorkerService (com.genonbeta.TrebleShot.service.WorkerService)2 IOException (java.io.IOException)2 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 MediaScannerConnection (android.media.MediaScannerConnection)1 Bundle (android.os.Bundle)1 ChooserTarget (android.service.chooser.ChooserTarget)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1