Search in sources :

Example 26 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project iosched by google.

the class WelcomeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
    mContentFragment = getCurrentFragment(this);
    // If there's no fragment to use, we're done.
    if (mContentFragment == null) {
        finish();
    } else {
        // Wire up the fragment.
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        Fragment existing = fragmentManager.findFragmentById(R.id.welcome_content);
        if (existing != null) {
            fragmentTransaction.remove(existing);
        }
        fragmentTransaction.add(R.id.welcome_content, mContentFragment);
        fragmentTransaction.commit();
        CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        ctl.setBackgroundResource(mContentFragment.getHeaderColorRes());
        ImageView logo = (ImageView) ctl.findViewById(R.id.logo);
        logo.setImageResource(mContentFragment.getLogoDrawableRes());
    }
    GoogleSignInOptions gso = SignInManager.getGoogleSignInOptions(BuildConfig.DEFAULT_WEB_CLIENT_ID);
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    mSignInManager = new SignInManager(this, this, mGoogleApiClient);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) SignInManager(com.google.samples.apps.iosched.signin.SignInManager) ImageView(android.widget.ImageView) Fragment(android.support.v4.app.Fragment)

Example 27 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project malp by gateship-one.

the class MainActivity method setupToolbar.

@Override
public void setupToolbar(String title, boolean scrollingEnabled, boolean drawerIndicatorEnabled, boolean showImage) {
    // set drawer state
    mDrawerToggle.setDrawerIndicatorEnabled(drawerIndicatorEnabled);
    RelativeLayout collapsingImageLayout = findViewById(R.id.appbar_image_layout);
    ImageView collapsingImage = findViewById(R.id.collapsing_image);
    if (collapsingImage != null) {
        if (showImage) {
            collapsingImageLayout.setVisibility(View.VISIBLE);
            mHeaderImageActive = true;
            // Get the primary color of the active theme from the helper.
            int newColor = ThemeUtils.getThemeColor(this, R.attr.colorPrimaryDark);
            // Calculate the offset depending on the floating point position (0.0-1.0 of the view)
            // Shift by 24 bit to set it as the A from ARGB and set all remaining 24 bits to 1 to
            int alphaOffset = (((255 - (int) (255.0 * (mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP ? 0.0 : 1.0))) << 24) | 0xFFFFFF);
            // and with this mask to set the new alpha value.
            newColor &= (alphaOffset);
            getWindow().setStatusBarColor(newColor);
        } else {
            collapsingImageLayout.setVisibility(View.GONE);
            mHeaderImageActive = false;
            // Get the primary color of the active theme from the helper.
            getWindow().setStatusBarColor(ThemeUtils.getThemeColor(this, R.attr.colorPrimaryDark));
        }
    } else {
        // If in portrait mode (no collapsing image exists), the status bar also needs dark coloring
        mHeaderImageActive = false;
        // Get the primary color of the active theme from the helper.
        getWindow().setStatusBarColor(ThemeUtils.getThemeColor(this, R.attr.colorPrimaryDark));
    }
    // set scrolling behaviour
    CollapsingToolbarLayout toolbar = findViewById(R.id.collapsing_toolbar);
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
    params.height = -1;
    if (scrollingEnabled && !showImage) {
        toolbar.setTitleEnabled(false);
        setTitle(title);
        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
    } else if (!scrollingEnabled && showImage && collapsingImage != null) {
        toolbar.setTitleEnabled(true);
        toolbar.setTitle(title);
        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED + AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL);
    } else {
        toolbar.setTitleEnabled(false);
        setTitle(title);
        params.setScrollFlags(0);
    }
}
Also used : RelativeLayout(android.widget.RelativeLayout) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) ImageView(android.widget.ImageView) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 28 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project SimpleNews by liuling07.

the class NewsDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    mTVNewsContent = (HtmlTextView) findViewById(R.id.htNewsContent);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    mSwipeBackLayout = getSwipeBackLayout();
    mSwipeBackLayout.setEdgeSize(ToolsUtil.getWidthInPx(this));
    mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
    mNews = (NewsBean) getIntent().getSerializableExtra("news");
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(mNews.getTitle());
    ImageLoaderUtils.display(getApplicationContext(), (ImageView) findViewById(R.id.ivImage), mNews.getImgsrc());
    mNewsDetailPresenter = new NewsDetailPresenterImpl(getApplication(), this);
    mNewsDetailPresenter.loadNewsDetail(mNews.getDocid());
}
Also used : NewsDetailPresenterImpl(com.lauren.simplenews.news.presenter.NewsDetailPresenterImpl) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) NewsDetailView(com.lauren.simplenews.news.view.NewsDetailView) ImageView(android.widget.ImageView) HtmlTextView(org.sufficientlysecure.htmltextview.HtmlTextView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 29 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project Tusky by tuskyapp.

the class AccountActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    avatar = findViewById(R.id.account_avatar);
    header = findViewById(R.id.account_header);
    floatingBtn = findViewById(R.id.floating_btn);
    followBtn = findViewById(R.id.follow_btn);
    followsYouView = findViewById(R.id.account_follows_you);
    tabLayout = findViewById(R.id.tab_layout);
    accountLockedView = findViewById(R.id.account_locked);
    container = findViewById(R.id.activity_account);
    followersTextView = findViewById(R.id.followers_tv);
    followingTextView = findViewById(R.id.following_tv);
    statusesTextView = findViewById(R.id.statuses_btn);
    if (savedInstanceState != null) {
        accountId = savedInstanceState.getString("accountId");
        followState = (FollowState) savedInstanceState.getSerializable("followState");
        blocking = savedInstanceState.getBoolean("blocking");
        muting = savedInstanceState.getBoolean("muting");
    } else {
        Intent intent = getIntent();
        accountId = intent.getStringExtra("id");
        followState = FollowState.NOT_FOLLOWING;
        blocking = false;
        muting = false;
    }
    loadedAccount = null;
    // Setup the toolbar.
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    hideFab = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fabHide", false);
    // Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
    AppBarLayout appBarLayout = findViewById(R.id.account_app_bar_layout);
    final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @AttrRes
        int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            @AttrRes int attribute;
            if (collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
                toolbar.setTitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorPrimary));
                toolbar.setSubtitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorSecondary));
                attribute = R.attr.account_toolbar_icon_tint_collapsed;
            } else {
                toolbar.setTitleTextColor(Color.TRANSPARENT);
                toolbar.setSubtitleTextColor(Color.TRANSPARENT);
                attribute = R.attr.account_toolbar_icon_tint_uncollapsed;
            }
            if (attribute != priorAttribute) {
                priorAttribute = attribute;
                Context context = toolbar.getContext();
                ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute);
                ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute);
            }
            if (floatingBtn != null && hideFab && !isSelf && !blocking) {
                if (verticalOffset > oldOffset) {
                    floatingBtn.show();
                }
                if (verticalOffset < oldOffset) {
                    floatingBtn.hide();
                }
            }
            oldOffset = verticalOffset;
        }
    });
    // Initialise the default UI states.
    floatingBtn.hide();
    followBtn.setVisibility(View.GONE);
    followsYouView.setVisibility(View.GONE);
    // Obtain information to fill out the profile.
    obtainAccount();
    AccountEntity activeAccount = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (accountId.equals(activeAccount.getAccountId())) {
        isSelf = true;
    } else {
        isSelf = false;
        obtainRelationships();
    }
    // Setup the tabs and timeline pager.
    AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), accountId);
    String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_media) };
    adapter.setPageTitles(pageTitles);
    final ViewPager viewPager = findViewById(R.id.pager);
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(0);
    tabLayout.setupWithViewPager(viewPager);
    View.OnClickListener accountListClickListener = v -> {
        AccountListActivity.Type type;
        switch(v.getId()) {
            case R.id.followers_tv:
                type = AccountListActivity.Type.FOLLOWERS;
                break;
            case R.id.following_tv:
                type = AccountListActivity.Type.FOLLOWING;
                break;
            default:
                throw new AssertionError();
        }
        Intent intent = AccountListActivity.newIntent(AccountActivity.this, type, accountId);
        startActivity(intent);
    };
    followersTextView.setOnClickListener(accountListClickListener);
    followingTextView.setOnClickListener(accountListClickListener);
    statusesTextView.setOnClickListener(v -> {
        // Make nice ripple effect on tab
        // noinspection ConstantConditions
        tabLayout.getTabAt(0).select();
        final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0);
        poorTabView.setPressed(true);
        tabLayout.postDelayed(() -> poorTabView.setPressed(false), 300);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) Picasso(com.squareup.picasso.Picasso) Assert(com.keylesspalace.tusky.util.Assert) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) AttrRes(android.support.annotation.AttrRes) ViewCompat(android.support.v4.view.ViewCompat) Account(com.keylesspalace.tusky.entity.Account) PreferenceManager(android.preference.PreferenceManager) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) Fragment(android.support.v4.app.Fragment) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) NumberFormat(java.text.NumberFormat) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Menu(android.view.Menu) ActionBar(android.support.v7.app.ActionBar) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) DialogInterface(android.content.DialogInterface) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) LinkListener(com.keylesspalace.tusky.interfaces.LinkListener) Color(android.graphics.Color) Callback(retrofit2.Callback) Toolbar(android.support.v7.widget.Toolbar) CircularImageView(com.pkmmte.view.CircularImageView) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) Collections(java.util.Collections) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CircularImageView(com.pkmmte.view.CircularImageView) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) AttrRes(android.support.annotation.AttrRes) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AccountManager(com.keylesspalace.tusky.db.AccountManager) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 30 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project YalpStore by yeriomin.

the class Background method draw.

@Override
public void draw() {
    View background = activity.findViewById(R.id.background);
    CollapsingToolbarLayout collapsingToolbarLayout = activity.findViewById(R.id.collapsing_toolbar_layout);
    collapsingToolbarLayout.setExpandedTitleColor(activity.getResources().getColor(android.R.color.transparent));
    if (!NetworkUtil.isNetworkAvailable(activity) || (!app.isInPlayStore() && !TextUtils.isEmpty(app.getDeveloperName()) && null == app.getPageBackgroundImage())) {
        collapsingToolbarLayout.setTitleEnabled(false);
        collapsingToolbarLayout.getLayoutParams().height = CollapsingToolbarLayout.LayoutParams.MATCH_PARENT;
        background.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        background.setVisibility(View.GONE);
    } else {
        int height = DEFAULT_HEIGHT * smallerDimension / DEFAULT_WIDTH;
        collapsingToolbarLayout.setTitleEnabled(true);
        collapsingToolbarLayout.getLayoutParams().height = height;
        background.getLayoutParams().height = height;
        background.setVisibility(View.VISIBLE);
        if (null != app.getPageBackgroundImage()) {
            new LoadImageTask((ImageView) background).setPlaceholder(false).setFadeInMillis(500).setImageSource(app.getPageBackgroundImage()).executeOnExecutorIfPossible();
        }
    }
}
Also used : LoadImageTask(com.github.yeriomin.yalpstore.task.LoadImageTask) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)30 Toolbar (android.support.v7.widget.Toolbar)14 View (android.view.View)11 ImageView (android.widget.ImageView)10 AppBarLayout (android.support.design.widget.AppBarLayout)6 Activity (android.app.Activity)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 TextView (android.widget.TextView)5 Intent (android.content.Intent)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Bundle (android.os.Bundle)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)3 TabLayout (android.support.design.widget.TabLayout)3 ViewPager (android.support.v4.view.ViewPager)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 Drawable (android.graphics.drawable.Drawable)2 AttrRes (android.support.annotation.AttrRes)2 NonNull (android.support.annotation.NonNull)2 NavigationView (android.support.design.widget.NavigationView)2