use of com.looklook.xinghongfei.looklook.presenter.implPresenter.MainPresenterImpl in project LookLook by xinghongfei.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
IMainPresenter = new MainPresenterImpl(this, this);
IMainPresenter.getBackground();
toolbar.setOnMenuItemClickListener(onMenuItemClick);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
animateToolbar();
}
addfragmentsAndTitle();
// setStatusColor();
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
if (savedInstanceState == null) {
nevigationId = SharePreferenceUtil.getNevigationItem(this);
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
}
if (currentMenuItem == null) {
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
if (currentMenuItem != null) {
currentMenuItem.setChecked(true);
// TODO: 16/8/17 add a fragment and set toolbar title
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
}
} else {
if (currentMenuItem != null) {
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
} else {
switchFragment(new ZhihuFragment(), " ");
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
}
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (currentMenuItem != item && currentMenuItem != null) {
currentMenuItem.setChecked(false);
int id = item.getItemId();
SharePreferenceUtil.putNevigationItem(MainActivity.this, id);
currentMenuItem = item;
currentMenuItem.setChecked(true);
switchFragment(getFragmentById(currentMenuItem.getItemId()), mTitleArryMap.get(currentMenuItem.getItemId()));
}
drawer.closeDrawer(GravityCompat.END, true);
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
mFragmentContainer.setPadding(mFragmentContainer.getPaddingLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(MainActivity.this), // landscape
mFragmentContainer.getPaddingRight() + insets.getSystemWindowInsetRight(), mFragmentContainer.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
}
int[][] state = new int[][] { // unchecked
new int[] { -android.R.attr.state_checked }, // pressed
new int[] { android.R.attr.state_checked } };
int[] color = new int[] { Color.BLACK, Color.BLACK };
int[] iconcolor = new int[] { Color.GRAY, Color.BLACK };
navView.setItemTextColor(new ColorStateList(state, color));
navView.setItemIconTintList(new ColorStateList(state, iconcolor));
//主题变色
MenuItem item = navView.getMenu().findItem(R.id.nav_theme);
mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mThemeSwitch.setChecked(isChecked);
if (isChecked) {
setThemeColor(Color.GREEN);
} else {
setThemeColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
});
}
Aggregations