forked from android-cn/android-open-project-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
479 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
android-Ultra-Pull-To-Refresh-demo/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...-To-Refresh-demo/app/src/main/java/com/grumoon/androidultrapulltorefreshdemo/AppHome.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
...pp/src/main/java/com/grumoon/androidultrapulltorefreshdemo/adapter/DrawerMenuAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.grumoon.androidultrapulltorefreshdemo.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.TextView; | ||
|
||
import com.grumoon.androidultrapulltorefreshdemo.R; | ||
import com.grumoon.androidultrapulltorefreshdemo.util.DataUtil; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by grumoon on 15/1/11. | ||
*/ | ||
public class DrawerMenuAdapter extends BaseAdapter { | ||
|
||
private int selectedIndex = 0; | ||
|
||
private List<HashMap<String, String>> menuList; | ||
private LayoutInflater layoutInflater; | ||
|
||
public DrawerMenuAdapter(Context context, List<HashMap<String, String>> menuList) { | ||
this.layoutInflater = LayoutInflater.from(context); | ||
this.menuList = menuList; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
if (menuList == null) { | ||
return 0; | ||
} | ||
return menuList.size(); | ||
} | ||
|
||
@Override | ||
public Object getItem(int position) { | ||
if (menuList == null || position > menuList.size() - 1) { | ||
return null; | ||
} | ||
return menuList.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
ViewHolder viewHolder = null; | ||
|
||
if (convertView == null) { | ||
viewHolder = new ViewHolder(); | ||
convertView = layoutInflater.inflate(R.layout.fragment_drawer_menu_item, parent, false); | ||
viewHolder.tvGroupName = (TextView) convertView.findViewById(R.id.tv_group_name); | ||
viewHolder.tvItemName = (TextView) convertView.findViewById(R.id.tv_item_name); | ||
convertView.setTag(viewHolder); | ||
|
||
} else { | ||
viewHolder = (ViewHolder) convertView.getTag(); | ||
} | ||
|
||
Map<String, String> menuItem = menuList.get(position); | ||
if (menuItem.containsKey(DataUtil.MENU_KEY_GROUP_NAME)) { | ||
viewHolder.tvGroupName.setText(menuItem.get(DataUtil.MENU_KEY_GROUP_NAME)); | ||
viewHolder.tvGroupName.setVisibility(View.VISIBLE); | ||
} else { | ||
viewHolder.tvGroupName.setVisibility(View.GONE); | ||
} | ||
|
||
viewHolder.tvItemName.setText(menuItem.get(DataUtil.MENU_KEY_ITEM_NAME)); | ||
|
||
if (position == selectedIndex) { | ||
viewHolder.tvItemName.setBackgroundResource(R.drawable.drawer_menu_item_selected_bg); | ||
} else { | ||
viewHolder.tvItemName.setBackgroundResource(R.drawable.drawer_menu_item_bg); | ||
} | ||
|
||
return convertView; | ||
} | ||
|
||
|
||
static class ViewHolder { | ||
TextView tvGroupName; | ||
TextView tvItemName; | ||
} | ||
|
||
|
||
public void setSelectedIndex(int position) { | ||
if (menuList != null && position < menuList.size()) { | ||
selectedIndex = position; | ||
notifyDataSetChanged(); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...-Refresh-demo/app/src/main/java/com/grumoon/androidultrapulltorefreshdemo/ui/AppHome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.grumoon.androidultrapulltorefreshdemo.ui; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.support.v7.app.ActionBarActivity; | ||
import android.support.v7.app.ActionBarDrawerToggle; | ||
import android.support.v7.widget.Toolbar; | ||
|
||
import com.grumoon.androidultrapulltorefreshdemo.R; | ||
|
||
public class AppHome extends ActionBarActivity { | ||
|
||
|
||
private Toolbar toolbar; | ||
private DrawerLayout dlHome; | ||
private ActionBarDrawerToggle drawerToggle; | ||
|
||
|
||
private FragmentManager fm; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_app_home); | ||
initView(); | ||
} | ||
|
||
private void initView() { | ||
|
||
toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
dlHome = (DrawerLayout) findViewById(R.id.dl_home); | ||
|
||
|
||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
drawerToggle = new ActionBarDrawerToggle(this, dlHome, toolbar, 0, 0); | ||
drawerToggle.syncState(); | ||
dlHome.setDrawerListener(drawerToggle); | ||
|
||
|
||
} | ||
|
||
|
||
public void drawerMenuClose() { | ||
dlHome.closeDrawers(); | ||
} | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...mo/app/src/main/java/com/grumoon/androidultrapulltorefreshdemo/ui/DrawerMenuFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.grumoon.androidultrapulltorefreshdemo.ui; | ||
|
||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AdapterView; | ||
import android.widget.ListView; | ||
|
||
import com.grumoon.androidultrapulltorefreshdemo.R; | ||
import com.grumoon.androidultrapulltorefreshdemo.adapter.DrawerMenuAdapter; | ||
import com.grumoon.androidultrapulltorefreshdemo.util.DataUtil; | ||
|
||
|
||
/** | ||
* A simple {@link Fragment} subclass. | ||
*/ | ||
public class DrawerMenuFragment extends Fragment { | ||
|
||
private ListView lvMenu; | ||
|
||
private DrawerMenuAdapter adapter; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.fragment_drawer_menu, container, false); | ||
initView(v); | ||
return v; | ||
} | ||
|
||
|
||
private void initView(View v) { | ||
|
||
lvMenu = (ListView) v.findViewById(R.id.lv_menu); | ||
adapter = new DrawerMenuAdapter(getActivity(), DataUtil.getMenuList()); | ||
lvMenu.setAdapter(adapter); | ||
|
||
lvMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||
adapter.setSelectedIndex(position); | ||
((AppHome) getActivity()).drawerMenuClose(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.