Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:com.aashir.gmote.player.widget.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)}.//from  ww  w.j  a  v a 2  s .c o m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

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

    return textView;
}

From source file:com.android.messaging.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//  w  w  w  .  jav  a 2s.  c  om
    textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

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//  w ww  .  j a v a2  s.  c om
 * @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:mobisocial.musubi.objects.PictureObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    ImageView imageView = new ImageView(context);
    imageView.setBackgroundResource(android.R.drawable.picture_frame);
    imageView.setPadding(6, 4, 8, 9);//from w w w  .j av  a  2  s  .  c om
    frame.addView(imageView);

    TextView textView = new TextView(context);
    frame.addView(textView);

    return frame;
}

From source file:com.travelguide.GuideActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    final String TAG = "Activity2";

    String ln = getIntent().getExtras().getString("tag");
    if ((ln.equals("Espaol")) || (ln.equals("Spanish"))) {
        TextView t1 = (TextView) findViewById(R.id.thanks);
        t1.setText("Gracias por usar mi aplicacin.");

        TextView t2 = (TextView) findViewById(R.id.link);
        t2.setText("Las ubicaciones de visitantes en el interior "
                + getIntent().getExtras().getString("com.travelguide.radius") + " millas para "
                + getIntent().getExtras().getString("com.travelguide.location"));

    } else {//from  w ww.  j av  a  2  s .c om
        TextView t1 = (TextView) findViewById(R.id.thanks);
        t1.setText("Thanks for using my App.");

        TextView t2 = (TextView) findViewById(R.id.link);
        t2.setText(
                "Visitor locations found within " + getIntent().getExtras().getString("com.travelguide.radius")
                        + " miles for " + getIntent().getExtras().getString("com.travelguide.location"));

    }

    String url = getIntent().getExtras().getString("com.travelguide.link");
    Log.i(TAG, url);

    try {
        //***** Parsing the xml file*****
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        tgparse myXML_parser = new tgparse();
        xr.setContentHandler(myXML_parser);

        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url.replace(" ", "%20"));
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpget, responseHandler);
        Log.i(TAG, "responseBody: " + responseBody);
        ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());
        xr.parse(new InputSource(is));

        Log.i(TAG, "parse complete");

        TextView placename[];
        TextView placeaddress[];
        TextView placerating[];

        tgxml data;
        data = tgparse.getXMLData();
        placename = new TextView[data.getName().size()];
        placeaddress = new TextView[data.getName().size()];
        placerating = new TextView[data.getName().size()];

        webview = (WebView) findViewById(R.id.myWebView);

        //    webview.setBackgroundColor(0);
        //    webview.setBackgroundResource(R.drawable.openbook);

        String stg1 = new String();
        stg1 = "<html>";
        for (int i = 1; i < (data.getName().size()); i++) {
            Log.i(TAG, " " + i);
            Log.i(TAG, "Name= " + data.getName().get(i));
            Log.i(TAG, "Address= " + data.getAddress().get(i));
            Log.i(TAG, "Rating= " + data.getRating().get(i));

            placename[i] = new TextView(this);
            placename[i].setText("Name= " + data.getName().get(i));

            placeaddress[i] = new TextView(this);
            placeaddress[i].setText("Address= " + data.getAddress().get(i));

            placerating[i] = new TextView(this);
            placerating[i].setText("Rating= " + data.getRating().get(i));

            if ((ln.equals("Espaol")) || (ln.equals("Spanish"))) {
                stg1 = stg1 + "Nombre: " + data.getName().get(i) + "<br>" + " Direccin: "
                        + data.getAddress().get(i) + "<br>" + " clasificacin= " + data.getRating().get(i)
                        + "<br>" + "<br>";
            } else {
                stg1 = stg1 + "Name: " + data.getName().get(i) + "<br>" + " Address: "
                        + data.getAddress().get(i) + "<br>" + " Rating= " + data.getRating().get(i) + "<br>"
                        + "<br>";
            }

        }
        stg1 = stg1 + "</html>";
        webview.loadDataWithBaseURL(null, stg1, "text/html", "utf-8", "about:blank");

    } catch (Exception e) {
        Log.i(TAG, "Exception caught", e);

    }

}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_pnr_status);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("PNR Status");
    mUtil = Util.getUtil(this);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    pnrDB = PNRDatabase.getPNRDatabase(this);
    mPNRList = new ArrayList<String>();
    mPNRList = pnrDB.getPNRs();/*from   w ww . ja v  a  2s. c  om*/
    mACTPNR = (AutoCompleteTextView) findViewById(R.id.id_act_pnr_sts);
    mACTPNR.setAdapter(new ArrayAdapter<String>(this, R.layout.layout_dropdown_list, mPNRList));
    mPref = PreferenceManager.getDefaultSharedPreferences(this);
    isWaitingList = false;

    if (savedInstanceState != null) {
        if (!mPNRNumber.equals("")) {
            if (!mUtil.isConnected()) {
                mFrameLayout = null;
                mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
                readAndShowOfflinePNRStatus();
                return;
            }
            mFrameLayout = null;
            mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);

            mPassengerDetails = savedInstanceState.getParcelable("PSN");
            mTrainDetails = savedInstanceState.getParcelable("TRAIN");
            mPageResult = savedInstanceState.getString("PAGE");
            if (mPageResult == null) {
                return;
            }

            mTextViewPNRSts = null;
            mTextViewPNRSts = new TextView(mActivity);
            mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
            mTextViewPNRSts.setTextColor(Color.RED);

            createTableLayoutTrnDtls();
            createTableLayoutPsnDtls();
            try {
                combineTrainAndPsnDetails();
            } catch (Exception e) {
                Log.e("PNRStat Error:", "Error creating table layout. Please try again later!");
            }
            return;
        }
    }

    mActivity = this;
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    mTextViewPNRSts = new TextView(mActivity);
    mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
    mTextViewPNRSts.setTextColor(Color.RED);
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule./* w  ww  .  ja v  a  2  s .com*/
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TITLE ROW// ww  w  .  j av a  2s  .c  o m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);
    container_layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText("");
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value2"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t2, ltext2);

    linear.addView(container_layout);
    return linear;
}

From source file:com.ciandt.thegarage.navapp.view.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 ww .j  a va 2s  . c o m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);

    //TypefaceUtil.loadCustomFonts(context, Constants.Font.MUSEO_REGULAR500, textView);

    textView.setTextColor(context.getResources().getColor(android.R.color.white));

    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);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding + 20, padding, padding + 20, padding);

    return textView;
}

From source file:edu.rowan.app.carousel.CarouselFeature.java

private void setupView() {
    imageView.setId(1);//  ww w. j a  va 2 s  .c  o  m
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    imageView.setLayoutParams(imageParams);
    //      imageView.setAdjustViewBounds(true);
    Resources r = context.getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

    TextView descriptionView = new TextView(context);
    descriptionView.setId(2);
    descriptionView.setPadding(padding, 0, padding, padding);
    descriptionView.setText(description);
    descriptionView.setBackgroundColor(Color.argb(220, 63, 26, 10));
    descriptionView.setTextColor(Color.WHITE);
    RelativeLayout.LayoutParams descParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    descParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageView.getId());
    carouselView.addView(descriptionView, descParams);

    TextView titleView = new TextView(context);
    titleView.setText(title);
    titleView.setPadding(padding, 0, padding, 0);
    RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    titleParams.addRule(RelativeLayout.ABOVE, descriptionView.getId());
    titleView.setLayoutParams(titleParams);
    titleView.setTextColor(Color.WHITE);
    titleView.setShadowLayer(2, 3, 3, Color.argb(230, 0, 0, 0));
    titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);

    carouselView.addView(titleView);
}