alpha 0.0.2
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / Tools.java
index 02c8d7ac80a16eed56af9e19263ba7bdfaa9e524..5829802fc08f71fee4ba165a815c2e9fa143c182 100644 (file)
@@ -1,7 +1,13 @@
 package de.dhbwloe.campusapp;
 
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.Calendar;
+import java.util.Date;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
@@ -51,4 +57,44 @@ public class Tools {
         return decrypted;
     }
 
+    public static void removeAllChildViews(ViewGroup viewGroup) {
+        for (int i = 0; i < viewGroup.getChildCount(); i++) {
+            View child = viewGroup.getChildAt(i);
+            if (child instanceof ViewGroup) {
+                if (child instanceof AdapterView) {
+                    viewGroup.removeView(child);
+                    return;
+                }
+                removeAllChildViews(((ViewGroup) child));
+            } else {
+                viewGroup.removeView(child);
+            }
+        }
+    }
+
+    public static String getWeekdayString(long date) {
+        return getWeekdayString(date, true);
+    }
+
+    public static String getWeekdayString(long date, boolean fullString) {
+        return getWeekdayString(new Date(date * 1000), fullString);
+    }
+
+    public static String getWeekdayString(Date date) {
+        return getWeekdayString(date, true);
+    }
+
+    public static String getWeekdayString(Date date, boolean fullString) {
+        int weekdayResIds[];
+        if(fullString)
+            weekdayResIds = new int[] { R.string.week_sunday, R.string.week_monday, R.string.week_tuesday, R.string.week_wednesday, R.string.week_thursday, R.string.week_friday, R.string.week_saturday };
+        else
+            weekdayResIds = new int[] { R.string.week_sunday_short, R.string.week_monday_short, R.string.week_tuesday_short, R.string.week_wednesday_short, R.string.week_thursday_short, R.string.week_friday_short, R.string.week_saturday_short };
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        int dow = cal.get(Calendar.DAY_OF_WEEK);
+        int weekdayResId = weekdayResIds[dow-1];
+        return CampusAppContext.getInstance().getResString(weekdayResId);
+    }
+
 }