From 6af5525f3ef7af6089aa5b4db90777eb4eecdbdd Mon Sep 17 00:00:00 2001 From: Zeeshan Asghar Date: Tue, 15 Mar 2016 14:59:37 +0500 Subject: [PATCH] squid:S1192 String literals should not be duplicated --- .../tourguidedemo/ToolTilMeasureTest.java | 9 ++-- .../test/SequenceTestActivity.java | 7 +-- .../tourguide/FrameLayoutWithHole.java | 23 ++++---- .../java/tourguide/tourguide/TourGuide.java | 54 ++++++++++--------- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/app/src/androidTest/java/tourguide/tourguidedemo/ToolTilMeasureTest.java b/app/src/androidTest/java/tourguide/tourguidedemo/ToolTilMeasureTest.java index ea63178..44ace41 100644 --- a/app/src/androidTest/java/tourguide/tourguidedemo/ToolTilMeasureTest.java +++ b/app/src/androidTest/java/tourguide/tourguidedemo/ToolTilMeasureTest.java @@ -13,6 +13,7 @@ * Created by tanjunrong on 8/6/15. */ public class ToolTilMeasureTest extends ActivityInstrumentationTestCase2 { + public static final String TOURGUIDE_TEST = "tourguide_test"; ToolTipMeasureTestActivity mActivity; View mToolTip; public ToolTilMeasureTest() { @@ -32,10 +33,10 @@ protected void setUp() throws Exception { public void testNoCrash(){ // mToolTip.performClick(); - Log.d("tourguide_test","height:" + mToolTip.getHeight()); - Log.d("tourguide_test","width:" + mToolTip.getWidth()); - Log.d("tourguide_test","getX:" + mToolTip.getX()); - Log.d("tourguide_test", "screen width:" + getScreenWidth(mActivity)); + Log.d(TOURGUIDE_TEST,"height:" + mToolTip.getHeight()); + Log.d(TOURGUIDE_TEST,"width:" + mToolTip.getWidth()); + Log.d(TOURGUIDE_TEST,"getX:" + mToolTip.getX()); + Log.d(TOURGUIDE_TEST, "screen width:" + getScreenWidth(mActivity)); // mToolTip.getViewTreeObserver().addOnGlobalLayoutListener( // new ViewTreeObserver.OnGlobalLayoutListener() { // diff --git a/app/src/main/java/tourguide/instrumentation/test/SequenceTestActivity.java b/app/src/main/java/tourguide/instrumentation/test/SequenceTestActivity.java index ee2d6e5..4e55550 100644 --- a/app/src/main/java/tourguide/instrumentation/test/SequenceTestActivity.java +++ b/app/src/main/java/tourguide/instrumentation/test/SequenceTestActivity.java @@ -34,6 +34,7 @@ * . */ public class SequenceTestActivity extends ActionBarActivity { + public static final String BELLO_THIS_IS_THE_DEFAULT_OVERLAY = "Bello! This is the default Overlay"; public TourGuide mTutorialHandler; public Activity mActivity; public Sequence mSequence; @@ -116,7 +117,7 @@ private void runOverlayContinueMethod(){ .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(SequenceTestActivity.this, "Bello! This is the default Overlay", Toast.LENGTH_SHORT).show(); + Toast.makeText(SequenceTestActivity.this, BELLO_THIS_IS_THE_DEFAULT_OVERLAY, Toast.LENGTH_SHORT).show(); mTutorialHandler.next(); } })) @@ -136,7 +137,7 @@ public void onClick(View v) { .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(SequenceTestActivity.this, "Bello! This is the default Overlay", Toast.LENGTH_SHORT).show(); + Toast.makeText(SequenceTestActivity.this, BELLO_THIS_IS_THE_DEFAULT_OVERLAY, Toast.LENGTH_SHORT).show(); mTutorialHandler.next(); } })) @@ -181,7 +182,7 @@ private void runOverlayListenerContinueMethod(){ .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(SequenceTestActivity.this, "Bello! This is the default Overlay", Toast.LENGTH_SHORT).show(); + Toast.makeText(SequenceTestActivity.this, BELLO_THIS_IS_THE_DEFAULT_OVERLAY, Toast.LENGTH_SHORT).show(); mTutorialHandler.next(); } })) diff --git a/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java b/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java index 6141d30..03af4ed 100644 --- a/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java +++ b/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java @@ -24,6 +24,7 @@ * TODO: document your custom view class. */ public class FrameLayoutWithHole extends FrameLayout { + public static final String TOURGUIDE = "tourguide"; private TextPaint mTextPaint; private Activity mActivity; private TourGuide.MotionType mMotionType; @@ -52,11 +53,11 @@ public void addAnimatorSet(AnimatorSet animatorSet){ mAnimatorSetArrayList.add(animatorSet); } private void enforceMotionType(){ - Log.d("tourguide", "enforceMotionType 1"); - if (mViewHole!=null) {Log.d("tourguide","enforceMotionType 2"); + Log.d(TOURGUIDE, "enforceMotionType 1"); + if (mViewHole!=null) {Log.d(TOURGUIDE,"enforceMotionType 2"); if (mMotionType!=null && mMotionType == TourGuide.MotionType.ClickOnly) { - Log.d("tourguide","enforceMotionType 3"); - Log.d("tourguide","only Clicking"); + Log.d(TOURGUIDE,"enforceMotionType 3"); + Log.d(TOURGUIDE,"only Clicking"); mViewHole.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { @@ -65,8 +66,8 @@ public boolean onTouch(View view, MotionEvent motionEvent) { } }); } else if (mMotionType!=null && mMotionType == TourGuide.MotionType.SwipeOnly) { - Log.d("tourguide","enforceMotionType 4"); - Log.d("tourguide","only Swiping"); + Log.d(TOURGUIDE,"enforceMotionType 4"); + Log.d(TOURGUIDE,"only Swiping"); mViewHole.setClickable(false); } } @@ -132,8 +133,8 @@ private void init(AttributeSet attrs, int defStyle) { mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mEraser.setFlags(Paint.ANTI_ALIAS_FLAG); - Log.d("tourguide","getHeight: "+ size.y); - Log.d("tourguide","getWidth: " + size.x); + Log.d(TOURGUIDE,"getHeight: "+ size.y); + Log.d(TOURGUIDE,"getWidth: " + size.x); } @@ -151,7 +152,7 @@ private void performOverlayExitAnimation(){ if (!mCleanUpLock) { final FrameLayout _pointerToFrameLayout = this; mCleanUpLock = true; - Log.d("tourguide","Overlay exit animation listener is overwritten..."); + Log.d(TOURGUIDE,"Overlay exit animation listener is overwritten..."); mOverlay.mExitAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @@ -203,7 +204,7 @@ private void dumpEvent(MotionEvent event) { sb.append(";" ); } sb.append("]" ); - Log.d("tourguide", sb.toString()); + Log.d(TOURGUIDE, sb.toString()); } @Override @@ -229,7 +230,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) { // Log.d("tourguide", "[dispatchTouchEvent] Y higher bound: "+(pos[1] +mViewHole.getHeight())); if(isWithinButton(ev) && mOverlay != null && mOverlay.mDisableClickThroughHole) { - Log.d("tourguide", "block user clicking through hole"); + Log.d(TOURGUIDE, "block user clicking through hole"); // block it return true; } else if (isWithinButton(ev)) { diff --git a/tourguide/src/main/java/tourguide/tourguide/TourGuide.java b/tourguide/src/main/java/tourguide/tourguide/TourGuide.java index ee696ef..ffb8552 100644 --- a/tourguide/src/main/java/tourguide/tourguide/TourGuide.java +++ b/tourguide/src/main/java/tourguide/tourguide/TourGuide.java @@ -24,6 +24,12 @@ * Created by tanjunrong on 2/10/15. */ public class TourGuide { + + public static final String ALPHA = "alpha"; + public static final String SCALE_X = "scaleX"; + public static final String SCALE_Y = "scaleY"; + public static final String TRANSLATION_X = "translationX"; + /** * This describes the animation techniques * */ @@ -489,26 +495,26 @@ public void onAnimationEnd(Animator animator) { long fadeOutDuration = goLeftXDuration; float translationX = getScreenWidth()/2; - final ValueAnimator fadeInAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); + final ValueAnimator fadeInAnim = ObjectAnimator.ofFloat(view, ALPHA, 0f, 1f); fadeInAnim.setDuration(fadeInDuration); - final ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f); + final ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, SCALE_X, 1f, 0.85f); scaleDownX.setDuration(scaleDownDuration); - final ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f); + final ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, SCALE_Y, 1f, 0.85f); scaleDownY.setDuration(scaleDownDuration); - final ObjectAnimator goLeftX = ObjectAnimator.ofFloat(view, "translationX", -translationX); + final ObjectAnimator goLeftX = ObjectAnimator.ofFloat(view, TRANSLATION_X, -translationX); goLeftX.setDuration(goLeftXDuration); - final ValueAnimator fadeOutAnim = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); + final ValueAnimator fadeOutAnim = ObjectAnimator.ofFloat(view, ALPHA, 1f, 0f); fadeOutAnim.setDuration(fadeOutDuration); - final ValueAnimator fadeInAnim2 = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); + final ValueAnimator fadeInAnim2 = ObjectAnimator.ofFloat(view, ALPHA, 0f, 1f); fadeInAnim2.setDuration(fadeInDuration); - final ObjectAnimator scaleDownX2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f); + final ObjectAnimator scaleDownX2 = ObjectAnimator.ofFloat(view, SCALE_X, 1f, 0.85f); scaleDownX2.setDuration(scaleDownDuration); - final ObjectAnimator scaleDownY2 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f); + final ObjectAnimator scaleDownY2 = ObjectAnimator.ofFloat(view, SCALE_Y, 1f, 0.85f); scaleDownY2.setDuration(scaleDownDuration); - final ObjectAnimator goLeftX2 = ObjectAnimator.ofFloat(view, "translationX", -translationX); + final ObjectAnimator goLeftX2 = ObjectAnimator.ofFloat(view, TRANSLATION_X, -translationX); goLeftX2.setDuration(goLeftXDuration); - final ValueAnimator fadeOutAnim2 = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); + final ValueAnimator fadeOutAnim2 = ObjectAnimator.ofFloat(view, ALPHA, 1f, 0f); fadeOutAnim2.setDuration(fadeOutDuration); animatorSet.play(fadeInAnim); @@ -565,34 +571,34 @@ public void onAnimationEnd(Animator animator) { long fadeOutDuration = 800; long delay = 1000; - final ValueAnimator delayAnim = ObjectAnimator.ofFloat(view, "translationX", 0); + final ValueAnimator delayAnim = ObjectAnimator.ofFloat(view, TRANSLATION_X, 0); delayAnim.setDuration(delay); - final ValueAnimator fadeInAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); + final ValueAnimator fadeInAnim = ObjectAnimator.ofFloat(view, ALPHA, 0f, 1f); fadeInAnim.setDuration(fadeInDuration); - final ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f); + final ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, SCALE_X, 1f, 0.85f); scaleDownX.setDuration(scaleDownDuration); - final ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f); + final ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, SCALE_Y, 1f, 0.85f); scaleDownY.setDuration(scaleDownDuration); - final ObjectAnimator scaleUpX = ObjectAnimator.ofFloat(view, "scaleX", 0.85f, 1f); + final ObjectAnimator scaleUpX = ObjectAnimator.ofFloat(view, SCALE_X, 0.85f, 1f); scaleUpX.setDuration(scaleDownDuration); - final ObjectAnimator scaleUpY = ObjectAnimator.ofFloat(view, "scaleY", 0.85f, 1f); + final ObjectAnimator scaleUpY = ObjectAnimator.ofFloat(view, SCALE_Y, 0.85f, 1f); scaleUpY.setDuration(scaleDownDuration); - final ValueAnimator fadeOutAnim = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); + final ValueAnimator fadeOutAnim = ObjectAnimator.ofFloat(view, ALPHA, 1f, 0f); fadeOutAnim.setDuration(fadeOutDuration); - final ValueAnimator delayAnim2 = ObjectAnimator.ofFloat(view, "translationX", 0); + final ValueAnimator delayAnim2 = ObjectAnimator.ofFloat(view, TRANSLATION_X, 0); delayAnim2.setDuration(delay); - final ValueAnimator fadeInAnim2 = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); + final ValueAnimator fadeInAnim2 = ObjectAnimator.ofFloat(view, ALPHA, 0f, 1f); fadeInAnim2.setDuration(fadeInDuration); - final ObjectAnimator scaleDownX2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f); + final ObjectAnimator scaleDownX2 = ObjectAnimator.ofFloat(view, SCALE_X, 1f, 0.85f); scaleDownX2.setDuration(scaleDownDuration); - final ObjectAnimator scaleDownY2 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f); + final ObjectAnimator scaleDownY2 = ObjectAnimator.ofFloat(view, SCALE_Y, 1f, 0.85f); scaleDownY2.setDuration(scaleDownDuration); - final ObjectAnimator scaleUpX2 = ObjectAnimator.ofFloat(view, "scaleX", 0.85f, 1f); + final ObjectAnimator scaleUpX2 = ObjectAnimator.ofFloat(view, SCALE_X, 0.85f, 1f); scaleUpX2.setDuration(scaleDownDuration); - final ObjectAnimator scaleUpY2 = ObjectAnimator.ofFloat(view, "scaleY", 0.85f, 1f); + final ObjectAnimator scaleUpY2 = ObjectAnimator.ofFloat(view, SCALE_Y, 0.85f, 1f); scaleUpY2.setDuration(scaleDownDuration); - final ValueAnimator fadeOutAnim2 = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); + final ValueAnimator fadeOutAnim2 = ObjectAnimator.ofFloat(view, ALPHA, 1f, 0f); fadeOutAnim2.setDuration(fadeOutDuration); view.setAlpha(0); animatorSet.setStartDelay(mToolTip != null ? mToolTip.mEnterAnimation.getDuration() : 0);