diff --git a/README.md b/README.md index 54d00ca..f2111db 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ A Material Design Shipment Tracker Android App. ### 开发环境需求 -- Android SDK Platform 24 -- Android Support Library 24.0.0 -- Gradle + Android Studio 2.2 Preview1 +- Android SDK Platform 26 +- Android Support Library 26.0.0 +- Gradle + Android Studio 2.3 / IntelliJ IDEA 2017.1 - Windows / Linux / Mac ### 应用安装需求 @@ -28,16 +28,16 @@ Fung Go (fython) Email: fython@163.com 联系 QQ: 2850029060 -捐赠支持(支付宝): 316643843@qq.com +捐赠支持(支付宝): fythonx@gmail.com -博客地址: http://blog.feng.moe +博客地址: https://feng.moe ### License ``` GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 -Copyright (C) 2016 Fung Go +Copyright (C) 2016-2017 Fung Go This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. diff --git a/build.gradle b/build.gradle index b902c03..a999425 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,10 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { + ext.android_support_lib_version = '26.0.0-beta2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } @@ -18,6 +14,9 @@ allprojects { maven { url "https://jitpack.io" } + maven { + url "https://maven.google.com" + } } } diff --git a/gradle.properties b/gradle.properties index 7ed875d..aaf3844 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,6 @@ -## Project-wide Gradle settings. -# -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx1024m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -# -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -#Wed Dec 28 20:18:09 CST 2016 org.gradle.jvmargs=-Xmx1536m -BUILD_TOOLS_VERSION=25.0.2 -VERSION_NAME=2.5.1 -TARGET_SDK_VERSION=25 -VERSION_CODE=34 +BUILD_TOOLS_VERSION=26.0.0 +VERSION_NAME=2.6.0 +TARGET_SDK_VERSION=26 +VERSION_CODE=35 MIN_SDK_VERSION=19 \ No newline at end of file diff --git a/mobile/build.gradle b/mobile/build.gradle index b4c7147..3a3a25d 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -28,11 +28,11 @@ dependencies { compile project(':libraries:AdvancedRecyclerView') compile project(':libraries:StatusBarCompat') compile project(':bottom-bar-1.4.0.1') - compile 'com.android.support:appcompat-v7:25.1.0' - compile 'com.android.support:cardview-v7:25.1.0' - compile 'com.android.support:design:25.1.0' - compile 'com.android.support:support-v13:25.1.0' - compile 'com.android.support:customtabs:25.1.0' + compile "com.android.support:appcompat-v7:$android_support_lib_version" + compile "com.android.support:cardview-v7:$android_support_lib_version" + compile "com.android.support:recyclerview-v7:$android_support_lib_version" + compile "com.android.support:design:$android_support_lib_version" + compile "com.android.support:customtabs:$android_support_lib_version" compile 'com.google.code.gson:gson:2.8.0' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.rengwuxian.materialedittext:library:2.1.4' diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index 1ad283a..27c2fd0 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -109,6 +109,14 @@ + + + + + + diff --git a/mobile/src/main/java/info/papdt/express/helper/asynctask/CompanyFilterTask.java b/mobile/src/main/java/info/papdt/express/helper/asynctask/CompanyFilterTask.java index 3e27147..0eefa97 100644 --- a/mobile/src/main/java/info/papdt/express/helper/asynctask/CompanyFilterTask.java +++ b/mobile/src/main/java/info/papdt/express/helper/asynctask/CompanyFilterTask.java @@ -12,11 +12,16 @@ public class CompanyFilterTask extends AsyncTask doInBackground(String... strings) { - String keyword = ZHConverter.convert(strings[0], ZHConverter.SIMPLIFIED); + return doSync(strings[0]); + } + + public static ArrayList doSync(String keyword) { + keyword = ZHConverter.convert(keyword, ZHConverter.SIMPLIFIED).replaceAll("快递", ""); ArrayList src = new ArrayList<>(); if (keyword != null && keyword.trim().length() > 0) { for (int i = 0; i < PackageApi.CompanyInfo.info.size(); i++) { - if (!PackageApi.CompanyInfo.names [i].toLowerCase().contains(keyword.toLowerCase()) && !PackageApi.CompanyInfo.pinyin [i].contains(keyword)) { + if (!PackageApi.CompanyInfo.names [i].toLowerCase().contains(keyword.toLowerCase()) + && !PackageApi.CompanyInfo.pinyin[i].contains(keyword)) { continue; } diff --git a/mobile/src/main/java/info/papdt/express/helper/services/DetectNumberService.java b/mobile/src/main/java/info/papdt/express/helper/services/DetectNumberService.java new file mode 100644 index 0000000..f2c9e0a --- /dev/null +++ b/mobile/src/main/java/info/papdt/express/helper/services/DetectNumberService.java @@ -0,0 +1,361 @@ +package info.papdt.express.helper.services; + +import android.accessibilityservice.AccessibilityService; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.*; +import android.os.Build; +import android.text.TextUtils; +import android.util.Log; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityNodeInfo; +import info.papdt.express.helper.R; +import info.papdt.express.helper.dao.PackageDatabase; +import info.papdt.express.helper.ui.AddActivity; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class DetectNumberService extends AccessibilityService { + + private PackageDatabase mPackageDatabase; + private String mShowingNumber = null; + private NotificationManager mNotificationManager; + private NotificationActionReceiver mActionReceiver; + + private String lastCompany = null, lastName = null; + + public static final int NOTIFICATION_ID_ASSIST = 100; + + private static final String PACKAGE_TAOBAO = "com.taobao.taobao", PACKAGE_JD = "com.jingdong.app.mall"; + + private static final String TAOBAO_WAYBILL_VIEW_ID = "tv_logistic_waybill_number", + TAOBAO_COMPANY_VIEW_ID = "tv_logistic_company", + JD_TEXT_RIGHT_VIEW_ID = "text_right", + JD_TEXT_LEFT_VIEW_ID = "text_left", + JD_TEXT_MSG_ITEM_VIEW_ID = "item_msg", + JD_ORDER_ID_CONTENT_VIEW_ID = "order_id_content", + JD_DELIVERY_WAY_CONTENT_VIEW_ID = "delivery_way_content", + JD_WARE_INFO_NAME_VIEW_ID = "ware_info_name"; + + private static final String TAOBAO_CHECK_ACTIVITY = "com.taobao.cainiao.logistic.LogisticDetailActivity"; + private static final String JD_CHECK_ACTIVITY = "com.jd.lib.ordercenter.logisticstrack.LogisticsTrackActivity"; + private static final String JD_CHECK_ACTIVITY_2 = "com.jd.lib.ordercenter.neworderdetail.NewOrderDetailActivity"; + + private static final String ACTION_DELETE_ASSIST_NOTI = "info.papdt.express.helper.ACTION_DELETE_ASSIST_NOTI"; + + public static final String TAG = DetectNumberService.class.getSimpleName(); + + @Override + public void onServiceConnected() { + mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mPackageDatabase = PackageDatabase.getInstance(this); + getServiceInfo().packageNames = new String[] { + PACKAGE_TAOBAO, + PACKAGE_JD + }; + setServiceInfo(getServiceInfo()); + + try { + if (mActionReceiver != null) { + unregisterReceiver(mActionReceiver); + } + mActionReceiver = new NotificationActionReceiver(); + registerReceiver(mActionReceiver, new IntentFilter(ACTION_DELETE_ASSIST_NOTI)); + } catch (Exception e) { + + } + } + + @Override + public void onAccessibilityEvent(AccessibilityEvent event) { + AccessibilityNodeInfo nodeInfo = event.getSource(); + switch (event.getEventType()) { + case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: + Log.i(TAG, event.getClassName().toString()); + switch (event.getPackageName().toString()) { + case PACKAGE_TAOBAO: + if (!TAOBAO_CHECK_ACTIVITY.equals(event.getClassName().toString())) { + mShowingNumber = null; + lastCompany = null; + lastName = null; + } + break; + case PACKAGE_JD: + if (!JD_CHECK_ACTIVITY.equals(event.getClassName().toString()) && + !JD_CHECK_ACTIVITY_2.equals(event.getClassName().toString())) { + mShowingNumber = null; + lastCompany = null; + lastName = null; + } + break; + } + case AccessibilityEvent.TYPE_WINDOWS_CHANGED: + case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: + switch (event.getPackageName().toString()) { + case PACKAGE_TAOBAO: + try { + String number = null, company = null; + List nodes + = search(0, nodeInfo, TAOBAO_WAYBILL_VIEW_ID); + for (AccessibilityNodeInfo node : nodes) { + number = getPackageNumber(node.getText().toString()); + break; + } + nodes = search(0, nodeInfo, TAOBAO_COMPANY_VIEW_ID); + for (AccessibilityNodeInfo node : nodes) { + company = getPackageCompany(node.getText().toString()); + break; + } + if (number != null && mPackageDatabase.indexOf(number) == -1 + && !number.equals(mShowingNumber)) { + mShowingNumber = number; + sendNotification("淘宝", company, number, null, true); + } + } catch (Exception e) { + + } + break; + case PACKAGE_JD: + try { + List flatNodes = flatNodes(nodeInfo); + String number = findNumberFromJd(flatNodes); + String company = findCompanyFromJd(flatNodes); + String name = findNameFromJd(flatNodes); + if (number != null && mPackageDatabase.indexOf(number) == -1) { + if (!number.equals(mShowingNumber)) { + mShowingNumber = number; + lastCompany = company; + lastName = name; + sendNotification("京东", company, number, name, true); + } else if (lastCompany == null || lastName == null) { + lastCompany = company; + lastName = name; + sendNotification("京东", company, number, name, false); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + break; + } + break; + } + } + + @Override + public void onInterrupt() { + unregisterReceiver(mActionReceiver); + mActionReceiver = null; + mPackageDatabase = null; + } + + private String findCompanyFromJd(List nodeInfos) { + Iterator iterator = nodeInfos.iterator(); + while (iterator.hasNext()) { + AccessibilityNodeInfo cur = iterator.next(); + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_TEXT_LEFT_VIEW_ID)) { + if (cur.getText().toString().contains("国内承运人")) { + AccessibilityNodeInfo next = iterator.next(); + if (next != null + && next.getViewIdResourceName() != null + && next.getViewIdResourceName().contains(JD_TEXT_RIGHT_VIEW_ID) + && !TextUtils.isEmpty(next.getText())) { + if (next.getText().toString().contains("京东")) { + return "京东快递"; + } else { + return next.getText().toString(); + } + } + } + } + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_TEXT_MSG_ITEM_VIEW_ID)) { + if (cur.getText() != null && cur.getText().toString().contains("待出库交付")) { + String target = cur.getText().toString(); + int startIndex = target.indexOf("待出库交付") + 5; + int endIndex = target.substring(startIndex).indexOf(",") + startIndex; + if (endIndex == -1) endIndex = startIndex + 4; + if (endIndex >= target.length()) endIndex = target.length() - 1; + return target.substring(startIndex, endIndex); + } + } + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_DELIVERY_WAY_CONTENT_VIEW_ID)) { + if (cur.getText().toString().contains("京东")) { + return "京东快递"; + } else { + return cur.getText().toString(); + } + } + } + return null; + } + + private String findNumberFromJd(List nodeInfos) { + Iterator iterator = nodeInfos.iterator(); + String result = null; + while (iterator.hasNext()) { + AccessibilityNodeInfo cur = iterator.next(); + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_TEXT_LEFT_VIEW_ID)) { + if (cur.getText().toString().contains("订单编号")) { + AccessibilityNodeInfo next = iterator.next(); + if (next != null + && next.getViewIdResourceName() != null + && next.getViewIdResourceName().contains(JD_TEXT_RIGHT_VIEW_ID) + && !TextUtils.isEmpty(next.getText())) { + result = next.getText().toString(); + } + } + } + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_TEXT_MSG_ITEM_VIEW_ID)) { + if (cur.getText() != null && cur.getText().toString().contains("运单号")) { + String target = cur.getText().toString(); + int startIndex = target.indexOf("运单号"); + StringBuffer sb = new StringBuffer(); + String temp = target.substring(startIndex); + for (int i = 0; i < temp.length(); i++) { + int next = (i + 1) > temp.length() ? temp.length() - 1 : i + 1; + String c = temp.substring(i, next); + if (TextUtils.isDigitsOnly(c)) { + sb.append(c); + if (i == temp.length() - 1) { + result = sb.toString(); + } + } else if (sb.length() > 0) { + result = sb.toString(); + sb = new StringBuffer(); + } + } + } + } + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_ORDER_ID_CONTENT_VIEW_ID)) { + return cur.getText().toString(); + } + } + return result; + } + + private String findNameFromJd(List nodeInfos) { + for (AccessibilityNodeInfo cur : nodeInfos) { + if (cur.getViewIdResourceName() != null && cur.getViewIdResourceName().contains(JD_WARE_INFO_NAME_VIEW_ID)) { + return cur.getText().toString(); + } + } + return null; + } + + private List flatNodes(AccessibilityNodeInfo root) { + if (root == null) return null; + if (root.getChildCount() == 0) { + List result = new ArrayList<>(); + result.add(root); + return result; + } + ArrayList list = new ArrayList<>(); + for (int i = 0; i < root.getChildCount(); i++) { + List result = flatNodes(root.getChild(i)); + if (result == null) continue; + list.addAll(result); + } + return list; + } + + private List search(int depth, AccessibilityNodeInfo root, String targetIdName) { + if (root == null) return null; + if (root.getChildCount() == 0) { + //String space = ""; + //for (;depth > 0; depth--) space += " "; + //Log.i(TAG, space + "id:" + root.getViewIdResourceName()); + //try { Log.i(TAG, space + "content:" + root.getText()); } catch (Exception e) {} + if (root.getViewIdResourceName() != null && root.getViewIdResourceName().contains(targetIdName)) { + List result = new ArrayList<>(); + result.add(root); + return result; + } + } + ArrayList list = new ArrayList<>(); + for (int i = 0; i < root.getChildCount(); i++) { + List result = search(depth + 1, root.getChild(i), targetIdName); + if (result == null) continue; + list.addAll(result); + } + return list; + } + + private String getPackageCompany(String source) { + return source.substring(source.indexOf(" ") + 1); + } + + private String getPackageNumber(String source) { + ArrayList results = new ArrayList<>(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < source.length(); i++) { + int next = (i + 1) > source.length() ? source.length() - 1 : i + 1; + String c = source.substring(i, next); + if (TextUtils.isDigitsOnly(c)) { + sb.append(c); + if (i == source.length() - 1) { + results.add(sb.toString()); + Log.i(TAG, "getPackageNumber, found " + sb.toString()); + } + } else if (sb.length() > 0) { + results.add(sb.toString()); + Log.i(TAG, "getPackageNumber, found " + sb.toString()); + sb = new StringBuffer(); + } + } + if (results.isEmpty()) { + return null; + } else { + String longest = ""; + for (String result : results) if (longest.length() < result.length()) longest = result; + return longest; + } + } + + private void sendNotification(String appName, String company, String number, String name, boolean headsUp) { + Intent addIntent = new Intent(getApplicationContext(), AddActivity.class); + addIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + addIntent.putExtra(AddActivity.EXTRA_HAS_PREINFO, true); + addIntent.putExtra(AddActivity.EXTRA_PRE_NUMBER, number); + addIntent.putExtra(AddActivity.EXTRA_PRE_COMPANY, company); + if (name != null) addIntent.putExtra(AddActivity.EXTRA_PRE_NAME, name); + String notiTitle = (name != null) ? getString(R.string.auto_detect_noti_title_with_name, name) + : getString(R.string.auto_detect_noti_title); + String notiText = getString(R.string.auto_detect_noti_result, appName, company, number); + Notification.Builder builder = new Notification.Builder(this) + .setContentTitle(notiTitle) + .setContentText(notiText) + .setSmallIcon(R.drawable.ic_assistant_black_24dp) + .setPriority(Notification.PRIORITY_HIGH) + .setShowWhen(false) + .setAutoCancel(true) + .addAction(R.drawable.ic_add_black_24dp, getString(R.string.auto_detect_noti_action_add), + PendingIntent.getActivity( + this, 0, addIntent, PendingIntent.FLAG_CANCEL_CURRENT + )) + .setDeleteIntent(PendingIntent.getBroadcast( + this, 1002, + new Intent(ACTION_DELETE_ASSIST_NOTI), PendingIntent.FLAG_CANCEL_CURRENT + )); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder.setColor(getResources().getColor(R.color.teal_500)); + } + if (headsUp) { + builder.setDefaults(Notification.DEFAULT_VIBRATE); + } + Notification mNotification = builder.build(); + mNotificationManager.notify(NOTIFICATION_ID_ASSIST, mNotification); + } + + private class NotificationActionReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "Received Action:" + intent.toString()); + } + + } + +} diff --git a/mobile/src/main/java/info/papdt/express/helper/ui/AddActivity.java b/mobile/src/main/java/info/papdt/express/helper/ui/AddActivity.java index db9a966..7d2ac63 100644 --- a/mobile/src/main/java/info/papdt/express/helper/ui/AddActivity.java +++ b/mobile/src/main/java/info/papdt/express/helper/ui/AddActivity.java @@ -2,6 +2,8 @@ import android.app.Fragment; import android.app.FragmentTransaction; +import android.app.NotificationManager; +import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.Build; @@ -15,6 +17,7 @@ import info.papdt.express.helper.R; import info.papdt.express.helper.dao.PackageDatabase; import info.papdt.express.helper.model.Package; +import info.papdt.express.helper.services.DetectNumberService; import info.papdt.express.helper.support.ScreenUtils; import info.papdt.express.helper.support.Settings; import info.papdt.express.helper.ui.common.AbsActivity; @@ -34,13 +37,18 @@ public class AddActivity extends AbsActivity{ private Package pack; private String number; + private String preName, preNumber, preCompany; + private boolean isFromMainActivity = false; private int nowStep; + public static final String EXTRA_PRE_NUMBER = "pre_number", + EXTRA_PRE_COMPANY = "pre_company", EXTRA_PRE_NAME = "pre_name"; + public static final String RESULT_EXTRA_PACKAGE_JSON = "package_json"; - public static final String EXTRA_IS_FROM_MAIN_ACTIVITY = "is_from_main"; + public static final String EXTRA_IS_FROM_MAIN_ACTIVITY = "is_from_main", EXTRA_HAS_PREINFO = "has_pre_info"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,11 +65,22 @@ protected void onCreate(Bundle savedInstanceState) { } setContentView(R.layout.activity_add); - if (getIntent().hasExtra(EXTRA_IS_FROM_MAIN_ACTIVITY) - && getIntent().getBooleanExtra(EXTRA_IS_FROM_MAIN_ACTIVITY, false)) { + Intent intent = getIntent(); + + if (intent.hasExtra(EXTRA_IS_FROM_MAIN_ACTIVITY) + && intent.getBooleanExtra(EXTRA_IS_FROM_MAIN_ACTIVITY, false)) { isFromMainActivity = true; } + if (intent.hasExtra(EXTRA_HAS_PREINFO) + && intent.getBooleanExtra(EXTRA_HAS_PREINFO, false)) { + preNumber = intent.getStringExtra(EXTRA_PRE_NUMBER); + preCompany = intent.getStringExtra(EXTRA_PRE_COMPANY); + preName = intent.getStringExtra(EXTRA_PRE_NAME); + NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + nm.cancel(DetectNumberService.NOTIFICATION_ID_ASSIST); + } + mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setDisplayShowTitleEnabled(false); ((ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams()).topMargin += @@ -170,4 +189,27 @@ public void onBackPressed() { } } + public static void launch(Context context, String company, String number, String name) { + Intent intent = new Intent(context, AddActivity.class); + intent.putExtra(EXTRA_HAS_PREINFO, true); + intent.putExtra(EXTRA_PRE_NUMBER, number); + intent.putExtra(EXTRA_PRE_COMPANY, company); + if (name != null) { + intent.putExtra(EXTRA_PRE_NAME, name); + } + context.startActivity(intent); + } + + public String getPreName() { + return preName; + } + + public String getPreNumber() { + return preNumber; + } + + public String getPreCompany() { + return preCompany; + } + } diff --git a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepInput.java b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepInput.java index 642597a..9545439 100644 --- a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepInput.java +++ b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepInput.java @@ -2,6 +2,7 @@ import android.content.Intent; import android.text.InputType; +import android.text.TextUtils; import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.EditorInfo; @@ -11,6 +12,8 @@ import com.rengwuxian.materialedittext.MaterialEditText; import info.papdt.express.helper.R; +import info.papdt.express.helper.api.PackageApi; +import info.papdt.express.helper.asynctask.CompanyFilterTask; import info.papdt.express.helper.asynctask.GetPackageTask; import info.papdt.express.helper.dao.PackageDatabase; import info.papdt.express.helper.model.BaseMessage; @@ -19,6 +22,8 @@ import info.papdt.express.helper.ui.AddActivity; import info.papdt.express.helper.ui.ScannerActivity; +import java.util.ArrayList; + public class StepInput extends AbsStepFragment { private MaterialEditText mEditText; @@ -43,6 +48,10 @@ public void onClick(View view) { } }); + if (!TextUtils.isEmpty(getAddActivity().getPreNumber())) { + mEditText.setText(getAddActivity().getPreNumber()); + } + mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { @@ -69,7 +78,11 @@ public void onClick(View view) { // Pass check number = mEditText.getText().toString(); if (ConnectivityReceiver.readNetworkState(getActivity())) { - new FindPackageTask().execute(number); + if (TextUtils.isEmpty(getAddActivity().getPreCompany())) { + new FindPackageTask().execute(number); + } else { + new FindCompanyAndGetPackageTask().execute(getAddActivity().getPreCompany()); + } } else { getAddActivity().step(AddActivity.STEP_NO_INTERNET_CONNECTION); } @@ -125,4 +138,18 @@ public void onPostExecute(BaseMessage message) { } } + + private class FindCompanyAndGetPackageTask extends CompanyFilterTask { + + @Override + public void onPostExecute(ArrayList lists) { + if (lists.size() == 1) { + new FindPackageTask().execute(number, lists.get(0).code); + } else { + new FindPackageTask().execute(number); + } + } + + } + } diff --git a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepSuccess.java b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepSuccess.java index 66eff45..47669ee 100644 --- a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepSuccess.java +++ b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepSuccess.java @@ -73,6 +73,9 @@ private void updateUIContent(Package p) { } else { mDescText.setText(getString(R.string.message_failure_forced)); } + if (!TextUtils.isEmpty(getAddActivity().getPreName())) { + mNameEdit.setText(getAddActivity().getPreName()); + } } @Override diff --git a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/settings/SettingsMain.java b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/settings/SettingsMain.java index 00c934f..0066d60 100644 --- a/mobile/src/main/java/info/papdt/express/helper/ui/fragment/settings/SettingsMain.java +++ b/mobile/src/main/java/info/papdt/express/helper/ui/fragment/settings/SettingsMain.java @@ -1,7 +1,9 @@ package info.papdt.express.helper.ui.fragment.settings; +import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; +import android.provider.Settings; import android.support.design.widget.Snackbar; import info.papdt.express.helper.R; @@ -14,7 +16,9 @@ public class SettingsMain extends AbsPrefFragment implements Preference.OnPrefer private Preference mPrefUI, mPrefNetwork, mPrefVersion, mPrefSina, mPrefGithub, mPrefAlipay, mPrefLicense, mPrefGooglePlus; - private Preference mPrefIconDesigner, mPrefContributors; + private Preference mPrefIconDesigner, mPrefContributors, mPrefAutoDetect; + + private static final int REQUEST_AUTO_DETECT_ENABLE = 1001; @Override public void onCreatePreferences(Bundle bundle, String s) { @@ -22,6 +26,7 @@ public void onCreatePreferences(Bundle bundle, String s) { mPrefUI = findPreference("settings_ui"); mPrefNetwork = findPreference("settings_network"); + mPrefAutoDetect = findPreference("settings_auto_detect"); mPrefVersion = findPreference("version"); mPrefGithub = findPreference("github"); mPrefSina = findPreference("sina"); @@ -43,6 +48,7 @@ public void onCreatePreferences(Bundle bundle, String s) { mPrefUI.setOnPreferenceClickListener(this); mPrefNetwork.setOnPreferenceClickListener(this); + mPrefAutoDetect.setOnPreferenceClickListener(this); mPrefVersion.setOnPreferenceClickListener(this); mPrefGithub.setOnPreferenceClickListener(this); mPrefSina.setOnPreferenceClickListener(this); @@ -95,6 +101,12 @@ public boolean onPreferenceClick(Preference pref) { } if (pref == mPrefGooglePlus) { openWebsite(getString(R.string.google_plus_url)); + return true; + } + if (pref == mPrefAutoDetect) { + Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); + startActivityForResult(intent, REQUEST_AUTO_DETECT_ENABLE); + return true; } return false; } diff --git a/mobile/src/main/res/drawable/ic_assistant_black_24dp.xml b/mobile/src/main/res/drawable/ic_assistant_black_24dp.xml new file mode 100644 index 0000000..2430c47 --- /dev/null +++ b/mobile/src/main/res/drawable/ic_assistant_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index af481d6..b392cb8 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -83,8 +83,8 @@ Github 源码 https://github.com/fython/PackageTracker 通过支付宝捐赠 - 316643843@qq.com - 316643843\@qq.com + fythonx@gmail.com + fythonx\@gmail.com 支付宝帐号已成功复制。 开源代码许可证 GPL v3 @@ -132,6 +132,8 @@ 勿扰模式 在 23:00 到次日 06:00 期间不发出通知。 + 自动检测新包裹 + 详情 标为未读 @@ -198,4 +200,12 @@ 所有包裹均已送达。 + + 水表助手 - 快递自动检测 + 当你打开淘宝或京东应用时,水表助手会检测当前页面是否有新包裹信息(通常只会出现在订单信息中)并帮助你添加追踪。 + 发现新的运单号 + 发现新的运单:%s + 来自%1$s的【%2$s】%3$s + 添加 + diff --git a/mobile/src/main/res/values-zh-rTW/strings.xml b/mobile/src/main/res/values-zh-rTW/strings.xml index 833923d..c328eba 100644 --- a/mobile/src/main/res/values-zh-rTW/strings.xml +++ b/mobile/src/main/res/values-zh-rTW/strings.xml @@ -83,8 +83,8 @@ Github 源代碼 https://github.com/fython/PackageTracker 通過支付寶捐贈 - 316643843@qq.com - 316643843\@qq.com + fythonx@gmail.com + fythonx\@gmail.com 支付寶帳號已成功拷貝到剪貼板。 開放源代碼許可證 GPL v3 @@ -132,6 +132,8 @@ 勿擾模式 在 23:00 至次日 06:00 期間不發出通知。 + 自動偵測新包裹 + 詳情 標為未讀 @@ -198,4 +200,12 @@ 所有包裹均已送達。 + + 水錶助手 - 運單自動偵測 + 當你打開淘寶或京東應用程式,水錶助手會檢測當前頁面是否有新包裹資料(通常只會出現在訂單頁面中)並幫助你添加追蹤。 + 發現新的運單號碼 + 發現新的運單:%s + 來自%1$s的【%2$s】%3$s + 新增 + diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 8e62e5f..4ad2bd1 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -83,8 +83,8 @@ Github Source https://github.com/fython/PackageTracker Donate through Alipay - 316643843@qq.com - 316643843\@qq.com + fythonx@gmail.com + fythonx\@gmail.com Alipay account has been copied successfully. Open Source License GPL v3 @@ -139,6 +139,8 @@ Do not disturb mode Don\'t send notifications from 23:00 to 06:00. + New package auto-detection + Details Set unread @@ -205,4 +207,12 @@ All packages have been delivered. + + Package Tracker Auto-detection + When you open Taobao or JD.com application, Package Tracker can detect if there is a new package in current page (Generally, it exists in order details page.) and help you to add it. + New package number detected + New package detected: %s + From %1$s: %2$s %3$s + Add + diff --git a/mobile/src/main/res/xml/service_detect_number.xml b/mobile/src/main/res/xml/service_detect_number.xml new file mode 100644 index 0000000..f881d89 --- /dev/null +++ b/mobile/src/main/res/xml/service_detect_number.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/xml/settings_main.xml b/mobile/src/main/res/xml/settings_main.xml index ec10d4c..f1e25e3 100644 --- a/mobile/src/main/res/xml/settings_main.xml +++ b/mobile/src/main/res/xml/settings_main.xml @@ -3,6 +3,7 @@ +