Added tool IP Query.

This commit is contained in:
2022-09-27 18:46:16 +08:00
parent 09eeab35c4
commit 95124ad291
26 changed files with 437 additions and 13 deletions

2
.idea/misc.xml generated
View File

@@ -22,8 +22,10 @@
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_bottom_radius.xml" value="0.2915" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_no_radius.xml" value="0.165" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_progress_bar.xml" value="0.2655" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_right_radius.xml" value="0.2495" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_round.xml" value="0.2655" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_side_nav_bar.xml" value="0.2655" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_start_radius.xml" value="0.2495" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_theme_bottom.xml" value="0.164" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_theme_middle.xml" value="0.2655" />
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_theme_top.xml" value="0.164" />

View File

@@ -96,7 +96,7 @@ afterEvaluate {
dependencies {
//noinspection GradleDependency
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@@ -57,6 +57,16 @@
<intent-filter>
<action android:name="oxygentoolbox.translation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".tools.ip.MainActivity"
android:exported="false"
android:theme="@style/Theme.OxygenToolbox.Default">
<intent-filter>
<action android:name="oxygentoolbox.ip" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

View File

@@ -29,6 +29,13 @@
"en": "Translation"
},
"activity": "com.fatapp.oxygentoolbox.tools.translation.MainActivity"
},
{
"text": {
"cn": "\u0049\u0050\u0020\u67e5\u8be2",
"en": "IP Query"
},
"activity": "com.fatapp.oxygentoolbox.tools.ip.MainActivity"
}
]
}

View File

@@ -130,7 +130,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
super.onAnimationEnd(animation);
if (!isShow) {
LinearLayout linearLayout = defaultView.findViewById(R.id.linear_layout_head);
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_bottom_radius));
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_radius));
}
}
});

View File

@@ -0,0 +1,160 @@
package com.fatapp.oxygentoolbox.tools.ip;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.fatapp.oxygentoolbox.BuildConfig;
import com.fatapp.oxygentoolbox.R;
import com.fatapp.oxygentoolbox.util.ResourceUtil;
import com.fatapp.oxygentoolbox.util.http.HttpHelper;
import com.fatapp.oxygentoolbox.util.http.ResponseListener;
import com.fatapp.oxygentoolbox.util.tool.BaseActivityNormal;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends BaseActivityNormal {
final String URL_SELF = "https://www.mxnzp.com/api/ip/self?app_id=%s&app_secret=%s";
final String URL_QUERY = "https://www.mxnzp.com/api/ip/aim_ip?ip=%s&app_id=%s&app_secret=%s";
private TextView textViewCurrentIP;
private EditText editTextIpAddress;
private ImageView imageViewQuery;
private TextView textViewResultIP;
private TextView textViewResultProvince;
private TextView textViewResultCity;
private TextView textViewResultIsp;
private void initView() {
textViewCurrentIP = findViewById(R.id.text_view_current_ip);
editTextIpAddress = findViewById(R.id.edit_text_ipaddress);
imageViewQuery = findViewById(R.id.image_view_query);
textViewResultIP = findViewById(R.id.text_view_result_ip);
textViewResultProvince = findViewById(R.id.text_view_result_province);
textViewResultCity = findViewById(R.id.text_view_result_city);
textViewResultIsp = findViewById(R.id.text_view_result_isp);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadView(this, R.layout.activity_tool_ip);
initView();
getCurrentIP();
initQuery();
}
private void getCurrentIP() {
final HttpHelper httpHelper = new HttpHelper(this, URL_SELF, new ResponseListener() {
@Override
public void onResponse(int code, String responseBody) {
if (code == 200) {
try {
if (new JSONObject(responseBody).getInt("code") == 1) {
final JSONObject data = new JSONObject(responseBody).getJSONObject("data");
String ip = data.getString("ip");
String desc = data.getString("desc");
textViewCurrentIP.setText(String.format("%s %s", ip, desc));
} else {
onFailed();
}
} catch (JSONException e) {
onFailed();
}
} else {
onFailed();
}
}
@Override
public void onFailed() {
textViewCurrentIP.setText(ResourceUtil.getString(R.string.tool_ip_Unknown));
}
});
httpHelper.request(BuildConfig.ROLL_APP_ID, BuildConfig.ROLL_APP_SECRET);
}
private void initQuery() {
editTextIpAddress.addTextChangedListener(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) {
imageViewQuery.setEnabled(charSequence.length() != 0);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
editTextIpAddress.setOnEditorActionListener((textView, actionId, keyEvent) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
query();
return true;
}
return false;
});
imageViewQuery.setEnabled(false);
imageViewQuery.setOnClickListener(view -> query());
}
private void query() {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(editTextIpAddress.getWindowToken(), 0);
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle(R.string.tool_ip_querying);
progressDialog.show();
final HttpHelper httpHelper = new HttpHelper(this, URL_QUERY, new ResponseListener() {
@Override
public void onResponse(int code, String responseBody) {
progressDialog.cancel();
if (code == 200) {
try {
if (new JSONObject(responseBody).getInt("code") == 1) {
final JSONObject data = new JSONObject(responseBody).getJSONObject("data");
String ip = data.getString("ip");
String province = data.getString("province");
String city = data.getString("city");
String isp = data.getString("isp");
textViewResultIP.setText(ip.isEmpty() ? ResourceUtil.getString(R.string.tool_ip_Unknown) : ip);
textViewResultProvince.setText(province.isEmpty() ? ResourceUtil.getString(R.string.tool_ip_Unknown) : province);
textViewResultCity.setText(city.isEmpty() ? ResourceUtil.getString(R.string.tool_ip_Unknown) : city);
textViewResultIsp.setText(isp.isEmpty() ? ResourceUtil.getString(R.string.tool_ip_Unknown) : isp);
} else {
onFailed();
textViewResultIP.setText(new JSONObject(responseBody).getString("msg"));
}
} catch (JSONException e) {
onFailed();
}
} else {
onFailed();
}
}
@Override
public void onFailed() {
textViewResultIP.setText(ResourceUtil.getString(R.string.tool_ip_Unknown));
textViewResultProvince.setText(ResourceUtil.getString(R.string.tool_ip_Unknown));
textViewResultCity.setText(ResourceUtil.getString(R.string.tool_ip_Unknown));
textViewResultIsp.setText(ResourceUtil.getString(R.string.tool_ip_Unknown));
}
});
httpHelper.request(editTextIpAddress.getText().toString(), BuildConfig.ROLL_APP_ID, BuildConfig.ROLL_APP_SECRET);
}
}

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?attr/tools_button_ripple">
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/tools_button_ripple">
<item android:id="@android:id/mask">
<shape>
<solid android:color="?attr/tools_button_ripple" />

View File

@@ -3,5 +3,5 @@
<solid android:color="?attr/app_on_background_theme" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"/>
android:bottomRightRadius="10dp" />
</shape>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/app_on_background_theme" />
<corners
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" />
</shape>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?attr/app_on_background_theme" />
<stroke
android:width="2dp"
android:color="?attr/app_theme" />
<corners
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" />
</shape>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/app_on_background_theme" />
<corners
android:bottomRightRadius="10dp"
android:topRightRadius="10dp" />
</shape>

View File

@@ -3,5 +3,5 @@
<solid android:color="?attr/app_on_background_theme" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"/>
android:bottomRightRadius="10dp" />
</shape>

View File

@@ -3,5 +3,5 @@
<solid android:color="?attr/app_on_background_theme" />
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
android:topRightRadius="10dp" />
</shape>

View File

@@ -3,5 +3,5 @@
<solid android:color="?attr/app_on_background_theme" />
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
android:topRightRadius="10dp" />
</shape>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/app_theme" />
<corners
android:bottomRightRadius="10dp"
android:topRightRadius="10dp" />
</shape>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/app_on_theme"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z" />
</vector>

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".tools.ip.MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout_current_ip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/text_view_current_ip_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tool_ip_current_IP"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/text_view_current_ip"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_current_ip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tool_ip_Unknown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/text_view_current_ip_tip"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:padding="@dimen/tool_ip_common_padding"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/constraint_layout_current_ip">
<EditText
android:id="@+id/edit_text_ipaddress"
android:layout_width="0dp"
android:layout_height="@dimen/tool_ip_query_bar_size"
android:autofillHints="ip"
android:background="@drawable/background_left_radius_border"
android:hint="@string/tool_ip_ipaddress"
android:imeOptions="actionSearch"
android:inputType="text"
android:padding="@dimen/tool_ip_common_padding"
app:layout_constraintEnd_toStartOf="@id/image_view_query"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/image_view_query"
android:layout_width="@dimen/tool_ip_query_bar_size"
android:layout_height="@dimen/tool_ip_query_bar_size"
android:background="@drawable/foreground_right_radius"
android:clickable="true"
android:contentDescription="Query"
android:focusable="true"
android:foreground="@drawable/foreground_ripple"
android:padding="@dimen/tool_ip_common_padding"
android:src="@drawable/ic_search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/edit_text_ipaddress"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:orientation="vertical"
android:padding="@dimen/tool_ip_common_padding"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/constraint_layout_query">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_ipaddress" />
<TextView
android:id="@+id/text_view_result_ip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_Unknown" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_province" />
<TextView
android:id="@+id/text_view_result_province"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_Unknown" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_city" />
<TextView
android:id="@+id/text_view_result_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_Unknown" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_isp" />
<TextView
android:id="@+id/text_view_result_isp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/common_layout_margin"
android:text="@string/tool_ip_Unknown" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/tool_translation_layout_margin"
android:background="@drawable/background_top_bottom_radius"
android:background="@drawable/background_radius"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
@@ -52,7 +52,7 @@
android:layout_height="@dimen/tool_translation_edit_text_view_height"
android:layout_margin="@dimen/tool_translation_layout_margin"
android:autofillHints="text"
android:background="@drawable/background_top_bottom_radius"
android:background="@drawable/background_radius"
android:gravity="start|top"
android:hint="@string/tool_translation_please_enter_text"
android:inputType="textMultiLine"
@@ -71,7 +71,7 @@
android:layout_height="@dimen/tool_translation_edit_text_view_height"
android:layout_margin="@dimen/tool_translation_layout_margin"
android:autofillHints="text"
android:background="@drawable/background_top_bottom_radius"
android:background="@drawable/background_radius"
android:gravity="start|top"
android:paddingHorizontal="@dimen/tool_translation_edit_text_view_padding"
android:paddingTop="@dimen/tool_translation_edit_text_view_padding_plus"

File diff suppressed because one or more lines are too long

View File

@@ -77,4 +77,12 @@
<string name="tool_translation_choose_language">选择语言</string>
<string name="tool_translation_please_enter_text">请输入内容……</string>
<string name="tool_translation_translation_failed">翻译失败</string>
<string name="tool_ip_current_IP">当前 IP</string>
<string name="tool_ip_Unknown">未知</string>
<string name="tool_ip_ipaddress">IP 地址</string>
<string name="tool_ip_querying">查询中</string>
<string name="tool_ip_city">城市</string>
<string name="tool_ip_province">省份</string>
<string name="tool_ip_isp">网络提供商</string>
</resources>

View File

@@ -77,4 +77,12 @@
<string name="tool_translation_choose_language">选择语言</string>
<string name="tool_translation_please_enter_text">请输入内容……</string>
<string name="tool_translation_translation_failed">翻译失败</string>
<string name="tool_ip_current_IP">当前 IP</string>
<string name="tool_ip_Unknown">未知</string>
<string name="tool_ip_ipaddress">IP 地址</string>
<string name="tool_ip_querying">查询中</string>
<string name="tool_ip_city">城市</string>
<string name="tool_ip_province">省份</string>
<string name="tool_ip_isp">网络提供商</string>
</resources>

View File

@@ -77,4 +77,12 @@
<string name="tool_translation_choose_language">选择语言</string>
<string name="tool_translation_please_enter_text">请输入内容……</string>
<string name="tool_translation_translation_failed">翻译失败</string>
<string name="tool_ip_current_IP">当前 IP</string>
<string name="tool_ip_Unknown">未知</string>
<string name="tool_ip_ipaddress">IP 地址</string>
<string name="tool_ip_querying">查询中</string>
<string name="tool_ip_city">城市</string>
<string name="tool_ip_province">省份</string>
<string name="tool_ip_isp">网络提供商</string>
</resources>

View File

@@ -44,4 +44,7 @@
<dimen name="tool_translation_edit_text_view_padding_plus">30dp</dimen>
<dimen name="tool_translation_layout_margin">@dimen/common_layout_margin</dimen>
<dimen name="tool_translation_edit_text_view_height">200dp</dimen>
<dimen name="tool_ip_common_padding">10dp</dimen>
<dimen name="tool_ip_query_bar_size">48dp</dimen>
</resources>

View File

@@ -113,4 +113,12 @@
<string name="tool_translation_language_korean" translatable="false">한국인</string>
<string name="tool_translation_please_enter_text">Please enter text…</string>
<string name="tool_translation_translation_failed">Translation Failed</string>
<string name="tool_ip_current_IP">Current IP:&#160;</string>
<string name="tool_ip_Unknown">Unknown</string>
<string name="tool_ip_ipaddress">IP address</string>
<string name="tool_ip_querying">Querying</string>
<string name="tool_ip_city">City</string>
<string name="tool_ip_province">Province</string>
<string name="tool_ip_isp">ISP</string>
</resources>

View File

@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'com.mikepenz.aboutlibraries.plugin' version '10.3.1' apply false
}