diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..58b0054 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/com_1sters/app/MainActivity.java=UTF-8 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..5a08abd --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/ic_launcher-web.png b/ic_launcher-web.png new file mode 100644 index 0000000..a18cbb4 Binary files /dev/null and b/ic_launcher-web.png differ diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar new file mode 100644 index 0000000..187bdf4 Binary files /dev/null and b/libs/android-support-v4.jar differ diff --git a/libs/volley.jar b/libs/volley.jar new file mode 100644 index 0000000..fee2152 Binary files /dev/null and b/libs/volley.jar differ diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..4ab1256 --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/res/drawable-hdpi/action_search.png b/res/drawable-hdpi/action_search.png new file mode 100644 index 0000000..f12e005 Binary files /dev/null and b/res/drawable-hdpi/action_search.png differ diff --git a/res/drawable-hdpi/ic_drawer.png b/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 0000000..ff7b1de Binary files /dev/null and b/res/drawable-hdpi/ic_drawer.png differ diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..288b665 Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..6ae570b Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..d4fb7cd Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..85a6081 Binary files /dev/null and b/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/drawable/earth.jpg b/res/drawable/earth.jpg new file mode 100644 index 0000000..6cabbf4 Binary files /dev/null and b/res/drawable/earth.jpg differ diff --git a/res/drawable/mercury.jpg b/res/drawable/mercury.jpg new file mode 100644 index 0000000..531790b Binary files /dev/null and b/res/drawable/mercury.jpg differ diff --git a/res/drawable/venus.jpg b/res/drawable/venus.jpg new file mode 100644 index 0000000..e04f078 Binary files /dev/null and b/res/drawable/venus.jpg differ diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml new file mode 100644 index 0000000..8b27a2a --- /dev/null +++ b/res/layout/activity_main.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/res/layout/drawer_list_item.xml b/res/layout/drawer_list_item.xml new file mode 100644 index 0000000..e8d8639 --- /dev/null +++ b/res/layout/drawer_list_item.xml @@ -0,0 +1,11 @@ + diff --git a/res/layout/fragment_planet.xml b/res/layout/fragment_planet.xml new file mode 100644 index 0000000..27e1a5c --- /dev/null +++ b/res/layout/fragment_planet.xml @@ -0,0 +1,8 @@ + diff --git a/res/menu/main.xml b/res/menu/main.xml new file mode 100644 index 0000000..66ccd71 --- /dev/null +++ b/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/res/values-v11/styles.xml b/res/values-v11/styles.xml new file mode 100644 index 0000000..3c02242 --- /dev/null +++ b/res/values-v11/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/res/values-v14/styles.xml b/res/values-v14/styles.xml new file mode 100644 index 0000000..a91fd03 --- /dev/null +++ b/res/values-v14/styles.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/res/values-w820dp/dimens.xml b/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..f3e7020 --- /dev/null +++ b/res/values-w820dp/dimens.xml @@ -0,0 +1,10 @@ + + + + 64dp + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..5b33152 --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,13 @@ + + + + 1sters + Hello world! + Settings + Open drawer + Close drawer + Search + + + + diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/src/com_1sters/app/MainActivity.java b/src/com_1sters/app/MainActivity.java new file mode 100644 index 0000000..3f919a2 --- /dev/null +++ b/src/com_1sters/app/MainActivity.java @@ -0,0 +1,192 @@ +package com_1sters.app; + +import java.util.Locale; + +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.content.res.Configuration; +import android.os.Bundle; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.widget.DrawerLayout; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; + +public class MainActivity extends Activity { + + private String[] mPlanetTitles = new String [] {"话题", "文章", "工作"}; + private CharSequence mTitle; + private CharSequence mDrawerTitle; + + private DrawerLayout mDrawerLayout; + private ActionBarDrawerToggle mDrawerToggle; + private ListView mDrawerList; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mTitle = mDrawerTitle = getTitle(); + + mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mDrawerToggle = new DrawActionBarDrawerToggle( + this, + mDrawerLayout, + R.drawable.ic_drawer, + R.string.drawer_open, + R.string.drawer_close); + mDrawerLayout.setDrawerListener(mDrawerToggle); + + mDrawerList = (ListView) findViewById(R.id.left_drawer); + mDrawerList.setAdapter(new ArrayAdapter( + this, + R.layout.drawer_list_item, + mPlanetTitles)); + mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); + + getActionBar().setDisplayHomeAsUpEnabled(true); + getActionBar().setHomeButtonEnabled(true); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Sync the toggle state after onRestoreInstanceState has occurred. + mDrawerToggle.syncState(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Pass the event to ActionBarDrawerToggle, if it returns + // true, then it has handled the app icon touch event + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + // Handle your other action bar items... + + return super.onOptionsItemSelected(item); + } + + private class DrawerItemClickListener implements ListView.OnItemClickListener { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(position); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + // If the nav drawer is open, hide action items related to the content view + boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); + menu.findItem(R.id.action_search).setVisible(!drawerOpen); + return super.onPrepareOptionsMenu(menu); + } + + private void selectItem(int position) { + // Create a new fragment and specify the planet to show based on position + Fragment fragment = new PlanetFragment(); + Bundle args = new Bundle(); + args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); + fragment.setArguments(args); + + // Insert the fragment by replacing any existing fragment + FragmentManager fragmentManager = getFragmentManager(); + fragmentManager.beginTransaction() + .replace(R.id.content_frame, fragment) + .commit(); + + // Highlight the selected item, update the title, and close the drawer + mDrawerList.setItemChecked(position, true); + setTitle(mPlanetTitles[position]); + mDrawerLayout.closeDrawer(mDrawerList); + } + + @Override + public void setTitle(CharSequence title) { + mTitle = title; + getActionBar().setTitle(mTitle); + } + + /** + * Fragment that appears in the "content_frame", shows a planet + */ + public static class PlanetFragment extends Fragment { + + public static final String ARG_PLANET_NUMBER = "planet_number"; + private static final String [] mPlanets = new String [] {"Mercury", "Venus", "Earth"}; + + public PlanetFragment() { + // Empty constructor required for fragment subclasses + } + + @Override + public View onCreateView( + LayoutInflater inflater, + ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_planet, container, false); + + int i = getArguments().getInt(ARG_PLANET_NUMBER); + String planet = mPlanets[i]; + + int imageId = getResources().getIdentifier( + planet.toLowerCase(Locale.getDefault()), + "drawable", + getActivity().getPackageName()); + + ((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId); + + return rootView; + } + } + + private class DrawActionBarDrawerToggle extends ActionBarDrawerToggle { + + public DrawActionBarDrawerToggle( + Activity activity, + DrawerLayout drawerLayout, + int drawerImageRes, + int openDrawerContentDescRes, + int closeDrawerContentDescRes) { + super(activity, drawerLayout, drawerImageRes, openDrawerContentDescRes, + closeDrawerContentDescRes); + } + + public void onDrawerClosed(View view) { + super.onDrawerClosed(view); + getActionBar().setTitle(mTitle); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + getActionBar().setTitle(mDrawerTitle); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + + } + +}