Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / Tools.java
index 02c8d7ac80a16eed56af9e19263ba7bdfaa9e524..6b6cd03ed1d1ccf5d037aec918848f6fe56585f8 100644 (file)
@@ -1,7 +1,28 @@
+/* Tools.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
 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 +72,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);
+    }
+
 }