Permalink
Browse files

use MenuDrawer for slide bar

  • Loading branch information...
lytsing committed May 26, 2013
1 parent 3d6f203 commit 15e61dc2fbb556b68db21d2fe8a4d0e2aadc4938
View
@@ -24,7 +24,6 @@ All code that is contributed must be compliant with [Apache License 2.0](http://
Dependent three-part libraries projects:
* ActionBarSherlock http://actionbarsherlock.com/
* android-actionbar https://github.com/johannilsson/android-actionbar
* MenuDrawer https://github.com/SimonVT/android-menudrawer
* android-pulltorefresh-and-loadmore https://github.com/shontauro/android-pulltorefresh-and-loadmore
@@ -19,7 +19,7 @@
<application
android:label="@string/app_name"
android:name=".WeiboApplication"
android:icon="@drawable/icon"
android:icon="@drawable/ic_launcher"
android:theme="@style/Weibo"
android:hardwareAccelerated="true">
<activity
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFF" >
<fragment
android:id="@+id/left_menu"
android:name="org.lytsing.android.weibo.ui.MenuFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
View
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:paddingLeft="13.0dip"
android:paddingTop="16.0dip"
android:paddingBottom="16.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:layout_gravity="center_vertical"
android:id="@+id/slide_list_icon"
android:layout_width="32.0dip"
android:layout_height="32.0dip"
android:scaleType="centerCrop"
>
</ImageView>
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_vertical"
android:id="@+id/slide_list_title"
android:paddingLeft="13.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-1.0dip"
android:maxLines="1"
android:scrollHorizontally="true"
>
</TextView>
</LinearLayout>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Used in MenuFragment.java -->
<string-array name="slide_list_items">
<item>Home</item>
<item>Search</item>
</string-array>
</resources>
@@ -21,7 +21,7 @@
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.weibo.sdk.android.Oauth2AccessToken;
@@ -34,7 +34,7 @@
/**
* A base activity that handles common functionality in the app.
*/
public abstract class BaseActivity extends SherlockActivity {
public abstract class BaseActivity extends SherlockFragmentActivity {
private static final int TOAST_DURATION = Toast.LENGTH_SHORT;
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2013 lytsing.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lytsing.android.weibo.ui;
import android.os.Bundle;
import android.view.View;
import android.widget.SimpleAdapter;
import com.actionbarsherlock.app.SherlockListFragment;
import org.lytsing.android.weibo.R;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MenuFragment extends SherlockListFragment {
//String[] list_items = getSherlockActivity().getResources().getStringArray(R.array.slide_list_items);
String[] list_items = new String[] {"Home", "Settings", "Search", "Help"};
int[] icons = new int[]{
R.drawable.ic_menu_home,
android.R.drawable.ic_menu_preferences,
android.R.drawable.ic_menu_search,
android.R.drawable.ic_menu_help
};
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
for (int i = 0; i < list_items.length; i++) {
Map<String, Object> listItem = new HashMap<String, Object>();
listItem.put("values", list_items[i]);
listItem.put("images", icons[i]);
listItems.add(listItem);
}
SimpleAdapter adapter = new SimpleAdapter(getActivity(), listItems,
R.layout.slide, new String[] { "values", "images" },
new int[] { R.id.slide_list_title, R.id.slide_list_icon });
setListAdapter(adapter);
}
}
@@ -16,7 +16,6 @@
package org.lytsing.android.weibo.ui;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -28,6 +27,7 @@
import android.preference.PreferenceScreen;
import android.text.format.Formatter;
import com.actionbarsherlock.app.SherlockActivity;
import com.androidquery.util.AQUtility;
import org.lytsing.android.weibo.R;
@@ -36,7 +36,7 @@
import java.io.File;
public class SettingsActivity extends Activity {
public class SettingsActivity extends SherlockActivity {
private static SettingsActivity mSettingsActivity;
@@ -49,6 +49,8 @@ protected void onCreate(Bundle savedInstanceState) {
new SettingsFragment()).commit();
mSettingsActivity = this;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public static class SettingsFragment extends PreferenceFragment {
@@ -31,7 +31,6 @@
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
import com.actionbarsherlock.view.Window;
import com.androidquery.AQuery;
import com.commonsware.cwac.merge.MergeAdapter;
@@ -26,7 +26,6 @@
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.androidquery.AQuery;
import com.costum.android.widget.PullAndLoadListView;
import com.google.gson.Gson;
@@ -35,6 +34,8 @@
import com.weibo.sdk.android.api.WeiboAPI.FEATURE;
import com.weibo.sdk.android.net.RequestListener;
import net.simonvt.menudrawer.MenuDrawer;
import org.lytsing.android.weibo.Consts;
import org.lytsing.android.weibo.R;
import org.lytsing.android.weibo.StatusItemAdapter;
@@ -47,10 +48,14 @@
import java.io.IOException;
public class TimelineActivity extends BaseActivity {
private static final String STATE_MENUDRAWER = TimelineActivity.class.getName() + ".menuDrawer";
private StatusItemAdapter mAdapter = null;
private PullAndLoadListView mListView = null;
private MenuDrawer mMenuDrawer;
protected long mSinceId = 0;
@@ -59,9 +64,7 @@
private AQuery aq;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (hasAccessToken()) {
@@ -96,6 +99,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mMenuDrawer.toggleMenu();
break;
case R.id.compose:
startActivity(createComposeIntent());
break;
@@ -111,6 +117,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
private void initView() {
setContentView(R.layout.timeline);
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_WINDOW);
mMenuDrawer.setMenuView(R.layout.menu);
MenuFragment menu = (MenuFragment)getSupportFragmentManager().findFragmentById(R.id.left_menu);
menu.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 1) {
Intent intent = new Intent(TimelineActivity.this, SettingsActivity.class);
startActivity(intent);
}
mMenuDrawer.setActiveView(view);
mMenuDrawer.closeMenu();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
@@ -164,6 +190,29 @@ public void onItemClick(AdapterView<?> parent, View view,
}
});
}
@Override
protected void onRestoreInstanceState(Bundle inState) {
super.onRestoreInstanceState(inState);
mMenuDrawer.restoreState(inState.getParcelable(STATE_MENUDRAWER));
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(STATE_MENUDRAWER, mMenuDrawer.saveState());
}
@Override
public void onBackPressed() {
final int drawerState = mMenuDrawer.getDrawerState();
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
mMenuDrawer.closeMenu();
return;
}
super.onBackPressed();
}
private void showLoadingIndicator() {
aq.id(R.id.placeholder_loading).visible();
@@ -216,7 +265,6 @@ public void onComplete(String result) {
@Override
public void run() {
setSupportProgressBarIndeterminateVisibility(false);
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mListView.onRefreshComplete();

0 comments on commit 15e61dc

Please sign in to comment.