Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <include layout="@layout/toolbar" />
- <androidx.drawerlayout.widget.DrawerLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/drawer_layout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="?attr/actionBarSize"
- android:fitsSystemWindows="false"
- android:orientation="vertical"
- tools:openDrawer="start">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <FrameLayout
- android:id="@+id/fragment_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- </FrameLayout>
- </LinearLayout>
- <com.google.android.material.navigation.NavigationView
- android:id="@+id/navigation_view"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_gravity="start|left"
- android:fitsSystemWindows="true"
- app:menu="@menu/navigation_menu" />
- <!--app:headerLayout="@layout/navigation_header"-->
- <include layout="@layout/activity_home" />
- </androidx.drawerlayout.widget.DrawerLayout>
- </RelativeLayout>
- toolbar.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <androidx.appcompat.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:background="@color/blueSecondary"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
- </androidx.appcompat.widget.Toolbar>
- </LinearLayout>
- homeactivity.xml
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".activity.HomeActivity">
- </androidx.constraintlayout.widget.ConstraintLayout>
- HomeActivity.java
- public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
- private NavigationView mNavigation;
- private DrawerLayout mdrawerLayout;
- private ActionBarDrawerToggle toggle;
- private Toolbar toolbar;
- private String token;
- private String title = "";
- private static final String TAG = "HomeActivity";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.navigation_drawer);
- //token = getIntent().getStringExtra("token");
- token = getSharedPreferences("TOKEN", 0)
- .getString("x", "");
- ;
- mNavigation = findViewById(R.id.navigation_view);
- //mNavigation.setNavigationItemSelectedListener(this);
- toolbar = findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- mdrawerLayout = findViewById(R.id.drawer_layout);
- toggle = new ActionBarDrawerToggle(HomeActivity.this, mdrawerLayout, toolbar,
- R.string.open, R.string.close);
- mdrawerLayout.setDrawerListener(toggle);
- //toolbar.setNavigationIcon(R.drawable.ic_account); //custome icon navigation
- toggle.syncState(); //use navigation icon burger
- //main layout
- if (savedInstanceState == null) {
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.fragment_container, new SummaryFragment(token))
- .commit();
- title = ("Summary 4 TV");
- mNavigation.setCheckedItem(R.id.menu_summary);
- //end main layout
- }
- retrotittoketn();
- }
- private void retrotittoketn() {
- ApiRetrofit retrofittoken = new ApiRetrofit();
- retrofittoken.ApiRetrofit2(token);
- }
- //implement method
- @Override
- public boolean onNavigationItemSelected(@NonNull MenuItem item) {
- int id = (item.getItemId());
- switch (id) {
- case R.id.menu_summary:
- title = ("Summary 4 TV");
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.fragment_container, new SummaryFragment(token))
- .commit();
- break;
- case R.id.menu_occupancyByTv:
- title = ("Occupancy By TV");
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.fragment_container, new OccupancyByTVFragment(token))
- .commit();
- break;
- case R.id.menu_occupancyDetail:
- title = ("Occupancy Detail");
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.fragment_container, new OccupancyDetailFragment())
- .commit();
- break;
- case R.id.menu_occupancy_industry:
- title = ("Occupancy Industry");
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.fragment_container, new OccupancyIndustryFragment())
- .commit();
- break;
- case R.id.menu_logout:
- startActivity(new Intent(getApplicationContext(), LoginActivity.class));
- finish();
- getSharedPreferences("TOKEN", 0)
- .edit()
- .clear()
- .apply();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- // open or close the drawer if home button is pressed
- mdrawerLayout.closeDrawer(GravityCompat.START);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement