Example usage for android.view View setPadding

List of usage examples for android.view View setPadding

Introduction

In this page you can find the example usage for android.view View setPadding.

Prototype

public void setPadding(int left, int top, int right, int bottom) 

Source Link

Document

Sets the padding.

Usage

From source file:com.miz.functions.MizLib.java

/**
 * Add a padding with a height of the ActionBar to the bottom of a given View
 * @param c/*from   w  ww. j  a v a2s . co m*/
 * @param v
 */
public static void addActionBarPaddingBottom(Context c, View v) {
    int mActionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    v.setPadding(0, 0, 0, mActionBarHeight);
}

From source file:github.daneren2005.dsub.fragments.NowPlayingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    rootView = inflater.inflate(R.layout.download, container, false);
    setTitle(R.string.button_bar_now_playing);

    WindowManager w = context.getWindowManager();
    Display d = w.getDefaultDisplay();//from w  w  w .  j a  v  a2s .c  o  m
    swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    gestureScanner = new GestureDetector(this);

    playlistFlipper = (ViewFlipper) rootView.findViewById(R.id.download_playlist_flipper);
    emptyTextView = (TextView) rootView.findViewById(R.id.download_empty);
    songTitleTextView = (TextView) rootView.findViewById(R.id.download_song_title);
    albumArtImageView = (ImageView) rootView.findViewById(R.id.download_album_art_image);
    positionTextView = (TextView) rootView.findViewById(R.id.download_position);
    durationTextView = (TextView) rootView.findViewById(R.id.download_duration);
    statusTextView = (TextView) rootView.findViewById(R.id.download_status);
    progressBar = (SeekBar) rootView.findViewById(R.id.download_progress_bar);
    previousButton = (AutoRepeatButton) rootView.findViewById(R.id.download_previous);
    nextButton = (AutoRepeatButton) rootView.findViewById(R.id.download_next);
    pauseButton = rootView.findViewById(R.id.download_pause);
    stopButton = rootView.findViewById(R.id.download_stop);
    startButton = rootView.findViewById(R.id.download_start);
    repeatButton = (ImageButton) rootView.findViewById(R.id.download_repeat);
    bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark);
    rateBadButton = (ImageButton) rootView.findViewById(R.id.download_rating_bad);
    rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good);
    toggleListButton = rootView.findViewById(R.id.download_toggle_list);

    playlistView = (RecyclerView) rootView.findViewById(R.id.download_list);
    FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.download_fast_scroller);
    fastScroller.attachRecyclerView(playlistView);
    setupLayoutManager(playlistView, false);
    ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, true));
    touchHelper.attachToRecyclerView(playlistView);

    starButton = (ImageButton) rootView.findViewById(R.id.download_star);
    if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) {
        starButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
                if (currentDownload != null) {
                    final Entry currentSong = currentDownload.getSong();
                    toggleStarred(currentSong, new OnStarChange() {
                        @Override
                        void starChange(boolean starred) {
                            if (currentSong.isStarred()) {
                                starButton.setImageDrawable(
                                        DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
                            } else {
                                if (context.getResources()
                                        .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                                    starButton.setImageResource(
                                            DrawableTint.getDrawableRes(context, R.attr.star_outline));
                                } else {
                                    starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark);
                                }
                            }
                        }
                    });
                }
            }
        });
    } else {
        starButton.setVisibility(View.GONE);
    }

    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent me) {
            return gestureScanner.onTouchEvent(me);
        }
    };
    pauseButton.setOnTouchListener(touchListener);
    stopButton.setOnTouchListener(touchListener);
    startButton.setOnTouchListener(touchListener);
    bookmarkButton.setOnTouchListener(touchListener);
    rateBadButton.setOnTouchListener(touchListener);
    rateGoodButton.setOnTouchListener(touchListener);
    emptyTextView.setOnTouchListener(touchListener);
    albumArtImageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent me) {
            if (me.getAction() == MotionEvent.ACTION_DOWN) {
                lastY = (int) me.getRawY();
            }
            return gestureScanner.onTouchEvent(me);
        }
    });

    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfStorageUnavailable();
            new SilentBackgroundTask<Void>(context) {
                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().previous();
                    return null;
                }
            }.execute();
            setControlsVisible(true);
        }
    });
    previousButton.setOnRepeatListener(new Runnable() {
        public void run() {
            changeProgress(-INCREMENT_TIME);
        }
    });

    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfStorageUnavailable();
            new SilentBackgroundTask<Boolean>(context) {
                @Override
                protected Boolean doInBackground() throws Throwable {
                    getDownloadService().next();
                    return true;
                }
            }.execute();
            setControlsVisible(true);
        }
    });
    nextButton.setOnRepeatListener(new Runnable() {
        public void run() {
            changeProgress(INCREMENT_TIME);
        }
    });

    pauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new SilentBackgroundTask<Void>(context) {
                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().pause();
                    return null;
                }
            }.execute();
        }
    });

    stopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new SilentBackgroundTask<Void>(context) {
                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().reset();
                    return null;
                }
            }.execute();
        }
    });

    startButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfStorageUnavailable();
            new SilentBackgroundTask<Void>(context) {
                @Override
                protected Void doInBackground() throws Throwable {
                    start();
                    return null;
                }
            }.execute();
        }
    });

    repeatButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
            getDownloadService().setRepeatMode(repeatMode);
            switch (repeatMode) {
            case OFF:
                Util.toast(context, R.string.download_repeat_off);
                break;
            case ALL:
                Util.toast(context, R.string.download_repeat_all);
                break;
            case SINGLE:
                Util.toast(context, R.string.download_repeat_single);
                break;
            default:
                break;
            }
            updateRepeatButton();
            setControlsVisible(true);
        }
    });

    bookmarkButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            createBookmark();
        }
    });

    rateBadButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DownloadService downloadService = getDownloadService();
            if (downloadService == null) {
                return;
            }

            DownloadFile downloadFile = downloadService.getCurrentPlaying();
            if (downloadFile == null) {
                return;
            }
            Entry entry = downloadFile.getSong();

            // If rating == 1, already set so unset
            if (entry.getRating() == 1) {
                setRating(entry, 0);

                if (context.getResources()
                        .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                    rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_dark);
                } else {
                    rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad));
                }
            } else {
                // Immediately skip to the next song
                downloadService.next(true);

                // Otherwise set rating to 1
                setRating(entry, 1);
                rateBadButton.setImageDrawable(
                        DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_bad_selected));

                // Make sure good rating is blank
                if (context.getResources()
                        .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                    rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_dark);
                } else {
                    rateGoodButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good));
                }
            }
        }
    });
    rateGoodButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DownloadService downloadService = getDownloadService();
            if (downloadService == null) {
                return;
            }

            DownloadFile downloadFile = downloadService.getCurrentPlaying();
            if (downloadFile == null) {
                return;
            }
            Entry entry = downloadFile.getSong();

            // If rating == 5, already set so unset
            if (entry.getRating() == 5) {
                setRating(entry, 0);

                if (context.getResources()
                        .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                    rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_dark);
                } else {
                    rateGoodButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good));
                }
            } else {
                // Otherwise set rating to maximum
                setRating(entry, 5);
                rateGoodButton.setImageDrawable(
                        DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_good_selected));

                // Make sure bad rating is blank
                if (context.getResources()
                        .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                    rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_dark);
                } else {
                    rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad));
                }
            }
        }
    });

    toggleListButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleFullscreenAlbumArt();
            setControlsVisible(true);
        }
    });

    View overlay = rootView.findViewById(R.id.download_overlay_buttons);
    final int overlayHeight = overlay != null ? overlay.getHeight() : -1;
    albumArtImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (overlayHeight == -1 || lastY < (view.getBottom() - overlayHeight)) {
                toggleFullscreenAlbumArt();
                setControlsVisible(true);
            }
        }
    });

    progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
            new SilentBackgroundTask<Void>(context) {
                @Override
                protected Void doInBackground() throws Throwable {
                    getDownloadService().seekTo(progressBar.getProgress());
                    return null;
                }

                @Override
                protected void done(Void result) {
                    seekInProgress = false;
                }
            }.execute();
        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
            seekInProgress = true;
        }

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) {
            if (fromUser) {
                positionTextView.setText(Util.formatDuration(position / 1000));
                setControlsVisible(true);
            }
        }
    });

    if (Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) {
        View slider = rootView.findViewById(R.id.download_slider);
        slider.setPadding(0, 0, 0, 0);
    }

    return rootView;
}

From source file:com.icenler.lib.view.support.percentlayout.PercentLayoutHelper.java

private void supportPadding(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    int left = view.getPaddingLeft(), right = view.getPaddingRight(), top = view.getPaddingTop(),
            bottom = view.getPaddingBottom();
    PercentLayoutInfo.PercentVal percentVal = info.paddingLeftPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        left = (int) (base * percentVal.percent);
    }/*  www  .  ja v a  2s.c om*/
    percentVal = info.paddingRightPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        right = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingTopPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        top = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingBottomPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        bottom = (int) (base * percentVal.percent);
    }
    view.setPadding(left, top, right, bottom);

}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final View contentView = window.findViewById(android.R.id.content);
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + Utils.getActionBarHeight(this) - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;// w w  w.j ava2s  .c o m
}

From source file:com.aware.Aware.java

/**
 * Given a plugin's package name, fetch the context card for reuse.
 * @param context: application context/*  w  w w .j ava 2 s . co  m*/
 * @param package_name: plugin's package name
 * @return View for reuse (instance of LinearLayout)
 */
public static View getContextCard(final Context context, final String package_name) {

    if (!isClassAvailable(context, package_name, "ContextCard")) {
        return null;
    }

    String ui_class = package_name + ".ContextCard";
    LinearLayout card = new LinearLayout(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    card.setLayoutParams(params);
    card.setOrientation(LinearLayout.VERTICAL);

    try {
        Context packageContext = context.createPackageContext(package_name,
                Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);

        Class<?> fragment_loader = packageContext.getClassLoader().loadClass(ui_class);
        Object fragment = fragment_loader.newInstance();
        Method[] allMethods = fragment_loader.getDeclaredMethods();
        Method m = null;
        for (Method mItem : allMethods) {
            String mName = mItem.getName();
            if (mName.contains("getContextCard")) {
                mItem.setAccessible(true);
                m = mItem;
                break;
            }
        }

        View ui = (View) m.invoke(fragment, packageContext);
        if (ui != null) {
            //Check if plugin has settings. If it does, tapping the card shows the settings
            if (isClassAvailable(context, package_name, "Settings")) {
                ui.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent open_settings = new Intent();
                        open_settings.setClassName(package_name, package_name + ".Settings");
                        open_settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(open_settings);
                    }
                });
            }

            //Set card look-n-feel
            ui.setBackgroundColor(Color.WHITE);
            ui.setPadding(20, 20, 20, 20);
            card.addView(ui);

            LinearLayout shadow = new LinearLayout(context);
            LayoutParams params_shadow = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            params_shadow.setMargins(0, 0, 0, 10);
            shadow.setBackgroundColor(context.getResources().getColor(R.color.card_shadow));
            shadow.setMinimumHeight(5);
            shadow.setLayoutParams(params_shadow);
            card.addView(shadow);

            return card;
        } else {
            return null;
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final int actionBarHeight = ThemeUtils.getActionBarHeight(this);
    final View contentView = window.findViewById(android.R.id.content);
    final int[] location = new int[2];
    contentView.getLocationOnScreen(location);
    if (location[1] > actionBarHeight) {
        contentView.setPadding(contentView.getPaddingLeft(), 0, contentView.getPaddingRight(),
                contentView.getPaddingBottom());
        return true;
    }/*from  w  ww . j a v a 2  s .c  om*/
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + actionBarHeight - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a padding with a combined height of the ActionBar and Status bar to the top of a given View
 * @param c//from   w w  w .j ava2s .  c  o m
 * @param v
 */
public static void addActionBarAndStatusBarPadding(Context c, View v) {
    int mActionBarHeight = 0, mStatusBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    if (hasKitKat())
        mStatusBarHeight = convertDpToPixels(c, 25);

    v.setPadding(0, mActionBarHeight + mStatusBarHeight, 0, 0);
}

From source file:android.percent.support.PercentLayoutHelper.java

private void supportPadding(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    int left = view.getPaddingLeft(), right = view.getPaddingRight(), top = view.getPaddingTop(),
            bottom = view.getPaddingBottom();
    PercentLayoutInfo.PercentVal percentVal = info.paddingLeftPercent;
    if (percentVal != null) {
        int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
        left = (int) (base * percentVal.percent);
    }/*from  w w  w.  j  a  v  a2  s .c o  m*/
    percentVal = info.paddingRightPercent;
    if (percentVal != null) {
        int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
        right = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingTopPercent;
    if (percentVal != null) {
        int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
        top = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingBottomPercent;
    if (percentVal != null) {
        int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
        bottom = (int) (base * percentVal.percent);
    }
    view.setPadding(left, top, right, bottom);

}

From source file:im.vector.fragments.VectorRoomSettingsFragment.java

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        View listView = view.findViewById(android.R.id.list);

        if (null != listView) {
            listView.setPadding(0, 0, 0, 0);
        }/*  w  ww.j a v a 2  s  .  co  m*/

        // seems known issue that the preferences screen does not use the activity theme
        view.setBackgroundColor(ThemeUtils.getColor(getActivity(), R.attr.riot_primary_background_color));
        return view;
    }

From source file:com.google.android.apps.forscience.whistlepunk.review.RunReviewFragment.java

private void setTimepickerUi(View rootView, boolean showTimepicker) {
    if (showTimepicker) {
        mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() {
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                mode.setTitle(getResources().getString(R.string.edit_note_time));
                return true;
            }/*from  ww w .  j a  v a  2 s.c o  m*/

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                if (mActionMode != null) {
                    mActionMode = null;
                    dismissEditTimeDialog();
                }
            }
        });

        rootView.findViewById(R.id.embedded).setVisibility(View.VISIBLE);

        // Collapse app bar layout as much as possible to bring the graph to the top.
        AppBarLayout appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar_layout);
        appBarLayout.setExpanded(false);
        setFrozen(rootView, true);

        // Show a grey overlay over the notes. Make it so users can cancel the dialog
        // by clicking in the grey overlay to simulate a normal dialog.
        View notesOverlay = rootView.findViewById(R.id.pinned_note_overlay);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            // On Kitkat devices, the pinned note list is shown over the AppBarLayout
            // instead of under it. We can manually adjust the layout params to show it
            // in the right location and at the right size to cover just the pinned note
            // list.
            ViewGroup.MarginLayoutParams params = (CoordinatorLayout.LayoutParams) rootView
                    .findViewById(R.id.pinned_note_list).getLayoutParams();
            params.setMargins(0, 0, 0, 0);
            notesOverlay.setLayoutParams(params);
            notesOverlay.setPadding(0, 0, 0, 0);
        }

        notesOverlay.setVisibility(View.VISIBLE);
        notesOverlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActionMode.finish();
            }
        });

        EditTimeDialog dialog = (EditTimeDialog) getChildFragmentManager()
                .findFragmentByTag(EditTimeDialog.TAG);
        if (dialog != null) {
            mRunReviewOverlay.setActiveTimestamp(dialog.getCurrentTimestamp());
            mRunReviewOverlay.setOnTimestampChangeListener(dialog);
        }
    } else {
        if (mActionMode != null) {
            mActionMode.finish();
        }
        setFrozen(rootView, false);
        rootView.findViewById(R.id.pinned_note_overlay).setVisibility(View.GONE);
        rootView.findViewById(R.id.embedded).setVisibility(View.GONE);
    }
}