diff --git a/library/src/main/java/com/vinaygaba/rubberstamp/PositionCalculator.java b/library/src/main/java/com/vinaygaba/rubberstamp/PositionCalculator.java index 4bd9880..93dbe4c 100644 --- a/library/src/main/java/com/vinaygaba/rubberstamp/PositionCalculator.java +++ b/library/src/main/java/com/vinaygaba/rubberstamp/PositionCalculator.java @@ -1,17 +1,17 @@ -/** - * Copyright (C) 2017 Vinay Gaba - * - * 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. +/* + Copyright (C) 2017 Vinay Gaba + + 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.vinaygaba.rubberstamp; @@ -19,11 +19,20 @@ public class PositionCalculator { + /** + * Utility method to calculate the coordinates of the rubberstamp based on the params passed to + * it. + * @param location The RubberStampPosition which denotes the position of the watermark + * @param bitmapWidth The width of the bitmap where the rubberstamp will be drawn + * @param bitmapHeight The height of the bitmap where the rubberstamp will be drawn + * @param rubberstampWidth The width of the rubberstamp + * @param rubberstampHeight The height of the rubberstamp + * @return Returns a Pair object which has the x-coordinate and the y-coordinate + */ public static Pair getCoordinates(RubberStampPosition location, int bitmapWidth, int bitmapHeight, int rubberstampWidth, int rubberstampHeight) { switch(location){ - case TOP_LEFT: return new Pair<>(0, rubberstampHeight); diff --git a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStamp.java b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStamp.java index 9a824ef..86918b5 100644 --- a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStamp.java +++ b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStamp.java @@ -1,17 +1,17 @@ -/** - * Copyright (C) 2017 Vinay Gaba - * - * 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. +/* + Copyright (C) 2017 Vinay Gaba + + 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.vinaygaba.rubberstamp; @@ -26,6 +26,7 @@ import android.graphics.Shader; import android.graphics.Typeface; import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Pair; @@ -36,14 +37,18 @@ public class RubberStamp { - static Context mContext; - public static final int BACKGROUND_MARGIN = 10; + private Context mContext; + private static final int BACKGROUND_MARGIN = 10; - public RubberStamp(Context context){ + public RubberStamp(@NonNull Context context){ mContext = context; } - public Bitmap addStamp(RubberStampConfig config) { + public Bitmap addStamp(@NonNull RubberStampConfig config) { + if (config == null) { + throw new IllegalArgumentException("The config passed to this method should never" + + "be null"); + } Bitmap baseBitmap = getBaseBitmap(config); if (baseBitmap == null) { return baseBitmap; @@ -58,9 +63,7 @@ public Bitmap addStamp(RubberStampConfig config) { if (!TextUtils.isEmpty(config.getRubberStampString())) { addTextToBitmap(config, canvas, baseBitmapWidth, baseBitmapHeight); - } - - if (config.getRubberStampBitmap() != null) { + } else if (config.getRubberStampBitmap() != null) { addBitmapToBitmap(config.getRubberStampBitmap(), config, canvas, baseBitmapWidth, baseBitmapHeight); } @@ -68,7 +71,7 @@ public Bitmap addStamp(RubberStampConfig config) { } @Nullable - private Bitmap getBaseBitmap(RubberStampConfig config) { + private Bitmap getBaseBitmap(@NonNull RubberStampConfig config) { Bitmap baseBitmap = config.getBaseBitmap(); @DrawableRes int drawable = config.getBaseDrawable(); @@ -79,7 +82,16 @@ private Bitmap getBaseBitmap(RubberStampConfig config) { return baseBitmap; } - private void addTextToBitmap(RubberStampConfig config, Canvas canvas, int baseBitmapWidth, + /** + * Method to add text RubberStamp to a canvas based on the provided configuration + * @param config The RubberStampConfig that specifies how the RubberStamp should look + * @param canvas The canvas on top of which the RubberStamp needs to be drawn + * @param baseBitmapWidth The width of the base bitmap + * @param baseBitmapHeight The height of the base bitmap + */ + private void addTextToBitmap(@NonNull RubberStampConfig config, + @NonNull Canvas canvas, + int baseBitmapWidth, int baseBitmapHeight) { Rect bounds = new Rect(); @@ -168,8 +180,19 @@ private void addTextToBitmap(RubberStampConfig config, Canvas canvas, int baseBi } } - private void addBitmapToBitmap(Bitmap rubberStampBitmap, RubberStampConfig config, Canvas canvas, - int baseBitmapWidth, int baseBitmapHeight) { + /** + * Method to add a bitmap RubberStamp to a canvas based on the provided configuration + * @param rubberStampBitmap The bitmap which will be used as the RubberStamp + * @param config The RubberStampConfig that specifies how the RubberStamp should look + * @param canvas The canvas on top of which the RubberStamp needs to be drawn + * @param baseBitmapWidth The width of the base bitmap + * @param baseBitmapHeight The height of the base bitmap + */ + private void addBitmapToBitmap(@NonNull Bitmap rubberStampBitmap, + @NonNull RubberStampConfig config, + @NonNull Canvas canvas, + int baseBitmapWidth, + int baseBitmapHeight) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setUnderlineText(false); diff --git a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampConfig.java b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampConfig.java index 3239b78..3ccbe2a 100644 --- a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampConfig.java +++ b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampConfig.java @@ -1,17 +1,17 @@ -/** - * Copyright (C) 2017 Vinay Gaba - * - * 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. +/* + Copyright (C) 2017 Vinay Gaba + + 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.vinaygaba.rubberstamp; diff --git a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampPosition.java b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampPosition.java index eecdbd8..a6effce 100644 --- a/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampPosition.java +++ b/library/src/main/java/com/vinaygaba/rubberstamp/RubberStampPosition.java @@ -1,20 +1,23 @@ -/** - * Copyright (C) 2017 Vinay Gaba - * - * 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. +/* + Copyright (C) 2017 Vinay Gaba + + 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.vinaygaba.rubberstamp; +/** + * Enums to represent the position configurations of the rubberstamp + */ public enum RubberStampPosition { TOP_LEFT, TOP_RIGHT, TOP_CENTER, CENTER_LEFT, CENTER_RIGHT, CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, BOTTOM_CENTER, CUSTOM, TILE