Java Code Examples for androidx.appcompat.widget.Toolbar#setOnMenuItemClickListener()

The following examples show how to use androidx.appcompat.widget.Toolbar#setOnMenuItemClickListener() . 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: ProfileManagerActivity.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init toolbar
 */
private void initToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.profiles);
    toolbar.setNavigationIcon(R.drawable.ic_navigation_close);
    toolbar.setNavigationOnClickListener(v -> {
        Intent intent = getParentActivityIntent();
        if (shouldUpRecreateTask(intent) || isTaskRoot()) {
            TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(intent).startActivities();
        } else {
            finish();
        }
    });
    toolbar.inflateMenu(R.menu.profile_manager_menu);
    toolbar.setOnMenuItemClickListener(this);
}
 
Example 2
Source File: MainActivity.java    From HeaderView with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    toolbar.inflateMenu(R.menu.menu_main);
    toolbar.setOnMenuItemClickListener(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }

    findViewById(R.id.normal_drawer).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, NormalHeaderActivity.class)));
    findViewById(R.id.compact_drawer).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, CompactHeaderActivity.class)));
}
 
Example 3
Source File: AbstractTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the menu of the toolbar, which is shown, when the tab switcher is shown.
 */
private void inflateToolbarMenu() {
    Toolbar[] toolbars = getToolbars();
    int menuId = getModel().getToolbarMenuId();

    if (toolbars != null && menuId != -1) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[TabSwitcher.SECONDARY_TOOLBAR_INDEX] :
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
        Menu previousMenu = toolbar.getMenu();

        if (previousMenu != null) {
            previousMenu.clear();
        }

        toolbar.inflateMenu(menuId);
        toolbar.setOnMenuItemClickListener(getModel().getToolbarMenuItemListener());
    }
}
 
Example 4
Source File: ProfileManagerActivity.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init toolbar
 */
private void initToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.profiles);
    toolbar.setNavigationIcon(R.drawable.ic_navigation_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = getParentActivityIntent();
            if (shouldUpRecreateTask(intent) || isTaskRoot()) {
                TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(intent).startActivities();
            } else {
                finish();
            }
        }
    });
    toolbar.inflateMenu(R.menu.profile_manager_menu);
    toolbar.setOnMenuItemClickListener(this);
}
 
Example 5
Source File: SettingsActivity.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initToolbar() {
    Toolbar toolbar = findViewById(R.id.activity_settings_toolbar);
    toolbar.setTitle(getString(R.string.action_settings));
    toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
    toolbar.setNavigationOnClickListener(view -> finish());
    toolbar.inflateMenu(R.menu.activity_settings);
    toolbar.setOnMenuItemClickListener(this);
}
 
Example 6
Source File: SingleActivity.java    From PhotoDraweeView with Apache License 2.0 5 votes vote down vote up
private void initToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.single);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.default_image:
                    mPhotoDraweeView.setOnDoubleTapListener(null);
                    mPhotoDraweeView.setPhotoUri(Uri.parse("res:///" + R.drawable.panda));
                    break;
                case R.id.failure_image:
                    mPhotoDraweeView.setPhotoUri(Uri.parse("http://google.com/404.jpg"));
                    break;
                case R.id.view_pager:
                    ViewPagerActivity.startActivity(SingleActivity.this);
                    break;
                case R.id.recycler_view:
                    RecyclerViewActivity.startActivity(SingleActivity.this);
                    break;
                case R.id.scale_step:
                    mPhotoDraweeView.setOnDoubleTapListener(
                            new ScaleStepDoubleTapListener(mPhotoDraweeView.getAttacher(),
                                    0.25f));
                    break;
                case R.id.shared_element:
                    SharedElementActivity.startActivity(SingleActivity.this);
                    break;
                default:
                    break;
            }

            return true;
        }
    });
}
 
Example 7
Source File: MapFragment.java    From nearby-android with Apache License 2.0 5 votes vote down vote up
/**
 * When activity first starts, the action bar
 * shows the back arrow for navigating back
 * to parent activity.  Menu item click listener
 * responds in one of the following ways:
 * 1) navigating back to list of places,
 * 2) showing the filter UI
 * 3) showing the route to selected place in map
 */
private void setUpToolbar(){
  final Toolbar toolbar = getActivity().findViewById(R.id.map_toolbar);
  ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
  toolbar.setTitle("");
  final ActionBar ab = ((AppCompatActivity)getActivity()).getSupportActionBar();
  if (ab != null){
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeAsUpIndicator(0); // Use default home icon
  }

  // Menu items change depending on presence/absence of bottom sheet
  toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
    @Override public boolean onMenuItemClick(final MenuItem item) {
      if (item.getTitle().toString().equalsIgnoreCase(getString(R.string.list_view))){
        // Show the list of places
        showList();
      }
      if (item.getTitle().toString().equalsIgnoreCase(getString(R.string.filter))){
        final FilterDialogFragment dialogFragment = new FilterDialogFragment();
        final FilterContract.Presenter filterPresenter = new FilterPresenter();
        dialogFragment.setPresenter(filterPresenter);
        dialogFragment.show(getActivity().getFragmentManager(),"dialog_fragment");

      }
        if (item.getTitle().toString().equalsIgnoreCase("Route")){
          mPresenter.getRoute();

      }
      return false;
    }
  });
}
 
Example 8
Source File: ToolbarHelper.java    From Paginize with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public static void setupMenu(Toolbar toolbar,
                             @MenuRes int menuResId,
                             Toolbar.OnMenuItemClickListener listener) {
  if (menuResId > 0) {
    toolbar.inflateMenu(menuResId);
    if (listener != null) {
      toolbar.setOnMenuItemClickListener(listener);
    }
  }
}
 
Example 9
Source File: ToolbarHelper.java    From Paginize with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public static void setupMenu(Toolbar toolbar,
                             @MenuRes int menuResId,
                             Toolbar.OnMenuItemClickListener listener) {
  if (menuResId > 0) {
    toolbar.inflateMenu(menuResId);
    if (listener != null) {
      toolbar.setOnMenuItemClickListener(listener);
    }
  }
}
 
Example 10
Source File: PreviewIconActivity.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initWidget() {
    this.container = findViewById(R.id.activity_preview_icon_container);

    Toolbar toolbar = findViewById(R.id.activity_preview_icon_toolbar);
    toolbar.setTitle(provider.getProviderName());
    toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
    toolbar.setNavigationOnClickListener(v -> finish());
    toolbar.inflateMenu(R.menu.activity_preview_icon);
    toolbar.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
            case R.id.action_appStore:
                if (provider instanceof DefaultResourceProvider
                        || provider instanceof PixelResourcesProvider) {
                    IntentHelper.startAppStoreDetailsActivity(this);
                } else {
                    IntentHelper.startAppStoreDetailsActivity(this, provider.getPackageName());
                }
                break;

            case R.id.action_about:
                if (provider instanceof DefaultResourceProvider
                        || provider instanceof PixelResourcesProvider) {
                    IntentHelper.startApplicationDetailsActivity(this);
                } else {
                    IntentHelper.startApplicationDetailsActivity(this, provider.getPackageName());
                }
                break;
        }
        return true;
    });

    RecyclerView recyclerView = findViewById(R.id.activity_preview_icon_recyclerView);
    GridLayoutManager manager = new GridLayoutManager(this, 4);
    manager.setSpanSizeLookup(WeatherIconAdapter.getSpanSizeLookup(4, itemList));
    recyclerView.setLayoutManager(manager);
    recyclerView.setAdapter(new WeatherIconAdapter(this, itemList));
}
 
Example 11
Source File: ConfigActivity.java    From Daedalus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Daedalus.isDarkTheme()) {
        setTheme(R.style.AppTheme_Dark_NoActionBar);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_config);

    ConfigFragment fragment;
    switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) {
        case LAUNCH_FRAGMENT_RULE:
            fragment = new RuleConfigFragment();
            break;
        case LAUNCH_FRAGMENT_DNS_SERVER:
        default://should never reach this
            fragment = new DnsServerConfigFragment();
            break;
    }

    Toolbar toolbar = findViewById(R.id.toolbar_config);
    Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear);
    Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(wrappedDrawable, Color.WHITE);
    toolbar.setNavigationIcon(drawable);
    toolbar.setNavigationOnClickListener(v -> onBackPressed());
    toolbar.setOnMenuItemClickListener(fragment);
    toolbar.inflateMenu(R.menu.custom_config);

    FragmentManager manager = getSupportFragmentManager();
    fragment.setIntent(getIntent());
    FragmentTransaction fragmentTransaction = manager.beginTransaction();
    fragmentTransaction.replace(R.id.id_config, fragment);
    fragmentTransaction.commit();
}
 
Example 12
Source File: CreatePoiFragment.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private void setupView() {
    createPoiFeature = (TextView) getActivity().findViewById(R.id.createPoiFeature);
    createPoiFeature.setOnClickListener(clickListener);
    createName = (EditText) getActivity().findViewById(R.id.createName);
    createStreet = (EditText) getActivity().findViewById(R.id.createStreet);
    createHouseNumber = (EditText) getActivity().findViewById(R.id.createHouseNumber);
    createPostCode = (EditText) getActivity().findViewById(R.id.createPostCode);
    createCity = (EditText) getActivity().findViewById(R.id.createCity);
    createPhone = (EditText) getActivity().findViewById(R.id.createPhone);
    createWebsite = (EditText) getActivity().findViewById(R.id.createWebsite);
    createEmail = (EditText) getActivity().findViewById(R.id.createEmail);
    createInternetContainer = (LinearLayout) getActivity().findViewById(R.id.createInternetContainer);
    createInternet = (Spinner) getActivity().findViewById(R.id.createInternet);
    dropdownItems = new String[]{"", getString(R.string.yes), getString(R.string.no), getString(R.string.wifi), getString(R.string.wired), getString(R.string.wlan)};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, dropdownItems);
    createInternet.setAdapter(adapter);

    TextView osmCopyright = (TextView) getActivity().findViewById(R.id.osmCopyrightCreatePoi);
    osmCopyright.setText(Html.fromHtml(getString(R.string.osm_copyright)));
    toolbar = (Toolbar) getActivity().findViewById(R.id.createPoiToolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener()

    {
        @Override
        public void onClick(View v) {
            closeFragment();
        }
    });
    toolbar.inflateMenu(R.menu.update_poi);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (!allFieldsValid()) return true;
            createPoi();
            return true;
        }
    });
}
 
Example 13
Source File: ImageControlFragment.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);

    final Toolbar toolbar = view.findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.help);
    toolbar.setOnMenuItemClickListener(this);

    // This makes the layout animate when the TextView value changes.
    // By default it animates only on hiding./showing views.
    // The view must have android:animateLayoutChanges(true) attribute set in the XML.
    ((ViewGroup) view).getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
}
 
Example 14
Source File: FragmentHistory.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void initToolbar(Toolbar toolbar) {
    super.initToolbar(toolbar);
    toolbar.inflateMenu(R.menu.delete_all);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.action_delete) {
                if (allItems.size() == 0) {
                    Common.showToast("没有浏览历史");
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setTitle("PixShaft 提示");
                    builder.setMessage("这将会删除所有的本地浏览历史");
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            AppDatabase.getAppDatabase(mContext).downloadDao().deleteAllHistory();
                            Common.showToast("删除成功");
                            mRefreshLayout.autoRefresh();
                        }
                    });
                    builder.setNegativeButton("取消", null);
                    AlertDialog alertDialog = builder.create();
                    alertDialog.show();
                }
            }
            return true;
        }
    });
}
 
Example 15
Source File: DetailFragment.java    From Passbook with Apache License 2.0 5 votes vote down vote up
private void setupToolbar(View rootView, String title) {
    Toolbar toolbar;
    TextView titleView;
    toolbar = rootView.findViewById(R.id.toolbar);
    View close = rootView.findViewById(R.id.close);
    close.setOnClickListener(this);
    View header = rootView.findViewById(R.id.header);
    ImageButton fab = rootView.findViewById(R.id.fab);

    fab.setOnClickListener(this);
    header.setBackgroundColor(mColor);
    titleView = rootView.findViewById(android.R.id.title);
    titleView.setText(title);
    // Elevation to minus 1 so that fab would not be covered on 5.0
    float elevation = getResources().getDimension(R.dimen.fab_small_elevation) - 0.5f;
    ViewCompat.setElevation(header, elevation);
    if(rootView.findViewById(R.id.frame_box)==null) {
        MainActivity ma = (MainActivity) getActivity();
        if (ma != null) {
            ma.setStatusBarColor(mColor, 200, false);
        }
    }
    toolbar.inflateMenu(R.menu.menu_detail);
    toolbar.getMenu().getItem(0).getIcon().setColorFilter(
            C.ThemedColors[C.colorTextNormal], PorterDuff.Mode.SRC_ATOP);
    toolbar.setOnMenuItemClickListener(this);
}
 
Example 16
Source File: MainActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_main); // have 3 styles
    initialApp();

    // UIL setting
    if (ImageLoader.getInstance() == null || !ImageLoader.getInstance().isInited()) {
        GlobalConfig.initImageLoader(this);
    }

    // UMeng initialization
    UMConfigure.init(MyApp.getContext(), UMConfigure.DEVICE_TYPE_PHONE, null);

    // Update old save files ----------------


    // set Toolbar
    Toolbar mToolbar = findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mToolbar);
    // getSupportActionBar().setDisplayShowHomeEnabled(true);

    // set Tool button
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_drawer);
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, findViewById(R.id.drawer), mToolbar);

    // find search box
    mToolbar.setOnMenuItemClickListener(item -> {
        //Toast.makeText(MyApp.getContext(),"called button",Toast.LENGTH_SHORT).show();
        if (item.getItemId() == R.id.action_search) {
            // start search activity
            startActivity(new Intent(MainActivity.this, SearchActivity.class));
            overridePendingTransition(R.anim.fade_in, R.anim.hold); // fade in animation

        }
        return true;
    });

    // change status bar color tint, and this require SDK16
    if (Build.VERSION.SDK_INT >= 16) { //&& Build.VERSION.SDK_INT <= 21) {
        // Android API 22 has more effects on status bar, so ignore

        // create our manager instance after the content view is set
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        // enable all tint
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setNavigationBarTintEnabled(true);
        tintManager.setTintAlpha(0.15f);
        tintManager.setNavigationBarAlpha(0.0f);
        // set all color
        tintManager.setTintColor(getResources().getColor(android.R.color.black));
        // set Navigation bar color
        if (Build.VERSION.SDK_INT >= 21)
            getWindow().setNavigationBarColor(getResources().getColor(R.color.myNavigationColor));
    }
}
 
Example 17
Source File: BottomAppBarMainDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater.inflate(getBottomAppBarContent(), viewGroup, false);

  Toolbar toolbar = view.findViewById(R.id.toolbar);
  toolbar.setTitle(getDefaultDemoTitle());
  themeSwitcherHelper.onCreateOptionsMenu(toolbar.getMenu(), getActivity().getMenuInflater());
  toolbar.setOnMenuItemClickListener(themeSwitcherHelper::onOptionsItemSelected);
  toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());

  coordinatorLayout = view.findViewById(R.id.coordinator_layout);
  bar = view.findViewById(R.id.bar);
  ((AppCompatActivity) getActivity()).setSupportActionBar(bar);

  setUpBottomDrawer(view);

  fab = view.findViewById(R.id.fab);
  fab.setOnClickListener(v -> showSnackbar(fab.getContentDescription()));
  NavigationView navigationView = view.findViewById(R.id.navigation_view);
  navigationView.setNavigationItemSelectedListener(
      item -> {
        showSnackbar(item.getTitle());
        return false;
      });

  Button centerButton = view.findViewById(R.id.center);
  Button endButton = view.findViewById(R.id.end);
  ToggleButton attachToggle = view.findViewById(R.id.attach_toggle);
  attachToggle.setChecked(fab.getVisibility() == View.VISIBLE);
  centerButton.setOnClickListener(
      v -> {
        bar.setFabAlignmentModeAndReplaceMenu(
            BottomAppBar.FAB_ALIGNMENT_MODE_CENTER, R.menu.demo_primary);
      });
  endButton.setOnClickListener(
      v -> {
        bar.setFabAlignmentModeAndReplaceMenu(
            BottomAppBar.FAB_ALIGNMENT_MODE_END, R.menu.demo_primary_alternate);
      });
  attachToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) -> {
        if (isChecked) {
          fab.show();
        } else {
          fab.hide();
        }
      });

  ToggleButton barScrollToggle = view.findViewById(R.id.bar_scroll_toggle);
  barScrollToggle.setChecked(bar.getHideOnScroll());
  barScrollToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) -> bar.setHideOnScroll(isChecked));

  ToggleButton fabAnimToggle = view.findViewById(R.id.fab_animation_mode_toggle);
  fabAnimToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) ->
          bar.setFabAnimationMode(
              isChecked
                  ? BottomAppBar.FAB_ANIMATION_MODE_SLIDE
                  : BottomAppBar.FAB_ANIMATION_MODE_SCALE));

  setUpBottomAppBarShapeAppearance();

  return view;
}
 
Example 18
Source File: NowPlayingFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void setupToolbar(Toolbar toolbar) {
    if (getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE) {
        toolbar.setBackground(new ColorDrawable(Color.TRANSPARENT));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(getResources().getDimension(R.dimen.header_elevation));
    }

    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_clear_24dp);

    toolbar.inflateMenu(R.menu.activity_now_playing);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setNavigationOnClickListener(v -> {
        getActivity().onBackPressed();
    });

    mCreatePlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_save);
    mAppendToPlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_append);
    mShuffleMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_shuffle);
    mRepeatMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_repeat);

    toolbar.getMenu().findItem(R.id.menu_open_equalizer)
            .setEnabled(EqualizerActivity.newIntent(getContext(), false) != null);

    mPlayerController.getQueue()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .map(this::queueContainsLocalSongs)
            .subscribe(this::updatePlaylistActionEnabled, throwable -> {
                Timber.e(throwable, "Failed to update playlist enabled state");
            });

    mPlayerController.isShuffleEnabled()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::updateShuffleIcon, throwable -> {
                Timber.e(throwable, "Failed to update shuffle icon");
            });

    mPlayerController.getRepeatMode()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::updateRepeatIcon, throwable -> {
                Timber.e(throwable, "Failed to update repeat icon");
            });
}
 
Example 19
Source File: ViewTaskFragment.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    mShowFloatingActionButton = !getResources().getBoolean(R.bool.has_two_panes);

    mRootView = inflater.inflate(R.layout.fragment_task_view_detail, container, false);
    mContent = (ViewGroup) mRootView.findViewById(R.id.content);
    mDetailView = (TaskView) inflater.inflate(R.layout.task_view, mContent, false);
    mContent.addView(mDetailView);
    mAppBar = (AppBarLayout) mRootView.findViewById(R.id.appbar);
    mToolBar = (Toolbar) mRootView.findViewById(R.id.toolbar);
    mToolBar.setOnMenuItemClickListener(this);
    mToolBar.setTitle("");
    mAppBar.addOnOffsetChangedListener(this);

    animate(mToolBar.findViewById(R.id.toolbar_title), 0, View.INVISIBLE);

    mFloatingActionButton = (FloatingActionButton) mRootView.findViewById(R.id.floating_action_button);
    showFloatingActionButton(false);
    mFloatingActionButton.setOnClickListener(v -> completeTask());

    // Update the toolbar color until the actual is loaded for the task

    mListColor = new ValueColor(getArguments().getInt(ARG_STARTING_COLOR)).argb();
    updateColor();

    mRestored = savedInstanceState != null;

    if (savedInstanceState != null)
    {
        if (mContent != null && mContentSet != null)
        {
            // register for content updates
            mContentSet.addOnChangeListener(this, null, true);

            // register observer
            if (mTaskUri != null)
            {
                mAppContext.getContentResolver().registerContentObserver(mTaskUri, false, mObserver);
            }
        }
    }
    else if (mTaskUri != null)
    {
        Uri uri = mTaskUri;
        // pretend we didn't load anything yet
        mTaskUri = null;
        loadUri(uri);
    }

    return mRootView;
}
 
Example 20
Source File: BaseWebActivity.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this);

    objectBoxDAO = new ObjectBoxDAO(this);

    setContentView(R.layout.activity_base_web);

    if (getStartSite() == null) {
        Timber.w("Site is null!");
    } else {
        Timber.d("Loading site: %s", getStartSite());
    }

    // Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClickListener(this::onMenuItemSelected);
    refreshStopMenu = toolbar.getMenu().findItem(R.id.web_menu_refresh_stop);

    bottomToolbar = findViewById(R.id.bottom_navigation);
    bottomToolbar.setOnNavigationItemSelectedListener(this::onMenuItemSelected);
    bottomToolbar.setItemIconTintList(null); // Hack to make selector resource work
    backMenu = bottomToolbar.getMenu().findItem(R.id.web_menu_back);
    forwardMenu = bottomToolbar.getMenu().findItem(R.id.web_menu_forward);
    galleryMenu = bottomToolbar.getMenu().findItem(R.id.web_menu_gallery);
    actionMenu = bottomToolbar.getMenu().findItem(R.id.web_menu_download);

    initWebView();
    initSwipeLayout();
    webView.loadUrl(getStartUrl());

    if (!Preferences.getRecentVisibility()) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    // Alert banner
    alertBanner = findViewById(R.id.web_alert_group);
    alertIcon = findViewById(R.id.web_alert_icon);
    alertMessage = findViewById(R.id.web_alert_txt);
    displayAlertBanner();
}