最近喜欢上中国玄学,奇门遁甲,风水八字等,虽然网上有很多奇门排盘的软件,但是都是非安卓原生代码实现的,所以为了验证自己所学,原生代码写了个自动排盘
如图
具体的逻辑主要是公历转为中国传统的农历
/**
* @param rgz 日干
* @param curtime 时间
* @return
*/
public static List<Object> getPanInfo(long curtime, String rgz) {
int index = 0;
String curJieqi = "";
boolean isYangdun = true;//是否是阳盾
//夏至和冬至时间 夏至以后为阴盾局 冬至以后为阳盾局
int curYear = DateUtil.getYearByTimeStamp(curtime);
int curMonth = DateUtil.getMonthByTimeStamp(curtime);
Jieqi mj = new Jieqi();
Map<String, String> map = replaceMapValue(mj.paiYue(curYear), SolarTermsUtil.solarTermToString(curtime), curtime);
for (Entry<String, String> entry : map.entrySet()) {
String jq = entry.getKey();
String date = entry.getValue();
long dd = DateUtil.getStringToDate(date);
}
//冬至后用阳盾2020-12-21 18:02:21,夏至后用阴盾2020-06-21 05:43:37
String xzDate = map.get("夏至");
String dzDate = map.get("冬至");
long xztime = DateUtil.getStringToDate(xzDate);
long dztime = DateUtil.getStringToDate(dzDate);
//如果当前月份为夏至后,冬至前则用阴盾
for (int i = 0; i < sixty_jiazi.length; i++) {
if (sixty_jiazi[i].equals(rgz)) {
index = i;
}
}
if (curtime > xztime && curtime < dztime) {
isYangdun = false;
}
int line = index / 5;
String yuan = yuan_fu[line];
//首先判断月份是否匹配,每个月两个节气,再根据两个节气的时间做判断,是属于什么节气
//存储根据正常节气顺序获取的时间戳
List<Long> datas = new ArrayList<>(24);
List<String> jq = new ArrayList<>(24);
List<Integer> indexYue = new ArrayList<>(24);
for (int i = 0; i < jieqi.length; i++) {
String time = map.get(jieqi[i]);
datas.add(i, DateUtil.getStringToDate(time));
jq.add(i, jieqi[i]);
}
for (int i = 0; i < yuefen.length; i++) {
if (yuefen[i] == curMonth) {
indexYue.add(i);
}
}
if (curMonth == 2) {
if (curtime < datas.get(indexYue.get(0))) {
curJieqi = jieqi[23];
} else if (curtime >= datas.get(indexYue.get(0)) && curtime < datas.get(indexYue.get(1))) {
curJieqi = jieqi[indexYue.get(0)];
} else if (curtime >= datas.get(indexYue.get(1))) {
curJieqi = jieqi[indexYue.get(1)];
}
} else {
if (curtime < datas.get(indexYue.get(0))) {
curJieqi = jieqi[indexYue.get(0) - 1];
} else if (curtime >= datas.get(indexYue.get(0)) && curtime < datas.get(indexYue.get(1))) {
curJieqi = jieqi[indexYue.get(0)];
} else if (curtime >= datas.get(indexYue.get(1))) {
curJieqi = jieqi[indexYue.get(1)];
}
}
Map<String, String> dunMap = new HashMap<>(24);
dunMap.put("冬至", "174");
dunMap.put("小寒", "285");
dunMap.put("大寒", "396");
dunMap.put("立春", "852");
dunMap.put("雨水", "963");
dunMap.put("惊蛰", "174");
dunMap.put("春分", "396");
dunMap.put("清明", "417");
dunMap.put("谷雨", "528");
dunMap.put("立夏", "417");
dunMap.put("小满", "528");
dunMap.put("芒种", "639");
dunMap.put("夏至", "936");
dunMap.put("小暑", "825");
dunMap.put("大暑", "714");
dunMap.put("立秋", "258");
dunMap.put("处暑", "147");
dunMap.put("白露", "936");
dunMap.put("秋分", "714");
dunMap.put("寒露", "693");
dunMap.put("霜降", "582");
dunMap.put("立冬", "693");
dunMap.put("小雪", "582");
dunMap.put("大雪", "471");
int jushu = 0;
Log.e(TAG, "isYangdun: " + isYangdun);
Log.e(TAG, "curJieqi: " + curJieqi);
if (isYangdun) {
String s = dunMap.get(curJieqi);
if (yuan.equals("上元")) {
jushu = Integer.parseInt(s.substring(0, 1));
} else if (yuan.equals("中元")) {
jushu = Integer.parseInt(s.substring(1, 2));
} else {
jushu = Integer.parseInt(s.substring(s.length() - 1));
}
} else {
String s = dunMap.get(curJieqi);
if (yuan.equals("上元")) {
jushu = Integer.parseInt(s.substring(0, 1));
} else if (yuan.equals("中元")) {
jushu = Integer.parseInt(s.substring(1, 2));
} else {
jushu = Integer.parseInt(s.substring(s.length() - 1));
}
}
List<Object> list = new ArrayList<>(5);
list.add(0, isYangdun);
list.add(1, yuan);
list.add(2, curJieqi);
list.add(3, jushu);
Log.e("DHD", "isYangdun: " + isYangdun);
Log.e("DHD", "yuan: " + yuan);
Log.e("DHD", "curMonth: " + curMonth);
Log.e("DHD", "curJieqi: " + curJieqi);
Log.e("DHD", "jushu: " + jushu);
return list;
}
盘面是用recyclerview实现,其中用到很多算法逻辑
包括干支纪年法计算,十二长生,五行生克,八门九星等,不一一贴图
有排盘自然要有风水罗盘
Android端具体逻辑是将时间选择转为农历,再根据干支纪年法,五行生克,十二长生,八门九星等宫位排列规则用recyclerview进行计算排序,
服务端使用go开发
需要代码的可以联系wx:kotm0066