From 075c7c09d718118b054393b8cc316c262b6ff605 Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Fri, 20 Sep 2013 05:28:18 +0000 Subject: [PATCH] First draft of NetDB page: nav drawer w/ ViewPager, tabbed categories --- AndroidManifest.xml.in | 8 +- res/layout/activity_navdrawer_viewpager.xml | 33 ++++ res/layout/fragment_table.xml | 10 ++ res/values/arrays.xml | 1 + .../router/activity/I2PActivityBase.java | 26 ++- .../router/activity/NetDbActivity.java | 150 ++++++++++++++++++ .../android/router/fragment/LogFragment.java | 1 - .../fragment/NetDbSummaryTableFragment.java | 92 +++++++++++ 8 files changed, 311 insertions(+), 10 deletions(-) create mode 100644 res/layout/activity_navdrawer_viewpager.xml create mode 100644 res/layout/fragment_table.xml create mode 100644 src/net/i2p/android/router/activity/NetDbActivity.java create mode 100644 src/net/i2p/android/router/fragment/NetDbSummaryTableFragment.java diff --git a/AndroidManifest.xml.in b/AndroidManifest.xml.in index 50b85f2a1..a3b2b6b25 100644 --- a/AndroidManifest.xml.in +++ b/AndroidManifest.xml.in @@ -40,10 +40,6 @@ android:label="I2P License Information" android:parentActivityName=".activity.HelpActivity" > </activity> - <activity android:name=".activity.PeersActivity" - android:label="Peers Information" - android:parentActivityName=".activity.MainActivity" > - </activity> <activity android:name=".activity.WebActivity" android:label="I2P Web Browser" android:configChanges="orientation|keyboardHidden" > @@ -102,5 +98,9 @@ android:configChanges="orientation|keyboardHidden" android:launchMode="singleTop" > </activity> + <activity android:name=".activity.NetDbActivity" + android:label="NetDB" + android:parentActivityName=".activity.MainActivity" > + </activity> </application> </manifest> diff --git a/res/layout/activity_navdrawer_viewpager.xml b/res/layout/activity_navdrawer_viewpager.xml new file mode 100644 index 000000000..2d8399609 --- /dev/null +++ b/res/layout/activity_navdrawer_viewpager.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.v4.widget.DrawerLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/drawer_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity" > + + <!-- The main content view --> + <android.support.v4.view.ViewPager + android:id="@+id/pager" + android:layout_width="match_parent" + android:layout_height="match_parent" > + <android.support.v4.view.PagerTitleStrip + android:id="@+id/pager_title_strip" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="top" /> + </android.support.v4.view.ViewPager> + + <!-- The navigation drawer --> + <ListView + android:id="@+id/drawer" + android:layout_width="240dp" + android:layout_height="match_parent" + android:layout_gravity="start" + android:choiceMode="singleChoice" + android:divider="@android:color/transparent" + android:dividerHeight="0dp" + android:background="#111"/> + +</android.support.v4.widget.DrawerLayout> \ No newline at end of file diff --git a/res/layout/fragment_table.xml b/res/layout/fragment_table.xml new file mode 100644 index 000000000..5654fd2b1 --- /dev/null +++ b/res/layout/fragment_table.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + <TableLayout + android:id="@+id/table" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> +</ScrollView> diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 6637d9a9c..d9ec951ec 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -7,6 +7,7 @@ <item>@string/label_logs</item> <item>@string/label_graphs</item> <item>@string/label_peers_status</item> + <item>NetDB</item> <item>@string/label_welcome_page</item> <item>@string/label_news</item> <item>@string/label_website_nonanon</item> diff --git a/src/net/i2p/android/router/activity/I2PActivityBase.java b/src/net/i2p/android/router/activity/I2PActivityBase.java index 5332c0998..2adc44700 100644 --- a/src/net/i2p/android/router/activity/I2PActivityBase.java +++ b/src/net/i2p/android/router/activity/I2PActivityBase.java @@ -59,9 +59,18 @@ public abstract class I2PActivityBase extends ActionBarActivity implements /** true leads to a poor install experience, very slow to paint the screen */ protected static final boolean DEFAULT_AUTO_START = false; + /** + * Override this in subclasses that need a ViewPager, such as a + * category view. + * @return whether this Activity needs a ViewPager. + */ + protected boolean useViewPager() { + return false; + } + /** * Override this in subclasses that can use two panes, such as a - * list/detail class. + * list/detail class. * @return whether this Activity can use a two-pane layout. */ protected boolean canUseTwoPanes() { @@ -77,10 +86,13 @@ public abstract class I2PActivityBase extends ActionBarActivity implements _sharedPrefs = getSharedPreferences(SHARED_PREFS, 0); _myDir = getFilesDir().getAbsolutePath(); + // If the Activity wants to use a ViewPager, provide it. // If the Activity can make use of two panes (if available), // load the layout that will enable them. Otherwise, load the // layout that will only ever have a single pane. - if (canUseTwoPanes()) + if (useViewPager()) + setContentView(R.layout.activity_navdrawer_viewpager); + else if (canUseTwoPanes()) setContentView(R.layout.activity_navdrawer); else setContentView(R.layout.activity_navdrawer_onepane); @@ -152,23 +164,27 @@ public abstract class I2PActivityBase extends ActionBarActivity implements startActivity(peers); break; case 6: + Intent netdb = new Intent(I2PActivityBase.this, NetDbActivity.class); + startActivity(netdb); + break; + case 7: Intent wp = new Intent(I2PActivityBase.this, WebActivity.class); wp.putExtra(WebFragment.HTML_RESOURCE_ID, R.raw.welcome_html); startActivity(wp); break; - case 7: + case 8: getSupportFragmentManager() .beginTransaction() .replace(R.id.main_fragment, new NewsFragment()) .addToBackStack(null) .commit(); break; - case 8: + case 9: Intent website = new Intent(I2PActivityBase.this, WebActivity.class); website.putExtra(WebFragment.HTML_URI, "http://www.i2p2.de/"); startActivity(website); break; - case 9: + case 10: Intent faq = new Intent(I2PActivityBase.this, WebActivity.class); faq.putExtra(WebFragment.HTML_URI, "http://www.i2p2.de/faq"); startActivity(faq); diff --git a/src/net/i2p/android/router/activity/NetDbActivity.java b/src/net/i2p/android/router/activity/NetDbActivity.java new file mode 100644 index 000000000..e30600da7 --- /dev/null +++ b/src/net/i2p/android/router/activity/NetDbActivity.java @@ -0,0 +1,150 @@ +package net.i2p.android.router.activity; + +import net.i2p.android.router.R; +import net.i2p.android.router.fragment.NetDbSummaryTableFragment; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBar.Tab; + +public class NetDbActivity extends I2PActivityBase { + static final int TAB_SUMMARY = 0; + static final int TAB_ROUTERS = 1; + static final int TAB_LEASESETS = 2; + private static final String SELECTED_TAB = "selected_tab"; + + NetDbPagerAdapter mNetDbPagerAdapter; + ViewPager mViewPager; + + @Override + protected boolean useViewPager() { + return true; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Set up action bar for tabs + ActionBar actionBar = getSupportActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + // Set up NetDbPagerAdapter containing the categories + mNetDbPagerAdapter = new NetDbPagerAdapter(getSupportFragmentManager()); + + // Set up ViewPager for swiping between categories + mViewPager = (ViewPager) findViewById(R.id.pager); + mViewPager.setAdapter(mNetDbPagerAdapter); + mViewPager.setOnPageChangeListener( + new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + mViewPager.setCurrentItem(position); + } + }); + + // Set up TabListener to update NetDbPagerAdapter with the + // current section to display categories for + ActionBar.TabListener tabListener = new ActionBar.TabListener() { + + public void onTabSelected(Tab tab, FragmentTransaction ft) { + mNetDbPagerAdapter.setCurrentSection(tab.getPosition()); + } + + public void onTabUnselected(Tab tab, FragmentTransaction ft) { + mNetDbPagerAdapter.setCurrentSection(TAB_SUMMARY); + } + + public void onTabReselected(Tab tab, FragmentTransaction ft) { + // User selected the already selected tab. + } + }; + + actionBar.addTab( + actionBar.newTab() + .setText("Statistics") + .setTabListener(tabListener)); + actionBar.addTab( + actionBar.newTab() + .setText("Routers") + .setTabListener(tabListener)); + actionBar.addTab( + actionBar.newTab() + .setText("LeaseSets") + .setTabListener(tabListener)); + + if (savedInstanceState != null) { + int selected = savedInstanceState.getInt(SELECTED_TAB); + actionBar.setSelectedNavigationItem(selected); + } + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(SELECTED_TAB, + getSupportActionBar().getSelectedNavigationIndex()); + } + + public class NetDbPagerAdapter extends FragmentStatePagerAdapter { + private int mSection; + + public NetDbPagerAdapter(FragmentManager fm) { + super(fm); + mSection = TAB_SUMMARY; + } + + public void setCurrentSection(int section) { + // Change the ViewPager item (in case the + // new section doesn't have as many items) + mViewPager.setCurrentItem(0); + // Update the section + mSection = section; + notifyDataSetChanged(); + } + + @Override + public Fragment getItem(int i) { + switch (mSection) { + case TAB_ROUTERS: + case TAB_LEASESETS: + default: // TAB_SUMMARY + return NetDbSummaryTableFragment.newInstance(i); + } + } + + @Override + public int getCount() { + switch (mSection) { + case TAB_ROUTERS: + return 2; + case TAB_LEASESETS: + return 1; + default: // TAB_SUMMARY + return 3; + } + } + + @Override + public CharSequence getPageTitle(int i) { + switch (mSection) { + case TAB_ROUTERS: + case TAB_LEASESETS: + return "CAT " + (i + 1); + default: // TAB_SUMMARY + switch (i) { + case 1: + return "Countries"; + case 2: + return "Transports"; + default: + return "Versions"; + } + } + } + } +} diff --git a/src/net/i2p/android/router/fragment/LogFragment.java b/src/net/i2p/android/router/fragment/LogFragment.java index 2a9fe63d5..30ee6ae31 100644 --- a/src/net/i2p/android/router/fragment/LogFragment.java +++ b/src/net/i2p/android/router/fragment/LogFragment.java @@ -10,7 +10,6 @@ import java.util.Collections; import java.util.List; import net.i2p.I2PAppContext; import net.i2p.android.router.R; -import net.i2p.android.router.util.Util; public class LogFragment extends ListFragment { diff --git a/src/net/i2p/android/router/fragment/NetDbSummaryTableFragment.java b/src/net/i2p/android/router/fragment/NetDbSummaryTableFragment.java new file mode 100644 index 000000000..ee01e4698 --- /dev/null +++ b/src/net/i2p/android/router/fragment/NetDbSummaryTableFragment.java @@ -0,0 +1,92 @@ +package net.i2p.android.router.fragment; + +import net.i2p.android.router.R; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; + +public class NetDbSummaryTableFragment extends Fragment { + private static final String CATEGORY = "category"; + + private int mCategory; + private TableLayout mTable; + + public static NetDbSummaryTableFragment newInstance(int category) { + NetDbSummaryTableFragment f = new NetDbSummaryTableFragment(); + Bundle args = new Bundle(); + args.putInt(CATEGORY, category); + f.setArguments(args); + return f; + } + + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.fragment_table, container, false); + + mCategory = getArguments().getInt(CATEGORY); + + mTable = (TableLayout) v.findViewById(R.id.table); + createTableTitle(); + addTableRow("foo", "123"); + addTableRow("bar", "45"); + if (mCategory == 2) + addTableRow("bing", "67"); + + return v; + } + + private void createTableTitle() { + TableRow titleRow; + TextView tl1, tl2; + + titleRow = new TableRow(getActivity()); + titleRow.setPadding(10, 0, 0, 0); + + tl1 = new TextView(getActivity()); + tl1.setTextSize(20); + tl2 = new TextView(getActivity()); + tl2.setTextSize(20); + + switch (mCategory) { + case 1: + tl1.setText("Transports"); + break; + case 2: + tl1.setText("Country"); + break; + default: + tl1.setText("Version"); + break; + } + tl2.setText("Count"); + + titleRow.addView(tl1); + titleRow.addView(tl2); + + mTable.addView(titleRow); + } + + private void addTableRow(String name, String count) { + TableRow row; + TextView tl1, tl2; + + row = new TableRow(getActivity()); + row.setPadding(10, 0, 0, 0); + + tl1 = new TextView(getActivity()); + tl2 = new TextView(getActivity()); + + tl1.setText(name); + tl2.setText(count); + + row.addView(tl1); + row.addView(tl2); + + mTable.addView(row); + } +} -- GitLab