Java Code Examples for android.support.v7.widget.Toolbar#inflateMenu()

The following examples show how to use android.support.v7.widget.Toolbar#inflateMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewPictureActivity.java    From Swface with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_view_picture);
	Intent intent = getIntent();
	userHasSigned = (UserHasSigned) intent.getSerializableExtra("userHasSigned");
	faceTokenAndUrl = intent.getStringExtra("faceTokenAndUrl");
	imageView_face = (ImageView) findViewById(R.id.imageView_face);
	toolbar = (Toolbar) findViewById(R.id.toolbar_view_picture);
	toolbar.setNavigationIcon(R.mipmap.button_back);
	toolbar.setNavigationOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			finish();
		}
	});
	toolbar.setTitle(userHasSigned.getUser_name()+"的人脸照片");
	toolbar.inflateMenu(R.menu.base_toolbar_menu);

	startViewPicture();
}
 
Example 2
Source File: MainActivity.java    From InkPageIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ViewPager viewPager = findViewById(R.id.image_view_pager);
    ArrayList<String> images = new ArrayList<>();
    images.add(IMAGE_URL);
    images.add("http://static1.squarespace.com/static/51609147e4b0715db61d32b6/521b97cee4b05f031fd12dde/5519e33de4b06a1002802805/1431718693701/?format=1500w");
    images.add("http://phandroid.s3.amazonaws.com/wp-content/uploads/2014/12/Ultimate-Material-Lollipop-Collection-407.png");
    final ImageAdapter adapter = new ImageAdapter(images);
    viewPager.setAdapter(adapter);

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    toolbar.inflateMenu(R.menu.menu_main);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_remove:
                    adapter.removeLast();
                    return true;
                case R.id.action_add:
                    adapter.add(IMAGE_URL);
                    return true;
            }
            return false;
        }
    });


    InkPageIndicator inkPageIndicator = findViewById(R.id.ink_pager_indicator);
    inkPageIndicator.setViewPager(viewPager);
}
 
Example 3
Source File: ChapterFragment.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void initToolbarMenu(Toolbar toolbar) {
    toolbar.inflateMenu(R.menu.menu_article_pop);
    menu = toolbar.getMenu();
    menu.getItem(0).setVisible(false);
    menu.getItem(1).setVisible(false);
}
 
Example 4
Source File: AvatarToolbarSample.java    From CollapsingAvatarToolbar with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_avatar_toolbar_sample);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.menu_avatar_toolbar_sample);
    toolbar.setNavigationIcon(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha);
}
 
Example 5
Source File: AddDeviceActivity.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_add_device);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.activity_add_device);
}
 
Example 6
Source File: ActionBarCastActivity.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
protected void initializeToolbar() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar == null) {
        throw new IllegalStateException("Layout is required to include a Toolbar with id " +
                "'toolbar'");
    }
    mToolbar.inflateMenu(R.menu.main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    if (mDrawerLayout != null) {
        mDrawerList = (ListView) findViewById(R.id.drawer_list);
        if (mDrawerList == null) {
            throw new IllegalStateException("A layout with a drawerLayout is required to" +
                    "include a ListView with id 'drawerList'");
        }

        // Create an ActionBarDrawerToggle that will handle opening/closing of the drawer:
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                mToolbar, R.string.open_content_drawer, R.string.close_content_drawer);
        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setStatusBarBackgroundColor(
                ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.black));
        populateDrawerItems();
        setSupportActionBar(mToolbar);
        updateDrawerToggle();
    } else {
        setSupportActionBar(mToolbar);
    }

    mToolbarInitialized = true;
}
 
Example 7
Source File: Test3Activity.java    From YCStateLayout with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化toolbar
 */
private void initToolBar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.tb_bar);
    toolbar.setTitleTextColor(Color.WHITE);
    toolbar.setTitle("状态切换");
    toolbar.inflateMenu(R.menu.base_toolbar_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if(item.getItemId() == R.id.action_contents) {
                showContent();
            }
            if(item.getItemId() == R.id.action_emptyData) {
                initEmptyDataView();
            }
            if(item.getItemId() == R.id.action_error) {
                initErrorDataView();
            }
            if(item.getItemId() == R.id.action_networkError) {
                initSettingNetwork();
            }
            if(item.getItemId() == R.id.action_loading) {
                statusLayoutManager.showLoading();
            }
            return true;
        }
    });
}
 
Example 8
Source File: DebugSettingsListFragment.java    From United4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * adds a close button to the menu bar
 * @param toolbar the toolbar
 */
public void addOptions(Toolbar toolbar) {
    toolbar.setTitle(R.string.app_name);
    toolbar.getMenu().clear();
    toolbar.inflateMenu(R.menu.debug_menu);
    toolbar.inflateMenu(R.menu.back_item);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            //noinspection SwitchStatementWithoutDefaultBranch
            switch (item.getItemId()) {
                case R.id.back_item:
                    getActivity().finish();
                    return true;
                case R.id.reload_all:
                    NotifierService.notify(NotifierService.NotificationType.RELOAD_ALL);
                    return true;
                case R.id.reload_index:
                    NotifierService.notify(NotifierService.NotificationType.RELOAD_INDEX);
                    return true;
                case R.id.reload_music:
                    NotifierService.notify(NotifierService.NotificationType.RELOAD_MUSIC);
                    return true;
                case R.id.invalidate_toolbar:
                    ((HiddenSettingsActivity) getActivity()).invalidateToolbarColor();
                    NotifierService.notify(NotifierService.NotificationType.INVALIDATE_TOOLBAR);
                    return true;
            }
            return false;
        }
    });
}
 
Example 9
Source File: ColorListFragment.java    From United4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * adds a close button to the menu bar
 *
 * @param toolbar the toolbar
 */
public void addOptions(Toolbar toolbar) {
    toolbar.setTitle(R.string.app_name);
    toolbar.getMenu().clear();
    toolbar.inflateMenu(R.menu.back_item);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().finish();
            return true;
        }
    });
}
 
Example 10
Source File: MainActivity.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setNavigationIcon(R.mipmap.ic_nav_main);
    mToolbar.setOnMenuItemClickListener(this);
    mToolbar.inflateMenu(R.menu.menu_main);

    initSyncItem();
    initTitle();

    mCreate = findViewById(R.id.main_img_create);
    mCreate.setOnClickListener(this);

    mAdapter = new SectionsPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setOnPageChangeListener(mAdapter);
    mPager.setPageTransformer(true, new ZoomOutPageTransformer());

    mPresenter = new SyncPresenter(this);

    // Get the Create button Translation 56+16+8 dp
    mCreateTranslationY = (int) (getResources().getDisplayMetrics().density * 80);
}
 
Example 11
Source File: AwooEndpointFragment.java    From United4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * adds a close option to the toolbar
 * @param toolbar the toolbar to update
 */
public void addOptions(Toolbar toolbar) {
    toolbar.setTitle(R.string.app_name);
    toolbar.getMenu().clear();
    toolbar.inflateMenu(R.menu.back_item);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().finish();
            return true;
        }
    });
}
 
Example 12
Source File: CustomListActivity.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_customlist);

	// Set up toolbar
	Toolbar mainToolbar = setupDefaultUpButton();
	mainToolbar.inflateMenu(R.menu.menu_delete);

	EditText listNameEdit = (EditText) findViewById(R.id.list_name_edit);
	beersList = (RecyclerView) findViewById(R.id.beers_list);
	emptyText = (TextView) findViewById(R.id.empty_text);

	customListBeersAdapter = new CustomListBeersAdapter();
	beersList.setLayoutManager(new LinearLayoutManager(this));
	beersList.setAdapter(customListBeersAdapter);

	long listId = getIntent().getLongExtra("listId", 0);
	if (listId > 0) {
		list = database(this).get(CustomList.class, listId);
		listNameEdit.setText(list.name);
	} else {
		// Create and directly save, such that we have an id to bind beers to
		list = new CustomList();
		rxdb(this).put(list);
	}

	// Allow deleting the entire list
	RxToolbar.itemClicks(mainToolbar).compose(onUi())
			.filter(item -> item.getItemId() == R.id.menu_delete).compose(toIo())
			.flatMap(event -> Db.deleteCustomList(this, list)).compose(toUi())
			.doOnEach(RBLog::rx)
			.first().toCompletable()
			.subscribe(this::finish, e -> Snackbar.show(this, R.string.error_unexpectederror));

	// Directly persist name changes
	RxTextView.textChanges(listNameEdit)
			.map(name -> {
				list.name = name.toString();
				return list;
			})
			.compose(bindToLifecycle())
			.subscribe(rxdb(this).put(), e -> RBLog.e("Error persisting the list name", e));

	// Directly visualize item changes
	Db.getCustomListBeerChanges(this, list._id)
			.compose(bindToLifecycle())
			.subscribe(
					change -> customListBeersAdapter.change(change),
					e -> RBLog.e("Error handling a beer list change", e));

	// Load current beers list and always have it update the empty view visibility when adding/removing beers
	Db.getCustomListBeers(this, list._id)
			.toList()
			.compose(onIoToUi())
			.compose(bindToLifecycle())
			.subscribe(
					beers -> customListBeersAdapter.init(beers),
					e -> Snackbar.show(this, R.string.error_unexpectederror));
	RxRecyclerViewAdapter.dataEvents(customListBeersAdapter)
			.filter(event -> event.getKind() != RecyclerAdapterDataEvent.Kind.RANGE_CHANGE)
			.subscribe(event -> {
				emptyText.setVisibility(customListBeersAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
				beersList.setVisibility(customListBeersAdapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
			}, e -> RBLog.e("Unexpected error when handling list addition/removal", e));
}
 
Example 13
Source File: BaseFragment.java    From fingerpoetry-android with Apache License 2.0 4 votes vote down vote up
protected void initToolbarMenu(Toolbar toolbar) {
    if(toolbar != null) {
        toolbar.inflateMenu(R.menu.menu_main);
    }
}
 
Example 14
Source File: PostFragment.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.activity_toolbar, container, false);
    ViewGroup contentPanel = (ViewGroup) view.findViewById(R.id.content_panel);
    ViewGroup contentView = (ViewGroup) inflater.inflate(R.layout.fragment_post, contentPanel, true);

    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    // I like hardcode
    mToolbar.setSubtitle("A岛·adnmb.com");
    if (mId != null) {
        mToolbar.setTitle(mSite.getPostTitle(getContext(), mId));
    } else {
        mToolbar.setTitle(getString(R.string.thread));
    }
    mToolbar.setNavigationIcon(DrawableManager.getDrawable(getContext(), R.drawable.v_arrow_left_dark_x24));
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentHost().finishFragment(PostFragment.this);
        }
    });
    mToolbar.inflateMenu(R.menu.activity_post);
    mToolbar.setOnMenuItemClickListener(this);

    mContentLayout = (ContentLayout) contentView.findViewById(R.id.content_layout);
    mRecyclerView = mContentLayout.getRecyclerView();

    mReplyHelper = new ReplyHelper();
    mReplyHelper.setEmptyString(getString(R.string.not_found));
    mContentLayout.setHelper(mReplyHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    mReplyAdapter = new ReplyAdapter();
    mRecyclerView.setAdapter(mReplyAdapter);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(
            getContext(), ResourcesUtils.getAttrBoolean(getContext(), R.attr.dark)));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.hasFixedSize();
    mOnScrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (RecyclerView.SCROLL_STATE_DRAGGING == newState) {
                pauseHolders();
            } else if (RecyclerView.SCROLL_STATE_IDLE == newState) {
                resumeHolders();
            }
        }
    };
    mRecyclerView.addOnScrollListener(mOnScrollListener);

    mOpColor = getResources().getColor(R.color.colorAccent);

    // Refresh
    mReplyHelper.firstRefresh();

    Messenger.getInstance().register(Constants.MESSENGER_ID_REPLY, this);
    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);

    isLoaded = false;

    return view;
}
 
Example 15
Source File: OFragment.java    From fingerpoetry-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void initToolbarMenu(Toolbar toolbar) {
    toolbar.inflateMenu(R.menu.menu_wxarticle_pop);
}
 
Example 16
Source File: SwipeableCard.java    From SwipeableCard with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize Toolbar.
 * @param context Context
 */
@SuppressWarnings("deprecation")
private void initToolbar(Context context, OptionView option)
{
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(titleAttr);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(colorTitleAttr == 0)
        {
            toolbar.setTitleTextColor(ContextCompat.getColor(context, option.getColorTitle()));
        }
        else {
            toolbar.setTitleTextColor(colorTitleAttr);
        }
        if(colorToolbarAttr == 0)
        {
            toolbar.setBackgroundColor((ContextCompat.getColor(context, option.getColorToolbar())));
        }else {

            toolbar.setBackgroundColor(colorToolbarAttr);
        }

    } else {
        if(colorTitleAttr == 0)
        {
            toolbar.setTitleTextColor(getResources().getColor(option.getColorTitle()));
        }
        else {
            toolbar.setTitleTextColor(colorTitleAttr);
        }
        if(colorToolbarAttr == 0) {
            toolbar.setBackgroundColor(getResources().getColor(option.getColorToolbar()));
        }else{
            toolbar.setBackgroundColor(colorToolbarAttr);
        }
    }
    if (option.isMenuItem()) {
        //Reset menù item (avoids duplicate)
        toolbar.getMenu().clear();
        //Set new menù item
        toolbar.inflateMenu(option.getMenuItem());
        toolbar.setOnMenuItemClickListener(option.getToolbarListener());
    }
    if(option.isAutoAnimation()) {
        toolbar.setOnClickListener(this);
    }else{
        toolbar.setOnClickListener(null);
    }
}
 
Example 17
Source File: SignLogActivity.java    From Swface with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_sign_log);
	toolbar = (Toolbar) findViewById(R.id.toolbar_sign_log);
	stickyList = (StickyListHeadersListView) findViewById(R.id.list);
	toolbar.setTitle("签到记录");
	toolbar.setNavigationIcon(R.mipmap.button_back);
	toolbar.setNavigationOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			finish();
		}
	});
	toolbar.inflateMenu(R.menu.sign_log_toobar_menu);
	toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(MenuItem item) {
			switch (item.getItemId()){
				case R.id.action_only_signed:
					mAdapter.only_signed();
					break;
				case R.id.action_only_no_signed:
					mAdapter.only_no_signed();
					break;
				case R.id.action_all_people:
					mAdapter.all_signed();
					break;
				case R.id.action_about:

					break;
				default:
					break;

			}
			return false;
		}
	});
	stickyList.setOnItemClickListener(this);
	stickyList.setOnHeaderClickListener(this);
	stickyList.setOnStickyHeaderChangedListener(this);
	stickyList.setOnStickyHeaderOffsetChangedListener(this);
	stickyList.addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null));
	stickyList.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null));
	TextView textView = new TextView(this);
	textView.setText("当前签到内容为空!");
	stickyList.setEmptyView(textView);
	stickyList.setDrawingListUnderStickyHeader(true);
	stickyList.setAreHeadersSticky(true);

	refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
	refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
		@Override
		public void onRefresh() {
			new Handler().postDelayed(new Runnable() {
				@Override
				public void run() {
					refreshLayout.setRefreshing(false);
				}
			}, 1000);
		}
	});
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setCancelable(false);
	builder.setTitle("温馨提示");
	builder.setMessage("正在加载,请稍后......");
	builder.setView(new ProgressBar(this));
	dialog = builder.show();
	loadData();
}
 
Example 18
Source File: DetailFragment.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        ViewParent vp = getView().getParent();
        if ( vp instanceof CardView ) {
            ((View)vp).setVisibility(View.VISIBLE);
        }

        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

        if ( Utility.usingLocalGraphics(getActivity()) ) {
            mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
        } else {
            // Use weather art image
            Glide.with(this)
                    .load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId))
                    .error(Utility.getArtResourceForWeatherCondition(weatherId))
                    .crossFade()
                    .into(mIconView);
        }

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String dateText = Utility.getFullFriendlyDayString(getActivity(),date);
        mDateView.setText(dateText);

        // Get description from weather condition ID
        String description = Utility.getStringForWeatherCondition(getActivity(), weatherId);
        mDescriptionView.setText(description);
        mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description));

        // For accessibility, add a content description to the icon field. Because the ImageView
        // is independently focusable, it's better to have a description of the image. Using
        // null is appropriate when the image is purely decorative or when the image already
        // has text describing it in the same UI component.
        mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description));

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high);
        mHighTempView.setText(highString);
        mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString));

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low);
        mLowTempView.setText(lowString);
        mLowTempView.setContentDescription(getString(R.string.a11y_low_temp, lowString));

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));
        mHumidityView.setContentDescription(getString(R.string.a11y_humidity, mHumidityView.getText()));
        mHumidityLabelView.setContentDescription(mHumidityView.getContentDescription());

        // Read wind speed and direction from cursor and update view
        float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
        float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));
        mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText()));
        mWindLabelView.setContentDescription(mWindView.getContentDescription());

        // Read pressure from cursor and update view
        float pressure = data.getFloat(COL_WEATHER_PRESSURE);
        mPressureView.setText(getString(R.string.format_pressure, pressure));
        mPressureView.setContentDescription(getString(R.string.a11y_pressure, mPressureView.getText()));
        mPressureLabelView.setContentDescription(mPressureView.getContentDescription());

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

    }
    AppCompatActivity activity = (AppCompatActivity)getActivity();
    Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar);

    // We need to start the enter transition after the data has loaded
    if ( mTransitionAnimation ) {
        activity.supportStartPostponedEnterTransition();

        if ( null != toolbarView ) {
            activity.setSupportActionBar(toolbarView);

            activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
            activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    } else {
        if ( null != toolbarView ) {
            Menu menu = toolbarView.getMenu();
            if ( null != menu ) menu.clear();
            toolbarView.inflateMenu(R.menu.detailfragment);
            finishCreatingMenu(toolbarView.getMenu());
        }
    }
}
 
Example 19
Source File: TableLayoutFragment.java    From AdaptiveTableLayout with MIT License 4 votes vote down vote up
@Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_tab_layout, container, false);

        mTableLayout = view.findViewById(R.id.tableLayout);
        progressBar = view.findViewById(R.id.progressBar);
        vHandler = view.findViewById(R.id.vHandler);

        Toolbar toolbar = view.findViewById(R.id.toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    Objects.requireNonNull(getActivity()).onBackPressed();
                }
            }
        });
        toolbar.inflateMenu(R.menu.table_layout);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.actionSave) {
                    applyChanges();
                } else if (item.getItemId() == R.id.actionSettings) {
                    SettingsDialog.newInstance(
                            mTableLayout.isHeaderFixed(),
                            mTableLayout.isSolidRowHeader(),
                            mTableLayout.isRTL(),
                            mTableLayout.isDragAndDropEnabled())
                            .show(getChildFragmentManager(), SettingsDialog.class.getSimpleName());
                }
                return true;
            }
        });
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
//            mTableLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
        }
        initAdapter();

        return view;
    }
 
Example 20
Source File: ToolBarUtil.java    From Android-Architecture with Apache License 2.0 2 votes vote down vote up
/**
 * 向Toolbar添加menu,一般fragment使用
 *
 * @param toolbar
 * @param layout
 * @param itemClickListener
 */
public static void addMenu(Toolbar toolbar, int layout, Toolbar.OnMenuItemClickListener itemClickListener) {
    if (toolbar == null) return;
    toolbar.inflateMenu(layout);
    toolbar.setOnMenuItemClickListener(itemClickListener);
}