use of com.google.android.material.tabs.TabLayout in project twicalico by moko256.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MainActivityTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
disposable = new CompositeDisposable();
client = GlobalApplicationKt.getClient(this);
accountsModel = GlobalApplicationKt.getAccountsModel(this);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.getChildAt(0).setOnClickListener(v -> {
Fragment fragment = getMainFragment();
if (fragment instanceof MovableTopInterface) {
((MovableTopInterface) fragment).moveToTop();
}
});
drawer = findViewById(R.id.drawer_layout);
if (drawer != null) {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.setDrawerSlideAnimationEnabled(false);
toggle.syncState();
drawer.addDrawerListener(this);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.color_primary_dark));
}
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(item -> {
int id = item.getItemId();
if (!item.isChecked()) {
switch(id) {
case R.id.nav_timeline:
replaceFragment(new HomeTimeLineFragment());
break;
case R.id.nav_mentions:
replaceFragment(new MentionsFragment());
break;
case R.id.nav_account:
startMyUserActivity();
break;
case R.id.nav_follow_and_follower:
replaceFragment(new MyFollowFollowerFragment());
break;
case R.id.nav_like:
replaceFragment(UserLikeFragment.Companion.newInstance(client.getAccessToken().getUserId()));
break;
case R.id.nav_lists:
replaceFragment(SelectListsEntriesFragment.Companion.newInstance(client.getAccessToken().getUserId()));
break;
case R.id.nav_settings:
startActivity(new Intent(this, SettingsActivity.class));
break;
}
}
if (drawer != null) {
drawer.closeDrawer(GravityCompat.START);
}
return (id != R.id.nav_settings) && (id != R.id.nav_account);
});
View headerView = navigationView.inflateHeaderView(R.layout.nav_header_main);
userNameText = headerView.findViewById(R.id.user_name);
userIdText = headerView.findViewById(R.id.user_id);
userImage = headerView.findViewById(R.id.user_image);
userToggleImage = headerView.findViewById(R.id.toggle_account);
userBackgroundImage = headerView.findViewById(R.id.user_bg_image);
userBackgroundImage.setOnClickListener(v -> changeIsDrawerAccountsSelection());
accountListView = new RecyclerView(this);
accountListView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
accountListView.setLayoutManager(new LinearLayoutManager(this));
accountListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
accountListView.setVisibility(View.GONE);
navigationView.addHeaderView(accountListView);
adapter = new SelectAccountsAdapter(this);
adapter.onImageButtonClickListener = accessToken -> {
if (accessToken.getUserId() != client.getAccessToken().getUserId()) {
changeIsDrawerAccountsSelection();
if (drawer != null) {
drawer.closeDrawer(GravityCompat.START);
}
GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, accessToken.getKeyString());
((GlobalApplication) getApplication()).initCurrentClient(accessToken);
client = GlobalApplicationKt.getClient(this);
adapter.updateSelectedPosition(accessToken);
updateDrawerImage();
clearAndPrepareFragment();
}
};
adapter.onAddButtonClickListener = v -> startActivityForResult(new Intent(this, OAuthActivity.class), REQUEST_OAUTH);
adapter.onRemoveButtonClickListener = v -> new AlertDialog.Builder(this).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
AccessToken token = accountsModel.get(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1"));
accountsModel.delete(token);
adapter.removeAccessTokensAndUpdate(token);
int point = accountsModel.size() - 1;
if (point != -1) {
AccessToken accessToken = accountsModel.getAccessTokens().get(point);
GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, accessToken.getKeyString());
((GlobalApplication) getApplication()).initCurrentClient(accessToken);
client = GlobalApplicationKt.getClient(this);
adapter.updateSelectedPosition(accessToken);
updateDrawerImage();
updateAccountsList();
clearAndPrepareFragment();
} else {
GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, "-1");
((GlobalApplication) getApplication()).clearCurrentClient();
startActivityForResult(new Intent(this, OAuthActivity.class), REQUEST_OAUTH);
}
}).setNegativeButton(android.R.string.cancel, null).show();
accountListView.setAdapter(adapter);
findViewById(R.id.fab).setOnClickListener(v -> startActivity(new Intent(this, PostActivity.class)));
tabLayout = findViewById(R.id.toolbar_tab);
tabLayout.addOnTabSelectedListener(this);
alwaysCloseApp = GlobalApplicationKt.preferenceRepository.getBoolean(KEY_ALWAYS_CLOSE_APP, true);
recycledViewPool = new RecyclerView.RecycledViewPool();
recycledViewPool.setMaxRecycledViews(R.layout.layout_post_card, 16);
getSupportFragmentManager().addOnBackStackChangedListener(() -> attachFragment(getMainFragment()));
if (client == null) {
startActivityForResult(new Intent(this, OAuthActivity.class), REQUEST_OAUTH);
} else {
updateDrawerImage();
updateAccountsList();
if (savedInstanceState == null) {
prepareFragment();
}
if (client.getAccessToken().getToken().isEmpty()) {
Toast.makeText(this, R.string.please_re_login, Toast.LENGTH_LONG).show();
}
}
}
use of com.google.android.material.tabs.TabLayout in project FlexibleAdapter by davideas.
the class ViewPagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
HeaderView headerView = (HeaderView) findViewById(R.id.toolbar_header_view);
headerView.bindTo(getString(R.string.app_name), getString(R.string.viewpager));
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
// Coordinatorlayout Status Bar Padding Disappears From Viewpager 2nd-page
// http://stackoverflow.com/questions/31368781/coordinatorlayout-status-bar-padding-disappears-from-viewpager-2nd-page
ViewCompat.setOnApplyWindowInsetsListener(mViewPager, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
insets = ViewCompat.onApplyWindowInsets(v, insets);
if (insets.isConsumed()) {
return insets;
}
boolean consumed = false;
for (int i = 0, count = mViewPager.getChildCount(); i < count; i++) {
ViewCompat.dispatchApplyWindowInsets(mViewPager.getChildAt(i), insets);
if (insets.isConsumed()) {
consumed = true;
}
}
return consumed ? insets.consumeSystemWindowInsets() : insets;
}
});
}
use of com.google.android.material.tabs.TabLayout in project kcanotify by antest1.
the class ResourceLogActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resourcelog);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getStringWithLocale(R.string.action_reslog));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
resourceLogger = new KcaResourceLogger(getApplicationContext(), null, KCANOTIFY_RESOURCELOG_VERSION);
KcaApiData.setDBHelper(dbHelper);
tabLayout = findViewById(R.id.reslog_tab);
tabLayout.addTab(tabLayout.newTab().setText(getStringWithLocale(R.string.reslog_label_resource)));
tabLayout.addTab(tabLayout.newTab().setText(getStringWithLocale(R.string.reslog_label_consumable)));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
export_msg = findViewById(R.id.export_msg);
viewPager = findViewById(R.id.reslog_pager);
pageAdapter = new KcaResourceLogPageAdapter(getSupportFragmentManager());
viewPager.setAdapter(pageAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
tab_position = position;
tabLayout.setScrollPosition(position, positionOffset, true);
Log.e("KCA", "onPageScrolled " + position);
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
tab_position = tab.getPosition();
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
tab_position = tab.getPosition();
viewPager.setCurrentItem(tab.getPosition());
}
});
showhide_btn = findViewById(R.id.reslog_showhide);
showhide_btn.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.black), PorterDuff.Mode.MULTIPLY);
showhide_btn.setImageResource(R.mipmap.ic_arrow_down);
showhide_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
is_hidden = !is_hidden;
if (is_hidden) {
showhide_btn.setImageResource(R.mipmap.ic_arrow_up);
} else {
showhide_btn.setImageResource(R.mipmap.ic_arrow_down);
}
pageAdapter.notifyDataSetChanged();
}
});
start_date = findViewById(R.id.reslog_date_start);
start_date.setOnClickListener(dateViewListener);
end_date = findViewById(R.id.reslog_date_end);
end_date.setOnClickListener(dateViewListener);
interval_d = findViewById(R.id.reslog_interval_day);
interval_d.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (interval_value != INTERVAL_1D) {
interval_value = INTERVAL_1D;
setFragmentChartInfo(interval_value);
interval_select.setSelection(INTERVAL_1D);
} else {
pageAdapter.notifyDataSetChanged();
}
}
});
interval_w = findViewById(R.id.reslog_interval_week);
interval_w.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (interval_value != INTERVAL_1W) {
interval_value = INTERVAL_1W;
setFragmentChartInfo(interval_value);
interval_select.setSelection(INTERVAL_1W);
} else {
pageAdapter.notifyDataSetChanged();
}
}
});
interval_m = findViewById(R.id.reslog_interval_month);
interval_m.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (interval_value != INTERVAL_1M) {
interval_value = INTERVAL_1M;
setFragmentChartInfo(interval_value);
interval_select.setSelection(INTERVAL_1M);
} else {
pageAdapter.notifyDataSetChanged();
}
}
});
interval_select = findViewById(R.id.reslog_date_interval);
final ArrayAdapter<CharSequence> interval_adapter = ArrayAdapter.createFromResource(this, R.array.time_interval_array, R.layout.spinner_item_14dp);
interval_adapter.setDropDownViewResource(R.layout.spinner_dropdown_item_14dp);
interval_select.setAdapter(interval_adapter);
interval_select.setSelection(INTERVAL_1D);
interval_select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
Log.e("KCA-RL", "onItemSelected");
interval_value = position;
setFragmentChartInfo(interval_value);
KcaResourcelogItemAdpater.setListViewItemList(convertData(resourceLog));
pageAdapter.notifyDataSetChanged();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
long current_time = System.currentTimeMillis();
current_time = KcaUtils.getCurrentDateTimestamp(current_time);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy", Locale.US);
String[] time_list = dateFormat.format(new Date(current_time)).split("\\-");
int year = Integer.parseInt(time_list[2]);
int month = Integer.parseInt(time_list[0]);
start_timestamp = current_time - DAY_MILLISECOND * KcaUtils.getLastDay(year, month == 1 ? 12 : month - 1);
end_timestamp = current_time + DAY_MILLISECOND - 1;
start_date.setText(convertMillsToDate(start_timestamp));
end_date.setText(convertMillsToDate(end_timestamp));
resourceLog = resourceLogger.getResourceLogInRange(start_timestamp, end_timestamp);
KcaResourcelogItemAdpater.setListViewItemList(convertData(resourceLog));
pageAdapter.notifyDataSetChanged();
}
use of com.google.android.material.tabs.TabLayout in project syncthing-android by syncthing.
the class MainActivity method onCreate.
/**
* Initializes tab navigation.
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((SyncthingApp) getApplication()).component().inject(this);
setContentView(R.layout.activity_main);
mDrawerLayout = findViewById(R.id.drawer_layout);
FragmentManager fm = getSupportFragmentManager();
if (savedInstanceState != null) {
mFolderListFragment = (FolderListFragment) fm.getFragment(savedInstanceState, FolderListFragment.class.getName());
mDeviceListFragment = (DeviceListFragment) fm.getFragment(savedInstanceState, DeviceListFragment.class.getName());
mDrawerFragment = (DrawerFragment) fm.getFragment(savedInstanceState, DrawerFragment.class.getName());
} else {
mFolderListFragment = new FolderListFragment();
mDeviceListFragment = new DeviceListFragment();
mDrawerFragment = new DrawerFragment();
}
mViewPager = findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabContainer);
tabLayout.setupWithViewPager(mViewPager);
if (savedInstanceState != null) {
mViewPager.setCurrentItem(savedInstanceState.getInt("currentTab"));
if (savedInstanceState.getBoolean(IS_SHOWING_RESTART_DIALOG)) {
showRestartDialog();
}
mBatteryOptimizationDialogDismissed = savedInstanceState.getBoolean(BATTERY_DIALOG_DISMISSED);
if (savedInstanceState.getBoolean(IS_QRCODE_DIALOG_DISPLAYED)) {
showQrCodeDialog(savedInstanceState.getString(DEVICEID_KEY), savedInstanceState.getParcelable(QRCODE_BITMAP_KEY));
}
}
fm.beginTransaction().replace(R.id.drawer, mDrawerFragment).commit();
mDrawerToggle = new Toggle(this, mDrawerLayout);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.addDrawerListener(mDrawerToggle);
setOptimalDrawerWidth(findViewById(R.id.drawer));
// SyncthingService needs to be started from this activity as the user
// can directly launch this activity from the recent activity switcher.
Intent serviceIntent = new Intent(this, SyncthingService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(serviceIntent);
} else {
startService(serviceIntent);
}
onNewIntent(getIntent());
}
use of com.google.android.material.tabs.TabLayout in project collect by opendatakit.
the class QRCodeTabsActivity method setupViewPager.
private void setupViewPager() {
fragmentTitleList = new String[] { getString(R.string.scan_qr_code_fragment_title), getString(R.string.view_qr_code_fragment_title) };
ViewPager2 viewPager = findViewById(R.id.viewPager);
TabLayout tabLayout = findViewById(R.id.tabLayout);
QRCodeTabsAdapter adapter = new QRCodeTabsAdapter(this);
viewPager.setAdapter(adapter);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(fragmentTitleList[position])).attach();
}
Aggregations