From abb4479d01d35744f9542a76c4d9d4b305bdefa3 Mon Sep 17 00:00:00 2001 From: kosh Date: Fri, 25 Sep 2015 19:48:21 +0800 Subject: [PATCH] ready for v7.5 --- app/build.gradle | 4 +- .../pro/global/helper/EventTrackerHelper.java | 28 +++++ .../floating/FloatingHorizontalLayout.java | 113 +++++------------- .../pro/widget/floating/FloatingLayout.java | 96 +++------------ 4 files changed, 73 insertions(+), 168 deletions(-) create mode 100644 app/src/main/java/com/styleme/floating/toolbox/pro/global/helper/EventTrackerHelper.java diff --git a/app/build.gradle b/app/build.gradle index 00c2d5f..bd2cac9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.styleme.floating.toolbox.pro" minSdkVersion 16 targetSdkVersion 23 - versionCode 74 - versionName '7.4' + versionCode 75 + versionName '7.5' } buildTypes { release { diff --git a/app/src/main/java/com/styleme/floating/toolbox/pro/global/helper/EventTrackerHelper.java b/app/src/main/java/com/styleme/floating/toolbox/pro/global/helper/EventTrackerHelper.java new file mode 100644 index 0000000..19bf8f6 --- /dev/null +++ b/app/src/main/java/com/styleme/floating/toolbox/pro/global/helper/EventTrackerHelper.java @@ -0,0 +1,28 @@ +package com.styleme.floating.toolbox.pro.global.helper; + +import com.google.android.gms.analytics.HitBuilders; +import com.google.android.gms.analytics.Tracker; +import com.styleme.floating.toolbox.pro.AppController; + +/** + * Created by Kosh on 9/25/2015. copyrights are reserved + */ +public class EventTrackerHelper { + + public static void sendEvent(Object className, String category, String action) { + HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); + eventBuilder.setCategory(category).setAction(action); + Tracker tracker = AppController.getController().tracker(); + tracker.setScreenName((String) className); + tracker.send(eventBuilder.build()); + } + + public static void sendEvent(Object className, String category, String action, String label) { + HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); + eventBuilder.setCategory(category).setAction(action).setLabel(label); + Tracker tracker = AppController.getController().tracker(); + tracker.setScreenName((String) className); + tracker.send(eventBuilder.build()); + } + +} diff --git a/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingHorizontalLayout.java b/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingHorizontalLayout.java index b7e4d15..b7d9b0b 100644 --- a/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingHorizontalLayout.java +++ b/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingHorizontalLayout.java @@ -22,12 +22,11 @@ import android.view.WindowManager.LayoutParams; import android.widget.ImageView; -import com.google.android.gms.analytics.HitBuilders; -import com.google.android.gms.analytics.Tracker; import com.styleme.floating.toolbox.pro.AppController; import com.styleme.floating.toolbox.pro.R; import com.styleme.floating.toolbox.pro.global.adapter.RecyclerFloatingAdapter; import com.styleme.floating.toolbox.pro.global.helper.AppHelper; +import com.styleme.floating.toolbox.pro.global.helper.EventTrackerHelper; import com.styleme.floating.toolbox.pro.global.helper.Notifier; import com.styleme.floating.toolbox.pro.global.loader.MyPopupAppsLoader; import com.styleme.floating.toolbox.pro.global.model.AppsModel; @@ -65,7 +64,6 @@ public class FloatingHorizontalLayout implements OnFloatingTouchListener, OnItem private Point szWindow = new Point(); private ImageView floatingImage; private MyPopupAppsLoader onMyAppsLoader; - private Tracker tracker = AppController.getController().tracker(); private View view; public FloatingHorizontalLayout(Context context) { @@ -76,12 +74,7 @@ public FloatingHorizontalLayout(Context context) { adapter = new RecyclerFloatingAdapter(this, new ArrayList()); gestureDetector = new GestureDetector(context, new GestureListener(this)); initWindows(); - tracker.setScreenName("FloatingHorizontalLayout"); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder.setCategory("FloatingHorizontalLayout") - .setAction("Init") - .setLabel("FloatingLayout"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "FloatingHorizontalLayout", "Init"); } private void initWindows() { @@ -200,46 +193,27 @@ public void onDestroy() { if (AppController.getController().eventBus().isRegistered(this)) { AppController.getController().eventBus().unregister(this); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onDestroy") - .setLabel("onDestroy"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onDestroy", "onDestroy"); } @Override public void onClick() { - animateShowing(); - try { - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); + if (view != null) { + animateShowing(); if (view.isShown()) { hideRecycler(); - eventBuilder.setCategory("FloatingHorizontalLayout") - .setAction("hide") - .setLabel("onClick"); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "OnClick", "Hide"); } else { showRecycler(); - eventBuilder.setCategory("FloatingHorizontalLayout") - .setAction("show") - .setLabel("onClick"); - + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onClick", "Show"); } - tracker.send(eventBuilder.build()); - } catch (Exception e) { - e.printStackTrace(); } } @Override public void onLongClick() { Notifier.createNotification(context, adapter.getItemCount()); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onLongClick") - .setLabel("onLongClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onLongClick", "onLongClick"); } @Override @@ -250,12 +224,7 @@ public void onDoubleClick() { startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startMain); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onDoubleClick") - .setLabel("onDoubleClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onDoubleClick", "onDoubleClick"); } @Override @@ -280,21 +249,23 @@ public boolean onTouch(View v, MotionEvent event) { animateHidden(); break; case MotionEvent.ACTION_MOVE: - if (paramsF.y >= 0 && paramsF.y < (szWindow.y - AppHelper.getFinalSize(context))) { + if (paramsF.y < 0) { + paramsF.y = 0; + } + if (paramsF.y >= 0 || paramsF.y <= (szWindow.y - AppHelper.getFinalSize(context))) { paramsF.x = initialX + (int) (event.getRawX() - initialTouchX); paramsF.y = initialY + (int) (event.getRawY() - initialTouchY); try { windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF); - rParams.x = paramsF.x; - rParams.y = paramsF.y + AppHelper.getFinalSize(context); - windowManager.updateViewLayout(FloatingHorizontalLayout.this.view, rParams); + if (view.isShown()) { + showRecycler(); + } } catch (Exception e) { e.printStackTrace(); } animateShowing(); - } - if (paramsF.y < 0) { - paramsF.y = 0; + } else if (paramsF.y > (szWindow.y - AppHelper.getFinalSize(context))) { + paramsF.y = (szWindow.y - AppHelper.getFinalSize(context)); } break; } @@ -361,20 +332,12 @@ public void onAppClick(AppsModel appsModel) { intent.addCategory(Intent.CATEGORY_LAUNCHER); context.startActivity(intent); appsModel.updateEntry(appsModel.getPackageName()); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("Open App") - .setLabel(appsModel.getAppName() == null ? appsModel.getPackageName() : appsModel.getAppName()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onAppClick", "onAppClick", appsModel.getAppName() == null ? appsModel + .getPackageName() : appsModel.getAppName()); + } catch (Exception e) { e.printStackTrace(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("Open App Exception") - .setLabel(e.getMessage() == null ? "Open App Crash" : e.getMessage()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onAppClick", "Crash!!!", e.getMessage()); } hideRecycler(); } @@ -382,12 +345,7 @@ public void onAppClick(AppsModel appsModel) { @Override public void onReset() { adapter.clear(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onReset") - .setLabel("Adapter Reset"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onReset", "onReset"); } private void animateHidden() { @@ -414,12 +372,7 @@ public void onLoadComplete(Loader> loader, List data) if (adapter != null) { adapter.insert(data); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onLoadCompleteListener") - .setLabel("new Data: " + data.size()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingHorizontalLayout", "onLoadCompleteListener", "onLoadCompleteListener", "new Data: " + data.size()); } }; @@ -428,22 +381,12 @@ public void onEvent(EventsModel eventsModel) { setupParams(); setupFloatingImage(true); animateHidden(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onEvent") - .setLabel("EventType.SETTINGS_CHANGE"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("onEvent", "onLoadCompleteListener", "EventType.SETTINGS_CHANGE"); } else if (eventsModel != null && eventsModel.getEventType() == EventType.PREVIEW) { mParams.height = AppHelper.toPx(context, eventsModel.getPreviewSize()); mParams.width = AppHelper.toPx(context, eventsModel.getPreviewSize()); try { - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory("FloatingHorizontalLayout") - .setAction("onEvent") - .setLabel("EventType.PREVIEW"); + EventTrackerHelper.sendEvent("onEvent", "onLoadCompleteListener", "EventType.PREVIEW"); if (windowManager != null) { windowManager.updateViewLayout(FloatingHorizontalLayout.this.view, mParams); new Handler().postDelayed(new Runnable() { @@ -468,7 +411,5 @@ public void onItemClickListener(View view, int position) { } @Override - public void onItemLongClickListener(RecyclerView.ViewHolder viewHolder, View view, int position) { - - } + public void onItemLongClickListener(RecyclerView.ViewHolder viewHolder, View view, int position) {} } diff --git a/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingLayout.java b/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingLayout.java index 990aa72..3dbf8ab 100644 --- a/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingLayout.java +++ b/app/src/main/java/com/styleme/floating/toolbox/pro/widget/floating/FloatingLayout.java @@ -24,12 +24,11 @@ import android.widget.ListAdapter; import android.widget.PopupWindow; -import com.google.android.gms.analytics.HitBuilders; -import com.google.android.gms.analytics.Tracker; import com.styleme.floating.toolbox.pro.AppController; import com.styleme.floating.toolbox.pro.R; import com.styleme.floating.toolbox.pro.global.adapter.FloatingAdapter; import com.styleme.floating.toolbox.pro.global.helper.AppHelper; +import com.styleme.floating.toolbox.pro.global.helper.EventTrackerHelper; import com.styleme.floating.toolbox.pro.global.helper.Notifier; import com.styleme.floating.toolbox.pro.global.loader.MyPopupAppsLoader; import com.styleme.floating.toolbox.pro.global.model.AppsModel; @@ -67,7 +66,6 @@ public class FloatingLayout implements OnFloatingTouchListener { private Point szWindow = new Point(); private ImageView floatingImage; private MyPopupAppsLoader onMyAppsLoader; - private Tracker tracker = AppController.getController().tracker(); private boolean isShowed = true; public FloatingLayout(Context context) { @@ -78,13 +76,7 @@ public FloatingLayout(Context context) { adapter = new FloatingAdapter(new ArrayList(), this); gestureDetector = new GestureDetector(context, new GestureListener(this)); initWindows(); - tracker.setScreenName("FloatingLayout"); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("Init") - .setLabel("FloatingLayout"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "Init()", "Init()"); } private void initWindows() { @@ -181,24 +173,14 @@ public void onDestroy() { if (AppController.getController().eventBus().isRegistered(this)) { AppController.getController().eventBus().unregister(this); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onDestroy") - .setLabel("onDestroy"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onDestroy()", "onDestroy()"); + } @Override public void onLongClick() { Notifier.createNotification(context, adapter.getCount()); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onLongClick") - .setLabel("onLongClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onLongClick()", "onLongClick()"); } @Override @@ -209,13 +191,7 @@ public void onDoubleClick() { startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startMain); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onDoubleClick") - .setLabel("onDoubleClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onDoubleClick()", "onDoubleClick()"); } @Override @@ -224,22 +200,10 @@ public void onClick() { try { if (popupWindow.isShowing()) { popupWindow.dismiss(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("dismiss") - .setLabel("onClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onClick()", "hide()"); } else { popupWindow.show(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("show") - .setLabel("onClick"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onClick()", "show()"); } configure(); isShowed = false; @@ -364,20 +328,12 @@ public void onAppClick(AppsModel appsModel) { intent.addCategory(Intent.CATEGORY_LAUNCHER); context.startActivity(intent); appsModel.updateEntry(appsModel.getPackageName()); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("Open App") - .setLabel(appsModel.getAppName() == null ? appsModel.getPackageName() : appsModel.getAppName()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onAppClick()", "onAppClick()", appsModel.getAppName() == null ? appsModel + .getPackageName() : appsModel.getAppName()); + } catch (Exception e) { e.printStackTrace(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("Open App Exception") - .setLabel(e.getMessage() == null ? "Open App Crash" : e.getMessage()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onAppClick()", "onAppClick()", "Crash " + e.getMessage()); } if (popupWindow.isShowing()) { popupWindow.dismiss(); @@ -389,12 +345,7 @@ public void onAppClick(AppsModel appsModel) { @Override public void onReset() { adapter.clear(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onReset") - .setLabel("Adapter Reset"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onReset()", "onReset()"); } private void animateHidden() { @@ -451,12 +402,7 @@ public void onLoadComplete(Loader> loader, List data) adapter.insert(data); popupWindow.setContentWidth(measureContentWidth(adapter)); } - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onLoadCompleteListener") - .setLabel("new Data: " + data.size()); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onLoadCompleteListener()", "Data Size", "" + data.size()); } }; @@ -465,22 +411,12 @@ public void onEvent(EventsModel eventsModel) { setupParams(); setupFloatingImage(true); animateHidden(); - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onEvent") - .setLabel("EventType.SETTINGS_CHANGE"); - tracker.send(eventBuilder.build()); + EventTrackerHelper.sendEvent("FloatingLayout", "onEvent()", "EventType.SETTINGS_CHANGE"); } else if (eventsModel != null && eventsModel.getEventType() == EventType.PREVIEW) { mParams.height = AppHelper.toPx(context, eventsModel.getPreviewSize()); mParams.width = AppHelper.toPx(context, eventsModel.getPreviewSize()); try { - HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); - - eventBuilder - .setCategory(this.getClass().getSimpleName()) - .setAction("onEvent") - .setLabel("EventType.PREVIEW"); + EventTrackerHelper.sendEvent("FloatingLayout", "onEvent()", "EventType.PREVIEW"); if (windowManager != null) { windowManager.updateViewLayout(floatingImage, mParams); new Handler().postDelayed(new Runnable() {