use of android.support.v7.app.ActionBar.LayoutParams in project Lightning-Browser by anthonycr.
the class BrowserActivity method initialize.
private synchronized void initialize(Bundle savedInstanceState) {
initializeToolbarHeight(getResources().getConfiguration());
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
//TODO make sure dark theme flag gets set correctly
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) : ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
mSwapBookmarksAndTabs = mPreferences.getBookmarksAndTabsSwapped();
// initialize background ColorDrawable
int primaryColor = ThemeUtils.getPrimaryColor(this);
mBackground.setColor(primaryColor);
// Drawer stutters otherwise
mDrawerLeft.setLayerType(View.LAYER_TYPE_NONE, null);
mDrawerRight.setLayerType(View.LAYER_TYPE_NONE, null);
mDrawerLayout.addDrawerListener(new DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerStateChanged(int newState) {
if (newState == DrawerLayout.STATE_DRAGGING) {
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else if (newState == DrawerLayout.STATE_IDLE) {
mDrawerLeft.setLayerType(View.LAYER_TYPE_NONE, null);
mDrawerRight.setLayerType(View.LAYER_TYPE_NONE, null);
}
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !mShowTabsInDrawer) {
getWindow().setStatusBarColor(Color.BLACK);
}
setNavigationDrawerWidth();
mDrawerLayout.addDrawerListener(new DrawerLocker());
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme);
final FragmentManager fragmentManager = getSupportFragmentManager();
TabsFragment tabsFragment = (TabsFragment) fragmentManager.findFragmentByTag(TAG_TABS_FRAGMENT);
BookmarksFragment bookmarksFragment = (BookmarksFragment) fragmentManager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
if (tabsFragment != null) {
fragmentManager.beginTransaction().remove(tabsFragment).commit();
}
tabsFragment = TabsFragment.createTabsFragment(isIncognito(), mShowTabsInDrawer);
mTabsView = tabsFragment;
if (bookmarksFragment != null) {
fragmentManager.beginTransaction().remove(bookmarksFragment).commit();
}
bookmarksFragment = BookmarksFragment.createFragment(isIncognito());
mBookmarksView = bookmarksFragment;
fragmentManager.executePendingTransactions();
fragmentManager.beginTransaction().replace(getTabsFragmentViewId(), tabsFragment, TAG_TABS_FRAGMENT).replace(getBookmarksFragmentViewId(), bookmarksFragment, TAG_BOOKMARK_FRAGMENT).commit();
if (mShowTabsInDrawer) {
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
}
Preconditions.checkNonNull(actionBar);
// set display options of the ActionBar
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.toolbar_content);
View customView = actionBar.getCustomView();
LayoutParams lp = customView.getLayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
customView.setLayoutParams(lp);
mArrowImage = (ImageView) customView.findViewById(R.id.arrow);
FrameLayout arrowButton = (FrameLayout) customView.findViewById(R.id.arrow_button);
if (mShowTabsInDrawer) {
if (mArrowImage.getWidth() <= 0) {
mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
}
updateTabNumber(0);
// Post drawer locking in case the activity is being recreated
Handlers.MAIN.post(new Runnable() {
@Override
public void run() {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getTabDrawer());
}
});
} else {
// Post drawer locking in case the activity is being recreated
Handlers.MAIN.post(new Runnable() {
@Override
public void run() {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, getTabDrawer());
}
});
mArrowImage.setImageResource(R.drawable.ic_action_home);
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
// Post drawer locking in case the activity is being recreated
Handlers.MAIN.post(new Runnable() {
@Override
public void run() {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getBookmarkDrawer());
}
});
arrowButton.setOnClickListener(this);
// create the search EditText in the ToolBar
mSearch = (SearchView) customView.findViewById(R.id.search);
mSearchBackground = customView.findViewById(R.id.search_container);
// initialize search background color
mSearchBackground.getBackground().setColorFilter(getSearchBarColor(primaryColor, primaryColor), PorterDuff.Mode.SRC_IN);
mSearch.setHintTextColor(ThemeUtils.getThemedTextHintColor(mDarkTheme));
mSearch.setTextColor(mDarkTheme ? Color.WHITE : Color.BLACK);
mUntitledTitle = getString(R.string.untitled);
mBackgroundColor = ThemeUtils.getPrimaryColor(this);
mDeleteIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
mRefreshIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_refresh, mDarkTheme);
mClearIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
int iconBounds = Utils.dpToPx(24);
mDeleteIcon.setBounds(0, 0, iconBounds, iconBounds);
mRefreshIcon.setBounds(0, 0, iconBounds, iconBounds);
mClearIcon.setBounds(0, 0, iconBounds, iconBounds);
mIcon = mRefreshIcon;
SearchListenerClass search = new SearchListenerClass();
mSearch.setCompoundDrawablePadding(Utils.dpToPx(3));
mSearch.setCompoundDrawables(null, null, mRefreshIcon, null);
mSearch.setOnKeyListener(search);
mSearch.setOnFocusChangeListener(search);
mSearch.setOnEditorActionListener(search);
mSearch.setOnTouchListener(search);
mSearch.setOnPreFocusListener(search);
initializeSearchSuggestions(mSearch);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START);
if (API <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//noinspection deprecation
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
}
@SuppressWarnings("VariableNotUsedInsideIf") Intent intent = savedInstanceState == null ? getIntent() : null;
boolean launchedFromHistory = intent != null && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0;
if (isPanicTrigger(intent)) {
setIntent(null);
panicClean();
} else {
if (launchedFromHistory) {
intent = null;
}
mPresenter.setupTabs(intent);
setIntent(null);
mProxyUtils.checkForProxy(this);
}
}
use of android.support.v7.app.ActionBar.LayoutParams in project platform_frameworks_base by android.
the class NavBarTuner method inflatePreview.
private void inflatePreview(ViewGroup view) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
boolean isRotated = display.getRotation() == Surface.ROTATION_90 || display.getRotation() == Surface.ROTATION_270;
Configuration config = new Configuration(getContext().getResources().getConfiguration());
boolean isPhoneLandscape = isRotated && (config.smallestScreenWidthDp < 600);
final float scale = isPhoneLandscape ? PREVIEW_SCALE_LANDSCAPE : PREVIEW_SCALE;
config.densityDpi = (int) (config.densityDpi * scale);
mPreview = (PreviewNavInflater) LayoutInflater.from(getContext().createConfigurationContext(config)).inflate(R.layout.nav_bar_tuner_inflater, view, false);
final ViewGroup.LayoutParams layoutParams = mPreview.getLayoutParams();
layoutParams.width = (int) ((isPhoneLandscape ? display.getHeight() : display.getWidth()) * scale);
// Not sure why, but the height dimen is not being scaled with the dp, set it manually
// for now.
layoutParams.height = (int) (layoutParams.height * scale);
if (isPhoneLandscape) {
int width = layoutParams.width;
layoutParams.width = layoutParams.height;
layoutParams.height = width;
}
view.addView(mPreview);
if (isRotated) {
mPreview.findViewById(R.id.rot0).setVisibility(View.GONE);
final View rot90 = mPreview.findViewById(R.id.rot90);
} else {
mPreview.findViewById(R.id.rot90).setVisibility(View.GONE);
final View rot0 = mPreview.findViewById(R.id.rot0);
}
}
use of android.support.v7.app.ActionBar.LayoutParams in project material-components-android by material-components.
the class CoordinatorSnackbarWithFabTest method testBehaviorBasedSlidingFromRuntimeApiCall.
@Test
public void testBehaviorBasedSlidingFromRuntimeApiCall() {
// Use a layout in which an AppCompatTextView child doesn't have any configured Behavior
onView(withId(R.id.coordinator_stub)).perform(inflateViewStub(R.layout.design_snackbar_behavior_runtime));
// and configure that Behavior at runtime by setting it on its LayoutParams
final AppCompatTextView textView = (AppCompatTextView) mCoordinatorLayout.findViewById(R.id.text);
final CoordinatorLayout.LayoutParams textViewLp = (CoordinatorLayout.LayoutParams) textView.getLayoutParams();
textViewLp.setBehavior(new TestFloatingBehavior());
// Create and show a snackbar
mSnackbar = Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_INDEFINITE).setAction(ACTION_TEXT, mock(View.OnClickListener.class));
SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(mSnackbar);
verifySnackbarViewStacking(textView, 0);
}
use of android.support.v7.app.ActionBar.LayoutParams in project TwinklingRefreshLayout by lcodecorex.
the class ScrollingUtil method isRecyclerViewToTop.
public static boolean isRecyclerViewToTop(RecyclerView recyclerView) {
if (recyclerView != null) {
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) {
return true;
}
if (manager.getItemCount() == 0) {
return true;
}
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
int firstChildTop = 0;
if (recyclerView.getChildCount() > 0) {
// 处理item高度超过一屏幕时的情况
View firstVisibleChild = recyclerView.getChildAt(0);
if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0);
} else {
return !ViewCompat.canScrollVertically(recyclerView, -1);
}
}
// 如果RecyclerView的子控件数量不为0,获取第一个子控件的top
// 解决item的topMargin不为0时不能触发下拉刷新
View firstChild = recyclerView.getChildAt(0);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild.getLayoutParams();
firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop();
}
if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) {
return true;
}
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null);
if (out[0] < 1) {
return true;
}
}
}
return false;
}
use of android.support.v7.app.ActionBar.LayoutParams in project android_frameworks_base by AOSPA.
the class NavBarTuner method inflatePreview.
private void inflatePreview(ViewGroup view) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
boolean isRotated = display.getRotation() == Surface.ROTATION_90 || display.getRotation() == Surface.ROTATION_270;
Configuration config = new Configuration(getContext().getResources().getConfiguration());
boolean isPhoneLandscape = isRotated && (config.smallestScreenWidthDp < 600);
final float scale = isPhoneLandscape ? PREVIEW_SCALE_LANDSCAPE : PREVIEW_SCALE;
config.densityDpi = (int) (config.densityDpi * scale);
mPreview = (PreviewNavInflater) LayoutInflater.from(getContext().createConfigurationContext(config)).inflate(R.layout.nav_bar_tuner_inflater, view, false);
final ViewGroup.LayoutParams layoutParams = mPreview.getLayoutParams();
layoutParams.width = (int) ((isPhoneLandscape ? display.getHeight() : display.getWidth()) * scale);
// Not sure why, but the height dimen is not being scaled with the dp, set it manually
// for now.
layoutParams.height = (int) (layoutParams.height * scale);
if (isPhoneLandscape) {
int width = layoutParams.width;
layoutParams.width = layoutParams.height;
layoutParams.height = width;
}
view.addView(mPreview);
if (isRotated) {
mPreview.findViewById(R.id.rot0).setVisibility(View.GONE);
final View rot90 = mPreview.findViewById(R.id.rot90);
} else {
mPreview.findViewById(R.id.rot90).setVisibility(View.GONE);
final View rot0 = mPreview.findViewById(R.id.rot0);
}
}
Aggregations