Skip to content

Commit

Permalink
Hardcode some DHT node values and start on dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Apr 13, 2014
1 parent 403a7b4 commit 59f4e30
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 15 deletions.
54 changes: 45 additions & 9 deletions app/src/main/java/im/tox/antox/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
Expand All @@ -22,6 +24,7 @@
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.app.ActionBar;
import android.text.Layout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -30,8 +33,10 @@
import android.view.inputmethod.InputMethodManager;
import android.webkit.MimeTypeMap;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;

import org.jsoup.Jsoup;
Expand All @@ -43,6 +48,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -279,13 +285,25 @@ protected void onCreate(Bundle savedInstanceState) {
getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());
}

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

toxSingleton.leftPaneActive = true;

// Check for a theme - currently this isn't very expandable to allow for user created themes
// but works for just setting a dark theme
if(settingsPref.getString("theme", "").equals("Dark")) {
// CHAT FRAGMENT - BACKGROUND COLOR
FrameLayout chatLayout = (FrameLayout) findViewById(R.id.right_pane);
chatLayout.setBackgroundColor(Color.rgb(64,64,64)); // zoo lane

// ACTION BAR - BACKGROUND COLOR
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(13,13,13)));


}

/* Check if connected to the Internet */
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
Expand Down Expand Up @@ -856,16 +874,14 @@ protected Void doInBackground(Void... params) {
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 @@ -874,13 +890,33 @@ protected Void doInBackground(Void... params) {
DhtNode.location.add(nodeDetails[5]);
}
}
} catch (UnknownHostException e) {
// If for some reason website is down, add some known values
DhtNode.ipv4.add("192.254.75.98");
DhtNode.ipv4.add("107.161.21.13");
DhtNode.ipv4.add("144.76.60.215");
DhtNode.port.add("33445");
DhtNode.port.add("33445");
DhtNode.port.add("33445");
DhtNode.key.add("FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B");
DhtNode.key.add("5848E6344856921AAF28DAB860C5816780FE0C8873AAC415C1B7FA7FAA4EF046");
DhtNode.key.add("04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F");
DhtNode.ipv6.add("");
DhtNode.ipv6.add("");
DhtNode.ipv6.add("");
DhtNode.owner.add("");
DhtNode.owner.add("");
DhtNode.owner.add("");
DhtNode.location.add("");
DhtNode.location.add("");
DhtNode.location.add("");
} catch (IOException e) {
e.printStackTrace();
}

Log.d(TAG, "About to ping servers...");
/**
* Ping servers to find quickest connection
* Ping servers to find quickest connection - Threading this would be goood
*/
long shortestTime = 99999;
int pos = -1;
Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/im/tox/antox/activities/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.v4.app.DialogFragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -26,8 +27,6 @@
* Settings Activity DHT nodes.
* Allows the user to specify their own DHT Node, or to pick one from a downloaded list of known
* working nodes.
*
* @author Mark Winter (Astonex)
*/

public class SettingsActivity extends ActionBarActivity
Expand Down Expand Up @@ -61,6 +60,11 @@ public class SettingsActivity extends ActionBarActivity
*/
private Spinner languageSpinner;

/**
* Spinner for displaying themes
*/
private Spinner themeSpinner;



@Override
Expand Down Expand Up @@ -110,6 +114,19 @@ protected void onCreate(Bundle savedInstanceState) {
dhtBox.setChecked(true);
}

themeSpinner = (Spinner) findViewById(R.id.spinner_theme_options);
String theme = pref.getString("theme", "");
switch (theme) {
case "Light":
themeSpinner.setSelection(0);
break;
case "Dark":
themeSpinner.setSelection(1);
break;
default:
themeSpinner.setSelection(0);
}

languageSpinner = (Spinner) findViewById(R.id.spinner_language_settings);
String lang = pref.getString("language", "");
switch (lang) {
Expand Down Expand Up @@ -185,6 +202,12 @@ public void updateSettings(View view) {
DhtNode.port.add(dhtPort);
}

// Save the theme
String theme = themeSpinner.getSelectedItem().toString();
if(!pref.getString("theme", "").equals(theme)) {
editor.putString("theme", theme);
}

//save the language
String language = languageSpinner.getSelectedItem().toString();
if(!pref.getString("language", "").equals(language)) {
Expand Down
28 changes: 24 additions & 4 deletions app/src/main/java/im/tox/antox/utils/ConnectionChangeReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import im.tox.antox.activities.MainActivity;
import im.tox.antox.tox.ToxDoService;
Expand Down Expand Up @@ -54,14 +55,14 @@ protected Void doInBackground(Void... params) {
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 @@ -70,6 +71,25 @@ protected Void doInBackground(Void... params) {
DhtNode.location.add(nodeDetails[5]);
}
}
} catch (UnknownHostException e) {
DhtNode.ipv4.add("192.254.75.98");
DhtNode.ipv4.add("107.161.21.13");
DhtNode.ipv4.add("144.76.60.215");
DhtNode.port.add("33445");
DhtNode.port.add("33445");
DhtNode.port.add("33445");
DhtNode.key.add("FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B");
DhtNode.key.add("5848E6344856921AAF28DAB860C5816780FE0C8873AAC415C1B7FA7FAA4EF046");
DhtNode.key.add("04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F");
DhtNode.ipv6.add("");
DhtNode.ipv6.add("");
DhtNode.ipv6.add("");
DhtNode.owner.add("");
DhtNode.owner.add("");
DhtNode.owner.add("");
DhtNode.location.add("");
DhtNode.location.add("");
DhtNode.location.add("");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@
android:drawSelectorOnTop="true"
android:entries="@array/languages" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:paddingTop="10dp"
android:text="@string/settings_theme_title"
/>

<Spinner
android:id="@+id/spinner_theme_options"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:drawSelectorOnTop="true"
android:entries="@array/themes"
/>

<TextView
android:id="@+id/dhtSpinnerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:paddingTop="10dp"
android:text="@string/settings_dht_spinner_title" />

<CheckBox
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
<item>Русский</item>
<item>Український</item>
</string-array>

<string-array name="themes">
<item>Light</item>
<item>Dark</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<string name="settings_language_title">Language</string>
<string name="settings_status_title">Status</string>
<string name="settings_note_title">Mood</string>
<string name="settings_theme_title">Theme</string>
<string name="settings_username_title">Username</string>
<string name="settings_empty_strings">You must fill out all fields</string>
<string name="settings_invalid_key">Invalid key entered</string>
Expand Down

0 comments on commit 59f4e30

Please sign in to comment.