Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

In this page you can find the example usage for android.widget TextView setPadding.

Prototype

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

Source Link

Usage

From source file:com.abcvoipsip.ui.prefs.CodecsFragment.java

@Override
@SuppressWarnings("unchecked")
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from   ww w.  ja v a  2 s  . com
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return false;
    }

    HashMap<String, Object> codec = null;
    codec = (HashMap<String, Object>) mAdapter.getItem(info.position);

    if (codec == null) {
        // If for some reason the requested item isn't available, do nothing
        return false;
    }
    int selId = item.getItemId();
    if (selId == MENU_ITEM_ACTIVATE) {
        boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
        final short newPrio = isDisabled ? (short) 1 : (short) 0;
        if (NON_FREE_CODECS.containsKey(codec.get(CODEC_ID)) && isDisabled) {
            final HashMap<String, Object> fCodec = codec;

            final TextView message = new TextView(getActivity());
            final SpannableString s = new SpannableString(
                    getString(R.string.this_codec_is_not_free) + NON_FREE_CODECS.get(codec.get(CODEC_ID)));
            Linkify.addLinks(s, Linkify.WEB_URLS);
            message.setText(s);
            message.setMovementMethod(LinkMovementMethod.getInstance());
            message.setPadding(10, 10, 10, 10);

            //Alert user that we will disable for all incoming calls as he want to quit
            new AlertDialog.Builder(getActivity()).setTitle(R.string.warning).setView(message)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            setCodecActivated(fCodec, newPrio);
                        }
                    }).setNegativeButton(R.string.cancel, null).show();
        } else {
            setCodecActivated(codec, newPrio);
        }
        return true;
    }
    return false;
}

From source file:com.tune.news.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }/*from  w w w.  j av  a 2  s .co  m*/

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setFastScrollEnabled(true);
    //        mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button);
    mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            UiUtils.displayHideReadButtonAction(mListView.getContext());
            return true;
        }
    });
    UiUtils.updateHideReadButton(mHideReadButton);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mUri != null) {
                restartLoaders();
            }
        }
    });

    mSearchView = (SearchView) rootView.findViewById(R.id.searchView);
    if (savedInstanceState != null) {
        refreshUI(); // To hide/show the search bar
    }

    mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState
        @Override
        public void run() {
            mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    setData(EntryColumns.SEARCH_URI(s), true);
                    return false;
                }
            });
        }
    });

    disableSwipe();

    return rootView;
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java

private void AddLogMessage(final String Message) {
    addMessageProgressDialog = new ProgressDialog(this);
    addMessageProgressDialog.setTitle("Contacting Zenoss");
    addMessageProgressDialog.setMessage("Please wait:\nProcessing Event Log Updates");
    addMessageProgressDialog.show();/*  w w w . j av  a  2  s. c  om*/

    addLogMessageHandler = new Handler() {
        public void handleMessage(Message msg) {
            addMessageProgressDialog.dismiss();

            if (msg.what == 1) {
                try {
                    /*String[] tmp = LogEntries.clone();
                    final int NewArrlength = tmp.length + 1;
                    LogEntries = new String[NewArrlength];
                            
                    LogEntries[0] = settings.getString("userName", "") + " wrote " + Message + "\nAt: Just now";*/

                    /*for (int i = 1; i < NewArrlength; ++i) //
                    {
                       LogEntries[i] = tmp[(i -1)];
                    }
                    tmp = null;//help out the GC
                          ((ListView) findViewById(R.id.LogList)).setAdapter(new ArrayAdapter<String>(ViewZenossEvent.this, R.layout.search_simple,LogEntries));*/

                    TextView newLog = new TextView(ViewZenossEvent.this);
                    newLog.setText(Html.fromHtml("<strong>" + settings.getString("userName", "")
                            + "</strong> wrote " + Message + "\n<br/><strong>At:</strong> Just now"));
                    newLog.setPadding(0, 6, 0, 6);
                    ((LinearLayout) findViewById(R.id.LogList)).addView(newLog);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddMessageProgressHandler", e);
                    Toast.makeText(ViewZenossEvent.this,
                            "The log message was successfully sent to Zenoss but an error occured when updating the UI",
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(ViewZenossEvent.this, "An error was encountered adding your message to the log",
                        Toast.LENGTH_LONG).show();
            }

        }
    };

    addLogMessageThread = new Thread() {
        public void run() {
            Boolean Success = false;

            try {
                if (API == null) {
                    if (settings.getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                        API = new ZenossAPIZaas();
                    } else {
                        API = new ZenossAPICore();
                    }
                    ZenossCredentials credentials = new ZenossCredentials(ViewZenossEvent.this);
                    API.Login(credentials);
                }

                Success = API.AddEventLog(getIntent().getStringExtra("EventID"), Message);
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddLogMessageThread", e);
                addLogMessageHandler.sendEmptyMessage(0);
            }

            if (Success) {
                addLogMessageHandler.sendEmptyMessage(1);
            } else {
                addLogMessageHandler.sendEmptyMessage(0);
            }
        }
    };

    addLogMessageThread.start();
}

From source file:com.google.adsensequickstart.DisplayReportFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ScrollView sv = new ScrollView(getActivity());
    TableLayout tl = new TableLayout(getActivity());
    sv.addView(tl);//from ww w  .ja v a 2s  .  c  o m

    if (displayReportController == null) {
        return sv;
    }
    AdsenseReportsGenerateResponse response = displayReportController.getReportResponse();

    TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableRowParams.setMargins(10, 10, 10, 10);

    TableRow.LayoutParams tvParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tvParams.setMargins(10, 10, 10, 10);

    List<Headers> headers = response.getHeaders();
    TableRow tr = new TableRow(getActivity());
    tl.addView(tr);

    for (Headers header : headers) {
        TextView tv = new TextView(getActivity());
        tv.setText(header.getName());
        tr.setLayoutParams(tableRowParams);
        tr.addView(tv);
    }
    if (response.getRows() != null && !response.getRows().isEmpty()) {
        for (List<String> row : response.getRows()) {
            TableRow trow = new TableRow(getActivity());
            tl.addView(trow);
            for (String cell : row) {
                TextView tv = new TextView(getActivity());
                tv.setText(cell);
                trow.addView(tv);
                tv.setLayoutParams(tvParams);
                tv.setPadding(15, 5, 15, 5);
                tv.setBackgroundColor(Color.WHITE);
            }
        }
    }
    return sv;
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }/*from w w  w.  j ava2s.  c om*/

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mCurrentUri != null) {
                restartLoaders();
            }
        }
    });

    disableSwipe();

    return rootView;
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * ??tab.//from ww  w.j a v a2 s .  c  o m
 *
 * @param tabTexts the tab texts
 * @param fragments the fragments
 */
public void addItemViews(List<String> tabTexts, List<Fragment> fragments) {

    tabItemTextList.addAll(tabTexts);
    pagerItemList.addAll(fragments);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);

}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * ??tab./*from   ww  w  .j  a  v  a2  s.  co m*/
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    AbLogUtil.d(AbSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.bangqu.eshow.view.sliding.ESSlidingSmoothFixTabView.java

/**
 * ??tab.//from w w  w . j a v  a2  s. co  m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    ESLogUtil.d(ESSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:br.org.funcate.dynamicforms.views.GPictureView.java

/**
 * @param fragmentDetail        the fragment detail  to use.
 * @param attrs                 attributes.
 * @param requestCode           the code for starting the activity with result.
 * @param parentView            parent// ww  w  .jav a2  s .c  o m
 * @param label                 label
 * @param pictures              the value are the ids and binary data of the images.
 * @param constraintDescription constraints
 */
public GPictureView(final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode,
        LinearLayout parentView, String label, Map<String, Map<String, String>> pictures,
        String constraintDescription) {
    super(fragmentDetail.getActivity(), attrs);

    thumbnailWidth = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_width);
    thumbnailHeight = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_height);

    mFragmentDetail = fragmentDetail;

    _pictures = pictures;

    PICTURE_VIEW_RESULT = requestCode;

    final FragmentActivity activity = fragmentDetail.getActivity();
    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setPadding(10, 5, 10, 5);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(activity);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    String t = label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription;
    textView.setText(t);
    textView.setTextColor(activity.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    final Button button = new Button(activity);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);
    button.setText(R.string.take_picture);
    textLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent cameraIntent = new Intent(activity, CameraActivity.class);

            cameraIntent.putExtra(FormUtilities.MAIN_APP_WORKING_DIRECTORY,
                    fragmentDetail.getWorkingDirectory());

            fragmentDetail.startActivityForResult(cameraIntent, requestCode);
        }
    });

    ScrollView scrollView = new ScrollView(activity);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setHorizontalScrollBarEnabled(true);
    scrollView.setOverScrollMode(HorizontalScrollView.OVER_SCROLL_ALWAYS);
    parentView.addView(scrollView);

    imageLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    imageLayout.setLayoutParams(imageLayoutParams);
    imageLayout.setPadding(15, 5, 15, 5);
    imageLayout.setOrientation(LinearLayout.HORIZONTAL);
    imageLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    scrollView.addView(imageLayout);

    updateValueForm();
    try {
        refresh(activity);
    } catch (Exception e) {
        //GPLog.error(this, null, e);
        e.printStackTrace();
        Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.conferenceengineer.android.iosched.ui.TracksAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (isAllTracksItem(position)) {
        if (convertView == null) {
            convertView = mActivity.getLayoutInflater().inflate(R.layout.list_item_track, parent, false);
        }//from w  w  w  .  j  a v a2s. co  m

        // Custom binding for the first item
        ((TextView) convertView.findViewById(android.R.id.text1))
                .setText("(" + mActivity.getResources().getString(R.string.all_tracks) + ")");
        convertView.findViewById(android.R.id.icon1).setVisibility(View.INVISIBLE);

        return convertView;

    } else if (isLevel2Header(position)) {
        TextView view = (TextView) convertView;
        if (view == null) {
            view = (TextView) mActivity.getLayoutInflater().inflate(R.layout.list_item_track_header, parent,
                    false);
            if (mIsDropDown) {
                Rect r = new Rect(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(),
                        view.getPaddingBottom());
                view.setBackgroundResource(R.drawable.track_header_bottom_border);
                view.setPadding(r.left, r.top, r.right, r.bottom);
            }
        }
        view.setText(R.string.other_tracks);
        return view;
    }
    return super.getView(adapterPositionToCursorPosition(position), convertView, parent);
}