Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show local IP on setting activity #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* From: https://resources.oreilly.com/examples/9781565923713/blob/master/SimpleProxyServer.java
*/
public class Simple implements Runnable {
public static int defaultLocalPort = 9999;

public void run(String remotehost, int remoteport, int localport) throws IOException {
// Create a ServerSocket to listen for connections with
ServerSocket ss = new ServerSocket(localport);
Expand Down Expand Up @@ -109,7 +111,7 @@ public void run() {
public void run() {
Log.d("Freenet", "Proxy thread started");
try {
run("127.0.0.1", 8888, 9999);
run("127.0.0.1", 8888, defaultLocalPort);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package org.freenetproject.mobile.ui.settings.activity;

import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.text.format.Formatter;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;

import org.freenetproject.mobile.R;
import org.freenetproject.mobile.proxy.Simple;

public class SettingsActivity extends AppCompatActivity {

private static String localIp;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,12 +28,23 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
localIp = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
SwitchPreferenceCompat editPref = findPreference("web_access");
editPref.setSummary(
getActivity().getApplicationContext().getString(
R.string.web_access_summary,
localIp,
Simple.defaultLocalPort
)
);
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="preserve_data_summary">Freenet nutzt Netzwerkdaten intensiv. Wenn diese Option aktiviert ist, wird Freenet nur ausgeführt, wenn eine Verbindung zu Wifi besteht. Der Knoten muss neu gestartet werden, um diese Einstellung zu aktivieren.</string>
<string name="preserve_battery_summary">Freenet kann dazu führen, dass sich der Akku schnell entlädt. Wenn diese Option aktiviert ist, läuft Freenet nur beim Aufladen. Der Knoten muss neu gestartet werden, um diese Einstellung zu aktivieren.</string>
<string name="web_access">Zugriff vom PC</string>
<string name="web_access_summary">Greifen Sie von einem PC oder Tablet auf Freenet zu, das auf Ihrem Telefon ausgeführt wird. Das Gerät muss sich im selben Netzwerk befinden. Greifen Sie über die lokale IP-Adresse und den Port des Telefons darauf zu: 9999 (z. B. 192.168.x.x:9999).</string>
<string name="web_access_summary">Greifen Sie von einem PC oder Tablet auf Freenet zu, das auf Ihrem Telefon ausgeführt wird. Das Gerät muss sich im selben Netzwerk befinden. Greifen Sie über: http://%1$s:%2$d.</string>
<string name="node_paused">Freenet ist angehalten.</string>
<string name="preserve_battery">Batterie schonen</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<string name="preserve_battery">Conservar la batería</string>
<string name="preserve_battery_summary">Freenet puede hacer que la batería se descargue rápidamente. Con esta opción habilitada, Freenet solo se ejecutará cuando se cargue. El nodo debe reiniciarse para activar esta configuración.</string>
<string name="web_access">Acceso desde PC</string>
<string name="web_access_summary">Acceda a Freenet en su teléfono desde una PC o tableta. El dispositivo debe estar en la misma red. Acceda a él a través del teléfono IP local y el puerto: 9999 (ej. 192.168.x.x: 9999).</string>
<string name="web_access_summary">Acceda a Freenet en su teléfono desde una PC o tableta. El dispositivo debe estar en la misma red. Acceda a él a través de: http://%1$s:%2$d.</string>
<string name="node_paused">Freenet está pausado.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<string name="preserve_battery">Préserver la batterie</string>
<string name="preserve_battery_summary">Freenet peut provoquer une décharge rapide de la batterie. Avec cette option activée, Freenet ne fonctionnera que lors du chargement. Le nœud doit être redémarré pour activer ce paramètre.</string>
<string name="web_access">Accès depuis un PC</string>
<string name="web_access_summary">Accédez à Freenet en cours d\'exécution sur votre téléphone depuis un PC ou une tablette. L\'appareil doit être sur le même réseau. Accédez-y via l\'adresse IP et le port locaux du téléphone: 9999 (ex. 192.168.x.x:9999).</string>
<string name="web_access_summary">Accédez à Freenet en cours d\'exécution sur votre téléphone depuis un PC ou une tablette. L\'appareil doit être sur le même réseau. Accédez-y via: http://%1$s:%2$d.</string>
<string name="node_paused">Freenet est en pause.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<string name="preserve_battery">Preservar bateria</string>
<string name="preserve_battery_summary">O Freenet pode fazer com que a bateria descarregue rapidamente. Com esta opção ativada, o Freenet funcionará apenas durante o carregamento. O nó deve ser reiniciado para ativar esta configuração.</string>
<string name="web_access">Acesso do PC</string>
<string name="web_access_summary">Acesse o Freenet em execução no seu telefone a partir de um PC ou tablet. O dispositivo deve estar na mesma rede. Acesse-o através do IP local do telefone e porta: 9999 (ex. 192.168.x.x:9999).</string>
<string name="web_access_summary">Acesse o Freenet em execução no seu telefone a partir de um PC ou tablet. O dispositivo deve estar na mesma rede. Acesse-o através do: http://%1$s:%2$d.</string>
<string name="node_paused">Freenet está em pausa.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<string name="preserve_battery_summary">Freenet may cause the battery to discharge quickly. With this option enabled Freenet will run only when charging.\n\nThe node must be restarted to activate this setting.</string>
<!-- Freenet Web Preferences -->
<string name="web_access">Access from PC</string>
<string name="web_access_summary">Access Freenet running on your phone from a PC or Tablet. The device must be on the same network. Access it through the phone\'s local IP and port: 9999 (ex. 192.168.x.x:9999).</string>
<string name="web_access_summary">Access Freenet running on your phone from a PC or Tablet. The device must be on the same network. Access it through: http://%1$s:%2$d.</string>
<string name="node_paused">Freenet is paused.</string>
<string name="app_version" translatable="false">v%1$s</string>
</resources>