List of usage examples for android.widget Toolbar addView
public void addView(View child)
Adds a child view.
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Trace.beginSection("onCreate()"); super.onCreate(savedInstanceState); if (RequestPermissionsActivity.startPermissionActivity(this) || RequestDesiredPermissionsActivity.startPermissionActivity(this)) { return;/*from ww w . j ava 2 s.co m*/ } final int previousScreenType = getIntent().getIntExtra(EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); Logger.logScreenView(this, ScreenType.QUICK_CONTACT, previousScreenType); if (CompatUtils.isLollipopCompatible()) { getWindow().setStatusBarColor(Color.TRANSPARENT); } processIntent(getIntent()); // Show QuickContact in front of soft input getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); setContentView(R.layout.quickcontact_activity); mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); mCollapsedSuggestionCardView = (CardView) findViewById(R.id.collapsed_suggestion_card); mExpandSuggestionCardView = (CardView) findViewById(R.id.expand_suggestion_card); mCollapasedSuggestionHeader = findViewById(R.id.collapsed_suggestion_header); mCollapsedSuggestionCardTitle = (TextView) findViewById(R.id.collapsed_suggestion_card_title); mExpandSuggestionCardTitle = (TextView) findViewById(R.id.expand_suggestion_card_title); mSuggestionSummaryPhoto = (ImageView) findViewById(R.id.suggestion_icon); mSuggestionForName = (TextView) findViewById(R.id.suggestion_for_name); mSuggestionContactsNumber = (TextView) findViewById(R.id.suggestion_for_contacts_number); mSuggestionList = (LinearLayout) findViewById(R.id.suggestion_list); mSuggestionsCancelButton = (Button) findViewById(R.id.cancel_button); mSuggestionsLinkButton = (Button) findViewById(R.id.link_button); if (savedInstanceState != null) { mIsSuggestionListCollapsed = savedInstanceState.getBoolean(KEY_IS_SUGGESTION_LIST_COLLAPSED, true); mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID); mSuggestionsShouldAutoSelected = savedInstanceState.getBoolean(KEY_SUGGESTIONS_AUTO_SELECTED, true); mSelectedAggregationIds = (TreeSet<Long>) savedInstanceState .getSerializable(KEY_SELECTED_SUGGESTION_CONTACTS); } else { mIsSuggestionListCollapsed = true; mSelectedAggregationIds.clear(); } if (mSelectedAggregationIds.isEmpty()) { disableLinkButton(); } else { enableLinkButton(); } mCollapasedSuggestionHeader.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mCollapsedSuggestionCardView.setVisibility(View.GONE); mExpandSuggestionCardView.setVisibility(View.VISIBLE); mIsSuggestionListCollapsed = false; mExpandSuggestionCardTitle.requestFocus(); mExpandSuggestionCardTitle.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); } }); mSuggestionsCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mCollapsedSuggestionCardView.setVisibility(View.VISIBLE); mExpandSuggestionCardView.setVisibility(View.GONE); mIsSuggestionListCollapsed = true; } }); mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); mContactCard.setOnClickListener(mEntryClickHandler); mContactCard.setExpandButtonText(getResources().getString(R.string.expanding_entry_card_view_see_all)); mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); mRecentCard.setOnClickListener(mEntryClickHandler); mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); mAboutCard.setOnClickListener(mEntryClickHandler); mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); mPhotoView = (QuickContactImageView) findViewById(R.id.photo); final View transparentView = findViewById(R.id.transparent_view); if (mScroller != null) { transparentView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mScroller.scrollOffBottom(); } }); } // Allow a shadow to be shown under the toolbar. ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); getActionBar().setTitle(null); // Put a TextView with a known resource id into the ActionBar. This allows us to easily // find the correct TextView location & size later. toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); mHasAlreadyBeenOpened = savedInstanceState != null; mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; mWindowScrim = new ColorDrawable(SCRIM_COLOR); mWindowScrim.setAlpha(0); getWindow().setBackgroundDrawable(mWindowScrim); mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); // mScroller needs to perform asynchronous measurements after initalize(), therefore // we can't mark this as GONE. mScroller.setVisibility(View.INVISIBLE); setHeaderNameText(R.string.missing_name); mSelectAccountFragmentListener = (SelectAccountDialogFragmentListener) getFragmentManager() .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); if (mSelectAccountFragmentListener == null) { mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); getFragmentManager().beginTransaction() .add(0, mSelectAccountFragmentListener, FRAGMENT_TAG_SELECT_ACCOUNT).commit(); mSelectAccountFragmentListener.setRetainInstance(true); } mSelectAccountFragmentListener.setQuickContactActivity(this); SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, new Runnable() { @Override public void run() { if (!mHasAlreadyBeenOpened) { // The initial scrim opacity must match the scrim opacity that would be // achieved by scrolling to the starting position. final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 1 : mScroller.getStartingTransparentHeightRatio(); final int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); final int desiredAlpha = (int) (0xFF * alphaRatio); ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, desiredAlpha) .setDuration(duration); o.start(); } } }); if (savedInstanceState != null) { final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, new Runnable() { @Override public void run() { // Need to wait for the pre draw before setting the initial scroll // value. Prior to pre draw all scroll values are invalid. if (mHasAlreadyBeenOpened) { mScroller.setVisibility(View.VISIBLE); mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); } // Need to wait for pre draw for setting the theme color. Setting the // header tint before the MultiShrinkScroller has been measured will // cause incorrect tinting calculations. if (color != 0) { setThemeColor(mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(color)); } } }); } Trace.endSection(); }