1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 04:41:16 +00:00

Fixed drawer width.

This commit is contained in:
George Venios 2015-09-06 13:52:35 +01:00
parent 020e593b1a
commit 507e841864

View file

@ -22,11 +22,14 @@ import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.R;
@ -38,6 +41,8 @@ import com.nutomic.syncthingandroid.syncthing.SyncthingService;
import java.util.Date; import java.util.Date;
import static java.lang.Math.min;
/** /**
* Shows {@link com.nutomic.syncthingandroid.fragments.FoldersFragment} and * Shows {@link com.nutomic.syncthingandroid.fragments.FoldersFragment} and
* {@link com.nutomic.syncthingandroid.fragments.DevicesFragment} in different tabs, and * {@link com.nutomic.syncthingandroid.fragments.DevicesFragment} in different tabs, and
@ -231,6 +236,7 @@ public class MainActivity extends SyncthingActivity
mDrawerToggle = new Toggle(this, mDrawerLayout); mDrawerToggle = new Toggle(this, mDrawerLayout);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerListener(mDrawerToggle);
setOptimalDrawerWidth(findViewById(R.id.drawer));
} }
@Override @Override
@ -337,6 +343,25 @@ public class MainActivity extends SyncthingActivity
return super.onKeyDown(keyCode, e); return super.onKeyDown(keyCode, e);
} }
/**
* Calculating width based on
* http://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs.
*/
private void setOptimalDrawerWidth(View drawerContainer) {
int actionBarSize = 0;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarSize = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
ViewGroup.LayoutParams params = drawerContainer.getLayoutParams();
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int minScreenWidth = min(displayMetrics.widthPixels, displayMetrics.heightPixels);
params.width = min(minScreenWidth - actionBarSize, 5 * actionBarSize);
drawerContainer.requestLayout();
}
/** /**
* Displays dialog asking user to accept/deny usage reporting. * Displays dialog asking user to accept/deny usage reporting.
*/ */