Fix some of the lint warnigns
Change-Id: I437e41c646b4edd81ef9ba05a303bdfc232d0f94
diff --git a/app/src/main/java/net/named_data/nfd/DrawerFragment.java b/app/src/main/java/net/named_data/nfd/DrawerFragment.java
index 60144a0..79dfce9 100644
--- a/app/src/main/java/net/named_data/nfd/DrawerFragment.java
+++ b/app/src/main/java/net/named_data/nfd/DrawerFragment.java
@@ -1,18 +1,18 @@
/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2015-2017 Regents of the University of California
- *
+ * <p/>
* This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
* See AUTHORS.md for complete list of NFD Android authors and contributors.
- *
+ * <p/>
* NFD Android is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
- *
+ * <p/>
* NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ * <p/>
* You should have received a copy of the GNU General Public License along with
* NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -23,13 +23,14 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
+import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.ViewDragHelper;
import android.support.v7.app.ActionBar;
@@ -64,6 +65,7 @@
return fragment;
}
+ @SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@@ -167,7 +169,7 @@
// Allow update calls to onCreateOptionsMenu() and
// onPrepareOptionsMenu() to update Menu UI.
m_shouldHideOptionsMenu = false;
- getActivity().supportInvalidateOptionsMenu();
+ getActivity().invalidateOptionsMenu();
}
@Override
@@ -188,7 +190,7 @@
// Allow update calls to onCreateOptionsMenu() and
// onPrepareOptionsMenu() to update Menu UI
m_shouldHideOptionsMenu = true;
- getActivity().supportInvalidateOptionsMenu();
+ getActivity().invalidateOptionsMenu();
}
@Override
@@ -197,12 +199,12 @@
if (newState != ViewDragHelper.STATE_IDLE) {
// opened/closed is handled by onDrawerOpened and onDrawerClosed callbacks
m_shouldHideOptionsMenu = true;
- getActivity().supportInvalidateOptionsMenu();
- } else if (newState == ViewDragHelper.STATE_IDLE && !isDrawerOpen()) {
+ getActivity().invalidateOptionsMenu();
+ } else if (!isDrawerOpen()) {
// This condition takes care of the case of displaying the option menu
// items when the drawer is retracted prematurely.
m_shouldHideOptionsMenu = false;
- getActivity().supportInvalidateOptionsMenu();
+ getActivity().invalidateOptionsMenu();
}
}
};
@@ -221,7 +223,7 @@
}
});
- m_drawerLayout.setDrawerListener(m_drawerToggle);
+ m_drawerLayout.addDrawerListener(m_drawerToggle);
}
@Override
@@ -370,24 +372,23 @@
}
};
- public
DrawerItem(int itemNameId, int resIconId, int itemCode) {
m_itemNameId = itemNameId;
m_iconResId = resIconId;
m_itemCode = itemCode;
}
- public int
+ int
getItemName() {
return m_itemNameId;
}
- public int
+ int
getIconResId() {
return m_iconResId;
}
- public int
+ int
getItemCode() {
return m_itemCode;
}
@@ -411,35 +412,37 @@
*/
private static class DrawerListAdapter extends ArrayAdapter<DrawerItem> {
- public DrawerListAdapter(Context context, ArrayList<DrawerItem> drawerItems) {
+ DrawerListAdapter(Context context, ArrayList<DrawerItem> drawerItems) {
super(context, 0, drawerItems);
m_layoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- m_resources = context.getResources();
+ m_context = context;
}
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ @Override @NonNull
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
DrawerItemHolder holder;
if (convertView == null) {
holder = new DrawerItemHolder();
- convertView = m_layoutInflater.inflate(R.layout.list_item_drawer_item, null);
+ convertView = m_layoutInflater.inflate(R.layout.list_item_drawer_item, parent, false);
convertView.setTag(holder);
- holder.m_icon = (ImageView) convertView.findViewById(R.id.drawer_item_icon);
- holder.m_text = (TextView) convertView.findViewById(R.id.drawer_item_text);
+ holder.m_icon = convertView.findViewById(R.id.drawer_item_icon);
+ holder.m_text = convertView.findViewById(R.id.drawer_item_text);
} else {
holder = (DrawerItemHolder)convertView.getTag();
}
// Update items in holder
DrawerItem item = getItem(position);
- if (item.getIconResId() != 0) {
- holder.m_icon.setImageDrawable(m_resources.getDrawable(item.getIconResId()));
+ if (item != null) {
+ if (item.getIconResId() != 0) {
+ holder.m_icon.setImageDrawable(ContextCompat.getDrawable(m_context, item.getIconResId()));
+ }
+ holder.m_text.setText(item.getItemName());
}
- holder.m_text.setText(item.getItemName());
return convertView;
}
@@ -453,13 +456,13 @@
private final LayoutInflater m_layoutInflater;
/** Reference to get context's resources */
- private final Resources m_resources;
+ private final Context m_context;
}
//////////////////////////////////////////////////////////////////////////////
/** Callback that host activity must implement */
- public static interface DrawerCallbacks {
+ public interface DrawerCallbacks {
/** Callback to host activity when a drawer item is selected */
void onDrawerItemSelected(int itemCode, int itemNameId);
}
diff --git a/app/src/main/java/net/named_data/nfd/FaceListFragment.java b/app/src/main/java/net/named_data/nfd/FaceListFragment.java
index 022ec32..a8faa90 100644
--- a/app/src/main/java/net/named_data/nfd/FaceListFragment.java
+++ b/app/src/main/java/net/named_data/nfd/FaceListFragment.java
@@ -1,18 +1,18 @@
/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2015-2017 Regents of the University of California
- *
+ * <p/>
* This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
* See AUTHORS.md for complete list of NFD Android authors and contributors.
- *
+ * <p/>
* NFD Android is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
- *
+ * <p/>
* NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ * <p/>
* You should have received a copy of the GNU General Public License along with
* NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -27,6 +27,7 @@
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
+import android.support.v4.content.ContextCompat;
import android.util.Pair;
import android.util.SparseArray;
import android.view.ActionMode;
@@ -75,17 +76,15 @@
{
super.onViewCreated(view, savedInstanceState);
- @SuppressLint("InflateParams")
- View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_face_list_list_header, null);
+ View v = getLayoutInflater().inflate(R.layout.fragment_face_list_list_header, getListView(), false);
getListView().addHeaderView(v, null, false);
- getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));
+ getListView().setDivider(ContextCompat.getDrawable(getContext(), R.drawable.list_item_divider));
// Get info unavailable view
m_faceListInfoUnavailableView = v.findViewById(R.id.face_list_info_unavailable);
// Get progress bar spinner view
- m_reloadingListProgressBar
- = (ProgressBar)v.findViewById(R.id.face_list_reloading_list_progress_bar);
+ m_reloadingListProgressBar = v.findViewById(R.id.face_list_reloading_list_progress_bar);
// Setup list view for deletion
ListView listView = getListView();
@@ -209,6 +208,7 @@
}
}
+ @SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
diff --git a/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java b/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
index f37a455..143ed58 100644
--- a/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
+++ b/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
@@ -1,30 +1,31 @@
/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015 Regents of the University of California
- *
+/*
+ * Copyright (c) 2015-2017 Regents of the University of California
+ * <p/>
* This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
* See AUTHORS.md for complete list of NFD Android authors and contributors.
- *
+ * <p/>
* NFD Android is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
- *
+ * <p/>
* NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ * <p/>
* You should have received a copy of the GNU General Public License along with
* NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
package net.named_data.nfd;
-import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
+import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -80,9 +81,9 @@
{
super.onViewCreated(view, savedInstanceState);
- View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_face_detail_list_header, null);
+ View v = getLayoutInflater().inflate(R.layout.fragment_face_detail_list_header, getListView(), false);
getListView().addHeaderView(v, null, false);
- getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));
+ getListView().setDivider(ContextCompat.getDrawable(getContext(), R.drawable.list_item_divider));
}
@Override
@@ -91,7 +92,9 @@
super.onActivityCreated(savedInstanceState);
if (m_faceStatusAdapter == null) {
- m_listItems = new ArrayList<>();
+ // List items to be displayed; Used when creating
+ // {@link net.named_data.nfd.FaceStatusFragment.FaceStatusAdapter}
+ ArrayList<ListItem> listItems = new ArrayList<>();
Resources res = getResources();
m_scopes = res.getStringArray(R.array.face_scopes);
@@ -102,31 +105,34 @@
FaceStatus faceStatus = new FaceStatus();
try {
byte[] args = getArguments().getByteArray(EXTRA_FACE_INFORMATION);
+ if (args == null) {
+ throw new EncodingException("Not extra face in formation available");
+ }
faceStatus.wireDecode(new Blob(args).buf());
} catch (EncodingException e) {
G.Log("EXTRA_FACE_INFORMATION: EncodingException: " + e);
}
// Creating list of items to be displayed
- m_listItems.add(new ListItem(R.string.face_id, String.valueOf(faceStatus.getFaceId())));
- m_listItems.add(new ListItem(R.string.local_face_uri, faceStatus.getLocalUri()));
- m_listItems.add(new ListItem(R.string.remote_face_uri, faceStatus.getRemoteUri()));
- m_listItems.add(new ListItem(R.string.expires_in, faceStatus.getExpirationPeriod() < 0 ?
+ listItems.add(new ListItem(R.string.face_id, String.valueOf(faceStatus.getFaceId())));
+ listItems.add(new ListItem(R.string.local_face_uri, faceStatus.getLocalUri()));
+ listItems.add(new ListItem(R.string.remote_face_uri, faceStatus.getRemoteUri()));
+ listItems.add(new ListItem(R.string.expires_in, faceStatus.getExpirationPeriod() < 0 ?
getString(R.string.expire_never) :
PeriodFormat.getDefault().print(new Period(faceStatus.getExpirationPeriod()))));
- m_listItems.add(new ListItem(R.string.face_scope, getScope(faceStatus.getFaceScope())));
- m_listItems.add(new ListItem(R.string.face_persistency, getPersistency(faceStatus.getFacePersistency())));
- m_listItems.add(new ListItem(R.string.link_type, getLinkType(faceStatus.getLinkType())));
- m_listItems.add(new ListItem(R.string.in_interests, String.valueOf(
+ listItems.add(new ListItem(R.string.face_scope, getScope(faceStatus.getFaceScope())));
+ listItems.add(new ListItem(R.string.face_persistency, getPersistency(faceStatus.getFacePersistency())));
+ listItems.add(new ListItem(R.string.link_type, getLinkType(faceStatus.getLinkType())));
+ listItems.add(new ListItem(R.string.in_interests, String.valueOf(
faceStatus.getNInInterests())));
- m_listItems.add(new ListItem(R.string.in_data, String.valueOf(faceStatus.getNInDatas())));
- m_listItems.add(new ListItem(R.string.out_interests, String.valueOf(
+ listItems.add(new ListItem(R.string.in_data, String.valueOf(faceStatus.getNInDatas())));
+ listItems.add(new ListItem(R.string.out_interests, String.valueOf(
faceStatus.getNOutInterests())));
- m_listItems.add(new ListItem(R.string.out_data, String.valueOf(faceStatus.getNOutDatas())));
- m_listItems.add(new ListItem(R.string.in_bytes, String.valueOf(faceStatus.getNInBytes())));
- m_listItems.add(new ListItem(R.string.out_bytes, String.valueOf(faceStatus.getNOutBytes())));
+ listItems.add(new ListItem(R.string.out_data, String.valueOf(faceStatus.getNOutDatas())));
+ listItems.add(new ListItem(R.string.in_bytes, String.valueOf(faceStatus.getNInBytes())));
+ listItems.add(new ListItem(R.string.out_bytes, String.valueOf(faceStatus.getNOutBytes())));
- m_faceStatusAdapter = new FaceStatusAdapter(getActivity(), m_listItems);
+ m_faceStatusAdapter = new FaceStatusAdapter(getActivity(), listItems);
}
// setListAdapter must be called after addHeaderView. Otherwise, there is an exception on some platforms.
// http://stackoverflow.com/a/8141537/2150331
@@ -164,7 +170,7 @@
* {@link net.named_data.nfd.FaceStatusFragment.FaceStatusAdapter}.
*/
private static class ListItem {
- public ListItem(int title, String value) {
+ ListItem(int title, String value) {
m_title = title;
m_value = value;
}
@@ -198,25 +204,26 @@
m_layoutInflater = LayoutInflater.from(context);
}
- @SuppressLint("InflateParams")
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ @Override @NonNull
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ListItemHolder holder;
if (convertView == null) {
holder = new ListItemHolder();
- convertView = m_layoutInflater.inflate(R.layout.list_item_face_generic_item, null);
+ convertView = m_layoutInflater.inflate(R.layout.list_item_face_generic_item, parent, false);
convertView.setTag(holder);
- holder.m_title = (TextView)convertView.findViewById(R.id.list_item_generic_title);
- holder.m_value = (TextView)convertView.findViewById(R.id.list_item_generic_value);
+ holder.m_title = convertView.findViewById(R.id.list_item_generic_title);
+ holder.m_value = convertView.findViewById(R.id.list_item_generic_value);
} else {
holder = (ListItemHolder)convertView.getTag();
}
ListItem info = getItem(position);
- holder.m_title.setText(info.getTitle());
- holder.m_value.setText(info.getValue());
+ if (info != null) {
+ holder.m_title.setText(info.getTitle());
+ holder.m_value.setText(info.getValue());
+ }
return convertView;
}
@@ -235,12 +242,6 @@
private static final String EXTRA_FACE_INFORMATION
= "net.named_data.nfd.face_detail_fragment_face_id";
- /**
- * List items to be displayed; Used when creating
- * {@link net.named_data.nfd.FaceStatusFragment.FaceStatusAdapter}
- */
- private ArrayList<ListItem> m_listItems;
-
/** Reference to custom {@link net.named_data.nfd.FaceStatusFragment.FaceStatusAdapter} */
private FaceStatusAdapter m_faceStatusAdapter;
diff --git a/app/src/main/java/net/named_data/nfd/LogcatSettingsFragment.java b/app/src/main/java/net/named_data/nfd/LogcatSettingsFragment.java
index 7368c3a..1cb1b82 100644
--- a/app/src/main/java/net/named_data/nfd/LogcatSettingsFragment.java
+++ b/app/src/main/java/net/named_data/nfd/LogcatSettingsFragment.java
@@ -1,25 +1,24 @@
/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015 Regents of the University of California
- *
+/*
+ * Copyright (c) 2015-2017 Regents of the University of California
+ * <p/>
* This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
* See AUTHORS.md for complete list of NFD Android authors and contributors.
- *
+ * <p/>
* NFD Android is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
- *
+ * <p/>
* NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ * <p/>
* You should have received a copy of the GNU General Public License along with
* NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
package net.named_data.nfd;
-import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -32,6 +31,7 @@
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.ListFragment;
+import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -62,9 +62,9 @@
{
super.onViewCreated(view, savedInstanceState);
- View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_logcat_tags_list_header, null);
+ View v = getLayoutInflater().inflate(R.layout.fragment_logcat_tags_list_header, getListView(), false);
getListView().addHeaderView(v, null, false);
- getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));
+ getListView().setDivider(ContextCompat.getDrawable(getContext(), R.drawable.list_item_divider));
// @TODO implement log item removal
// ListView listView = (ListView) v.findViewById(android.R.id.list);
@@ -222,31 +222,32 @@
*/
private static class LogcatSettingsAdapter extends ArrayAdapter<LogcatSettingItem> {
- public LogcatSettingsAdapter(Context context, ArrayList<LogcatSettingItem> objects) {
+ LogcatSettingsAdapter(Context context, ArrayList<LogcatSettingItem> objects) {
super(context, 0, objects);
m_layoutInflater = LayoutInflater.from(context);
}
- @SuppressLint("InflateParams")
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ @Override @NonNull
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
SettingItemHolder holder;
if (convertView == null) {
holder = new SettingItemHolder();
- convertView = m_layoutInflater.inflate(R.layout.list_item_setting_item, null);
+ convertView = m_layoutInflater.inflate(R.layout.list_item_setting_item, parent, false);
convertView.setTag(holder);
- holder.m_logTag = (TextView) convertView.findViewById(R.id.list_item_log_tag);
- holder.m_logLevel = (TextView) convertView.findViewById(R.id.list_item_setting_log_level);
+ holder.m_logTag = convertView.findViewById(R.id.list_item_log_tag);
+ holder.m_logLevel = convertView.findViewById(R.id.list_item_setting_log_level);
} else {
holder = (SettingItemHolder) convertView.getTag();
}
LogcatSettingItem item = getItem(position);
- holder.m_logTag.setText(item.getLogTag());
- holder.m_logLevel.setText(item.getLogLevel());
+ if (item != null) {
+ holder.m_logTag.setText(item.getLogTag());
+ holder.m_logLevel.setText(item.getLogLevel());
+ }
return convertView;
}
diff --git a/app/src/main/java/net/named_data/nfd/MainFragment.java b/app/src/main/java/net/named_data/nfd/MainFragment.java
index f7a6f2e..276c6e1 100644
--- a/app/src/main/java/net/named_data/nfd/MainFragment.java
+++ b/app/src/main/java/net/named_data/nfd/MainFragment.java
@@ -202,7 +202,8 @@
private void
startNfdService() {
- assert m_isNfdServiceConnected;
+ if (BuildConfig.DEBUG && !m_isNfdServiceConnected)
+ throw new RuntimeException("Service must be connected at this point");
m_nfdStartStopSwitch.setText(R.string.starting_nfd);
sendNfdServiceMessage(NfdService.START_NFD_SERVICE);
@@ -210,7 +211,8 @@
private void
stopNfdService() {
- assert m_isNfdServiceConnected;
+ if (BuildConfig.DEBUG && !m_isNfdServiceConnected)
+ throw new RuntimeException("Service must be connected at this point");
m_nfdStartStopSwitch.setText(R.string.stopping_nfd);
sendNfdServiceMessage(NfdService.STOP_NFD_SERVICE);
diff --git a/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java b/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
index 4e77718..435ee88 100644
--- a/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
+++ b/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
@@ -1,3 +1,22 @@
+/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2015-2017 Regents of the University of California
+ * <p/>
+ * This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
+ * See AUTHORS.md for complete list of NFD Android authors and contributors.
+ * <p/>
+ * NFD Android is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ * <p/>
+ * NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ * <p/>
+ * You should have received a copy of the GNU General Public License along with
+ * NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
package net.named_data.nfd;
import android.app.Activity;
@@ -7,6 +26,7 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
+import android.support.v4.content.ContextCompat;
import android.util.Pair;
import android.view.ActionMode;
import android.view.LayoutInflater;
@@ -32,7 +52,6 @@
import net.named_data.jndn.Name;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.util.Blob;
-import net.named_data.jndn_xx.util.FaceUri;
import net.named_data.nfd.utils.G;
import net.named_data.nfd.utils.NfdcHelper;
@@ -54,6 +73,7 @@
return fragment;
}
+ @SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity)
{
@@ -72,7 +92,13 @@
m_ribEntry = new RibEntry();
try {
- m_ribEntry.wireDecode(new Blob(getArguments().getByteArray(ROUTE_INFORMATION)).buf());
+ byte[] data = getArguments().getByteArray(ROUTE_INFORMATION);
+ if (data != null) {
+ m_ribEntry.wireDecode(new Blob(data).buf());
+ }
+ else {
+ throw new EncodingException("No route information data");
+ }
}
catch (EncodingException e) {
G.Log("ROUTE_INFORMATION: EncodingException: " + e);
@@ -83,15 +109,15 @@
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
- View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_route_detail_list_header, null);
+ View v = getLayoutInflater().inflate(R.layout.fragment_route_detail_list_header, getListView(), false);
getListView().addHeaderView(v, null, false);
- getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));
+ getListView().setDivider(ContextCompat.getDrawable(getContext(), R.drawable.list_item_divider));
- TextView prefix = (TextView)v.findViewById(R.id.route_detail_prefix);
+ TextView prefix = v.findViewById(R.id.route_detail_prefix);
prefix.setText(m_ribEntry.getName().toUri());
// Get progress bar spinner view
- m_reloadingListProgressBar = (ProgressBar)v.findViewById(R.id.route_detail_list_reloading_list_progress_bar);
+ m_reloadingListProgressBar = v.findViewById(R.id.route_detail_list_reloading_list_progress_bar);
ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
diff --git a/app/src/main/java/net/named_data/nfd/RouteListFragment.java b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
index 275dcde..f461dce 100644
--- a/app/src/main/java/net/named_data/nfd/RouteListFragment.java
+++ b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
@@ -1,18 +1,18 @@
/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2015-2017 Regents of the University of California
- * <p>
+ * <p/>
* This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
* See AUTHORS.md for complete list of NFD Android authors and contributors.
- * <p>
+ * <p/>
* NFD Android is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
- * <p>
+ * <p/>
* NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- * <p>
+ * <p/>
* You should have received a copy of the GNU General Public License along with
* NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -26,6 +26,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
+import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
@@ -95,20 +96,19 @@
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_route_list_list_header, null);
+ View v = getLayoutInflater().inflate(R.layout.fragment_route_list_list_header, getListView(), false);
getListView().addHeaderView(v, null, false);
- getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));
+ getListView().setDivider(ContextCompat.getDrawable(getContext(), R.drawable.list_item_divider));
m_routeListInfoUnavailableView = v.findViewById(R.id.route_list_info_unavailable);
// Get progress bar spinner view
- m_reloadingListProgressBar = (ProgressBar) v.findViewById(R.id.route_list_reloading_list_progress_bar);
+ m_reloadingListProgressBar = v.findViewById(R.id.route_list_reloading_list_progress_bar);
getListView().setLongClickable(true);
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
final RibEntry entry = (RibEntry) parent.getItemAtPosition(position);
- ;
new AlertDialog.Builder(v.getContext())
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Deleting route")
@@ -126,7 +126,6 @@
.setNegativeButton("No", null)
.show();
-
return true;
}
});
@@ -357,11 +356,11 @@
if (convertView == null) {
holder = new RouteItemHolder();
- convertView = m_layoutInflater.inflate(R.layout.list_item_route_item, null);
+ convertView = m_layoutInflater.inflate(R.layout.list_item_route_item, parent, false);
convertView.setTag(holder);
- holder.m_uri = (TextView) convertView.findViewById(R.id.list_item_route_uri);
- holder.m_faceList = (TextView) convertView.findViewById(R.id.list_item_face_list);
+ holder.m_uri = convertView.findViewById(R.id.list_item_route_uri);
+ holder.m_faceList = convertView.findViewById(R.id.list_item_face_list);
} else {
holder = (RouteItemHolder) convertView.getTag();
}
@@ -459,9 +458,7 @@
}
nfdcHelper.shutdown();
return "OK";
- } catch (FaceUri.CanonizeError e) {
- return "Error creating face (" + e.getMessage() + ")";
- } catch (FaceUri.Error e) {
+ } catch (FaceUri.CanonizeError|FaceUri.Error e) {
return "Error creating face (" + e.getMessage() + ")";
} catch (Exception e) {
return "Error communicating with NFD (" + e.getMessage() + ")";
@@ -503,7 +500,7 @@
private class RouteRemoveAsyncTask extends AsyncTask<Void, Void, String> {
- public RouteRemoveAsyncTask(Name prefix, List<Integer> faceIds) {
+ RouteRemoveAsyncTask(Name prefix, List<Integer> faceIds) {
m_prefix = prefix;
m_faceList = faceIds;
}
@@ -514,9 +511,7 @@
try {
removeRouteSyncs(getActivity().getApplicationContext(), m_prefix, m_faceList);
return "OK";
- } catch (FaceUri.CanonizeError e) {
- return "Error destroying face (" + e.getMessage() + ")";
- } catch (FaceUri.Error e) {
+ } catch (FaceUri.CanonizeError|FaceUri.Error e) {
return "Error destroying face (" + e.getMessage() + ")";
} catch (Exception e) {
return "Error communicating with NFD (" + e.getMessage() + ")";
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index b0d48f1..2fc1654 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -7,7 +7,7 @@
<LinearLayout
style="@style/default_linear_layout_padding"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
android:orientation="vertical"
>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 0c82fa3..b9519a1 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="ndn_color_fire_bush" type="color">#DB9710</item>
- <item name="ndn_color_grenadier" type="color">#C04818</item>
<item name="android_color_gray" type="color">#C6C6C6</item>
-</resources>
\ No newline at end of file
+</resources>