Example usage for android.widget TextView setTextAppearance

List of usage examples for android.widget TextView setTextAppearance

Introduction

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

Prototype

@Deprecated
public void setTextAppearance(Context context, @StyleRes int resId) 

Source Link

Document

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

Usage

From source file:info.semanticsoftware.semassist.android.activity.SemanticResultsActivity.java

/** Presents the results in a list format.
 * @param savedInstanceState saved instance state
 *//*from   w ww  .  j  a v  a2 s  .  c  o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String resultsXML = getIntent().getStringExtra("xml");
    Vector<SemanticServiceResult> results = ClientUtils.getServiceResults(resultsXML);
    setContentView(R.layout.results);

    TableLayout tblResults = (TableLayout) findViewById(R.id.tblResultsLayout);
    tblResults.setStretchAllColumns(true);

    TableRow resultRow;
    TextView txtContent;
    TextView txtType;
    TextView txtStart;
    TextView txtEnd;
    TextView txtFeats;

    if (results == null) {
        // handle server errors
    } else {
        for (SemanticServiceResult current : results) {
            if (current.mResultType.equals(SemanticServiceResult.ANNOTATION)) {

                List<AnnotationInstance> annots = ServerResponseHandler.createAnnotation(current);
                for (int i = 0; i < annots.size(); i++) {
                    resultRow = new TableRow(getApplicationContext());

                    txtContent = new TextView(getApplicationContext());
                    txtContent.setText(annots.get(i).getContent());
                    txtContent.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtContent);

                    txtType = new TextView(getApplicationContext());
                    txtType.setText(annots.get(i).getType());
                    txtType.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtType);

                    txtStart = new TextView(getApplicationContext());
                    txtStart.setText(annots.get(i).getStart());
                    txtStart.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtStart);

                    txtEnd = new TextView(getApplicationContext());
                    txtEnd.setText(annots.get(i).getEnd());
                    txtEnd.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtEnd);

                    txtFeats = new TextView(getApplicationContext());
                    txtFeats.setText(annots.get(i).getFeatures());
                    txtFeats.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtFeats);

                    tblResults.addView(resultRow);
                }
            } else if (current.mResultType.equals(SemanticServiceResult.BOUNDLESS_ANNOTATION)) {
                //TODO find an actual pipeline to test this with
            } else if (current.mResultType.equals(SemanticServiceResult.FILE)) {
                fileName = current.mFileUrl;
                fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
                Log.d(Constants.TAG, fileName);
                getFileContentTask task = new getFileContentTask();
                task.execute(SemanticAssistantsActivity.serverURL);
            }
        }

        // reduce the number of allowed requests by one
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String strReqNum = settings.getString("reqNum", "0");
        try {
            int intReqNum = Integer.parseInt(strReqNum);
            Editor editor = settings.edit();
            intReqNum--;
            editor.putString("reqNum", Integer.toString(intReqNum));
            boolean result = editor.commit();
            if (result) {
                Log.d(Constants.TAG, "Successfully reduced the reqNum");
            } else {
                Log.d(Constants.TAG, "Cannot reduced the reqNum");
            }
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    } //else

}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void showOfflinePNRStatus(String trainDetails, ArrayList<String> passnDetails) {
    LinearLayout ll = new LinearLayout(mActivity);

    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);
    TextView tvTrainDetails = new TextView(mActivity);
    TextView[] tvPassnDetails = new TextView[passnDetails.size()];

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);/*w w  w.j  av a  2s  . c  o  m*/
    textViewPsnDtls.setText("Passenger Details");
    tvTrainDetails.setText(trainDetails);
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    tvTrainDetails.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    tvTrainDetails.setPadding(10, 10, 10, 10);

    tvTrainDetails.setBackgroundResource(R.drawable.card_background);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);

    ll.addView(tvTrainDetails);
    ll.addView(textViewPsnDtls);
    for (int i = 0; i < passnDetails.size(); ++i) {
        tvPassnDetails[i] = new TextView(mActivity);
        tvPassnDetails[i].setText(passnDetails.get(i));
        tvPassnDetails[i].setPadding(10, 10, 10, 10);
        tvPassnDetails[i].setBackgroundResource(R.drawable.card_background);
        tvPassnDetails[i].setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        ll.addView(tvPassnDetails[i]);
    }
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
}

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

private LinearLayout getCenteredRowText(Context context, String text, float layoutWeightSum, boolean largeText,
        float textViewWeight) {
    final LinearLayout inner = new LinearLayout(context);
    final TableRow.LayoutParams innerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, 1f);
    innerParams.span = itemsPerInnerRow;
    inner.setLayoutParams(innerParams);/*from  www  .  j  ava 2  s  .  com*/
    inner.setWeightSum(layoutWeightSum);
    inner.setBackgroundResource(R.drawable.cell_shape);
    final TextView nameTextView = new TextView(context);
    nameTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, textViewWeight));
    nameTextView.setTextAppearance(context,
            largeText ? android.R.style.TextAppearance_Large : android.R.style.TextAppearance_Medium);
    nameTextView.setText(text);
    nameTextView.setGravity(Gravity.CENTER);
    inner.addView(nameTextView);
    return inner;
}

From source file:com.andreadec.musicplayer.MainActivity.java

private void showItemInfo(PlayableItem item) {
    if (item == null || item.getInformation() == null)
        return;/* w  w  w . j  av a2  s.c  o m*/
    ArrayList<Information> information = item.getInformation();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.songInfo);
    View view = getLayoutInflater().inflate(R.layout.layout_songinfo, null, false);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutInformation);

    Bitmap image = item.getImage();
    if (image != null) {
        ImageView imageView = new ImageView(this);
        imageView.setImageBitmap(image);
        linearLayout.addView(imageView);
    }

    for (Information info : information) {
        TextView info1 = new TextView(this);
        info1.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        info1.setText(getResources().getString(info.key));
        TextView info2 = new TextView(this);
        info2.setText(info.value);
        info2.setPadding(0, 0, 0, 10);
        linearLayout.addView(info1);
        linearLayout.addView(info2);
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.ok, null);
    builder.show();
}

From source file:hu.fnf.devel.atlas.Atlas.java

private void addChilds(View parent, LinearLayout pll) {
    Uri.Builder builder = new Builder();
    builder.scheme("content");
    builder.authority(AtlasData.DB_AUTHORITY);
    builder.appendPath(AtlasData.TABLE_CATEGORIES);
    builder.appendPath("childs");
    builder.appendPath(String.valueOf(parent.getId()));

    Cursor items = getContentResolver().query(builder.build(), AtlasData.CATEGORIES_COLUMNS, null, null, null);

    if (items != null && items.moveToFirst()) {
        LinearLayout ll = null;/*from  www  .j  a v  a 2 s  . c o m*/
        do {
            ll = new LinearLayout(getApplicationContext());
            LayoutParams llp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            ll.setLayoutParams(llp);
            TextView child = new TextView(getApplicationContext());
            child.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_Medium_Inverse);

            ll.setId(items.getInt(AtlasData.CATEGORIES_ID));
            child.setId(items.getInt(AtlasData.CATEGORIES_ID));
            child.setText(items.getString(AtlasData.CATEGORIES_NAME));
            for (int i = 0; i < AtlasData.MAX_CAT_DEPTH - items.getInt(AtlasData.CATEGORIES_DEPTH); i++) {
                TextView holder = new TextView(getApplicationContext());
                holder.setText("        ");
                ll.addView(holder);
            }

            child.setClickable(true);

            Log.d("Atlas", "build to ll: " + child.getText().toString());
            ll.addView(child);

            ll.setOnClickListener(onCatClick);
            child.setOnClickListener(onCatClick);

            View line = new View(getApplicationContext());

            line.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
            line.setBackgroundColor(Color.GRAY);

            pll.addView(line);
            pll.addView(ll);
            Log.d("Atlas", "build to pll: " + ll.getId());

            addChilds(child, pll);
        } while (items.moveToNext());
        items.close();
    } else {
        // no more kids
        return;
    }
}

From source file:com.yooiistudios.newskit.ui.widget.viewpager.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)}./* w  w  w.  j  av  a  2 s  .c  o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    //  ? 48dp 
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            getResources().getDimensionPixelSize(R.dimen.news_select_sliding_tab_height)));
    textView.setGravity(Gravity.CENTER);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    // TextAppearance_Body2 -> sans-serif-medium, 14sp
    // ? ? ?? 
    textView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Body2);
    textView.setTextColor(getResources().getColor(R.color.news_select_disabled_text_color)); // black with opacity 54%

    if (Display.isTablet(getContext())) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.text_size_subhead_material));
    } else {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.text_size_body_2_material));
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);

    if (Display.isTablet(getContext())) {
        padding *= 1.5;
    }
    textView.setPadding(padding, 0, padding, 0);

    return textView;
}

From source file:liqui.droid.activity.Base.java

/**
 * Creates the breadcrumb.// w  ww  .ja  va2 s. com
 *
 * @param subTitle the sub title
 * @param breadCrumbHolders the bread crumb holders
 */
public void createBreadcrumb(String subTitle, BreadCrumbHolder... breadCrumbHolders) {
    if (breadCrumbHolders != null) {
        LinearLayout llPart = (LinearLayout) this.findViewById(R.id.ll_part);
        for (int i = 0; i < breadCrumbHolders.length; i++) {
            TextView tvBreadCrumb = new TextView(getApplication());
            SpannableString part = new SpannableString(breadCrumbHolders[i].getLabel());
            part.setSpan(new UnderlineSpan(), 0, part.length(), 0);
            tvBreadCrumb.append(part);
            tvBreadCrumb.setTag(breadCrumbHolders[i]);
            tvBreadCrumb.setBackgroundResource(R.drawable.default_link);
            tvBreadCrumb.setTextAppearance(getApplication(), R.style.default_text_small);
            tvBreadCrumb.setSingleLine(true);
            tvBreadCrumb.setOnClickListener(new OnClickBreadCrumb(this));

            llPart.addView(tvBreadCrumb);

            if (i < breadCrumbHolders.length - 1) {
                TextView slash = new TextView(getApplication());
                slash.setText(" / ");
                slash.setTextAppearance(getApplication(), R.style.default_text_small);
                llPart.addView(slash);
            }
        }
    }

    ScrollingTextView tvSubtitle = (ScrollingTextView) this.findViewById(R.id.tv_subtitle);
    tvSubtitle.setText(subTitle);
}

From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java

protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed) {
    if (view != null && dueDate != null) {
        Time now = mNow;/* ww w.  ja  v  a  2  s.  c  om*/
        if (now == null) {
            now = mNow = new Time();
        }
        if (!now.timezone.equals(TimeZone.getDefault().getID())) {
            now.clear(TimeZone.getDefault().getID());
        }

        if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000) {
            now.setToNow();
            now.normalize(true);
        }

        dueDate.normalize(true);

        view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW));
        if (dueIcon != null) {
            dueIcon.setVisibility(View.VISIBLE);
        }

        // highlight overdue dates & times, handle allDay tasks separately
        if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay
                && (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year))
                && !isClosed) {
            view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text);
        } else {
            view.setTextAppearance(view.getContext(), R.style.task_list_due_text);
        }
    } else if (view != null) {
        view.setText("");
        if (dueIcon != null) {
            dueIcon.setVisibility(View.GONE);
        }
    }
}

From source file:com.simplealertdialog.SimpleAlertDialog.java

public void setItems(final CharSequence[] items, final AdapterView.OnItemClickListener listener) {
    mAdapter = new ArrayAdapter<CharSequence>(getContext(), android.R.layout.simple_list_item_1, items) {
        @Override/*from w w  w .  j ava 2s  . c om*/
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            if (view != null) {
                TextView tv = (TextView) view.findViewById(android.R.id.text1);
                if (mListItemTextStyle != 0) {
                    tv.setTextAppearance(getContext(), mListItemTextStyle);
                }
                tv.setText(items[position]);
            }
            return view;
        }
    };
    mListItemListener = listener;
}

From source file:com.simplealertdialog.SimpleAlertDialog.java

public void setItems(final CharSequence[] items, final int[] iconResIds,
        final AdapterView.OnItemClickListener listener) {
    if (iconResIds == null || items == null) {
        return;/*from   ww w  .j  a  v  a  2  s.  c o m*/
    }
    final IconListItem[] iconListItems = new IconListItem[Math.min(iconResIds.length, items.length)];
    for (int i = 0; i < iconResIds.length && i < items.length; i++) {
        iconListItems[i] = new IconListItem(iconResIds[i], items[i]);
    }
    mAdapter = new ArrayAdapter<IconListItem>(getContext(), android.R.layout.simple_list_item_1,
            iconListItems) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            if (view != null) {
                TextView tv = (TextView) view.findViewById(android.R.id.text1);
                if (mListItemTextStyle != 0) {
                    tv.setTextAppearance(getContext(), mListItemTextStyle);
                }
                tv.setText(iconListItems[position].text);
                tv.setCompoundDrawablesWithIntrinsicBounds(iconListItems[position].iconResId, 0, 0, 0);
                int padding = (int) (8 * getContext().getResources().getDisplayMetrics().density);
                tv.setCompoundDrawablePadding(padding);
            }
            return view;
        }
    };
    mListItemListener = listener;
}