Skip to content

Commit

Permalink
Removed extra spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cuttingedge03 committed Mar 25, 2014
1 parent 0de4040 commit ceab202
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions app/src/main/java/im/tox/antox/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public void onReceive(Context context, Intent intent) {

public void updateChat(String key) {
Log.d(TAG, "updating chat");
if (toxSingleton.friendsList.getById(key) != null
&& toxSingleton.friendsList.getById(key).getName() != null) {
if(toxSingleton.friendsList.getById(key)!=null
&& toxSingleton.friendsList.getById(key).getName()!=null ){
AntoxDB db = new AntoxDB(this);
if (toxSingleton.rightPaneActive) {
db.markIncomingMessagesRead(key);
Expand Down Expand Up @@ -193,7 +193,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

/* Fix for an android 4.1.x bug */
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.JELLY_BEAN
if(Build.VERSION.SDK_INT != Build.VERSION_CODES.JELLY_BEAN
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
Expand All @@ -215,27 +215,29 @@ protected void onCreate(Bundle savedInstanceState) {
}

Log.i(TAG, "onCreate");
toxSingleton.activeFriendKey = null;
toxSingleton.activeFriendRequestKey = null;
toxSingleton.activeFriendKey=null;
toxSingleton.activeFriendRequestKey=null;
setContentView(R.layout.activity_main);

toxSingleton.leftPaneActive = true;

/* Check if connected to the Internet */
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo != null && networkInfo.isConnected())
{
// Executes in a separate thread so UI experience isn't affected
// Downloads the DHT node details
if (DhtNode.ipv4.size() == 0)
if(DhtNode.ipv4.size() == 0)
new DHTNodeDetails().execute();
} else {
}
else {
showAlertDialog(MainActivity.this, getString(R.string.main_no_internet),
getString(R.string.main_not_connected));
}

/* If the tox service isn't already running, start it */
if (!isToxServiceRunning()) {
if(!isToxServiceRunning()) {
/* If the service wasn't running then we wouldn't have gotten callbacks for a user
* going offline so default everyone to offline and just wait for callbacks.
*/
Expand Down Expand Up @@ -292,19 +294,18 @@ protected void onDestroy() {
Log.i(TAG, "onDestroy");
super.onDestroy();
}

private Message mostRecentMessage(String key, ArrayList<Message> messages) {
for (int i = 0; i < messages.size(); i++) {
for (int i=0; i<messages.size(); i++) {
if (key.equals(messages.get(i).key)) {
return messages.get(i);
}
}
return new Message(-1, key, "", false, true, true, true, new Timestamp(0, 0, 0, 0, 0, 0, 0));
return new Message(-1, key, "", false, true, true, true, new Timestamp(0,0,0,0,0,0,0));
}

private int countUnreadMessages(String key, ArrayList<Message> messages) {
int counter = 0;
if (key != null) {
if(key!=null) {
Message m;
for (int i = 0; i < messages.size(); i++) {
m = messages.get(i);
Expand All @@ -319,7 +320,6 @@ private int countUnreadMessages(String key, ArrayList<Message> messages) {
}
return counter;
}

public void updateLeftPane() {

AntoxDB antoxDB = new AntoxDB(this);
Expand Down Expand Up @@ -382,7 +382,6 @@ private void openSettings() {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}

/**
* Starts a new intent to open the SettingsActivity class
*
Expand All @@ -392,7 +391,6 @@ private void openProfile() {
Intent intent = new Intent(this, ProfileActivity.class);
startActivity(intent);
}

/**
* Starts a new intent to open the AboutActivity class
*
Expand All @@ -402,7 +400,6 @@ private void openAbout() {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
}

/**
* Starts a new intent to open the AddFriendActivity class
*
Expand All @@ -413,7 +410,7 @@ private void addFriend() {
startActivityForResult(intent, Constants.ADD_FRIEND_REQUEST_CODE);
}

private void clearUselessNotifications() {
private void clearUselessNotifications () {
if (toxSingleton.rightPaneActive && toxSingleton.activeFriendKey != null
&& toxSingleton.friendsList.all().size() > 0) {
AntoxFriend friend = toxSingleton.friendsList.getById(toxSingleton.activeFriendKey);
Expand Down Expand Up @@ -484,7 +481,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void addFriendToGroup() {
Log.v("Add friend to group method", "To implement");
Log.v("Add friend to group method","To implement");
}

@Override
Expand Down Expand Up @@ -522,7 +519,7 @@ public void onFocusChange(View v, boolean hasFocus) {
}
});
//the class menu property is now the initialized menu
this.menu = menu;
this.menu=menu;

return true;
}
Expand Down Expand Up @@ -552,21 +549,24 @@ private class DHTNodeDetails extends AsyncTask<Void, Void, Void> {
final String[] nodeDetails = new String[7];



@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
Document document = Jsoup.connect("http://wiki.tox.im/Nodes").timeout(10000).get();
Elements nodeRows = document.getElementsByTag("tr");

for (Element nodeRow : nodeRows) {
for(Element nodeRow : nodeRows)
{
Elements nodeElements = nodeRow.getElementsByTag("td");
int c = 0;
for (Element nodeElement : nodeElements)
nodeDetails[c++] = nodeElement.text();
for(Element nodeElement : nodeElements)
nodeDetails[c++]=nodeElement.text();


if (nodeDetails[6] != null && nodeDetails[6].equals("WORK")) {
if(nodeDetails[6]!=null && nodeDetails[6].equals("WORK"))
{
DhtNode.ipv4.add(nodeDetails[0]);
DhtNode.ipv6.add(nodeDetails[1]);
DhtNode.port.add(nodeDetails[2]);
Expand All @@ -587,7 +587,7 @@ protected Void doInBackground(Void... params) {
int pos = -1;
Socket socket = null;
Log.d(TAG, "DhtNode size: " + DhtNode.ipv4.size());
for (int i = 0; i < DhtNode.ipv4.size(); i++) {
for(int i = 0;i < DhtNode.ipv4.size(); i++) {
Log.d(TAG, "i = " + i);
try {
long currentTime = System.currentTimeMillis();
Expand All @@ -606,7 +606,7 @@ protected Void doInBackground(Void... params) {
}
}

if (socket != null) {
if(socket != null) {
try {
socket.close();
} catch (IOException e) {
Expand All @@ -615,7 +615,7 @@ protected Void doInBackground(Void... params) {
}

/* Move quickest node to front of list */
if (pos != -1) {
if(pos != -1) {
DhtNode.ipv4.add(0, DhtNode.ipv4.get(pos));
DhtNode.ipv6.add(0, DhtNode.ipv6.get(pos));
DhtNode.port.add(0, DhtNode.port.get(pos));
Expand All @@ -629,7 +629,8 @@ protected Void doInBackground(Void... params) {
}

@Override
protected void onPostExecute(Void result) {
protected void onPostExecute(Void result)
{
try {
//Checking the details
System.out.println("node details:");
Expand All @@ -639,23 +640,24 @@ protected void onPostExecute(Void result) {
System.out.println(DhtNode.key);
System.out.println(DhtNode.owner);
System.out.println(DhtNode.location);
} catch (NullPointerException e) {
Toast.makeText(MainActivity.this, getString(R.string.main_node_list_download_error), Toast.LENGTH_SHORT).show();
}catch (NullPointerException e){
Toast.makeText(MainActivity.this,getString(R.string.main_node_list_download_error),Toast.LENGTH_SHORT).show();
}
/**
* There is a chance that downloading finishes later than the bootstrapping call in the
* ToxService, because both are in separate threads. In that case to make sure the nodes
* are bootstrapped we restart the ToxService
*/
if (!DhtNode.connected) {
if(!DhtNode.connected)
{
Log.d(TAG, "Restarting START_TOX as DhtNode.connected returned false");
Intent restart = new Intent(getApplicationContext(), ToxDoService.class);
restart.setAction(Constants.START_TOX);
getApplicationContext().startService(restart);
}

/* Restart intent if it was connected before nodes were sorted */
if (DhtNode.connected && !DhtNode.sorted) {
if(DhtNode.connected && !DhtNode.sorted) {
Log.d(TAG, "Restarting START_TOX as DhtNode.sorted was false");
Intent restart = new Intent(getApplicationContext(), ToxDoService.class);
restart.setAction(Constants.START_TOX);
Expand All @@ -672,29 +674,27 @@ public void onBackPressed() {
finish();
}
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.ADD_FRIEND_REQUEST_CODE && resultCode == RESULT_OK) {
if(requestCode==Constants.ADD_FRIEND_REQUEST_CODE && resultCode==RESULT_OK){
updateLeftPane();
} else if (requestCode == Constants.SENDFILE_PICKEDFRIEND_CODE && resultCode == RESULT_OK) {
Uri uri = data.getData();
} else if(requestCode==Constants.SENDFILE_PICKEDFRIEND_CODE && resultCode==RESULT_OK) {
Uri uri= data.getData();
File pickedFile = new File(uri.getPath());
MimeTypeMap mime = MimeTypeMap.getSingleton();
Log.d("file picked", "" + pickedFile.getAbsolutePath());
Log.d("file type", "" + getContentResolver().getType(uri));
Log.d("file picked",""+pickedFile.getAbsolutePath() );
Log.d("file type",""+getContentResolver().getType(uri));
}
}

private class PaneListener implements SlidingPaneLayout.PanelSlideListener {

@Override
public void onPanelClosed(View view) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(activeTitle);
MenuItem af = menu.findItem(R.id.add_friend);
MenuItemCompat.setShowAsAction(af, MenuItem.SHOW_AS_ACTION_NEVER);
MenuItemCompat.setShowAsAction(af,MenuItem.SHOW_AS_ACTION_NEVER);
ag.setVisible(true);
MenuItemCompat.setShowAsAction(ag, MenuItem.SHOW_AS_ACTION_ALWAYS);
MenuItemCompat.setShowAsAction(ag,MenuItem.SHOW_AS_ACTION_ALWAYS);
ag.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Expand All @@ -705,7 +705,7 @@ public boolean onMenuItemClick(MenuItem item) {
toxSingleton.rightPaneActive = true;
System.out.println("Panel closed");
toxSingleton.leftPaneActive = false;
if (toxSingleton.activeFriendKey != null) {
if(toxSingleton.activeFriendKey!=null){
updateChat(toxSingleton.activeFriendKey);
}
clearUselessNotifications();
Expand All @@ -716,15 +716,15 @@ public void onPanelOpened(View view) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
setTitle(R.string.app_name);
MenuItem af = menu.findItem(R.id.add_friend);
MenuItemCompat.setShowAsAction(af, MenuItem.SHOW_AS_ACTION_IF_ROOM);
MenuItemCompat.setShowAsAction(af,MenuItem.SHOW_AS_ACTION_IF_ROOM);
// af.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
/*af.setIcon(R.drawable.ic_action_add_person);
af.setTitle(R.string.add_friend);*/
menu.removeGroup(666);
supportInvalidateOptionsMenu();
toxSingleton.rightPaneActive = false;
toxSingleton.rightPaneActive =false;
toxSingleton.leftPaneActive = true;
InputMethodManager imm = (InputMethodManager) getSystemService(
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
/* This is causing a null pointer exception */
//imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
Expand All @@ -738,4 +738,4 @@ public void onPanelSlide(View view, float arg1) {
}


}
}

0 comments on commit ceab202

Please sign in to comment.