3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp;
18 import android.view.View;
19 import android.view.ViewGroup;
20 import android.widget.AdapterView;
22 import java.security.MessageDigest;
23 import java.security.NoSuchAlgorithmException;
24 import java.util.Calendar;
25 import java.util.Date;
27 import javax.crypto.Cipher;
28 import javax.crypto.spec.SecretKeySpec;
31 * Created by pk910 on 25.01.2016.
35 public static final String md5(final String s) {
36 final String MD5 = "MD5";
39 MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
40 digest.update(s.getBytes());
41 byte messageDigest[] = digest.digest();
44 StringBuilder hexString = new StringBuilder();
45 for (byte aMessageDigest : messageDigest) {
46 String h = Integer.toHexString(0xFF & aMessageDigest);
47 while (h.length() < 2)
51 return hexString.toString();
53 } catch (NoSuchAlgorithmException e) {
59 public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
60 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
61 Cipher cipher = Cipher.getInstance("AES");
62 cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
63 byte[] encrypted = cipher.doFinal(clear);
67 public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
68 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
69 Cipher cipher = Cipher.getInstance("AES");
70 cipher.init(Cipher.DECRYPT_MODE, skeySpec);
71 byte[] decrypted = cipher.doFinal(encrypted);
75 public static void removeAllChildViews(ViewGroup viewGroup) {
76 for (int i = 0; i < viewGroup.getChildCount(); i++) {
77 View child = viewGroup.getChildAt(i);
78 if (child instanceof ViewGroup) {
79 if (child instanceof AdapterView) {
80 viewGroup.removeView(child);
83 removeAllChildViews(((ViewGroup) child));
85 viewGroup.removeView(child);
90 public static String getWeekdayString(long date) {
91 return getWeekdayString(date, true);
94 public static String getWeekdayString(long date, boolean fullString) {
95 return getWeekdayString(new Date(date * 1000), fullString);
98 public static String getWeekdayString(Date date) {
99 return getWeekdayString(date, true);
102 public static String getWeekdayString(Date date, boolean fullString) {
105 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 };
107 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 };
108 Calendar cal = Calendar.getInstance();
110 int dow = cal.get(Calendar.DAY_OF_WEEK);
111 int weekdayResId = weekdayResIds[dow-1];
112 return CampusAppContext.getInstance().getResString(weekdayResId);