Example usage for android.widget TextView setGravity

List of usage examples for android.widget TextView setGravity

Introduction

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

Prototype

public void setGravity(int gravity) 

Source Link

Document

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

Usage

From source file:com.astuetz.PagerSlidingTabStripPlus.java

/**
 * Add new text view to the linear layout that contains the tab title*
 * @param position of the linear layout in the tabsContainer
 * @param text is the text of the subtitle
 *//*from   w  w w  . j  av  a  2  s  .c o m*/
public void addSubtitleAtTab(int position, String text) {
    LinearLayout tab = getSingleTabLayoutAtPosition(position);
    tab.setWeightSum(tab.getChildCount() + 1);
    if (tab.getChildCount() == 1) {
        tab.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    }

    ((TextView) tab.getChildAt(0)).setGravity(Gravity.CENTER_HORIZONTAL);

    TextView newSubTab = new TextView(getContext());
    newSubTab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    newSubTab.setText(text);
    newSubTab.setGravity(Gravity.CENTER_HORIZONTAL);

    tab.addView(newSubTab);
    updateTabStyles();
}

From source file:com.cytmxk.test.animation.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    View tabView;/*  ww  w  .  j  a  v  a2s. c o m*/
    if (mTabIcons != null && position < mTabIcons.length) {
        View iconView = new View(getContext());
        iconView.setBackgroundResource(mTabIcons[position]);
        iconView.setContentDescription(tabTitle);

        tabView = iconView;
    } else {
        final TextView textView = new TextView(getContext());
        textView.setText(tabTitle);
        textView.setBackgroundResource(R.drawable.view_pager_tab_background);

        // 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.setGravity(Gravity.CENTER);

        tabView = textView;
    }

    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    tabView.setOnLongClickListener(new OnTabLongClickListener(position));

    tabView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(tabView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));

    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        tabView.setSelected(true);
    }
}

From source file:com.jgraves.achievementunlocked.AchievementsList_Fragment.java

private void addAchievementToList(Long id, String name, int points) {
    Log.i(ExploraApp.TAG, "Adding achievement image request of id " + id + " with height, " + imageViewHeight);
    FrameLayout fl = new FrameLayout(getActivity());
    touchMap.put(fl, id);/*from www.  j  a v a  2s .c o m*/
    fl.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Long id = touchMap.get(v);
            Log.i(ExploraApp.TAG, "TOUCHED " + id);
            Intent intent = new Intent(getActivity(), Activity_AchievementInfo.class);
            intent.putExtra("achievement_id", Long.toString(id));
            startActivity(intent);
        }
    });
    TextView tv_name = new TextView(getActivity());
    TextView tv_points = new TextView(getActivity());
    ImageView iv = new ImageView(getActivity());
    fl.setMinimumHeight(imageViewHeight);
    fl.setMinimumWidth(ExploraApp.screenWidth);
    robotoTypeface = Typeface.createFromAsset(getActivity().getAssets(), "Roboto-Thin.ttf");
    tv_name.setText(name);
    tv_name.setTextSize(15f);
    tv_points.setTextSize(15f);
    tv_name.setTypeface(robotoTypeface);
    tv_points.setTypeface(robotoTypeface);
    tv_points.setText(Integer.toString(points));
    tv_points.setGravity(Gravity.RIGHT);
    tv_points.setTextColor(Color.WHITE);
    tv_name.setTextColor(Color.WHITE);
    iv.setMinimumHeight(imageViewHeight);
    iv.setMinimumWidth(ExploraApp.screenWidth);
    fl.addView(iv);
    fl.addView(tv_name);
    fl.addView(tv_points);
    ll_images_container.addView(fl);
    sv_images.bringChildToFront(mQuickReturnView);
    DefaultImageListener listener = new DefaultImageListener(iv);
    ImageRequest imageRequest = new ImageRequest(
            ExploraApp.url_main + "/achievement/" + id + "/photo?y=" + imageViewHeight + "&x="
                    + ExploraApp.screenWidth,
            listener, ExploraApp.screenWidth, imageViewHeight, Bitmap.Config.ARGB_8888, listener);
    ExploraApp.mRequestQueue.add(imageRequest);
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

/**
 * Refreshes funds table with fetched data
 *
 * @param response JSONObject with funds data
 *//*from   ww  w . j  a va 2s.  co  m*/
private void refreshFunds(JSONObject response) {
    try {
        if (response == null) {
            Toast.makeText(getActivity(), getResources().getString(R.string.GeneralErrorText),
                    Toast.LENGTH_LONG).show();
            return;
        }
        String notificationText;
        if (response.getInt("success") == 1) {

            View.OnClickListener fillAmount = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ScrollView scrollView = (ScrollView) getView();
                    if (scrollView != null) {
                        EditText tradeAmount = (EditText) scrollView.findViewById(R.id.TradeAmount);
                        tradeAmount.setText(((TextView) v).getText());
                        scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom());
                    }
                }
            };

            notificationText = getResources().getString(R.string.FundsInfoUpdatedtext);
            TableLayout fundsContainer = (TableLayout) getView().findViewById(R.id.FundsContainer);
            fundsContainer.removeAllViews();
            JSONObject funds = response.getJSONObject("return").getJSONObject("funds");
            JSONArray fundsNames = response.getJSONObject("return").getJSONObject("funds").names();
            List<String> arrayList = new ArrayList<>();

            for (int i = 0; i < fundsNames.length(); i++) {
                arrayList.add(fundsNames.getString(i));
            }
            Collections.sort(arrayList);
            TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1);

            for (String anArrayList : arrayList) {

                TableRow row = new TableRow(getActivity());
                TextView currency = new TextView(getActivity());
                TextView amount = new TextView(getActivity());
                currency.setText(anArrayList.toUpperCase(Locale.US));
                amount.setText(funds.getString(anArrayList));
                currency.setLayoutParams(layoutParams);
                currency.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                currency.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
                currency.setGravity(Gravity.CENTER);
                amount.setLayoutParams(layoutParams);
                amount.setGravity(Gravity.CENTER);
                amount.setOnClickListener(fillAmount);
                row.addView(currency);
                row.addView(amount);
                fundsContainer.addView(row);
            }

        } else {
            notificationText = response.getString("error");
        }

        mCallback.makeNotification(ConstantHolder.ACCOUNT_INFO_NOTIF_ID, notificationText);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

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

/**
 * Shows the progress UI and hides the login form.
 *///from   ww  w  .j a  va  2  s  .c  o  m
@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.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *//*ww  w  .  java  2 s  .  co m*/
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    // UI settings for dialog pop-up
    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + name + " created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Close dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 *//*w  ww. j  a  v  a2 s  .com*/
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer position = mListView.getPositionForView(view);
    final Dialog editDialog = new Dialog(this);

    // UI settings for dialog pop-up
    editDialog.setContentView(R.layout.add_edit_dialog);
    editDialog.setTitle("Edit Todo");
    TextView textView = (TextView) editDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    editDialog.setCancelable(true);
    EditText currentText = (EditText) editDialog.findViewById(R.id.todo);

    // Get selected TodoItem values
    final String name = mTodoItemList.get(position).text;
    final boolean isDone = mTodoItemList.get(position).isDone;
    final int id = mTodoItemList.get(position).idNumber;
    currentText.setText(name);

    Button editDone = (Button) editDialog.findViewById(R.id.Add);
    editDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    editDone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) editDialog.findViewById(R.id.todo);

            final String updatedName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!updatedName.isEmpty()) {
                String json = "{\"text\":\"" + updatedName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + updatedName + " updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            editDialog.dismiss();
        }
    });
}

From source file:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java

public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) {
    // map our custom item data to fields
    //        title.setText(item.getTitle());
    resultItems = item.getResultItems();

    resultListView.removeAllViews();/*  www .  j  a va  2  s  .c  o  m*/

    final float scale = getResources().getDisplayMetrics().density;

    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    final int topBottomItem = Helperfunctions.dpToPx(3, scale);

    final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);

    final int topBottomImg = Helperfunctions.dpToPx(1, scale);

    if (resultItems != null && resultItems.length() > 0) {

        for (int i = 0; i < 1; i++)
            // JSONObject resultListItem;
            try {
                final JSONObject result = resultItems.getJSONObject(i);

                final LayoutInflater resultInflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent);

                final LinearLayout measurementLayout = (LinearLayout) resultView
                        .findViewById(R.id.resultMeasurementList);
                measurementLayout.setVisibility(View.GONE);

                final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList);
                netLayout.setVisibility(View.GONE);

                final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement);
                measurementHeader.setVisibility(View.GONE);

                final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet);
                netHeader.setVisibility(View.GONE);

                final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate);
                dateHeader.setVisibility(View.GONE);

                dateHeader.setText(result.optString("time_string"));

                final JSONArray measurementArray = result.getJSONArray("measurement");

                final JSONArray netArray = result.getJSONArray("net");

                for (int j = 0; j < measurementArray.length(); j++) {

                    final JSONObject singleItem = measurementArray.getJSONObject(j);

                    final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    measurememtItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

                    measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL);
                    measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem,
                            topBottomItem);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    measurememtItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
                    // itemClassification.set setGravity(Gravity.LEFT);

                    itemClassification.setImageDrawable(getResources().getDrawable(
                            Helperfunctions.getClassificationImage(singleItem.getInt("classification"))));

                    measurememtItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.getString("value"));

                    measurememtItemLayout.addView(itemValue);

                    measurementLayout.addView(measurememtItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    measurementLayout.addView(divider);

                    measurementLayout.invalidate();
                }

                for (int j = 0; j < netArray.length(); j++) {

                    final JSONObject singleItem = netArray.getJSONObject(j);

                    final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    netItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
                    netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);

                    netItemLayout.setGravity(Gravity.CENTER_VERTICAL);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    netItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);

                    itemClassification.setImageDrawable(
                            context.getResources().getDrawable(R.drawable.traffic_lights_none));
                    netItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.optString("value", null));

                    netItemLayout.addView(itemValue);

                    netLayout.addView(netItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    netLayout.addView(divider);

                    netLayout.invalidate();
                }

                measurementHeader.setVisibility(View.VISIBLE);
                netHeader.setVisibility(View.VISIBLE);

                measurementLayout.setVisibility(View.VISIBLE);
                netLayout.setVisibility(View.VISIBLE);

                dateHeader.setVisibility(View.VISIBLE);

                resultListView.addView(resultView);

                Log.d(DEBUG_TAG, "View Added");
                // codeText.setText(resultListItem.getString("sync_code"));

            } catch (final JSONException e) {
                e.printStackTrace();
            }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultListView.setVisibility(View.VISIBLE);

        resultListView.invalidate();
    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(context.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}

From source file:com.cssweb.android.quote.QuoteDetail.java

/**
 * //w  w w.  j a va  2s  .  c  o  m
 * @param jArr
 * @param table
 * @param zrsp
 * @throws JSONException
 */
private void appendRow(JSONArray jArr, TableLayout table, double zrsp) throws JSONException {
    table.setStretchAllColumns(true);
    table.removeAllViews();

    if ("cf".equals(exchange.toLowerCase()) || "dc".equals(exchange.toLowerCase())
            || "sf".equals(exchange.toLowerCase()) || "cz".equals(exchange.toLowerCase())) {
        int len = jArr.length();
        int color = Utils.getTextColor(mContext, 0);
        for (int i = 0; i < len; i++) {
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.title23);
            linearLayout.setVisibility(View.VISIBLE);

            JSONArray jA = (JSONArray) jArr.get(i);
            TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.zr_quote_price_item, null);
            TextView t1 = (TextView) row.findViewById(R.id.zr_table_col1);
            TextView t2 = (TextView) row.findViewById(R.id.zr_table_col2);
            TextView t3 = (TextView) row.findViewById(R.id.zr_table_col3);
            TextView t4 = (TextView) row.findViewById(R.id.zr_table_col4);
            TextView t5 = (TextView) row.findViewById(R.id.zr_table_col5);
            t1.setText(jA.getString(4));
            t2.setText(Utils.dataFormation(jA.getDouble(0), Utils.getStockDigit(type)));
            t2.setTextColor(Utils.getTextColor(mContext, jA.getDouble(0), zrsp));
            t2.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            double cjsl = Arith.round(jA.getDouble(1), 0);
            t3.setText(Utils.dataFormation(cjsl, 0));
            t3.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            t4.setText(jA.getString(7));
            t5.setText(jA.getString(8));
            table.addView(row);
            if ("B".equals(jA.getString(6))) {
                color = Utils.getTextColor(mContext, 3);
                t3.setTextColor(color);
                t4.setTextColor(color);
                t5.setTextColor(color);
            } else if ("S".equals(jA.getString(6))) {
                color = Utils.getTextColor(mContext, 4);
                t3.setTextColor(color);
                t4.setTextColor(color);
                t5.setTextColor(color);
            } else {
                t3.setTextColor(color);
                t4.setTextColor(color);
                t5.setTextColor(color);
            }
        }
    } else {
        if (stocktype.charAt(0) == '0') {//
            //for (int i = jArr.length()-1; i >= 0; i--) {
            for (int i = 0; i <= jArr.length() - 1; i++) {
                JSONArray jA = (JSONArray) jArr.get(i);
                TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.zr_quote_price_item, null);
                TextView t1 = (TextView) row.findViewById(R.id.zr_table_col1);
                TextView t2 = (TextView) row.findViewById(R.id.zr_table_col2);
                TextView t3 = (TextView) row.findViewById(R.id.zr_table_col3);
                TextView t4 = (TextView) row.findViewById(R.id.zr_table_col4);
                t1.setText(jA.getString(4));
                t2.setText(Utils.dataFormation(jA.getDouble(0), Utils.getStockDigit(type)));
                t2.setTextColor(Utils.getTextColor(mContext, jA.getDouble(0), zrsp));
                t2.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
                double cjsl = Arith.round(jA.getDouble(1), 0);
                t3.setText(Utils.dataFormation(cjsl, 0));
                if (cjsl > 500)
                    t3.setTextColor(Utils.getTextColor(mContext, 6));
                else
                    t3.setTextColor(Utils.getTextColor(mContext, 1));
                t3.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
                t4.setText(jA.getString(6));
                if ("B".equals(jA.getString(6)))
                    t4.setTextColor(Utils.getTextColor(mContext, 3));
                else
                    t4.setTextColor(Utils.getTextColor(mContext, 4));
                table.addView(row);
            }
            //?
            int num = jArr.length();
            if (num < 16) {
                while (num < 16) {
                    TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.zr_quote_price_item,
                            null);
                    table.addView(row);
                    num++;
                }
            }
        } else if (stocktype.charAt(0) == '1' || stocktype.charAt(0) == '2') {//
            //for (int i = jArr.length()-1; i >= 0; i--) {
            for (int i = 0; i <= jArr.length() - 1; i++) {
                JSONArray jA = (JSONArray) jArr.get(i);
                TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.zr_quote_price_item, null);
                TextView t1 = (TextView) row.findViewById(R.id.zr_table_col1);
                TextView t2 = (TextView) row.findViewById(R.id.zr_table_col2);
                TextView t3 = (TextView) row.findViewById(R.id.zr_table_col4);
                t1.setText(jA.getString(4));
                t2.setText(Utils.dataFormation(jA.getDouble(0), Utils.getStockDigit(type)));
                t2.setTextColor(Utils.getTextColor(mContext, jA.getDouble(0), zrsp));
                t3.setText(Utils.getAmountFormat(jA.getDouble(5), true));
                t3.setTextColor(Utils.getTextColor(mContext, 1));
                table.addView(row);
            }
            //?
            int num = jArr.length();
            if (num < 16) {
                while (num < 16) {
                    TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.zr_quote_price_item,
                            null);
                    table.addView(row);
                    num++;
                }
            }
        }
    }

}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
    final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance()
            .getCurrent().mShouldShowUiToAcceptTypedWord;
    final int stripWidth = addToDictionaryStrip.getWidth();
    final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2;

    final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save);
    wordView.setTextColor(mColorTypedWord);
    final int wordWidth = (int) (width * mCenterSuggestionWeight);
    final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint());
    final float wordScaleX = wordView.getTextScaleX();
    wordView.setText(wordToSave);//from w ww  .j a v  a  2s .  c  o  m
    wordView.setTextScaleX(wordScaleX);
    setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
    final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
    wordView.setVisibility(wordVisibility);
    addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);

    final Resources res = addToDictionaryStrip.getResources();
    final CharSequence hintText;
    final int hintWidth;
    final float hintWeight;
    final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary);
    if (shouldShowUiToAcceptTypedWord) {
        hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
        hintWidth = width;
        hintWeight = 1.0f;
        hintView.setGravity(Gravity.CENTER);
    } else {
        final boolean isRtlLanguage = (ViewCompat
                .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL);
        final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
        final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale);
        final CharSequence hint = res.getText(R.string.hint_add_to_dictionary);
        hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow);
        hintWidth = width - wordWidth;
        hintWeight = 1.0f - mCenterSuggestionWeight;
        hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    }
    hintView.setTextColor(mColorAutoCorrect);
    final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
    hintView.setText(hintText);
    hintView.setTextScaleX(hintScaleX);
    setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}