티스토리 뷰

[ 팬 어플 만들기 ]


친구중에서 걸그룹 '오마이걸'을 심각하게 좋아하는 친구가 있어

연습겸 제작하게 된 어플입니다.


[  인트로 액티비티 ]


intro 라는 이름으로 설정했다면 좋았겠지만, 빠르게 finish를 눌러버리는바람에 생성된

Main2Activity를 2초간 띄운뒤, 없애고 Mainactivity로 넘어가는것으로 인트로 페이지를 구현했습니다.


아래는 레이아웃과 사용된 소스입니다.




 인트로 액티비티.xml (Design탭)




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
package site.skinsiro.ohmygirl;
 
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 
import android.os.Handler;
 
public class Main2Activity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
 
        Handler hand = new Handler();
        hand.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent it = new Intent(Main2Activity.this, MainActivity.class);
                startActivity(it);
                finish();
            }
        },2000);
    }
}
cs






[  메인 액티비티 ]

메인 액티비티 에서는 DC인사이드 갤러리와 팬카페로 이동할수 있으며
남은공간은 웹뷰로 채운뒤 팬카페의 자유이벤트 페이지를 가져와서 이벤트를 볼수 있도록 계획하였습니다.

그런데 만드는 과정에서 문제가 발생하고 말았습니다. 
자유이벤 게시판으로 이동해도 보여지는 주소는 변하지 않았습니다.



오마이걸 팬카페 자유이벤 게시판



웹뷰로 어떻게 가져오면 좋을까 생각하다가 이벤트 게시판이 있는 프레임의 소스를 살펴보다가 찾은 링크를

복사하여 가져왔더니 웹뷰가 작동하는걸 볼수 있었습니다.





웹뷰로 가져온 주소



메인 액티비티의 소스와 레이아웃입니다.( 스위치는 작동시 웹뷰가 급식으로, 버튼의 이름이 'school meal'로 전환되게 설정하였습니다.)



메인 액티비티.xml (Design탭)




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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package site.skinsiro.ohmygirl;
 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
 
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
 
import java.util.Date;
import java.util.Locale;
import java.util.logging.Handler;
 
public class MainActivity extends AppCompatActivity {
    String[] items = {"팬카페""갤러리"};
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final WebView wv = (WebView) findViewById(R.id.viewv);
        wv.setWebViewClient(new WebViewClient());
        String a = "http://cafe.daum.net/_c21_/bbs_list?grpid=1VTSi&mgrpid=&fldid=XuKj";
        wv.loadUrl(a);
        final Button button = (Button) findViewById(R.id.button3);
        Button button2 = (Button) findViewById(R.id.button4);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(MainActivity.this);
                ab.setTitle("선택하면 이동합니다");
                ab.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (items[which].toString().equals("팬카페")) {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cafe.daum.net/-ohmygirl"));
                            Toast.makeText(MainActivity.this"펜카페로 이동하였습니다", Toast.LENGTH_SHORT).show();
                            startActivity(intent);
                        } else {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://gall.dcinside.com/board/lists/?id=ohmygirl"));
                            Toast.makeText(MainActivity.this"갤러리로 이동하였습니다", Toast.LENGTH_SHORT).show();
                            startActivity(intent);
                        }
                    }
                });
 
                AlertDialog alertDialog = ab.create();
                ab.show();
 
            }
        });
        Switch sw = (Switch) findViewById(R.id.switch1);
        sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked == true) {
                    button.setVisibility(View.INVISIBLE);
                    SimpleDateFormat fm = new SimpleDateFormat("yyyy/MM", Locale.KOREA);
                    Date ct = new Date();
                    String time = fm.format(ct);
                    String af = "http://iys.icehs.kr/foodList.do?evFlag=next&strDate="+time+"&m=020601";
 
                    wv.loadUrl(af);
                } else {
                    button.setVisibility(View.VISIBLE);
                    String a = "http://m.cafe.daum.net/-ohmygirl/XuKj?boardType=";
                    wv.loadUrl(a);
                }
            }
        });
 
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }
 
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    public Action getIndexApiAction() {
        Thing object = new Thing.Builder()
                .setName("Main Page"// TODO: Define a title for the content shown.
                // TODO: Make sure this auto-generated URL is correct.
                .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
                .build();
        return new Action.Builder(Action.TYPE_VIEW)
                .setObject(object)
                .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                .build();
    }
 
    @Override
    public void onStart() {
        super.onStart();
 
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        AppIndex.AppIndexApi.start(client, getIndexApiAction());
    }
 
    @Override
    public void onStop() {
        super.onStop();
 
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        AppIndex.AppIndexApi.end(client, getIndexApiAction());
        client.disconnect();
    }
}
 
cs



메인 액티비티.java



[  작동 화면 ]



 아무것도 안한 상태, cafe/gallery클릭시, 스위치 작동시 화면









댓글