Bläddra i källkod

上传文件至 'app\src\main\java\com\Intelligent\FamilyU\model\main'

生生化息 6 år sedan
förälder
incheckning
7646661c64
1 ändrade filer med 255 tillägg och 0 borttagningar
  1. 255 0
      app\src\main\java\com\Intelligent\FamilyU\model\main/MainActivity.java

+ 255 - 0
app\src\main\java\com\Intelligent\FamilyU\model\main/MainActivity.java

@@ -0,0 +1,255 @@
+package com.Intelligent.FamilyU.model.main;
+
+import android.content.Intent;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
+import android.support.v7.widget.RecyclerView;
+import android.view.KeyEvent;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+import com.Intelligent.FamilyU.base.BaseFragmentActivity;
+import com.Intelligent.FamilyU.base.BasePagerAdapter;
+import com.Intelligent.FamilyU.manager.ActivityStackManager;
+import com.Intelligent.FamilyU.model.home.fragment.HomeFurnishingFragment;
+import com.Intelligent.FamilyU.model.message.activity.MessageListActivity;
+import com.Intelligent.FamilyU.model.my.fragment.HomeMyFragment;
+import com.Intelligent.FamilyU.model.plugin.activity.PluginActivity;
+import com.Intelligent.FamilyU.model.scene.fragment.HomeSceneMainFragment;
+import com.Intelligent.FamilyU.model.shopping.fragment.HomeShopingFragment;
+import com.Intelligent.FamilyU.model.user.activity.UserListActivity;
+import com.Intelligent.FamilyU.utils.ToastUtils;
+import com.Intelligent.FamilyU.view.CustomViewPager;
+
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+
+/**
+ * 首頁
+ */
+public class MainActivity extends BaseFragmentActivity {
+
+    @BindView(R.id.view_pager)
+    CustomViewPager viewPager;
+    @BindView(R.id.page_title)
+    TextView titleTv;
+    @BindView(R.id.page_right_tv)
+    TextView pageRightTv;
+    @BindView(R.id.page_right_rl)
+    RelativeLayout pageRightRl;
+    @BindView(R.id.page_cancle)
+    TextView pageCancle;
+
+//    @BindView(R.id.drawer_layout)
+//    DrawerLayout drawerLayout;
+//    @BindView(R.id.header_rl)
+//    RelativeLayout headerRl;
+
+//    @BindView(R.id.user_list_number)
+//    TextView userNumberTv;
+//    @BindView(R.id.plugn_list_number)
+//    TextView plugnNumberTv;
+
+
+    private BasePagerAdapter mPagerAdapter;
+    private ArrayList<Fragment> mFragmentList = new ArrayList<>();
+    private SoftReference<Fragment> mHomeFurnishingFragment = null;
+    private SoftReference<Fragment> mHomeSceneFragment = null;
+    private SoftReference<Fragment> mHomeShopingFragment = null;
+    private SoftReference<Fragment> mHomeMyFragment = null;
+    private FragmentManager mFragmentManager = null;
+    private Fragment currentFragment = null;
+    private long clickTime = 0; // 第一次点击的时间
+
+//    private MainPluginListRecyclerViewAdapter adapter;
+//    private List<HashMap<String, String>> mlist = new ArrayList<HashMap<String, String>>();
+//    private LinearLayoutManager mLayoutManager;
+//    private String[] nameStrings = null;
+//
+//    private MainPluginListRecyclerViewAdapter.OnItemClickListener mOnItemClickListener = new MainPluginListRecyclerViewAdapter.OnItemClickListener() {
+//        @Override
+//        public void onItemClick(int postion) {
+//            //dapter.notifyDataSetChanged();
+//        }
+//
+//        @Override
+//        public void onItemLongClick(int postion) {
+//
+//        }
+//    };
+
+    @Override
+    protected int getContentViewId() {
+        return R.layout.drawerlayout_main;
+    }
+
+    @Override
+    protected void initBundleData() {
+
+    }
+
+    @Override
+    protected void initView() {
+        //initNavigationView();
+        //initAdapter();
+    }
+
+    @Override
+    protected void initData() {
+        mHomeFurnishingFragment = new SoftReference(new HomeFurnishingFragment());
+        mHomeSceneFragment = new SoftReference(new HomeSceneMainFragment());
+        mHomeShopingFragment = new SoftReference(new HomeShopingFragment());
+        mHomeMyFragment = new SoftReference(new HomeMyFragment());
+
+        mFragmentList.add(mHomeFurnishingFragment.get());
+        mFragmentList.add(mHomeSceneFragment.get());
+        mFragmentList.add(mHomeShopingFragment.get());
+        mFragmentList.add(mHomeMyFragment.get());
+        mFragmentManager = getSupportFragmentManager();
+
+        mPagerAdapter = new BasePagerAdapter(mFragmentManager, mFragmentList);
+        //设置Adapter
+        viewPager.setAdapter(mPagerAdapter);
+        viewPager.setScanScroll(false);
+        viewPager.setCurrentItem(0);
+        currentFragment = mFragmentList.get(0);
+        titleTv.setText(R.string.home_furnishing);
+        pageRightTv.setBackgroundResource(R.mipmap.icon_message);
+        pageRightRl.setVisibility(View.VISIBLE);
+     //   pageCancle.setBackgroundResource(R.mipmap.dlna_head_menu);
+
+//        userNumberTv.setText(mContext.getResources().getString(R.string.home_individual, 5));
+//        plugnNumberTv.setText(mContext.getResources().getString(R.string.home_individual, 3));
+    }
+
+//    private void initNavigationView() {
+//        //关闭手势滑动
+//        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+//        drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
+//            @Override
+//            public void onDrawerSlide(View view, float v) {
+//
+//            }
+//
+//            @Override
+//            public void onDrawerOpened(View view) {
+//
+//            }
+//
+//            @Override
+//            public void onDrawerClosed(View view) {
+//            }
+//
+//            @Override
+//            public void onDrawerStateChanged(int i) {
+//
+//            }
+//        });
+//    }
+
+//    @Override
+//    public boolean onOptionsItemSelected(MenuItem item) {
+//        if (item.getItemId() == android.R.id.home) {
+//            //打开抽屉侧滑菜单
+//            drawerLayout.openDrawer(GravityCompat.START);
+//        }
+//        return super.onOptionsItemSelected(item);
+//    }
+
+    @OnClick({R.id.main_page, R.id.main_scene, R.id.main_shopping, R.id.main_my, R.id.page_back, R.id.page_right_rl, R.id.user_list_ll, R.id.plugn_list_ll})
+    public void onClick(View v) {
+        Fragment mFragment = null;
+        switch (v.getId()) {
+            case R.id.main_page:
+                mFragment = mHomeFurnishingFragment.get();
+                if (!mFragment.isAdded()) {
+                    mFragmentList.set(0, mFragment);
+                }
+                currentFragment = switchFragment(mFragmentManager, currentFragment, mFragment);
+                viewPager.setCurrentItem(0);
+                titleTv.setText(R.string.home_furnishing);
+                pageRightRl.setVisibility(View.VISIBLE);
+                pageCancle.setVisibility(View.VISIBLE);
+                break;
+            case R.id.main_scene:
+                mFragment = mHomeSceneFragment.get();
+                if (!mFragment.isAdded()) {
+                    mFragmentList.set(1, mFragment);
+                }
+                currentFragment = switchFragment(mFragmentManager, currentFragment, mFragment);
+                viewPager.setCurrentItem(1);
+                titleTv.setText(R.string.home_scene);
+                pageRightRl.setVisibility(View.GONE);
+                break;
+            case R.id.main_shopping:
+                mFragment = mHomeShopingFragment.get();
+                if (!mFragment.isAdded()) {
+                    mFragmentList.set(2, mFragment);
+                }
+                currentFragment = switchFragment(mFragmentManager, currentFragment, mFragment);
+                viewPager.setCurrentItem(2);
+                titleTv.setText(R.string.home_shopping);
+                pageRightRl.setVisibility(View.GONE);
+                break;
+            case R.id.main_my:
+                mFragment = mHomeMyFragment.get();
+                if (!mFragment.isAdded()) {
+                    mFragmentList.set(3, mFragment);
+                }
+                currentFragment = switchFragment(mFragmentManager, currentFragment, mFragment);
+                viewPager.setCurrentItem(3);
+                titleTv.setText(R.string.home_my);
+                pageRightRl.setVisibility(View.GONE);
+                break;
+            case R.id.page_right_rl:
+                startActivity(new Intent(mContext, MessageListActivity.class));
+                break;
+            case R.id.page_back:
+                ActivityStackManager.getManager().exitApp(mContext);
+               // drawerLayout.openDrawer(headerRl);
+                break;
+        }
+    }
+
+
+    @Override
+    public void onBackPressed() {
+        exit();
+    }
+
+    @Override
+    public boolean onKeyDown(int keyCode, KeyEvent event) {
+        // 是否触发按键为back键
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            onBackPressed();
+            return true;
+        } else {
+            // 如果不是back键正常响应
+            return super.onKeyDown(keyCode, event);
+        }
+    }
+
+    private void exit() {
+        if ((System.currentTimeMillis() - clickTime) > 2000) {
+            ToastUtils.showToast(this, getResources().getString(R.string.home_exits));
+            clickTime = System.currentTimeMillis();
+        } else {
+            ActivityStackManager.getManager().exitApp(mContext);
+        }
+    }
+
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        ActivityStackManager.getManager().exitApp(mContext);
+    }
+}