Example usage for android.view ViewGroup removeAllViews

List of usage examples for android.view ViewGroup removeAllViews

Introduction

In this page you can find the example usage for android.view ViewGroup removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:lewa.support.v7.app.ActionBarActivityDelegateBase.java

@Override
public void setContentView(View v, ViewGroup.LayoutParams lp) {
    ensureSubDecor();//w w w.j a v a2s.  c om
    if (mHasActionBar) {
        ViewGroup contentParent = (ViewGroup) mActivity.findViewById(android.R.id.content);
        contentParent.removeAllViews();
        contentParent.addView(v, lp);
    } else {
        mActivity.superSetContentView(v, lp);
    }
    mActivity.onSupportContentChanged();
}

From source file:net.sf.aria2.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean offerUpNav;

    // at some point after API 11 framework begins to throw, when you use old style..
    if (Build.VERSION.SDK_INT < HONEYCOMB) {
        initLegacyPrefs();//from   ww w .jav  a  2s .  c o m
        offerUpNav = false;
    } else
        offerUpNav = isOfferingUpNav();

    final LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.activity_prefs, null);

    // transplant content view children (created for us by framework)
    final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    final int contentChildrenCount = root.getChildCount();
    final List<View> childViews = new ArrayList<>(contentChildrenCount);

    for (int i = 0; i < contentChildrenCount; ++i)
        childViews.add(root.getChildAt(i));

    root.removeAllViews();

    for (View childView : childViews)
        toolbarContainer.addView(childView);

    root.addView(toolbarContainer);

    // initialize toolbar
    final Toolbar toolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);
    toolbar.setTitle(getTitle());

    if (offerUpNav) {
        toolbar.setLogo(null);
        toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        toolbar.setNavigationOnClickListener(v -> goUp());
    } else {
        toolbar.setNavigationIcon(null);
        toolbar.setLogo(R.drawable.aria2_logo);
    }
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

private void updateAnomalies(Audit audit) {

    ViewGroup anomalyContainerView = (ViewGroup) findViewById(com.orange.ocara.R.id.anomaly_container);
    anomalyContainerView.removeAllViews();

    for (AuditObject auditObject : audit.getObjects()) {
        final List<Comment> comments = auditObject.getComments();
        final String auditObjectName = auditObject.getName();
        final Uri auditObjectIcon = Uri.parse(auditObject.getObjectDescription().getIcon().toString());
        if (auditObject.getResponse().equals(Response.NOK) || !auditObject.getComments().isEmpty()) {
            final AuditObjectAnomalyView auditObjectAnomalyView = AuditObjectAnomalyView_
                    .build(getApplicationContext());
            auditObjectAnomalyView.setOnGroupClickListener(new AuditObjectAnomalyView.OnGroupClickListener() {
                @Override//from ww  w  .  j  ava2s.c  om
                public void onExpand(AuditObjectAnomalyView view) {
                    scrollTo(view);
                }
            });

            auditObjectAnomalyView
                    .setOnCommentClickListener(new AuditObjectAnomalyView.OnCommentClickListener() {
                        @Override
                        public void onCommentClick(Comment comment, View CommentView) {
                            ResultAuditActivity.this.onCommentClicked(auditObjectIcon, auditObjectName,
                                    comments, comment, CommentView);
                        }
                    });
            auditObjectAnomalyView.bind(auditObject);
            anomalyContainerView.addView(auditObjectAnomalyView);
        }
    }

    anomalyLayout.setVisibility(anomalyContainerView.getChildCount() > 0 ? View.VISIBLE : View.GONE);
}

From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java

/**
 * creates a grid of textViews from layout files based on the gridSize
 *  and sets the new textViews to use the controller as their listener
 * /*from w  ww  .  ja  v a  2 s  . com*/
 * @param gridSize square size of the new grid to make
 * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid
 */
public void setupViewGrid() {
    control.setLetter(null);
    int gridSize = control.getGridSize();
    TextViewGridController controller = control.getGridManager();
    ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable);
    if (gridTable.getChildCount() != gridSize) {
        if (gridTable.getChildCount() == 0) {
            gridTable.setKeepScreenOn(true);
            gridTable.setOnTouchListener(controller);
        }
        controller.clearPointDemension();
        gridTable.removeAllViews();
        Point point = new Point();
        controller.setGridView(new TextView[gridSize][]);
        TextView[][] gridView = controller.getGridView();
        for (point.y = 0; point.y < gridSize; point.y++) {
            this.getLayoutInflater().inflate(R.layout.grid_row, gridTable, true);
            ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y);
            TextView[] rowText = new TextView[gridSize];
            for (point.x = 0; point.x < gridSize; point.x++) {
                this.getLayoutInflater().inflate(R.layout.grid_text_view, row, true);
                TextView view = (TextView) row.getChildAt(point.x);
                view.setId(ConversionUtil.convertPointToID(point, control.getGridSize()));
                view.setOnKeyListener(controller);

                rowText[point.x] = view;
            }
            gridView[point.y] = rowText;
        }
        gridTable.requestLayout();
    }
}

From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java

/**
 * creates a grid of textViews from layout files based on the gridSize
 *  and sets the new textViews to use the controller as their listener
 * //from   w w w  .  j a  v a  2s.  c  o  m
 * @param gridSize square size of the new grid to make
 * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid
 */
public void setupViewGrid() {
    control.setLetter(null);
    int gridSize = control.getGridSize();
    TextViewGridController controller = control.getGridManager();
    ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable);
    if (gridTable.getChildCount() != gridSize) {
        if (gridTable.getChildCount() == 0) {
            gridTable.setKeepScreenOn(true);
            gridTable.setOnTouchListener(controller);
        }
        controller.clearPointDemension();
        gridTable.removeAllViews();
        Point point = new Point();
        controller.setGridView(new TextView[gridSize][]);
        TextView[][] gridView = controller.getGridView();
        for (point.y = 0; point.y < gridSize; point.y++) {
            this.getLayoutInflater().inflate(R.layout.ws_grid_row, gridTable, true);
            ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y);
            TextView[] rowText = new TextView[gridSize];
            for (point.x = 0; point.x < gridSize; point.x++) {
                this.getLayoutInflater().inflate(R.layout.ws_grid_text_view, row, true);
                TextView view = (TextView) row.getChildAt(point.x);
                view.setId(ConversionUtil.convertPointToID(point, control.getGridSize()));
                view.setOnKeyListener(controller);

                rowText[point.x] = view;
            }
            gridView[point.y] = rowText;
        }
        gridTable.requestLayout();
    }
}

From source file:com.cw.litenote.note.Note.java

@Override
public void finish() {
    System.out.println("Note / _finish");
    if (mPagerHandler != null)
        mPagerHandler.removeCallbacks(mOnBackPressedRun);

    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.setBackgroundColor(getResources().getColor(color.background_dark)); // avoid white flash
    view.removeAllViews();

    super.finish();
}

From source file:cz.muni.fi.japanesedictionary.fragments.DisplayTranslation.java

/**
 * Updates Fragment view acording to saved translation.
 *///from  ww  w.  j  a v a2s  .  c  om
public void updateTranslation(View view) {
    Log.i(LOG_TAG, " Update translation");
    if (getActivity() == null || view == null) {
        return;
    }

    TextView layoutSelect = (TextView) view.findViewById(R.id.translation_select);
    LinearLayout layoutTranslation = (LinearLayout) view.findViewById(R.id.translation_container);
    if (mTranslation == null) {
        layoutSelect.setVisibility(View.VISIBLE);
        layoutTranslation.setVisibility(View.GONE);
        return;
    }
    Log.i(LOG_TAG, " Ruby: " + mTranslation.getRuby());
    layoutSelect.setVisibility(View.GONE);
    layoutTranslation.setVisibility(View.VISIBLE);

    updateLanguages();

    LinearLayout readWriteContainer = (LinearLayout) view
            .findViewById(R.id.translation_reading_writing_container);
    readWriteContainer.removeAllViews();
    //Ruby: ,?;?;?;,??;

    String writeCharacters = null;

    StringBuilder alternativeStrBuilder = new StringBuilder();
    if (mTranslation.getRuby() != null) {
        String ruby = mTranslation.getRuby();
        String[] pairs = ruby.split(";");
        for (String pair : pairs) {
            View viewReading = mInflater.inflate(R.layout.display_translation_reading_group, readWriteContainer,
                    false);
            String[] parts = pair.split(",");
            TextView writing = (TextView) viewReading.findViewById(R.id.translation_write);
            writing.setText(parts[0]);
            if (parts.length == 2) {
                TextView reading = (TextView) viewReading.findViewById(R.id.translation_read);
                reading.setText(parts[1]);
            }
            readWriteContainer.addView(viewReading);
        }
    } else {
        View viewReading = mInflater.inflate(R.layout.display_translation_reading_group, readWriteContainer,
                false);
        TextView write = (TextView) viewReading.findViewById(R.id.translation_write);
        TextView read = (TextView) viewReading.findViewById(R.id.translation_read);
        if (mTranslation.getJapaneseKeb() != null && mTranslation.getJapaneseKeb().size() > 0) {
            writeCharacters = mTranslation.getJapaneseKeb().get(0);
            write.setText(writeCharacters);
        } else {
            write.setVisibility(View.GONE);
        }

        if (mTranslation.getJapaneseReb() != null) {
            String reading = mTranslation.getJapaneseReb().get(0);
            read.setText(reading);
            ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(reading);
        } else {
            read.setVisibility(View.GONE);
        }
        readWriteContainer.addView(viewReading);
    }

    if (mTranslation.getJapaneseReb() != null) {
        String reading = mTranslation.getJapaneseReb().get(0);
        ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(reading);
        DBAsyncTask saveTranslation = new DBAsyncTask(mCallbackTranslation.getDatabase());
        saveTranslation.execute(mTranslation);

        TextView romaji = (TextView) view.findViewById(R.id.translation_romaji);
        romaji.setText(RomanizationEnum.Hepburn.toRomaji(reading));

        int sizeReb = mTranslation.getJapaneseReb().size();
        if (sizeReb > 1) {
            for (int i = 1; i < sizeReb; i++) {
                alternativeStrBuilder.append(mTranslation.getJapaneseReb().get(i));
                if (i + 1 < sizeReb) {
                    alternativeStrBuilder.append(", ");
                }
            }
        }
    }
    if (mTranslation.getJapaneseKeb() != null) {
        writeCharacters = mTranslation.getJapaneseKeb().get(0);
        int size_keb = mTranslation.getJapaneseKeb().size();
        if (size_keb > 1) {
            if (alternativeStrBuilder.length() > 0) {
                alternativeStrBuilder.append(", ");
            }
            for (int i = 1; i < size_keb; i++) {
                alternativeStrBuilder.append(mTranslation.getJapaneseKeb().get(i));
                if (i + 1 < size_keb) {
                    alternativeStrBuilder.append(", ");
                }
            }
        }
    }

    TextView alternative = (TextView) view.findViewById(R.id.translation_alternative);
    if (alternativeStrBuilder.length() > 0) {
        alternative.setText(alternativeStrBuilder);
        view.findViewById(R.id.translation_alternative_container).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.translation_alternative_container).setVisibility(View.GONE);
    }

    if (mInflater != null) {
        LinearLayout translationsContainer = (LinearLayout) getView()
                .findViewById(R.id.translation_translation_container);
        translationsContainer.removeAllViews();
        if ((mEnglish || (!mFrench && !mDutch && !mGerman && !mRussian))
                && mTranslation.getEnglishSense() != null && mTranslation.getEnglishSense().size() > 0) {
            View translationLanguage = mInflater.inflate(R.layout.translation_language, translationsContainer,
                    false);
            TextView textView = (TextView) translationLanguage.findViewById(R.id.translation_language);
            if (!mFrench && !mDutch && !mGerman && !mRussian) {
                textView.setVisibility(View.GONE);
            }
            textView.setText(getString(R.string.language_english));
            translationsContainer.addView(translationLanguage);
            for (List<String> tran : mTranslation.getEnglishSense()) {
                int tran_size = tran.size();
                if (tran_size > 0) {
                    int i = 0;
                    StringBuilder strBuilder = new StringBuilder();
                    for (String str : tran) {
                        strBuilder.append(str);
                        i++;
                        if (i < tran_size) {
                            strBuilder.append(", ");
                        }
                    }
                    View translation_ll = mInflater.inflate(R.layout.translation_line, translationsContainer,
                            false);
                    TextView tView = (TextView) translation_ll.findViewById(R.id.translation_translation);
                    tView.setText(strBuilder.toString());
                    translationsContainer.addView(translation_ll);
                }

            }
        }
        if (mFrench && mTranslation.getFrenchSense() != null && mTranslation.getFrenchSense().size() > 0) {
            View translation_language = mInflater.inflate(R.layout.translation_language, translationsContainer,
                    false);
            TextView textView = (TextView) translation_language.findViewById(R.id.translation_language);
            if (!mEnglish && !mDutch && !mGerman && !mRussian) {
                textView.setVisibility(View.GONE);
            }
            textView.setText(getString(R.string.language_french));
            translationsContainer.addView(translation_language);
            for (List<String> tran : mTranslation.getFrenchSense()) {
                int tran_size = tran.size();
                if (tran_size > 0) {
                    int i = 0;
                    StringBuilder strBuilder = new StringBuilder();
                    for (String str : tran) {
                        strBuilder.append(str);
                        i++;
                        if (i < tran_size) {
                            strBuilder.append(", ");
                        }
                    }
                    View translation_ll = mInflater.inflate(R.layout.translation_line, translationsContainer,
                            false);
                    TextView tView = (TextView) translation_ll.findViewById(R.id.translation_translation);
                    tView.setText(strBuilder.toString());
                    translationsContainer.addView(translation_ll);
                }
            }
        }
        if (mDutch && mTranslation.getDutchSense() != null && mTranslation.getDutchSense().size() > 0) {
            View translation_language = mInflater.inflate(R.layout.translation_language, translationsContainer,
                    false);
            TextView textView = (TextView) translation_language.findViewById(R.id.translation_language);
            if (!mFrench && !mEnglish && !mGerman && !mRussian) {
                textView.setVisibility(View.GONE);
            }
            textView.setText(getString(R.string.language_dutch));
            translationsContainer.addView(translation_language);
            for (List<String> tran : mTranslation.getDutchSense()) {
                int tran_size = tran.size();
                if (tran_size > 0) {
                    int i = 0;
                    StringBuilder strBuilder = new StringBuilder();
                    for (String str : tran) {
                        strBuilder.append(str);
                        i++;
                        if (i < tran_size) {
                            strBuilder.append(", ");
                        }
                    }
                    View translation_ll = mInflater.inflate(R.layout.translation_line, translationsContainer,
                            false);
                    TextView tView = (TextView) translation_ll.findViewById(R.id.translation_translation);
                    tView.setText(strBuilder.toString());
                    translationsContainer.addView(translation_ll);
                }
            }
        }
        if (mGerman && mTranslation.getGermanSense() != null && mTranslation.getGermanSense().size() > 0) {
            View translation_language = mInflater.inflate(R.layout.translation_language, translationsContainer,
                    false);
            TextView textView = (TextView) translation_language.findViewById(R.id.translation_language);
            if (!mFrench && !mDutch && !mEnglish && !mRussian) {
                textView.setVisibility(View.GONE);
            }
            textView.setText(getString(R.string.language_german));
            translationsContainer.addView(translation_language);
            for (List<String> tran : mTranslation.getGermanSense()) {
                int tran_size = tran.size();
                if (tran_size > 0) {
                    int i = 0;
                    StringBuilder strBuilder = new StringBuilder();
                    for (String str : tran) {
                        strBuilder.append(str);
                        i++;
                        if (i < tran_size) {
                            strBuilder.append(", ");
                        }
                    }
                    View translation_ll = mInflater.inflate(R.layout.translation_line, translationsContainer,
                            false);
                    TextView tView = (TextView) translation_ll.findViewById(R.id.translation_translation);
                    tView.setText(strBuilder.toString());
                    translationsContainer.addView(translation_ll);
                }
            }
        }
        if (mRussian && mTranslation.getRussianSense() != null && mTranslation.getRussianSense().size() > 0) {
            View translation_language = mInflater.inflate(R.layout.translation_language, translationsContainer,
                    false);
            TextView textView = (TextView) translation_language.findViewById(R.id.translation_language);
            if (!mFrench && !mDutch && !mEnglish && !mGerman) {
                textView.setVisibility(View.GONE);
            }
            textView.setText(getString(R.string.language_russian));
            translationsContainer.addView(translation_language);
            for (List<String> tran : mTranslation.getRussianSense()) {
                int tran_size = tran.size();
                if (tran_size > 0) {
                    int i = 0;
                    StringBuilder strBuilder = new StringBuilder();
                    for (String str : tran) {
                        strBuilder.append(str);
                        i++;
                        if (i < tran_size) {
                            strBuilder.append(", ");
                        }
                    }
                    View translation_ll = mInflater.inflate(R.layout.translation_line, translationsContainer,
                            false);
                    TextView tView = (TextView) translation_ll.findViewById(R.id.translation_translation);
                    tView.setText(strBuilder.toString());
                    translationsContainer.addView(translation_ll);
                }
            }
        }

        view.findViewById(R.id.translation_kanji_container).setVisibility(View.GONE);
        mCharacters = null;
        if (writeCharacters != null) {
            // write single characters
            if (writeCharacters.length() > 0) {
                CharacterLoader charLoader = new CharacterLoader(getActivity().getApplicationContext(), this);
                charLoader.execute(writeCharacters);
            }
        }
        view.findViewById(R.id.detail_example_sentences_progress_bar).setVisibility(View.VISIBLE);
        view.findViewById(R.id.translation_tatoeba_container).setVisibility(View.VISIBLE);
        ViewGroup tatoebaContainer = (ViewGroup) view.findViewById(R.id.detail_example_sentences_container);
        tatoebaContainer.removeAllViews();

        List<String> kebRebList = kebRebToList(mTranslation);
        if (kebRebList != null && kebRebList.size() > 0) {
            TatoebaSentenceLoader sentenceLoader = new TatoebaSentenceLoader(
                    this.getActivity().getApplicationContext(), this);
            sentenceLoader.execute(kebRebList);
        }
    } else {
        Log.e(LOG_TAG, "inflater null");
    }
}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

@Override
public void onRequestcompleted(int requestCode, Object result) {
    timeoutHandler.removeCallbacks(timeout);
    if (mPd != null && mPd.isShowing()) {
        // clear pd from memory to avoid progress bar freeze when showed again
        removeDialog(DIALOG_PROGRESS);// ww w  .j a  va2s.c o  m
    }
    // //Log.d(Constants.PROJECT_TAG, "Request result " + (String) result);

    if (requestCode == AVService.REQUEST_IMAGE) {
        new AlertDialog.Builder(this).setMessage(R.string.news_photo_added)
                .setPositiveButton(android.R.string.ok, null).show();
        requestAdditionalPhotos();
        return;
    }

    if (requestCode == AVService.REQUEST_JSON && result != null) {
        try {
            JSONObject answer = new JSONArray((String) result).getJSONObject(0);
            boolean isIncident = JsonData.VALUE_REQUEST_NEW_INCIDENT
                    .equals(answer.getString(JsonData.PARAM_REQUEST));
            boolean isOk = (JsonData.VALUE_INCIDENT_SAVED == (answer.getJSONObject(JsonData.PARAM_ANSWER)
                    .getInt(JsonData.PARAM_STATUS)));

            if (isIncident && isOk) {
                /*
                 * FileInputStream fis_close = openFileInput(CAPTURE_CLOSE);
                 * FileInputStream fis_far = openFileInput(CAPTURE_FAR);
                 */

                File img_close = new File(getFilesDir() + "/" + CAPTURE_CLOSE);
                if (!img_close.exists()
                        || ((ImageView) findViewById(R.id.ImageView_close)).getDrawable() == null) {
                    img_close = null;
                }
                File img_far = new File(getFilesDir() + "/" + CAPTURE_ARROW);
                if (!img_far.exists() || ((ImageView) findViewById(R.id.ImageView_far)).getDrawable() == null) {
                    img_far = null;
                }

                // if (!img_far.exists()) {
                // img_far = new File(getFilesDir() + "/" + CAPTURE_FAR);
                // }

                // TODO add a listener which handles commands properly
                AVService.getInstance(this).postImage(null, Utils.getUdid(this), img_comment,
                        answer.getJSONObject(JsonData.PARAM_ANSWER).getString(JsonData.ANSWER_INCIDENT_ID),
                        img_far, img_close, true);
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                AlertDialog alert;
                builder.setMessage(R.string.report_detail_new_report_ok).setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        });
                alert = builder.create();
                alert.show();
            } else {

                // hotfix nico : here we can have valid answer for incident updates !!!
                // handle answer and display popup here instead of when we click on buttons
                int statuscode = answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS);

                if (statuscode == 0) {
                    // FIXME end activity when resolve incident ??
                    switch (mCurrentAction) {
                    case ACTION_GET_IMAGES:
                        //Log.d("AlerteVoirie_PM", "images : " + result);
                        JSONArray imgList = answer.getJSONObject(JsonData.PARAM_ANSWER)
                                .getJSONArray(JsonData.PARAM_PHOTOS);
                        ViewGroup photocontainer = (ViewGroup) findViewById(R.id.extra_images_container);
                        photocontainer.removeAllViews();
                        LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT);
                        for (int i = 0; i < imgList.length() - 2; i++) {
                            JSONObject imgObj = imgList.getJSONObject(i);
                            //Log.d("AlerteVoirie_PM", "received image obj : " + imgObj);
                            View v = getLayoutInflater().inflate(R.layout.extra_photo, null);
                            v.setLayoutParams(params);
                            TextView date = (TextView) v.findViewById(R.id.textView_date);
                            TextView comment = (TextView) v.findViewById(R.id.textView_comment);
                            ImageView icon = (ImageView) v.findViewById(R.id.imageView_icon);

                            // format date
                            String dateString = imgObj.getString(JsonData.PARAM_IMAGES_DATE);
                            date.setText(getFormatedDate(dateString));

                            comment.setText(imgObj.getString(JsonData.PARAM_IMAGES_COMMENT));
                            imgd.download(imgObj.getString(JsonData.PARAM_IMAGES_URL), icon);
                            photocontainer.addView(v);
                        }
                        if (imgList.length() > 2) {
                            findViewById(R.id.TextView_additional_photos_header).setVisibility(View.VISIBLE);
                        } else {
                            findViewById(R.id.TextView_additional_photos_header).setVisibility(View.GONE);
                        }
                        break;
                    case ACTION_CONFIRM_INCIDENT:
                        findViewById(R.id.existing_incidents_confirmed).setEnabled(false);
                        new AlertDialog.Builder(this).setMessage(R.string.news_incidents_confirmed)
                                .setPositiveButton(android.R.string.ok, null).show();
                        break;
                    case ACTION_INVALID_INCIDENT: {
                        AlertDialog dialog = new AlertDialog.Builder(this)
                                .setMessage(R.string.news_incidents_invalidated)
                                .setPositiveButton(android.R.string.ok, null).create();
                        dialog.setOnDismissListener(new OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                finish();
                            }
                        });
                        dialog.show();
                        break;
                    }
                    case ACTION_SOLVE_INCIDENT: {
                        AlertDialog dialog = new AlertDialog.Builder(this)
                                .setMessage(R.string.news_incidents_resolved)
                                .setPositiveButton(android.R.string.ok, null).create();
                        dialog.setOnDismissListener(new OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                finish();
                            }
                        });
                        dialog.show();
                        break;
                    }
                    default:
                        // assume it's a generic update request in other cases ...
                        new AlertDialog.Builder(this).setMessage(R.string.report_detail_update_ok)
                                .setPositiveButton(android.R.string.ok, null).show();
                        break;
                    }
                } else {
                    // other things
                    // FIXME show popups instead of toasts !
                    if ((answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS)) == 18) {
                        findViewById(R.id.existing_incidents_confirmed).setEnabled(false);
                        Toast.makeText(this, getString(R.string.incident_already_confirmed), Toast.LENGTH_LONG)
                                .show();
                    } else {
                        //Log.d("AlerteVoirie_PM", "erreur ?");
                        Toast.makeText(this, getString(R.string.server_error), Toast.LENGTH_LONG).show();
                    }
                }
            }
        } catch (JSONException e) {
            Log.e(Constants.PROJECT_TAG, "Erreur d'envoi d'image", e);
        } /*
           * catch (FileNotFoundException e) {
           * // TODO Auto-generated catch block
           * Log.e(Constants.PROJECT_TAG,"File not found",e);
           * }
           */

    } else if (requestCode == AVService.REQUEST_ERROR) {
        AVServiceErrorException error = (AVServiceErrorException) result;
        String errorString = null;
        switch (error.errorCode) {
        case 19:
            // already invalidated
            errorString = getString(R.string.error_already_invalidated);
            break;

        default:
            errorString = getString(R.string.server_error);
            break;
        }

        new AlertDialog.Builder(this).setTitle(R.string.error_popup_title).setMessage(errorString)
                .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).show();
    }

}

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

private void buildLinksSection(Cursor cursor) {
    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(this);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(R.string.session_link_livestream, getWatchLiveIntent(this)));
    }/*from  w  ww  .  ja v a2  s  .  c  o m*/

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Object>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(this);
        int columns = getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            if (link.first == R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        findViewById(R.id.session_links_header).setVisibility(View.GONE);
        findViewById(R.id.links_container).setVisibility(View.GONE);
    }

}

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

private void buildLinksSection(Cursor cursor) {
    final Context context = mRootView.getContext();

    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(context);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(R.string.session_link_livestream, getWatchLiveIntent(context)));
    }// w w  w.j a  v a  2  s .c  om

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Object>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(context);
        int columns = context.getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            if (link.first == R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.GONE);
    }

}