package com.example.dwight.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.Bmob;
import me.yokeyword.fragmentation.SupportActivity;
import me.yokeyword.fragmentation.SupportFragment;
import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator;
import me.yokeyword.fragmentation.anim.FragmentAnimator;
import com.example.dwight.myapplication.ui.BaseMainFragment;
import com.example.dwight.myapplication.ui.fragment.account.LoginFragment;
import com.example.dwight.myapplication.ui.fragment.discover.DiscoverFragment;
import com.example.dwight.myapplication.ui.fragment.home.HomeFragment;
import com.example.dwight.myapplication.ui.fragment.shop.ShopFragment;
import com.example.dwight.myapplication.ui.fragment_swipe_back.SwipeBackSampleFragment;
/**
* Created by YoKeyword on 16/1/29.
*/
public class MainActivity extends SupportActivity
implements NavigationView.OnNavigationItemSelectedListener, BaseMainFragment.OnFragmentOpenDrawerListener
, LoginFragment.OnLoginSuccessListener, SwipeBackSampleFragment.OnLockDrawLayoutListener {
public static final String TAG = MainActivity.class.getSimpleName();
private DrawerLayout mDrawer;
private NavigationView mNavigationView;
private TextView mTvName; // NavigationView上的名字
private ImageView mImgNav; // NavigationView上的头像
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bmob.initialize(this, "dd4c63ac45326ba15f7b6ea5cfa5c648");
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
start(HomeFragment.newInstance());
}
initView();
}
@Override
protected FragmentAnimator onCreateFragmentAnimator() {
// 设置默认Fragment动画 默认竖向(和安卓5.0以上的动画相同)
return super.onCreateFragmentAnimator();
// 设置横向(和安卓4.x动画相同)
// return new DefaultHorizontalAnimator();
// 设置自定义动画
// return new FragmentAnimator(enter,exit,popEnter,popExit);
}
private void initView() {
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
// mDrawer.setDrawerListener(toggle);
toggle.syncState();
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
mNavigationView.setCheckedItem(R.id.nav_home);
LinearLayout llNavHeader = (LinearLayout) mNavigationView.getHeaderView(0);
mTvName = (TextView) llNavHeader.findViewById(R.id.tv_name);
mImgNav = (ImageView) llNavHeader.findViewById(R.id.img_nav);
llNavHeader.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawer.closeDrawer(GravityCompat.START);
mDrawer.postDelayed(new Runnable() {
@Override
public void run() {
goLogin();
}
}, 250);
}
});
}
@Override
public int setContainerId() {
return R.id.fl_container;
}
@Override
public void onBackPressed() {
if (mDrawer.isDrawerOpen(GravityCompat.START)) {
mDrawer.closeDrawer(GravityCompat.START);
} else {
Fragment topFragment = getTopFragment();
// 主页的Fragment
if (topFragment instanceof DiscoverFragment || topFragment instanceof ShopFragment) {
mNavigationView.setCheckedItem(R.id.nav_home);
}
super.onBackPressed();
}
}
/**
* 打开抽屉
*/
@Override
public void onOpenDrawer() {
if (!mDrawer.isDrawerOpen(GravityCompat.START)) {
mDrawer.openDrawer(GravityCompat.START);
}
}
@Override
public boolean onNavigationItemSelected(final MenuItem item) {
mDrawer.closeDrawer(GravityCompat.START);
mDrawer.postDelayed(new Runnable() {
@Override
public void run() {
int id = item.getItemId();
final SupportFragment topFragment = getTopFragment();
if (id == R.id.nav_home) {
HomeFragment fragment = findFragment(HomeFragment.class);
Bundle newBundle = new Bundle();
newBundle.putString("from", "主页-->来自:" + topFragment.getClass().getSimpleName());
fragment.putNewBundle(newBundle);
start(fragment, SupportFragment.SINGLETASK);
} else if (id == R.id.nav_discover) {
DiscoverFragment fragment = findFragment(DiscoverFragment.class);
if (fragment == null) {
popTo(HomeFragment.class, false, new Runnable() {
@Override
public void run() {
start(DiscoverFragment.newInstance());
}
});
} else {
// 如果已经在栈内,则以SingleTask模式start
start(fragment, SupportFragment.SINGLETASK);
}
} else if (id == R.id.nav_msg) {
ShopFragment fragment = findFragment(ShopFragment.class);
if (fragment == null) {
popTo(HomeFragment.class, false, new Runnable() {
@Override
public void run() {
start(ShopFragment.newInstance());
}
});
} else {
// 如果已经在栈内,则以SingleTask模式start
// start(fragment, SupportFragment.SINGLETASK);
popTo(ShopFragment.class, false);
}
} else if (id == R.id.nav_login) {
goLogin();
} else if (id == R.id.nav_swipe_back) {
startActivity(new Intent(MainActivity.this, SwipeBackSampleActivity.class));
} else if (id == R.id.nav_swipe_back_f) {
start(SwipeBackSampleFragment.newInstance());
}
}
}, 250);
return true;
}
private void goLogin() {
start(LoginFragment.newInstance());
}
@Override
public void onLoginSuccess(String account) {
mTvName.setText(account);
mImgNav.setImageResource(R.drawable.ic_account_circle_white_48dp);
Toast.makeText(this, "登录成功,NavigationView的用户名已经更改!", Toast.LENGTH_SHORT).show();
}
@Override
public void onLockDrawLayout(boolean lock) {
if (lock) {
mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android安卓期末大作业-新闻阅读App
共112个文件
xml:43个
java:30个
png:26个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 5 下载量 31 浏览量
2023-11-02
17:36:45
上传
评论 8
收藏 451KB ZIP 举报
温馨提示
界面美观,功能齐全,适合用作毕业设计、课程设计作业等,项目均经过测试,可快速部署运行! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 -------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
资源推荐
资源详情
资源评论
收起资源包目录
Android安卓期末大作业-新闻阅读App (112个子文件)
gradlew.bat 2KB
.gitignore 97B
.gitignore 7B
build.gradle 2KB
build.gradle 661B
settings.gradle 15B
gradlew 5KB
dom4j-1.6.1.jar 307KB
gradle-wrapper.jar 52KB
MainActivity.java 8KB
HomeFragment.java 7KB
MenuListFragment.java 4KB
RegisterFragment.java 4KB
DetailFragment.java 4KB
LoginFragment.java 3KB
MenuAdapter.java 3KB
ModifyDetailFragment.java 3KB
PagerChildFragment.java 3KB
ShopFragment.java 3KB
ContentFragment.java 3KB
HomeAdapter.java 2KB
CycleFragment.java 2KB
PagerAdapter.java 2KB
RecyclerSwipeBackFragment.java 2KB
BaseMainFragment.java 2KB
DiscoverFragment.java 2KB
SwipeBackSampleFragment.java 2KB
FirstSwipeBackFragment.java 1KB
SwipeBackSampleActivity.java 1KB
DiscoverFragmentAdapter.java 1KB
BaseFragment.java 972B
BaseSwipeBackFragment.java 727B
BaseBackFragment.java 632B
article_demo.java 580B
Article.java 572B
ApplicationTest.java 363B
ExampleUnitTest.java 325B
OnItemLongClickListener.java 179B
OnItemClickListener.java 172B
.name 13B
ic_launcher.png 10KB
ic_launcher.png 8KB
ic_launcher.png 5KB
ic_launcher.png 3KB
ic_account_circle_white_48dp.png 2KB
ic_launcher.png 2KB
internet_news_reader_24px.png 2KB
ic_account_circle_white_48dp.png 2KB
ic_discover_white_24dp.png 1KB
ic_home_white_24dp.png 1KB
ic_settings_white_24dp.png 1KB
ic_discover_white_24dp.png 935B
ic_touch_app_white_24dp.png 793B
ic_home_white_24dp.png 774B
ic_settings_white_24dp.png 674B
ic_touch_app_white_24dp.png 532B
ic_arrow_back_white_24dp.png 374B
ic_arrow_forward_white_24dp.png 366B
ic_message_white_24dp.png 347B
ic_format_list_numbered_white_24dp.png 295B
ic_arrow_forward_white_24dp.png 261B
ic_message_white_24dp.png 247B
ic_arrow_back_white_24dp.png 233B
ic_format_list_numbered_white_24dp.png 211B
ic_menu_white_24dp.png 183B
ic_menu_white_24dp.png 135B
proguard-rules.pro 656B
gradle.properties 855B
gradle-wrapper.properties 231B
strings.xml 7KB
fragment_login.xml 3KB
fragment_register.xml 3KB
misc.xml 2KB
fragment_detail.xml 2KB
AndroidManifest.xml 2KB
fragment_discover.xml 2KB
fragment_home.xml 2KB
nav_header_main.xml 2KB
item_home.xml 1KB
styles.xml 1KB
activity_main_drawer.xml 1KB
fragment_cycle.xml 1KB
item_menu.xml 1KB
activity_main.xml 1KB
fragment_modify_detail.xml 953B
fragment_swipe_back.xml 933B
fragment_content.xml 923B
fragment_shop.xml 888B
fragment_swipe_back_first.xml 857B
item_pager.xml 827B
gradle.xml 816B
content_detail.xml 759B
compiler.xml 686B
home_pop.xml 583B
runConfigurations.xml 564B
toolbar.xml 550B
activity_swipe_back.xml 528B
dimens.xml 524B
swipe_orientation.xml 507B
fragment_swipe_back_recy.xml 484B
共 112 条
- 1
- 2
资源评论
- 兽兽鸭.2024-06-05感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
- gAmbler_0712024-04-30非常有用的资源,有一定的参考价值,受益匪浅,值得下载。
- xiaoli32312422024-01-15资源内容详细全面,与描述一致,对我很有用,有一定的使用价值。
- 我看你像没睡醒2024-06-11超级好的资源,很值得参考学习,对我启发很大,支持!
- 2301_813498542024-01-10这个资源对我启发很大,受益匪浅,学到了很多,谢谢分享~
机智的程序员zero
- 粉丝: 2423
- 资源: 5033
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功