Change number of columns in grids based on screen size. Make navigation view persistent if device is tablet in landscape mode.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.maptology.android.app.model.LocalShare;
|
||||
import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.UpdateUserTask;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
import com.maptology.android.feign.model.DeviceHandle;
|
||||
import com.maptology.android.feign.model.User;
|
||||
|
||||
@@ -117,11 +118,11 @@ public class MainActivity extends AppCompatActivity implements
|
||||
app = (MaptologyApp) getApplicationContext();
|
||||
LocationService.runService(this);
|
||||
setTitle(R.string.application_short);
|
||||
getSupportActionBar().setDisplayUseLogoEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
setContentView(R.layout.activity_main);
|
||||
if (TabletUtil.isLandscapeTablet(this)) {
|
||||
setContentView(R.layout.activity_main_tablet);
|
||||
} else {
|
||||
setContentView(R.layout.activity_main_default);
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
setScreen(Screen.MAP);
|
||||
}
|
||||
@@ -150,45 +151,33 @@ public class MainActivity extends AppCompatActivity implements
|
||||
usernameView = (TextView)header.findViewById(R.id.view_header_username);
|
||||
TextView deviceView = (TextView)header.findViewById(R.id.view_header_device);
|
||||
deviceView.setText(Build.MANUFACTURER + " " + Build.DEVICE);
|
||||
// toggle with burger icon
|
||||
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
setTitle(R.string.application_short);
|
||||
}
|
||||
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
setTitle(R.string.drawer_title);
|
||||
}
|
||||
|
||||
};
|
||||
drawerToggle.setDrawerIndicatorEnabled(true); // show burger icon
|
||||
drawerToggle.syncState(); // show burger / back arrow
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
getSupportActionBar().setDisplayUseLogoEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
prepareDrawerIfNeeded();
|
||||
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_notice:
|
||||
setScreen(Screen.NOTICE);
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_map:
|
||||
setScreen(Screen.MAP);
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_share:
|
||||
createShare();
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_manage:
|
||||
setScreen(Screen.MANAGE);
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
case R.id.menu_settings:
|
||||
showSettings();
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
closeDrawerIfNeeded();
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -202,17 +191,60 @@ public class MainActivity extends AppCompatActivity implements
|
||||
// override method so toggling with burger icon is possible
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
} else {
|
||||
drawerLayout.openDrawer(navigationView);
|
||||
}
|
||||
handleHomeIfNeeded();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles presses to the home button, if there is a drawer.
|
||||
*/
|
||||
private void handleHomeIfNeeded() {
|
||||
if (drawerLayout != null) {
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
} else {
|
||||
drawerLayout.openDrawer(navigationView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the drawer setup, if it is contained in the layout
|
||||
*/
|
||||
private void prepareDrawerIfNeeded() {
|
||||
if (drawerLayout != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
// toggle with burger icon
|
||||
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
setTitle(R.string.application_short);
|
||||
}
|
||||
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
setTitle(R.string.drawer_title);
|
||||
}
|
||||
|
||||
};
|
||||
drawerToggle.setDrawerIndicatorEnabled(true); // show burger icon
|
||||
drawerToggle.syncState(); // show burger / back arrow
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the drawer, if there is one.
|
||||
*/
|
||||
private void closeDrawerIfNeeded() {
|
||||
if (drawerLayout != null) {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to request location permission for the app.
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.UpdateGrantsTask;
|
||||
import com.maptology.android.app.util.ActionUtil;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
|
||||
import javax.xml.soap.Text;
|
||||
|
||||
@@ -133,7 +134,8 @@ public class GrantListFragment extends AbstractFragment {
|
||||
View view = inflater.inflate(R.layout.fragment_list_grant, container, false);
|
||||
explainText = view.findViewById(R.id.fragment_list_grant_explain);
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.grant_recycler);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 1));
|
||||
int span = (TabletUtil.isLandscapeTablet(view.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
swipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.fragment_grant_swipe);
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -17,6 +17,7 @@ import com.maptology.android.app.repository.IValueListener;
|
||||
import com.maptology.android.app.repository.Repository;
|
||||
import com.maptology.android.app.repository.Value;
|
||||
import com.maptology.android.app.task.SyncNoticeTask;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
|
||||
/**
|
||||
* A fragment to display a list of notices. This fragment is using the
|
||||
@@ -87,7 +88,8 @@ public class NoticeListFragment extends AbstractFragment {
|
||||
swipeLayout = (SwipeRefreshLayout)v.findViewById(R.id.fragment_notice_swipe);
|
||||
swipeLayout.setOnRefreshListener(refreshListener);
|
||||
recyclerView = (RecyclerView)v.findViewById(R.id.fragment_notice_recycler);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 1));
|
||||
int span = (TabletUtil.isLandscapeTablet(v.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.view.ViewGroup;
|
||||
import com.maptology.android.app.R;
|
||||
import com.maptology.android.app.adapter.ShareAdapter;
|
||||
import com.maptology.android.app.model.LocalShare;
|
||||
import com.maptology.android.app.util.TabletUtil;
|
||||
|
||||
/**
|
||||
* Shows a list of shares.
|
||||
@@ -79,7 +80,8 @@ public class ShareListFragment extends AbstractFragment {
|
||||
View view = inflater.inflate(R.layout.fragment_list_share, container, false);
|
||||
explainText = view.findViewById(R.id.fragment_list_share_explain);
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.share_recycler);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 1));
|
||||
int span = (TabletUtil.isLandscapeTablet(view.getContext()))?2:1;
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), span));
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.maptology.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
/**
|
||||
* Utility to detect tablets running in landscape mode.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class TabletUtil {
|
||||
|
||||
/**
|
||||
* Returns true if this device has a large screen.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if there is a large screen.
|
||||
*/
|
||||
public static boolean isTablet(Context context) {
|
||||
return (context.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this device is in landscape mode.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if landscape mode.
|
||||
*/
|
||||
public static boolean isLandscape(Context context) {
|
||||
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the device has a large screen AND is in landscape mode.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if tablet in landscape, false otherwise.
|
||||
*/
|
||||
public static boolean isLandscapeTablet(Context context) {
|
||||
return isLandscape(context) && isTablet(context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/navigation_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
app:headerLayout="@layout/view_drawer_header"
|
||||
app:menu="@menu/menu_drawer"/>
|
||||
|
||||
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/coordinator">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/container"
|
||||
android:orientation="vertical">
|
||||
</FrameLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user