texts) {
66 | mTextView.setTextSize(mOptions.textSize);
67 | mTextView.setTextColor(mOptions.textColor);
68 |
69 | Spannable spannable = new SpannableString(TextUtils.join("\n", texts));
70 | spannable.setSpan(new BackgroundColorSpan(mOptions.backgroundColor), 0, spannable.length(),
71 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
72 |
73 | mTextView.setText(spannable);
74 | }
75 |
76 | @Override
77 | public void onDestroy() {
78 | super.onDestroy();
79 | if (mTextView != null) {
80 | WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
81 | wm.removeView(mTextView);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/helper/MakeUp.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.helper;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 03. 17..
5 | */
6 | import android.graphics.Typeface;
7 | import android.text.Spannable;
8 | import android.text.SpannableString;
9 | import android.text.style.BackgroundColorSpan;
10 | import android.text.style.ForegroundColorSpan;
11 | import android.text.style.RelativeSizeSpan;
12 | import android.text.style.StrikethroughSpan;
13 | import android.text.style.StyleSpan;
14 | import android.text.style.UnderlineSpan;
15 |
16 | public class MakeUp
17 | {
18 | private final Spannable sb;
19 |
20 | public MakeUp( String input )
21 | {
22 | sb = new SpannableString( input );
23 | }
24 |
25 | public MakeUp strikethrough( int start, int length )
26 | {
27 | final StrikethroughSpan span = new StrikethroughSpan();
28 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
29 | return this;
30 | }
31 |
32 | public MakeUp underline( int start, int length )
33 | {
34 | final UnderlineSpan span = new UnderlineSpan();
35 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
36 | return this;
37 | }
38 |
39 | public MakeUp boldify( int start, int length )
40 | {
41 | final StyleSpan span = new StyleSpan( android.graphics.Typeface.BOLD );
42 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
43 | return this;
44 | }
45 |
46 | public MakeUp italize( int start, int length )
47 | {
48 | final StyleSpan span = new StyleSpan( Typeface.ITALIC );
49 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
50 | return this;
51 | }
52 |
53 | public MakeUp colorize( int start, int length, int color )
54 | {
55 | final ForegroundColorSpan span = new ForegroundColorSpan( color );
56 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
57 | return this;
58 | }
59 |
60 | public MakeUp mark( int start, int length, int color )
61 | {
62 | final BackgroundColorSpan span = new BackgroundColorSpan( color );
63 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
64 | return this;
65 | }
66 |
67 | public MakeUp proportionate( int start, int length, float proportion )
68 | {
69 | final RelativeSizeSpan span = new RelativeSizeSpan( proportion );
70 | sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
71 | return this;
72 | }
73 |
74 | public Spannable apply()
75 | {
76 | return sb;
77 | }
78 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/helper/OnClickHelper.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.helper;
2 |
3 | import org.apache.commons.lang3.time.DateUtils;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.11..
9 | */
10 | public class OnClickHelper {
11 | private static Date occupiedUntil = null;
12 |
13 | public static int DEFAULT_WAIT_MS = 600;
14 |
15 | /**
16 | * Tries to occupy the onclick enabler.
17 | * @param waitMs the time interval to occupy
18 | * @return if noone occupied it, returns true, else false
19 | */
20 | public static boolean occupy(int waitMs){
21 | if(occupiedUntil != null && occupiedUntil.after(new Date())){
22 | return false;
23 | }
24 | occupiedUntil = DateUtils.addMilliseconds(new Date(), waitMs);
25 | return true;
26 | }
27 |
28 | /**
29 | * Tries to occupy the onclick enabler for the default time limit
30 | * @return if noone occupied it, returns true, else false
31 | */
32 | public static boolean occupy(){
33 | return occupy(DEFAULT_WAIT_MS);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/helper/TelephonyHelper.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.helper;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.telephony.TelephonyManager;
7 |
8 | /**
9 | * Created by Richard Radics on 2015.02.11..
10 | */
11 | public class TelephonyHelper {
12 |
13 | /**
14 | * Starts the dial activity with SIM enabled check.
15 | * @param context
16 | * @param phone
17 | */
18 | public static void startDialActivityWithSimCheck(Context context, String phone) {
19 | if (isTelephonyEnabled(context)) {
20 | Intent intent = new Intent(Intent.ACTION_DIAL);
21 | intent.setData(Uri.parse("tel:" + clearPhoneText(phone)));
22 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
23 | context.startActivity(intent);
24 | }
25 | }
26 |
27 |
28 | /**
29 | * Starts the dial activity.
30 | * @param context
31 | * @param phone
32 | */
33 | public static void startDialActivity(Context context, String phone) {
34 | Intent intent = new Intent(Intent.ACTION_DIAL);
35 | intent.setData(Uri.parse("tel:" + clearPhoneText(phone)));
36 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
37 | context.startActivity(intent);
38 | }
39 |
40 | /**
41 | * Checks the device has sim card.
42 | * @param context
43 | * @return
44 | */
45 | public static boolean isTelephonyEnabled(Context context) {
46 | TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
47 | return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
48 | }
49 |
50 | public static String clearPhoneText(String phone){
51 | String s = phone.replace("/", "");
52 | String s2 = s.replace("-","");
53 | return s2;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/helper/Validator.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.helper;
2 |
3 | import android.text.TextUtils;
4 |
5 | /**
6 | * Created by PontApps on 2015.03.11..
7 | */
8 | public class Validator {
9 |
10 | public final static boolean isValidEmail(CharSequence target) {
11 | if (TextUtils.isEmpty(target)) {
12 | return false;
13 | } else {
14 | return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/listeners/CustomDialogOnClickListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.listeners;
2 |
3 | import android.content.DialogInterface;
4 |
5 | /**
6 | * Created by richardradics on 2015.02.23..
7 | */
8 | public class CustomDialogOnClickListener implements DialogInterface.OnClickListener {
9 |
10 | private int id;
11 |
12 | public int getId() {
13 | return id;
14 | }
15 |
16 | ExtendedDialogOnClickListener extendedDialogOnClickListener;
17 |
18 | public CustomDialogOnClickListener(int id, ExtendedDialogOnClickListener extendedDialogOnClickListener){
19 | this.id = id;
20 | this.extendedDialogOnClickListener = extendedDialogOnClickListener;
21 | }
22 |
23 | @Override
24 | public void onClick(DialogInterface dialogInterface, int i) {
25 | if(extendedDialogOnClickListener != null) {
26 | extendedDialogOnClickListener.onDialogClick(dialogInterface, i, id);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/listeners/ExtendedDialogOnClickListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.listeners;
2 |
3 | import android.content.DialogInterface;
4 |
5 | /**
6 | * Created by richardradics on 2015.02.23..
7 | */
8 | public interface ExtendedDialogOnClickListener {
9 | void onDialogClick(DialogInterface dialogInterface, int i, int id);
10 | }
11 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/listeners/OnItemSelectedListenerWrapper.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.listeners;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.widget.AdapterView;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.11..
9 | */
10 | public class OnItemSelectedListenerWrapper implements AdapterView.OnItemSelectedListener {
11 |
12 | private int lastPosition;
13 | private AdapterView.OnItemSelectedListener listener;
14 |
15 | private boolean isFirstStart = true;
16 |
17 |
18 | public OnItemSelectedListenerWrapper(AdapterView.OnItemSelectedListener listener) {
19 | lastPosition = 0;
20 | this.listener = listener;
21 | }
22 |
23 | @Override
24 | public void onItemSelected(AdapterView> aParentView, View aView, int aPosition, long anId) {
25 | if (!isFirstStart) {
26 | if (lastPosition == aPosition) {
27 | Log.d("ItemSelectedWrapper", "Ignoring onItemSelected for same position: " + aPosition);
28 | } else {//
29 | Log.d("ItemSelectedWrapper", "Passing on onItemSelected for different position: " + aPosition);
30 | listener.onItemSelected(aParentView, aView, aPosition, anId);
31 | }
32 | lastPosition = aPosition;
33 | } else {
34 | isFirstStart = false;
35 | }
36 | }
37 |
38 | @Override
39 | public void onNothingSelected(AdapterView> aParentView) {
40 | listener.onNothingSelected(aParentView);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/security/HashGenerator.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.security;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | /**
7 | * Created by Richard Radics on 2015.02.11..
8 | */
9 | public class HashGenerator {
10 |
11 |
12 | /**
13 | * Generates hash from the specified string.
14 | * @param s
15 | * @return
16 | */
17 | public static final String generateHash(final String s) {
18 | try {
19 | // Create MD5 Hash
20 | MessageDigest digest = java.security.MessageDigest
21 | .getInstance("MD5");
22 | digest.update(s.getBytes());
23 | byte messageDigest[] = digest.digest();
24 |
25 | // Create Hex String
26 | StringBuffer hexString = new StringBuffer();
27 | for (int i = 0; i < messageDigest.length; i++) {
28 | String h = Integer.toHexString(0xFF & messageDigest[i]);
29 | while (h.length() < 2)
30 | h = "0" + h;
31 | hexString.append(h);
32 | }
33 | return hexString.toString();
34 |
35 | } catch (NoSuchAlgorithmException e) {
36 | e.printStackTrace();
37 | }
38 | return "";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/test/TestHelper.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.test;
2 |
3 | import android.util.Log;
4 |
5 | import org.apache.commons.io.IOUtils;
6 |
7 | import java.io.IOException;
8 | import java.lang.reflect.Field;
9 | import java.lang.reflect.Modifier;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by radicsrichard on 15. 05. 18..
14 | */
15 | public class TestHelper {
16 |
17 | public static void setFinalStatic(Field field, Object newValue) throws Exception {
18 | field.setAccessible(true);
19 |
20 | // remove final modifier from field
21 | Field modifiersField = Field.class.getDeclaredField("modifiers");
22 | modifiersField.setAccessible(true);
23 | modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
24 |
25 | field.set(null, newValue);
26 | }
27 |
28 | public static String getStringFromResource(String resourceName){
29 | String result = "";
30 | ClassLoader classLoader = TestHelper.class.getClassLoader();
31 | try {
32 | result = IOUtils.toString(classLoader.getResourceAsStream(resourceName), "UTF-8");
33 | } catch (IOException e) {
34 | e.printStackTrace();
35 | }
36 |
37 | return result;
38 | }
39 |
40 | public static void printCollection(List collection){
41 | Log.i("Data", String.valueOf(collection));
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/ui/ActivityAnimator.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.ui;
2 |
3 | import android.app.Activity;
4 |
5 | import com.richardradics.commons.R;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.09..
9 | */
10 | public class ActivityAnimator {
11 |
12 | public static void flipHorizontalAnimation(Activity a)
13 | {
14 | a.overridePendingTransition(R.anim.flip_horizontal_in, R.anim.flip_horizontal_out);
15 | }
16 |
17 | public static void flipVerticalAnimation(Activity a)
18 | {
19 | a.overridePendingTransition(R.anim.flip_vertical_in, R.anim.flip_vertical_out);
20 | }
21 |
22 | public static void fadeAnimation(Activity a)
23 | {
24 | a.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
25 | }
26 |
27 | public static void disappearTopLeftAnimation(Activity a)
28 | {
29 | a.overridePendingTransition(R.anim.disappear_top_left_in, R.anim.disappear_top_left_out);
30 | }
31 |
32 | public static void appearTopLeftAnimation(Activity a)
33 | {
34 | a.overridePendingTransition(R.anim.appear_top_left_in, R.anim.appear_top_left_out);
35 | }
36 |
37 | public static void disappearBottomRightAnimation(Activity a)
38 | {
39 | a.overridePendingTransition(R.anim.disappear_bottom_right_in, R.anim.disappear_bottom_right_out);
40 | }
41 |
42 | public static void appearBottomRightAnimation(Activity a)
43 | {
44 | a.overridePendingTransition(R.anim.appear_bottom_right_in, R.anim.appear_bottom_right_out);
45 | }
46 |
47 | public static void unzoomAnimation(Activity a)
48 | {
49 | a.overridePendingTransition(R.anim.unzoom_in, R.anim.unzoom_out);
50 | }
51 |
52 | public static void PullRightPushLeft(Activity a)
53 | {
54 | a.overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
55 | }
56 | public static void PullLeftPushRight(Activity a)
57 | {
58 | a.overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/AsyncTaskUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.AsyncTask;
5 | import android.os.Build;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.09..
9 | */
10 | public class AsyncTaskUtil {
11 |
12 | /**
13 | * AsyncTask executor, if the phone is below HoneyComb it's use a single executor
14 | * above HoneyComb parallal executor.
15 | * @param task
16 | * @param
17 | * @param
18 | */
19 | public static > void execute(T task) {
20 | execute(task, (P[]) null);
21 | }
22 |
23 | @SuppressLint("NewApi")
24 | public static
> void execute(T task, P... params) {
25 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
26 | task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
27 | } else {
28 | task.execute(params);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/BitmapUtil2.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.BitmapFactory;
5 |
6 | /**
7 | * Created by radicsrichard on 15. 03. 13..
8 | */
9 | public class BitmapUtil2 {
10 |
11 | public static BitmapFactory.Options getSize(Context c, int resId){
12 | android.graphics.BitmapFactory.Options o = new android.graphics.BitmapFactory.Options();
13 | o.inJustDecodeBounds = true;
14 | BitmapFactory.decodeResource(c.getResources(), resId, o);
15 | return o;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/ColorUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.graphics.Color;
4 |
5 | import java.util.Random;
6 |
7 | /**
8 | * Created by Richard Radics on 2014.12.11..
9 | */
10 | public class ColorUtil {
11 |
12 | private static Random randomGenerator = new Random();
13 |
14 |
15 | /**
16 | * Gets a random darker color.
17 | * @return
18 | */
19 | public static int getRandomDarkColor(){
20 | int randColor = getRandomColor();
21 | return darker(randColor, 0.75f);
22 | }
23 |
24 |
25 | /**
26 | * Retuns a darker color from a specified color by the factor.
27 | * @param color
28 | * @param factor
29 | * @return
30 | */
31 | public static int darker (int color, float factor) {
32 | int a = Color.alpha( color );
33 | int r = Color.red( color );
34 | int g = Color.green( color );
35 | int b = Color.blue( color );
36 |
37 | return Color.argb( a,
38 | Math.max( (int)(r * factor), 0 ),
39 | Math.max( (int)(g * factor), 0 ),
40 | Math.max( (int)(b * factor), 0 ) );
41 | }
42 |
43 |
44 | /**
45 | * Returns a random color.
46 | * @return
47 | */
48 | public static int getRandomColor(){
49 | return Color.rgb(randomGenerator.nextInt(255), randomGenerator.nextInt(255), randomGenerator.nextInt(255));
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/Constants.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | /**
4 | * Created by Rcsk on 2014.09.25..
5 | */
6 | public class Constants {
7 |
8 |
9 | public static final String APP_JSON = "application/json";
10 | public static final String APP_URLENCODED = "application/x-www-form-urlencoded";
11 |
12 | public static final class EncodingTypes{
13 | public static final String UTF_8 = "UTF-8";
14 | public static final String ENC_UTF8 = "UTF-8";
15 | public static final String ENC_ISO_8859_1 = "iso-8859-1";
16 | public static final String ENC_ISO_8859_2 = "iso-8859-2";
17 | }
18 |
19 | public static final class HTTP {
20 | public static final long ERROR_404 = 404;
21 | public static final long ERROR_403 = 403;
22 | }
23 |
24 | public static class Text{
25 | public static final String DOUBLE_LINE_SEP = "\n\n";
26 | public static final String SINGLE_LINE_SEP = "\n";
27 |
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/CountUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.text.DecimalFormat;
4 |
5 | /**
6 | *
Utility methods for formatting counts
7 | *
8 | * Common uses:
9 | * CountUtil.{@link #getFormattedCount getFormattedCount}(1200000);
// returns "1.2m"
10 | */
11 |
12 | public class CountUtil {
13 |
14 | /**
15 | * @see #getFormattedCount(Long)
16 | */
17 | public static String getFormattedCount(int count) {
18 | return getFormattedCount(Long.valueOf(count));
19 | }
20 |
21 | /**
22 | * @see #getFormattedCount(Long)
23 | */
24 | public static String getFormattedCount(String count) {
25 | return getFormattedCount(Long.parseLong(count));
26 | }
27 |
28 | /**
29 | * Used to format a given number into a short representation.
30 | *
31 | * Examples:
32 | * Given 9100, will return "9.1k".
33 | * Given 8100000, will return "8.1m"
34 | * Given 10, will return 10"
35 | *
36 | * @param count Value to convert.
37 | * @return Formatted value (see examples)
38 | */
39 | public static String getFormattedCount(Long count) {
40 | final String unit;
41 | final Double dbl;
42 | final DecimalFormat format = new DecimalFormat("#.#");
43 | if (count < 1000) {
44 | return format.format(count);
45 | } else if (count < 1000000) {
46 | unit = "k";
47 | dbl = count / 1000.0;
48 | } else if (count < 1000000000) {
49 | unit = "m";
50 | dbl = count / 1000000.0;
51 | } else {
52 | unit = "b";
53 | dbl = count / 1000000000.0;
54 | }
55 | return format.format(dbl) + unit;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/DecimalFormatUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.text.DecimalFormat;
4 | import java.text.DecimalFormatSymbols;
5 | import java.text.NumberFormat;
6 | import java.util.Locale;
7 |
8 | /**
9 | * Created by Rcsk on 2014.06.16..
10 | */
11 | public class DecimalFormatUtil {
12 |
13 | /**
14 | * Returns a thousans separated decimar formatter.
15 | *
16 | * @return
17 | */
18 | public static DecimalFormat getThousandSeperatedDecimalFormat() {
19 | DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US);
20 | DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
21 | symbols.setGroupingSeparator(' ');
22 | df.setDecimalFormatSymbols(symbols);
23 | return df;
24 | }
25 |
26 |
27 | /**
28 | *
29 | * @param value e.g. 1.199999
30 | * @return 1.2
31 | */
32 | public static String formatDouble(double value) {
33 | return new DecimalFormat("#.##").format(value);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/DensityUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.util.DisplayMetrics;
6 |
7 | /**
8 | * Created by mark on 2015. 03. 20..
9 | */
10 | public class DensityUtil {
11 | /**
12 | * This method converts dp unit to equivalent pixels, depending on device density.
13 | *
14 | * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
15 | * @param context Context to get resources and device specific display metrics
16 | * @return A float value to represent px equivalent to dp depending on device density
17 | */
18 | public static float convertDpToPixel(float dp, Context context){
19 | Resources resources = context.getResources();
20 | DisplayMetrics metrics = resources.getDisplayMetrics();
21 | float px = dp * (metrics.densityDpi / 160f);
22 | return px;
23 | }
24 |
25 | /**
26 | * This method converts device specific pixels to density independent pixels.
27 | *
28 | * @param px A value in px (pixels) unit. Which we need to convert into db
29 | * @param context Context to get resources and device specific display metrics
30 | * @return A float value to represent dp equivalent to px value
31 | */
32 | public static float convertPixelsToDp(float px, Context context){
33 | Resources resources = context.getResources();
34 | DisplayMetrics metrics = resources.getDisplayMetrics();
35 | float dp = px / (metrics.densityDpi / 160f);
36 | return dp;
37 | }
38 |
39 |
40 | public static int getDeviceWidthInPixes(Context context){
41 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
42 | return metrics.widthPixels;
43 |
44 | }
45 |
46 | public static int getDeviceHeightInPixes(Context context){
47 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
48 | return metrics.heightPixels;
49 |
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/DialogUtils.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.app.AlertDialog.Builder;
6 | import android.content.DialogInterface;
7 | import android.content.DialogInterface.OnClickListener;
8 | import android.text.SpannableString;
9 | import android.text.method.LinkMovementMethod;
10 | import android.text.util.Linkify;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by Richard Radics on 2015.02.12..
15 | */
16 | public class DialogUtils {
17 |
18 | /**
19 | * Show a model dialog box. The android.app.AlertDialog
object is returned so that
20 | * you can specify an OnDismissListener (or other listeners) if required.
21 | * Note: show() is already called on the AlertDialog being returned.
22 | *
23 | * @param context The current Context or Activity that this method is called from.
24 | * @param message Message to display in the dialog.
25 | * @return AlertDialog that is being displayed.
26 | */
27 | public static AlertDialog quickDialog(final Activity context, final String message) {
28 | final SpannableString s = new SpannableString(message); //Make links clickable
29 | Linkify.addLinks(s, Linkify.ALL);
30 |
31 | Builder builder = new AlertDialog.Builder(context);
32 | builder.setMessage(s);
33 | builder.setPositiveButton(android.R.string.ok, closeDialogListener());
34 | AlertDialog dialog = builder.create();
35 | dialog.show();
36 |
37 | ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); //Make links clickable
38 |
39 | return dialog;
40 | }
41 |
42 | /**
43 | * Simple listener event that closes the current dialog event when fired.
44 | *
45 | * @return DialogInterface.OnClickListener that can be attached to a button
46 | */
47 | public static OnClickListener closeDialogListener() {
48 | return new OnClickListener() {
49 | public void onClick(DialogInterface dialog, int id) {
50 | dialog.dismiss();
51 | }
52 | };
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/EmailUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.widget.Toast;
6 |
7 | /**
8 | * Project: commons
9 | * Package: com.richardradics.commons.util
10 | * Created by richardradics on 2015.02.25..
11 | */
12 | public class EmailUtil {
13 |
14 |
15 | public static void startEmailActivity(Context context, String to, String subject, String body, String pickerTitle){
16 | Intent i = new Intent(Intent.ACTION_SEND);
17 | i.setType("message/rfc822");
18 | i.putExtra(Intent.EXTRA_EMAIL , new String[]{to});
19 | i.putExtra(Intent.EXTRA_SUBJECT, subject);
20 | i.putExtra(Intent.EXTRA_TEXT , body);
21 | try {
22 | context.startActivity(Intent.createChooser(i, pickerTitle).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
23 | } catch (android.content.ActivityNotFoundException ex) {
24 |
25 | }
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/GridViewUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 | import android.widget.GridView;
6 | import android.widget.ListAdapter;
7 |
8 | /**
9 | * Created by Richard Radics on 2014.12.11..
10 | */
11 | public class GridViewUtil {
12 |
13 | /**
14 | * Resizes the gridview.
15 | * @param gridView
16 | * @param items count
17 | * @param columns column number
18 | */
19 | public static void resizeGridView(GridView gridView, int columns) {
20 | ListAdapter listAdapter = gridView.getAdapter();
21 | if (listAdapter == null) {
22 | // pre-condition
23 | return;
24 | }
25 |
26 | int totalHeight = 0;
27 | int items = listAdapter.getCount();
28 | int rows = 0;
29 |
30 | int maxHeight = 0;
31 |
32 | for(int i = 0; i< listAdapter.getCount(); i++ ){
33 | View listItem = listAdapter.getView(i, null, gridView);
34 | listItem.measure(0, 0);
35 | totalHeight = listItem.getMeasuredHeight();
36 | if(maxHeight < totalHeight){
37 | maxHeight = totalHeight;
38 | }
39 | }
40 |
41 |
42 |
43 | float x = 1;
44 | if( items > columns ){
45 | x = items/columns;
46 | rows = (int) (x + 1);
47 | maxHeight *= rows;
48 | }
49 |
50 | ViewGroup.LayoutParams params = gridView.getLayoutParams();
51 | params.height = maxHeight;
52 | gridView.setLayoutParams(params);
53 |
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/HungarianCollation.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.text.ParseException;
4 | import java.text.RuleBasedCollator;
5 |
6 | /**
7 | * Created by User on 2014.12.19..
8 | */
9 | public class HungarianCollation extends RuleBasedCollator {
10 |
11 | /**
12 | * Constructs a new instance of {@code RuleBasedCollator} using the
13 | * specified {@code rules}. (See the {@link java.text.RuleBasedCollator class description}.)
14 | *
15 | * Note that the {@code rules} are interpreted as a delta to the
16 | * default sort order. This differs
17 | * from other implementations which work with full {@code rules}
18 | * specifications and may result in different behavior.
19 | *
20 | * @param rules the collation rules.
21 | * @throws NullPointerException if {@code rules == null}.
22 | * @throws java.text.ParseException if {@code rules} contains rules with invalid collation rule
23 | * syntax.
24 | */
25 | public HungarianCollation() throws ParseException {
26 | super(hungarianRules);
27 | }
28 |
29 | /**
30 | * Hungarian Collator Rules.
31 | */
32 | public static String hungarianRules = ("&9 < a,A < á,Á < b,B < c,C < cs,Cs < d,D < dz,Dz < dzs,Dzs "
33 | + "< e,E < é,É < f,F < g,G < gy,Gy < h,H < i,I < í,Í < j,J "
34 | + "< k,K < l,L < ly,Ly < m,M < n,N < ny,Ny < o,O < ó,Ó "
35 | + "< ö,Ö < õ,Õ < p,P < q,Q < r,R < s,S < sz,Sz < t,T "
36 | + "< ty,Ty < u,U < ú,Ú < v,V < w,W < x,X < y,Y < z,Z < zs,Zs");
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/ListViewUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 |
4 | import android.util.Log;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ListAdapter;
8 | import android.widget.ListView;
9 |
10 | /**
11 | * Created by Richard Radics on 2015.02.09..
12 | */
13 | public class ListViewUtil {
14 |
15 |
16 | /**** Method for Setting the Height of the ListView dynamically.
17 | **** Hack to fix the issue of not showing all the items of the ListView
18 | **** when placed inside a ScrollView ****/
19 | public static void setListViewHeightBasedOnChildren(ListView listView) {
20 | ListAdapter mAdapter = listView.getAdapter();
21 |
22 | int totalHeight = 0;
23 |
24 | for (int i = 0; i < mAdapter.getCount(); i++) {
25 | View mView = mAdapter.getView(i, null, listView);
26 |
27 | mView.measure(
28 | View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
29 |
30 | View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
31 |
32 | totalHeight += mView.getMeasuredHeight();
33 | Log.w("HEIGHT" + i, String.valueOf(totalHeight));
34 |
35 | }
36 |
37 | ViewGroup.LayoutParams params = listView.getLayoutParams();
38 | params.height = totalHeight
39 | + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
40 | listView.setLayoutParams(params);
41 | listView.requestLayout();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | /**
4 | * Created by PontApps on 2015.03.03..
5 | */
6 | public class LogUtils {
7 |
8 |
9 | private LogUtils() {
10 | //You shall not pass
11 | }
12 |
13 | public static String generateTag(Object object) {
14 | return object.getClass().getCanonicalName();
15 | }
16 | }
17 |
18 |
19 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/MapUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created by radicsrichard on 15. 04. 16..
7 | */
8 | public class MapUtil {
9 |
10 | public static T getSingleValue(Map map) {
11 | return (T) map.values().toArray()[0];
12 | }
13 |
14 | public static T getSingleKey(Map map) {
15 | return (T) map.keySet().toArray()[0];
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/NetworkUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 |
6 | /**
7 | * Created by Richard Radics on 2015.02.11..
8 | */
9 | public class NetworkUtil {
10 |
11 | /**
12 | * Checks the internet is active.
13 | * @param context
14 | * @return
15 | */
16 | public static boolean checkInternetIsActive(Context context) {
17 | ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
18 | android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
19 | android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
20 |
21 | if (wifi.isConnected() || mobile.isConnected()) {
22 | return true;
23 | }
24 |
25 | return false;
26 |
27 | }
28 |
29 | /**
30 | * Checks wifi is active.
31 | * @param context
32 | * @return
33 | */
34 | public static boolean checkWifiIsActive(Context context) {
35 | ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
36 | android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
37 | if (wifi.isConnected()) {
38 | return true;
39 | }
40 | return false;
41 | }
42 |
43 | /**
44 | * Checks mobile network is active.
45 | * @param context
46 | * @return
47 | */
48 | public static boolean checkMobileIsActive(Context context) {
49 | ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
50 | android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
51 | if (mobile.isConnected()) {
52 | return true;
53 | }
54 | return false;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/PhoneUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.provider.Settings;
5 | import android.util.DisplayMetrics;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.12..
9 | */
10 | public class PhoneUtil {
11 |
12 | /**
13 | * Checks to see if the user has rotation enabled/disabled in their phone settings.
14 | *
15 | * @param context The current Context or Activity that this method is called from
16 | * @return true if rotation is enabled, otherwise false.
17 | */
18 | public static boolean isRotationEnabled(Context context) {
19 | return android.provider.Settings.System.getInt(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1;
20 | }
21 |
22 | /**
23 | * Retuns device DPI.
24 | * @param c
25 | * @return
26 | */
27 | public static int deviceDPI(Context c) {
28 | return c.getResources().getDisplayMetrics().densityDpi;
29 | }
30 |
31 | /**
32 | * Retuns device resolution.
33 | * @param c
34 | * @return
35 | */
36 | public static String deviceResolution(Context c) {
37 | DisplayMetrics metrics = c.getResources().getDisplayMetrics();
38 | return String.valueOf(metrics.widthPixels) + "x" + metrics.heightPixels;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/RandomUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | /**
8 | * Created by richardradics on 2015.02.17..
9 | */
10 | public class RandomUtil {
11 |
12 |
13 | /***
14 | * Random numbers generator.
15 | *
16 | * @param startNumber the range start number
17 | * @param endNumber the range end number
18 | * @param numberCount the count of the requested randomnumbers.
19 | * @return an array with random numbers
20 | */
21 | public static int[] getRandomNumbers(int startNumber, int endNumber, int numberCount){
22 |
23 | int[] randomNumbers = new int[numberCount];
24 |
25 | List list = new ArrayList();
26 | for(int i = startNumber; i <= endNumber; i++) list.add(i);
27 | Collections.shuffle(list);
28 |
29 |
30 | for(int i = 0; i< numberCount; i++){
31 | randomNumbers[i] = list.get(i);
32 | }
33 |
34 |
35 | return randomNumbers;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/RangePickerUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | /**
4 | * Created by richardradics on 2015.02.17..
5 | */
6 | public class RangePickerUtil {
7 |
8 | /**
9 | * Prints range selection
10 | *
11 | * @param leftValue 5
12 | * @param rightValue 10
13 | * @param separator -
14 | * @return 5 - 10
15 | */
16 | public static String printRangeValue(String leftValue, String rightValue, String separator){
17 | StringBuilder sb = new StringBuilder();
18 | sb.append(leftValue+ " " );
19 | sb.append(separator);
20 | sb.append(" " + rightValue);
21 |
22 | return sb.toString();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/RegexUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | /**
4 | * Common regexps.
5 | *
6 | * Created by Richard Radics on 2015.02.11..
7 | */
8 | public class RegexUtil {
9 |
10 |
11 | public static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-\\+]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
12 |
13 | // public static final String PASSWORD_PATTERN =
14 | // "(?=(.*[a-zA-Z]))^[0-9a-zA-Z!@#$%^&*()_+\\-=\\[\\]{};':\"\\|,.<>\\/?]{4,}$";
15 |
16 | public static final String PASSWORD_PATTERN = ".{4,}";
17 |
18 |
19 | public static final String USERNAME_PATTERN = "(?=(.*[a-zA-Z]){3})^[0-9a-zA-Z]{3,}$";
20 |
21 | public static final String ANYTHING_PATTERN = ".*";
22 |
23 | // public static final String USERNAME_LENGTH_PATTERN =
24 | // "((?=.*\d)|(?=.*[a-z])|(?=.*[a-z])|(?=.*[A-Z]).{5,20})";
25 |
26 | public static final String FULL_NAME_PATTERN = "^([ \\x{00C0}-\\x{01FF}a-zA-Z\\'\\-\\.])*$"; //
27 |
28 | public static final String PHONE_PATTERN = "^[0-9]{8,13}$";
29 |
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/ResourceUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.drawable.Drawable;
5 |
6 | /**
7 | * Created by radicsrichard on 15. 04. 15..
8 | */
9 | public class ResourceUtil {
10 |
11 | static public int getAndroidDrawableId(String pDrawableName){
12 | int resourceId= Resources.getSystem().getIdentifier(pDrawableName, "drawable", "android");
13 | if(resourceId==0){
14 | return 0;
15 | } else {
16 | return resourceId;
17 | }
18 | }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/RomanNumeralCollation.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import java.text.ParseException;
4 | import java.text.RuleBasedCollator;
5 |
6 |
7 | /**
8 | * Created by radicsrichard on 15. 04. 30..
9 | */
10 | public class RomanNumeralCollation extends RuleBasedCollator {
11 |
12 | public RomanNumeralCollation() throws ParseException {
13 | super(romanNumerals);
14 | }
15 |
16 | private static String romanNumerals = "&9 < I < II < III < IV < V < VI < VII" +
17 | " < VIII < IX < X < XI < XII < XIII < XIV < XV < XVI < XVII < XVIII < XIX < XX" +
18 | " < XXI < XXII < XXIII < XXIV < XXV < XXVI < XXVII < XXVIII < XXIX" +
19 | " < XXX < XXXI < XL < L < LX < LXX < LXXX < XC < C < CI" +
20 | " < CL < CC < CCC < CD < D < DC < DCC < DCCC < CM < M < MDC < MDCC < MCM";
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/SDCardUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.os.Environment;
4 | import android.os.StatFs;
5 |
6 | /**
7 | * Created by Richard Radics on 2015.02.11..
8 | */
9 | public class SDCardUtil {
10 |
11 | /**
12 | * Returns the SD card is available.
13 | * @return
14 | */
15 | public static Boolean checkAvailable() {
16 | String state = Environment.getExternalStorageState();
17 |
18 | if (Environment.MEDIA_MOUNTED.equals(state)) {
19 | return true;
20 | } else {
21 | return false;
22 | }
23 | }
24 |
25 | /**
26 | * Checks the SD card is readonly.
27 | * @return
28 | */
29 | public static Boolean checkIsReadOnly() {
30 | String state = Environment.getExternalStorageState();
31 | if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
32 | return true;
33 | } else {
34 | return false;
35 | }
36 | }
37 |
38 | /**
39 | * Returns the available space in megabytes.
40 | * @return
41 | */
42 | public static int getAvailableSpaceInMegaBytes() {
43 | int availableSpace = 0;
44 |
45 | try {
46 | StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
47 | availableSpace = stat.getAvailableBlocks() * stat.getBlockSize() / 1048576;
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | }
51 | return availableSpace;
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/ServiceUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.app.ActivityManager;
4 | import android.app.Service;
5 | import android.content.Context;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.12..
9 | */
10 | public class ServiceUtil {
11 |
12 | /**
13 | * Checks the specified service is running.
14 | * @param service
15 | * @param context
16 | * @return
17 | */
18 | public static boolean isServiceRunning(Class extends Service> service, Context context) {
19 | ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
20 | for (ActivityManager.RunningServiceInfo runningServiceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
21 | if (service.getName().equals(runningServiceInfo.service.getClassName())) {
22 | return true;
23 | }
24 | }
25 | return false;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/TextUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.util.TypedValue;
6 |
7 | /**
8 | * Created by Richard Radics on 2014.12.08..
9 | */
10 | public class TextUtil {
11 |
12 | private final static String EMPTY_STRING = "";
13 | private final static String THREE_DOTS = "…";
14 |
15 | public static String getLineSepartor() {
16 | return System.getProperty("line.separator");
17 | }
18 |
19 | public static String getDoubleLineSeparator() {
20 | StringBuilder sb = new StringBuilder();
21 | sb.append(getLineSepartor());
22 | sb.append(getLineSepartor());
23 | return sb.toString();
24 | }
25 |
26 | public static float getScaleIndependentSize(Context context, int fontSize) {
27 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
28 | float val = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, fontSize, metrics);
29 | return val;
30 | }
31 |
32 | /**
33 | * Truncates the string provided if its length is more than the value provided, and replaces
34 | * the extra text by "…" ensuring that the resulting length of the string will be
35 | * as maximum as the param maximumLengthAllowed
36 | *
37 | * @param maximumLengthAllowed The maximum allowed length for the provided string
38 | * @param string The string that will be truncated if necessary
39 | * @return The original string if its length is less than maximumLengthAllowed,
40 | * or the string cropped and … appended at the end if it's length is more than maximumLengthAllowed
41 | */
42 | public static String truncateIfLengthMoreThan(final int maximumLengthAllowed, String string) {
43 | if (string.length() > maximumLengthAllowed) {
44 | return string.substring(0, maximumLengthAllowed - THREE_DOTS.length()).concat(THREE_DOTS);
45 | } else {
46 | return string;
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/ToastUtil.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by Richard Radics on 2015.02.12..
8 | */
9 | public class ToastUtil {
10 |
11 | /**
12 | * Display a toast with the given message (Length will be Toast.LENGTH_SHORT -- approx 2 sec).
13 | *
14 | * @param context The current Context or Activity that this method is called from
15 | * @param message Message to display
16 | * @return Toast object that is being displayed. Note,show() has already been called on this object.
17 | */
18 | public static Toast quickToast(Context context, String message) {
19 | return quickToast(context, message, false);
20 | }
21 |
22 | /**
23 | * Display a toast with the given message.
24 | *
25 | * @param context The current Context or Activity that this method is called from
26 | * @param message Message to display
27 | * @param longLength if true, will use Toast.LENGTH_LONG (approx 3.5 sec) instead of
28 | * @return Toast object that is being displayed. Note,show() has already been called on this object.
29 | */
30 | public static Toast quickToast(Context context, String message, boolean longLength) {
31 | final Toast toast;
32 | if (longLength) {
33 | toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
34 | } else {
35 | toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
36 | }
37 | toast.show();
38 | return toast;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/io/CloseableUtils.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util.io;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.Closeable;
6 | import java.io.IOException;
7 |
8 | /**
9 | * Utility for the {@link java.io.Closeable}.
10 | */
11 | @SuppressWarnings("unused") // public APIs
12 | public final class CloseableUtils {
13 | private static final String TAG = CloseableUtils.class.getSimpleName();
14 | private CloseableUtils() {}
15 |
16 | /**
17 | * Close closeable like i/o streams quietly.
18 | * Do NOT close {@link android.database.Cursor} with this method, or will cause crashing on some device.
19 | * @param closeable to close.
20 | */
21 | public static final void close(Closeable closeable) {
22 | if (closeable == null) {
23 | return;
24 | }
25 | try {
26 | closeable.close();
27 | } catch (IOException e) {
28 | Log.e(TAG, "something went wrong on close", e);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/util/io/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.util.io;
2 |
3 |
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileNotFoundException;
7 | import java.io.FileOutputStream;
8 | import java.io.IOException;
9 | import java.nio.channels.FileChannel;
10 |
11 |
12 | /**
13 | * Utility for the {@link java.io.File}.
14 | */
15 | @SuppressWarnings("unused") // public APIs
16 | public final class FileUtils {
17 | private FileUtils() {}
18 |
19 | /**
20 | * Create a new directory if not exists.
21 | * @param dir to create.
22 | * @return true if already exists, or newly created.
23 | */
24 | public static boolean makeDirsIfNeeded(File dir) {
25 | return dir.exists() || dir.mkdirs();
26 | }
27 |
28 | /**
29 | * Copy the file from the source to the destination.
30 | * @param source the source file to be copied.
31 | * @param destination the destination file to copy.
32 | * @see java.nio.channels.FileChannel#transferTo(long, long, java.nio.channels.WritableByteChannel).
33 | * @return the transferred byte count.
34 | * @throws FileNotFoundException
35 | * @throws IOException
36 | */
37 | public static long copy(File source, File destination) throws FileNotFoundException, IOException {
38 | FileInputStream in = null;
39 | FileOutputStream out = null;
40 | try {
41 | in = new FileInputStream(source);
42 | out = new FileOutputStream(destination);
43 | return copy(in, out);
44 | } finally {
45 | CloseableUtils.close(in);
46 | CloseableUtils.close(out);
47 | }
48 | }
49 |
50 | /**
51 | * Copy the file using streams.
52 | * @param in source.
53 | * @param out destination.
54 | * @see java.nio.channels.FileChannel#transferTo(long, long, java.nio.channels.WritableByteChannel)
55 | * @return the transferred byte count.
56 | * @throws IOException
57 | */
58 | public static long copy(FileInputStream in, FileOutputStream out) throws IOException {
59 | FileChannel source = null;
60 | FileChannel destination = null;
61 | try {
62 | source = in.getChannel();
63 | destination = out.getChannel();
64 | return source.transferTo(0, source.size(), destination);
65 | } finally {
66 | CloseableUtils.close(source);
67 | CloseableUtils.close(destination);
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/ExpandableHeightGridView.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.MotionEvent;
6 | import android.view.ViewGroup;
7 | import android.widget.GridView;
8 |
9 | /**
10 | * Created by Richard Radics on 2014.12.11..
11 | */
12 | public class ExpandableHeightGridView extends GridView
13 | {
14 |
15 | boolean expanded = false;
16 |
17 | public ExpandableHeightGridView(Context context)
18 | {
19 | super(context);
20 | }
21 |
22 | public ExpandableHeightGridView(Context context, AttributeSet attrs)
23 | {
24 | super(context, attrs);
25 | }
26 |
27 | public ExpandableHeightGridView(Context context, AttributeSet attrs,
28 | int defStyle)
29 | {
30 | super(context, attrs, defStyle);
31 | }
32 |
33 | public boolean isExpanded()
34 | {
35 | return expanded;
36 | }
37 |
38 | @Override
39 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
40 | {
41 | /* // HACK! TAKE THAT ANDROID!
42 | if (isExpanded())
43 | {
44 |
45 | // Calculate entire height by providing a very large height hint.
46 | // View.MEASURED_SIZE_MASK represents the largest height possible.
47 | int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
48 | MeasureSpec.AT_MOST);
49 | super.onMeasure(widthMeasureSpec, expandSpec);
50 |
51 | ViewGroup.LayoutParams params = getLayoutParams();
52 | params.height = getMeasuredHeight();
53 | }
54 | else
55 | {
56 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
57 | }*/
58 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
59 | }
60 |
61 | public void setExpanded(boolean expanded)
62 | {
63 | this.expanded = expanded;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/FixedHeightListView.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.widget.ArrayAdapter;
7 | import android.widget.LinearLayout;
8 |
9 | /**
10 | * Project: commons
11 | * Package: com.richardradics.commons.widget
12 | * Created by richardradics on 2015.02.24..
13 | */
14 | public class FixedHeightListView extends LinearLayout implements View.OnClickListener {
15 |
16 | private ArrayAdapter mList;
17 | private View.OnClickListener mListener;
18 | private View view;
19 |
20 | public FixedHeightListView(Context context) {
21 | super(context);
22 | }
23 |
24 | public FixedHeightListView(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | }
27 |
28 | public FixedHeightListView(Context context, AttributeSet attrs, int defStyle) {
29 | super(context, attrs, defStyle);
30 | }
31 |
32 | public void setAdapter(ArrayAdapter list) {
33 | this.mList = list;
34 | setOrientation(VERTICAL);
35 |
36 | if (mList != null) {
37 | for (int i = 0; i < mList.getCount(); i++) {
38 | view = mList.getView(i, null, null);
39 | this.addView(view);
40 | }
41 | }
42 | }
43 |
44 | public void setListener(View.OnClickListener listener) {
45 | this.mListener = listener;
46 | }
47 |
48 | @Override
49 | public void onClick(View v) {
50 | }
51 |
52 |
53 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/HackyViewPager.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget;
2 |
3 |
4 | import android.content.Context;
5 | import android.support.v4.view.ViewPager;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 |
9 | /**
10 | * Found at http://stackoverflow.com/questions/7814017/is-it-possible-to-disable-scrolling-on-a-viewpager.
11 | * Convenient way to temporarily disable ViewPager navigation while interacting with ImageView.
12 | *
13 | * Julia Zudikova
14 | */
15 |
16 | /**
17 | * Hacky fix for Issue #4 and
18 | * http://code.google.com/p/android/issues/detail?id=18990
19 | *
20 | * ScaleGestureDetector seems to mess up the touch events, which means that
21 | * ViewGroups which make use of onInterceptTouchEvent throw a lot of
22 | * IllegalArgumentException: pointerIndex out of range.
23 | *
24 | * There's not much I can do in my code for now, but we can mask the result by
25 | * just catching the problem and ignoring it.
26 | *
27 | * @author Chris Banes
28 | */
29 | public class HackyViewPager extends ViewPager {
30 |
31 | private boolean isLocked;
32 |
33 | public HackyViewPager(Context context) {
34 | super(context);
35 | isLocked = false;
36 | }
37 |
38 | public HackyViewPager(Context context, AttributeSet attrs) {
39 | super(context, attrs);
40 | isLocked = false;
41 | }
42 |
43 | @Override
44 | public boolean onInterceptTouchEvent(MotionEvent ev) {
45 | if (!isLocked) {
46 | try {
47 | return super.onInterceptTouchEvent(ev);
48 | } catch (IllegalArgumentException e) {
49 | e.printStackTrace();
50 | return false;
51 | }
52 | }
53 | return false;
54 | }
55 |
56 | @Override
57 | public boolean onTouchEvent(MotionEvent event) {
58 | if (!isLocked) {
59 | return super.onTouchEvent(event);
60 | }
61 | return false;
62 | }
63 |
64 | public void toggleLock() {
65 | isLocked = !isLocked;
66 | }
67 |
68 | public void setLocked(boolean isLocked) {
69 | this.isLocked = isLocked;
70 | }
71 |
72 | public boolean isLocked() {
73 | return isLocked;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/NonSwipeableViewPager.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 | import android.view.animation.DecelerateInterpolator;
8 | import android.widget.Scroller;
9 |
10 | import java.lang.reflect.Field;
11 |
12 | /**
13 | * Created by Richard Radics on 2015.02.11..
14 | */
15 | public class NonSwipeableViewPager extends ViewPager{
16 |
17 |
18 | private boolean enabled;
19 |
20 | public NonSwipeableViewPager(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | this.enabled = true;
23 | setMyScroller();
24 | }
25 |
26 | @Override
27 | public boolean onTouchEvent(MotionEvent event) {
28 | if (this.enabled) {
29 | return super.onTouchEvent(event);
30 | }
31 |
32 | return false;
33 | }
34 |
35 | private void setMyScroller() {
36 | try {
37 | Class> viewpager = ViewPager.class;
38 | Field scroller = viewpager.getDeclaredField("mScroller");
39 | scroller.setAccessible(true);
40 | scroller.set(this, new SmoothScroller(getContext()));
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | }
44 | }
45 |
46 | public class SmoothScroller extends Scroller {
47 | public SmoothScroller(Context context) {
48 | super(context, new DecelerateInterpolator());
49 | }
50 |
51 | @Override
52 | public void startScroll(int startX, int startY, int dx, int dy, int duration) {
53 | super.startScroll(startX, startY, dx, dy, 300 /* 05 secs */);
54 | }
55 | }
56 |
57 | @Override
58 | public boolean onInterceptTouchEvent(MotionEvent event) {
59 | if (this.enabled) {
60 | return super.onInterceptTouchEvent(event);
61 | }
62 |
63 | return false;
64 | }
65 |
66 | public void setPagingEnabled(boolean enabled) {
67 | this.enabled = enabled;
68 | }
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/ObservableScrollView.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 03. 17..
5 | */
6 |
7 | import android.content.Context;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.widget.ScrollView;
11 |
12 | public class ObservableScrollView extends ScrollView {
13 |
14 | private ScrollViewListener scrollViewListener = null;
15 |
16 | public ObservableScrollView(Context context) {
17 | super(context);
18 | }
19 |
20 | public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
21 | super(context, attrs, defStyle);
22 | }
23 |
24 | public ObservableScrollView(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | }
27 |
28 | public void setScrollViewListener(ScrollViewListener scrollViewListener) {
29 | this.scrollViewListener = scrollViewListener;
30 | }
31 |
32 |
33 | @Override
34 | public void fling(int velocityY) {
35 | super.fling(velocityY);
36 |
37 | }
38 |
39 | @Override
40 | protected void onScrollChanged(int x, int y, int oldx, int oldy) {
41 | super.onScrollChanged(x, y, oldx, oldy);
42 |
43 | if (y == 0) {
44 | if (scrollViewListener != null) {
45 | scrollViewListener.onScrollStartHitted();
46 | }
47 | }
48 |
49 | if (scrollViewListener != null) {
50 | scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
51 | }
52 |
53 |
54 | if (Math.abs(y - oldy) < 2 || y >= getMeasuredHeight() || y == 0) {
55 | if (scrollViewListener != null) {
56 | scrollViewListener.onScrollEnded();
57 | }
58 | }
59 |
60 |
61 | int dy = y - oldy;
62 | if (dy > 10) {
63 | if (scrollViewListener != null) {
64 | scrollViewListener.onScrollUp();
65 | }
66 | } else if (dy < -10) {
67 | if (scrollViewListener != null) {
68 | scrollViewListener.onScrollDown();
69 | }
70 | }
71 |
72 | View view = (View) this.getChildAt(this.getChildCount() - 1);
73 | int diff = (view.getBottom() - (this.getHeight() + this.getScrollY()));
74 |
75 | // if diff is zero, then the bottom has been reached
76 | if (diff == 0) {
77 | if (scrollViewListener != null) {
78 | scrollViewListener.onScrollBottomHitted();
79 | }
80 | }
81 |
82 | }
83 |
84 | public interface ScrollViewListener {
85 |
86 | void onScrollStartHitted();
87 |
88 | void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy);
89 |
90 | void onScrollBottomHitted();
91 |
92 | void onScrollUp();
93 |
94 | void onScrollDown();
95 |
96 | void onScrollEnded();
97 |
98 | }
99 |
100 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/echeckbox/EnhancedCheckbox.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.echeckbox;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.AttributeSet;
6 | import android.widget.CheckBox;
7 | import android.widget.CompoundButton;
8 |
9 | import com.richardradics.commons.util.ViewUtils;
10 |
11 | /**
12 | * An enhanced {@code CheckBox} that differentiates between user clicks and
13 | * programmatic clicks. In particular, the {@code OnCheckedChangeListener} is
14 | * not triggered when the state of the checkbox is changed
15 | * programmatically.
16 | *
17 | */
18 | public class EnhancedCheckbox extends CheckBox implements ProgrammaticallyCheckable{
19 | private CompoundButton.OnCheckedChangeListener mListener = null;
20 | public EnhancedCheckbox(Context context) {
21 | super(context);
22 | }
23 |
24 | public EnhancedCheckbox(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | }
27 |
28 | public EnhancedCheckbox(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | @Override
33 | public void setOnCheckedChangeListener(
34 | CompoundButton.OnCheckedChangeListener listener) {
35 | if (this.mListener == null) {this.mListener = listener;}
36 | super.setOnCheckedChangeListener(listener);
37 | }
38 | /**
39 | * Set the checked state of the checkbox programmatically. This is to differentiate it from a user click
40 | * @param checked Whether to check the checkbox
41 | */
42 | @Override
43 | public void setCheckedProgrammatically(boolean checked) {
44 | super.setOnCheckedChangeListener(null);
45 | super.setChecked(checked);
46 | super.setOnCheckedChangeListener(mListener);
47 | }
48 |
49 | @Override
50 | public int getCompoundPaddingLeft() {
51 | return ViewUtils.convertToPix(this.getResources().getDisplayMetrics().density, 20);
52 | }
53 |
54 |
55 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/echeckbox/EnhancedSwitch.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.echeckbox;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.util.AttributeSet;
7 | import android.widget.CompoundButton;
8 | import android.widget.Switch;
9 |
10 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
11 | public class EnhancedSwitch extends Switch implements ProgrammaticallyCheckable {
12 | private CompoundButton.OnCheckedChangeListener mListener = null;
13 |
14 | public EnhancedSwitch(Context context, AttributeSet attrs, int defStyle) {
15 | super(context, attrs, defStyle);
16 | }
17 |
18 | public EnhancedSwitch(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 | }
21 |
22 | public EnhancedSwitch(Context context) {
23 | super(context);
24 | }
25 |
26 | @Override
27 | public void setOnCheckedChangeListener(
28 | CompoundButton.OnCheckedChangeListener listener){
29 | if(this.mListener == null) {this.mListener = listener;}
30 | super.setOnCheckedChangeListener(listener);
31 | }
32 |
33 | @Override
34 | public void setCheckedProgrammatically(boolean checked){
35 | super.setOnCheckedChangeListener(null);
36 | super.setChecked(checked);
37 | super.setOnCheckedChangeListener(mListener);
38 | }
39 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/echeckbox/EnhancedToggleButton.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.echeckbox;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.CompoundButton;
6 | import android.widget.ToggleButton;
7 |
8 | public class EnhancedToggleButton extends ToggleButton implements ProgrammaticallyCheckable {
9 | private CompoundButton.OnCheckedChangeListener mListener = null;
10 | public EnhancedToggleButton(Context context, AttributeSet attrs, int defStyle) {
11 | super(context, attrs, defStyle);
12 | }
13 |
14 | public EnhancedToggleButton(Context context, AttributeSet attrs) {
15 | super(context, attrs);
16 | }
17 |
18 | public EnhancedToggleButton(Context context) {
19 | super(context);
20 | }
21 |
22 | @Override
23 | public void setOnCheckedChangeListener(
24 | CompoundButton.OnCheckedChangeListener listener){
25 | if(this.mListener == null) {this.mListener = listener;}
26 | super.setOnCheckedChangeListener(listener);
27 | }
28 |
29 | @Override
30 | public void setCheckedProgrammatically(boolean checked){
31 | super.setOnCheckedChangeListener(null);
32 | super.setChecked(checked);
33 | super.setOnCheckedChangeListener(mListener);
34 | }
35 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/echeckbox/OnSelectionListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.echeckbox;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 16..
5 | */
6 | public interface OnSelectionListener {
7 | void onSelectionChange(String value, boolean isChecked, boolean isParentCheckbox);
8 | }
9 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/echeckbox/ProgrammaticallyCheckable.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.echeckbox;
2 |
3 | /**
4 | * Interface for UI widgets (particularly, checkable widgets) whose checked state can be changed programmatically, without triggering the {@code OnCheckedChangeListener}
5 | *
6 | */
7 | public interface ProgrammaticallyCheckable {
8 | void setCheckedProgrammatically(boolean checked);
9 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/floatingwidgets/ChoicableItemPickerListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.floatingwidgets;
2 |
3 | /**
4 | * Created by Richard Radics on 2015.02.10..
5 | */
6 | public class ChoicableItemPickerListener {
7 |
8 |
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/floatingwidgets/Choiceable.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.floatingwidgets;
2 |
3 | import android.os.Parcelable;
4 |
5 | /**
6 | * Created by Richard Radics on 2015.02.10..
7 | */
8 | public interface Choiceable extends Parcelable {
9 |
10 | String getTitleText();
11 |
12 | Long getId();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/floatingwidgets/ChoiceableExpandPickerWidgetListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.floatingwidgets;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import com.richardradics.commons.animations.ExpandAnimation;
7 |
8 | /**
9 | * Created by Richard Radics on 2015.02.12..
10 | */
11 | public class ChoiceableExpandPickerWidgetListener implements FloatingLabelItemPickerWithSetSelectedItems.OnWidgetEventListener{
12 |
13 | private boolean isExpanded = false;
14 |
15 | private View viewToExpand;
16 |
17 | public ChoiceableExpandPickerWidgetListener(View viewToExpand){
18 | this.viewToExpand = viewToExpand;
19 | }
20 |
21 |
22 | @Override
23 | public void onShowItemPickerDialog(FloatingLabelItemPickerWithSetSelectedItems floatingLabelItemPicker) {
24 | if (!isExpanded) {
25 | floatingLabelItemPicker.floatLabel();
26 | ExpandAnimation.expand(viewToExpand);
27 | isExpanded = true;
28 | } else {
29 | if (((TextView) floatingLabelItemPicker.getInputWidget()).getText().toString().equals("")) {
30 | floatingLabelItemPicker.anchorLabel();
31 | }
32 | ExpandAnimation.collapse(viewToExpand);
33 | isExpanded = false;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/floatingwidgets/ChoiceableFloatPickerRippleClickListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.floatingwidgets;
2 |
3 | import android.view.View;
4 |
5 | import com.marvinlabs.widget.floatinglabel.FloatingLabelTextViewBase;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.12..
9 | */
10 | public class ChoiceableFloatPickerRippleClickListener implements View.OnClickListener {
11 |
12 | @Override
13 | public void onClick(View v) {
14 | (((FloatingLabelTextViewBase)v).getInputWidget()).performClick();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/floatingwidgets/ChoiceableItemPrinter.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.floatingwidgets;
2 |
3 | import com.marvinlabs.widget.floatinglabel.itempicker.ItemPrinter;
4 |
5 | import java.util.Collection;
6 |
7 | /**
8 | * Created by Richard Radics on 2015.02.10..
9 | */
10 | public class ChoiceableItemPrinter implements ItemPrinter {
11 |
12 |
13 | @Override
14 | public String print(Choiceable choiceable) {
15 | return choiceable.getTitleText() == null ? "" : choiceable.getTitleText();
16 | }
17 |
18 | @Override
19 | public String printCollection(Collection choiceables) {
20 | if (choiceables.size() == 0) return "";
21 |
22 | StringBuilder sb = new StringBuilder();
23 | boolean prependSeparator = false;
24 | for (Choiceable item : choiceables) {
25 | if (prependSeparator) {
26 | sb.append(", ");
27 | } else {
28 | prependSeparator = true;
29 | }
30 |
31 | sb.append(print(item));
32 | }
33 |
34 | return sb.toString();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/kenburnsview/IncompatibleRatioException.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.kenburnsview;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 24..
5 | */
6 | public class IncompatibleRatioException extends RuntimeException {
7 |
8 | public IncompatibleRatioException() {
9 | super("Can't perform Ken Burns effect on rects with distinct aspect ratios!");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/kenburnsview/MathUtils.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.kenburnsview;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 24..
5 | */
6 |
7 | import android.graphics.RectF;
8 |
9 | /**
10 | * Helper class to perform math computations.
11 | */
12 | public final class MathUtils {
13 |
14 | /**
15 | * Truncates a float number {@code f} to {@code decimalPlaces}.
16 | * @param f the number to be truncated.
17 | * @param decimalPlaces the amount of decimals that {@code f}
18 | * will be truncated to.
19 | * @return a truncated representation of {@code f}.
20 | */
21 | protected static float truncate(float f, int decimalPlaces) {
22 | float decimalShift = (float) Math.pow(10, decimalPlaces);
23 | return Math.round(f * decimalShift) / decimalShift;
24 | }
25 |
26 |
27 | /**
28 | * Checks whether two {@link RectF} have the same aspect ratio.
29 | * @param r1 the first rect.
30 | * @param r2 the second rect.
31 | * @return {@code true} if both rectangles have the same aspect ratio,
32 | * {@code false} otherwise.
33 | */
34 | protected static boolean haveSameAspectRatio(RectF r1, RectF r2) {
35 | // Reduces precision to avoid problems when comparing aspect ratios.
36 | float srcRectRatio = MathUtils.truncate(MathUtils.getRectRatio(r1), 2);
37 | float dstRectRatio = MathUtils.truncate(MathUtils.getRectRatio(r2), 2);
38 |
39 | // Compares aspect ratios that allows for a tolerance range of [0, 0.01]
40 | return (Math.abs(srcRectRatio-dstRectRatio) <= 0.01f);
41 | }
42 |
43 |
44 | /**
45 | * Computes the aspect ratio of a given rect.
46 | * @param rect the rect to have its aspect ratio computed.
47 | * @return the rect aspect ratio.
48 | */
49 | protected static float getRectRatio(RectF rect) {
50 | return rect.width() / rect.height();
51 | }
52 | }
--------------------------------------------------------------------------------
/commons/src/main/java/com/richardradics/commons/widget/kenburnsview/TransitionGenerator.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.commons.widget.kenburnsview;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 24..
5 | */
6 | import android.graphics.RectF;
7 |
8 | public interface TransitionGenerator {
9 |
10 | /**
11 | * Generates the next transition to be played by the {@link KenBurnsView}.
12 | * @param drawableBounds the bounds of the drawable to be shown in the {@link KenBurnsView}.
13 | * @param viewport the rect that represents the viewport where
14 | * the transition will be played in. This is usually the bounds of the
15 | * {@link KenBurnsView}.
16 | * @return a {@link Transition} object to be played by the {@link KenBurnsView}.
17 | */
18 | public Transition generateNextTransition(RectF drawableBounds, RectF viewport);
19 |
20 | }
--------------------------------------------------------------------------------
/commons/src/main/res/anim/alpha_1000.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/alpha_3000.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/appear_bottom_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/appear_bottom_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/appear_top_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/appear_top_left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/disappear_bottom_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/disappear_bottom_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/disappear_top_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/disappear_top_left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/flip_horizontal_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/flip_horizontal_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/flip_vertical_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/flip_vertical_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/pull_in_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/pull_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/push_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/push_out_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/slide_in_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/slide_in_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/slide_out_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/slide_out_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/stay.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/swap_in_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/swap_out_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
19 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/translate_1000.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/translate_2000.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/unzoom_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/commons/src/main/res/anim/unzoom_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_off.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_off_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_off_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_off_disable_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_off_disable_focused.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_off_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_off_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_off_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_off_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_on.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_on_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_on_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_on_disable_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_on_disable_focused.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_on_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_on_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/btn_check_on_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/btn_check_on_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_off.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_off_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_off_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_off_disable_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_off_disable_focused.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_off_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_off_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_off_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_off_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_on.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_on_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_on_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_on_disable_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_on_disable_focused.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_on_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_on_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/btn_check_on_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/btn_check_on_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_off.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_off_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_off_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_off_disable_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_off_disable_focused.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_off_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_off_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_off_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_off_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_on.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_on_disable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_on_disable.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_on_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_on_pressed.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/btn_check_on_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/btn_check_on_selected.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xxhdpi/ic_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xxhdpi/ic_error.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable-xxhdpi/ic_navigation_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/commons/src/main/res/drawable-xxhdpi/ic_navigation_check.png
--------------------------------------------------------------------------------
/commons/src/main/res/drawable/btn_check.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
27 |
28 |
31 |
34 |
35 |
38 |
41 |
42 |
45 |
48 |
49 |
50 |
51 |
52 |
54 |
56 |
57 |
59 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/commons/src/main/res/layout/default_divider.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/commons/src/main/res/layout/grouped_checkbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
25 |
26 |
37 |
38 |
--------------------------------------------------------------------------------
/commons/src/main/res/layout/grouped_checkbox_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
20 |
21 |
26 |
27 |
28 |
29 |
33 |
34 |
--------------------------------------------------------------------------------
/commons/src/main/res/layout/labeled_textview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
--------------------------------------------------------------------------------
/commons/src/main/res/layout/list_item_cb_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/commons/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #7c4dff
4 | #3CCD88
5 | #f44336
6 |
--------------------------------------------------------------------------------
/commons/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - 0.6
4 | - 6
5 |
--------------------------------------------------------------------------------
/commons/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | pont commons
3 |
4 | Igen
5 | Nem
6 |
7 | pont commons
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/commons/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
15 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/core/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 | *.jar
5 | !gradle/wrapper/gradle-wrapper.jar
6 | lint
7 | *.dex
8 | *.class
9 | # generated files
10 | bin/
11 | gen/
12 | classes/
13 | gen-external-apklibs/
14 | target
15 | local.properties
16 | .idea/workspace.xml
17 | .idea/tasks.xml
18 | .idea/datasources.xml
19 | .idea/dataSources.ids
20 | .DS_Store
21 | *.swp
22 | *.bak
23 | .gradle
24 | build/
25 | .idea/libraries
26 | *.iml
27 | *.idea
--------------------------------------------------------------------------------
/core/build.workaround-missing-resource.gradle:
--------------------------------------------------------------------------------
1 | // Workaround for missing test resources when run unit tests within android studio.
2 | // This copy the test resources next to the test classes for each variant.
3 | // Tracked at https://github.com/nenick/AndroidStudioAndRobolectric/issues/7
4 | // Original solution comes from https://code.google.com/p/android/issues/detail?id=136013#c10
5 |
6 | gradle.projectsEvaluated {
7 | // Base path which is recognized by android studio.
8 | def testClassesPath = "${buildDir}/intermediates/classes/test/"
9 | // Copy must be done for each variant.
10 | def variants = android.libraryVariants.collect()
11 |
12 | variants.each { variant ->
13 | def variationName = variant.name.capitalize()
14 |
15 | // Get the flavor and also merge flavor groups.
16 | def productFlavorNames = variant.productFlavors.collect { it.name.capitalize() }
17 | if (productFlavorNames.isEmpty()) {
18 | productFlavorNames = [""]
19 | }
20 | productFlavorNames = productFlavorNames.join('')
21 |
22 | // Base path addition for this specific variant.
23 | def variationPath = variant.buildType.name;
24 | if (productFlavorNames != null && !productFlavorNames.isEmpty()) {
25 | variationPath = uncapitalize(productFlavorNames) + "/${variationPath}"
26 | }
27 |
28 | // Specific copy task for each variant
29 | def copyTestResourcesTask = project.tasks.create("copyTest${variationName}Resources", Copy)
30 | copyTestResourcesTask.from("${projectDir}/src/test/resources")
31 | copyTestResourcesTask.into("${testClassesPath}/${variationPath}")
32 | copyTestResourcesTask.execute()
33 | }
34 | }
35 |
36 | def uncapitalize(String str) {
37 | int strLen;
38 | if (str == null || (strLen = str.length()) == 0) {
39 | return str;
40 | }
41 | return new StringBuffer(strLen)
42 | .append(Character.toLowerCase(str.charAt(0)))
43 | .append(str.substring(1))
44 | .toString();
45 | }
--------------------------------------------------------------------------------
/core/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/radicsrichard/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/app/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.app;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.util.Log;
7 |
8 | import com.richardradics.commons.util.ErrorUtil;
9 | import com.richardradics.core.error.NetworkErrorHandler;
10 | import com.richardradics.core.navigation.Navigator;
11 | import com.richardradics.core.retrofit.NoConnectivityListener;
12 | import com.richardradics.core.util.CommonUseCases;
13 | import com.richardradics.core.util.LoadAndToast;
14 |
15 |
16 | import org.androidannotations.annotations.Bean;
17 | import org.androidannotations.annotations.EActivity;
18 |
19 | /**
20 | * Created by radicsrichard on 15. 04. 28..
21 | */
22 | @EActivity
23 | public abstract class BaseActivity extends ActionBarActivity implements NoConnectivityListener {
24 |
25 | @Bean
26 | protected Navigator navigator;
27 |
28 | @Bean
29 | protected CommonUseCases commonUseCases;
30 |
31 | @Bean
32 | protected NetworkErrorHandler networkErrorHandler;
33 |
34 | @Bean
35 | protected LoadAndToast progress;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
41 | @Override
42 | public void uncaughtException(Thread thread, Throwable e) {
43 | handleUncaughtException(thread, e);
44 | }
45 | });
46 | }
47 |
48 | protected void handleUncaughtException(Thread thread, Throwable e) {
49 | Log.d("Report :: ", ErrorUtil.getErrorReport(e));
50 |
51 | String cause = ErrorUtil.getCause(e);
52 | String errorType = ErrorUtil.getExceptionType(e);
53 | String stackTrace = ErrorUtil.getStrackTrace(e);
54 | String deviceInfo = ErrorUtil.getDeviceInfo();
55 |
56 | Intent i = new Intent(getApplicationContext(), ErrorActivity.class);
57 | i.putExtra(ErrorActivity.EXCEPTION_TYPE_ARG, errorType);
58 | i.putExtra(ErrorActivity.STACKTRACE_ARG, stackTrace);
59 | i.putExtra(ErrorActivity.DEVICE_INFO_ARG, deviceInfo);
60 | i.putExtra(ErrorActivity.CAUSE_ARG, cause);
61 |
62 | i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
63 | i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
64 | startActivity(i);
65 |
66 |
67 | System.exit(0);
68 | }
69 |
70 |
71 | @Override
72 | protected void onResume() {
73 | super.onResume();
74 | navigator.setCurrentActivityOnScreen(this);
75 | }
76 |
77 | @Override
78 | protected void onPause() {
79 | super.onPause();
80 | navigator.setCurrentActivityOnScreen(null);
81 | }
82 |
83 | @Override
84 | public void onNoConnectivityError(){
85 | progress.endLoading(false);
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/app/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.app;
2 |
3 | import android.app.Application;
4 |
5 | import com.richardradics.core.error.NetworkErrorHandler;
6 | import com.richardradics.core.error.SnappyErrorHandler;
7 |
8 | import org.androidannotations.annotations.Bean;
9 | import org.androidannotations.annotations.EApplication;
10 |
11 | /**
12 | * Created by radicsrichard on 15. 04. 28..
13 | */
14 | @EApplication
15 | public class BaseApplication extends Application {
16 |
17 | @Bean
18 | protected NetworkErrorHandler networkErrorHandler;
19 |
20 | @Bean
21 | protected SnappyErrorHandler snappyErrorHandler;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/app/ErrorActivity.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.app;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.richardradics.core.R;
11 |
12 | /**
13 | * Created by radicsrichard on 15. 04. 28..
14 | */
15 | public class ErrorActivity extends ActionBarActivity {
16 |
17 | public final static String STACKTRACE_ARG = "strack-arg";
18 | public final static String EXCEPTION_TYPE_ARG = "extype-arg";
19 | public final static String CAUSE_ARG = "cause-arg";
20 | public final static String DEVICE_INFO_ARG = "devinf-arg";
21 |
22 | TextView errorStactTraceTextView;
23 | Button errorConfirmButton;
24 | TextView errorDeviceInfoTextView;
25 | TextView errorCauseTextView;
26 | TextView errorExceptionTypeTextView;
27 |
28 |
29 | @Override
30 | public void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 |
33 |
34 | setContentView(R.layout.activity_error);
35 |
36 | errorStactTraceTextView = (TextView) findViewById(R.id.errorStactTraceTextView);
37 | errorConfirmButton = (Button) findViewById(R.id.errorConfirmButton);
38 | errorDeviceInfoTextView = (TextView) findViewById(R.id.errorDeviceInfoTextView);
39 | errorCauseTextView = (TextView) findViewById(R.id.errorCauseTextView);
40 | errorExceptionTypeTextView = (TextView) findViewById(R.id.errorExceptionTypeTextView);
41 |
42 | onAfterViewFInish();
43 | }
44 |
45 |
46 | private void onAfterViewFInish() {
47 | if (getIntent().hasExtra(CAUSE_ARG)) {
48 | errorCauseTextView.setText(getIntent().getStringExtra(CAUSE_ARG));
49 | }
50 |
51 | if (getIntent().hasExtra(DEVICE_INFO_ARG)) {
52 | errorDeviceInfoTextView.setText(getIntent().getStringExtra(DEVICE_INFO_ARG));
53 | }
54 |
55 | if (getIntent().hasExtra(EXCEPTION_TYPE_ARG)) {
56 | errorExceptionTypeTextView.setText(getIntent().getStringExtra(EXCEPTION_TYPE_ARG));
57 | }
58 |
59 | if (getIntent().hasExtra(STACKTRACE_ARG)) {
60 | errorStactTraceTextView.setText(getIntent().getStringExtra(STACKTRACE_ARG));
61 | }
62 |
63 | errorConfirmButton.setOnClickListener(new View.OnClickListener() {
64 | @Override
65 | public void onClick(View v) {
66 | Intent intent = new Intent(Intent.ACTION_MAIN);
67 | intent.addCategory(Intent.CATEGORY_HOME);
68 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
69 | startActivity(intent);
70 | }
71 | });
72 | }
73 |
74 | @Override
75 | public void setContentView(int layoutResID) {
76 | super.setContentView(R.layout.activity_error);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/error/ErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.error;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.nispok.snackbar.Snackbar;
7 | import com.nispok.snackbar.SnackbarManager;
8 | import com.richardradics.commons.util.ErrorUtil;
9 | import com.richardradics.core.navigation.Navigator;
10 |
11 | import org.androidannotations.annotations.Bean;
12 | import org.androidannotations.annotations.EBean;
13 | import org.androidannotations.annotations.RootContext;
14 | import org.androidannotations.annotations.UiThread;
15 |
16 | /**
17 | * Created by radicsrichard on 15. 04. 28..
18 | */
19 | @EBean
20 | public class ErrorHandler {
21 |
22 | @RootContext
23 | protected Context context;
24 |
25 | @Bean
26 | protected Navigator navigator;
27 |
28 | protected Integer snackBarBackgroundColor;
29 |
30 | public Integer getSnackBarBackgroundColor() {
31 | return snackBarBackgroundColor;
32 | }
33 |
34 | public void setSnackBarBackgroundColor(Integer snackBarBackgroundColor) {
35 | this.snackBarBackgroundColor = snackBarBackgroundColor;
36 | }
37 |
38 | public void handlerError(Exception e) {
39 | logError(e);
40 | }
41 |
42 | @UiThread
43 | protected void showError(String s) {
44 | if (navigator.isInForeground()) {
45 | Snackbar errorSnack;
46 | if (snackBarBackgroundColor != null) {
47 | errorSnack = Snackbar.with(context)
48 | .text(s)
49 | .duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
50 | .color(snackBarBackgroundColor);
51 | } else {
52 | errorSnack = Snackbar.with(context)
53 | .text(s)
54 | .duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
55 | }
56 |
57 | SnackbarManager.show(errorSnack, navigator.getCurrentActivityOnScreen());
58 | }
59 | }
60 |
61 | protected void logError(Throwable e) {
62 | String report = ErrorUtil.getErrorReport(e);
63 | Log.e("ErrorHandler Report:", report);
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/error/NetworkErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.error;
2 |
3 | import com.richardradics.core.retrofit.NoConnectivityException;
4 |
5 | import org.androidannotations.annotations.EBean;
6 |
7 | /**
8 | * Created by radicsrichard on 15. 04. 28..
9 | */
10 | @EBean(scope = EBean.Scope.Singleton)
11 | public class NetworkErrorHandler extends ErrorHandler {
12 |
13 | @Override
14 | public void handlerError(Exception e) {
15 | super.handlerError(e);
16 | String s = "Hiba történt!";
17 | if (e instanceof NoConnectivityException) {
18 | s = "Nincs internet!";
19 | showError(s);
20 | }
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/error/SnappyErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.error;
2 |
3 | import org.androidannotations.annotations.EBean;
4 |
5 | /**
6 | * Created by radicsrichard on 15. 04. 29..
7 | */
8 | @EBean(scope = EBean.Scope.Singleton)
9 | public class SnappyErrorHandler extends ErrorHandler {
10 |
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/mvp/Presenter.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.mvp;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 28..
5 | */
6 | public interface Presenter {
7 |
8 | public void setView(View view);
9 | public void start();
10 | public void stop();
11 | public void onError(Exception exception);
12 | }
13 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/mvp/View.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.mvp;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 04. 28..
5 | */
6 | public interface View {
7 | void showLoading (String message);
8 | void hideLoading (boolean sucess);
9 | void showActionLabel(String message);
10 | void hideActionLabel ();
11 | }
12 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/navigation/Navigator.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.navigation;
2 |
3 | import android.content.Context;
4 |
5 | import com.richardradics.core.app.BaseActivity;
6 |
7 | import org.androidannotations.annotations.EBean;
8 | import org.androidannotations.annotations.RootContext;
9 |
10 |
11 | /**
12 | * Created by radicsrichard on 15. 03. 28..
13 | */
14 | @EBean(scope = EBean.Scope.Singleton)
15 | public class Navigator {
16 |
17 | @RootContext
18 | Context context;
19 |
20 |
21 | private BaseActivity currentActivityOnScreen;
22 |
23 |
24 | public BaseActivity getCurrentActivityOnScreen() {
25 | return currentActivityOnScreen;
26 | }
27 |
28 | public void setCurrentActivityOnScreen(BaseActivity currentActivityOnScreen) {
29 | this.currentActivityOnScreen = currentActivityOnScreen;
30 | }
31 |
32 | public static void navigateUp(BaseActivity activity) {
33 | activity.finish();
34 | }
35 |
36 | public boolean isInForeground(){
37 | if(currentActivityOnScreen != null){
38 | return Boolean.TRUE;
39 | }else{
40 | return Boolean.FALSE;
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/retrofit/BaseRetrofitClient.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.retrofit;
2 |
3 | import com.richardradics.core.error.NetworkErrorHandler;
4 | import com.richardradics.core.navigation.Navigator;
5 | import com.squareup.okhttp.OkHttpClient;
6 |
7 | import org.androidannotations.annotations.Bean;
8 | import org.androidannotations.annotations.EBean;
9 |
10 | import java.net.CookieHandler;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import retrofit.RestAdapter;
14 | import retrofit.client.OkClient;
15 |
16 | /**
17 | * Created by radicsrichard on 15. 04. 28..
18 | */
19 | @EBean
20 | public class BaseRetrofitClient {
21 |
22 | @Bean
23 | protected Navigator navigator;
24 |
25 |
26 | protected static OkHttpClient okHttpClient;
27 |
28 | @Bean
29 | protected BaseRetryHandler defaultRetryHandler;
30 |
31 | @Bean
32 | protected ConnectivityAwareUrlClient connectivityAwareUrlClient;
33 |
34 | @Bean
35 | protected NetworkErrorHandler networkErrorHandler;
36 |
37 | public T initRestAdapter(String ENDPOINT, Class restInterface, BaseRetryHandler baseRetryHandler) {
38 | okHttpClient = new OkHttpClient();
39 | okHttpClient.setCookieHandler(CookieHandler.getDefault());
40 | okHttpClient.setConnectTimeout(10, TimeUnit.MINUTES);
41 | connectivityAwareUrlClient.setWrappedClient(new OkClient(okHttpClient));
42 | connectivityAwareUrlClient.setRetryHandler(baseRetryHandler);
43 |
44 | RestAdapter restAdapter = new RestAdapter.Builder()
45 | .setEndpoint(ENDPOINT)
46 | .setClient(connectivityAwareUrlClient)
47 | // .setLogLevel(RestAdapter.LogLevel.FULL)
48 | .build();
49 | return restAdapter.create(restInterface);
50 | }
51 |
52 | public T initRestAdapter(String ENDPOINT, Class restInterface) {
53 | return initRestAdapter(ENDPOINT, restInterface, defaultRetryHandler);
54 | }
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/retrofit/BaseRetryHandler.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.retrofit;
2 |
3 | import com.richardradics.core.error.NetworkErrorHandler;
4 | import com.richardradics.core.navigation.Navigator;
5 |
6 | import org.androidannotations.annotations.Bean;
7 | import org.androidannotations.annotations.EBean;
8 |
9 | import hugo.weaving.DebugLog;
10 |
11 | /**
12 | * Created by radicsrichard on 15. 05. 16..
13 | */
14 | @EBean
15 | public class BaseRetryHandler {
16 |
17 | @Bean
18 | protected NetworkErrorHandler networkErrorHandler;
19 |
20 | @Bean
21 | protected Navigator navigator;
22 |
23 | public int DEFAULT_RETRY_COUNT = 2;
24 | public int RETRY_401_UNAUTHORIZED = 3;
25 | public int RETRY_400_BADREQUEST = 3;
26 | public int RETRY_403_FORBIDDEN = 3;
27 | public int RETRY_404_NOTFOUND = 3;
28 | public int RETRY_500_ISE = 3;
29 |
30 |
31 | @DebugLog
32 | public void on500() {
33 |
34 | }
35 |
36 | @DebugLog
37 | public void on401() {
38 |
39 | }
40 |
41 | @DebugLog
42 | public void on400() {
43 |
44 | }
45 |
46 |
47 | @DebugLog
48 | public void on404() {
49 |
50 | }
51 |
52 | @DebugLog
53 | public void on403() {
54 |
55 | }
56 |
57 | public void onNoInternet() {
58 | if (navigator.isInForeground()) {
59 | navigator.getCurrentActivityOnScreen().onNoConnectivityError();
60 | }
61 | networkErrorHandler.handlerError(new NoConnectivityException("Nincs internet!"));
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/retrofit/ConnectionError.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.retrofit;
2 |
3 | /**
4 | * Created by radicsrichard on 15. 05. 16..
5 | */
6 | public class ConnectionError extends RuntimeException {
7 | }
8 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/retrofit/NoConnectivityException.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.retrofit;
2 |
3 | /**
4 | * Created by mark on 2015. 03. 30..
5 | */
6 | public class NoConnectivityException extends RuntimeException {
7 |
8 | protected String reason;
9 |
10 |
11 | public NoConnectivityException(String message){
12 | super(message);
13 | this.reason = message;
14 | }
15 |
16 | @Override
17 | public String getMessage() {
18 | return reason;
19 | }
20 |
21 | public String getReason() {
22 | return reason;
23 | }
24 |
25 | public void setReason(String reason) {
26 | this.reason = reason;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/retrofit/NoConnectivityListener.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.retrofit;
2 |
3 | /**
4 | * Created by mark on 2015. 04. 29..
5 | */
6 | public interface NoConnectivityListener {
7 | public void onNoConnectivityError();
8 | }
9 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/ui/AnimatorAdapter.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.ui;
2 |
3 |
4 | import android.animation.Animator;
5 |
6 | public class AnimatorAdapter implements Animator.AnimatorListener {
7 |
8 | @Override
9 | public void onAnimationStart(Animator animation) {
10 |
11 | }
12 |
13 | @Override
14 | public void onAnimationEnd(Animator animation) {
15 |
16 | }
17 |
18 | @Override
19 | public void onAnimationCancel(Animator animation) {
20 |
21 | }
22 |
23 | @Override
24 | public void onAnimationRepeat(Animator animation) {
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/ui/TransitionAdapter.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.ui;
2 |
3 | import android.transition.Transition;
4 |
5 |
6 | public class TransitionAdapter implements Transition.TransitionListener {
7 |
8 | @Override
9 | public void onTransitionStart(Transition transition) {
10 |
11 | }
12 |
13 | @Override
14 | public void onTransitionEnd(Transition transition) {
15 |
16 | }
17 |
18 | @Override
19 | public void onTransitionCancel(Transition transition) {
20 |
21 | }
22 |
23 | @Override
24 | public void onTransitionPause(Transition transition) {
25 |
26 | }
27 |
28 | @Override
29 | public void onTransitionResume(Transition transition) {
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/core/src/main/java/com/richardradics/core/util/LoadAndToast.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.util;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Context;
6 |
7 | import com.nispok.snackbar.Snackbar;
8 | import com.nispok.snackbar.SnackbarManager;
9 | import com.richardradics.commons.util.DensityUtil;
10 | import com.richardradics.commons.widget.loadtoast.LoadToast;
11 | import com.richardradics.core.navigation.Navigator;
12 |
13 |
14 | import org.androidannotations.annotations.AfterInject;
15 | import org.androidannotations.annotations.Bean;
16 | import org.androidannotations.annotations.EBean;
17 | import org.androidannotations.annotations.RootContext;
18 |
19 | /**
20 | * Created by mark on 2015. 04. 29..
21 | */
22 | @EBean(scope = EBean.Scope.Singleton)
23 | public class LoadAndToast {
24 | @RootContext
25 | Context context;
26 |
27 | @Bean
28 | CommonUseCases commonUseCases;
29 |
30 | LoadToast loadToast;
31 | Snackbar loadingSnackBar;
32 |
33 |
34 | protected void init(Context context) {
35 | if (context != null) {
36 | loadToast = new LoadToast(context);
37 | setupLoadToast();
38 | loadingSnackBar = Snackbar.with(context);
39 | setupSnackBar();
40 | }
41 | }
42 |
43 | protected void setupLoadToast() {
44 | if (loadToast != null) {
45 | loadToast.setTranslationY((commonUseCases.getScreenSize().y-commonUseCases.getNavigationBarHeight() - commonUseCases.getScreenSize().y / 5)-5);
46 | // loadToast.setTranslationY(Float.floatToIntBits(DensityUtil.convertPixelsToDp(commonUseCases.getScreenSize().y,context) - DensityUtil.convertPixelsToDp(commonUseCases.getScreenSize().y/7,context)));
47 | }
48 | }
49 |
50 | protected void setupSnackBar() {
51 | if (loadingSnackBar != null) {
52 | loadingSnackBar.duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
53 | }
54 | }
55 |
56 | public void showLoading(Context context, String message) {
57 | if (loadingSnackBar == null)
58 | init(context);
59 | loadToast.setText(message);
60 | loadToast.show();
61 | }
62 |
63 | public void endLoading(boolean success) {
64 | if (loadToast != null)
65 | if (success)
66 | loadToast.success();
67 | else
68 | loadToast.error();
69 | }
70 |
71 |
72 | public void showMessage(Context context, String message) {
73 | if (loadToast == null)
74 | init(context);
75 |
76 | loadingSnackBar.text(message);
77 | SnackbarManager.show(loadingSnackBar);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/core/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | core
3 | Device Info
4 | Exception Type
5 | Cause
6 | Stacktrace
7 | Close
8 |
9 |
--------------------------------------------------------------------------------
/core/src/test/java/com/richardradics/core/app/TestBaseApplication_.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.app;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by radicsrichard on 15. 05. 15..
7 | */
8 | public class TestBaseApplication_ extends Application {
9 | }
10 |
--------------------------------------------------------------------------------
/core/src/test/java/com/richardradics/core/util/CoreRobolectricRunner.java:
--------------------------------------------------------------------------------
1 | package com.richardradics.core.util;
2 |
3 |
4 | import org.junit.runners.model.InitializationError;
5 | import org.robolectric.RobolectricGradleTestRunner;
6 | import org.robolectric.annotation.Config;
7 | import org.robolectric.manifest.AndroidManifest;
8 | import org.robolectric.res.FileFsFile;
9 | import org.robolectric.res.FsFile;
10 |
11 | /**
12 | * Created by radicsrichard on 15. 05. 15..
13 | */
14 | public class CoreRobolectricRunner extends RobolectricGradleTestRunner {
15 |
16 | public CoreRobolectricRunner(Class> testClass) throws InitializationError {
17 | super(testClass);
18 |
19 | }
20 | protected AndroidManifest getAppManifest(Config config) {
21 | AndroidManifest appManifest = super.getAppManifest(config);
22 | FsFile androidManifestFile = appManifest.getAndroidManifestFile();
23 |
24 | // Workaround also wrong paths for res and assets.
25 | // This will be fixed with next robolectric release https://github.com/robolectric/robolectric/issues/1709
26 | if (androidManifestFile.exists()) {
27 | FsFile resDirectory = FileFsFile.from(appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "res"));
28 | FsFile assetsDirectory = FileFsFile.from(appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "assets"));
29 | return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
30 | } else {
31 | String moduleRoot = getModuleRootPath(config);
32 | androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath());
33 | FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "res"));
34 | FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "assets"));
35 | return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
36 | }
37 | }
38 |
39 | private String getModuleRootPath(Config config) {
40 | String moduleRoot = config.constants().getResource("").toString().replace("file:", "").replace("jar:", "");
41 | return moduleRoot.substring(0, moduleRoot.indexOf("/build"));
42 | }
43 | }
44 |
45 |
46 |
--------------------------------------------------------------------------------
/core/src/test/resources/robolectric.properties:
--------------------------------------------------------------------------------
1 | constants=com.richardradics.core.BuildConfig
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/image.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardradics/MVPAndroidBootstrap/6fbd06c7917713714350edf936d62e3cadb1e7e9/image.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':core', ':commons'
2 |
--------------------------------------------------------------------------------