Search in sources :

Example 11 with TabLayout

use of com.google.android.material.tabs.TabLayout in project aware-client by denzilferreira.

the class ESM_DateTime method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    datePicked = Calendar.getInstance();
    View ui = inflater.inflate(R.layout.esm_datetime, null);
    builder.setView(ui);
    esm_dialog = builder.create();
    esm_dialog.setCanceledOnTouchOutside(false);
    try {
        TextView esm_title = (TextView) ui.findViewById(R.id.esm_title);
        esm_title.setText(getTitle());
        TextView esm_instructions = (TextView) ui.findViewById(R.id.esm_instructions);
        esm_instructions.setText(getInstructions());
        final ViewPager datetimePager = (ViewPager) ui.findViewById(R.id.datetimepager);
        DateTimePagerAdapter dateTimePagerAdapter = new DateTimePagerAdapter(getContext());
        datetimePager.setAdapter(dateTimePagerAdapter);
        datetimePager.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        final TabLayout tabLayout = ui.findViewById(R.id.datetimetabs);
        tabLayout.setupWithViewPager(datetimePager, true);
        Button cancel_text = (Button) ui.findViewById(R.id.esm_cancel);
        cancel_text.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                esm_dialog.cancel();
            }
        });
        Button submit_number = (Button) ui.findViewById(R.id.esm_submit);
        submit_number.setText(getSubmitButton());
        submit_number.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Provider.ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Provider.ESM_Data.ANSWER, dateFormat.format(datePicked.getTime()));
                    rowData.put(ESM_Provider.ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                    getActivity().getContentResolver().update(ESM_Provider.ESM_Data.CONTENT_URI, rowData, ESM_Provider.ESM_Data._ID + "=" + getID(), null);
                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    answer.putExtra(ESM.EXTRA_ANSWER, rowData.getAsString(ESM_Provider.ESM_Data.ANSWER));
                    getActivity().sendBroadcast(answer);
                    if (Aware.DEBUG)
                        Log.d(Aware.TAG, "Answer:" + rowData.toString());
                    esm_dialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return esm_dialog;
}
Also used : AlertDialog(android.app.AlertDialog) ContentValues(android.content.ContentValues) JSONException(org.json.JSONException) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) Button(android.widget.Button) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) SimpleDateFormat(java.text.SimpleDateFormat) NonNull(androidx.annotation.NonNull)

Example 12 with TabLayout

use of com.google.android.material.tabs.TabLayout in project collect by opendatakit.

the class DeleteSavedFormActivity method setUpViewPager.

private void setUpViewPager() {
    String[] tabNames = { getString(R.string.data), getString(R.string.forms) };
    ViewPager2 viewPager = findViewById(R.id.viewPager);
    TabLayout tabLayout = findViewById(R.id.tabLayout);
    viewPager.setAdapter(new DeleteFormsTabsAdapter(this, viewModel.isMatchExactlyEnabled()));
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(tabNames[position])).attach();
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) BlankFormsListViewModel(org.odk.collect.android.formmanagement.BlankFormsListViewModel) AppBarUtils(org.odk.collect.androidshared.utils.AppBarUtils) Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider) TabLayout(com.google.android.material.tabs.TabLayout) ViewPager2(androidx.viewpager2.widget.ViewPager2) DeleteFormsTabsAdapter(org.odk.collect.android.adapters.DeleteFormsTabsAdapter) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Configuration(android.content.res.Configuration) R(org.odk.collect.android.R) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayout(com.google.android.material.tabs.TabLayout) DeleteFormsTabsAdapter(org.odk.collect.android.adapters.DeleteFormsTabsAdapter) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator)

Example 13 with TabLayout

use of com.google.android.material.tabs.TabLayout in project Slide by ccrama.

the class ModQueue method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme("");
    setContentView(R.layout.activity_inbox);
    setupAppBar(R.id.toolbar, R.string.drawer_moderation, true, true);
    TabLayout tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(ModQueue.this).getColor("no sub"));
    final View header = findViewById(R.id.header);
    ViewPager pager = (ViewPager) findViewById(R.id.content_view);
    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            header.animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
        }
    });
    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
    pager.setAdapter(new ModQueuePagerAdapter(getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) TabLayout(com.google.android.material.tabs.TabLayout) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager)

Example 14 with TabLayout

use of com.google.android.material.tabs.TabLayout in project Alarmio by TheAndroidMaster.

the class HomeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_home, container, false);
    viewPager = view.findViewById(R.id.viewPager);
    tabLayout = view.findViewById(R.id.tabLayout);
    timePager = view.findViewById(R.id.timePager);
    bottomSheet = view.findViewById(R.id.bottomSheet);
    timeIndicator = view.findViewById(R.id.pageIndicator);
    background = view.findViewById(R.id.background);
    overlay = view.findViewById(R.id.overlay);
    menu = view.findViewById(R.id.fabsMenu);
    stopwatchFab = view.findViewById(R.id.stopwatchFab);
    timerFab = view.findViewById(R.id.timerFab);
    alarmFab = view.findViewById(R.id.alarmFab);
    behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.setHideable(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

            private int statusBarHeight = -1;

            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_COLLAPSED)
                    bottomSheet.setPadding(0, 0, 0, 0);
                else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
                    if (statusBarHeight < 0)
                        statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
                    bottomSheet.setPadding(0, statusBarHeight, 0, 0);
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                if (statusBarHeight < 0)
                    statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
                bottomSheet.setPadding(0, (int) (slideOffset * statusBarHeight), 0, 0);
            }
        });
    }
    pagerAdapter = new SimplePagerAdapter(getChildFragmentManager(), new AlarmsFragment(), new SettingsFragment());
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if (tab.getPosition() > 0) {
                shouldCollapseBack = behavior.getState() != BottomSheetBehavior.STATE_EXPANDED;
                behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            } else {
                setClockFragments();
                if (shouldCollapseBack) {
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    shouldCollapseBack = false;
                }
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    setClockFragments();
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            behavior.setPeekHeight(view.getMeasuredHeight() / 2);
            view.findViewById(R.id.timeContainer).setLayoutParams(new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, view.getMeasuredHeight() / 2));
        }
    });
    colorPrimarySubscription = Aesthetic.Companion.get().colorPrimary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            bottomSheet.setBackgroundColor(integer);
            overlay.setBackgroundColor(integer);
        }
    });
    colorAccentSubscription = Aesthetic.Companion.get().colorAccent().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            menu.setMenuButtonColor(integer);
            int color = ContextCompat.getColor(getContext(), getAlarmio().getActivityTheme() == Alarmio.THEME_AMOLED ? R.color.textColorPrimary : R.color.textColorPrimaryNight);
            menu.getMenuButton().setColorFilter(color);
            stopwatchFab.setColorFilter(color);
            timerFab.setColorFilter(color);
            alarmFab.setColorFilter(color);
            stopwatchFab.setBackgroundColor(integer);
            timerFab.setBackgroundColor(integer);
            alarmFab.setBackgroundColor(integer);
        }
    });
    textColorPrimarySubscription = Aesthetic.Companion.get().textColorPrimary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            stopwatchFab.setTitleTextColor(integer);
            timerFab.setTitleTextColor(integer);
            alarmFab.setTitleTextColor(integer);
        }
    });
    textColorPrimaryInverseSubscription = Aesthetic.Companion.get().textColorPrimaryInverse().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            alarmFab.setTitleBackgroundColor(integer);
            stopwatchFab.setTitleBackgroundColor(integer);
            timerFab.setTitleBackgroundColor(integer);
        }
    });
    stopwatchFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            menu.collapseImmediately();
            getFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_up_sheet, R.anim.slide_out_up_sheet, R.anim.slide_in_down_sheet, R.anim.slide_out_down_sheet).replace(R.id.fragment, new StopwatchFragment()).addToBackStack(null).commit();
        }
    });
    timerFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new TimerDialog(getContext(), getFragmentManager()).show();
            menu.collapse();
        }
    });
    alarmFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new AestheticTimeSheetPickerDialog(view.getContext()).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                @Override
                public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                    AlarmManager manager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE);
                    AlarmData alarm = getAlarmio().newAlarm();
                    alarm.time.set(Calendar.HOUR_OF_DAY, view.getHourOfDay());
                    alarm.time.set(Calendar.MINUTE, view.getMinute());
                    alarm.setEnabled(getContext(), manager, true);
                    getAlarmio().onAlarmsChanged();
                }

                @Override
                public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                }
            }).show();
            menu.collapse();
        }
    });
    menu.setMenuListener(new FABsMenuListener() {

        @Override
        public void onMenuExpanded(FABsMenu fabsMenu) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED)
                    requestPermissions(new String[] { Manifest.permission.FOREGROUND_SERVICE }, 0);
                else
                    fabsMenu.collapseImmediately();
            }
        }
    });
    return view;
}
Also used : FABsMenuListener(jahirfiquitiva.libs.fabsmenu.FABsMenuListener) SimplePagerAdapter(james.alarmio.adapters.SimplePagerAdapter) FABsMenu(jahirfiquitiva.libs.fabsmenu.FABsMenu) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) Consumer(io.reactivex.functions.Consumer) TabLayout(com.google.android.material.tabs.TabLayout) ViewTreeObserver(android.view.ViewTreeObserver) TimerDialog(james.alarmio.dialogs.TimerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) ImageView(android.widget.ImageView) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) PageIndicatorView(james.alarmio.views.PageIndicatorView) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AlarmManager(android.app.AlarmManager) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) AlarmData(james.alarmio.data.AlarmData) Nullable(androidx.annotation.Nullable)

Example 15 with TabLayout

use of com.google.android.material.tabs.TabLayout in project scroball by peterjosling.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    application = (ScroballApplication) getApplication();
    application.startListenerService();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // 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 = findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    TabLayout tabLayout = findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Initial tab may have been specified in the intent.
    int initialTab = getIntent().getIntExtra(EXTRA_INITIAL_TAB, TAB_NOW_PLAYING);
    mViewPager.setCurrentItem(initialTab);
    this.adsRemoved = application.getSharedPreferences().getBoolean(REMOVE_ADS_SKU, false);
    adView = findViewById(R.id.adView);
    if (this.adsRemoved) {
        RelativeLayout parent = (RelativeLayout) adView.getParent();
        if (parent != null) {
            parent.removeView(adView);
        }
    } else {
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("86193DC9EBC8E1C3873178900C9FCCFC").build();
        adView.loadAd(adRequest);
    }
}
Also used : AdRequest(com.google.android.gms.ads.AdRequest) TabLayout(com.google.android.material.tabs.TabLayout) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

TabLayout (com.google.android.material.tabs.TabLayout)36 View (android.view.View)19 Bundle (android.os.Bundle)13 Toolbar (androidx.appcompat.widget.Toolbar)13 NonNull (androidx.annotation.NonNull)12 ViewPager (androidx.viewpager.widget.ViewPager)12 ViewPager2 (androidx.viewpager2.widget.ViewPager2)11 TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)11 Fragment (androidx.fragment.app.Fragment)10 Intent (android.content.Intent)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 TextView (android.widget.TextView)7 Nullable (androidx.annotation.Nullable)7 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)7 Context (android.content.Context)6 R (de.danoeh.antennapod.R)5 SharedPreferences (android.content.SharedPreferences)3 MenuItem (android.view.MenuItem)3 FrameLayout (android.widget.FrameLayout)3