ClothesRecommend.java 4.26 KB
package com.example.test;

import android.os.StrictMode;

import java.util.ArrayList;

public class ClothesRecommend extends Thread {

    ClothesActivity cContext;
    WeatherActivity wContext;
    WeatherForCast mWeather;

    public ClothesRecommend(ClothesActivity mContext) {
        this.cContext = cContext;
    }

    public int Cal_Perceived(String Temper, String Velo) {

        int perceived;
        double temper = Double.parseDouble(Temper);
        double velo = Double.parseDouble(Velo);
        perceived = (int) (13.12 + 0.6215 * temper - 11.37 * Math.pow(velo, 0.16) + 0.3965 * Math.pow(velo, 0.16) * temper);

        return perceived;
    }

    // 체감온도에 따른 옷추천 (Recommend는 [체감온도, 성별]으로 이루어진 배열)
    public ArrayList<ArrayList<String>> Recommend(ArrayList<Integer> Recommend){
        int perceived = Recommend.get(0);
        int gender = Recommend.get(1);

        ArrayList<String> code = new ArrayList<String>();
        ArrayList<String> top = new ArrayList<String>();
        ArrayList<String> bottom = new ArrayList<String>();
        ArrayList<ArrayList<String>> clothes = new ArrayList<ArrayList<String>>();

        if (perceived >= 28){
            top.add("민소매");
            top.add("반팔");
            bottom.add("반바지");
            if (gender == 1){
                bottom.add("치마");
                top.add("원피스");
                code.add("11");
            } else { code.add("10"); }
        } else if (perceived >= 23) {
            top.add("반팔");
            top.add("얇은 셔츠");
            top.add("긴팔");
            bottom.add("반바지");
            bottom.add("면바지");
            if (gender == 1){
                bottom.add("치마");
                code.add("21");
            } else { code.add("20"); }
        } else if (perceived >= 20) {
            top.add("긴팔");
            top.add("가디건");
            bottom.add("면바지");
            bottom.add("슬랙스");
            bottom.add("스키니");
            code.add("30");
        } else if (perceived >= 17) {
            top.add("가디건");
            top.add("후드티");
            top.add("맨투맨");
            bottom.add("청바지");
            bottom.add("면바지");
            code.add("40");
        } else if (perceived >= 12) {
            top.add("후드티");
            top.add("셔츠");
            top.add("가디건");
            bottom.add("긴바지");
            bottom.add("청바지");
            if (gender == 1){
                bottom.add("살색스타킹");
                code.add("51");
            } else { code.add("50"); }
        } else if (perceived >= 10) {
            top.add("자켓");
            top.add("니트");
            top.add("트렌치코트");
            bottom.add("긴바지");
            if (gender == 1){
                bottom.add("검정스타킹");
                code.add("61");
            } else { code.add("60"); }
        } else if (perceived >= 4) {
            top.add("코트");
            top.add("자켓");
            top.add("히트텍");
            bottom.add("긴바지");
            if (gender == 1){
                bottom.add("레깅스");
                code.add("71");
            } else { code.add("70"); }
        } else {
            top.add("패딩");
            top.add("두꺼운 코트");
            bottom.add("긴바지");
            if (gender == 1) {
                bottom.add("레깅스");
                code.add("81");
            } else { code.add("80"); }
        }

        clothes.add(code);
        clothes.add(top);
        clothes.add(bottom);

        // Return [[이미지 코드], [상의], [하의]]
        return clothes;
    }

    public ArrayList<ArrayList<String>> AccessWeather(String code){
        ArrayList<ArrayList<String>> gData = new ArrayList<ArrayList<String>>();
        mWeather = new WeatherForCast(code, (WeatherActivity) wContext);
        gData = mWeather.GetOpenWeather(code);

        return gData;
    }

    @Override
    public void run() {
        super.run();
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
    }
}