2016-08-21 13:29:42 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
2016-08-21 15:42:42 +00:00
|
|
|
import android.os.Build;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2016-08-21 15:21:37 +00:00
|
|
|
import android.support.annotation.IdRes;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
import com.topjohnwu.magisk.ui.LogFragment;
|
|
|
|
import com.topjohnwu.magisk.ui.ModulesFragment;
|
|
|
|
import com.topjohnwu.magisk.ui.RootFragment;
|
2016-08-22 19:50:46 +00:00
|
|
|
import com.topjohnwu.magisk.ui.utils.Utils;
|
2016-08-21 13:29:42 +00:00
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
|
|
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
|
|
|
|
|
|
|
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
|
|
|
private final Handler mDrawerHandler = new Handler();
|
|
|
|
|
|
|
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
|
|
|
@BindView(R.id.drawer_layout) DrawerLayout drawer;
|
|
|
|
@BindView(R.id.nav_view) NavigationView navigationView;
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
@IdRes
|
|
|
|
private int mSelectedId = R.id.modules;// for now
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_welcome);
|
|
|
|
ButterKnife.bind(this);
|
2016-08-21 15:42:42 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
|
|
}
|
2016-08-21 13:29:42 +00:00
|
|
|
|
2016-08-22 19:50:46 +00:00
|
|
|
Utils.initialize.execute();
|
|
|
|
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
|
|
|
|
@Override
|
|
|
|
public void onDrawerOpened(View drawerView) {
|
|
|
|
super.onDrawerOpened(drawerView);
|
|
|
|
super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDrawerSlide(View drawerView, float slideOffset) {
|
|
|
|
super.onDrawerSlide(drawerView, 0); // this disables the animation
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
drawer.addDrawerListener(toggle);
|
2016-08-21 13:29:42 +00:00
|
|
|
toggle.syncState();
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
//noinspection ResourceType
|
|
|
|
mSelectedId = savedInstanceState == null ? mSelectedId : savedInstanceState.getInt(SELECTED_ITEM_ID);
|
|
|
|
navigationView.setCheckedItem(mSelectedId);
|
2016-08-21 13:29:42 +00:00
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
if (savedInstanceState == null) {
|
2016-08-21 13:29:42 +00:00
|
|
|
mDrawerHandler.removeCallbacksAndMessages(null);
|
|
|
|
mDrawerHandler.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-08-21 15:21:37 +00:00
|
|
|
navigate(mSelectedId);
|
2016-08-21 13:29:42 +00:00
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
|
|
|
outState.putInt(SELECTED_ITEM_ID, mSelectedId);
|
2016-08-21 13:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
2016-08-21 15:21:37 +00:00
|
|
|
mSelectedId = menuItem.getItemId();
|
2016-08-21 13:29:42 +00:00
|
|
|
mDrawerHandler.removeCallbacksAndMessages(null);
|
|
|
|
mDrawerHandler.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
navigate(menuItem.getItemId());
|
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void navigate(final int itemId) {
|
|
|
|
Fragment navFragment = null;
|
|
|
|
switch (itemId) {
|
|
|
|
case R.id.root:
|
|
|
|
setTitle(R.string.root);
|
|
|
|
navFragment = new RootFragment();
|
|
|
|
break;
|
|
|
|
case R.id.modules:
|
|
|
|
setTitle(R.string.modules);
|
|
|
|
navFragment = new ModulesFragment();
|
|
|
|
break;
|
|
|
|
case R.id.log:
|
|
|
|
setTitle(R.string.log);
|
|
|
|
navFragment = new LogFragment();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (navFragment != null) {
|
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
|
|
|
|
try {
|
2016-08-21 14:42:50 +00:00
|
|
|
toolbar.setElevation(navFragment instanceof ModulesFragment ? 0 : 10);
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
transaction.replace(R.id.content_frame, navFragment).commit();
|
|
|
|
} catch (IllegalStateException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|