Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / Tools.java
index 168446e9e96363da36f36acd0a2c13e299595266..6b6cd03ed1d1ccf5d037aec918848f6fe56585f8 100644 (file)
@@ -1,3 +1,18 @@
+/* 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;
@@ -6,6 +21,8 @@ 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;
@@ -70,4 +87,29 @@ public class Tools {
         }
     }
 
+    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);
+    }
+
 }