Search in sources :

Example 1 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class RecyclerViewFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
    if (mHandler == null) {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                mHandler = new Handler();
            }
        });
    }
    mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerview);
    if (mViewPagerFragments != null && !hideBanner()) {
        FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
        for (Fragment fragment : mViewPagerFragments) {
            fragmentTransaction.remove(fragment);
        }
        fragmentTransaction.commit();
        mViewPagerFragments.clear();
    } else {
        mViewPagerFragments = new ArrayList<>();
    }
    mViewPagerParent = mRootView.findViewById(R.id.viewpagerparent);
    mViewPager = (ViewPager) mRootView.findViewById(R.id.viewpager);
    mViewPager.setVisibility(View.INVISIBLE);
    mViewPagerShadow = mRootView.findViewById(R.id.viewpager_shadow);
    mViewPagerShadow.setVisibility(View.INVISIBLE);
    mCirclePageIndicator = (CirclePageIndicator) mRootView.findViewById(R.id.indicator);
    resizeBanner();
    mViewPagerParent.setVisibility(View.INVISIBLE);
    ViewUtils.dismissDialog(getChildFragmentManager());
    mProgress = mRootView.findViewById(R.id.progress);
    mAppBarLayout = ((BaseActivity) getActivity()).getAppBarLayout();
    mToolBar = ((BaseActivity) getActivity()).getToolBar();
    if (mAppBarLayout != null && !isForeground()) {
        mAppBarLayout.postDelayed(new Runnable() {

            @Override
            public void run() {
                if (mAppBarLayout != null && isAdded() && getActivity() != null) {
                    ViewCompat.setElevation(mAppBarLayout, showViewPager() && !hideBanner() ? 0 : getResources().getDimension(R.dimen.app_bar_elevation));
                }
            }
        }, 150);
    }
    mTopFab = (FloatingActionButton) mRootView.findViewById(R.id.top_fab);
    mBottomFab = (FloatingActionButton) mRootView.findViewById(R.id.bottom_fab);
    mRecyclerView.clearOnScrollListeners();
    if (showViewPager() && !hideBanner()) {
        mScroller = new Scroller();
        mRecyclerView.addOnScrollListener(mScroller);
    }
    mRecyclerView.setAdapter(mRecyclerViewAdapter == null ? mRecyclerViewAdapter = new RecyclerViewAdapter(mItems, new RecyclerViewAdapter.OnViewChangedListener() {

        @Override
        public void viewChanged() {
            getHandler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isAdded() && getActivity() != null) {
                        adjustScrollPosition();
                    }
                }
            }, 250);
        }
    }) : mRecyclerViewAdapter);
    mRecyclerView.setLayoutManager(mLayoutManager = getLayoutManager());
    if (!Utils.DONATED && !showTopFab() && !isForeground() && getActivity() instanceof NavigationActivity && showAd() && mAdView == null) {
        mAdView = new AdView();
    } else {
        mAdView = null;
    }
    mTopFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onTopFabClick();
        }
    });
    {
        Drawable drawable;
        if ((drawable = getTopFabDrawable()) != null) {
            mTopFab.setImageDrawable(drawable);
        }
    }
    mBottomFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBottomFabClick();
        }
    });
    {
        Drawable drawable;
        if ((drawable = getBottomFabDrawable()) != null) {
            mBottomFab.setImageDrawable(drawable);
        }
    }
    BaseFragment foregroundFragment = getForegroundFragment();
    mForegroundVisible = false;
    if (foregroundFragment != null) {
        mForegroundParent = mRootView.findViewById(R.id.foreground_parent);
        mForegroundText = (TextView) mRootView.findViewById(R.id.foreground_text);
        mForegroundText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismissForeground();
            }
        });
        getChildFragmentManager().beginTransaction().replace(R.id.foreground_content, foregroundFragment).commit();
        mForegroundHeight = getResources().getDisplayMetrics().heightPixels;
    }
    if (itemsSize() == 0) {
        mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                showProgress();
                init();
            }

            @Override
            protected List<RecyclerViewItem> doInBackground(Void... params) {
                if (mDelay && needDelay()) {
                    try {
                        Thread.sleep(250);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    mDelay = false;
                }
                if (isAdded() && getActivity() != null) {
                    List<RecyclerViewItem> items = new ArrayList<>();
                    addItems(items);
                    return items;
                }
                return null;
            }

            @Override
            protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
                super.onPostExecute(recyclerViewItems);
                if (isCancelled() || recyclerViewItems == null)
                    return;
                for (RecyclerViewItem item : recyclerViewItems) {
                    addItem(item);
                }
                hideProgress();
                postInit();
                mRecyclerView.post(new Runnable() {

                    @Override
                    public void run() {
                        Activity activity;
                        if ((activity = getActivity()) != null) {
                            mRecyclerView.scrollToPosition(0);
                            mLayoutManager.scrollToPosition(0);
                            mRecyclerView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.slide_in_bottom));
                        }
                    }
                });
                if (savedInstanceState == null) {
                    mViewPager.post(new Runnable() {

                        @Override
                        public void run() {
                            if (getActivity() != null) {
                                int cx = mViewPager.getWidth();
                                SupportAnimator animator = ViewAnimationUtils.createCircularReveal(mViewPager, cx / 2, 0, 0, cx);
                                animator.addListener(new SupportAnimator.SimpleAnimatorListener() {

                                    @Override
                                    public void onAnimationStart() {
                                        super.onAnimationStart();
                                        mViewPager.setVisibility(View.VISIBLE);
                                    }

                                    @Override
                                    public void onAnimationEnd() {
                                        super.onAnimationEnd();
                                        mViewPagerShadow.setVisibility(View.VISIBLE);
                                    }
                                });
                                animator.setDuration(400);
                                animator.start();
                            }
                        }
                    });
                } else {
                    mViewPager.setVisibility(View.VISIBLE);
                    mViewPagerShadow.setVisibility(View.VISIBLE);
                }
                mLoader = null;
            }
        };
        mLoader.execute();
    } else {
        showProgress();
        init();
        hideProgress();
        postInit();
        adjustScrollPosition();
        mViewPager.setVisibility(View.VISIBLE);
        mViewPagerShadow.setVisibility(View.VISIBLE);
    }
    return mRootView;
}
Also used : BaseActivity(com.moro.mtweaks.activities.BaseActivity) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Activity(android.app.Activity) RecyclerViewAdapter(com.moro.mtweaks.views.recyclerview.RecyclerViewAdapter) Fragment(android.support.v4.app.Fragment) FragmentTransaction(android.support.v4.app.FragmentTransaction) SupportAnimator(io.codetail.animation.SupportAnimator) ArrayList(java.util.ArrayList) List(java.util.List) AdView(com.moro.mtweaks.views.recyclerview.AdView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) AdView(com.moro.mtweaks.views.recyclerview.AdView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Nullable(android.support.annotation.Nullable)

Example 2 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class RecyclerViewFragment method onPause.

@Override
public void onPause() {
    super.onPause();
    mHandler.removeCallbacks(mRefresh);
    for (RecyclerViewItem item : mItems) {
        item.onPause();
    }
}
Also used : RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 3 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class LMKFragment method profileInit.

private void profileInit(List<RecyclerViewItem> items) {
    TitleView profilesTitle = new TitleView();
    profilesTitle.setText(getString(R.string.profile));
    items.add(profilesTitle);
    for (int id : sProfiles.keySet()) {
        DescriptionView profile = new DescriptionView();
        profile.setTitle(getString(id));
        profile.setSummary(sProfiles.get(id));
        profile.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

            @Override
            public void onClick(RecyclerViewItem item) {
                LMK.setMinFree(((DescriptionView) item).getSummary().toString(), getActivity());
                refreshMinFree();
            }
        });
        items.add(profile);
    }
}
Also used : DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) TitleView(com.moro.mtweaks.views.recyclerview.TitleView) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 4 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class PathReaderFragment method load.

private void load(List<RecyclerViewItem> items) {
    if (mPath == null)
        return;
    String path = mPath;
    if (path.contains("%d")) {
        path = Utils.strFormat(mPath, mMin);
    }
    RootFile files = new RootFile(path);
    for (final RootFile file : files.listFiles()) {
        final String name = file.getName();
        final String value = file.readFile();
        if (value != null && !value.isEmpty() && !value.contains("\n")) {
            DescriptionView descriptionView = new DescriptionView();
            descriptionView.setTitle(name);
            descriptionView.setSummary(value);
            descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                @Override
                public void onClick(RecyclerViewItem item) {
                    List<Integer> freqs = CPUFreq.getFreqs(mMin);
                    int freq = Utils.strToInt(value);
                    if (freqs != null && freq != 0 && freqs.contains(freq)) {
                        String[] values = new String[freqs.size()];
                        for (int i = 0; i < values.length; i++) {
                            values[i] = String.valueOf(freqs.get(i));
                        }
                        showArrayDialog(value, values, mPath + "/" + name, name);
                    } else {
                        showEditTextDialog(value, name);
                    }
                }
            });
            items.add(descriptionView);
        }
    }
}
Also used : DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) ArrayList(java.util.ArrayList) List(java.util.List) RootFile(com.moro.mtweaks.utils.root.RootFile) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 5 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class ScreenFragment method restoreValuesInit.

private void restoreValuesInit(List<RecyclerViewItem> items) {
    ButtonView2 bv = new ButtonView2();
    bv.setSummary(getString(R.string.restore_summary));
    bv.setButtonText(getString(R.string.restore_button));
    bv.setOnItemClickListener(new ButtonView2.OnItemClickListener() {

        @Override
        public void onClick(RecyclerViewItem item) {
            Calibration.restoreCalibrationStockValues(getActivity());
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.content_frame, new ScreenFragment()).commit();
        }
    });
    items.add(bv);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) ButtonView2(com.moro.mtweaks.views.recyclerview.ButtonView2) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Aggregations

RecyclerViewItem (com.moro.mtweaks.views.recyclerview.RecyclerViewItem)42 ArrayList (java.util.ArrayList)26 TitleView (com.moro.mtweaks.views.recyclerview.TitleView)18 DescriptionView (com.moro.mtweaks.views.recyclerview.DescriptionView)16 SwitchView (com.moro.mtweaks.views.recyclerview.SwitchView)15 SeekBarView (com.moro.mtweaks.views.recyclerview.SeekBarView)14 CardView (com.moro.mtweaks.views.recyclerview.CardView)9 List (java.util.List)9 SelectView (com.moro.mtweaks.views.recyclerview.SelectView)8 AsyncTask (android.os.AsyncTask)6 DialogInterface (android.content.DialogInterface)5 Intent (android.content.Intent)3 Activity (android.app.Activity)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 PopupMenu (android.support.v7.widget.PopupMenu)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 Profiles (com.moro.mtweaks.database.tools.profiles.Profiles)2 Dialog (com.moro.mtweaks.views.dialog.Dialog)2 ProgressDialog (android.app.ProgressDialog)1