Example usage for android.widget TextView setBackgroundColor

List of usage examples for android.widget TextView setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;/*from  w  w  w.jav a  2  s. com*/
    if (vi == null) {
        vi = new TextView(sourceFragment.getActivity());
    }

    TextView tv = (TextView) vi;
    final ProfileModel pm = data.get(position);
    String text = String.format("%s\n%s", pm.getName(), pm.getText());
    SpannableString spanString = new SpannableString(text);
    spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0);
    spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0);
    tv.setText(spanString);
    tv.setPadding(1, 10, 1, 10);
    tv.setBackgroundColor(Color.DKGRAY);
    tv.setTextColor(Color.WHITE);
    tv.setTextSize(10);
    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Bundle args = new Bundle();
            args.putString("link", pm.getLink());
            args.putString("title", pm.getName());
            FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false,
                    true, args);
        }
    });

    return vi;
}

From source file:com.landenlabs.all_devtool.TextFragment.java

private void fillLayout() {
    m_tableLayout.removeAllViews();//  w  ww . j a  va  2 s.c  om
    m_textInfoList.clear();

    int minSP = 8;
    int maxSP = 20;
    int stepSP = 2;

    int[] colors = new int[] { 0xffe0e0e0, 0xffffe0e0, 0xffe0ffe0, 0xffe0e0ff };

    TableLayout.LayoutParams tableLP = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.WRAP_CONTENT);
    TableRow.LayoutParams rowLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.MATCH_PARENT);

    TextView textView;
    TableRow tableRow;
    int textColor = 0xff000000;

    for (int tfIdx = 0; tfIdx < TextInfo.getCount(); tfIdx++) {
        Typeface typeface = TextInfo.getTypeface(tfIdx);
        String typefaceStr = TextInfo.getTypefaceStr(tfIdx);

        textView = new TextView(m_context);
        textView.setBackgroundColor(Utils.blend(colors[tfIdx], 0x20000000));
        textView.setText(typefaceStr);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(textColor);
        m_tableLayout.addView(textView, tableLP);

        for (int sizeSP = minSP; sizeSP <= maxSP; sizeSP += stepSP) {
            tableRow = new TableRow(m_context);
            tableRow.setBackgroundColor(colors[tfIdx]);

            tableRow.setTag(Integer.valueOf(m_textInfoList.size()));
            m_textInfoList.add(new TextInfo(sizeSP, tfIdx));

            tableRow.setClickable(true);
            tableRow.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int idx = (Integer) v.getTag();
                    showTextDialog(m_textInfoList, idx);
                }
            });

            textView = new TextView(m_context);
            textView.setText(String.valueOf(sizeSP) + "sp ");
            textView.setBackgroundColor(0x20000000);
            textView.setPadding(8, 0, 8, 0);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Normal");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.NORMAL);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Bold");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.BOLD);
            textView.setPadding(8, 0, 8, 0);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Italic");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.ITALIC);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            m_tableLayout.addView(tableRow, tableLP);
        }
    }
}

From source file:org.mindframes.latestfm.ui.views.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//www .  j a  va2s .  c  o  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(getResources().getColor(R.color.white));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, TEXT_SIZE);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setBackgroundColor(getResources().getColor(R.color.transparent));

    textView.setTextColor(getResources().getColorStateList(R.color.sliding_tab_text));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    textView.setPadding(HORIZONTAL_PADDING, 0, HORIZONTAL_PADDING, 0);
    return textView;
}

From source file:es.usc.citius.servando.calendula.activities.ScheduleCreationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_schedules);

    pColor = DB.patients().getActive(this).color();
    setupToolbar(null, pColor);//from ww w .  j ava2 s.  c  o  m
    setupStatusBar(pColor);
    subscribeToEvents();
    processIntent();

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    TextView title = ((TextView) findViewById(R.id.textView2));
    title.setBackgroundColor(pColor);
    title.setText(getString(mScheduleId != -1 ? R.string.title_edit_schedule_activity
            : R.string.title_create_schedule_activity));

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOffscreenPageLimit(3);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);

    tabs.setOnPageChangeListener(this);
    tabs.setAllCaps(true);
    tabs.setShouldExpand(true);
    tabs.setDividerPadding(3);
    tabs.setDividerColor(getResources().getColor(R.color.white_50));
    tabs.setDividerColor(getResources().getColor(R.color.transparent));
    tabs.setIndicatorHeight(ScreenUtils.dpToPx(getResources(), 4));
    tabs.setIndicatorColor(ScreenUtils.equivalentNoAlpha(pColor, 0.8f));
    tabs.setTextColor(Color.parseColor("#222222"));
    tabs.setUnderlineColor(ScreenUtils.equivalentNoAlpha(pColor, 0.5f));
    tabs.setViewPager(mViewPager);

    if (mSchedule != null) {
        mViewPager.setCurrentItem(1);
    }

    findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveSchedule();
        }
    });

}

From source file:fr.cph.chicago.core.activity.StationActivity.java

@SuppressWarnings("unchecked")
private void setUpStopLayouts(@NonNull final Map<TrainLine, List<Stop>> stopByLines) {
    Stream.of(stopByLines.entrySet()).forEach(entry -> {
        final TrainLine line = entry.getKey();
        final List<Stop> stops = entry.getValue();
        final View lineTitleView = getLayoutInflater().inflate(R.layout.activity_station_line_title, viewGroup,
                false);//from  w ww.j a va2 s  . c  om

        final TextView testView = (TextView) lineTitleView.findViewById(R.id.train_line_title);
        testView.setText(line.toStringWithLine());
        testView.setBackgroundColor(line.getColor());
        if (line == TrainLine.YELLOW) {
            testView.setBackgroundColor(yellowLine);
        }

        stopsView.addView(lineTitleView);

        Stream.of(stops).sorted().forEach(stop -> {
            final LinearLayout linearLayout = new LinearLayout(this);
            linearLayout.setOrientation(LinearLayout.HORIZONTAL);
            linearLayout.setLayoutParams(paramsStop);

            final AppCompatCheckBox checkBox = new AppCompatCheckBox(this);
            checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> Preferences
                    .saveTrainFilter(getApplicationContext(), stationId, line, stop.getDirection(), isChecked));
            checkBox.setOnClickListener(v -> {
                if (checkBox.isChecked()) {
                    trainArrivalObservable.subscribe(new SubscriberTrainArrival(this, swipeRefreshLayout));
                }
            });
            checkBox.setChecked(
                    Preferences.getTrainFilter(getApplicationContext(), stationId, line, stop.getDirection()));
            checkBox.setTypeface(checkBox.getTypeface(), Typeface.BOLD);
            checkBox.setText(stop.getDirection().toString());
            checkBox.setTextColor(grey);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                checkBox.setBackgroundTintList(ColorStateList.valueOf(line.getColor()));
                checkBox.setButtonTintList(ColorStateList.valueOf(line.getColor()));
                if (line == TrainLine.YELLOW) {
                    checkBox.setBackgroundTintList(ColorStateList.valueOf(yellowLine));
                    checkBox.setButtonTintList(ColorStateList.valueOf(yellowLine));
                }
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                checkBox.setForegroundTintList(ColorStateList.valueOf(line.getColor()));
                if (line == TrainLine.YELLOW) {
                    checkBox.setForegroundTintList(ColorStateList.valueOf(yellowLine));
                }
            }

            linearLayout.addView(checkBox);

            final LinearLayout arrivalTrainsLayout = new LinearLayout(this);
            arrivalTrainsLayout.setOrientation(LinearLayout.VERTICAL);
            arrivalTrainsLayout.setLayoutParams(paramsStop);
            int id = Util.generateViewId();
            arrivalTrainsLayout.setId(id);
            ids.put(line.toString() + "_" + stop.getDirection().toString(), id);

            linearLayout.addView(arrivalTrainsLayout);
            stopsView.addView(linearLayout);
        });
    });
}

From source file:com.timothy.android.api.fragment.PageFragmentNew.java

public void setAllComponent(List<HtmlCleanAPI.HtmlContent> hcList) {
    Log.i(LOG_TAG, "setAllComponent()...");
    for (HtmlCleanAPI.HtmlContent hc : hcList) {
        String tag = hc.getTag();
        String content = hc.getContent();
        if (StringUtil.isEmpty(content))
            continue;

        String contentMBlank = StringUtil.mergeBlank(content);
        if (StringUtil.isEmpty(contentMBlank))
            continue;

        String contentRBlank = StringUtil.rmvEnter(StringUtil.trim(contentMBlank));
        if (StringUtil.isEmpty(contentRBlank))
            continue;

        String contentRSpecial = StringUtil.rmvSpecial(contentRBlank);
        if (StringUtil.isEmpty(contentRSpecial))
            continue;

        Log.i(LOG_TAG, "tag:" + tag);
        Log.i(LOG_TAG, "content:" + contentRSpecial);

        if (tag.equalsIgnoreCase("P")) {
            final TextView tagPTV = new TextView(mContext);
            tagPTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 3, 2, 3);/*from ww  w  . ja va  2s  .  c o m*/
            tagPTV.setLayoutParams(lp);
            tagPTV.setPadding(3, 3, 3, 3);
            tagPTV.setPaddingRelative(3, 3, 3, 3);
            tagPTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPTV.setTextColor(Color.BLACK);
            tagPTV.setText(contentRSpecial);
            tagPTV.setTextSize(TEXT_SIZE);
            tagPTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPTV);

        } else if (tag.equalsIgnoreCase("pre")) {
            final TextView tagPre = new TextView(mContext);
            tagPre.setBackgroundColor(Color.parseColor("#D2EADE"));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagPre.setLayoutParams(lp);
            tagPre.setPadding(2, 2, 2, 2);
            tagPre.setPaddingRelative(2, 2, 2, 2);
            tagPre.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPre.setTextColor(Color.BLACK);
            //            String contentRSpecial = StringUtil.rmvSpecial(content);
            tagPre.setText(StringUtil.rmvSpecial(content));
            tagPre.setTextSize(TEXT_SIZE);
            tagPre.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPre.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPre);
        } else if (tag.equalsIgnoreCase("dt") || tag.equalsIgnoreCase("H1") || tag.equalsIgnoreCase("H2")
                || tag.equalsIgnoreCase("H3")) {//title
            TextView tagDtHTV = new TextView(mContext);
            tagDtHTV.setBackgroundColor(Color.DKGRAY);
            tagDtHTV.setTypeface(null, Typeface.BOLD);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 0, 2, 0);
            tagDtHTV.setLayoutParams(lp);
            tagDtHTV.setPadding(2, 2, 2, 2);
            tagDtHTV.setPaddingRelative(2, 2, 2, 2);
            tagDtHTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDtHTV.setTextColor(Color.WHITE);
            tagDtHTV.setText(contentRSpecial);
            tagDtHTV.setTextSize(TEXT_SIZE);
            lineLayout.addView(tagDtHTV);
        } else if (tag.equalsIgnoreCase("dd")) {
            final TextView tagDD = new TextView(mContext);
            tagDD.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagDD.setLayoutParams(lp);
            tagDD.setPadding(3, 3, 3, 3);
            tagDD.setPaddingRelative(3, 3, 3, 3);
            tagDD.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDD.setTextColor(Color.BLACK);
            tagDD.setText(contentRSpecial);
            tagDD.setTextSize(TEXT_SIZE);
            tagDD.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagDD.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagDD);
        } else if (tag.equalsIgnoreCase("li")) {
            final TextView tagLigTV = new TextView(mContext);
            tagLigTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagLigTV.setLayoutParams(lp);
            tagLigTV.setPaddingRelative(2, 2, 2, 2);
            tagLigTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagLigTV.setTextColor(Color.BLACK);
            tagLigTV.setText(contentRSpecial);
            tagLigTV.setTextSize(TEXT_SIZE);
            tagLigTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagLigTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagLigTV);
        } else if (tag.equalsIgnoreCase("img")) {
            final TextView imgTV = new TextView(mContext);
            imgTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            imgTV.setLayoutParams(lp);
            imgTV.setPaddingRelative(2, 2, 2, 2);
            imgTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            imgTV.setTextColor(Color.BLACK);
            imgTV.setText(content);
            imgTV.setTextSize(TEXT_SIZE);
            lineLayout.addView(imgTV);

            ImageView imageView = new ImageView(mContext);
            LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            imageView.setLayoutParams(imgLP);
            Bitmap localBt = getLoacalBitmap(baseFolder + File.separator + content);
            imageView.setImageBitmap(localBt);
            lineLayout.addView(imageView);
        }
    }
}

From source file:org.cvasilak.jboss.mobile.app.fragments.RuntimeViewFragment.java

private void buildTable() {
    Map<String, List<String>> table = new HashMap<String, List<String>>();

    table.put("Server Status", Arrays.asList("Configuration", "JVM"));

    List<String> metrics = new ArrayList<String>(
            Arrays.asList("Data Sources", "JMS Destinations", "Transactions"));
    // 'Web' section metrics is compatible (for now) only with MANAGEMENT_VERSION_1
    // TODO ('Undertow' subsystem metrics can possible replace)
    if (application.getOperationsManager()
            .getVersion() == JBossOperationsManager.ManagementVersion.MANAGEMENT_VERSION_1) {
        metrics.add("Web");
    }/*from   ww  w.j ava2 s .c om*/

    table.put("Subsystem Metrics", metrics);

    if (application.getOperationsManager().isDomainController()) {
        table.put("Deployments", Arrays.asList("Deployment Content", "Server Groups"));
    } else {
        table.put("Deployments", Arrays.asList("Manage Deployments"));
    }

    MergeAdapter adapter = new MergeAdapter();

    // cater for domain mode and display a button
    // for the user to change the active server
    if (application.getOperationsManager().isDomainController()) {
        chooseServer = new Button(getActivity());
        chooseServer.setText(application.getOperationsManager().getDomainHost() + ":"
                + application.getOperationsManager().getDomainServer());
        chooseServer.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_servers_selection, 0);
        chooseServer.setTypeface(null, Typeface.ITALIC);
        chooseServer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDomainHostChooser();
            }
        });

        adapter.addView(chooseServer);
    }

    for (Map.Entry<String, List<String>> entry : table.entrySet()) {
        // add section header
        TextView section = new TextView(getActivity());
        section.setBackgroundColor(Color.DKGRAY);
        section.setPadding(15, 10, 0, 10);
        section.setText(entry.getKey());
        adapter.addView(section);

        // add section data
        adapter.addAdapter(
                new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, entry.getValue()));
    }

    setListAdapter(adapter);
}

From source file:com.g_node.gca.abstracts.AbstractCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    /*//  w w  w . ja  v  a2s  . c  o  m
     * TextView for showing Title
     */
    TextView title = (TextView) view.findViewById(R.id.abTitle);
    title.setText(cursor.getString(cursor.getColumnIndexOrThrow("TITLE")));
    /*
     * TextView for showing Topic
     */
    TextView topic = (TextView) view.findViewById(R.id.abTopic);
    topic.setText(cursor.getString(cursor.getColumnIndexOrThrow("TOPIC")));
    /*
     * TextView for Showing Type
     */
    TextView type = (TextView) view.findViewById(R.id.abType);
    int absSortID = cursor.getInt(cursor.getColumnIndexOrThrow("SORTID"));

    if (absSortID != 0) {
        int groupid = ((absSortID & (0xFFFF << 16)) >> 16);

        switch (groupid) {
        case 0:
            type.setText("Invited Talk");
            type.setBackgroundColor(Color.parseColor("#33B5E5"));
            break;

        case 1:
            type.setText("Contributed Talk");
            type.setBackgroundColor(Color.parseColor("#ef4172"));
            break;

        case 2:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;

        case 3:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;
        default:
            break;
        }

        //absSortID.append("Group ID: " + get_groupid_str(groupid));

    } else {
        //type.setVisibility(View.GONE);
        type.setTextSize(TypedValue.COMPLEX_UNIT_SP, 4);
        type.setVisibility(View.INVISIBLE);
    }

    /*
    Following piece of commented code isn't needed as Abstract Type is 
    selected now based on GroupID. Previously it was being selected based on 'isTalk' field
    but now it's selected on basis of GroupID extracted from SortID. 
            
    String typeText = cursor.getString(cursor.getColumnIndexOrThrow("TYPE"));
    type.setText(typeText.toUpperCase());
            
    if(typeText.compareToIgnoreCase("poster") == 0) {
       type.setBackgroundColor(Color.parseColor("#AA66CC"));
    } else {
       type.setBackgroundColor(Color.parseColor("#33B5E5"));
    }
    */

    /*
     * _id for getting Author Names
     */
    String value = cursor.getString(cursor.getColumnIndexOrThrow("_id"));

    String authorNamesQuery = "SELECT ABSTRACT_UUID, AUTHORS_DETAILS.AUTHOR_UUID, AUTHORS_DETAILS.AUTHOR_FIRST_NAME, AUTHOR_MIDDLE_NAME, AUTHOR_LAST_NAME, AUTHOR_EMAIL, ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_POSITION as _aPos FROM ABSTRACT_AUTHOR_POSITION_AFFILIATION LEFT OUTER JOIN AUTHORS_DETAILS USING (AUTHOR_UUID) WHERE ABSTRACT_UUID = '"
            + value + "' ORDER BY _aPos;";
    cursorOne = DatabaseHelper.database.rawQuery(authorNamesQuery, null);

    if (cursorOne != null) {
        cursorOne.moveToFirst();
        /*
         * Name format will be like this A, B & C or A,B,C & D. So, if the
         * name is the last name. We should use '&' before the name
         */
        do {

            if (cursorOne.getPosition() == 0) {
                /*
                 * First data
                 */
                getName = cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else if (cursorOne.isLast()) {
                /*
                 * Last Data
                 */
                getName = getName + " & "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else {
                getName = getName + " , "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));

            }

        } while (cursorOne.moveToNext());
    }

    /*
     * TextView for Author Names
     */
    TextView authorNames = (TextView) view.findViewById(R.id.absAuthorNames);
    /*
     * Get Width
     */
    WindowManager WinMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    @SuppressWarnings("deprecation")
    int displayWidth = WinMgr.getDefaultDisplay().getWidth();
    Paint paint = new Paint();
    Rect bounds = new Rect();
    int text_width = 0;
    paint.getTextBounds(getName, 0, getName.length(), bounds);
    /*
     * Getting Text Width
     */
    text_width = bounds.width();
    /*
     * If Text Width is greater than Display Width Then show First Name et
     * al.
     */
    if (text_width > displayWidth) {
        String output = getName.split(",")[0] + " et al. ";
        authorNames.setText(output);

    } else {
        /*
         * Name Format will be like this If the Name is Yasir Adnan So,It
         * will be Y.Adnan
         */
        authorNames.setText(getName.replaceAll("((?:^|[^A-Z.])[A-Z])[a-z]*\\s(?=[A-Z])", "$1."));
    }
}

From source file:com.pixellostudio.qqdroid.BaseQuote.java

/** Called when the activity is first created. */
@Override//from   w  w  w.  java 2  s. c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setActionBarContentView(R.layout.show);

    getActionBar().setTitle(title);

    getActionBar().addItem(getActionBar().newActionBarItem(NormalActionBarItem.class)
            .setDrawable(R.drawable.seemore).setContentDescription("List"), R.id.actionbar_seemore);

    view = (ListView) findViewById(R.id.ListView);

    view.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            menu.add(0, 1, 0, R.string.sharequote);
        }
    });

    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1);
    adapter2 = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(BaseQuote.this);

            TextView txt = new TextView(this.getContext());
            txt.setTextSize(Float.parseFloat(pref.getString("policesize", "20")));
            txt.setText(Html.fromHtml(this.getItem(position)));

            if (pref.getString("design", "blackonwhite").equals("blackonwhite")) {
                txt.setTextColor(Color.BLACK);
                txt.setBackgroundColor(Color.WHITE);
                txt.setBackgroundDrawable(
                        this.getContext().getResources().getDrawable(R.drawable.quote_gradient_white));
            } else if (pref.getString("design", "blackonwhite").equals("whiteonblack")) {
                txt.setTextColor(Color.WHITE);
                txt.setBackgroundColor(Color.BLACK);
                txt.setBackgroundDrawable(
                        this.getContext().getResources().getDrawable(R.drawable.quote_gradient_black));
            }

            return txt;
        }

    };

    String[] liste = (String[]) getLastNonConfigurationInstance();

    if (liste != null && liste.length != 0) {
        for (int i = 0; i < liste.length; i++) {
            adapter.add(liste[i]);
            adapter2.add(liste[i]);
        }

        this.setTitle(name);
    } else {
        new LoadQuotes().execute();
    }

    view.setAdapter(adapter2);
}

From source file:com.gh4a.IssueLabelListActivity.java

private void unselectLabel(TextView tvLabel, View viewColor, String color) {
    final Typeface condensed = getApplicationContext().condensed;
    tvLabel.setTag(color);//from   w w  w .j a  va  2s  .  c om
    tvLabel.setBackgroundColor(0);
    if (Gh4Application.THEME == R.style.LightTheme) {
        tvLabel.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_light));
    } else {
        tvLabel.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_dark));
    }
    tvLabel.setTypeface(condensed);
    viewColor.setBackgroundColor(Color.parseColor("#" + color));
}