Search in sources :

Example 6 with DOWN

use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureNotificationSettings method initLockscreenNotifications.

private void initLockscreenNotifications() {
    mLockscreen = (RestrictedDropDownPreference) getPreferenceScreen().findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
    if (mLockscreen == null) {
        Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
        return;
    }
    ArrayList<CharSequence> entries = new ArrayList<>();
    ArrayList<CharSequence> values = new ArrayList<>();
    entries.add(getString(R.string.lock_screen_notifications_summary_disable));
    values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable));
    String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show);
    String summaryShowEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_show);
    entries.add(summaryShowEntry);
    values.add(summaryShowEntryValue);
    setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
    if (mSecure) {
        String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
        String summaryHideEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_hide);
        entries.add(summaryHideEntry);
        values.add(summaryHideEntryValue);
        setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
    }
    mLockscreen.setEntries(entries.toArray(new CharSequence[entries.size()]));
    mLockscreen.setEntryValues(values.toArray(new CharSequence[values.size()]));
    updateLockscreenNotifications();
    if (mLockscreen.getEntries().length > 1) {
        mLockscreen.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final int val = Integer.parseInt((String) newValue);
                if (val == mLockscreenSelectedValue) {
                    return false;
                }
                final boolean enabled = val != R.string.lock_screen_notifications_summary_disable;
                final boolean show = val == R.string.lock_screen_notifications_summary_show;
                Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
                Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
                mLockscreenSelectedValue = val;
                return true;
            }
        });
    } else {
        // There is one or less option for the user, disable the drop down.
        mLockscreen.setEnabled(false);
    }
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 7 with DOWN

use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project UltimateAndroid by cymcsg.

the class BlurDialogEngine method blur.

/**
     * Blur the given bitmap and add it to the activity.
     *
     * @param bkg  should be a bitmap of the background.
     * @param view background view.
     */
private void blur(Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    //define layout params to the previous imageView in order to match its parent
    mBlurredBackgroundLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    //overlay used to build scaled preview and blur background
    Bitmap overlay = null;
    //evaluate top offset due to action bar
    int actionBarHeight = 0;
    try {
        if (mHoldingActivity instanceof ActionBarActivity) {
            ActionBar supportActionBar = ((ActionBarActivity) mHoldingActivity).getSupportActionBar();
            if (supportActionBar != null) {
                actionBarHeight = supportActionBar.getHeight();
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.app.ActionBar actionBar = mHoldingActivity.getActionBar();
            if (actionBar != null) {
                actionBarHeight = actionBar.getHeight();
            }
        }
    } catch (NoClassDefFoundError e) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.app.ActionBar actionBar = mHoldingActivity.getActionBar();
            if (actionBar != null) {
                actionBarHeight = actionBar.getHeight();
            }
        }
    }
    //evaluate top offset due to status bar
    int statusBarHeight = 0;
    if ((mHoldingActivity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0) {
        //not in fullscreen mode
        statusBarHeight = getStatusBarHeight();
    }
    final int topOffset = actionBarHeight + statusBarHeight;
    final int bottomOffset = getNavigationBarOffset();
    //add offset to the source boundaries since we don't want to blur actionBar pixels
    Rect srcRect = new Rect(0, actionBarHeight + statusBarHeight, bkg.getWidth(), bkg.getHeight() - bottomOffset);
    //in order to keep the same ratio as the one which will be used for rendering, also
    //add the offset to the overlay.
    overlay = Bitmap.createBitmap((int) ((view.getWidth()) / mDownScaleFactor), (int) ((view.getMeasuredHeight() - topOffset - bottomOffset) / mDownScaleFactor), Bitmap.Config.RGB_565);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || mHoldingActivity instanceof ActionBarActivity) {
        //add offset as top margin since actionBar height must also considered when we display
        // the blurred background. Don't want to draw on the actionBar.
        mBlurredBackgroundLayoutParams.setMargins(0, actionBarHeight, 0, 0);
        mBlurredBackgroundLayoutParams.gravity = Gravity.TOP;
    }
    //scale and draw background view on the canvas overlay
    Canvas canvas = new Canvas(overlay);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    //build drawing destination boundaries
    final RectF destRect = new RectF(0, 0, overlay.getWidth(), overlay.getHeight());
    //draw background from source area in source background to the destination area on the overlay
    canvas.drawBitmap(bkg, srcRect, destRect, paint);
    //apply fast blur on overlay
    overlay = FastBlurHelper.doBlur(overlay, mBlurRadius, false);
    if (mDebudEnable) {
        String blurTime = (System.currentTimeMillis() - startMs) + " ms";
        //display information in LogCat
        Log.d(TAG, "Radius : " + mBlurRadius);
        Log.d(TAG, "Down Scale Factor : " + mDownScaleFactor);
        Log.d(TAG, "Blurred achieved in : " + blurTime);
        Log.d(TAG, "Allocation : " + bkg.getRowBytes() + "ko (screen capture) + " + overlay.getRowBytes() + "ko (FastBlur)");
        //display blurring time directly on screen
        Rect bounds = new Rect();
        Canvas canvas1 = new Canvas(overlay);
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        paint.setTextSize(20.0f);
        paint.getTextBounds(blurTime, 0, blurTime.length(), bounds);
        canvas1.drawText(blurTime, 2, bounds.height(), paint);
    }
    //set bitmap in an image view for final rendering
    mBlurredBackgroundView = new ImageView(mHoldingActivity);
    mBlurredBackgroundView.setImageDrawable(new BitmapDrawable(mHoldingActivity.getResources(), overlay));
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) ActionBarActivity(android.support.v7.app.ActionBarActivity) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ActionBar(android.support.v7.app.ActionBar)

Example 8 with DOWN

use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project Shuttle by timusus.

the class ScrollableViewHelper method getScrollableViewScrollPosition.

/**
     * Returns the current scroll position of the scrollable view. If this method returns zero or
     * less, it means at the scrollable view is in a position such as the panel should handle
     * scrolling. If the method returns anything above zero, then the panel will let the scrollable
     * view handle the scrolling
     *
     * @param scrollableView the scrollable view
     * @param isSlidingUp    whether or not the panel is sliding up or down
     * @return the scroll position
     */
public int getScrollableViewScrollPosition(View scrollableView, boolean isSlidingUp) {
    if (scrollableView == null)
        return 0;
    if (scrollableView instanceof ScrollView) {
        if (isSlidingUp) {
            return scrollableView.getScrollY();
        } else {
            ScrollView sv = ((ScrollView) scrollableView);
            View child = sv.getChildAt(0);
            return (child.getBottom() - (sv.getHeight() + sv.getScrollY()));
        }
    } else if (scrollableView instanceof ListView && ((ListView) scrollableView).getChildCount() > 0) {
        ListView lv = ((ListView) scrollableView);
        if (lv.getAdapter() == null)
            return 0;
        if (isSlidingUp) {
            View firstChild = lv.getChildAt(0);
            // Approximate the scroll position based on the top child and the first visible item
            return lv.getFirstVisiblePosition() * firstChild.getHeight() - firstChild.getTop();
        } else {
            View lastChild = lv.getChildAt(lv.getChildCount() - 1);
            // Approximate the scroll position based on the bottom child and the last visible item
            return (lv.getAdapter().getCount() - lv.getLastVisiblePosition() - 1) * lastChild.getHeight() + lastChild.getBottom() - lv.getBottom();
        }
    } else if (scrollableView instanceof RecyclerView && ((RecyclerView) scrollableView).getChildCount() > 0) {
        RecyclerView rv = ((RecyclerView) scrollableView);
        //return a value > 0
        if (rv instanceof NestedScrollBlocker) {
            if (!((NestedScrollBlocker) rv).getBlockScroll()) {
                return 1;
            }
        }
        RecyclerView.LayoutManager lm = rv.getLayoutManager();
        if (rv.getAdapter() == null)
            return 0;
        if (isSlidingUp) {
            View firstChild = rv.getChildAt(0);
            // Approximate the scroll position based on the top child and the first visible item
            return rv.getChildLayoutPosition(firstChild) * lm.getDecoratedMeasuredHeight(firstChild) - lm.getDecoratedTop(firstChild);
        } else {
            View lastChild = rv.getChildAt(rv.getChildCount() - 1);
            // Approximate the scroll position based on the bottom child and the last visible item
            return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
        }
    } else {
        return 0;
    }
}
Also used : ListView(android.widget.ListView) ScrollView(android.widget.ScrollView) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) ListView(android.widget.ListView)

Example 9 with DOWN

use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project iNGAGE by davis123123.

the class FrontPageFragment method onViewCreated.

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    threadListRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_posts);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    threadListRecyclerView.setLayoutManager(layoutManager);
    threadListRecyclerView.setAdapter(threadListAdapter);
    Log.d("STATE", "serverstring" + json_string);
    inflateThreads();
    postThreadButton = (FloatingActionButton) rootView.findViewById(R.id.fab);
    postThreadButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v == postThreadButton) {
                // goInsertThread();
                session.updatePage("date");
                /* initilize FrontPage Fragment*/
                final FragmentManager fragmentManager = getFragmentManager();
                final Class fragmentClass = FrontPageFragment.class;
                final Fragment fragment = Fragment.instantiate(getContext(), fragmentClass.getName());
                fragmentManager.beginTransaction().replace(R.id.main_fragment_container, fragment, fragmentClass.getSimpleName()).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
                Toast.makeText(getActivity(), "Page refreshed!", Toast.LENGTH_LONG).show();
            }
        }
    });
    threadListAdapter.setOnLoadMoreListener(new ThreadListAdapter.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            Log.d("haint", "Load More");
            // threadListAdapter.list.add(null);
            // threadListAdapter.notifyItemInserted(threadListAdapter.list.size() - 1);
            rowCount += 10;
            Thread getJSON = new Thread(new Runnable() {

                @Override
                public void run() {
                    getThreadsJSON(rowCount);
                    while (true) {
                        if (!threadListAdapter.getLoadStat()) {
                            Log.d("haint", "Load More222");
                            break;
                        }
                    // no longer loading
                    }
                }
            });
            getJSON.start();
            try {
                getJSON.join();
                // threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
                // threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
                inflateThreads();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        // getThreadsJSON(rowCount);
        // inflateThreads();
        /*new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Log.e("haint", "Load More 2");
                        threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
                        threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
                        rowCount += 10;
                        getThreadsJSON(rowCount);
                        inflateThreads();
                        threadListAdapter.setLoaded();
                    }
                }, 10000);*/
        }
    });
    threadListRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            Log.d("...", "Lastnot Item Wow !");
            if (// check for scroll down
            dy > 0) {
                visibleItemCount = layoutManager.getChildCount();
                totalItemCount = layoutManager.getItemCount();
                pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
                if (!threadListAdapter.isLoading && (visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    // if(mOnLoadMoreListener != null){
                    Log.d("...", "Last Item Wow !");
                    threadListAdapter.isLoading = true;
                    // threadListAdapter.list.add(null);
                    threadListAdapter.mOnLoadMoreListener.onLoadMore();
                // }
                // loading = false;
                // rowCount += 10;
                // getThreadsJSON(rowCount);
                // inflateThreads();
                // Do pagination.. i.e. fetch new data
                }
            }
        }
    });
}
Also used : ThreadListAdapter(ingage.ingage20.adapters.ThreadListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Fragment(android.support.v4.app.Fragment) FragmentManager(android.support.v4.app.FragmentManager) RecyclerView(android.support.v7.widget.RecyclerView)

Example 10 with DOWN

use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project boilerplate by koush.

the class ScrollingToolbarLayout method enableToolbarScrollOff.

public void enableToolbarScrollOff(final IHeaderRecyclerView headerRecyclerView, final Fragment fragment) {
    scrollOffEnabled = true;
    int extra;
    View paddingView;
    if (getChildCount() == 3)
        paddingView = getChildAt(0);
    else
        paddingView = getChildAt(getChildCount() - 1);
    if (paddingView.getLayoutParams().height > 0) {
        extra = paddingView.getLayoutParams().height;
    } else {
        // apparently this is the max size allowed
        final int SIZE_MAX = 1073741823;
        paddingView.measure(MeasureSpec.makeMeasureSpec(SIZE_MAX, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(SIZE_MAX, MeasureSpec.AT_MOST));
        extra = paddingView.getMeasuredHeight();
    }
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, extra);
    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setLayoutParams(lp);
    headerRecyclerView.addHeaderView(0, frameLayout);
    headerRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView absListView, int scrollState) {
            // when scrolling stops, and the toolbar is only partially scrolled off, force to scroll bar in completely
            if (scrollState != RecyclerView.SCROLL_STATE_IDLE)
                return;
            if (absListView.getChildCount() < 1)
                return;
            int firstVisibleItem = headerRecyclerView.findFirstVisibleItemPosition();
            if (firstVisibleItem != 0)
                return;
            final View toolbarContainer = getChildAt(getChildCount() - 1);
            if (toolbarContainer.getTranslationY() <= -toolbarContainer.getHeight() || (existingToolbarYAnimation != null && existingToolbarYEnd <= toolbarContainer.getHeight()))
                return;
            toolbarScrollIn();
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (recyclerView.getChildCount() < 1)
                return;
            if (fragment != null && !fragment.getUserVisibleHint())
                return;
            // cancelToolbarScroll();
            final View firstView = recyclerView.getChildAt(0);
            final View toolbarContainer = getChildAt(getChildCount() - 1);
            final View backdrop;
            if (getChildCount() == 3)
                backdrop = getChildAt(0);
            else
                backdrop = null;
            final int toolbarHeight = toolbarContainer.getHeight();
            int firstVisibleItem = headerRecyclerView.findFirstVisibleItemPosition();
            if (backdrop != null) {
                int newBackdropHeight;
                int backdropHeight = getResources().getDimensionPixelSize(R.dimen.icon_list_drawer_activity_backdrop_height);
                if (firstVisibleItem >= 1) {
                    newBackdropHeight = toolbarHeight;
                } else {
                    newBackdropHeight = firstView.getTop() + backdropHeight;
                }
                newBackdropHeight = Math.max(newBackdropHeight, toolbarHeight);
                FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) backdrop.getLayoutParams();
                lp.height = newBackdropHeight;
                // another option is to use y translation to not do parallax
                backdrop.setLayoutParams(lp);
                if (newBackdropHeight / (float) backdropHeight < .5f) {
                    toolbarFadeToPrimary();
                } else {
                    toolbarFadeToTranslucent();
                }
            }
            if (firstVisibleItem == 0) {
                int remainder = firstView.getHeight() + firstView.getTop();
                // if there's less than toolbar height left, start scrolling off.
                if (remainder < toolbarHeight) {
                    remainder = toolbarHeight - remainder;
                    if (existingToolbarYAnimation == null) {
                        float diff = -remainder - toolbarContainer.getTranslationY();
                        if (false && Math.abs(diff) > toolbarHeight / 4) {
                            if (toolbarContainer.getTranslationY() < -remainder) {
                                // scrolling down
                                toolbarScrollIn();
                            } else {
                                // scrolling up
                                toolbarScrollOut();
                            }
                        } else {
                            toolbarContainer.setTranslationY(-remainder);
                        }
                    }
                    if (backdrop != null)
                        backdrop.setTranslationY(-remainder);
                } else {
                    cancelToolbarScroll();
                    toolbarContainer.setTranslationY(0);
                    // toolbarScrollIn();
                    if (backdrop != null)
                        backdrop.setTranslationY(0);
                }
                return;
            }
            if (firstVisibleItem == 1) {
                cancelToolbarScroll();
                toolbarContainer.setTranslationY(-toolbarHeight);
            } else {
                toolbarScrollOut();
            }
            if (backdrop != null)
                backdrop.setTranslationY(-toolbarHeight);
        }
    });
    if (getChildCount() == 3)
        toolbarFadeToTranslucent();
}
Also used : FrameLayout(android.widget.FrameLayout) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) IHeaderRecyclerView(com.koushikdutta.boilerplate.recyclerview.IHeaderRecyclerView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) IHeaderRecyclerView(com.koushikdutta.boilerplate.recyclerview.IHeaderRecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)37 View (android.view.View)37 Intent (android.content.Intent)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 TextView (android.widget.TextView)16 ImageView (android.widget.ImageView)15 Preference (android.support.v7.preference.Preference)14 Context (android.content.Context)13 PreferenceCategory (android.support.v7.preference.PreferenceCategory)12 BroadcastReceiver (android.content.BroadcastReceiver)8 IntentFilter (android.content.IntentFilter)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 Button (android.widget.Button)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 OnClickListener (android.view.View.OnClickListener)6 FrameLayout (android.widget.FrameLayout)6 SharedPreferences (android.content.SharedPreferences)5 SwitchPreference (android.support.v14.preference.SwitchPreference)5