Example usage for android.widget LinearLayout removeViewAt

List of usage examples for android.widget LinearLayout removeViewAt

Introduction

In this page you can find the example usage for android.widget LinearLayout removeViewAt.

Prototype

public void removeViewAt(int index) 

Source Link

Document

Removes the view at the specified position in the group.

Usage

From source file:com.ridhofkr.hanacaraka.LetterCardActivity.java

private void applyRotation(float start, float end, LinearLayout front, LinearLayout back, boolean flag) {
    final float centerX = front.getWidth() / 2.0f;
    final float centerY = front.getHeight() / 2.0f;

    final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
    rotation.setDuration(300);/*from  w  w w.j  a va2 s .  c o  m*/
    rotation.setFillAfter(true);
    rotation.setInterpolator(new AccelerateInterpolator());
    rotation.setAnimationListener(new DisplayNextView(flag, front, back));

    LinearLayout inside = (LinearLayout) back.findViewById(R.id.backcardinside);
    if (flag) {
        String text = ((String) ((TextView) front.findViewById(R.id.cardinfotitle)).getText());
        front.startAnimation(rotation);
        removeSoundListener(front);
        inside.addView(ctrl.playAnimation(LetterCardActivity.this, text, category));
    } else {
        back.startAnimation(rotation);
        addSoundListener(front);
        inside.removeViewAt(2);
    }
}

From source file:ng.kingsley.android.widget.CollectionView.java

private View recycleItemRow(View convertView, RowComputeResult rowInfo) {
    int i;/* ww w .ja  va2 s.c  om*/
    LinearLayout ll = (LinearLayout) convertView;
    for (i = 0; i < rowInfo.group.mDisplayCols; i++) {
        View view = ll.getChildAt(i);
        View newView = getItemView(rowInfo, i, view, ll);
        if (view != newView) {
            LinearLayout.LayoutParams thisViewParams = setupLayoutParams(newView);
            ll.removeViewAt(i);
            ll.addView(newView, i, thisViewParams);
        }
    }
    return ll;
}

From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java

/** Called when the activity is first created. */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//  ww w. ja va 2s .  com
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate()");
    super.onCreate(savedInstanceState);

    boolean needActionBar = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            if (!ViewConfiguration.get(this).hasPermanentMenuKey())
                needActionBar = true;
        } else {
            needActionBar = true;
        }
    }
    if (needActionBar) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
    } else {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Force landscape-only.
    updateNativeDisplayParameters();

    //Bundle extras = getIntent().getExtras();
    //String baseFolderPath = extras.getString("baseFolderPath");

    //int markerID = ARToolKit.getInstance().addMarker("multi;"+baseFolderPath +"/marker.dat");

    setContentView(R.layout.main_video);
    mButton = (Button) findViewById(R.id.button_capture);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Toast.makeText(ARCloud.this, "Take picture", Toast.LENGTH_LONG).show();
            LinearLayout linearLayoutResultWrapper = (LinearLayout) findViewById(R.id.result_wrapper);
            if (linearLayoutResultWrapper.getChildCount() > 0) {
                linearLayoutResultWrapper.removeViewAt(0);
                linearLayoutResultWrapper.removeAllViews();
            }

            camSurface.getCamera().takePicture(null, null, mPicture);
            ;
        }
    });

    ARMovieActivity.nativeCreate(this);
}

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

private View recycleItemRow(View convertView, RowComputeResult rowInfo) {
    LinearLayout ll = (LinearLayout) convertView;
    int nbColumns = rowInfo.group.mDisplayCols;
    if (hasCustomGroupView()) {
        nbColumns = 1;//from   w w  w .j  a va2s  . c  o m
    }
    for (int i = 0; i < nbColumns; i++) {
        View view = ll.getChildAt(i);
        View newView = getItemView(rowInfo, i, view, ll);
        if (view != newView) {
            setupLayoutParams(newView);
            ll.removeViewAt(i);
            ll.addView(newView, i);
        }
    }
    return ll;
}

From source file:org.zywx.wbpalmstar.plugin.inputtextfieldview.ACEInputTextFieldView.java

private void initPagerIndicator(int pagerSize, LinearLayout layout) {
    int childCount = layout.getChildCount();
    if (pagerSize == childCount) {
        return;//from w w  w.  j a v  a 2  s . co m
    }
    int width = getResources().getDimensionPixelSize(CRes.plugin_inputtextfieldview_pager_indicator_width);
    int left = getResources().getDimensionPixelSize(CRes.plugin_inputtextfieldview_pager_indicator_left);
    int top = getResources().getDimensionPixelSize(CRes.plugin_inputtextfieldview_pager_indicator_top);
    LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(width, width);
    viewParams.setMargins(left, top, left, top);
    if (pagerSize > childCount) {// ?
        while (childCount < pagerSize) {
            ImageView imageView = new ImageView(this.getContext());
            layout.addView(imageView, childCount, viewParams);
            childCount++;
        }
    } else {
        while (childCount > pagerSize) {
            layout.removeViewAt(childCount);
            childCount--;
        }
    }
}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

private void initPagerIndicator(int pagerSize, LinearLayout layout) {
    int childCount = layout.getChildCount();
    if (pagerSize == childCount) {
        return;//from ww  w  .  j a  v  a 2  s  . c  o m
    }
    int width = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_width);
    int left = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_left);
    int top = getResources().getDimensionPixelSize(CRes.plugin_chatkeyboard_pager_indicator_top);
    LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(width, width);
    viewParams.setMargins(left, top, left, top);
    if (pagerSize > childCount) {// ?
        while (childCount < pagerSize) {
            ImageView imageView = new ImageView(getContext());
            layout.addView(imageView, childCount, viewParams);
            childCount++;
        }
    } else {
        while (childCount > pagerSize) {
            layout.removeViewAt(childCount);
            childCount--;
        }
    }
}

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

private View createGroupView(RowComputeResult rowInfo, View view, ViewGroup parent) {
    ViewGroup groupView;/*w w  w.j av  a 2  s  .  c o  m*/
    if (view != null && view instanceof ViewGroup) {
        groupView = (ViewGroup) view;
        // If there are more children in the recycled view we remove the extra ones.
        if (groupView.getChildAt(0) instanceof LinearLayout) {
            LinearLayout groupViewContent = (LinearLayout) groupView.getChildAt(0);
            if (groupViewContent.getChildCount() > rowInfo.group.getRowCount()) {
                groupViewContent.removeViews(rowInfo.group.getRowCount(),
                        groupViewContent.getChildCount() - rowInfo.group.getRowCount());
            }
        }
        // Use the defined callbacks if the user has chosen to by implementing a
        // CardsCollectionViewCallbacks.
    } else if (mCallbacks instanceof CollectionViewCallbacks.GroupCollectionViewCallbacks) {
        groupView = ((CollectionViewCallbacks.GroupCollectionViewCallbacks) mCallbacks)
                .newCollectionGroupView(getContext(), rowInfo.groupId, rowInfo.group, parent);
        // This should never happened but if it does we'll display an EmptyView.
    } else {
        LOGE(TAG, "Tried to create a group view but the callback is not an instance of "
                + "GroupCollectionViewCallbacks");
        return new EmptyView(getContext());
    }
    LinearLayout groupViewContent;
    if (groupView.getChildAt(0) instanceof LinearLayout) {
        groupViewContent = (LinearLayout) groupView.getChildAt(0);
    } else {
        groupViewContent = new LinearLayout(getContext());
        groupViewContent.setOrientation(LinearLayout.VERTICAL);
        LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        groupViewContent.setLayoutParams(LLParams);
        groupView.addView(groupViewContent);
    }
    disableCustomGroupView();
    for (int i = 0; i < rowInfo.group.getRowCount(); i++) {
        View itemView;
        try {
            itemView = getRowView(rowInfo.groupOffset + i, groupViewContent.getChildAt(i), groupViewContent);
        } catch (Exception e) {
            // Recycling failed (maybe the items were not compatible) so we start again without
            // recycling.
            itemView = getRowView(rowInfo.groupOffset + i, null, groupViewContent);
        }
        if (itemView != groupViewContent.getChildAt(i)) {
            if (groupViewContent.getChildCount() > i) {
                groupViewContent.removeViewAt(i);
            }
            groupViewContent.addView(itemView, i);
        }
    }
    enableCustomGroupView();
    return groupView;
}

From source file:com.razza.apps.iosched.ui.widget.CollectionView.java

private View createGroupView(RowComputeResult rowInfo, View view, ViewGroup parent) {
    ViewGroup groupView;//from  w w  w  .j a v  a  2s  . co  m
    if (view != null && view instanceof ViewGroup) {
        groupView = (ViewGroup) view;
        // If there are more children in the recycled view we remove the extra ones.
        if (groupView.getChildAt(0) instanceof LinearLayout) {
            LinearLayout groupViewContent = (LinearLayout) groupView.getChildAt(0);
            if (groupViewContent.getChildCount() > rowInfo.group.getRowCount()) {
                groupViewContent.removeViews(rowInfo.group.getRowCount(),
                        groupViewContent.getChildCount() - rowInfo.group.getRowCount());
            }
        }
        // Use the defined callbacks if the user has chosen to by implementing a
        // CardsCollectionViewCallbacks.
    } else if (mCallbacks instanceof CollectionViewCallbacks.GroupCollectionViewCallbacks) {
        groupView = ((CollectionViewCallbacks.GroupCollectionViewCallbacks) mCallbacks)
                .newCollectionGroupView(getContext(), rowInfo.groupId, rowInfo.group, parent);
        // This should never happened but if it does we'll display an EmptyView.
    } else {
        LogUtils.LOGE(TAG, "Tried to create a group view but the callback is not an instance of "
                + "GroupCollectionViewCallbacks");
        return new EmptyView(getContext());
    }
    LinearLayout groupViewContent;
    if (groupView.getChildAt(0) instanceof LinearLayout) {
        groupViewContent = (LinearLayout) groupView.getChildAt(0);
    } else {
        groupViewContent = new LinearLayout(getContext());
        groupViewContent.setOrientation(LinearLayout.VERTICAL);
        LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        groupViewContent.setLayoutParams(LLParams);
        groupView.addView(groupViewContent);
    }
    disableCustomGroupView();
    for (int i = 0; i < rowInfo.group.getRowCount(); i++) {
        View itemView;
        try {
            itemView = getRowView(rowInfo.groupOffset + i, groupViewContent.getChildAt(i), groupViewContent);
        } catch (Exception e) {
            // Recycling failed (maybe the items were not compatible) so we start again without
            // recycling.
            itemView = getRowView(rowInfo.groupOffset + i, null, groupViewContent);
        }
        if (itemView != groupViewContent.getChildAt(i)) {
            if (groupViewContent.getChildCount() > i) {
                groupViewContent.removeViewAt(i);
            }
            groupViewContent.addView(itemView, i);
        }
    }
    enableCustomGroupView();
    return groupView;
}

From source file:org.nla.tarotdroid.lib.ui.GameSetSynthesisFragment.java

/**
  * Refreshes the stats rows on the synthesis view.
  *///from ww  w  .j a v a  2s .c  o  m
protected void refreshPlayerStatsRows() {
    // sort players
    List<Player> sortedPlayers = this.getGameSet().getPlayers().getPlayers();
    Collections.sort(sortedPlayers, new PlayerScoreComparator());

    // get general data sources
    IGameSetStatisticsComputer gameSetStatisticsComputer = GameSetStatisticsComputerFactory
            .GetGameSetStatisticsComputer(this.getGameSet(), "guava");
    MapPlayersScores lastScores = this.getGameSet().getGameSetScores().getResultsAtLastGame();
    Map<Player, Integer> leadingCount = gameSetStatisticsComputer.getLeadingCount();
    Map<Player, Integer> leadingSuccesses = gameSetStatisticsComputer.getLeadingSuccessCount();
    Map<Player, Integer> calledCount = gameSetStatisticsComputer.getCalledCount();
    int minScoreEver = gameSetStatisticsComputer.getMinScoreEver();
    int maxScoreEver = gameSetStatisticsComputer.getMaxScoreEver();

    // format statistics lines
    for (int rank = 0; rank < sortedPlayers.size(); ++rank) {
        // get player specific data sources
        Player player = sortedPlayers.get(rank);
        int lastScore = lastScores == null ? 0 : lastScores.get(player);
        int successfulLeadingGamesCount = leadingSuccesses.get(player) == null ? 0
                : leadingSuccesses.get(player).intValue();
        int leadingGamesCount = leadingCount.get(player) == null ? 0 : leadingCount.get(player);
        int successRate = (int) (((double) successfulLeadingGamesCount) / ((double) leadingGamesCount) * 100.0);
        int minScoreForPlayer = gameSetStatisticsComputer.getMinScoreEverForPlayer(player);
        int maxScoreForPlayer = gameSetStatisticsComputer.getMaxScoreEverForPlayer(player);

        // get line widgets
        LinearLayout statRow = this.statsRows.get(rank + 1);
        //TextView statPlayerName = (TextView)statRow.findViewById(R.id.statPlayerName);
        TextView statScore = (TextView) statRow.findViewById(R.id.statScore);
        TextView statLeadingGamesCount = (TextView) statRow.findViewById(R.id.statLeadingGamesCount);
        TextView statSuccessfulGamesCount = (TextView) statRow.findViewById(R.id.statSuccessfulGamesCount);
        TextView statMinScore = (TextView) statRow.findViewById(R.id.statMinScore);
        TextView statMaxScore = (TextView) statRow.findViewById(R.id.statMaxScore);

        //          Bitmap playerImage = null;
        //          if (player.getPictureUri() != null && !player.getPictureUri().equals("")) {
        //             playerImage = UIHelper.getPlayerImage(this.getActivity(), player);
        //          }
        //          
        //            
        //            // assign values to widgets
        //            if (player.getFacebookId() != null) {
        //             // player facebook image
        //             ProfilePictureView pictureView = new ProfilePictureView(this.getActivity());
        //             pictureView.setProfileId(player.getFacebookId());
        //             pictureView.setPresetSize(ProfilePictureView.SMALL);
        //             //pictureView.setOnClickListener(playerClickListener);
        //             pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);
        //             statRow.removeViewAt(0);
        //               statRow.addView(pictureView, 0);
        //            }
        //            else {
        //               // WARNING: The properties below reference the style ScoreTextStyle, but we can't set a style at runtime.
        //               TextView playerName = new TextView(this.getActivity());
        //               playerName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1));
        //               playerName.setGravity(Gravity.CENTER);
        //               playerName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //               playerName.setEllipsize(TruncateAt.END);
        //               playerName.setSingleLine();
        //               playerName.setTextColor(Color.WHITE);
        //               playerName.setTypeface(null, Typeface.BOLD);
        //               playerName.setText(player.getName());
        //               //playerName.setBackgroundResource(R.drawable.border_player_white);
        //               statRow.removeViewAt(0);
        //               statRow.addView(playerName, 0);
        //            }

        OnClickListener playerClickListener = new PlayerClickListener(player);

        // facebook picture
        if (player.getFacebookId() != null) {
            ProfilePictureView pictureView = new ProfilePictureView(this.getActivity());
            pictureView.setProfileId(player.getFacebookId());
            pictureView.setPresetSize(ProfilePictureView.SMALL);
            pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);

            pictureView.setOnClickListener(playerClickListener);
            //this.addView(pictureView);
            statRow.removeViewAt(0);
            statRow.addView(pictureView, 0);
        }

        // contact picture
        else if (player.getPictureUri() != null
                && player.getPictureUri().toString().contains("content://com.android.contacts/contacts")) {
            Bitmap playerImage = UIHelper.getContactPicture(this.getActivity(),
                    Uri.parse(player.getPictureUri()).getLastPathSegment());
            ImageView imgPlayer = new ImageView(this.getActivity());
            imgPlayer.setImageBitmap(playerImage);
            imgPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);

            imgPlayer.setOnClickListener(playerClickListener);
            //this.addView(imgPlayer);
            statRow.removeViewAt(0);
            statRow.addView(imgPlayer, 0);
        }

        // no picture, only name
        else {
            TextView txtPlayer = new TextView(this.getActivity());
            txtPlayer.setText(player.getName());
            txtPlayer.setGravity(Gravity.CENTER);
            txtPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);
            txtPlayer.setMinWidth(UIConstants.PLAYER_VIEW_WIDTH);
            txtPlayer.setHeight(UIConstants.PLAYER_VIEW_HEIGHT);
            txtPlayer.setBackgroundColor(Color.TRANSPARENT);
            txtPlayer.setTypeface(null, Typeface.BOLD);
            txtPlayer.setTextColor(Color.WHITE);
            txtPlayer.setSingleLine();
            txtPlayer.setEllipsize(TruncateAt.END);

            txtPlayer.setOnClickListener(playerClickListener);
            //this.addView(txtPlayer);
            statRow.removeViewAt(0);
            statRow.addView(txtPlayer, 0);
        }

        statScore.setText(Integer.toString(lastScore));
        statLeadingGamesCount.setText(Integer.toString(leadingGamesCount));
        statSuccessfulGamesCount.setText(
                Integer.toString(successfulLeadingGamesCount) + " (" + Integer.toString(successRate) + "%)");

        // display called game count if necessary 
        if (this.getGameSet().getGameStyleType() == GameStyleType.Tarot5) {
            TextView statCalledGamesCount = (TextView) statRow.findViewById(R.id.statCalledGamesCount);
            statCalledGamesCount
                    .setText(Integer.toString(calledCount.get(player) == null ? 0 : calledCount.get(player)));
        }

        statMinScore.setText(Integer.toString(minScoreForPlayer));
        statMaxScore.setText(Integer.toString(maxScoreForPlayer));
        statMinScore.setTextColor(Color.WHITE);
        statMaxScore.setTextColor(Color.WHITE);

        // color min score if lowest
        if (minScoreEver == minScoreForPlayer) {
            statMinScore.setTextColor(Color.YELLOW);
        }

        // color max score if highest
        if (maxScoreEver == maxScoreForPlayer) {
            statMaxScore.setTextColor(Color.GREEN);
        }
    }
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java

private void updateToolList(Set<Map.Entry<String, ArrayList<ToolEntry>>> tools,
        final LinearLayout toolContainer) {
    if (fiskInfoUtility.isNetworkAvailable(getActivity())) {
        List<ToolEntry> localTools = new ArrayList<>();
        final List<ToolEntry> unconfirmedRemovedTools = new ArrayList<>();
        final List<ToolEntry> synchedTools = new ArrayList<>();

        for (final Map.Entry<String, ArrayList<ToolEntry>> dateEntry : tools) {
            for (final ToolEntry toolEntry : dateEntry.getValue()) {
                if (toolEntry.getToolStatus() == ToolEntryStatus.STATUS_REMOVED) {
                    continue;
                } else if (toolEntry.getToolStatus() == ToolEntryStatus.STATUS_RECEIVED) {
                    synchedTools.add(toolEntry);
                } else if (!(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_REMOVED_UNCONFIRMED)) {
                    localTools.add(toolEntry);
                } else {
                    unconfirmedRemovedTools.add(toolEntry);
                }/*  w w  w. j av  a2  s .c  o  m*/
            }
        }

        barentswatchApi.setAccesToken(user.getToken());

        Response response = barentswatchApi.getApi().geoDataDownload("fishingfacility", "JSON");

        if (response == null) {
            Log.d(TAG, "RESPONSE == NULL");
        }

        byte[] toolData;
        try {
            toolData = FiskInfoUtility.toByteArray(response.getBody().in());
            JSONObject featureCollection = new JSONObject(new String(toolData));
            JSONArray jsonTools = featureCollection.getJSONArray("features");
            JSONArray matchedTools = new JSONArray();
            UserSettings settings = user.getSettings();

            for (int i = 0; i < jsonTools.length(); i++) {
                JSONObject tool = jsonTools.getJSONObject(i);
                boolean hasCopy = false;

                for (int j = 0; j < localTools.size(); j++) {
                    if (localTools.get(j).getToolId()
                            .equals(tool.getJSONObject("properties").getString("toolid"))) {
                        SimpleDateFormat sdfMilliSeconds = new SimpleDateFormat(
                                getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss_sss),
                                Locale.getDefault());
                        SimpleDateFormat sdfMilliSecondsRemote = new SimpleDateFormat(
                                getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss_sss),
                                Locale.getDefault());
                        SimpleDateFormat sdfRemote = new SimpleDateFormat(
                                getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss), Locale.getDefault());

                        sdfMilliSeconds.setTimeZone(TimeZone.getTimeZone("UTC"));
                        /* Timestamps from BW seem to be one hour earlier than UTC/GMT?  */
                        sdfMilliSecondsRemote.setTimeZone(TimeZone.getTimeZone("GMT-1"));
                        sdfRemote.setTimeZone(TimeZone.getTimeZone("GMT-1"));
                        Date localLastUpdatedDateTime;
                        Date localUpdatedBySourceDateTime;
                        Date serverUpdatedDateTime;
                        Date serverUpdatedBySourceDateTime = null;
                        try {
                            localLastUpdatedDateTime = sdfMilliSeconds
                                    .parse(localTools.get(j).getLastChangedDateTime());
                            localUpdatedBySourceDateTime = sdfMilliSeconds
                                    .parse(localTools.get(j).getLastChangedBySource());

                            serverUpdatedDateTime = tool.getJSONObject("properties")
                                    .getString("lastchangeddatetime").length() == getResources()
                                            .getInteger(R.integer.datetime_without_milliseconds_length)
                                                    ? sdfRemote.parse(tool.getJSONObject("properties")
                                                            .getString("lastchangeddatetime"))
                                                    : sdfMilliSecondsRemote
                                                            .parse(tool.getJSONObject("properties")
                                                                    .getString("lastchangeddatetime"));

                            if (tool.getJSONObject("properties").has("lastchangedbysource")) {
                                serverUpdatedBySourceDateTime = tool.getJSONObject("properties")
                                        .getString("lastchangedbysource").length() == getResources()
                                                .getInteger(R.integer.datetime_without_milliseconds_length)
                                                        ? sdfRemote.parse(tool.getJSONObject("properties")
                                                                .getString("lastchangedbysource"))
                                                        : sdfMilliSecondsRemote
                                                                .parse(tool.getJSONObject("properties")
                                                                        .getString("lastchangedbysource"));
                            }

                            if ((localLastUpdatedDateTime.equals(serverUpdatedDateTime)
                                    || localLastUpdatedDateTime.before(serverUpdatedDateTime))
                                    && serverUpdatedBySourceDateTime != null
                                    && (localUpdatedBySourceDateTime.equals(serverUpdatedBySourceDateTime)
                                            || localUpdatedBySourceDateTime
                                                    .before(serverUpdatedBySourceDateTime))) {
                                localTools.get(j).updateFromGeoJson(tool, getActivity());

                                localTools.get(j).setToolStatus(ToolEntryStatus.STATUS_RECEIVED);
                            } else if (serverUpdatedBySourceDateTime != null
                                    && localUpdatedBySourceDateTime.after(serverUpdatedBySourceDateTime)) {
                                // TODO: Do nothing, local changes should be reported.

                            } else {
                                // TODO: what gives?
                            }

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

                        localTools.remove(j);
                        j--;

                        hasCopy = true;
                        break;
                    }
                }

                for (int j = 0; j < unconfirmedRemovedTools.size(); j++) {
                    if (unconfirmedRemovedTools.get(j).getToolId()
                            .equals(tool.getJSONObject("properties").getString("toolid"))) {
                        hasCopy = true;
                        unconfirmedRemovedTools.remove(j);
                        j--;
                    }
                }

                for (int j = 0; j < synchedTools.size(); j++) {
                    if (synchedTools.get(j).getToolId()
                            .equals(tool.getJSONObject("properties").getString("toolid"))) {
                        hasCopy = true;
                        synchedTools.remove(j);
                        j--;
                    }
                }

                if (!hasCopy && settings != null) {
                    if ((!settings.getVesselName().isEmpty()
                            && (FiskInfoUtility.ReplaceRegionalCharacters(settings.getVesselName())
                                    .equalsIgnoreCase(tool.getJSONObject("properties").getString("vesselname"))
                                    || settings.getVesselName().equalsIgnoreCase(
                                            tool.getJSONObject("properties").getString("vesselname"))))
                            && ((!settings.getIrcs().isEmpty() && settings.getIrcs().toUpperCase()
                                    .equals(tool.getJSONObject("properties").getString("ircs")))
                                    || (!settings.getMmsi().isEmpty() && settings.getMmsi()
                                            .equals(tool.getJSONObject("properties").getString("mmsi")))
                                    || (!settings.getImo().isEmpty() && settings.getImo()
                                            .equals(tool.getJSONObject("properties").getString("imo"))))) {
                        matchedTools.put(tool);
                    }
                }
            }

            if (matchedTools.length() > 0) {
                final Dialog dialog = dialogInterface.getDialog(getActivity(),
                        R.layout.dialog_confirm_tools_from_api, R.string.tool_confirmation);
                Button cancelButton = (Button) dialog.findViewById(R.id.dialog_bottom_cancel_button);
                Button addToolsButton = (Button) dialog.findViewById(R.id.dialog_bottom_add_button);
                final LinearLayout linearLayoutToolContainer = (LinearLayout) dialog
                        .findViewById(R.id.dialog_confirm_tool_main_container_linear_layout);
                final List<ToolConfirmationRow> matchedToolsList = new ArrayList<>();

                for (int i = 0; i < matchedTools.length(); i++) {
                    ToolConfirmationRow confirmationRow = new ToolConfirmationRow(getActivity(),
                            matchedTools.getJSONObject(i));
                    linearLayoutToolContainer.addView(confirmationRow.getView());
                    matchedToolsList.add(confirmationRow);
                }

                addToolsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        for (ToolConfirmationRow row : matchedToolsList) {
                            if (row.isChecked()) {
                                ToolEntry newTool = row.getToolEntry();
                                user.getToolLog().addTool(newTool, newTool.getSetupDateTime().substring(0, 10));
                                ToolLogRow newRow = new ToolLogRow(v.getContext(), newTool,
                                        utilityOnClickListeners.getToolEntryEditDialogOnClickListener(
                                                getActivity(), getFragmentManager(), mGpsLocationTracker,
                                                newTool, user));
                                row.getView().setTag(newTool.getToolId());
                                toolContainer.addView(newRow.getView());
                            }
                        }

                        user.writeToSharedPref(v.getContext());
                        dialog.dismiss();
                    }
                });

                cancelButton.setOnClickListener(utilityOnClickListeners.getDismissDialogListener(dialog));
                dialog.show();
            }

            if (unconfirmedRemovedTools.size() > 0) {
                final Dialog dialog = dialogInterface.getDialog(getActivity(),
                        R.layout.dialog_confirm_tools_from_api, R.string.tool_confirmation);
                TextView infoTextView = (TextView) dialog.findViewById(R.id.dialog_description_text_view);
                Button cancelButton = (Button) dialog.findViewById(R.id.dialog_bottom_cancel_button);
                Button archiveToolsButton = (Button) dialog.findViewById(R.id.dialog_bottom_add_button);
                final LinearLayout linearLayoutToolContainer = (LinearLayout) dialog
                        .findViewById(R.id.dialog_confirm_tool_main_container_linear_layout);

                infoTextView.setText(R.string.removed_tools_information_text);
                archiveToolsButton.setText(R.string.ok);
                cancelButton.setVisibility(View.GONE);

                for (ToolEntry removedEntry : unconfirmedRemovedTools) {
                    ToolLogRow removedToolRow = new ToolLogRow(getActivity(), removedEntry, null);
                    removedToolRow.setToolNotificationImageViewVisibility(false);
                    removedToolRow.setEditToolImageViewVisibility(false);
                    linearLayoutToolContainer.addView(removedToolRow.getView());
                }

                archiveToolsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        for (ToolEntry removedEntry : unconfirmedRemovedTools) {
                            removedEntry.setToolStatus(ToolEntryStatus.STATUS_REMOVED);

                            for (int i = 0; i < toolContainer.getChildCount(); i++) {
                                if (removedEntry.getToolId()
                                        .equals(toolContainer.getChildAt(i).getTag().toString())) {
                                    toolContainer.removeViewAt(i);
                                    break;
                                }
                            }
                        }

                        user.writeToSharedPref(v.getContext());
                        dialog.dismiss();
                    }
                });

                dialog.show();
            }

            if (synchedTools.size() > 0) {
                final Dialog dialog = dialogInterface.getDialog(getActivity(),
                        R.layout.dialog_confirm_tools_from_api, R.string.tool_confirmation);
                TextView infoTextView = (TextView) dialog.findViewById(R.id.dialog_description_text_view);
                Button cancelButton = (Button) dialog.findViewById(R.id.dialog_bottom_cancel_button);
                Button archiveToolsButton = (Button) dialog.findViewById(R.id.dialog_bottom_add_button);
                final LinearLayout linearLayoutToolContainer = (LinearLayout) dialog
                        .findViewById(R.id.dialog_confirm_tool_main_container_linear_layout);

                infoTextView.setText(R.string.unexpected_tool_removal_info_text);
                archiveToolsButton.setText(R.string.archive);

                for (ToolEntry removedEntry : synchedTools) {
                    ToolLogRow removedToolRow = new ToolLogRow(getActivity(), removedEntry, null);
                    removedToolRow.setToolNotificationImageViewVisibility(false);
                    removedToolRow.setEditToolImageViewVisibility(false);
                    linearLayoutToolContainer.addView(removedToolRow.getView());
                }

                archiveToolsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        for (ToolEntry removedEntry : synchedTools) {
                            removedEntry.setToolStatus(ToolEntryStatus.STATUS_REMOVED);

                            for (int i = 0; i < toolContainer.getChildCount(); i++) {
                                if (removedEntry.getToolId()
                                        .equals(toolContainer.getChildAt(i).getTag().toString())) {
                                    toolContainer.removeViewAt(i);
                                    break;
                                }
                            }
                        }

                        user.writeToSharedPref(v.getContext());
                        dialog.dismiss();
                    }
                });

                cancelButton.setOnClickListener(utilityOnClickListeners.getDismissDialogListener(dialog));
                dialog.show();
            }

            if (unconfirmedRemovedTools.size() > 0) {
                // TODO: If not found server side, tool is assumed to be removed. Inform user.

                final Dialog dialog = dialogInterface.getDialog(getActivity(),
                        R.layout.dialog_confirm_tools_from_api, R.string.reported_tools_removed_title);
                TextView informationTextView = (TextView) dialog
                        .findViewById(R.id.dialog_description_text_view);
                Button cancelButton = (Button) dialog.findViewById(R.id.dialog_bottom_cancel_button);
                Button archiveToolsButton = (Button) dialog.findViewById(R.id.dialog_bottom_add_button);
                final LinearLayout linearLayoutToolContainer = (LinearLayout) dialog
                        .findViewById(R.id.dialog_confirm_tool_main_container_linear_layout);

                informationTextView.setText(getString(R.string.removed_tools_information_text));
                cancelButton.setVisibility(View.GONE);
                archiveToolsButton.setText(getString(R.string.ok));

                for (ToolEntry toolEntry : unconfirmedRemovedTools) {
                    ToolConfirmationRow confirmationRow = new ToolConfirmationRow(getActivity(), toolEntry);
                    linearLayoutToolContainer.addView(confirmationRow.getView());
                }

                archiveToolsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        for (ToolEntry toolEntry : unconfirmedRemovedTools) {
                            toolEntry.setToolStatus(ToolEntryStatus.STATUS_REMOVED);
                        }

                        user.writeToSharedPref(v.getContext());
                        dialog.dismiss();
                    }
                });

                dialog.show();
            }

            if (synchedTools.size() > 0) {
                //                    // TODO: Prompt user: Tool was confirmed, now is no longer at BW, remove or archive?

                final Dialog dialog = dialogInterface.getDialog(getActivity(),
                        R.layout.dialog_confirm_tools_from_api, R.string.tool_confirmation);
                TextView informationTextView = (TextView) dialog
                        .findViewById(R.id.dialog_description_text_view);
                Button cancelButton = (Button) dialog.findViewById(R.id.dialog_bottom_cancel_button);
                Button archiveToolsButton = (Button) dialog.findViewById(R.id.dialog_bottom_add_button);
                final LinearLayout linearLayoutToolContainer = (LinearLayout) dialog
                        .findViewById(R.id.dialog_confirm_tool_main_container_linear_layout);

                informationTextView.setText(getString(R.string.unexpected_tool_removal_info_text));
                archiveToolsButton.setText(getString(R.string.ok));

                for (ToolEntry toolEntry : synchedTools) {
                    ToolConfirmationRow confirmationRow = new ToolConfirmationRow(getActivity(), toolEntry);
                    linearLayoutToolContainer.addView(confirmationRow.getView());
                }

                archiveToolsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        for (ToolEntry toolEntry : synchedTools) {
                            toolEntry.setToolStatus(ToolEntryStatus.STATUS_REMOVED);
                        }

                        user.writeToSharedPref(v.getContext());
                        dialog.dismiss();
                    }
                });

                cancelButton.setOnClickListener(utilityOnClickListeners.getDismissDialogListener(dialog));

                dialog.show();
            }

            user.writeToSharedPref(getActivity());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}