Commit 4ff37557fe27a87b61a4e5853d60aa3f371bc873
1 parent
ccd9fb8a
- fix material design
- add login activity
Showing
13 changed files
with
166 additions
and
75 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/net/devfac/userstory/ActivityLogin.java
0 → 100644
1 | +package net.devfac.userstory; | |
2 | + | |
3 | +import android.os.Bundle; | |
4 | +import android.support.v7.app.AppCompatActivity; | |
5 | +import android.support.v7.widget.Toolbar; | |
6 | +import android.view.Menu; | |
7 | +import android.view.MenuInflater; | |
8 | + | |
9 | +/** | |
10 | + * Created by Onether on 15. 11. 10.. | |
11 | + */ | |
12 | +public class ActivityLogin extends AppCompatActivity { | |
13 | + private Toolbar mToolbarLogin; | |
14 | + | |
15 | + @Override | |
16 | + protected void onCreate(Bundle savedInstanceState) { | |
17 | + super.onCreate(savedInstanceState); | |
18 | + setContentView(R.layout.activity_login); | |
19 | + | |
20 | + mToolbarLogin = (Toolbar)findViewById(R.id.toolbar_login); | |
21 | + setSupportActionBar(mToolbarLogin); | |
22 | + } | |
23 | + | |
24 | + @Override | |
25 | + public boolean onCreateOptionsMenu(Menu menu) { | |
26 | + MenuInflater inflater = getMenuInflater(); | |
27 | + inflater.inflate(R.menu.login, menu); | |
28 | + | |
29 | + return super.onCreateOptionsMenu(menu); | |
30 | + } | |
31 | +} | ... | ... |
app/src/main/java/net/devfac/userstory/Constants.java
... | ... | @@ -17,11 +17,9 @@ public class Constants { |
17 | 17 | |
18 | 18 | public static final String IMAGE_FILE_SAVE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "USERSTORY"; |
19 | 19 | |
20 | - public enum FRAGMENT_SELECT{ | |
21 | - FRAG_LOGIN, | |
22 | - FRAG_BOOK_SHELF, | |
23 | - FRAG_ADD_BOOK | |
24 | - } | |
20 | + public static final String FRAGMENT_TITLE_LOGIN = "로그인"; | |
21 | + public static final String FRAGMENT_TITLE_BOOK_SHELF = "내 책장"; | |
22 | + public static final String FRAGMENT_TITLE_ADD_BOOK = "책 추가"; | |
25 | 23 | |
26 | 24 | //Preferences |
27 | 25 | public static final String PREF_USER_ID = "pref_user_id"; | ... | ... |
app/src/main/java/net/devfac/userstory/FragmentAddBook.java
1 | 1 | package net.devfac.userstory; |
2 | 2 | |
3 | -import android.app.Activity; | |
4 | -import android.app.Fragment; | |
5 | -import android.graphics.Bitmap; | |
6 | -import android.graphics.BitmapFactory; | |
7 | -import android.os.AsyncTask; | |
8 | 3 | import android.os.Bundle; |
9 | 4 | import android.support.annotation.Nullable; |
5 | +import android.support.v4.app.Fragment; | |
10 | 6 | import android.view.LayoutInflater; |
11 | 7 | import android.view.View; |
12 | 8 | import android.view.ViewGroup; |
13 | -import android.webkit.WebSettings; | |
14 | 9 | import android.webkit.WebView; |
15 | -import android.webkit.WebViewClient; | |
16 | 10 | import android.widget.AdapterView; |
17 | 11 | import android.widget.Button; |
18 | 12 | import android.widget.EditText; |
... | ... | @@ -24,25 +18,7 @@ import net.devfac.userstory.FSM.StateContext; |
24 | 18 | import net.devfac.userstory.FSM.StateEventListener; |
25 | 19 | import net.devfac.userstory.FSM.state.StateBookSearchToAdd; |
26 | 20 | import net.devfac.userstory.Utils.Logger; |
27 | -import net.devfac.userstory.Utils.UrlGenerator; | |
28 | -import net.htmlparser.jericho.Element; | |
29 | -import net.htmlparser.jericho.HTMLElementName; | |
30 | -import net.htmlparser.jericho.Source; | |
31 | - | |
32 | -import org.apache.http.client.HttpClient; | |
33 | - | |
34 | -import java.io.BufferedReader; | |
35 | -import java.io.File; | |
36 | -import java.io.FileOutputStream; | |
37 | -import java.io.IOException; | |
38 | -import java.io.InputStream; | |
39 | -import java.io.InputStreamReader; | |
40 | -import java.io.OutputStream; | |
41 | -import java.net.HttpURLConnection; | |
42 | -import java.net.MalformedURLException; | |
43 | -import java.net.URL; | |
44 | 21 | import java.util.ArrayList; |
45 | -import java.util.List; | |
46 | 22 | |
47 | 23 | import static net.devfac.userstory.FSM.state.StateBookSearchToAdd.*; |
48 | 24 | ... | ... |
app/src/main/java/net/devfac/userstory/FragmentBookShelf.java
app/src/main/java/net/devfac/userstory/FragmentLogin.java
app/src/main/java/net/devfac/userstory/MainActivity.java
1 | 1 | package net.devfac.userstory; |
2 | 2 | |
3 | +import android.app.ActionBar; | |
3 | 4 | import android.app.Dialog; |
4 | -import android.app.Fragment; | |
5 | -import android.app.FragmentTransaction; | |
6 | 5 | import android.content.Intent; |
7 | 6 | import android.os.Bundle; |
8 | 7 | import android.support.design.widget.FloatingActionButton; |
9 | 8 | import android.support.design.widget.Snackbar; |
9 | +import android.support.design.widget.TabLayout; | |
10 | +import android.support.v4.app.Fragment; | |
11 | +import android.support.v4.app.FragmentManager; | |
12 | +import android.support.v4.app.FragmentPagerAdapter; | |
13 | +import android.support.v4.view.ViewPager; | |
10 | 14 | import android.view.View; |
11 | 15 | import android.support.design.widget.NavigationView; |
12 | 16 | import android.support.v4.view.GravityCompat; |
... | ... | @@ -28,12 +32,19 @@ import net.devfac.userstory.FSM.state.StateLogoutRequested; |
28 | 32 | import net.devfac.userstory.Utils.Logger; |
29 | 33 | import net.devfac.userstory.Utils.PreferenceUtil; |
30 | 34 | |
35 | +import java.util.ArrayList; | |
36 | +import java.util.List; | |
37 | + | |
31 | 38 | public class MainActivity extends AppCompatActivity |
32 | 39 | implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener, StateEventListener { |
33 | 40 | |
34 | - private Fragment mFragmentBookShelf = new FragmentBookShelf(); | |
35 | - private Fragment mFragmentLogin = new FragmentLogin(); | |
36 | - private Fragment mFragmentAddBook = new FragmentAddBook(); | |
41 | +// private Fragment mFragmentBookShelf = new FragmentBookShelf(); | |
42 | +// private Fragment mFragmentLogin = new FragmentLogin(); | |
43 | +// private Fragment mFragmentAddBook = new FragmentAddBook(); | |
44 | + | |
45 | + private ViewPager mViewPagerMain; | |
46 | + private ViewPagerAdapter mViewPagerAdapter; | |
47 | + private TabLayout mTabLayoutMain; | |
37 | 48 | |
38 | 49 | @Override |
39 | 50 | protected void onCreate(Bundle savedInstanceState) { |
... | ... | @@ -60,13 +71,22 @@ public class MainActivity extends AppCompatActivity |
60 | 71 | StateContext.getInstance(this).processEvent(Action.REQ_LOGIN, null); |
61 | 72 | } |
62 | 73 | else{ |
63 | - fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_BOOK_SHELF); | |
74 | + mViewPagerMain.setCurrentItem(mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_BOOK_SHELF)); | |
75 | +// fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_BOOK_SHELF); | |
64 | 76 | } |
65 | 77 | } |
66 | 78 | void initWidget(){ |
67 | 79 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
68 | 80 | setSupportActionBar(toolbar); |
69 | 81 | |
82 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
83 | + | |
84 | + mViewPagerMain = (ViewPager)findViewById(R.id.viewPager_main); | |
85 | + setupViewPager(mViewPagerMain); | |
86 | + | |
87 | + mTabLayoutMain = (TabLayout)findViewById(R.id.tablayout_main); | |
88 | + mTabLayoutMain.setupWithViewPager(mViewPagerMain); | |
89 | + | |
70 | 90 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); |
71 | 91 | fab.setOnClickListener(new View.OnClickListener() { |
72 | 92 | @Override |
... | ... | @@ -74,7 +94,9 @@ public class MainActivity extends AppCompatActivity |
74 | 94 | Snackbar.make(view, "ADD BOOKS", Snackbar.LENGTH_LONG) |
75 | 95 | .setAction("Action", null).show(); |
76 | 96 | |
77 | - fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_ADD_BOOK); | |
97 | + mViewPagerMain.setCurrentItem(mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_ADD_BOOK)); | |
98 | + | |
99 | +// fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_ADD_BOOK); | |
78 | 100 | } |
79 | 101 | }); |
80 | 102 | |
... | ... | @@ -147,7 +169,8 @@ public class MainActivity extends AppCompatActivity |
147 | 169 | // Handle navigation view item clicks here. |
148 | 170 | switch( item.getItemId() ){ |
149 | 171 | case R.id.nav_book_shlef: |
150 | - fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_BOOK_SHELF); | |
172 | + mViewPagerMain.setCurrentItem( mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_BOOK_SHELF)); | |
173 | + | |
151 | 174 | break; |
152 | 175 | } |
153 | 176 | |
... | ... | @@ -156,43 +179,56 @@ public class MainActivity extends AppCompatActivity |
156 | 179 | return true; |
157 | 180 | } |
158 | 181 | |
159 | - public void fragmentReplace(Constants.FRAGMENT_SELECT requestedFragment){ | |
160 | - Fragment newFragment = getFragment(requestedFragment); | |
182 | + private void setupViewPager(ViewPager viewPager){ | |
183 | + mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager()); | |
184 | + mViewPagerAdapter.addFragment(new FragmentAddBook(), Constants.FRAGMENT_TITLE_ADD_BOOK); | |
185 | + mViewPagerAdapter.addFragment(new FragmentBookShelf(), Constants.FRAGMENT_TITLE_BOOK_SHELF); | |
186 | +// mViewPagerAdapter.addFragment(new FragmentLogin(), Constants.FRAGMENT_TITLE_LOGIN); | |
187 | + viewPager.setAdapter(mViewPagerAdapter); | |
188 | + } | |
161 | 189 | |
162 | - if( getFragmentManager().findFragmentById(R.id.fragment_view) != null | |
163 | - && getFragmentManager().findFragmentById(R.id.fragment_view).equals(newFragment)){ | |
164 | - newFragment.onResume(); | |
165 | - } else { | |
166 | - Logger.i("Fragment Replaced to " + requestedFragment); | |
167 | - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); | |
168 | - transaction.replace(R.id.fragment_view, newFragment); | |
169 | - transaction.commit(); | |
190 | + class ViewPagerAdapter extends FragmentPagerAdapter { | |
191 | + private final List<Fragment> mFragmentList = new ArrayList<>(); | |
192 | + private final List<String> mFragmentTitleList = new ArrayList<>(); | |
193 | + | |
194 | + public ViewPagerAdapter(FragmentManager fm) { | |
195 | + super(fm); | |
196 | + } | |
197 | + | |
198 | + @Override | |
199 | + public android.support.v4.app.Fragment getItem(int position) { | |
200 | + return mFragmentList.get(position); | |
170 | 201 | } |
171 | - } | |
172 | 202 | |
173 | - public Fragment getFragment(Constants.FRAGMENT_SELECT requestedFragment){ | |
174 | - Fragment newFragment = null; | |
203 | + @Override | |
204 | + public int getCount() { | |
205 | + return mFragmentList.size(); | |
206 | + } | |
175 | 207 | |
176 | - switch( requestedFragment ){ | |
177 | - case FRAG_ADD_BOOK: | |
178 | - newFragment = mFragmentAddBook; | |
179 | - break; | |
180 | - case FRAG_BOOK_SHELF: | |
181 | - newFragment = mFragmentBookShelf; | |
182 | - break; | |
183 | - case FRAG_LOGIN: | |
184 | - newFragment = mFragmentLogin; | |
185 | - break; | |
208 | + public void addFragment(Fragment fragment, String title){ | |
209 | + mFragmentList.add(fragment); | |
210 | + mFragmentTitleList.add(title); | |
211 | + } | |
212 | + | |
213 | + @Override | |
214 | + public CharSequence getPageTitle(int position) { | |
215 | + return mFragmentTitleList.get(position); | |
216 | + } | |
217 | + | |
218 | + public int getPosition(String title){ | |
219 | + return mFragmentTitleList.indexOf(title); | |
186 | 220 | } |
187 | 221 | |
188 | - return newFragment; | |
189 | 222 | } |
223 | + | |
224 | + | |
190 | 225 | @Override |
191 | 226 | public void onClick(View v) { |
192 | 227 | switch( v.getId() ){ |
193 | 228 | case R.id.btn_login: |
194 | 229 | if( ((Button)v).getText().equals("LOGIN")){ |
195 | - fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_LOGIN); | |
230 | +// mViewPagerMain.setCurrentItem( mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_LOGIN)); | |
231 | + startActivity(new Intent(this, ActivityLogin.class)); | |
196 | 232 | } |
197 | 233 | else{ |
198 | 234 | Logger.i("Logout Request"); |
... | ... | @@ -252,7 +288,9 @@ public class MainActivity extends AppCompatActivity |
252 | 288 | case LOGIN_FAIL: |
253 | 289 | Toast.makeText(this, "로그인을 실패했습니다.", Toast.LENGTH_LONG).show(); |
254 | 290 | PreferenceUtil.getInstance(this).putIsLoggedInState(false); |
255 | - fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_LOGIN); | |
291 | +// fragmentReplace(Constants.FRAGMENT_SELECT.FRAG_LOGIN); | |
292 | + mViewPagerMain.setCurrentItem( mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_LOGIN)); | |
293 | + | |
256 | 294 | break; |
257 | 295 | } |
258 | 296 | } | ... | ... |
app/src/main/res/layout/activity_login.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
4 | + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" | |
5 | + android:orientation="vertical" | |
6 | + android:layout_width="match_parent" | |
7 | + android:layout_height="match_parent"> | |
8 | + | |
9 | + <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" | |
10 | + android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> | |
11 | + <android.support.v7.widget.Toolbar android:id="@+id/toolbar_login" | |
12 | + android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" | |
13 | + android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" > | |
14 | + </android.support.v7.widget.Toolbar> | |
15 | + </android.support.design.widget.AppBarLayout> | |
16 | + | |
17 | + <include layout="@layout/fragment_login" android:layout_width="match_parent" | |
18 | + android:layout_height="match_parent"/> | |
19 | + | |
20 | + | |
21 | + | |
22 | +</LinearLayout> | |
0 | 23 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/app_bar_main.xml
... | ... | @@ -13,6 +13,10 @@ |
13 | 13 | android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" |
14 | 14 | android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> |
15 | 15 | |
16 | + <android.support.design.widget.TabLayout android:id="@+id/tablayout_main" | |
17 | + android:layout_width="match_parent" android:layout_height="match_parent" | |
18 | + app:tabMode="fixed" app:tabGravity="center"/> | |
19 | + | |
16 | 20 | </android.support.design.widget.AppBarLayout> |
17 | 21 | |
18 | 22 | <include layout="@layout/content_main" /> | ... | ... |
app/src/main/res/layout/content_main.xml
... | ... | @@ -9,14 +9,19 @@ |
9 | 9 | app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/app_bar_main" |
10 | 10 | tools:context=".MainActivity"> |
11 | 11 | |
12 | - <LinearLayout | |
13 | - android:id="@+id/fragment_view" | |
14 | - android:layout_width="fill_parent" | |
15 | - android:layout_height="fill_parent" | |
16 | - android:orientation="horizontal" | |
17 | - android:layout_alignParentStart="true" | |
18 | - android:layout_below="@+id/listBookshelf"> | |
19 | - </LinearLayout> | |
12 | + <android.support.v4.view.ViewPager | |
13 | + android:id="@+id/viewPager_main" | |
14 | + android:layout_width="match_parent" | |
15 | + android:layout_height="match_parent" | |
16 | + app:layout_behavior="@string/appbar_scrolling_view_behavior"/> | |
17 | + <!--<LinearLayout--> | |
18 | + <!--android:id="@+id/fragment_view"--> | |
19 | + <!--android:layout_width="fill_parent"--> | |
20 | + <!--android:layout_height="fill_parent"--> | |
21 | + <!--android:orientation="horizontal"--> | |
22 | + <!--android:layout_alignParentStart="true"--> | |
23 | + <!--android:layout_below="@+id/listBookshelf">--> | |
24 | + <!--</LinearLayout>--> | |
20 | 25 | |
21 | 26 | <!--<fragment--> |
22 | 27 | <!--android:id="@+id/fragment_view"--> | ... | ... |
app/src/main/res/menu/login.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | + | |
3 | +<menu xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
5 | + xmlns:tools="http://schemas.android.com/tools" | |
6 | + tools:context=".ActivityLogin"> | |
7 | + | |
8 | + <item android:id="@+id/back" | |
9 | + android:title="NEXT" | |
10 | + app:showAsAction="ifRoom"/> | |
11 | + | |
12 | +</menu> | |
0 | 13 | \ No newline at end of file | ... | ... |
app/src/main/res/values/colors.xml
app/src/main/res/values/styles.xml
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | <item name="colorPrimary">@color/colorPrimary</item> |
7 | 7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item> |
8 | 8 | <item name="colorAccent">@color/colorAccent</item> |
9 | + <item name="windowActionBar">false</item> | |
10 | + <item name="windowNoTitle">true</item> | |
9 | 11 | </style> |
10 | 12 | <style name="AppTheme.NoActionBar"> |
11 | 13 | <item name="windowActionBar">false</item> | ... | ... |