1 package de.dhbwloe.campusapp;
3 import android.view.View;
4 import android.view.ViewGroup;
5 import android.widget.AdapterView;
7 import java.security.MessageDigest;
8 import java.security.NoSuchAlgorithmException;
9 import java.util.Calendar;
10 import java.util.Date;
12 import javax.crypto.Cipher;
13 import javax.crypto.spec.SecretKeySpec;
16 * Created by pk910 on 25.01.2016.
20 public static final String md5(final String s) {
21 final String MD5 = "MD5";
24 MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
25 digest.update(s.getBytes());
26 byte messageDigest[] = digest.digest();
29 StringBuilder hexString = new StringBuilder();
30 for (byte aMessageDigest : messageDigest) {
31 String h = Integer.toHexString(0xFF & aMessageDigest);
32 while (h.length() < 2)
36 return hexString.toString();
38 } catch (NoSuchAlgorithmException e) {
44 public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
45 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
46 Cipher cipher = Cipher.getInstance("AES");
47 cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
48 byte[] encrypted = cipher.doFinal(clear);
52 public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
53 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
54 Cipher cipher = Cipher.getInstance("AES");
55 cipher.init(Cipher.DECRYPT_MODE, skeySpec);
56 byte[] decrypted = cipher.doFinal(encrypted);
60 public static void removeAllChildViews(ViewGroup viewGroup) {
61 for (int i = 0; i < viewGroup.getChildCount(); i++) {
62 View child = viewGroup.getChildAt(i);
63 if (child instanceof ViewGroup) {
64 if (child instanceof AdapterView) {
65 viewGroup.removeView(child);
68 removeAllChildViews(((ViewGroup) child));
70 viewGroup.removeView(child);
75 public static String getWeekdayString(long date) {
76 return getWeekdayString(date, true);
79 public static String getWeekdayString(long date, boolean fullString) {
80 return getWeekdayString(new Date(date * 1000), fullString);
83 public static String getWeekdayString(Date date) {
84 return getWeekdayString(date, true);
87 public static String getWeekdayString(Date date, boolean fullString) {
90 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 };
92 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 };
93 Calendar cal = Calendar.getInstance();
95 int dow = cal.get(Calendar.DAY_OF_WEEK);
96 int weekdayResId = weekdayResIds[dow-1];
97 return CampusAppContext.getInstance().getResString(weekdayResId);