mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -04:00
Remove extra stuff
Unnecessary comments, todos, variables, imports, methods
This commit is contained in:
parent
7759a4eb47
commit
36f563e209
@ -1,10 +1,8 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.p2p.WifiP2pDevice;
|
import android.net.wifi.p2p.WifiP2pDevice;
|
||||||
import android.net.wifi.p2p.WifiP2pDeviceList;
|
import android.net.wifi.p2p.WifiP2pDeviceList;
|
||||||
@ -12,15 +10,12 @@ import android.net.wifi.p2p.WifiP2pInfo;
|
|||||||
import android.net.wifi.p2p.WifiP2pManager;
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -29,22 +24,16 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.content.FileProvider;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.fragment.app.ListFragment;
|
import androidx.fragment.app.ListFragment;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
@ -54,18 +43,14 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
|
||||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.DeviceListFragment.TAG;
|
|
||||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.FileItem.TO_BE_SENT;
|
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.FileItem.TO_BE_SENT;
|
||||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity.filePath;
|
|
||||||
|
|
||||||
public class DeviceListFragment extends ListFragment implements WifiP2pManager.PeerListListener, WifiP2pManager.ConnectionInfoListener {
|
public class DeviceListFragment extends ListFragment implements WifiP2pManager.PeerListListener, WifiP2pManager.ConnectionInfoListener {
|
||||||
|
|
||||||
public static String TAG = "DeviceListFragment";
|
public static final String TAG = "DeviceListFragment";
|
||||||
|
|
||||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||||
|
|
||||||
@ -134,8 +119,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
selectedPeerDevice = (WifiP2pDevice) getListAdapter().getItem(position);
|
selectedPeerDevice = (WifiP2pDevice) getListAdapter().getItem(position);
|
||||||
Toast.makeText(getActivity(), selectedPeerDevice.deviceName, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), selectedPeerDevice.deviceName, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
// TODO: Set sender depending upon receiving file URI in activity opening intent
|
// TODO: Set sender depending upon receiving file URI in activity opening intent - DONE
|
||||||
//((LocalFileTransferActivity) getActivity()).setFileSender();
|
|
||||||
((DeviceActionListener) getActivity()).connect(selectedPeerDevice);
|
((DeviceActionListener) getActivity()).connect(selectedPeerDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +168,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
public void onConnectionInfoAvailable(WifiP2pInfo info) {
|
public void onConnectionInfoAvailable(WifiP2pInfo info) {
|
||||||
groupInfo = info;
|
groupInfo = info;
|
||||||
|
|
||||||
//TODO: Show progress of file transfer process
|
//TODO: Show progress of file transfer process - DONE
|
||||||
|
|
||||||
new PeerGroupHandshakeAsyncTask(this, groupInfo).execute();
|
new PeerGroupHandshakeAsyncTask(this, groupInfo).execute();
|
||||||
|
|
||||||
@ -260,34 +244,14 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
|
|
||||||
} else if(groupInfo.groupFormed) {
|
} else if(groupInfo.groupFormed) {
|
||||||
{
|
{
|
||||||
//Toast.makeText(getActivity(), "Sending file to "+selectedPeerDevice.deviceAddress+"\nSelf: "+userDevice.deviceAddress, Toast.LENGTH_SHORT).show();
|
|
||||||
Log.d(LocalFileTransferActivity.TAG, "Starting file transfer");
|
Log.d(LocalFileTransferActivity.TAG, "Starting file transfer");
|
||||||
|
|
||||||
new AlertDialog.Builder(getActivity())
|
Toast.makeText(getActivity(), "Starting file transfer", Toast.LENGTH_SHORT).show();
|
||||||
.setMessage("Transferring file")
|
|
||||||
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
/*Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
|
|
||||||
serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_URI, filePath.toString());//FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID+".fileprovider", new File(filePath)).toString());
|
|
||||||
|
|
||||||
if(groupInfo.isGroupOwner) fileReceiverAddress = selectedPeerDeviceInetAddress;
|
|
||||||
else fileReceiverAddress = groupInfo.groupOwnerAddress;
|
|
||||||
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS, fileReceiverAddress.getHostAddress());//getIPFromMac(selectedPeerDevice.deviceAddress));
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8008);
|
|
||||||
getActivity().startService(serviceIntent);*/
|
|
||||||
/*DeviceListFragment parent = ((DeviceListFragment) getActivity().getSupportFragmentManager().findFragmentByTag(TAG));
|
|
||||||
if(parent != null)
|
|
||||||
new FileSenderAsyncTask(getContext(), parent, parent.groupInfo).execute(((LocalFileTransferActivity) getActivity()).getFileURIArrayList());*/
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//.setNegativeButton("No", null)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
if(groupInfo.isGroupOwner) fileReceiverAddress = selectedPeerDeviceInetAddress;
|
if(groupInfo.isGroupOwner) fileReceiverAddress = selectedPeerDeviceInetAddress;
|
||||||
else fileReceiverAddress = groupInfo.groupOwnerAddress;
|
else fileReceiverAddress = groupInfo.groupOwnerAddress;
|
||||||
|
|
||||||
|
//TODO: Fix this
|
||||||
for(int i = 0; i < 10000000; i++);
|
for(int i = 0; i < 10000000; i++);
|
||||||
|
|
||||||
for(int i = 0; i < totalFiles; i++) {
|
for(int i = 0; i < totalFiles; i++) {
|
||||||
@ -332,17 +296,10 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface DeviceActionListener {
|
public interface DeviceActionListener {
|
||||||
|
|
||||||
/*void changeDeviceName(String deviceNewName);*/
|
|
||||||
|
|
||||||
/*void showDetails(WifiP2pDevice device);*/
|
|
||||||
|
|
||||||
void cancelSearch();
|
void cancelSearch();
|
||||||
|
|
||||||
void connect(WifiP2pDevice peerDevice);
|
void connect(WifiP2pDevice peerDevice);
|
||||||
|
|
||||||
//void disconnect();
|
|
||||||
|
|
||||||
void closeLocalFileTransferActivity();
|
void closeLocalFileTransferActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +325,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
Object object = objectInputStream.readObject();
|
Object object = objectInputStream.readObject();
|
||||||
if (object.getClass().equals(String.class) && ((String) object).equals("Request Kiwix File Sharing")) {
|
if (object.getClass().equals(String.class) && ((String) object).equals("Request Kiwix File Sharing")) {
|
||||||
Log.d(TAG, "Client IP address: "+ client.getInetAddress());
|
Log.d(TAG, "Client IP address: "+ client.getInetAddress());
|
||||||
//selectedPeerDeviceInetAddress = client.getInetAddress();
|
|
||||||
|
|
||||||
if(deviceListFragment.isFileSender()) {
|
if(deviceListFragment.isFileSender()) {
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(client.getOutputStream());
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(client.getOutputStream());
|
||||||
@ -400,7 +356,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
return client.getInetAddress();
|
return client.getInetAddress();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//Log.d(TAG, e.getMessage());
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -450,13 +405,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
|
|
||||||
serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, Environment.getExternalStorageDirectory() + "/MainPage.txt");
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS, groupInfo.groupOwnerAddress.getHostAddress());
|
|
||||||
serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8008);
|
|
||||||
getActivity().startService(serviceIntent);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -565,7 +513,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String s) {
|
protected void onPostExecute(String s) {
|
||||||
//
|
|
||||||
deviceListFragment.incrementTotalFilesSent();
|
deviceListFragment.incrementTotalFilesSent();
|
||||||
|
|
||||||
deviceListFragment.getActivity().runOnUiThread(new Runnable() {
|
deviceListFragment.getActivity().runOnUiThread(new Runnable() {
|
||||||
@ -588,7 +535,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
private DeviceListFragment deviceListFragment;
|
private DeviceListFragment deviceListFragment;
|
||||||
private TransferProgressFragment transferProgressFragment;
|
private TransferProgressFragment transferProgressFragment;
|
||||||
private int fileItemIndex;
|
private int fileItemIndex;
|
||||||
//private View statusView
|
|
||||||
|
|
||||||
public FileServerAsyncTask(Context context, DeviceListFragment deviceListFragment, TransferProgressFragment transferProgressFragment) {
|
public FileServerAsyncTask(Context context, DeviceListFragment deviceListFragment, TransferProgressFragment transferProgressFragment) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -660,13 +606,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
Log.d(LocalFileTransferActivity.TAG, "File transfer complete");
|
Log.d(LocalFileTransferActivity.TAG, "File transfer complete");
|
||||||
((LocalFileTransferActivity) deviceListFragment.getActivity()).closeLocalFileTransferActivity();
|
((LocalFileTransferActivity) deviceListFragment.getActivity()).closeLocalFileTransferActivity();
|
||||||
|
|
||||||
/*File recvFile = new File(filePath);
|
|
||||||
Uri fileUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID+".fileprovider",recvFile);
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
|
||||||
intent.setDataAndType(fileUri, "text/plain");
|
|
||||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
context.startActivity(intent);*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,7 +628,4 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public interface UpdateProgressCallback {
|
|
||||||
public void changeStatus(int itemIndex, short status);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import android.net.wifi.p2p.WifiP2pDevice;
|
|||||||
import android.net.wifi.p2p.WifiP2pManager;
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -38,7 +37,6 @@ import org.kiwix.kiwixmobile.KiwixApplication;
|
|||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -46,12 +44,11 @@ import javax.inject.Inject;
|
|||||||
public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener {
|
public class LocalFileTransferActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener, DeviceListFragment.DeviceActionListener {
|
||||||
|
|
||||||
/*TODO
|
/*TODO
|
||||||
* - Fix activity closure upon file transfer (successful or otherwise)
|
* - Fix activity closure upon file transfer (successful or otherwise) - DONE
|
||||||
* - Handle multiple selected files - DONE
|
* - Handle multiple selected files - DONE
|
||||||
* */
|
* */
|
||||||
|
|
||||||
public static final String TAG = "LocalFileTransferActvty"; // Not a typo, Tags have a length upper limit of 25 characters
|
public static final String TAG = "LocalFileTransferActvty"; // Not a typo, 'Log' tags have a length upper limit of 25 characters
|
||||||
public static Uri filePath = null; // = Environment.getExternalStorageDirectory() + "/Kiwix/temp.txt";///psiram_en_all_2018-09.zim";//Notes/Granblue Fantasy Wiki/Main Page.txt";
|
|
||||||
private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1;
|
private final int PERMISSION_REQUEST_CODE_COARSE_LOCATION = 1;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -67,7 +64,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
private WifiP2pManager.Channel channel;
|
private WifiP2pManager.Channel channel;
|
||||||
private BroadcastReceiver receiver = null;
|
private BroadcastReceiver receiver = null;
|
||||||
private Boolean fileSendingDevice = false; // True if intent has file uri
|
private Boolean fileSendingDevice = false; // True if intent has file uri
|
||||||
// TODO: Set to true if activity opening intent has the file URI
|
// TODO: Set to true if activity opening intent has the file URI- DONE
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -76,34 +73,17 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
||||||
KiwixApplication.getApplicationComponent().inject(this);
|
KiwixApplication.getApplicationComponent().inject(this);
|
||||||
|
|
||||||
/*setContentView(R.layout.activity_local_file_transfer);
|
|
||||||
|
|
||||||
TextView fileUriListView = findViewById(R.id.text_view_file_uris);
|
|
||||||
|
|
||||||
Intent filesIntent = getIntent();
|
|
||||||
ArrayList<Uri> fileURIArrayList = filesIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
||||||
|
|
||||||
String uriList = "Selected File URIs:\n\n";
|
|
||||||
if(fileURIArrayList != null && fileURIArrayList.size() > 0) {
|
|
||||||
for(int i = 0; i < fileURIArrayList.size(); i++) {
|
|
||||||
uriList += fileURIArrayList.get(i) + "\n\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileUriListView.setText(uriList);*/
|
|
||||||
|
|
||||||
Intent filesIntent = getIntent();
|
Intent filesIntent = getIntent();
|
||||||
fileURIArrayList = filesIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
fileURIArrayList = filesIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
|
|
||||||
if(fileURIArrayList != null && fileURIArrayList.size() > 0) {
|
if(fileURIArrayList != null && fileURIArrayList.size() > 0) {
|
||||||
//filePath = fileURIArrayList.get(0);
|
|
||||||
setFileSender();
|
setFileSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
Toolbar actionBar = findViewById(R.id.toolbar_local_file_transfer);
|
Toolbar actionBar = findViewById(R.id.toolbar_local_file_transfer);
|
||||||
setSupportActionBar(actionBar);
|
setSupportActionBar(actionBar);
|
||||||
|
//TODO: Fix this text colour
|
||||||
actionBar.setTitle("Local ZIM file transfer");
|
actionBar.setTitle("Local ZIM file transfer");
|
||||||
// TODO: Fix this drawable file/colour & text colour
|
// TODO: Fix this drawable file/colour - DONE
|
||||||
actionBar.setNavigationIcon(R.drawable.ic_close_white_24dp);
|
actionBar.setNavigationIcon(R.drawable.ic_close_white_24dp);
|
||||||
actionBar.setNavigationOnClickListener(new View.OnClickListener(){
|
actionBar.setNavigationOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
@ -118,11 +98,11 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
||||||
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
||||||
|
|
||||||
//TODO: Start WiFi
|
//TODO: Start WiFi - DONE through permissions
|
||||||
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
||||||
channel = manager.initialize(this, getMainLooper(), null);
|
channel = manager.initialize(this, getMainLooper(), null);
|
||||||
|
|
||||||
// TODO: Add manager.removeGroup(channel, null); to remove previous groups
|
// TODO: !!!!!!!!!!!Add manager.removeGroup(channel, null); to remove previous groups
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||||
&& checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
&& checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
@ -210,9 +190,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
return true;
|
return true;
|
||||||
} else if(item.getItemId() == R.id.menu_item_cancel_search) {
|
} else if(item.getItemId() == R.id.menu_item_cancel_search) {
|
||||||
if(manager != null) {
|
if(manager != null) {
|
||||||
// TODO: 'cancelDisconnect', for removing incorrect connections
|
// TODO: 'cancelDisconnect', for removing incorrect connections - DONE thru cancelSearch
|
||||||
//removeGroupDetails();
|
|
||||||
//disconnect();
|
|
||||||
cancelSearch();
|
cancelSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,29 +202,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeGroupDetails() {
|
|
||||||
try {
|
|
||||||
Method deletePersistentGroup = manager.getClass().getMethod("deletePersistentGroup", WifiP2pManager.Channel.class, int.class, WifiP2pManager.ActionListener.class);
|
|
||||||
for(int netId = 0; netId < 32; netId++) {
|
|
||||||
deletePersistentGroup.invoke(manager, channel, netId, new WifiP2pManager.ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
Log.d(TAG, "WiFi Direct Group successfully deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(int reason) {
|
|
||||||
Log.d(TAG, "Group deletion failed: "+getErrorMessage(reason));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.d(TAG, "Error removing group details: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLocationServicesEnabled() {
|
private boolean isLocationServicesEnabled() {
|
||||||
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||||
boolean gps_enabled = false;
|
boolean gps_enabled = false;
|
||||||
@ -260,11 +215,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||||
} catch(Exception ex) {ex.printStackTrace();}
|
} catch(Exception ex) {ex.printStackTrace();}
|
||||||
|
|
||||||
/*if(!gps_enabled && !network_enabled) {
|
|
||||||
// notify user
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return (gps_enabled || network_enabled);
|
return (gps_enabled || network_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,23 +261,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
|
|
||||||
private void requestEnableWifiP2pServices() {
|
private void requestEnableWifiP2pServices() {
|
||||||
|
|
||||||
/*new AlertDialog.Builder(this)
|
|
||||||
.setMessage("Enable WiFi P2P from system settings")
|
|
||||||
.setPositiveButton("Open WiFi Settings", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
|
|
||||||
paramDialogInterface.cancel();
|
|
||||||
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();*/
|
|
||||||
|
|
||||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||||
Fragment prev = getSupportFragmentManager().findFragmentByTag("WifiP2pDialog");
|
Fragment prev = getSupportFragmentManager().findFragmentByTag("WifiP2pDialog");
|
||||||
if(prev != null) {
|
if(prev != null) {
|
||||||
@ -376,15 +309,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
/*new AlertDialog.Builder(this)
|
|
||||||
.setMessage("Cannot discover peers without location services")
|
|
||||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
//((MainActivity) getApplicationContext()).finish();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();*/
|
|
||||||
showNeutralDialog("Cannot discover peers without location services");
|
showNeutralDialog("Cannot discover peers without location services");
|
||||||
//TODO: Close activity
|
//TODO: Close activity
|
||||||
}
|
}
|
||||||
@ -527,11 +451,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
fileSendingDevice = true;
|
fileSendingDevice = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public void showDetails(WifiP2pDevice device) {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelSearch() {
|
public void cancelSearch() {
|
||||||
|
|
||||||
@ -578,7 +497,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
/*else
|
/*else
|
||||||
config.groupOwnerIntent = 15;*/
|
config.groupOwnerIntent = 15;*/
|
||||||
|
|
||||||
//TODO: Show a progress bar between starting & completion of connection
|
//TODO: Show a progress bar between starting & completion of connection - DONE
|
||||||
|
|
||||||
manager.connect(channel, config, new WifiP2pManager.ActionListener() {
|
manager.connect(channel, config, new WifiP2pManager.ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user