use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class TransactionActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transaction);
mDatabase = new AccessDatabase(this);
mTransactionFragment = (TransactionListFragment) getSupportFragmentManager().findFragmentById(R.id.activity_transaction_listfragment_transaction);
mPathView = findViewById(R.id.activity_transaction_explorer_recycler);
mHomeButton = findViewById(R.id.activity_transaction_explorer_image_home);
mPowafulActionMode = findViewById(R.id.activity_transaction_action_mode);
// mPowafulActionMode.setContainerLayout(findViewById(R.id.activity_transaction_action_mode_container));
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = findViewById(R.id.drawer_layout);
if (mDrawerLayout != null) {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.text_navigationDrawerOpen, R.string.text_navigationDrawerClose);
mDrawerLayout.addDrawerListener(toggle);
toggle.syncState();
}
mNavigationView = findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
mPathView.setHasFixedSize(true);
mFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
mPathAdapter = new TransactionPathResolverRecyclerAdapter();
mPathView.setLayoutManager(mLayoutManager);
mLayoutManager.setStackFromEnd(true);
mPathView.setAdapter(mPathAdapter);
mPowafulActionMode.setOnSelectionTaskListener(new PowerfulActionMode.OnSelectionTaskListener() {
@Override
public void onSelectionTask(boolean started, PowerfulActionMode actionMode) {
toolbar.setVisibility(!started ? View.VISIBLE : View.GONE);
}
});
mPathAdapter.setOnClickListener(new PathResolverRecyclerAdapter.OnClickListener<String>() {
@Override
public void onClick(PathResolverRecyclerAdapter.Holder<String> holder) {
goPath(holder.index.object);
}
});
mHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goPath(null);
}
});
if (ACTION_LIST_TRANSFERS.equals(getIntent().getAction()) && getIntent().hasExtra(EXTRA_GROUP_ID)) {
TransactionObject.Group group = new TransactionObject.Group(getIntent().getIntExtra(EXTRA_GROUP_ID, -1));
try {
mDatabase.reconstruct(group);
NetworkDevice networkDevice = new NetworkDevice(group.deviceId);
mDatabase.reconstruct(networkDevice);
mGroup = group;
mDevice = networkDevice;
mInfoDialog = new TransactionGroupInfoDialog(this, mDatabase, mGroup);
if (getSupportActionBar() != null)
getSupportActionBar().setTitle(mDevice.nickname);
mTransactionFragment.getAdapter().setPathChangedListener(this);
applyPath(null);
View headerView = mNavigationView.getHeaderView(0);
View layoutView = headerView.findViewById(R.id.header_default_device_container);
ImageView imageView = headerView.findViewById(R.id.header_default_device_image);
TextView deviceNameText = headerView.findViewById(R.id.header_default_device_name_text);
TextView versionText = headerView.findViewById(R.id.header_default_device_version_text);
String firstLetters = TextUtils.getFirstLetters(mDevice.nickname, 1);
TextDrawable drawable = TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(getApplicationContext(), R.color.networkDeviceRipple), 100);
layoutView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DeviceInfoDialog(TransactionActivity.this, mDatabase, mDevice).show();
if (mDrawerLayout != null)
mDrawerLayout.closeDrawer(Gravity.START);
}
});
imageView.setImageDrawable(drawable);
deviceNameText.setText(mDevice.nickname);
versionText.setText(mDevice.versionName);
} catch (Exception e) {
e.printStackTrace();
}
}
if (mGroup == null)
finish();
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class NetworkDeviceListAdapter method onLoad.
@Override
public ArrayList<NetworkDevice> onLoad() {
ArrayList<NetworkDevice> list = new ArrayList<>();
if (mFragment.canReadScanResults(getContext())) {
for (ScanResult resultIndex : mFragment.getWifiManager().getScanResults()) {
if (!resultIndex.SSID.startsWith(AppConfig.PREFIX_ACCESS_POINT))
continue;
HotspotNetwork hotspotNetwork = new HotspotNetwork();
hotspotNetwork.lastUsageTime = System.currentTimeMillis();
hotspotNetwork.SSID = resultIndex.SSID;
hotspotNetwork.BSSID = resultIndex.BSSID;
hotspotNetwork.nickname = getFriendlySSID(resultIndex.SSID);
list.add(hotspotNetwork);
}
}
if (list.size() == 0 && mFragment.isConnectionSelfNetwork()) {
WifiInfo wifiInfo = mFragment.getWifiManager().getConnectionInfo();
HotspotNetwork hotspotNetwork = new HotspotNetwork();
hotspotNetwork.lastUsageTime = System.currentTimeMillis();
hotspotNetwork.SSID = wifiInfo.getSSID();
hotspotNetwork.BSSID = wifiInfo.getBSSID();
hotspotNetwork.nickname = getFriendlySSID(wifiInfo.getSSID());
list.add(hotspotNetwork);
}
for (NetworkDevice device : mDatabase.castQuery(new SQLQuery.Select(AccessDatabase.TABLE_DEVICES).setOrderBy(AccessDatabase.FIELD_DEVICES_LASTUSAGETIME + " DESC"), NetworkDevice.class)) if (device instanceof HotspotNetwork || (device.nickname != null && device.model != null && device.brand != null && (mShowLocalAddresses || !device.isLocalAddress)))
list.add(device);
return list;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class NetworkDeviceListAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
if (view == null)
view = getInflater().inflate(R.layout.list_network_device, viewGroup, false);
NetworkDevice device = (NetworkDevice) getItem(position);
String firstLetters = TextUtils.getFirstLetters(device.nickname, 1);
boolean hotspotNetwork = device instanceof HotspotNetwork;
TextView deviceText = view.findViewById(R.id.network_device_list_device_text);
TextView userText = view.findViewById(R.id.network_device_list_user_text);
ImageView userImage = view.findViewById(R.id.network_device_list_device_image);
userText.setText(device.nickname);
deviceText.setText(hotspotNetwork ? mContext.getString(R.string.text_trebleshotHotspot) : device.model);
userImage.setImageDrawable(TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(mContext, hotspotNetwork ? R.color.hotspotNetworkRipple : R.color.networkDeviceRipple), 100));
return view;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class CommunicationService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (intent != null)
Log.d(TAG, "onStart() : action = " + intent.getAction());
if (intent != null && AppUtils.checkRunningConditions(this)) {
if (ACTION_FILE_TRANSFER.equals(intent.getAction())) {
final int groupId = intent.getIntExtra(EXTRA_GROUP_ID, -1);
final int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, -1);
final boolean isAccepted = intent.getBooleanExtra(EXTRA_IS_ACCEPTED, false);
getNotificationHelper().getUtils().cancel(notificationId);
try {
final TransferInstance transferInstance = new TransferInstance(getDatabase(), groupId);
CommunicationBridge.connect(getDatabase(), new CommunicationBridge.Client.ConnectionHandler() {
@Override
public void onConnect(CommunicationBridge.Client client) {
try {
CoolSocket.ActiveConnection activeConnection = client.communicate(transferInstance.getDevice(), transferInstance.getConnection());
activeConnection.reply(new JSONObject().put(Keyword.REQUEST, Keyword.REQUEST_RESPONSE).put(Keyword.TRANSFER_GROUP_ID, groupId).put(Keyword.TRANSFER_IS_ACCEPTED, isAccepted).toString());
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (isAccepted)
startFileReceiving(groupId);
else
mDatabase.remove(transferInstance.getGroup());
} catch (Exception e) {
e.printStackTrace();
if (isAccepted)
getNotificationHelper().showToast(R.string.mesg_somethingWentWrong);
}
} else if (ACTION_IP.equals(intent.getAction())) {
String deviceId = intent.getStringExtra(EXTRA_DEVICE_ID);
boolean isAccepted = intent.getBooleanExtra(EXTRA_IS_ACCEPTED, false);
int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, -1);
getNotificationHelper().getUtils().cancel(notificationId);
NetworkDevice device = new NetworkDevice(deviceId);
try {
mDatabase.reconstruct(device);
device.isRestricted = !isAccepted;
mDatabase.update(device);
} catch (Exception e) {
e.printStackTrace();
return START_NOT_STICKY;
}
} else if (ACTION_CANCEL_INDEXING.equals(intent.getAction())) {
int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, -1);
int groupId = intent.getIntExtra(EXTRA_GROUP_ID, -1);
getNotificationHelper().getUtils().cancel(notificationId);
Interrupter interrupter = getOngoingIndexList().get(groupId);
if (interrupter != null)
interrupter.interrupt();
} else if (ACTION_CLIPBOARD.equals(intent.getAction()) && intent.hasExtra(EXTRA_CLIPBOARD_ACCEPTED)) {
int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, -1);
int clipboardId = intent.getIntExtra(EXTRA_CLIPBOARD_ID, -1);
boolean isAccepted = intent.getBooleanExtra(EXTRA_CLIPBOARD_ACCEPTED, false);
TextStreamObject textStreamObject = new TextStreamObject(clipboardId);
getNotificationHelper().getUtils().cancel(notificationId);
try {
getDatabase().reconstruct(textStreamObject);
if (isAccepted) {
((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("receivedText", textStreamObject.text));
Toast.makeText(this, R.string.mesg_textCopiedToClipboard, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (ACTION_END_SESSION.equals(intent.getAction())) {
stopSelf();
} else if (ACTION_SEAMLESS_RECEIVE.equals(intent.getAction()) && intent.hasExtra(EXTRA_GROUP_ID)) {
int groupId = intent.getIntExtra(EXTRA_GROUP_ID, -1);
try {
CoolTransfer.TransferHandler<ProcessHolder> process = findProcessById(groupId);
if (process == null)
startFileReceiving(groupId);
else
Toast.makeText(this, getString(R.string.mesg_groupOngoingNotice, process.getExtra().transactionObject.friendlyName), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
} else if (ACTION_CANCEL_JOB.equals(intent.getAction()) || ACTION_CANCEL_KILL.equals(intent.getAction())) {
int groupId = intent.getIntExtra(EXTRA_GROUP_ID, -1);
int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_NOTIFICATION_ID, -1);
CoolTransfer.TransferHandler<ProcessHolder> handler = findProcessById(groupId);
if (handler == null || ACTION_CANCEL_KILL.equals(intent.getAction()))
getNotificationHelper().getUtils().cancel(notificationId);
if (handler != null) {
if (ACTION_CANCEL_KILL.equals(intent.getAction())) {
try {
if (handler instanceof CoolTransfer.Receive.Handler) {
CoolTransfer.Receive.Handler receiveHandler = ((CoolTransfer.Receive.Handler) handler);
if (receiveHandler.getServerSocket() != null)
receiveHandler.getServerSocket().close();
}
if (handler.getExtra().activeConnection.getSocket() != null)
handler.getExtra().activeConnection.getSocket().close();
if (handler.getSocket() != null)
handler.getSocket().close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
handler.getExtra().notification = getNotificationHelper().notifyStuckThread(handler.getExtra().transactionObject);
handler.interrupt();
}
}
} else if (ACTION_TOGGLE_SEAMLESS_MODE.equals(intent.getAction())) {
updateServiceState(!mSeamlessMode);
} else if (ACTION_TOGGLE_HOTSPOT.equals(intent.getAction()) && (Build.VERSION.SDK_INT < 23 || Settings.System.canWrite(this))) {
setupHotspot();
} else if (ACTION_REQUEST_HOTSPOT_STATUS.equals(intent.getAction()))
sendHotspotStatus(getHotspotUtils().getConfiguration());
}
return START_STICKY;
}
use of com.genonbeta.TrebleShot.object.NetworkDevice in project TrebleShot by genonbeta.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.text_navigationDrawerOpen, R.string.text_navigationDrawerClose);
mDrawerLayout.addDrawerListener(toggle);
toggle.syncState();
mUpdater = new GitHubUpdater(this, AppConfig.URI_REPO_APP_UPDATE, R.style.AppTheme);
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mActionMode = findViewById(R.id.content_powerful_action_mode);
mNavigationView = findViewById(R.id.nav_view);
mFAB = findViewById(R.id.content_fab);
mNavigationView.setNavigationItemSelectedListener(this);
mFragmentDeviceList = Fragment.instantiate(this, NetworkDeviceListFragment.class.getName());
mFragmentFileExplorer = Fragment.instantiate(this, FileExplorerFragment.class.getName());
mFragmentTransactions = Fragment.instantiate(this, TransactionGroupListFragment.class.getName());
mFragmentShareApp = Fragment.instantiate(this, ApplicationListFragment.class.getName());
mFragmentShareImage = Fragment.instantiate(this, ImageListFragment.class.getName());
mFragmentShareMusic = Fragment.instantiate(this, MusicListFragment.class.getName());
mFragmentShareVideo = Fragment.instantiate(this, VideoListFragment.class.getName());
mFragmentShareText = Fragment.instantiate(this, TextStreamListFragment.class.getName());
mActionMode.setOnSelectionTaskListener(new PowerfulActionMode.OnSelectionTaskListener() {
@Override
public void onSelectionTask(boolean started, PowerfulActionMode actionMode) {
toolbar.setVisibility(!started ? View.VISIBLE : View.GONE);
}
});
if (mPreferences.contains("availableVersion") && mUpdater.isNewVersion(mPreferences.getString("availableVersion", null))) {
highlightUpdater(mPreferences.getString("availableVersion", null));
} else {
mUpdater.checkForUpdates(false, new GitHubUpdater.OnInfoAvailableListener() {
@Override
public void onInfoAvailable(boolean newVersion, String versionName, String title, String description, String releaseDate) {
mPreferences.edit().putString("availableVersion", versionName).apply();
if (newVersion)
highlightUpdater(versionName);
}
});
}
NetworkDevice localDevice = AppUtils.getLocalDevice(getApplicationContext());
if (mPreferences.getInt("migrated_version", localDevice.versionNumber) < localDevice.versionNumber) {
// migrating to a new version
}
mPreferences.edit().putInt("migrated_version", localDevice.versionNumber).apply();
if (!checkRequestedFragment(getIntent()) && !restorePreviousFragment()) {
changeFragment(mFragmentDeviceList);
mNavigationView.setCheckedItem(R.id.menu_activity_main_device_list);
}
}
Aggregations