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;
}
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);
}
});
}
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));
}
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);
}
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;
}
Aggregations