Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WidgetTest01/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,26 @@
import javax.net.ssl.HttpsURLConnection;

public class MainActivity extends AppCompatActivity {
TextView textView;
TextView location;
TextView tc;
TextView minNmax;
TextView currentIndex;
TextView UV;
FloatingActionButton fab_add, fab_mypage, fab_main;
String[] items = {"강남구", "강동구", "강북구", "강서구", "관악구", "광진구", "구로구", "금천구", "노원구", "도봉구", "동대문구", "동작구", "마포구", "서대문구", "서초구", "성동구", "성북구", "송파구", "양천구", "영등포구", "용산구", "은평구", "종로구", "중구", "중랑구"};
String[] villages = {"삼성동", "성내1동", "수유3동", "화곡6동", "봉천동", "자양동", "구로동", "시흥동", "상계6.7동", "방학동", "용두동", "노량진2동", "성산동", "연희동", "서초2동", "행당동", "삼선동", "신천동", "신정6동", "당산동", "이태원동", "녹번동", "수송동", "광희동", "신내동"};
String[] items = {"강남구","강동구","강북구","강서구","관악구","광진구","구로구","금천구","노원구","도봉구","동대문구","동작구","마포구","서대문구","서초구","성동구","성북구","송파구","양천구","영등포구","용산구","은평구","종로구","중구","중랑구"};
String[] villages = {"삼성동","성내1동","수유3동","화곡6동","봉천동","자양동","구로동","시흥동","상계6.7동","방학동","용두동","노량진2동","성산동","연희동","서초2동","행당동","삼선동","신천동","신정6동","당산동","이태원동","녹번동","수송동","광희동","신내동"};
int countyPosition;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView = (TextView) findViewById(R.id.textView);
location = (TextView) findViewById(R.id.location);
minNmax = (TextView) findViewById(R.id.minNmax);
tc = (TextView) findViewById(R.id.tc);
currentIndex = (TextView) findViewById(R.id.currentIndex);
UV = (TextView) findViewById(R.id.UV);

fab_add = (FloatingActionButton)findViewById(R.id.fab_add);
fab_mypage = (FloatingActionButton)findViewById(R.id.fab_mypage);
Expand All @@ -57,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
// 아이템 선택시 호출됨
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
textView.setText(items[position] + " " +villages[position]);
location.setText(items[position] + " " +villages[position]);
countyPosition = position;

String baseUrl = "https://api2.sktelecom.com/weather/current/minutely?appkey=8ab05bc6-8297-4251-bb89-e7a085516286&version=1";
Expand All @@ -77,6 +81,8 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int position,

longitude = tInfo[3];
latitude = tInfo[4];
Log.d("longitude 가져옴?", longitude);
Log.d("latitude 가져옴?", latitude);
} catch (InterruptedException e) {
Log.d("weatherAPI 결과1", "에러1");
e.printStackTrace();
Expand All @@ -85,11 +91,26 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int position,
e.printStackTrace();
}

baseUrl = "";
url = baseUrl + longitude + latitude;
baseUrl = "https://api2.sktelecom.com/weather/index/wct?appkey=8ab05bc6-8297-4251-bb89-e7a085516286&version=1";
String lat = "&lat=" + latitude;
String lon = "&lon=" + longitude;
url = baseUrl + lat + lon;
indexAPI iAPI = new indexAPI(url, longitude, latitude);
try {
String index = iAPI.execute().get();
currentIndex.setText(index);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

baseUrl = "https://api2.sktelecom.com/weather/index/uv?appkey=8ab05bc6-8297-4251-bb89-e7a085516286&version=1";
url = baseUrl + lat + lon;
UVAPI uvAPI = new UVAPI(url, longitude, latitude);
try{
String comment = uvAPI.execute().get();
UV.setText(comment);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
Expand All @@ -100,7 +121,7 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int position,
// 아무것도 선택되지 않았을때 호출됨 -> 여기에 기본 설정 지역을..
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
textView.setText("");
location.setText("");
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.techtown.widgettest01;

import android.os.AsyncTask;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

/**
* Created by 수연 on 2018-08-14.
*/

public class UVAPI extends AsyncTask<Map<String, String>, Integer, String> {
String urlStr;
String line;
String longitude;
String latitude;

public UVAPI(String urlStr, String longitude, String latitude) {
this.urlStr = urlStr;
this.longitude = longitude;
this.latitude = latitude;
}

@Override
protected String doInBackground(Map<String, String>[] maps) {
Log.d("urlString", urlStr);
try {
URL url = new URL(urlStr);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream in = urlConnection.getInputStream();

StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
while ((line = reader.readLine()) != null) {
builder.append(line + "\n");
}

String result = builder.toString();
String comment = "";

try {
JSONObject jsonObject = new JSONObject(result);
JSONObject weather = jsonObject.getJSONObject("weather");
JSONObject wIndex = weather.getJSONObject("wIndex");
JSONArray wctIndex = wIndex.getJSONArray("uvindex");
JSONObject c = wctIndex.getJSONObject(0);

JSONObject currentJSON = c.getJSONObject("day00");

comment = currentJSON.getString("comment");

Log.d(">>>>> comment", comment);
} catch (JSONException e) {
Log.d("제이슨 만들기", "실패");
e.printStackTrace();
}

urlConnection.disconnect();
return comment;
} else {
Log.d("UV-API연결", "실패");
}
} catch (MalformedURLException e) {
Log.d("에러1", "MalformedURL");
e.printStackTrace();
} catch (IOException e) {
Log.d("에러2", "IOException");
e.printStackTrace();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import android.os.AsyncTask;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -42,8 +46,31 @@ protected String doInBackground(Map<String, String>[] maps) {
while ((line = reader.readLine()) != null) {
builder.append(line + "\n");
}

String result = builder.toString();
String index = "";

try {
JSONObject jsonObject = new JSONObject(result);
JSONObject weather = jsonObject.getJSONObject("weather");
JSONObject wIndex = weather.getJSONObject("wIndex");
JSONArray wctIndex = wIndex.getJSONArray("wctIndex");
JSONObject c = wctIndex.getJSONObject(0);

JSONObject currentJSON = c.getJSONObject("current");

index = currentJSON.getString("index");

Log.d(">>>>> index", index);
} catch (JSONException e) {
Log.d("제이슨 만들기", "실패");
e.printStackTrace();
}

urlConnection.disconnect();
return index;
} else {
Log.d("API연결", "실패");
Log.d("index-API연결", "실패");
}
} catch (MalformedURLException e) {
Log.d("에러1", "MalformedURL");
Expand Down
21 changes: 17 additions & 4 deletions WidgetTest01/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<TextView
android:id="@+id/tc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="현재온도" />

<LinearLayout
Expand All @@ -50,19 +50,32 @@
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="51dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="40dp"
app:layout_collapseMode="parallax" />

<TextView
android:id="@+id/minNmax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="최저/최고" />

<TextView
android:id="@+id/currentIndex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="체감온도"/>

<TextView
android:id="@+id/UV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />

</LinearLayout>
</LinearLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_width="300dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/popupButtons"
tools:context="org.techtown.widgettest01.popup_clothes">

<LinearLayout
Expand Down