Search in sources :

Example 1 with SlidingTabLayout

use of de.mkrtchyan.recoverytools.view.SlidingTabLayout in project Rashr by DsLNeXuS.

the class BackupRestoreFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_backup_restore, container, false);
    mActivity = (RashrActivity) getActivity();
    mContext = root.getContext();
    mPager = (ViewPager) root.findViewById(R.id.vpBackupRestore);
    mAdapter = new BackupRestorePagerAdapter(getChildFragmentManager());
    mPager.setAdapter(mAdapter);
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) root.findViewById(R.id.stlBackupRestore);
    slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {

        @Override
        public int getIndicatorColor(int position) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = mContext.getTheme();
            theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
            return typedValue.data;
        }

        @Override
        public int getDividerColor(int position) {
            return 0;
        }
    });
    slidingTabLayout.setViewPager(mPager);
    final FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fabCreateBackup);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isRecovery = mPager.getCurrentItem() == 0;
            createBackup(isRecovery);
        }
    });
    fab.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_add_white));
    slidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                if (RashrApp.DEVICE.isRecoveryDD() || RashrApp.DEVICE.isRecoveryMTD()) {
                    fab.setVisibility(View.VISIBLE);
                } else {
                    fab.setVisibility(View.INVISIBLE);
                }
            } else {
                if (RashrApp.DEVICE.isKernelDD() || RashrApp.DEVICE.isKernelMTD()) {
                    fab.setVisibility(View.VISIBLE);
                } else {
                    fab.setVisibility(View.INVISIBLE);
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mAdapter.getRecoveryBackupFragment().getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(RashrApp.DEVICE.isRecoveryDD() || RashrApp.DEVICE.isRecoveryMTD())) {
                Toast.makeText(mContext, R.string.op_not_supported, Toast.LENGTH_SHORT).show();
            } else {
                showPopup(view);
            }
        }
    });
    mAdapter.getKernelBackupFragment().getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(RashrApp.DEVICE.isKernelDD() || RashrApp.DEVICE.isKernelMTD())) {
                Toast.makeText(mContext, R.string.op_not_supported, Toast.LENGTH_SHORT).show();
            } else {
                showPopup(view);
            }
        }
    });
    return root;
}
Also used : SlidingTabLayout(de.mkrtchyan.recoverytools.view.SlidingTabLayout) View(android.view.View) AdapterView(android.widget.AdapterView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ListView(android.widget.ListView) ViewPager(android.support.v4.view.ViewPager) FloatingActionButton(android.support.design.widget.FloatingActionButton) AdapterView(android.widget.AdapterView) TypedValue(android.util.TypedValue)

Aggregations

FloatingActionButton (android.support.design.widget.FloatingActionButton)1 ViewPager (android.support.v4.view.ViewPager)1 AppCompatTextView (android.support.v7.widget.AppCompatTextView)1 TypedValue (android.util.TypedValue)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 SlidingTabLayout (de.mkrtchyan.recoverytools.view.SlidingTabLayout)1