/*
 * Android Scan, an app for scanning and configuring HBM devices.
 *
 * The MIT License (MIT)
 *
 * Copyright (C) Stephan Gatzka
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.hbm.devices.scan.ui.android;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils.TruncateAt;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.List;

import com.hbm.devices.scan.announce.Announce;
import com.hbm.devices.scan.announce.Device;
import com.hbm.devices.scan.announce.Interface;
import com.hbm.devices.scan.announce.IPv4Entry;
import com.hbm.devices.scan.announce.IPv6Entry;
import com.hbm.devices.scan.announce.ServiceEntry;

public final class ConfigureActivity extends AppCompatActivity {

    private Announce announce;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.configure_layout);

        announce = (Announce) getIntent().getSerializableExtra(DeviceDetailsActivity.DETAILS);
    	initToolbar(announce);
    }

    private void initToolbar(Announce announce) {
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        setTitle(getDisplayName(announce.getParams().getDevice()));
    }

   	private String getDisplayName(Device device) {
        StringBuilder title = new StringBuilder(getResources().getText(R.string.configure));
        String displayName = device.getName();
        if (displayName == null || displayName.length() == 0) {
            displayName = device.getUuid();
        }
        title.append(" ");
        title.append(displayName);
        return title.toString();
    }
}

@@ -1272,747 +1272,181 @@
 oid.
-content.Context;%0Aimport android.content.Intent;%0Aimport android.net.Uri;%0Aimport android.os.Build;%0Aimport android.os.Bundle;%0Aimport android.support.v4.app.ActivityCompat;%0Aimport android.support.v4.content.ContextCompat;%0Aimport android.support.v7.app.ActionBar;%0Aimport android.support.v7.app.AppCompatActivity;%0Aimport android.support.v7.widget.AppCompatTextView;%0Aimport android.support.v7.widget.CardView;%0Aimport android.support.v7.widget.Toolbar;%0Aimport android.text.TextUtils.TruncateAt;%0Aimport android.view.Menu;%0Aimport android.view.MenuInflater;%0Aimport android.view.MenuItem;%0Aimport android.view.View;%0Aimport android.widget.LinearLayout.LayoutParams;%0Aimport android.widget.LinearLayout;%0Aimport android.widget.Toast;%0A%0Aimport java.util.List
+os.Bundle;%0Aimport android.support.v7.app.ActionBar;%0Aimport android.support.v7.app.AppCompatActivity;%0Aimport android.support.v7.widget.Toolbar;%0Aimport android.widget.TextView
 ;%0A%0Ai
@@ -1530,20 +1530,28 @@
 ounce.De
-vice
+faultGateway
 ;%0Aimport
@@ -1585,15 +1585,12 @@
 nce.
-Interfa
+Devi
 ce;%0A
@@ -1641,105 +1641,30 @@
 ry;%0A
+%0A
 import 
-com.hbm.devices.scan.announce.IPv6Entry;%0Aimport com.hbm.devices.scan.announce.ServiceEntry
+java.util.List
 ;%0A%0Ap
@@ -2046,16 +2046,1100 @@
 nounce);
+%0A%0A        setCurrentIp(announce);%0A        setCurrentGateway(announce);%0A    %7D%0A%0A    private void setCurrentIp(Announce announce) %7B%0A        List%3CIPv4Entry%3E ipv4Addresses = announce.getParams().getNetSettings().getInterface().getIPv4();%0A        if (!ipv4Addresses.isEmpty()) %7B%0A            IPv4Entry entry = ipv4Addresses.get(0);%0A            TextView currentIp = (TextView) findViewById(R.id.configure_current_ip);%0A            currentIp.setText(entry.getAddress());%0A            TextView currentNetMask = (TextView) findViewById(R.id.configure_current_subnetmask);%0A            currentNetMask.setText(entry.getNetmask());%0A        %7D%0A    %7D%0A%0A    private void setCurrentGateway(Announce announce) %7B%0A        DefaultGateway gateway = announce.getParams().getNetSettings().getDefaultGateway();%0A        if (gateway != null) %7B%0A            String ipv4Gateway = gateway.getIpv4Address();%0A            if (ipv4Gateway != null) %7B%0A                TextView currentGateway = (TextView) findViewById(R.id.configure_current_gateway);%0A                currentGateway.setText(ipv4Gateway);%0A            %7D%0A        %7D
 %0A    %7D%0A%0A

Set current IP settings in ConfigureActivity.