-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.java
67 lines (61 loc) · 2.63 KB
/
Tools.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package imo.card.gametest;
import android.app.Activity;
import android.widget.Toast;
import android.view.View;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ColorDrawable;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Tools
{
static void setViewSize(View view, int width, int height){
if (width != 0) view.getLayoutParams().width = width;
if (height != 0) view.getLayoutParams().height = height;
}
static void showToast(Context context, String message) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
static void setCustomBgWithStroke(View view, int bgColor, int cornerRadius, int strokeWidth, int strokeColor, float strokeAlpha) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(bgColor);
shape.setCornerRadius(cornerRadius);
int strokeColorWithAlpha = strokeColor & 0xFFFFFF | ((int)(strokeAlpha * 255)) << 24;
shape.setStroke(strokeWidth, strokeColorWithAlpha);
view.setBackground(shape);
}
static void convertStringToArraylist(String string,
ArrayList<Map<String, String>> arraylist,
String splitItemsBy,
String splitContentsBy){
String[] rawItems = string.split(splitItemsBy);//seperate the contents to individual sections
for (String rawItem : rawItems) {//loop to every sections made
if(!rawItem.isEmpty()){
String rawContent = rawItem.replaceFirst(splitContentsBy, "");//remove the leading desired char before seperating
String[] keyValues = rawContent.split(splitContentsBy);//seperate into pieces by the desired char
Map<String, String> newMap = new HashMap<>();
for (String keyValue : keyValues) {//get the seperated pieces
if(keyValue.contains("=") || !keyValue.isEmpty()){
String[] splitKeyValue = keyValue.split("=");//seperate into 2 pieces by =
newMap.put(splitKeyValue[0].trim(), splitKeyValue[1].trim());//put the 1st piece into the key and 2nd piece to the value of a map
}
}
arraylist.add(newMap);//add the maps
}
}
}
static Map<String, String> findMapFromArraylist(
ArrayList<Map<String, String>> arrayList,
String key, String value){
Map<String, String> output = new HashMap<>();
for (Map<String, String> map : arrayList) {// Loop through the ArrayList and find the map with the desired key-value pair
if (map.containsKey(key) && map.get(key).equals(value)) {
output = map;// Found the map with the desired key-value pair
}
}
return output;
}
}