OSDN Git Service

Refactor UsageStatistic so it can be disabled more easily.
authorSascha Haeberling <haeberling@google.com>
Mon, 31 Mar 2014 20:22:17 +0000 (13:22 -0700)
committerSascha Haeberling <haeberling@google.com>
Wed, 2 Apr 2014 00:30:38 +0000 (17:30 -0700)
Change-Id: I2ca6e7d5642b1400d4b13f2c45cb48793b2fc178

src/com/android/camera/CameraActivity.java
src/com/android/camera/FocusOverlayManager.java
src/com/android/camera/ListPreference.java
src/com/android/camera/PhotoModule.java
src/com/android/camera/VideoModule.java
src/com/android/camera/app/CameraApp.java
src/com/android/camera/app/CameraAppUI.java
src/com/android/camera/ui/MainActivityLayout.java
src_pd/com/android/camera/util/UsageStatistics.java

index da26b7b..728734b 100644 (file)
@@ -308,7 +308,7 @@ public class CameraActivity extends Activity
                 @Override
                 public void onDelete() {
                     final int currentDataId = getCurrentDataId();
-                    UsageStatistics.photoInteraction(
+                    UsageStatistics.instance().photoInteraction(
                             UsageStatistics.hashFileName(fileNameFromDataID(currentDataId)),
                             eventprotos.CameraEvent.InteractionType.DELETE,
                             InteractionCause.BUTTON);
@@ -451,15 +451,15 @@ public class CameraActivity extends Activity
 
     @Override
     public void onCameraDisabled(int cameraId) {
-        UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.SECURITY);
-
+        UsageStatistics.instance().cameraFailure(
+                eventprotos.CameraFailure.FailureReason.SECURITY);
         CameraUtil.showErrorAndFinish(this, R.string.camera_disabled);
     }
 
     @Override
     public void onDeviceOpenFailure(int cameraId) {
-        UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.OPEN_FAILURE);
-
+        UsageStatistics.instance().cameraFailure(
+                eventprotos.CameraFailure.FailureReason.OPEN_FAILURE);
         CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera);
     }
 
@@ -470,8 +470,8 @@ public class CameraActivity extends Activity
 
     @Override
     public void onReconnectionFailure(CameraManager mgr) {
-        UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.RECONNECT_FAILURE);
-
+        UsageStatistics.instance().cameraFailure(
+                eventprotos.CameraFailure.FailureReason.RECONNECT_FAILURE);
         CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera);
     }
 
@@ -514,7 +514,8 @@ public class CameraActivity extends Activity
 
                 @Override
                 public void onSwipeOut() {
-                    UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
+                    UsageStatistics.instance().changeScreen(
+                            eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
                             eventprotos.CameraEvent.InteractionCause.SWIPE_RIGHT);
                 }
 
@@ -549,7 +550,7 @@ public class CameraActivity extends Activity
 
                 @Override
                 public void onFocusedDataPromoted(int dataID) {
-                    UsageStatistics.photoInteraction(
+                    UsageStatistics.instance().photoInteraction(
                             UsageStatistics.hashFileName(fileNameFromDataID(dataID)),
                             eventprotos.CameraEvent.InteractionType.DELETE,
                             InteractionCause.SWIPE_UP);
@@ -559,7 +560,7 @@ public class CameraActivity extends Activity
 
                 @Override
                 public void onFocusedDataDemoted(int dataID) {
-                    UsageStatistics.photoInteraction(
+                    UsageStatistics.instance().photoInteraction(
                             UsageStatistics.hashFileName(fileNameFromDataID(dataID)),
                             eventprotos.CameraEvent.InteractionType.DELETE,
                             InteractionCause.SWIPE_DOWN);
@@ -662,7 +663,7 @@ public class CameraActivity extends Activity
             };
 
     public void gotoGallery() {
-        UsageStatistics.changeScreen(NavigationChange.Mode.FILMSTRIP,
+        UsageStatistics.instance().changeScreen(NavigationChange.Mode.FILMSTRIP,
                 InteractionCause.BUTTON);
 
         mFilmstripController.goToNextItem();
@@ -753,7 +754,7 @@ public class CameraActivity extends Activity
         if (currentDataId < 0) {
             return false;
         }
-        UsageStatistics.photoInteraction(
+        UsageStatistics.instance().photoInteraction(
                 UsageStatistics.hashFileName(fileNameFromDataID(currentDataId)),
                 eventprotos.CameraEvent.InteractionType.SHARE,
                 InteractionCause.BUTTON);
@@ -1229,7 +1230,7 @@ public class CameraActivity extends Activity
             // Foreground event caused by lock screen startup.
             // It is necessary to log this in onCreate, to avoid the
             // onResume->onPause->onResume sequence.
-            UsageStatistics.foregrounded(
+            UsageStatistics.instance().foregrounded(
                     eventprotos.ForegroundEvent.ForegroundSource.LOCK_SCREEN);
 
             // Change the window flags so that secure camera can show when
@@ -1301,7 +1302,7 @@ public class CameraActivity extends Activity
             v.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
-                    UsageStatistics.changeScreen(NavigationChange.Mode.GALLERY,
+                    UsageStatistics.instance().changeScreen(NavigationChange.Mode.GALLERY,
                             InteractionCause.BUTTON);
                     startGallery();
                     finish();
@@ -1511,11 +1512,11 @@ public class CameraActivity extends Activity
 
         if (isCaptureIntent()) {
             // Foreground event caused by photo or video capure intent.
-            UsageStatistics.foregrounded(
+            UsageStatistics.instance().foregrounded(
                     eventprotos.ForegroundEvent.ForegroundSource.INTENT_PICKER);
         } else if (!mSecureCamera) {
             // Foreground event that is not caused by an intent.
-            UsageStatistics.foregrounded(
+            UsageStatistics.instance().foregrounded(
                     eventprotos.ForegroundEvent.ForegroundSource.ICON_LAUNCHER);
         }
 
@@ -2206,7 +2207,8 @@ public class CameraActivity extends Activity
             return false;
         }
         try {
-            UsageStatistics.changeScreen(NavigationChange.Mode.GALLERY, InteractionCause.BUTTON);
+            UsageStatistics.instance().changeScreen(NavigationChange.Mode.GALLERY,
+                    InteractionCause.BUTTON);
             Intent startGalleryIntent = new Intent(mGalleryIntent);
             int currentDataId = mFilmstripController.getCurrentId();
             LocalData currentLocalData = mDataAdapter.getLocalData(currentDataId);
@@ -2424,7 +2426,7 @@ public class CameraActivity extends Activity
         Dialog detailDialog = DetailsDialog.create(CameraActivity.this, details);
         detailDialog.show();
 
-        UsageStatistics.photoInteraction(
+        UsageStatistics.instance().photoInteraction(
                 UsageStatistics.hashFileName(fileNameFromDataID(dataId)),
                 eventprotos.CameraEvent.InteractionType.DETAILS,
                 InteractionCause.BUTTON);
index 0f41da3..98d9a93 100644 (file)
@@ -336,7 +336,7 @@ public class FocusOverlayManager implements PreviewStatusListener.PreviewAreaCha
     public void onSingleTapUp(int x, int y) {
         if (!mInitialized || mState == STATE_FOCUSING_SNAP_ON_FINISH) return;
 
-        UsageStatistics.tapToFocus();
+        UsageStatistics.instance().tapToFocus();
 
         // Let users be able to cancel previous touch focus.
         if ((mFocusArea != null) && (mState == STATE_FOCUSING ||
index c192d34..2d615b3 100644 (file)
@@ -182,7 +182,7 @@ public class ListPreference extends CameraPreference {
         SharedPreferences.Editor editor = preferences.edit();
         editor.putString(mKey, value);
         editor.apply();
-        UsageStatistics.changePreference(mKey, value, oldValue);
+        UsageStatistics.instance().changePreference(mKey, value, oldValue);
         return true;
     }
 
index 7f62190..9b0f053 100644 (file)
@@ -944,7 +944,7 @@ public class PhotoModule
 
         mFaceDetectionStarted = false;
         setCameraState(SNAPSHOT_IN_PROGRESS);
-        UsageStatistics.captureEvent(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
+        UsageStatistics.instance().captureEvent(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
                 UsageStatistics.hashFileName(mNamedImages.mQueue.lastElement().title + ".jpg"),
                 mParameters, null);
         return true;
@@ -1166,7 +1166,7 @@ public class PhotoModule
             initializeSecondTime();
         }
 
-        UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
+        UsageStatistics.instance().changeScreen(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE,
                 eventprotos.CameraEvent.InteractionCause.BUTTON);
 
         Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
index bf3f4be..5003c96 100644 (file)
@@ -67,7 +67,6 @@ import com.android.camera.hardware.HardwareSpecImpl;
 import com.android.camera.module.ModuleController;
 import com.android.camera.settings.SettingsManager;
 import com.android.camera.settings.SettingsUtil;
-import com.android.camera.util.AccessibilityUtils;
 import com.android.camera.util.ApiHelper;
 import com.android.camera.util.CameraUtil;
 import com.android.camera.util.UsageStatistics;
@@ -407,8 +406,8 @@ public class VideoModule extends CameraModule
                     null, null, null, new JpegPictureCallback(loc));
             showVideoSnapshotUI(true);
             mSnapshotInProgress = true;
-            UsageStatistics.captureEvent(eventprotos.NavigationChange.Mode.VIDEO_STILL,
-                    null, null, null);
+            UsageStatistics.instance().captureEvent(
+                    eventprotos.NavigationChange.Mode.VIDEO_STILL, null, null, null);
         }
     }
 
@@ -1338,8 +1337,9 @@ public class VideoModule extends CameraModule
                 String statisticFilename = (mCurrentVideoFilename == null
                         ? "INTENT"
                         : mCurrentVideoFilename);
-                UsageStatistics.captureEvent(eventprotos.NavigationChange.Mode.VIDEO_CAPTURE,
-                        statisticFilename, mParameters, duration);
+                UsageStatistics.instance().captureEvent(
+                        eventprotos.NavigationChange.Mode.VIDEO_CAPTURE, statisticFilename,
+                        mParameters, duration);
             } catch (RuntimeException e) {
                 Log.e(TAG, "stop fail",  e);
                 if (mVideoFilename != null) {
@@ -1611,7 +1611,7 @@ public class VideoModule extends CameraModule
             mHandler.sendEmptyMessageDelayed(MSG_CHECK_DISPLAY_ROTATION, 100);
         }
 
-        UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.VIDEO_CAPTURE,
+        UsageStatistics.instance().changeScreen(eventprotos.NavigationChange.Mode.VIDEO_CAPTURE,
                 eventprotos.CameraEvent.InteractionCause.BUTTON);
         getServices().getMemoryManager().addListener(this);
     }
index 1cfa5ff..e613a0b 100644 (file)
@@ -45,7 +45,7 @@ public class CameraApp extends Application implements CameraServices {
     public void onCreate() {
         super.onCreate();
 
-        UsageStatistics.initialize(this);
+        UsageStatistics.instance().initialize(this);
         CameraUtil.initialize(this);
 
         Context context = getApplicationContext();
index 629e64b..7842fd4 100644 (file)
@@ -853,8 +853,9 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
             }
         } else if (swipeState == SWIPE_LEFT) {
             // Pass the touch sequence to filmstrip layout.
-            UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.FILMSTRIP,
-                eventprotos.CameraEvent.InteractionCause.SWIPE_LEFT);
+            UsageStatistics.instance().changeScreen(
+                    eventprotos.NavigationChange.Mode.FILMSTRIP,
+                    eventprotos.CameraEvent.InteractionCause.SWIPE_LEFT);
             mAppRootView.redirectTouchEventsTo(mFilmstripLayout);
         } else if (swipeState == SWIPE_RIGHT) {
             // Pass the touch to mode switcher
@@ -1098,7 +1099,7 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
         mFocusOverlay = mCameraRootView.findViewById(R.id.focus_overlay);
         mTutorialsPlaceholder = (FrameLayout) mCameraRootView
                 .findViewById(R.id.tutorials_placeholder);
-        mIndicatorBottomBarWrapper = (View) mAppRootView
+        mIndicatorBottomBarWrapper = mAppRootView
                 .findViewById(R.id.indicator_bottombar_wrapper);
 
         mTextureViewHelper.addPreviewAreaSizeChangedListener(
index b12eb01..4b759f9 100644 (file)
@@ -30,7 +30,6 @@ import com.android.camera.debug.Log;
 import com.android.camera.util.UsageStatistics;
 import com.android.camera.widget.FilmstripLayout;
 import com.android.camera2.R;
-
 import com.google.common.logging.eventprotos;
 
 public class MainActivityLayout extends FrameLayout {
@@ -113,7 +112,8 @@ public class MainActivityLayout extends FrameLayout {
                 // Intercept left swipe
                 else if (deltaX < -Math.abs(deltaY) * 2) {
                     mTouchReceiver = mFilmstripLayout;
-                    UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.FILMSTRIP,
+                    UsageStatistics.instance().changeScreen(
+                            eventprotos.NavigationChange.Mode.FILMSTRIP,
                             eventprotos.CameraEvent.InteractionCause.SWIPE_LEFT);
                     onTouchEvent(mDown);
                     return true;
index 155f0c0..10037d9 100644 (file)
  * limitations under the License.
  */
 
+
 package com.android.camera.util;
+
 import android.content.Context;
-import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
 
 public class UsageStatistics {
-    public static void initialize(Context context) {}
-    public static void photoInteraction(String fileNameHash, int interactionType, int cause) {}
-    public static void foregrounded(int source) {}
-    public static void captureEvent(int mode, String fileNameHash,
-                                    Camera.Parameters parameters, Float duration) {}
-    public static void changePreference(String preference, String newValue, String oldValue) {}
-    public static void cameraFailure(int cause) {}
-    public static void tapToFocus() {}
-    public static void changeScreen(int newScreen, Integer interactionCause) {}
+    private static UsageStatistics sInstance;
+
+    public static UsageStatistics instance() {
+        if (sInstance == null) {
+            sInstance = new UsageStatistics();
+        }
+        return sInstance;
+    }
+
+    public void initialize(Context context) {
+    }
+
+    public void photoInteraction(String fileNameHash, int interactionType, int cause) {
+    }
+
+    public void foregrounded(int source) {
+    }
+
+    public void captureEvent(int mode, String fileNameHash, Parameters parameters, Float duration) {
+    }
+
+    public void changePreference(String preference, String newValue, String oldValue) {
+    }
+
+    public void cameraFailure(int cause) {
+    }
+
+    public void tapToFocus() {
+    }
+
+    public void changeScreen(int newScreen, Integer interactionCause) {
+    }
 
     public static String hashFileName(String fileName) {
-        return "";
+        return fileName;
     }
 }