Example usage for android.view ViewGroup setPadding

List of usage examples for android.view ViewGroup setPadding

Introduction

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

Prototype

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

Source Link

Document

Sets the padding.

Usage

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_folders, container, false);
    mContext = getActivity().getApplicationContext();
    mFilesFoldersFragment = this;
    mApp = (Common) mContext;//from   w ww . ja v  a  2 s.com
    mFolderStateMap = new HashMap<String, Parcelable>();

    //Set the hidden files flag.
    SHOW_HIDDEN_FILES = mApp.getSharedPreferences().getBoolean("SHOW_HIDDEN_FILES", false);

    listView = (ListView) rootView.findViewById(R.id.folders_list_view);
    listView.setFastScrollEnabled(true);
    listView.setVisibility(View.INVISIBLE);

    //Set the background color based on the theme.
    rootView.setBackgroundColor(UIElementsHelper.getBackgroundColor(mContext));

    //Apply the ListView params.
    //Apply the ListViews' dividers.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        listView.setDivider(mContext.getResources().getDrawable(R.drawable.icon_list_divider));
    } else {
        listView.setDivider(mContext.getResources().getDrawable(R.drawable.icon_list_divider_light));
    }

    listView.setDividerHeight(1);

    //KitKat translucent navigation/status bar.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        int topPadding = Common.getStatusBarHeight(mContext);

        //Calculate navigation bar height.
        int navigationBarHeight = 0;
        int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            navigationBarHeight = getResources().getDimensionPixelSize(resourceId);
        }

        if (rootView != null) {
            rootView.setPadding(0, topPadding, 0, 0);
        }

        listView.setClipToPadding(false);
        listView.setPadding(0, 0, 0, navigationBarHeight);
    }

    rootDir = mApp.getSharedPreferences().getString("DEFAULT_FOLDER",
            Environment.getExternalStorageDirectory().getPath());
    currentDir = rootDir;
    mHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            slideUpListView();
        }

    }, 250);
    return rootView;
}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealTabsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_search_add_item_pager, container, false);
    // Change the status bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window w = getActivity().getWindow();
        w.setStatusBarColor(getResources().getColor(R.color.accent_dark));
    }/* w  w  w  . j  a  va  2  s .  c om*/

    Bundle extras = getActivity().getIntent().getExtras();
    if (extras != null) {
        mealType = extras.getString(Globals.MEAL_TYPE);
        page = extras.getInt("PAGE");
    }

    card_search_manual = (CardView) v.findViewById(R.id.card_search_manual);
    card_search_fav = (CardView) v.findViewById(R.id.card_search_fav);

    // Initiate Toolbar
    Toolbar mToolbar = (Toolbar) v.findViewById(R.id.toolbar_search_main);
    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(mToolbar.getWindowToken(), 0);
    mToolbar.setNavigationIcon(R.mipmap.ic_arrow_back);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_search)
                mCallbacks.searchClicked();
            if (menuItem.getItemId() == R.id.action_manual) {
                Intent i = new Intent(getActivity(), ManualEntryActivity.class);
                i.putExtra(Globals.MEAL_TYPE, mealType);
                startActivity(i);
            }
            return false;
        }
    });
    TextViewFont txtTitle = (TextViewFont) v.findViewById(R.id.txtTitle);
    if (txtTitle != null)
        txtTitle.setText(mealType);
    mToolbar.inflateMenu(R.menu.menu_search_add);

    // Hide keyboard
    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(mToolbar.getWindowToken(), 0);

    // Initiate Pager and Tabs
    ChooseAddMealPagerAdapter myPagerAdapterAdd = new ChooseAddMealPagerAdapter();
    ViewPager mViewPager = (ViewPager) v.findViewById(R.id.pager);
    TabLayout tabs = (TabLayout) v.findViewById(R.id.tabs);
    tabs.setTabTextColors(Color.parseColor("#80ffffff"), Color.parseColor("#ffffff"));
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    mViewPager.setAdapter(myPagerAdapterAdd);
    mViewPager.setOffscreenPageLimit(4);
    tabs.setupWithViewPager(mViewPager);
    mViewPager.setCurrentItem(page);
    // Initiate ListView and their adapters
    ListView mListRecentSearches = (ListView) v.findViewById(R.id.listRecentSearches);
    mListFavorites = (ListView) v.findViewById(R.id.listFavorites);
    listViewManual = (ListView) v.findViewById(R.id.listViewManual);
    llNoRecentFav = (LinearLayout) v.findViewById(R.id.llNoRecentFav);
    llNoRecentManual = (LinearLayout) v.findViewById(R.id.llNoRecentManual);
    llNoRecentSearch = (LinearLayout) v.findViewById(R.id.llNoRecentSearch);
    mRecentLogAdapter = new LogQuickSearchSimpleAdapter(getActivity(), 0, LogQuickSearch.all());
    mListRecentSearches.setAdapter(mRecentLogAdapter);
    mListRecentSearches.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LogQuickSearch recentLog = mRecentLogAdapter.getItem(position);
            mCallbacks.recentSearchClicked(recentLog.getName());
        }
    });

    mLogAdapterFavorite = new LogAdapterAll(getActivity(), 0, LogMeal.logSortByFavorite("favorite"));
    ViewGroup headerFav = (ViewGroup) inflater.inflate(R.layout.list_header_search_favorites, listViewManual,
            false);
    mListFavorites.addHeaderView(headerFav, null, false);
    mListFavorites.setAdapter(mLogAdapterFavorite);
    mListFavorites.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(searchManual.getWindowToken(), 0);
            LogMeal logMeal = mLogAdapterFavorite.getItem(position - 1);
            Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class);
            i.putExtra(Globals.MEAL_TYPE, mealType);
            i.putExtra(Globals.MEAL_ID, logMeal.getMealId());
            i.putExtra(Globals.MEAL_BRAND, logMeal.getBrand());
            i.putExtra(Globals.MEAL_FAVORITE, logMeal.getFavorite());
            startActivity(i);
        }
    });

    mLogAdapterManual = new LogAdapterManual(getActivity(), 0, LogManual.all(), mealType);
    ViewGroup header = (ViewGroup) inflater.inflate(R.layout.list_header_search, listViewManual, false);
    listViewManual.addHeaderView(header, null, false);
    listViewManual.setAdapter(mLogAdapterManual);
    listViewManual.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(searchManual.getWindowToken(), 0);
            LogManual logManual = mLogAdapterManual.getItem(position - 1);
            Intent i = new Intent(getActivity(), ManualEntrySaveMealActivity.class);
            i.putExtra(Globals.MEAL_TYPE, mealType);
            i.putExtra(Globals.MEAL_ID, logManual.getMealId());
            startActivity(i);
        }
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ((RelativeLayout.LayoutParams) card_search_manual.getLayoutParams()).setMargins(0, 0, 0, 0); // get rid of margins since shadow area is now the margin
        ((RelativeLayout.LayoutParams) card_search_fav.getLayoutParams()).setMargins(0, 0, 0, 0); // get rid of margins since shadow area is now the margin
        headerFav.setPadding(0, 0, 0, Equations.dpToPx(getActivity(), 16));
        header.setPadding(0, 0, 0, Equations.dpToPx(getActivity(), 16));
    }

    searchManualEntry();
    searchFav();

    /**
     * TODO RECIPE
     */
    Button btnRecipe = (Button) v.findViewById(R.id.btnRecipe);
    btnRecipe.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LogRecipeHolder newRecipe = new LogRecipeHolder();
            newRecipe.setDate(new Date());
            newRecipe.setMealChoice(mealType);
            newRecipe.setMealName("Recipe");
            newRecipe.save();
            Intent i = new Intent(getActivity(), RecipeActivity.class);
            i.putExtra(Globals.MEAL_ID, newRecipe.getId());
            i.putExtra(Globals.MEAL_TYPE, mealType);
            startActivity(i);
        }
    });
    logAdapterMealRecipe = new LogRecipeHolderAdapter(getActivity(), 0, LogRecipeHolder.all());
    listRecipes = (ListView) v.findViewById(R.id.listRecipes);
    listRecipes.setAdapter(logAdapterMealRecipe);
    listRecipes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LogRecipeHolder newRecipe = logAdapterMealRecipe.getItem(position);
            Intent i = new Intent(getActivity(), RecipeActivity.class);
            i.putExtra(Globals.MEAL_ID, newRecipe.getId());
            i.putExtra(Globals.MEAL_TYPE, mealType);
            startActivity(i);
        }
    });

    searchManual = (Button) v.findViewById(R.id.searchManual);
    searchManual.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            handleSearchManual();
        }
    });
    searchFavorite = (Button) v.findViewById(R.id.searchFav);
    searchFavorite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            handleSearchFavorite();
        }
    });

    updateListView();
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(searchManual.getWindowToken(), 0);
        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    return v;
}