parent
aec090b22e
commit
fb2d81550c
|
@ -23,6 +23,10 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
|
||||
package com.luca0n.joguitos.pluck.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -33,10 +37,14 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.luca0n.joguitos.pluck.R;
|
||||
import com.luca0n.joguitos.pluck.PluckApplication;
|
||||
import com.luca0n.joguitos.pluck.exceptions.NoTriviaResultsException;
|
||||
import com.luca0n.joguitos.pluck.trivia.TriviaQuery;
|
||||
import com.luca0n.joguitos.pluck.trivia.TriviaQuestion;
|
||||
|
@ -62,7 +70,23 @@ public class ApiUtil {
|
|||
String response;
|
||||
|
||||
URL url = new URL(query);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
HttpURLConnection connection;
|
||||
|
||||
// Check if the player wants to play the game using Tor.
|
||||
Context c = PluckApplication.getAppContext();
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
|
||||
String key = c.getResources().getString(R.string.pref_network_tor);
|
||||
// Connect without Tor by default.
|
||||
boolean useTor = sp.getBoolean(key, false);
|
||||
// Default Orbot SOCKS5 address.
|
||||
String orbotSocks5Hostname = "127.0.0.1";
|
||||
int orbotSocks5Port = 9050;
|
||||
|
||||
if (useTor)
|
||||
connection = (HttpURLConnection) url.openConnection(
|
||||
new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(orbotSocks5Hostname, orbotSocks5Port)));
|
||||
else
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
try {
|
||||
InputStream in = new BufferedInputStream(connection.getInputStream());
|
||||
|
|
Loading…
Reference in New Issue