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.android.mail.browse.ConversationItemView.java

public ConversationItemView(Context context, Account account) {
    super(context);
    Utils.traceBeginSection("CIVC constructor");
    setClickable(true);//from w w w  .  j a v  a  2s  .  c  om
    setLongClickable(true);
    mContext = context.getApplicationContext();
    final Resources res = mContext.getResources();
    mTabletDevice = Utils.useTabletUI(res);
    mListCollapsible = !res.getBoolean(R.bool.is_tablet_landscape);
    mAccount = account;

    getItemViewResources(mContext);

    final int layoutDir = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());

    mSendersTextView = new TextView(mContext);
    mSendersTextView.setIncludeFontPadding(false);

    mSubjectTextView = new TextView(mContext);
    mSubjectTextView.setEllipsize(TextUtils.TruncateAt.END);
    mSubjectTextView.setIncludeFontPadding(false);
    ViewCompat.setLayoutDirection(mSubjectTextView, layoutDir);
    ViewUtils.setTextAlignment(mSubjectTextView, View.TEXT_ALIGNMENT_VIEW_START);

    mSnippetTextView = new TextView(mContext);
    mSnippetTextView.setEllipsize(TextUtils.TruncateAt.END);
    mSnippetTextView.setIncludeFontPadding(false);
    mSnippetTextView.setTypeface(SANS_SERIF_LIGHT);
    mSnippetTextView.setTextColor(getResources().getColor(R.color.snippet_text_color));
    ViewCompat.setLayoutDirection(mSnippetTextView, layoutDir);
    ViewUtils.setTextAlignment(mSnippetTextView, View.TEXT_ALIGNMENT_VIEW_START);

    // hack for b/16345519. Root cause is b/17280038.
    if (layoutDir == LAYOUT_DIRECTION_RTL) {
        mSubjectTextView.setMaxLines(1);
        mSnippetTextView.setMaxLines(1);
    } else {
        mSubjectTextView.setSingleLine();
        mSnippetTextView.setSingleLine();
    }

    mSendersImageView = new CheckableContactFlipDrawable(res, sCabAnimationDuration);
    mSendersImageView.setCallback(this);

    Utils.traceEndSection();
}

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

private void createTableLayoutPsnDtls() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();//from  w  w w.  j a  v a2  s. c om
        mFrameLayout.addView(mTextViewPNRSts);
        mStrPassengerDetails = null;
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        mStrPassengerDetails = null;
        return;
    }
    List<List<String>> passengersList;
    if (mPassengerDetails == null || mPassengerDetails.getPNR() != mPNRNumber) {
        Elements elements = Jsoup.parse(mPageResult).select("table tr td:containsOwn(S. No.)");
        Iterator iterator = null;
        try {
            iterator = elements.first().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("PNRStat", mPageResult);
            return;
        }
        passengersList = new ArrayList<List<String>>();
        List<String> list;
        Element tmp;
        while (iterator.hasNext()) {
            tmp = (Element) iterator.next();
            if (tmp.toString().contains("Passenger")) {
                list = new ArrayList<String>();
                list.add(tmp.select("td").get(0).text());
                list.add(tmp.select("td").get(1).text());
                list.add(tmp.select("td").get(2).text());
                if (!tmp.select("td").get(2).text().toUpperCase().contains("CNF")
                        && !tmp.select("td").get(2).text().toUpperCase().contains("CAN")) {
                    isWaitingList = true;
                }
                passengersList.add(list);
            }
        }
        mPassengerDetails = new PassengerDetails(passengersList, mPNRNumber);
    } else {
        passengersList = mPassengerDetails.getPassengerList();
    }

    mTableLayoutPsn = new TableLayout(mActivity);
    TableRow row;
    TextView tv1, tv2, tv3, tv4;
    mStrPassengerDetails = new ArrayList<String>();
    int current;
    mTableLayoutPsn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < passengersList.size(); ++i) {
        current = i + 1;
        row = new TableRow(mActivity);
        row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        tv1 = new TextView(mActivity);
        tv2 = new TextView(mActivity);
        tv3 = new TextView(mActivity);
        tv4 = new TextView(mActivity);

        tv1.setText("" + (i + 1) + ".");
        tv2.setText("   " + passengersList.get(i).get(0));
        tv3.setText("   " + passengersList.get(i).get(1));
        tv4.setText("   " + passengersList.get(i).get(2));

        tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv4.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);

        tv1.setPadding(10, 10, 10, 10);
        tv2.setPadding(10, 10, 10, 10);
        tv3.setPadding(10, 10, 10, 10);
        tv4.setPadding(10, 10, 10, 10);

        row.addView(tv1);
        row.addView(tv2);
        row.addView(tv3);
        row.addView(tv4);

        row.setBackgroundResource(R.drawable.card_background);
        row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        mTableLayoutPsn.addView(row);
        String strPsn = "" + current + ". " + passengersList.get(i).get(0) + "   "
                + passengersList.get(i).get(1) + "   " + passengersList.get(i).get(2);
        mStrPassengerDetails.add(strPsn);
    }
}

From source file:com.appsimobile.appsii.module.home.HomeAdapter.java

private AbsHomeViewHolder createDummyViewHolder(int height) {
    TextView result = new TextView(mContext);
    HomeViewWrapper wrapped = wrapView(mContext, result, height);
    return new SimpleTextViewViewHolder(wrapped);
}

From source file:sjizl.com.FileUploadTest.java

private void Brows() {
    JSONArray json31;//from w  w w.j a va  2  s . c om
    UserFunctions userFunctions = new UserFunctions();
    json31 = userFunctions.getFotos(username, password, naam);
    String str = json31.toString();
    String aaaa = CommonUtilities.randInt(111, 999);
    stock_list = new ArrayList<String>();
    stock_list2 = new ArrayList<String>();
    stock_list3 = new ArrayList<String>();
    stock_list4 = new ArrayList<String>();
    stock_list5 = new ArrayList<String>();
    stock_list6 = new ArrayList<String>();
    stock_list7 = new ArrayList<String>();

    stock_list7.add("0");
    stock_list6.add("0");
    stock_list4.add("0");
    stock_list5.add("0");
    stock_list2.add("0");
    stock_list3.add("0");
    stock_list.add("drawable://" + R.drawable.add_photo);

    for (int i = 0; i < json31.length(); i++) { // **line 2**
        JSONObject childJSONObject = null;
        try {
            childJSONObject = json31.getJSONObject(i);
            String fid = childJSONObject.getString("fid");
            String name = childJSONObject.getString("pid");
            String foto2 = childJSONObject.getString("foto");
            String foto_mum2 = childJSONObject.getString("foto_num");
            String laatste_berichten2 = childJSONObject.getString("laatst_online");
            String aantal_new = childJSONObject.getString("woonplaats");

            MemoryCacheUtils.removeFromCache("http://sjizl.com/fotos/" + foto_mum2 + "/thumbs/" + foto2 + "",
                    ImageLoader.getInstance().getMemoryCache());
            DiskCacheUtils.removeFromCache("http://sjizl.com/fotos/" + foto_mum2 + "/thumbs/" + foto2 + "",
                    ImageLoader.getInstance().getDiscCache());

            stock_list7.add(fid);
            stock_list6.add(aantal_new);
            stock_list4.add(foto2);
            stock_list5.add(foto_mum2);
            stock_list2.add(name);
            stock_list3.add(laatste_berichten2);
            stock_list.add("http://sjizl.com/fotos/" + foto_mum2 + "/thumbs/" + foto2 + "");
            //imageUrls[] =url;

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    stockArr = new String[stock_list.size()];
    stockArr2 = new String[stock_list2.size()];
    stockArr3 = new String[stock_list3.size()];
    stockArr4 = new String[stock_list4.size()];
    stockArr5 = new String[stock_list5.size()];
    stockArr6 = new String[stock_list6.size()];
    stockArr7 = new String[stock_list7.size()];

    aantal_new_ber = stock_list6.toArray(stockArr6);
    imageUrls2 = stock_list.toArray(stockArr);
    names = stock_list2.toArray(stockArr2);
    laatste_bericht = stock_list3.toArray(stockArr3);
    fotos = stock_list4.toArray(stockArr4);
    fotos_nums = stock_list5.toArray(stockArr5);
    fids = stock_list7.toArray(stockArr7);

    if (stock_list4.toString().contains("geen")) {

        String mess = getResources().getString(R.string.app_name);

        TextView textv1 = new TextView(this);
        textv1.setText("To use all features of " + mess + " you need to upload a photo of yourself");
        upload_photo_text.addView(textv1);

        do_animation_top(upload_photo_text);
    } else {

        upload_photo_text.setVisibility(View.GONE);
    }

    listView = (GridView) findViewById(R.id.gridview);
    ImageAdapter aaa = new ImageAdapter();
    ((GridView) listView).setAdapter(aaa);
    aaa.notifyDataSetChanged();
}

From source file:com.juick.android.JuickMessagesAdapter.java

public static float getDefaultTextSize(Context context) {
    if (defaultTextSize == 0) {
        TextView textView = new TextView(context);
        defaultTextSize = textView.getTextSize();
    }/*www. j  a va 2 s.  co  m*/
    return defaultTextSize;
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/**
 * Creates the Application Info dialog with clickable links.
 * /*w w w  .  j  a v  a 2 s  .  c  o m*/
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private void showVersionInfoDialog() throws UnsupportedEncodingException, IOException {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.app_name) + " " + getString(R.string.version_name));

    AssetManager assetManager = getResources().getAssets();
    String versionInfoFile = getString(R.string.versioninfo_asset);
    InputStreamReader reader = new InputStreamReader(assetManager.open(versionInfoFile), "UTF-8");
    BufferedReader br = new BufferedReader(reader);
    StringBuffer sbuf = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        sbuf.append(line);
        sbuf.append("\r\n");
    }

    final ScrollView scroll = new ScrollView(this);
    final TextView message = new TextView(this);
    final SpannableString sWlinks = new SpannableString(sbuf.toString());
    Linkify.addLinks(sWlinks, Linkify.WEB_URLS);
    message.setText(sWlinks);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(15, 15, 15, 15);
    scroll.addView(message);
    alertDialog.setView(scroll);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // nothing to do, just dismiss dialog
        }
    });
    alertDialog.show();
}

From source file:app.sunstreak.yourpisd.LoginActivity.java

/**
 * Shows the progress UI and hides the login form.
 *///from  w w w  .  jav  a2s . c  om
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

        mLoginFormView.setVisibility(View.VISIBLE);
        mLoginFormView.animate().setDuration(shortAnimTime)
                //.translationY(-200)
                .alpha(show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
                    }
                });
        mLoginStatusView.setVisibility(View.VISIBLE);
        mLoginStatusView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
                    }
                });

        //            mLoginFormView.setVisibility(View.VISIBLE);
        //            mLoginFormView.animate().setDuration(500).setInterpolator(new DecelerateInterpolator())
        //                    .translationY(height*(show? -1 : 1)).setListener(new AnimatorListenerAdapter() {
        //            @Override
        //            public void onAnimationEnd(Animator animation) {
        //                    mLoginFormView.setVisibility(show ? View.INVISIBLE
        //                            : View.VISIBLE);
        //            }
        //         });
        //            mLoginStatusView.setVisibility(View.VISIBLE);
        //            mLoginStatusView.animate().setDuration(shortAnimTime).translationY(0)
        //         .setListener(new AnimatorListenerAdapter() {
        //            @Override
        //            public void onAnimationEnd(Animator animation) {
        //               mLoginStatusView.setVisibility(show ? View.VISIBLE
        //                     : View.INVISIBLE);
        //                    System.out.println("show loading: " + show);
        //            }
        //         });

        if (DateHelper.isAprilFools()) {
            mLoginStatusView.removeAllViews();

            try {
                ImageView img = new ImageView(this);
                //noinspection ResourceType
                img.setId(1337);
                InputStream is = getAssets().open("nyan.png");
                img.setImageBitmap(BitmapFactory.decodeStream(is));
                is.close();
                TextView april = new TextView(this);
                april.setText(
                        "Today and tomorrow, we shall pay \"homage\" to the numerous poor designs of the internet");
                april.setGravity(Gravity.CENTER_HORIZONTAL);
                mLoginStatusView.addView(img);
                mLoginStatusView.addView(april);

                RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation1.setInterpolator(new LinearInterpolator());
                rotateAnimation1.setDuration(500);
                rotateAnimation1.setRepeatCount(Animation.INFINITE);
                img.startAnimation(rotateAnimation1);

            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }

        //         mLoginStatusView.animate().setDuration(shortAnimTime)
        //               .alpha(show ? 1 : 0)
        //               .setListener(new AnimatorListenerAdapter() {
        //                  @Override
        //                  public void onAnimationEnd(Animator animation) {
        //                     mLoginStatusView.setVisibility(show ? View.VISIBLE
        //                           : View.GONE);
        //                  }
        //               });

        //         mLoginFormView.setVisibility(View.VISIBLE);
        //         mLoginFormView.animate().setDuration(shortAnimTime)
        //               .alpha(show ? 0 : 1)
        //               .setListener(new AnimatorListenerAdapter() {
        //                  @Override
        //                  public void onAnimationEnd(Animator animation) {
        //                     mLoginFormView.setVisibility(show ? View.GONE
        //                           : View.VISIBLE);
        //                  }
        //               });

    } /* else if(getIntent().getExtras().getBoolean("Refresh")){
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
      }*/

}

From source file:com.juick.android.JuickMessagesAdapter.java

public static float getLineHeight(Context context, double scale) {
    Integer integer = lineHeights.get(scale);
    if (integer == null) {
        TextView textView = new TextView(context);
        textView.setTextSize((int) (getDefaultTextSize(context) * scale));
        integer = textView.getLineHeight();
        lineHeights.put(scale, integer);
    }//from   w  w  w  .j a  v a2  s. c om
    return integer;
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showCashoutPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = "Please enter account details.";
    String positiveButtonText = "Withdraw";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelAccountNo = new TextView(getActivity());
    final EditText editAccountNo = new EditText(getActivity());
    editAccountNo.setSingleLine(true);//from w  w w.  jav a 2  s  .  c  o  m
    final TextView labelAccountHolderName = new TextView(getActivity());
    final EditText editAccountHolderName = new EditText(getActivity());
    editAccountHolderName.setSingleLine(true);
    final TextView labelIfscCode = new TextView(getActivity());
    final EditText editIfscCode = new EditText(getActivity());
    editIfscCode.setSingleLine(true);

    labelAmount.setText("Withdrawal Amount");
    labelAccountNo.setText("Account Number");
    labelAccountHolderName.setText("Account Holder Name");
    labelIfscCode.setText("IFSC Code");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelAccountNo.setLayoutParams(layoutParams);
    labelAccountHolderName.setLayoutParams(layoutParams);
    labelIfscCode.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editAccountNo.setLayoutParams(layoutParams);
    editAccountHolderName.setLayoutParams(layoutParams);
    editIfscCode.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelAccountNo);
    linearLayout.addView(editAccountNo);
    linearLayout.addView(labelAccountHolderName);
    linearLayout.addView(editAccountHolderName);
    linearLayout.addView(labelIfscCode);
    linearLayout.addView(editIfscCode);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

    alert.setTitle("Withdraw Money To Your Account");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String accontNo = editAccountNo.getText().toString();
            String accountHolderName = editAccountHolderName.getText().toString();
            String ifsc = editIfscCode.getText().toString();

            CashoutInfo cashoutInfo = new CashoutInfo(new Amount(amount), accontNo, accountHolderName, ifsc);
            mListener.onCashoutSelected(cashoutInfo);

            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

private void addTopTextView(String title, int count, int index) {
    if (mTopTextLayout == null) {
        mTopTextLayout = (LinearLayout) findViewById(R.id.top_text_layout);
    }//from w  w  w.  ja va2  s. c om
    if (mTopFocusLine == null) {
        mTopFocusLine = (ImageView) findViewById(R.id.top_focus_line);
    }
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = (int) getResources().getDimensionPixelSize(R.dimen.navigation_home_to_left);
    LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams2.leftMargin = (int) getResources().getDimensionPixelSize(R.dimen.navigation_home_margin_left);
    if (mTopTextView == null) {
        mTopTextView = new TextView[count];
    }

    TextView textView = new TextView(this);
    textView.setText(title);
    //      if (index == 0) {
    //         textView.setTextColor(getResources().getColor(R.color.blue));
    //         mTopTextLayout.addView(textView, layoutParams);
    //      } else {

    textView.setTextColor(getResources().getColor(R.color.white));
    if (mPageCount < 5) {
        mTopTextLayout.addView(textView, layoutParams2);
    } else {
        mTopTextLayout.addView(textView, layoutParams);
    }
    //      }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimensionPixelSize(R.dimen.view_page_text_size));
    mTopTextView[index] = textView;
    if (mTopTextView[index] != null) {
        mTopTextView[index].setTag(index);
        mTopTextView[index].setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                int tag = (Integer) arg0.getTag();
                mViewPager.setCurrentItem(tag);

            }
        });
    }
}