Skip to content

Commit

Permalink
feat: inject模块支持重复注解,减少注解代码复杂度
Browse files Browse the repository at this point in the history
  • Loading branch information
LitterSun authored and 小肥阳 committed Aug 20, 2020
1 parent bcd083d commit 3d839aa
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 55 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ buildscript {
compileVersion : 29,
minSdkVersion : 17,
targetSdkVersion : 29,
sourceCompatibility: JavaVersion.VERSION_1_7,
targetCompatibility: JavaVersion.VERSION_1_7,
sourceCompatibility: JavaVersion.VERSION_1_8,
targetCompatibility: JavaVersion.VERSION_1_8,
]

releaseConfiguration = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Switch;

import androidx.annotation.NonNull;

import com.gio.test.three.autotrack.R;

public class ClickTestActivity extends Activity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
Expand Down Expand Up @@ -69,6 +70,12 @@ protected void onCreate(Bundle savedInstanceState) {
setListAdapter(new MyAdapter(this, mGroupList, mItemSet));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bottom_nav_menu, menu);
return true;
}

@SuppressLint("LongLogTag")
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Expand Down
4 changes: 2 additions & 2 deletions demos/demo-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
}

compileOptions {
sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets.main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class HookClassesConfig {
putAroundHookMethod("android/webkit/WebView", "loadDataWithBaseURL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "com/growingio/android/sdk/autotrack/hybrid/WebViewInjector", "webkitWebViewLoadDataWithBaseURL", "(Landroid/webkit/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
putAroundHookMethod("com/tencent/smtt/sdk/WebView", "loadDataWithBaseURL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "com/growingio/android/sdk/autotrack/hybrid/WebViewInjector", "x5WebViewLoadDataWithBaseURL", "(Lcom/tencent/smtt/sdk/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
putAroundHookMethod("com/uc/webview/export/WebView", "loadDataWithBaseURL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "com/growingio/android/sdk/autotrack/hybrid/WebViewInjector", "ucWebViewLoadDataWithBaseURL", "(Lcom/uc/webview/export/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
putSuperHookMethod("android/view/View$OnFocusChangeListener", "onFocusChange", "(Landroid/view/View;Z)V", "com/growingio/android/sdk/autotrack/change/ChangeInjector", "beforeViewOnClick", "(Landroid/view/View$OnFocusChangeListener;Landroid/view/View;Z)V", false);
putSuperHookMethod("android/view/View$OnFocusChangeListener", "onFocusChange", "(Landroid/view/View;Z)V", "com/growingio/android/sdk/autotrack/change/ChangeInjector", "beforeViewOnClick", "(Landroid/view/View$OnClickListener;Landroid/view/View;Z)V", false);
putSuperHookMethod("android/view/View$OnClickListener", "onClick", "(Landroid/view/View;)V", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "viewOnClick", "(Landroid/view/View$OnClickListener;Landroid/view/View;)V", false);
putSuperHookMethod("android/content/DialogInterface$OnClickListener", "onClick", "(Landroid/content/DialogInterface;I)V", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "dialogOnClick", "(Landroid/content/DialogInterface$OnClickListener;Landroid/content/DialogInterface;I)V", false);
putSuperHookMethod("android/widget/AdapterView$OnItemClickListener", "onItemClick", "(Landroid/widget/AdapterView;Landroid/view/View;IJ)V", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "adapterViewOnItemClick", "(Landroid/widget/AdapterView$OnItemClickListener;Landroid/widget/AdapterView;Landroid/view/View;IJ)V", false);
Expand All @@ -56,7 +56,6 @@ public class HookClassesConfig {
putSuperHookMethod("android/widget/Toolbar$OnMenuItemClickListener", "onMenuItemClick", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "toolbarOnMenuItemClick", "(Landroid/widget/Toolbar$OnMenuItemClickListener;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/widget/ActionMenuView$OnMenuItemClickListener", "onMenuItemClick", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "actionMenuViewOnMenuItemClick", "(Landroid/widget/ActionMenuView$OnMenuItemClickListener;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/widget/PopupMenu$OnMenuItemClickListener", "onMenuItemClick", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "popupMenuOnMenuItemClick", "(Landroid/widget/PopupMenu$OnMenuItemClickListener;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/Activity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/Fragment", "onResume", "()V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "systemFragmentOnResume", "(Landroid/app/Fragment;)V", true);
putSuperHookMethod("android/app/Fragment", "setUserVisibleHint", "(Z)V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "systemFragmentSetUserVisibleHint", "(Landroid/app/Fragment;Z)V", true);
putSuperHookMethod("android/app/Fragment", "onHiddenChanged", "(Z)V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "systemFragmentOnHiddenChanged", "(Landroid/app/Fragment;Z)V", true);
Expand All @@ -81,6 +80,16 @@ public class HookClassesConfig {
putSuperHookMethod("androidx/fragment/app/Fragment", "setUserVisibleHint", "(Z)V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "androidxFragmentSetUserVisibleHint", "(Landroidx/fragment/app/Fragment;Z)V", true);
putSuperHookMethod("androidx/fragment/app/Fragment", "onHiddenChanged", "(Z)V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "androidxFragmentOnHiddenChanged", "(Landroidx/fragment/app/Fragment;Z)V", true);
putSuperHookMethod("androidx/fragment/app/Fragment", "onDestroyView", "()V", "com/growingio/android/sdk/autotrack/page/FragmentInjector", "androidxFragmentOnDestroyView", "(Landroidx/fragment/app/Fragment;)V", true);
putSuperHookMethod("android/app/Activity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/accounts/AccountAuthenticatorActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/ActivityGroup", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/AliasActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/ExpandableListActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/LauncherActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/ListActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/NativeActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/app/TabActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
putSuperHookMethod("android/preference/PreferenceActivity", "onOptionsItemSelected", "(Landroid/view/MenuItem;)Z", "com/growingio/android/sdk/autotrack/click/ViewClickInjector", "menuItemOnOptionsItemSelected", "(Landroid/app/Activity;Landroid/view/MenuItem;)V", false);
}

private HookClassesConfig() {
Expand Down
4 changes: 4 additions & 0 deletions growingio-autotracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility buildConfiguration.sourceCompatibility
targetCompatibility buildConfiguration.targetCompatibility
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

package com.growingio.android.sdk.autotrack.click;

import android.accounts.AccountAuthenticatorActivity;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.AlertDialog;
import android.app.AliasActivity;
import android.app.ExpandableListActivity;
import android.app.LauncherActivity;
import android.app.ListActivity;
import android.app.NativeActivity;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.preference.PreferenceActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.ActionMenuView;
Expand Down Expand Up @@ -130,7 +137,16 @@ public static void popupMenuOnMenuItemClick(PopupMenu.OnMenuItemClickListener li
ViewClickProvider.menuItemOnClick(item);
}

@BeforeSuper(clazz = Activity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = Activity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = AccountAuthenticatorActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = ActivityGroup.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = AliasActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = ExpandableListActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = LauncherActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = ListActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = NativeActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = TabActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
@BeforeSuper(clazz = PreferenceActivity.class, method = "onOptionsItemSelected", parameterTypes = {MenuItem.class}, returnType = boolean.class)
public static void menuItemOnOptionsItemSelected(Activity activity, MenuItem item) {
ViewClickProvider.menuItemOnClick(item);
}
Expand Down
4 changes: 4 additions & 0 deletions growingio-tracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility buildConfiguration.sourceCompatibility
targetCompatibility buildConfiguration.targetCompatibility
}
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions inject-annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'java-library'

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(Afters.class)
public @interface After {
Class<?> clazz();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(AfterSupers.class)
public @interface AfterSuper {
Class<?> clazz();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterSupers {
AfterSuper[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Afters {
After[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(Befores.class)
public @interface Before {
Class<?> clazz();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(BeforeSupers.class)
public @interface BeforeSuper {
Class<?> clazz();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface BeforeSupers {
BeforeSuper[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.growingio.sdk.inject.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Befores {
Before[] value();
}
4 changes: 2 additions & 2 deletions inject-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import org.gradle.internal.jvm.Jvm
apply plugin: 'java-library'

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
Expand Down
Loading

0 comments on commit 3d839aa

Please sign in to comment.