Java Code Examples for android.support.design.widget.TabLayout#setVisibility()

The following examples show how to use android.support.design.widget.TabLayout#setVisibility() . 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: PaginationHelper.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
public void updatePagination(Pagination newPagination) {
    this.pagination = newPagination;
    for (TabLayout tabLayout : tabLayouts) {
        if (pagination.getAll() <= 1) {
            tabLayout.setVisibility(View.GONE);
            return;
        }
        tabLayout.setVisibility(View.VISIBLE);
        boolean prevDisabled = pagination.getCurrent() <= 1;
        boolean nextDisabled = pagination.getCurrent() == pagination.getAll();
        TabLayout.Tab tab;
        int tag;
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            tab = tabLayout.getTabAt(i);
            if (tab == null || tab.getTag() == null) return;
            tag = (Integer) tab.getTag();
            if ((tag) == TAG_SELECT) continue;
            if (tab.getIcon() != null) {
                if ((tag == TAG_FIRST || tag == TAG_PREV) ? prevDisabled : nextDisabled)
                    tab.getIcon().setColorFilter(colorFilter);
                else
                    tab.getIcon().clearColorFilter();
            }
        }
    }
}
 
Example 2
Source File: EncryptionParamsActivity.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //make sure to clear any pending decrypt tasks in the background, as they might interfere with pending intents generated by the user in the UI thread of this activity
    CryptoHandlerFacade.Companion.getInstance(this).clearDecryptQueue();

    setContentView(R.layout.activity_encryption_params);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //   getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mCore = Core.getInstance(this);


    mImeWasVisible = getIntent().getBooleanExtra(EXTRA_IME_WAS_VISIBLE, false);
    mEditNodeId = getIntent().getIntExtra(EXTRA_EDIT_NODE_ID, 0);
    mPackagename = getIntent().getStringExtra(EXTRA_PACKAGENAME);

    String mode = getIntent().getStringExtra(EXTRA_MODE);
    boolean isForTextEncryption = MODE_DEFAULT.equals(mode) || MODE_CLIPBOARD.equals(mode);
    if (Util.isFeatureEnctypePGP(this)) {
        mGpgEncryptionParamsFragment = GpgEncryptionParamsFragment.newInstance(mPackagename, isForTextEncryption, savedInstanceState == null ? null : savedInstanceState.getBundle(EXTRA_STATE_GPG));
    }
    if (Util.isFeatureEnctypeSYM(this)) {
        mSymEncryptionParamsFragment = SymmetricEncryptionParamsFragment.newInstance(mPackagename, isForTextEncryption, savedInstanceState == null ? null : savedInstanceState.getBundle(EXTRA_STATE_SYM));
    }
    mSimpleSymEncryptionParamsFragment = SimpleSymmetricEncryptionParamsFragment.newInstance(mPackagename, isForTextEncryption, savedInstanceState == null ? null : savedInstanceState.getBundle(EXTRA_STATE_SIMPLESYM));
    mPager = (ViewPager) findViewById(R.id.pager);
    mTabAdapter = new TabAdapter(getFragmentManager());
    mPager.setOffscreenPageLimit(mTabAdapter.getCount());
    mPager.setAdapter(mTabAdapter);


    mPager.addOnPageChangeListener(this);


    mTitleIndicator = (TabLayout) findViewById(R.id.tabs);
    mTitleIndicator.setupWithViewPager(mPager);


    if (mTabAdapter.getCount() == 1) {
        mTitleIndicator.setVisibility(View.GONE);
        mSimpleSymEncryptionParamsFragment.setToolTipVisible(false);
    }

    if (savedInstanceState != null) {
        mPager.setCurrentItem(savedInstanceState.getInt(EXTRA_TAB));
    } else {
        AbstractEncryptionParams params = mCore.getBestEncryptionParams(mPackagename);

        //use last method of user activity or scraped
        EncryptionMethod method = params == null ? null : params.getEncryptionMethod();

        //no user activity, nothing scraped, let's see if we persisted it in database
        if (method == null) {
            method = mCore.getDb().getLastEncryptionMethod(mPackagename);
        }

        int page = 0;
        //even not in database?
        if (method != null) {
            page = mTabAdapter.getPageByMethod(method);
        }
        if (page < 0) page = 0;
        mPager.setCurrentItem(page);
    }
}
 
Example 3
Source File: MainActivity.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	if (Session.get().isUpgrade()) {
		startActivity(UpgradeActivity.start(this));
		finish();
		return;
	} else if (!Session.get().hasIgnoredAccount() && !Session.get().isLoggedIn()) {
		startActivity(WelcomeActivity.start(this));
		finish();
		return;
	}

	View scanButton = findViewById(R.id.scan_button);
	View helpButton = findViewById(R.id.help_button);
	searchEdit = (SearchView) findViewById(R.id.search_edit);
	TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	listsPager = (ViewPager) findViewById(R.id.lists_pager);
	loadingProgress = findViewById(R.id.loading_progress);
	statusText = (TextView) findViewById(R.id.status_text);
	emptyText = (TextView) findViewById(R.id.empty_text);
	RecyclerView searchList = (RecyclerView) findViewById(R.id.search_list);
	rateButton = (FloatingActionButton) findViewById(R.id.rate_button);
	listAddButton = (FloatingActionButton) findViewById(R.id.list_add_button);

	// Set up tabs
	tabTypes = new ArrayList<>(3);
	tabs = new ArrayList<>(3);
	tabsTitles = new ArrayList<>(3);
	if (Session.get().isLoggedIn()) {
		addTab(TAB_RATINGS, R.string.main_myratings);
		addTab(TAB_FEED_FRIENDS, R.string.main_friends);
		addTab(TAB_FEED_LOCAL, R.string.main_local);
	} else {
		addTab(TAB_FEED_GLOBAL, R.string.main_global);
	}
	addTab(TAB_NEARBY, R.string.main_nearby);
	addTab(TAB_MY_LISTS, R.string.main_mylists);
	addTab(TAB_TOP50, R.string.main_top50);
	RxViewPager.pageSelected(listsPager).subscribe(this::refreshTab);
	listsPager.setAdapter(new ActivityPagerAdapter());
	tabLayout.setupWithViewPager(listsPager);
	if (tabs.size() == 1) {
		tabLayout.setVisibility(View.GONE);
	} else if (tabs.size() > 4) {
		tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
	}

	// Set up access buttons
	RxView.clicks(scanButton)
			.compose(bindToLifecycle())
			.subscribe(v -> new BarcodeIntentIntegrator(this).initiateScan());
	RxView.clicks(helpButton)
			.compose(bindToLifecycle())
			.subscribe(v -> startActivity(HelpActivity.start(this)));
	RxView.clicks(statusText)
			.compose(bindToLifecycle())
			.subscribe(v -> startService(SyncService.start(this)));

	// Set up search box: show results with search view focus, start search on query submit and show suggestions on query text changes
	searchList.setLayoutManager(new LinearLayoutManager(this));
	searchList.setAdapter(searchSuggestionsAdaper = new SearchSuggestionsAdapter());
	ItemClickSupport.addTo(searchList)
			.setOnItemClickListener((parent, pos, v) -> searchFromSuggestion(searchSuggestionsAdaper.get(pos)));
	Observable<SearchViewQueryTextEvent> queryTextChangeEvents = RxSearchView.queryTextChangeEvents(searchEdit)
			.compose(onUi())
			.replay(1)
			.refCount();
	queryTextChangeEvents.map(event -> !TextUtils.isEmpty(event.queryText())).subscribe(hasQuery -> {
		searchList.setVisibility(hasQuery ? View.VISIBLE : View.GONE);
		tabLayout.setVisibility(hasQuery ? View.GONE : (tabs.size() == 1 ? View.GONE : View.VISIBLE));
		scanButton.setVisibility(hasQuery ? View.GONE : View.VISIBLE);
	});
	queryTextChangeEvents
			.filter(SearchViewQueryTextEvent::isSubmitted)
			.subscribe(event -> performSearch(event.queryText().toString()));
	queryTextChangeEvents
			.map(event -> event.queryText().toString())
			.map(String::trim)
			.switchMap(query -> {
				if (query.length() == 0) {
					return Db.getAllHistoricSearches(this).toList();
				} else {
					return Db.getSuggestions(this, query).toList();
				}
			})
			.compose(onIoToUi())
			.compose(bindToLifecycle())
			.subscribe(suggestions -> searchSuggestionsAdaper.update(suggestions));
	searchEdit.setInputType(InputType.TYPE_CLASS_TEXT);

}
 
Example 4
Source File: SearchActivity.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_search);

	searchEdit = (SearchView) findViewById(R.id.search_text);
	TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	resultsPager = (ViewPager) findViewById(R.id.results_pager);
	loadingProgress = (ProgressBar) findViewById(R.id.loading_progress);
	emptyText = (TextView) findViewById(R.id.empty_text);

	setupDefaultUpButton();

	modeBeerPicker = getIntent().getBooleanExtra("modeBeerPicker", false);

	// Set up tabs
	searchEdit.setQuery(getIntent().getStringExtra("query"), false);
	searchEdit.setInputType(InputType.TYPE_CLASS_TEXT);
	tabTypes = new ArrayList<>(3);
	tabs = new ArrayList<>(3);
	tabsTitles = new ArrayList<>(3);
	addTab(TAB_BEERS, R.string.search_beers);
	if (!modeBeerPicker) {
		addTab(TAB_BREWERIES, R.string.search_breweries);
		addTab(TAB_PLACES, R.string.search_places);
	}
	RxViewPager.pageSelected(resultsPager).subscribe(this::refreshTab);
	resultsPager.setAdapter(new SearchPagerAdapter());
	tabLayout.setupWithViewPager(resultsPager);
	if (tabs.size() == 1)
		tabLayout.setVisibility(View.GONE);
	refreshTab(0);

	// When in picker mode, only search beers and set the activity result as cancelled until we actually picked a beer
	if (modeBeerPicker) {
		setResult(RESULT_CANCELED);
		if (TextUtils.isEmpty(searchEdit.getQuery())) {
			// No query given so focus on search field and do not show loading spinner until an input is given
			loadingProgress.setVisibility(View.INVISIBLE);
			searchEdit.requestFocus();
		}
	}

}