Search in sources :

Example 16 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project LeMondeRssReader by MBach.

the class ArticleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initActivityTransitions();
    setContentView(R.layout.activity_article);
    appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    articleActivityRecyclerView = (ScrollFeedbackRecyclerView) findViewById(R.id.articleActivityRecyclerView);
    articleActivityRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fabProgressCircle = (FABProgressCircle) findViewById(R.id.fabProgressCircle);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            fabProgressCircle.show();
            List<Model> comments = loadMoreComments();
            fabProgressCircle.hide();
            if (comments.isEmpty()) {
                Snackbar.make(findViewById(R.id.coordinatorArticle), "Pas de nouveau commentaire", Snackbar.LENGTH_LONG).show();
            } else {
                ArticleAdapter adapter = (ArticleAdapter) articleActivityRecyclerView.getAdapter();
                adapter.insertItems(comments);
            }
        }
    });
    //ViewCompat.setTransitionName(appBarLayout, Constants.EXTRA_RSS_IMAGE);
    //supportPostponeEnterTransition();
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(extras.getString(Constants.EXTRA_NEWS_CATEGORY));
        final ImageView imageView = (ImageView) findViewById(R.id.imageArticle);
        Picasso.with(getBaseContext()).load(extras.getString(Constants.EXTRA_RSS_IMAGE)).into(imageView);
        try {
            Document doc = Jsoup.connect(extras.getString(Constants.EXTRA_RSS_LINK)).get();
            if (doc.getElementById("teaser_article") != null) {
                TextView paidArticle = (TextView) findViewById(R.id.paidArticle);
                paidArticle.setVisibility(View.VISIBLE);
            }
            Elements articles = doc.getElementsByTag("article");
            List<Model> items = null;
            if (!articles.isEmpty()) {
                Elements category = doc.select("div.tt_rubrique_ombrelle");
                if (atLeastOneChild(category)) {
                    getSupportActionBar().setTitle(category.text());
                }
                items = extractStandardArticle(articles);
                items.addAll(loadAndExtractCommentPreview(doc.getElementById("liste_reactions")));
            } else if (doc.getElementById("content") != null) {
                items = extractBlogArticle(doc);
            }
            if (items != null && !items.isEmpty()) {
                articleActivityRecyclerView.setAdapter(new ArticleAdapter(items));
            }
        } catch (IOException e) {
            Log.d(TAG, e.getMessage());
        }
    }
}
Also used : Bundle(android.os.Bundle) IOException(java.io.IOException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) ImageView(android.widget.ImageView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) FloatingActionButton(android.support.design.widget.FloatingActionButton) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 17 with CollapsingToolbarLayout

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

the class AccountActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    ButterKnife.bind(this);
    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;
    SharedPreferences preferences = getPrivatePreferences();
    String loggedInAccountId = preferences.getString("loggedInAccountId", null);
    // Setup the toolbar.
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    // Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.account_app_bar_layout);
    final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) 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);
            }
        }
    });
    // Initialise the default UI states.
    floatingBtn.hide();
    // Obtain information to fill out the profile.
    obtainAccount();
    if (!accountId.equals(loggedInAccountId)) {
        isSelf = false;
        obtainRelationships();
    } else {
        /* Cause the options menu to update and instead show an options menu for when the
             * account being shown is their own account. */
        isSelf = true;
        invalidateOptionsMenu();
    }
    // Setup the tabs and timeline pager.
    AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this, accountId);
    pagerAdapter = adapter;
    String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_follows), getString(R.string.title_followers) };
    adapter.setPageTitles(pageTitles);
    ViewPager 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);
    tabLayout.setupWithViewPager(viewPager);
    for (int i = 0; i < tabLayout.getTabCount(); i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        if (tab != null) {
            tab.setCustomView(adapter.getTabView(i, tabLayout));
        }
    }
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) ViewPager(android.support.v4.view.ViewPager) AttrRes(android.support.annotation.AttrRes) TabLayout(android.support.design.widget.TabLayout) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 18 with CollapsingToolbarLayout

use of android.support.design.widget.CollapsingToolbarLayout in project Synthese_2BIN by TheYoungSensei.

the class ItemDetailFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments().containsKey(ARG_ITEM_ID)) {
        // Load the dummy content specified by the fragment
        // arguments. In a real-world scenario, use a Loader
        // to load content from a content provider.
        //TODO mItem = Artist.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
        Activity activity = this.getActivity();
        CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
        if (appBarLayout != null) {
            appBarLayout.setTitle(mItem.content);
        }
    }
}
Also used : Activity(android.app.Activity) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout)

Aggregations

CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)18 View (android.view.View)9 Toolbar (android.support.v7.widget.Toolbar)6 AppBarLayout (android.support.design.widget.AppBarLayout)4 TextView (android.widget.TextView)4 Activity (android.app.Activity)3 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 Intent (android.content.Intent)2 UiController (android.support.test.espresso.UiController)2 ViewAction (android.support.test.espresso.ViewAction)2 ViewPager (android.support.v4.view.ViewPager)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Window (android.view.Window)2 ArrayList (java.util.ArrayList)2 ValueAnimator (android.animation.ValueAnimator)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1