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.google.android.apps.santatracker.launch.TvStartupActivity.java

private void addDebugMenuListRaw(ArrayObjectAdapter objectAdapter) {

    mMarkers.setPadding(mMarkers.getPaddingLeft(), mMarkers.getPaddingTop() + 150, mMarkers.getPaddingRight(),
            mMarkers.getPaddingBottom());

    Presenter debugMenuPresenter = new Presenter() {
        @Override//from w w w .  j  a v  a 2s.c  o m
        public ViewHolder onCreateViewHolder(ViewGroup parent) {
            TextView tv = new TextView(parent.getContext());
            ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(200, 150);
            tv.setLayoutParams(params);
            tv.setGravity(Gravity.CENTER);
            tv.setBackgroundColor(getResources().getColor(R.color.SantaBlueDark));
            tv.setFocusableInTouchMode(false);
            tv.setFocusable(true);
            tv.setClickable(true);
            return new ViewHolder(tv);
        }

        @Override
        public void onBindViewHolder(ViewHolder viewHolder, Object item) {
            ((TextView) viewHolder.view).setText((String) item);
            viewHolder.view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String text = ((TextView) v).getText().toString();
                    if (text.contains("Enable Tracker")) {
                        enableTrackerMode(true);
                    } else if (text.contains("Enable CountDown")) {
                        startCountdown(SantaPreferences.getCurrentTime());
                    } else {
                        mIsDebug = false;
                        initialiseViews();
                        resetLauncherStates();
                    }
                }
            });
        }

        @Override
        public void onUnbindViewHolder(ViewHolder viewHolder) {

        }
    };

    ObjectAdapter debugMenuAdapter = new ObjectAdapter(debugMenuPresenter) {

        private final String[] mMenuString = { "Enable Tracker", "Enable CountDown", "Hide DebugMenu" };

        @Override
        public int size() {
            return mMenuString.length;
        }

        @Override
        public Object get(int position) {
            return mMenuString[position];
        }
    };

    ListRow debugMenuListRow = new ListRow(debugMenuAdapter);
    objectAdapter.add(debugMenuListRow);
}

From source file:com.mifos.mifosxdroid.online.generatecollectionsheet.GenerateCollectionSheetFragment.java

private void inflateProductiveCollectionTable(CollectionSheetResponse collectionSheetResponse) {

    //Clear old views in case they are present.
    if (tableProductive.getChildCount() > 0) {
        tableProductive.removeAllViews();
    }/* www  .  j av a 2 s.c  om*/

    if (tableAdditional.getVisibility() == View.VISIBLE) {
        tableAdditional.removeAllViews();
        tableAdditional.setVisibility(View.GONE);
    }

    //A List to be used to inflate Attendance Spinners
    ArrayList<String> attendanceTypes = new ArrayList<>();
    attendanceTypeOptions.clear();
    attendanceTypeOptions = presenter.filterAttendanceTypes(collectionSheetResponse.getAttendanceTypeOptions(),
            attendanceTypes);

    //Add the heading Row
    TableRow headingRow = new TableRow(getContext());
    TableRow.LayoutParams headingRowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    headingRowParams.gravity = Gravity.CENTER;
    headingRowParams.setMargins(0, 0, 0, 10);
    headingRow.setLayoutParams(headingRowParams);

    TextView tvGroupName = new TextView(getContext());
    tvGroupName.setText(collectionSheetResponse.getGroups().get(0).getGroupName());
    tvGroupName.setTypeface(tvGroupName.getTypeface(), Typeface.BOLD);
    tvGroupName.setGravity(Gravity.CENTER);
    headingRow.addView(tvGroupName);

    for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
        TextView tvProduct = new TextView(getContext());
        tvProduct.setText(getString(R.string.collection_heading_charges, loanProduct.getName()));
        tvProduct.setTypeface(tvProduct.getTypeface(), Typeface.BOLD);
        tvProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvProduct);
    }

    TextView tvAttendance = new TextView(getContext());
    tvAttendance.setText(getString(R.string.attendance));
    tvAttendance.setGravity(Gravity.CENTER);
    tvAttendance.setTypeface(tvAttendance.getTypeface(), Typeface.BOLD);
    headingRow.addView(tvAttendance);

    tableProductive.addView(headingRow);

    for (ClientCollectionSheet clientCollectionSheet : collectionSheetResponse.getGroups().get(0)
            .getClients()) {
        //Insert rows
        TableRow row = new TableRow(getContext());
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        rowParams.gravity = Gravity.CENTER;
        rowParams.setMargins(0, 0, 0, 10);
        row.setLayoutParams(rowParams);

        //Column 1: Client Name and Id
        TextView tvClientName = new TextView(getContext());
        tvClientName.setText(
                concatIdWithName(clientCollectionSheet.getClientName(), clientCollectionSheet.getClientId()));
        row.addView(tvClientName);

        //Subsequent columns: The Loan products
        for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
            //Since there may be several items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the loans in of this type and add in the container
            for (LoanCollectionSheet loanCollectionSheet : clientCollectionSheet.getLoans()) {
                if (loanProduct.getName().equals(loanCollectionSheet.getProductShortName())) {
                    //This loan should be shown in this column. So, add it in the container.
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the loan id as the Tag of the EditText which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_LOAN + ":" + loanCollectionSheet.getLoanId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        Spinner spAttendance = new Spinner(getContext());
        setSpinner(spAttendance, attendanceTypes);
        row.addView(spAttendance);

        tableProductive.addView(row);
    }

    if (btnSubmitProductive.getVisibility() != View.VISIBLE) {
        //Show the button the first time sheet is loaded.
        btnSubmitProductive.setVisibility(View.VISIBLE);
        btnSubmitProductive.setOnClickListener(this);
    }

    //If this block has been executed, that the CollectionSheet
    //which is already shown on screen is for center - Productive.
    btnSubmitProductive.setTag(TAG_TYPE_PRODUCTIVE);
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);/*from   w  ww  .  j a v  a2s.c  o m*/
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("Synchronization");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:com.photon.phresco.nativeapp.eshop.activity.ProductDetailActivity.java

/**
 * Create the details sections at the bottom of the screen dynamically
 *
 * @param details//from   ww  w .  j  a  v  a 2s  . c  o  m
 * @throws NumberFormatException
 */
private void renderProdcutDetails(Map<String, String> details) {

    try {
        LinearLayout tl = (LinearLayout) findViewById(R.id.product_details_layout);
        int totalDetails = details.size();
        int cnt = 1;
        PhrescoLogger.info(TAG + "renderProdcutDetails() - totalDetails : " + totalDetails);
        TextView lblDetailLabel = null;
        for (Entry<String, String> entry : details.entrySet()) {

            // Create a TextView to hold the label for product detail
            lblDetailLabel = new TextView(this);
            if (cnt == 1) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_top);
            } else if (cnt == totalDetails) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_bottom);
            } else {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_middle);
            }
            lblDetailLabel.setText(entry.getKey() + ": " + entry.getValue());
            lblDetailLabel.setGravity(Gravity.CENTER);
            lblDetailLabel.setTypeface(Typeface.DEFAULT, style.TextViewStyle);
            lblDetailLabel.setTextColor(Color.WHITE);
            lblDetailLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
            tl.addView(lblDetailLabel);
            cnt++;
        }
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "renderProdcutDetails - Exception : " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.mifos.mifosxdroid.online.generatecollectionsheet.GenerateCollectionSheetFragment.java

private void inflateCollectionTable(CollectionSheetResponse collectionSheetResponse) {
    //Clear old views in case they are present.
    if (tableProductive.getChildCount() > 0) {
        tableProductive.removeAllViews();
    }/*from  ww w .j av a 2 s .  c  om*/

    //A List to be used to inflate Attendance Spinners
    ArrayList<String> attendanceTypes = new ArrayList<>();
    attendanceTypeOptions.clear();
    attendanceTypeOptions = presenter.filterAttendanceTypes(collectionSheetResponse.getAttendanceTypeOptions(),
            attendanceTypes);

    additionalPaymentTypeMap.clear();
    additionalPaymentTypeMap = presenter.filterPaymentTypes(collectionSheetResponse.getPaymentTypeOptions(),
            paymentTypes);

    //Add the heading Row
    TableRow headingRow = new TableRow(getContext());
    TableRow.LayoutParams headingRowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    headingRowParams.gravity = Gravity.CENTER;
    headingRowParams.setMargins(0, 0, 0, 10);
    headingRow.setLayoutParams(headingRowParams);

    TextView tvGroupName = new TextView(getContext());
    tvGroupName.setText(collectionSheetResponse.getGroups().get(0).getGroupName());
    tvGroupName.setTypeface(tvGroupName.getTypeface(), Typeface.BOLD);
    tvGroupName.setGravity(Gravity.CENTER);
    headingRow.addView(tvGroupName);

    for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
        TextView tvProduct = new TextView(getContext());
        tvProduct.setText(getString(R.string.collection_loan_product, loanProduct.getName()));
        tvProduct.setTypeface(tvProduct.getTypeface(), Typeface.BOLD);
        tvProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvProduct);
    }

    for (SavingsProduct savingsProduct : collectionSheetResponse.getSavingsProducts()) {
        TextView tvSavingProduct = new TextView(getContext());
        tvSavingProduct.setText(getString(R.string.collection_saving_product, savingsProduct.getName()));
        tvSavingProduct.setTypeface(tvSavingProduct.getTypeface(), Typeface.BOLD);
        tvSavingProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvSavingProduct);
    }

    TextView tvAttendance = new TextView(getContext());
    tvAttendance.setText(getString(R.string.attendance));
    tvAttendance.setGravity(Gravity.CENTER);
    tvAttendance.setTypeface(tvAttendance.getTypeface(), Typeface.BOLD);
    headingRow.addView(tvAttendance);

    tableProductive.addView(headingRow);

    for (ClientCollectionSheet clientCollectionSheet : collectionSheetResponse.getGroups().get(0)
            .getClients()) {
        //Insert rows
        TableRow row = new TableRow(getContext());
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        rowParams.gravity = Gravity.CENTER;
        rowParams.setMargins(0, 0, 0, 10);
        row.setLayoutParams(rowParams);

        //Column 1: Client Name and Id
        TextView tvClientName = new TextView(getContext());
        tvClientName.setText(
                concatIdWithName(clientCollectionSheet.getClientName(), clientCollectionSheet.getClientId()));
        row.addView(tvClientName);

        //Subsequent columns: The Loan products
        for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
            //Since there may be several items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the loans in of this type and add in the container
            for (LoanCollectionSheet loan : clientCollectionSheet.getLoans()) {
                if (loanProduct.getName().equals(loan.getProductShortName())) {
                    //This loan should be shown in this column. So, add it in the container.
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the loan id as the Tag of the EditText
                    // in format 'TYPE:ID' which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_LOAN + ":" + loan.getLoanId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        //After Loans, show Savings columns
        for (SavingsProduct product : collectionSheetResponse.getSavingsProducts()) {
            //Since there may be several Savings items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the Savings in of this type and add in the container
            for (SavingsCollectionSheet saving : clientCollectionSheet.getSavings()) {
                if (saving.getProductId() == product.getId()) {
                    //Add the saving in the container
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the Saving id as the Tag of the EditText
                    // in 'TYPE:ID' format which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_SAVING + ":" + saving.getSavingsId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        Spinner spAttendance = new Spinner(getContext());
        //Set the clientId as its tag which will be used as identifier later.
        spAttendance.setTag(clientCollectionSheet.getClientId());
        setSpinner(spAttendance, attendanceTypes);
        row.addView(spAttendance);

        tableProductive.addView(row);
    }

    if (btnSubmitProductive.getVisibility() != View.VISIBLE) {
        //Show the button the first time sheet is loaded.
        btnSubmitProductive.setVisibility(View.VISIBLE);
        btnSubmitProductive.setOnClickListener(this);
    }

    //If this block has been executed, that means the CollectionSheet
    //which is already shown is for groups.
    btnSubmitProductive.setTag(TAG_TYPE_COLLECTION);

    if (tableAdditional.getVisibility() != View.VISIBLE) {
        tableAdditional.setVisibility(View.VISIBLE);
    }
    //Show Additional Views
    TableRow rowPayment = new TableRow(getContext());
    TextView tvLabelPayment = new TextView(getContext());
    tvLabelPayment.setText(getString(R.string.payment_type));
    rowPayment.addView(tvLabelPayment);
    Spinner spPayment = new Spinner(getContext());
    setSpinner(spPayment, paymentTypes);
    rowPayment.addView(spPayment);
    tableAdditional.addView(rowPayment);

    TableRow rowAccount = new TableRow(getContext());
    TextView tvLabelAccount = new TextView(getContext());
    tvLabelAccount.setText(getString(R.string.account_number));
    rowAccount.addView(tvLabelAccount);
    EditText etPayment = new EditText(getContext());
    rowAccount.addView(etPayment);
    tableAdditional.addView(rowAccount);

    TableRow rowCheck = new TableRow(getContext());
    TextView tvLabelCheck = new TextView(getContext());
    tvLabelCheck.setText(getString(R.string.cheque_number));
    rowCheck.addView(tvLabelCheck);
    EditText etCheck = new EditText(getContext());
    rowCheck.addView(etCheck);
    tableAdditional.addView(rowCheck);

    TableRow rowRouting = new TableRow(getContext());
    TextView tvLabelRouting = new TextView(getContext());
    tvLabelRouting.setText(getString(R.string.routing_code));
    rowRouting.addView(tvLabelRouting);
    EditText etRouting = new EditText(getContext());
    rowRouting.addView(etRouting);
    tableAdditional.addView(rowRouting);

    TableRow rowReceipt = new TableRow(getContext());
    TextView tvLabelReceipt = new TextView(getContext());
    tvLabelReceipt.setText(getString(R.string.receipt_number));
    rowReceipt.addView(tvLabelReceipt);
    EditText etReceipt = new EditText(getContext());
    rowReceipt.addView(etReceipt);
    tableAdditional.addView(rowReceipt);

    TableRow rowBank = new TableRow(getContext());
    TextView tvLabelBank = new TextView(getContext());
    tvLabelBank.setText(getString(R.string.bank_number));
    rowBank.addView(tvLabelBank);
    EditText etBank = new EditText(getContext());
    rowBank.addView(etBank);
    tableAdditional.addView(rowBank);
}

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

private void combineTrainAndPsnDetails() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();/*w w  w  .  j av  a2  s .co  m*/
        mFrameLayout.addView(mTextViewPNRSts);
        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);
        return;
    }
    //Combine both Train & Passenger details table into a single LinearLayout and add it to FrameLayout
    LinearLayout ll = new LinearLayout(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);
    textViewPsnDtls.setText("Passenger Details");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    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(mTableLayoutTrn);
    ll.addView(textViewPsnDtls);
    ll.addView(mTableLayoutPsn);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
    if (isWaitingList && !mPNRList.contains(mPNRNumber)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Track this PNR?");
        builder.setMessage("Would you like this PNR to be tracked for status change?");
        builder.setPositiveButton("Track", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //save the pnr
                pnrDB.addPNRToTrack(mPNRNumber);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("No thanks", null);
        builder.create().show();
    }

}

From source file:edu.cens.loci.ui.PlaceViewActivity.java

private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) {

    ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>();

    HashMap<String, APInfoMapItem> apMap = wifi.getAps();
    Set<String> keys = apMap.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext()) {
        String bssid = iter.next();
        APInfoMapItem ap = apMap.get(bssid);
        items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets));
    }//from  ww w.j  av  a  2 s .c o m

    Collections.sort(items);

    table.setColumnCollapsed(0, false);
    table.setColumnCollapsed(1, true);
    table.setColumnShrinkable(0, true);

    for (int i = 0; i < mAddedRows.size(); i++) {
        table.removeView(mAddedRows.get(i));
    }
    mAddedRows.clear();

    int totalCount = wifi.getScanCount();

    for (WifiViewListItem item : items) {
        TableRow row = new TableRow(this);

        TextView ssidView = new TextView(this);
        ssidView.setText(item.ssid);
        //ssidView.setText("very very very veryvery very very very very very");
        ssidView.setPadding(2, 2, 2, 2);
        ssidView.setTextColor(0xffffffff);

        TextView bssidView = new TextView(this);
        bssidView.setText(item.bssid);
        bssidView.setPadding(2, 2, 2, 2);
        bssidView.setTextColor(0xffffffff);

        TextView cntView = new TextView(this);
        cntView.setText("" + (item.count * 100) / totalCount);
        cntView.setPadding(2, 2, 2, 2);
        cntView.setGravity(Gravity.CENTER);
        cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        TextView rssView = new TextView(this);
        rssView.setText("" + item.rss);
        rssView.setPadding(2, 2, 6, 2);
        rssView.setGravity(Gravity.CENTER);
        rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        row.addView(ssidView, new TableRow.LayoutParams(0));
        row.addView(bssidView, new TableRow.LayoutParams(1));
        row.addView(cntView, new TableRow.LayoutParams(2));
        row.addView(rssView, new TableRow.LayoutParams(3));

        //Log.d(TAG, item.ssid);
        for (int i = 0; i < item.rssBuckets.length; i++) {
            TextView box = new TextView(this);
            box.setText("  ");
            box.setGravity(Gravity.RIGHT);
            box.setPadding(2, 2, 2, 2);
            box.setHeight(15);
            box.setGravity(Gravity.CENTER_VERTICAL);

            float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount());
            //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]);
            int colorValInt = ((int) colorVal) - 1;
            if (colorValInt < 0)
                colorValInt = 0;

            box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan));
            box.setTextColor(0xffffffff);

            row.addView(box, new TableRow.LayoutParams(4 + i));
        }

        row.setGravity(Gravity.CENTER);

        table.addView(row, new TableLayout.LayoutParams());
        table.setColumnStretchable(3, true);
        mAddedRows.add(row);
    }

}

From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java

private void displayArtistInfo_bk(JSONObject j) throws JSONException {
    if (imageLoader == null)
        imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited())
        imageLoader.init(config);/* w  w w  .  ja v a  2s.c o m*/

    Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString());

    JSONObject j_artist_info = j.getJSONObject("artist");

    tArtistName.setText(j_artist_info.getString("name"));
    final JSONObject urls = j_artist_info.optJSONObject("urls");
    final JSONArray videos = j_artist_info.optJSONArray("video");
    final JSONArray images = j_artist_info.optJSONArray("images");
    final String fm_image = j.optString("fm_image");
    final JSONArray available_images = new JSONArray();
    ArrayList<String> image_urls = new ArrayList<String>();

    if (fm_image != null) {
        image_urls.add(fm_image);
    }

    Log.i("musicInfo", images.toString());

    if (images != null) {
        for (int i = 0; i < images.length(); i++) {
            JSONObject image = images.getJSONObject(i);
            int width = image.optInt("width", 0);
            int height = image.optInt("height", 0);
            String url = image.optString("url", "");
            Log.i("musicInfo", i + ": " + url);
            if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) {
                //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) {
                image_urls.add(url);
                Log.i("musicInfo", "Selected: " + url);
                //available_images.put(image);
            }
        }

        int random = (int) (Math.random() * image_urls.size());
        final String f_url = image_urls.get(random);

        //int random = (int) (Math.random() * available_images.length());
        //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0);

        Log.i("musicInfo",
                "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url);

        imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String imageUri, View view) {

            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                lLinkList.removeAllViews();
                //String attr = fImage.optJSONObject("license").optString("attribution");
                //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr));
                if (urls != null) {
                    String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url",
                            "twitter_url" };
                    for (int i = 0; i < jsonName.length; i++) {
                        if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) {
                            Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i]));
                            TextView tv = new TextView(getApplicationContext());
                            tv.setTextSize(11);
                            tv.setPadding(16, 16, 16, 16);
                            tv.setTextColor(Color.LTGRAY);
                            tv.setTypeface(Typeface.SANS_SERIF);
                            tv.setGravity(Gravity.CENTER_VERTICAL);
                            tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));

                            switch (jsonName[i]) {
                            case "official_url":
                                tv.setText("HOME.");
                                break;
                            case "wikipedia_url":
                                tv.setText("WIKI.");
                                break;
                            case "mb_url":
                                tv.setText("Music Brainz.");
                                break;
                            case "lastfm_url":
                                tv.setText("Last FM.");
                                break;
                            case "twitter_url":
                                tv.setText("Twitter.");
                                break;
                            }

                            try {
                                tv.setTag(urls.getString(jsonName[i]));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                            tv.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent();
                                    intent.setAction(Intent.ACTION_VIEW);
                                    intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                    intent.setData(Uri.parse((String) v.getTag()));
                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(intent);
                                    Toast.makeText(getApplicationContext(), "Open the Link...",
                                            Toast.LENGTH_SHORT).show();
                                    //finish();
                                }
                            });
                            lLinkList.addView(tv);
                        }
                    }
                } else {
                    TextView tv = new TextView(getApplicationContext());
                    tv.setTextSize(11);
                    tv.setPadding(16, 16, 16, 16);
                    tv.setTextColor(Color.LTGRAY);
                    tv.setTypeface(Typeface.SANS_SERIF);
                    tv.setGravity(Gravity.CENTER_VERTICAL);
                    tv.setText("Sorry, No Link Here...");
                    lLinkList.addView(tv);
                }

                if (videos != null) {
                    jVideoArray = videos;
                    mAdapter = new StaggeredViewAdapter(getApplicationContext(),
                            android.R.layout.simple_list_item_1, generateImageData(videos));
                    //if (mData == null) {
                    mData = generateImageData(videos);
                    //}

                    //mAdapter.clear();

                    for (JSONObject data : mData) {
                        mAdapter.add(data);
                    }
                    mGridView.setAdapter(mAdapter);
                } else {

                }

                adjBottomColor(((ImageView) view).getDrawable());
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {

            }
        });
    }

}

From source file:com.fjn.magazinereturncandidate.activities.SdmScannerActivity.java

/**
 * Function show path file save CSV when not connect internet
 *///from w w  w .java 2 s  .c  o  m
private void showDialogInfoPathSaveCSV() {

    progress.show();
    android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(this);
    dialog.setMessage(Message.MESSAGE_INFO_PATH_CSV).setCancelable(false).setPositiveButton(MESSAGE_YES,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    progress.dismiss();
                }
            });
    android.support.v7.app.AlertDialog alert = dialog.show();
    TextView messageText = (TextView) alert.findViewById(android.R.id.message);
    assert messageText != null;
    messageText.setGravity(Gravity.CENTER);

}

From source file:com.fjn.magazinereturncandidate.activities.SdmScannerActivity.java

/**
 * Function show dialog when connect fail (not internet - retry)
 *//*from w w  w .  j  a v  a2  s.  c  o  m*/
private void showDialogConnectFailedWhenLogin() {

    progress.show();
    android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(this);
    dialog.setMessage(Message.MESSAGE_NETWORK_ERR).setCancelable(false)
            .setPositiveButton(MESSAGE_RETRY, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    connectSendDataWhenLogin();
                }
            }).setNegativeButton(MESSAGE_CANCEL, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    progress.dismiss();
                    //Enable scan
                    isEnableScan = true;
                    registerLicenseCommon.EnableOCROrJanCode(flagSwitchOCR, hsmDecoder);
                }
            });
    android.support.v7.app.AlertDialog alert = dialog.show();
    TextView messageText = (TextView) alert.findViewById(android.R.id.message);
    assert messageText != null;
    messageText.setGravity(Gravity.CENTER);
}