diff --git a/README.md b/README.md index 4da5a84..ba07d6e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # goproxy-android snail007/goproxy全能代理服务器安卓版。 + +#源码说明 +项目使用androidstudio开发,基于[snail007/goproxy](https://github.com/snail007/goproxy)官方[安卓SDK](https://github.com/snail007/goproxy-sdk/blob/master/README_ZH.md)开发, +下载项目之后,需要下载[snail007/goproxy](https://github.com/snail007/goproxy)官方[安卓SDK](https://github.com/snail007/goproxy-sdk/blob/master/README_ZH.md)然后解压得到文件 +snail007.goproxy.sdk.aar和snail007.goproxy.sdk-sources.jar放到项目目录app/libs下面即可,然后项目就可以正常编译使用。 \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..1eae732 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,39 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.host900.goproxy" + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} +repositories { + flatDir { + dirs 'libs' + } +} +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation(name: 'snail007.goproxy.sdk', ext: 'aar') + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.vectordrawable:vectordrawable:1.0.1' + implementation 'androidx.navigation:navigation-fragment:2.0.0' + implementation 'androidx.navigation:navigation-ui:2.0.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..617af55 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..dc723ab Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/com/host900/goproxy/MainActivity.java b/app/src/main/java/com/host900/goproxy/MainActivity.java new file mode 100644 index 0000000..3875207 --- /dev/null +++ b/app/src/main/java/com/host900/goproxy/MainActivity.java @@ -0,0 +1,227 @@ +package com.host900.goproxy; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Paint; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.Uri; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.text.method.ScrollingMovementMethod; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +import snail007.proxysdk.LogCallback; +import snail007.proxysdk.Proxysdk; + +public class MainActivity extends AppCompatActivity { + + String TAG = "HomeFragment"; + String serviceID = "srv"; + int log_line_cnt = 0; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + final EditText editText = findViewById(R.id.input); + + SharedPreferences config = getSharedPreferences("config", Context.MODE_PRIVATE); + final SharedPreferences.Editor editor = config.edit(); + + final String args = config.getString("args", ""); + editText.setText(args); + editText.addTextChangedListener(watcher(editor, editText)); + + TextView status = findViewById(R.id.tv_status); + EditText log = (EditText)findViewById(R.id.log_output); + TextView tip = findViewById(R.id.tip); + TextView ipaddrs = findViewById(R.id.ip_addrs); + String sdkVersion = Proxysdk.version(); + TextView viewManual = findViewById(R.id.view_manual); + TextView joinQQ = findViewById(R.id.join_qq_group); + + //ui + viewManual.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线 + viewManual.getPaint().setAntiAlias(true);//抗锯齿 + + getSupportActionBar().setTitle("全能代理服务器"); + tip.setText("由 snail007/goproxy SDK " + sdkVersion + " 强力驱动!"); + ipaddrs.setText(getIpAddress(getBaseContext())); + + joinQQ.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线 + joinQQ.getPaint().setAntiAlias(true);//抗锯齿 + + log.setMovementMethod(ScrollingMovementMethod.getInstance()); + + //event + findViewById(R.id.btn_start).setOnClickListener(start(log, status, editText, this)); + findViewById(R.id.btn_stop).setOnClickListener(stop(status, editText)); + viewManual.setOnClickListener(openURL("https://snail007.github.io/goproxy/manual/zh/#/")); + joinQQ.setOnClickListener(openURL("https://jq.qq.com/?_wv=1027&k=5G2EwxR")); + + return; + } + + public View.OnClickListener stop(final TextView status, final EditText editText) { + return new View.OnClickListener() { + @Override + public void onClick(View view) { + Proxysdk.stop((serviceID)); + editText.setEnabled(true); + status.setText("已停止"); + } + }; + } + + public View.OnClickListener start(final EditText log, final TextView status, final EditText editText, final Context ctx) { + + return new View.OnClickListener() { + @Override + public void onClick(View view) { + String args = editText.getText().toString().trim(); + if(args.indexOf("proxy")==0&&args.length()>=5){ + args=args.substring(5); + } + String err = Proxysdk.startWithLog(serviceID, args, "", new LogCallback() { + @Override + public void write(String line) { + if (++log_line_cnt > 100) { + log.setText(""); + } + log.append(line + "\n"); + } + }); + if (!err.isEmpty()) { + Toast.makeText(ctx, err, Toast.LENGTH_LONG).show(); + // Log.d(TAG, err); + } else { + editText.setEnabled(false); + status.setText("运行中"); + } + } + }; + } + + public View.OnClickListener openURL(final String u) { + + return new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + Uri content_url = Uri.parse(u); + intent.setData(content_url); +// startActivity(Intent.createChooser(intent, "请选择浏览器")); + if (intent.resolveActivity(getPackageManager()) != null) { + startActivity(intent); + } + } + }; + } + + @Override + public void onDestroy() { + super.onDestroy(); + Proxysdk.stop(serviceID); + } + + public TextWatcher watcher(final SharedPreferences.Editor editor, final EditText editText) { + return new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + editor.putString("args", editText.getText().toString()); + // Log.d(TAG, editText.getText().toString()); + editor.commit(); + } + }; + } + + public static String getIpAddress(Context context) { + NetworkInfo info = ((ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); + if (info != null && info.isConnected()) { + // 3/4g网络 + if (info.getType() == ConnectivityManager.TYPE_MOBILE) { + try { + for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + + } else if (info.getType() == ConnectivityManager.TYPE_WIFI) { + // wifi网络 + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + String ipAddress = intIP2StringIP(wifiInfo.getIpAddress()); + return ipAddress; + } else if (info.getType() == ConnectivityManager.TYPE_ETHERNET) { + // 有限网络 + return getLocalIp(); + } + } + return null; + } + + private static String intIP2StringIP(int ip) { + return (ip & 0xFF) + "." + + ((ip >> 8) & 0xFF) + "." + + ((ip >> 16) & 0xFF) + "." + + (ip >> 24 & 0xFF); + } + + + // 获取有限网IP + private static String getLocalIp() { + try { + for (Enumeration en = NetworkInterface + .getNetworkInterfaces(); en.hasMoreElements(); ) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf + .getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress() + && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException ex) { + + } + return "0.0.0.0"; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-v24/log_shape.xml b/app/src/main/res/drawable-v24/log_shape.xml new file mode 100644 index 0000000..6735d4d --- /dev/null +++ b/app/src/main/res/drawable-v24/log_shape.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml new file mode 100644 index 0000000..46fc8de --- /dev/null +++ b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml new file mode 100644 index 0000000..f8bb0b5 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml new file mode 100644 index 0000000..78b75c3 --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..be746fa --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +