Feb 28, 2014

Weather app V6 (add weather map using google map API+Notification)


This Version I added weather map.


I added '지도보기' button in mainactivity.

If you touched this button that can be seen weather map.

I got this map from google maps library.

So, you see the different weather.

Because, main get from KMA and mapweather get from google.

And I added Notification.





You can be see new button,"지도보기".

If you touched '지도보기'button that can be seen google weather map. 

If you touched weather icon, can be seen detail information.

If you scroll down that can be seen notification information.

You can be seen Current location and current weather.

If you touched notification bar, app moved weather app.


Feb 26, 2014

Weather app V5 (add widget& bug fix)


This version is completed weather widget version(maybe~)

I changed receiver class.(inner class->outer class)

So you can be seen "MainReceiver.java", new java file.

This file being communication  "WeatherWidget.java",appwidgetprovider using broadcasting.

You can be seen below displays.

This is first display. You can possible to choose that how to getting weather.

First , you choose location using spinner and touched '선택위치 보기' button.

Second , you touched '현재위치 보기' button.
This button using GPS and geocoding.

This picture is using widget.
You can installed short cut in main display.

App will be automatically getting weather ,if you touched '업데이트' button.


This version is complete widget version.(maybe)

Why do know I wrote 'maybe'?

I think many test this app.

Because I using database in  two type files.(MainActivity & MainReceiver)

Now I don't found bug. But need a many times test.

And I changed size of spinner.(static->wrap_content)

And I fixed bug in getaddress class(geocoding parser)







Feb 25, 2014

Weather app V4.99(add widget version)-but not completed version





This version added weather widget and progress.

Widget has 2 buttons.

First is go to weather app.(This is same old version)

Second is update button.(This button use to getting weather using GPS in this app)



If you install & run this app,can be seen this display.

And exit app(push back key) then go to widget menu.

And you add widget in main display.

If you touched '업데이트'button,can be seen this.
Problem 1
Exception!!
Maybe widget doesn't use method in mainactivity



But If you touched first '앱으로'button, can be seen this(updated widget).

Problem 2
Maybe about several minute after(I don't know exactly) you touched '업데이트' button, can be seen exception. 







Feb 24, 2014

android widget



This is a  android basic widget.

1. install this app.

2. go to widget.(long button on main display or menu button)

3. make a short cut in main display

4. run


Look at the widget menu. app installed in widget menu.


You make a short cut in main display.

Run app.

This app is basic. 

because just display activity.

If you want data communication, you will use broadcast or service.


MyWidget.java

  1. public class MyWidget extends AppWidgetProvider {
  2.     @Override
  3.     public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
  4.        
  5.         super.onUpdate(context, appWidgetManager, appWidgetIds);
  6.         int appId;
  7.         for(int i=0;i<appWidgetIds.length;i++){
  8.             appId=appWidgetIds[i];
  9.             Intent intent=new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://m.daum.net"));
  10.             PendingIntent pe=PendingIntent.getActivity(context, 0, intent, 0);
  11.             RemoteViews views =  new RemoteViews(context.getPackageName(),R.layout.activity_main);
  12.            
  13.             views.setOnClickPendingIntent(R.id.eventBtn, pe);
  14.             appWidgetManager.updateAppWidget(appId, views);
  15.              
  16.             }
  17.     }
  18. }

activity_main.xml
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:tools="http://schemas.android.com/tools"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:orientation="vertical"
  6.    tools:context=".MainActivity" >
  7.     <Button
  8.        android:id="@+id/eventBtn"
  9.        android:layout_width="match_parent"
  10.        android:layout_height="wrap_content"
  11.        android:text="GOGOGO" />
  12.            
  13. </LinearLayout>
This is a widget layout


If you choose Graphical Layout,you can be seen this display.

res/xml/widget_config.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <appwidget-provider
  3.    xmlns:android="http://schemas.android.com/apk/res/android"
  4.    android:minWidth= "294dp"
  5.    android:minHeight="72dp"
  6.    android:updatePeriodMillis="1000"
  7.    android:initialLayout="@layout/activity_main"
  8.    />
This is a widget config file.

You can configuration update time, widget size. etc...

AndroidManifest.xml
  1. <receiver android:name="MyWidget">                       
  2.             <meta-data android:name="android.appwidget.provider"       
  3.                 android:resource="@xml/widget_cofig"/>            
  4.             <intent-filter >                                    
  5.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
  6.             </intent-filter>
  7.         </receiver>
And need a this. 

You change tag receiver instead of activity.

and metadata tag and intent-filter.








Feb 18, 2014

fragment



fragment is for use  many kinds of view in one activity.

detail...

This is a useful for wide display device similar tablet.

So I make a simple code.

Left of display is icon for move to website.

Right of display is web browser.

If you touched icon, browser is moved.




activity_main.xml

  1.      <fragment
  2.         android:id="@+id/fragment1"
  3.         android:name="com.answerofgod.fragment.Fragment1"
  4.         android:layout_width="wrap_content"
  5.         android:layout_height="match_parent"
  6.         android:layout_weight="1" />
  7.     <fragment
  8.        android:id="@+id/fragment2"
  9.        android:name="com.answerofgod.fragment.Fragment2"
  10.        android:layout_width="wrap_content"
  11.        android:layout_height="match_parent"
  12.        android:layout_weight="20" />
I added 'fragment' tag.

Number of 'fragment' tag is number of view.

Name means Java file below.

Layout_weight is range of view.

Fragment1.java
  1.  public class Fragment1 extends Fragment {
  2.    
  3.     @Override
  4.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  5.             Bundle savedInstanceState) {
  6.        
  7.         return inflater.inflate(R.layout.frag1,container,false);
  8.     }
  9. }
This class inflate frag1.xml file.

'Fragment ' java file just to define of xml file(layout).

frag1.xml
  1.     <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.  xmlns:android="http://schemas.android.com/apk/res/android"
  4.  android:orientation="vertical"
  5.  android:layout_width="match_parent"
  6.  android:layout_height="match_parent">
  7.    
  8.   <Button
  9.     android:id="@+id/daum"
  10.     android:background="@drawable/daum"
  11.     android:gravity="center"
  12.     android:layout_width="50dp"
  13.     android:layout_height="50dp"/>

  14. ......
  15. </LinearLayout>
This is left of display for icon.

Fragment2.java

  1. public class Fragment2 extends Fragment {
  2.    
  3.     @Override
  4.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  5.             Bundle savedInstanceState) {
  6.        
  7.         return inflater.inflate(R.layout.frag2,container,false);
  8.     }
  9. }
This file inflate frag2.xml file.

frag2.xml
  1. <LinearLayout
  2.  xmlns:android="http://schemas.android.com/apk/res/android"
  3.  android:orientation="vertical"
  4.  android:background="#ff00ff00"
  5.  android:layout_width="match_parent"
  6.  android:layout_height="match_parent">
  7.   <WebView
  8.     android:layout_width="match_parent"
  9.     android:layout_height="match_parent"
  10.     android:gravity="center"
  11.     android:id="@+id/webview"/>
  12. </LinearLayout>
This is left of display for web browser.

MainActivity.java

  1. public class MainActivity extends Activity implements OnClickListener{
  2.     WebView webview;
  3.     Button daum;
  4.     Button naver;
  5.     Button facebook;
  6.     Button twit;
  7.     String url="http://m.facebook.com";
  8.   
  9.     @Override
  10.     protected void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.activity_main);
  13.        
  14.         webview=(WebView)findViewById(R.id.webview);
  15.         daum=(Button)findViewById(R.id.daum);


  16. ..........       
  17.     }
  18.    
  19.     @Override
  20.     public void onClick(View v) {
  21.         // TODO Auto-generated method stub
  22.         switch(v.getId()){
  23.         case R.id.daum:
  24.             url="http://m.daum.net";
  25.             webview.loadUrl(url);
  26.             break;

  27.         .........
  28.   .........
This file is  to define all for app.

Function, define, casting.... all in this file.









Feb 17, 2014

MyLocation&MyPath (some added version)




I used to 'watchPosition' method for 'function getMylocation()'.

  1. function getMylocation(){
  2.     firstTime=false;
  3.     if(navigator.geolocation) {
  4.      keycnt=navigator.geolocation.watchPosition(success,error2,geoOptions);
  5.     } else {
  6.    handleNoGeolocation(false);
  7.   }
  8. }

It detect to your location is changed.

And I add option that 'enableHighAccuracy'.


  1. geoOptions={
  2.       enableHighAccuracy : true,
  3.       timeout: 5000,
  4.       maximumAge: 0
  5.   };


It option is Increases the accuracy of location.



Feb 13, 2014

My Location&My Path app(do it android mission 20)


This app is display my current moving path on map.

If you run the app the app displays 3 button and 1 input text.

If you touched 'rec' button then app getting your location using GPS or Network every 3 second.

And app save in database that displays your moving path on map using polyline.

If you touched 'stop' button then app delete polyline and database.


This picture is normal state(you run the app)

This picture is touched 'rec'button

This picture is touched 'stop' button


1. Using Database


Adding MainActivity.java code for using database

MainActivity.java

  1. mapview.getSettings().setDatabasePath("/data/data/"+this.getPackageName()+"/databases/");
  2. mapview.getSettings().setDomStorageEnabled(true);
  3. mapview.getSettings().setDatabaseEnabled(true);
  4. mapview.getSettings().setAppCacheEnabled(true);
It code need for using database.

and need a javascrpit code

index.html

  1. function setdatabase(){
  2.     getMylocation();
  3.     var sumlatlnt=curLat+","+curLng;
  4.     localStorage.setItem(keycnt,sumlatlnt);
  5.     keycnt++;
  6. }
important is "localStorage.setItem(key,value)"

This code is record to database.

and if you reading value in database

You need a this code

"var temp=localStorage.getItem(key)"

and remove code is
"localStorage.removeItem(key)"


2. overlay using polyline

It's simple drawing polyline using google maps API

you just add this code to initialize
  1. var polyOptions = {
  2.     strokeColor: '#000000',
  3.     strokeOpacity: 1.0,
  4.     strokeWeight: 3
  5.   };
  6.   poly = new google.maps.Polyline(polyOptions);
  7.   poly.setMap(map);
  8.   path = poly.getPath();
you possible to reference google API about polyOption.

and adding event function "path.push(event.latLng);"

But I used another method.

  1. if(navigator.geolocation) {
  2.      navigator.geolocation.getCurrentPosition(function(position) {  
  3.          curLat=position.coords.latitude;
  4.          curLng=position.coords.longitude;
  5.          var newpos = new google.maps.LatLng(curLat,curLng);
  6.          map.setCenter(newpos);
  7.          path.push(newpos);
  8.      }function() {
  9.       handleNoGeolocation(true);
  10.     });
  11.    
  12.      
  13.   } else {
  14.    
  15.     handleNoGeolocation(false);
  16.   }
because I want my current location using gps

"path.push(latLng)" is draw polyline on map.

And "path.clear()" is clear polyline on map.