Example usage for android.widget TextView setVisibility

List of usage examples for android.widget TextView setVisibility

Introduction

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

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:gr.scify.newsum.ui.ViewActivity.java

@Override
public void run() {
    // take the String from the TopicActivity
    Bundle extras = getIntent().getExtras();
    Category = extras.getString(CATEGORY_INTENT_VAR);

    // Make sure we have updated the data source
    NewSumUiActivity.setDataSource(this);

    // Get user sources
    String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

    // get Topics from TopicActivity (avoid multiple server calls)
    TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this);

    // Also get Topic Titles, to display to adapter
    final String[] saTopicTitles = new String[tiTopics.length];
    // Also get Topic IDs
    final String[] saTopicIDs = new String[tiTopics.length];
    // Also get Dates, in order to show in summary title
    final String[] saTopicDates = new String[tiTopics.length];
    // DeHTML titles
    for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) {
        // update Titles Array
        saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString();
        // update IDs Array
        saTopicIDs[iCnt] = tiTopics[iCnt].getID();
        // update Date Array
        saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale());
    }/*from   w  ww  .  ja  va  2s.  c  o  m*/
    // get the value of the TopicIDs list size (to use in swipe)
    saTopicIDsLength = saTopicIDs.length;
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTopicTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // Get active topic
    int iTopicNum;
    // If we have returned from a pause
    if (iPrvSelectedItem >= 0)
        // use previous selection before pause
        iTopicNum = iPrvSelectedItem;
    // else
    else
        // use selection from topic page
        iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR);
    final int num = iTopicNum;

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setAdapter(adapter);

            // Scroll view init
            final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
            final String[] saTopicTitlesArg = saTopicTitles;
            final String[] saTopicIDsArg = saTopicIDs;
            final String[] SaTopicDatesArg = saTopicDates;

            // Add selection event
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    // Changing summary
                    loading = true;
                    showWaitingDialog();
                    // Update visibility of rating bar
                    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
                    rb.setRating(0.0f);
                    rb.setVisibility(View.VISIBLE);
                    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
                    rateLbl.setVisibility(View.VISIBLE);
                    scroll.scrollTo(0, 0);

                    String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

                    String[] saTopicIDs = saTopicIDsArg;

                    // track summary views per category and topic title
                    if (getAnalyticsPref()) {
                        EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category,
                                saTopicTitlesArg[arg2], 0l);
                    }

                    if (sCustomCategory.trim().length() > 0) {
                        if (Category.equals(sCustomCategory)) {
                            Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this);
                            String sCustomCategoryURL = ctxCur.getResources()
                                    .getString(R.string.custom_category_url);
                            // Check if specific element needs to be read
                            String sElementID = ctxCur.getResources()
                                    .getString(R.string.custom_category_elementId);
                            // If an element needs to be selected
                            if (sElementID.trim().length() > 0) {
                                try {
                                    // Check if specific element needs to be read
                                    String sViewOriginalPage = ctxCur.getResources()
                                            .getString(R.string.custom_category_visit_source);
                                    // Init text by a link to the original page
                                    sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage
                                            + "</a></p>";
                                    // Get document
                                    Document doc = Jsoup.connect(sCustomCategoryURL).get();
                                    // If a table
                                    Element eCur = doc.getElementById(sElementID);
                                    if (eCur.tagName().equalsIgnoreCase("table")) {
                                        // Get table rows
                                        Elements eRows = eCur.select("tr");

                                        // For each row
                                        StringBuffer sTextBuf = new StringBuffer();
                                        for (Element eCurRow : eRows) {
                                            // Append content
                                            // TODO: Use HTML if possible. Now problematic (crashes when we click on link)
                                            sTextBuf.append("<p>" + eCurRow.text() + "</p>");
                                        }
                                        // Return as string
                                        sText = sText + sTextBuf.toString();
                                    } else
                                        // else get text
                                        sText = eCur.text();

                                } catch (IOException e) {
                                    // Show unavailable text
                                    sText = ctxCur.getResources()
                                            .getString(R.string.custom_category_unavailable);
                                    e.printStackTrace();
                                }

                            } else
                                sText = Utils.getFromHttp(sCustomCategoryURL, false);
                        }

                    } else {
                        // call getSummary with (sTopicID, sUserSources). Use "All" for
                        // all Sources
                        String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
                        // check if Summary exists, otherwise display message
                        if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT
                            // WORK. Updated: Probably OK
                            nothingFound = true;
                            AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this);
                            al.setMessage(R.string.shouldReloadSummaries);
                            al.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface arg0, int arg1) {
                                    // Reset cache
                                    CacheController.clearCache();
                                    // Restart main activity
                                    startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                                }
                            });
                            al.setCancelable(false);
                            al.show();
                            // Return to home activity
                            loading = false;
                            return;
                        }
                        // Generate Summary text for normal categories
                        sText = generateSummaryText(Summary, ViewActivity.this);
                        pText = generatesummarypost(Summary, ViewActivity.this);
                    }

                    // Update HTML
                    tx.setText(Html.fromHtml(sText));
                    // Allow links to be followed into browser
                    tx.setMovementMethod(LinkMovementMethod.getInstance());
                    // Also Add Date to Topic Title inside Summary
                    title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]);

                    // Update size
                    updateTextSize();

                    // Update visited topics
                    TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);
                    // Done
                    loading = false;
                    closeWaitingDialog();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                }

            });

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Get active topic
                    spinner.setSelection(num);
                }
            });

        }
    });

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    });

    closeWaitingDialog();
}

From source file:com.openerp.addons.messages.Message.java

private List<OEListViewRows> getMessages(TYPE type) {
    String[] where = null;/* w  w w .  j  a v a 2s  .com*/
    String[] whereArgs = null;
    current_type = type;
    switch (type) {
    case INBOX:
        where = new String[] { "to_read = ?", "AND", "starred  = ?" };
        whereArgs = new String[] { "true", "false" };
        message_resource = R.string.message_inbox_all_read;
        break;
    case TOME:
        where = new String[] { "res_id = ? ", "AND", "to_read= ?", };
        whereArgs = new String[] { "0", "true" };
        message_resource = R.string.message_tome_all_read;
        break;
    case TODO:
        where = new String[] { "starred  = ? ", "AND", "to_read = ?" };
        whereArgs = new String[] { "true", "true" };
        message_resource = R.string.message_todo_all_read;
        break;
    case GROUP:
        where = new String[] { "res_id  = ? ", "AND", "model = ?" };
        whereArgs = new String[] { group_id, "mail.group" };
        message_resource = R.string.message_no_group_message;
        break;
    default:
        break;
    }

    // Fetching parent ids from Child row with order by date desc
    HashMap<String, Object> result = db.search(db, from, where, whereArgs, null, null, "date", "DESC");
    HashMap<String, OEListViewRows> parent_list_details = new HashMap<String, OEListViewRows>();
    messages_sorted = new ArrayList<OEListViewRows>();
    if (Integer.parseInt(result.get("total").toString()) > 0) {
        scope.context().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                try {
                    rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE);
                } catch (Exception e) {
                }
            }
        });

        int i = 0;
        for (HashMap<String, Object> row : (List<HashMap<String, Object>>) result.get("records")) {

            boolean isParent = true;
            String key = row.get("parent_id").toString();
            if (key.equals("false")) {
                key = row.get("id").toString();
            } else {
                isParent = false;
            }
            if (!parent_list_details.containsKey(key)) {
                // Fetching row parent message
                HashMap<String, Object> newRow = null;
                OEListViewRows newRowObj = null;

                if (isParent) {

                    newRow = row;
                    newRow.put("subject",
                            updateSubject(newRow.get("subject").toString(), Integer.parseInt(key)));
                    newRowObj = new OEListViewRows(Integer.parseInt(key), (HashMap<String, Object>) newRow);

                } else {
                    newRow = db.search(db, from, new String[] { "id = ?" }, new String[] { key });
                    HashMap<String, Object> temp_row = new HashMap<String, Object>();
                    try {
                        temp_row = ((List<HashMap<String, Object>>) newRow.get("records")).get(0);
                        temp_row.put("subject",
                                updateSubject(temp_row.get("subject").toString(), Integer.parseInt(key)));
                        newRowObj = new OEListViewRows(Integer.parseInt(key), temp_row);
                    } catch (Exception e) {
                    }

                }

                parent_list_details.put(key, newRowObj);
                message_row_indexes.put(key, i);
                i++;
                messages_sorted.add(newRowObj);

            }
        }

    } else {
        if (db.isEmptyTable(db) && !isSynced) {
            isSynced = true;
            scope.context().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (rootView.findViewById(R.id.messageSyncWaiter) != null) {
                        rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.VISIBLE);
                    }
                }
            });

            try {
                Thread.sleep(2000);
                if (group_id != null) {
                    Bundle group_bundle = new Bundle();
                    JSONArray ids = new JSONArray();
                    ids.put(group_id);
                    group_bundle.putString("group_ids", ids.toString());
                    scope.context().requestSync(MessageProvider.AUTHORITY, group_bundle);
                } else {
                    scope.context().requestSync(MessageProvider.AUTHORITY);
                }
            } catch (Exception e) {
            }
        } else {
            scope.context().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE);
                    rootView.findViewById(R.id.lstMessages).setVisibility(View.GONE);
                    TextView txvMsg = (TextView) rootView.findViewById(R.id.txvMessageAllReadMessage);
                    txvMsg.setVisibility(View.VISIBLE);
                    txvMsg.setText(message_resource);
                }
            });

        }

    }
    return messages_sorted;
}

From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java

private void updateTimeBasedUi() {
    long currentTimeMillis = UIUtils.getCurrentTime(this);
    boolean canShowLivestream = mHasLivestream;

    if (canShowLivestream && !mDismissedWatchLivestreamCard && currentTimeMillis > mSessionStart
            && currentTimeMillis <= mSessionEnd) {
        // show the "watch now" card
        showWatchNowCard();//  w w w . j  av  a  2 s . c  o m
    } else if (!mAlreadyGaveFeedback && mInitStarred
            && currentTimeMillis >= (mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END)
            && !sDismissedFeedbackCard.contains(mSessionId)) {
        // show the "give feedback" card
        showGiveFeedbackCard();
    }

    String timeHint = "";
    long countdownMillis = mSessionStart - currentTimeMillis;

    if (TimeUtils.hasConferenceEnded(this)) {
        // no time hint to display
        timeHint = "";
    } else if (currentTimeMillis >= mSessionEnd) {
        timeHint = getString(R.string.time_hint_session_ended);
    } else if (currentTimeMillis >= mSessionStart) {
        long minutesAgo = (currentTimeMillis - mSessionStart) / 60000;
        if (minutesAgo > 1) {
            timeHint = getString(R.string.time_hint_started_min, minutesAgo);
        } else {
            timeHint = getString(R.string.time_hint_started_just);
        }
    } else if (countdownMillis > 0 && countdownMillis < Config.HINT_TIME_BEFORE_SESSION) {
        long millisUntil = mSessionStart - currentTimeMillis;
        long minutesUntil = millisUntil / 60000 + (millisUntil % 1000 > 0 ? 1 : 0);
        if (minutesUntil > 1) {
            timeHint = getString(R.string.time_hint_about_to_start_min, minutesUntil);
        } else {
            timeHint = getString(R.string.time_hint_about_to_start_shortly, minutesUntil);
        }
    }

    final TextView timeHintView = (TextView) findViewById(R.id.time_hint);

    if (!TextUtils.isEmpty(timeHint)) {
        timeHintView.setVisibility(View.VISIBLE);
        timeHintView.setText(timeHint);
    } else {
        timeHintView.setVisibility(View.GONE);
    }
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * /*from   w w  w . ja v  a  2 s.  c  o m*/
 * @param vg
 * @param inflater
 * @return
 */
public View instantiateMapView(final ViewGroup vg, final LayoutInflater inflater) {
    //final ResultMapView view = new ResultMapView(activity.getApplicationContext(), activity, testUuid, testResult, inflater);
    //final View view = inflater.inflate(R.layout.result_map, this);
    final View view = inflater.inflate(R.layout.result_map, vg, false);
    //final View view = inflater.inflate(R.layout.result_map, null);

    TextView locationView = (TextView) view.findViewById(R.id.result_map_location);
    TextView locationProviderView = (TextView) view.findViewById(R.id.result_map_location_provider);
    TextView motionView = (TextView) view.findViewById(R.id.result_map_motion);

    TextView notAvailableView = (TextView) view.findViewById(R.id.result_mini_map_not_available);
    MapView miniMapView = (MapView) view.findViewById(R.id.result_mini_map_view);
    Button overlayButton = (Button) view.findViewById(R.id.result_mini_map_view_button);

    try {
        System.out.println(testResult.toString());
        JSONObject testResultItem = testResult.getJSONObject(0);

        if (testResultItem.has("geo_lat") && testResultItem.has("geo_long")) {
            notAvailableView.setVisibility(View.GONE);
            miniMapView.setVisibility(View.VISIBLE);
            overlayButton.setVisibility(View.VISIBLE);

            if (dataChangedListener != null) {
                dataChangedListener.onChange(false, true, "HAS_MAP");
            }

            final double geoLat = testResultItem.getDouble("geo_lat");
            final double geoLong = testResultItem.getDouble("geo_long");
            final int networkType = testResultItem.getInt("network_type");
            mapType = Helperfunctions.getMapType(networkType) + "/download";

            if (testResultItem.has("motion")) {
                motionView.setText(testResultItem.getString("motion"));
                motionView.setVisibility(View.VISIBLE);
            }
            if (testResultItem.has("location")) {
                String loc = testResultItem.getString("location");
                int i = -1;
                if (loc != null) {
                    if ((i = loc.indexOf("(")) >= 0) {
                        locationView.setText(loc.substring(0, i - 1).trim());
                        locationProviderView.setText(loc.substring(i).trim());
                        locationProviderView.setVisibility(View.VISIBLE);
                    } else {
                        locationView.setText(loc);
                    }
                    locationView.setVisibility(View.VISIBLE);
                }
            }

            testPoint = new LatLng(geoLat, geoLong);

            if (miniMapView != null) {

                try {
                    MapsInitializer.initialize(activity);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                miniMapView.onCreate(null);
                miniMapView.onResume();
                miniMapView.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(testPoint, 16));
                miniMapView.getMap().addMarker(new MarkerOptions().position(testPoint));

                final UiSettings uiSettings = miniMapView.getMap().getUiSettings();
                uiSettings.setZoomControlsEnabled(false); // options.isEnableAllGestures());
                uiSettings.setMyLocationButtonEnabled(false);
                uiSettings.setCompassEnabled(false);
                uiSettings.setRotateGesturesEnabled(false);
                uiSettings.setScrollGesturesEnabled(false);
                uiSettings.setZoomGesturesEnabled(false);
                uiSettings.setAllGesturesEnabled(false);

                miniMapView.getMap().setTrafficEnabled(false);
                miniMapView.getMap().setIndoorEnabled(false);

                miniMapView.getMap().addMarker(new MarkerOptions().position(testPoint).draggable(false)
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

                miniMapView.getMap().setMapType(activity.getMapTypeSatellite() ? GoogleMap.MAP_TYPE_SATELLITE
                        : GoogleMap.MAP_TYPE_NORMAL);

                miniMapView.getMap().setOnMapClickListener(new OnMapClickListener() {
                    @Override
                    public void onMapClick(LatLng arg0) {
                        final Runnable runnable = new Runnable() {
                            @Override
                            public void run() {
                                activity.showMap(mapType, testPoint, true, false);
                            }
                        };

                        runnable.run();
                    }
                });
            }

            if (overlayButton != null) {
                overlayButton.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        activity.showMap(mapType, testPoint, true, false);
                    }
                });

                overlayButton.bringToFront();
            }

            Log.d("ResultMapView", "TESTRESULT OK. Drawing MapView");
        } else {
            notAvailableView.setVisibility(View.VISIBLE);
            miniMapView.setVisibility(View.GONE);
            overlayButton.setVisibility(View.GONE);

            if (dataChangedListener != null) {
                dataChangedListener.onChange(true, false, "HAS_MAP");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return view;
}

From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void populateHeader() {
    View headerView = findViewById(R.id.video_header);
    Log.d(LOG_TAG, "populateHeader: header is " + (headerView == null ? "null" : "not null"));
    if (video != null && headerView != null) {
        ((TextView) headerView.findViewById(R.id.video_title)).setText(video.getTitle());
        String desc = video.getDescription();
        TextView descView = (TextView) headerView.findViewById(R.id.video_description);
        if (desc != null && desc.length() > 0) {
            descView.setText(desc);/*from www  . ja  v a2 s. c  o m*/
            descView.setVisibility(View.VISIBLE);
            descView.setMovementMethod(new ScrollingMovementMethod());
        } else {
            descView.setVisibility(View.GONE);
        }
    }
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

private void showMemoryNotAvailable(boolean show, String text) {
    TextView view = (TextView) mRootView.findViewById(R.id.memory_not_available_page);
    if (view != null) {
        if (show) {
            showEmptyView(false);/*from  w  ww.  j  a  va 2 s.c  o m*/
            view.setText(text);
            view.setVisibility(View.VISIBLE);
        } else {
            view.setVisibility(View.GONE);
        }
    }
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void togglePlayOptionsVisible(PlayOptions option) {
    findViewById(R.id.my_turn_buttons).setVisibility(option == PlayOptions.play ? View.VISIBLE : View.GONE);

    TextView message = (TextView) findViewById(R.id.player_message);
    message.setVisibility(View.GONE);
    if (option == PlayOptions.turnMessage) {
        if (mTurnData != null)
            message.setText(mIdToName.get(mTurnData.state.currentPlayerId) + "'s turn");
        message.setVisibility(View.VISIBLE);
    } else if (option == PlayOptions.choosePlayer) {
        message.setText("Choose a player.");
        message.setVisibility(View.VISIBLE);
    } else if (option == PlayOptions.chooseCard) {
        message.setText("Choose a card from your hand.");
        message.setVisibility(View.VISIBLE);
    }//from   w  w w. j  a va 2s. c  o m

    LinearLayout chooseAttribute = (LinearLayout) findViewById(R.id.chooseAttribute);
    chooseAttribute.setVisibility(option == PlayOptions.chooseAttribute ? View.VISIBLE : View.GONE);
}

From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java

private void updateTimeBasedUi() {
    final Context context = mRootView.getContext();
    long currentTimeMillis = UIUtils.getCurrentTime(context);
    boolean canShowLivestream = mHasLivestream;

    if (canShowLivestream && !mDismissedWatchLivestreamCard && currentTimeMillis > mSessionStart
            && currentTimeMillis <= mSessionEnd) {
        // show the "watch now" card
        showWatchNowCard();/*  w w  w .j ava2  s.co m*/
    } else if (!mAlreadyGaveFeedback && mInitStarred
            && currentTimeMillis >= (mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END)
            && !sDismissedFeedbackCard.contains(mSessionId)) {
        // show the "give feedback" card
        showGiveFeedbackCard();
    }

    String timeHint = "";
    long countdownMillis = mSessionStart - currentTimeMillis;

    if (TimeUtils.hasConferenceEnded(context)) {
        // no time hint to display
        timeHint = "";
    } else if (currentTimeMillis >= mSessionEnd) {
        timeHint = context.getString(R.string.time_hint_session_ended);
    } else if (currentTimeMillis >= mSessionStart) {
        long minutesAgo = (currentTimeMillis - mSessionStart) / 60000;
        if (minutesAgo > 1) {
            timeHint = context.getString(R.string.time_hint_started_min, minutesAgo);
        } else {
            timeHint = context.getString(R.string.time_hint_started_just);
        }
    } else if (countdownMillis > 0 && countdownMillis < Config.HINT_TIME_BEFORE_SESSION) {
        long millisUntil = mSessionStart - currentTimeMillis;
        long minutesUntil = millisUntil / 60000 + (millisUntil % 1000 > 0 ? 1 : 0);
        if (minutesUntil > 1) {
            timeHint = context.getString(R.string.time_hint_about_to_start_min, minutesUntil);
        } else {
            timeHint = context.getString(R.string.time_hint_about_to_start_shortly, minutesUntil);
        }
    }

    final TextView timeHintView = (TextView) mRootView.findViewById(R.id.time_hint);

    if (!TextUtils.isEmpty(timeHint)) {
        timeHintView.setVisibility(View.VISIBLE);
        timeHintView.setText(timeHint);
    } else {
        timeHintView.setVisibility(View.GONE);
    }
}

From source file:com.hybris.mobile.app.commerce.view.CartViewUtils.java

/**
 * Populate the cart summary/* w  ww  .  jav a 2  s .  co m*/
 *
 * @param cart
 */
public static void createCartSummary(View view, Cart cart, boolean enableItems) {

    // Cart summary
    LinearLayout mCartSummaryItemsLayout;
    TextView mCartSummaryItems;
    TextView mCartSummarySubtotal;
    TextView mCartSummarySavings;
    TextView mCartSummaryTax;
    TextView mCartSummaryShipping;
    TextView mCartSummaryTotal;
    TextView mCartSummaryPromotion;
    TableRow mCartSummarySavingsRow;
    TableRow mCartSummaryTaxRow;
    TextView mCartSummaryNoTax;
    TableRow mCartSummaryShippingRow;
    TextView mCartSummaryEmpty;
    LinearLayout mCartSummaryDetailsLayout;

    // cart summary
    mCartSummaryItemsLayout = (LinearLayout) view.findViewById(R.id.cart_summary_items_layout);
    mCartSummaryItems = (TextView) view.findViewById(R.id.cart_summary_items);
    mCartSummarySubtotal = (TextView) view.findViewById(R.id.cart_summary_subtotal);
    mCartSummarySavings = (TextView) view.findViewById(R.id.cart_summary_savings);
    mCartSummaryTax = (TextView) view.findViewById(R.id.cart_summary_tax);
    mCartSummaryShipping = (TextView) view.findViewById(R.id.cart_summary_shipping);
    mCartSummaryTotal = (TextView) view.findViewById(R.id.cart_summary_total);
    mCartSummaryPromotion = (TextView) view.findViewById(R.id.cart_summary_promotion);
    mCartSummarySavingsRow = (TableRow) view.findViewById(R.id.cart_summary_savings_row);
    mCartSummaryTaxRow = (TableRow) view.findViewById(R.id.cart_summary_tax_row);
    mCartSummaryNoTax = (TextView) view.findViewById(R.id.cart_summary_no_taxes);
    mCartSummaryShippingRow = (TableRow) view.findViewById(R.id.cart_summary_shipping_row);
    mCartSummaryEmpty = (TextView) view.findViewById(R.id.cart_summary_empty);
    mCartSummaryDetailsLayout = (LinearLayout) view.findViewById(R.id.cart_summary_details_layout);

    if (cart != null) {
        if (cart.getEntries() != null && !cart.getEntries().isEmpty()) {
            // Display total price
            if (cart.getTotalPrice() != null) {
                mCartSummaryTotal.setText(cart.getTotalPrice().getFormattedValue());
            }

            // Display subtotal price
            if (cart.getSubTotal() != null) {
                mCartSummarySubtotal.setText(cart.getSubTotal().getFormattedValue());
            }

            // Display tax price
            if (cart.getTotalTax() != null && cart.getTotalTax().getValue().intValue() > 0) {
                mCartSummaryTax.setText(cart.getTotalTax().getFormattedValue());
                mCartSummaryTaxRow.setVisibility(View.VISIBLE);
                mCartSummaryNoTax.setVisibility(View.GONE);
            } else {
                mCartSummaryTaxRow.setVisibility(View.GONE);
                mCartSummaryNoTax.setVisibility(View.VISIBLE);
            }

            // Display delivery method cost
            if (cart.getDeliveryCost() != null) {
                mCartSummaryShipping.setText(cart.getDeliveryCost().getFormattedValue());
                mCartSummaryShippingRow.setVisibility(View.VISIBLE);
            } else {
                mCartSummaryShippingRow.setVisibility(View.GONE);
            }

            if (cart.getAppliedOrderPromotions() != null && !cart.getAppliedOrderPromotions().isEmpty()) {
                if (StringUtils.isNotBlank(cart.getOrderDiscounts().getFormattedValue())) {
                    mCartSummarySavingsRow.setVisibility(View.VISIBLE);
                    mCartSummarySavings.setText(cart.getOrderDiscounts().getFormattedValue());
                }
            }

            if (cart.getTotalDiscounts() != null && cart.getTotalDiscounts().getValue().doubleValue() > 0) {
                if (cart.getAppliedOrderPromotions() != null && !cart.getAppliedOrderPromotions().isEmpty()) {
                    mCartSummaryPromotion.setVisibility(View.VISIBLE);
                    // Nb order Promotion
                    StringBuffer promotion = new StringBuffer();
                    for (PromotionResult orderPromotion : cart.getAppliedOrderPromotions()) {
                        promotion.append(orderPromotion.getDescription()).append("\n");
                    }
                    mCartSummaryPromotion.setText(promotion);
                } else {
                    mCartSummaryPromotion.setVisibility(View.GONE);
                }
            } else {
                mCartSummaryPromotion.setVisibility(View.GONE);
                mCartSummarySavingsRow.setVisibility(View.GONE);
            }

            // Nb items
            mCartSummaryItemsLayout.setVisibility(enableItems ? View.VISIBLE : View.GONE);
            mCartSummaryItems.setText(CommerceApplication.getContext().getString(R.string.cart_summary_items,
                    cart.getTotalUnitCount()));

            //Cart is used
            mCartSummaryEmpty.setVisibility(View.GONE);
            mCartSummaryDetailsLayout.setVisibility(View.VISIBLE);
        } else {
            //Cart Empty show messages & Cart Empty remove all summary views
            mCartSummaryEmpty.setVisibility(View.VISIBLE);
            mCartSummaryDetailsLayout.setVisibility(View.GONE);
            mCartSummaryPromotion.setVisibility(View.GONE);

        }
    }
}

From source file:dentex.youtube.downloader.DashboardActivity.java

public static void showEmptyListInfo(Activity activity) {
    TextView info = (TextView) activity.findViewById(R.id.dashboard_activity_info);
    info.setVisibility(View.VISIBLE);
    //Utils.logger("v", "__dashboard is empty__", DEBUG_TAG);
}