replaced deprecated ActionBarActivity with AppCompatAcitivity.
replaced tab navigation with navigation drawer
1
CREDITS
@ -42,6 +42,7 @@ License: http://creativecommons.org/licenses/by/3.0/
|
||||
* Madebyoliver (https://www.flaticon.com/authors/madebyoliver)
|
||||
* Those Icons (https://www.flaticon.com/authors/those-icons)
|
||||
* Smashicons (https://www.flaticon.com/authors/smashicons)
|
||||
* Swifticons https://www.flaticon.com/authors/swifticons
|
||||
|
||||
Contributors to openScale are listed on:
|
||||
https://github.com/oliexdev/openScale/graphs/contributors
|
||||
|
@ -22,20 +22,23 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.health.openscale.R;
|
||||
@ -49,29 +52,16 @@ import com.health.openscale.gui.fragments.OverviewFragment;
|
||||
import com.health.openscale.gui.fragments.StatisticsFragment;
|
||||
import com.health.openscale.gui.fragments.TableFragment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity implements
|
||||
ActionBar.TabListener {
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a {@link FragmentPagerAdapter}
|
||||
* derivative, which will keep every loaded fragment in memory. If this
|
||||
* becomes too memory intensive, it may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static boolean firstAppStart = true;
|
||||
private static int bluetoothStatusIcon = R.drawable.ic_bluetooth_disabled;
|
||||
private static MenuItem bluetoothStatus;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
private DrawerLayout drawerLayout;
|
||||
private Toolbar toolbar;
|
||||
private NavigationView navDrawer;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
|
||||
|
||||
@Override
|
||||
@ -80,43 +70,43 @@ public class MainActivity extends ActionBarActivity implements
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
// Set a Toolbar to replace the ActionBar.
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// Set up the action bar.
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
actionBar.setLogo(R.drawable.ic_launcher_openscale);
|
||||
// Find our drawer view
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
// Find our drawer view
|
||||
navDrawer = (NavigationView) findViewById(R.id.navigation_view);
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
//Create Drawer Toggle
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open_drawer, R.string.close_drawer){
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
}
|
||||
|
||||
// When swiping between different sections, select the corresponding
|
||||
// tab. We can also use ActionBar.Tab#select() to do this if we have
|
||||
// a reference to the Tab.
|
||||
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
super.onDrawerClosed(drawerView);
|
||||
}
|
||||
};
|
||||
|
||||
// For each of the sections in the app, add a tab to the action bar.
|
||||
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
|
||||
// Create a tab with text corresponding to the page title defined by
|
||||
// the adapter. Also specify this Activity object, which implements
|
||||
// the TabListener interface, as the callback (listener) for when
|
||||
// this tab is selected.
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(mSectionsPagerAdapter.getPageTitle(i))
|
||||
.setTabListener(this));
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
|
||||
// Setup drawer view
|
||||
setupDrawerContent(navDrawer);
|
||||
|
||||
// Initial first fragment
|
||||
if(savedInstanceState == null) {
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content,new OverviewFragment()).commit();
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if (prefs.getBoolean("firstStart", true)) {
|
||||
Intent intent = new Intent(this, UserSettingsActivity.class);
|
||||
@ -127,10 +117,90 @@ public class MainActivity extends ActionBarActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDrawerContent(NavigationView navigationView) {
|
||||
navigationView.setNavigationItemSelectedListener(
|
||||
|
||||
new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
||||
selectDrawerItem(menuItem);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void selectDrawerItem(MenuItem menuItem) {
|
||||
// Create a new fragment and specify the fragment to show based on nav item clicked
|
||||
Fragment fragment = null;
|
||||
Class fragmentClass;
|
||||
|
||||
switch(menuItem.getItemId()) {
|
||||
case R.id.nav_overview:
|
||||
fragmentClass = OverviewFragment.class;
|
||||
break;
|
||||
case R.id.nav_graph:
|
||||
fragmentClass = GraphFragment.class;
|
||||
break;
|
||||
case R.id.nav_table:
|
||||
fragmentClass = TableFragment.class;
|
||||
break;
|
||||
case R.id.nav_statistic:
|
||||
fragmentClass = StatisticsFragment.class;
|
||||
break;
|
||||
default:
|
||||
fragmentClass = OverviewFragment.class;
|
||||
}
|
||||
|
||||
try {
|
||||
fragment = (Fragment) fragmentClass.newInstance();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Insert the fragment by replacing any existing fragment
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.fragment_content, fragment).commit();
|
||||
|
||||
// Highlight the selected item has been done by NavigationView
|
||||
menuItem.setChecked(true);
|
||||
|
||||
// Set action bar title
|
||||
//setTitle(menuItem.getTitle());
|
||||
|
||||
// Close the navigation drawer
|
||||
drawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if(drawerToggle.onOptionsItemSelected(item)){
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
drawerLayout.openDrawer(GravityCompat.START);
|
||||
return true;
|
||||
case R.id.action_general_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivityForResult(intent, 1);
|
||||
return true;
|
||||
case R.id.action_bluetooth_status:
|
||||
invokeSearchBluetoothDevice();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
getMenuInflater().inflate(R.menu.action_menu, menu);
|
||||
|
||||
bluetoothStatus = menu.findItem(R.id.action_bluetooth_status);
|
||||
|
||||
@ -149,21 +219,15 @@ public class MainActivity extends ActionBarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
drawerToggle.syncState();
|
||||
}
|
||||
|
||||
if (id == R.id.action_general_settings) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivityForResult(intent, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id == R.id.action_bluetooth_status) {
|
||||
invokeSearchBluetoothDevice();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig){
|
||||
super.onConfigurationChanged(newConfig);
|
||||
drawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
private void invokeSearchBluetoothDevice() {
|
||||
@ -253,107 +317,4 @@ public class MainActivity extends ActionBarActivity implements
|
||||
bluetoothStatusIcon = iconRessource;
|
||||
bluetoothStatus.setIcon(getResources().getDrawable(bluetoothStatusIcon));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
// When the given tab is selected, switch to the corresponding page in
|
||||
// the ViewPager.
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
if (requestCode == 1) {
|
||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private OverviewFragment overviewFrag;
|
||||
private GraphFragment graphFrag;
|
||||
private TableFragment tableFrag;
|
||||
private StatisticsFragment statisticsFrag;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
||||
overviewFrag = new OverviewFragment();
|
||||
graphFrag = new GraphFragment();
|
||||
tableFrag = new TableFragment();
|
||||
statisticsFrag = new StatisticsFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
// Return a PlaceholderFragment (defined as a static inner class
|
||||
// below).
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
return overviewFrag;
|
||||
case 1:
|
||||
return graphFrag;
|
||||
case 2:
|
||||
return tableFrag;
|
||||
case 3:
|
||||
return statisticsFrag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
Locale l = Locale.getDefault();
|
||||
switch (position) {
|
||||
case 0:
|
||||
return getString(R.string.title_overview).toUpperCase(l);
|
||||
case 1:
|
||||
return getString(R.string.title_graph).toUpperCase(l);
|
||||
case 2:
|
||||
return getString(R.string.title_table).toUpperCase(l);
|
||||
case 3:
|
||||
return getString(R.string.title_statistics).toUpperCase(l);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
return POSITION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDataSetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
|
||||
tableFrag = new TableFragment();
|
||||
graphFrag = new GraphFragment();
|
||||
overviewFrag = new OverviewFragment();
|
||||
statisticsFrag = new StatisticsFragment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 435 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 477 B |
After Width: | Height: | Size: 261 B |
After Width: | Height: | Size: 241 B |
After Width: | Height: | Size: 243 B |
After Width: | Height: | Size: 308 B |
After Width: | Height: | Size: 293 B |
After Width: | Height: | Size: 358 B |
After Width: | Height: | Size: 548 B |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 587 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 755 B |
After Width: | Height: | Size: 698 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 879 B |
@ -1,6 +1,44 @@
|
||||
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/pager"
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.health.openscale.gui.MainActivity" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- This LinearLayout represents the contents of the screen -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- The ActionBar displayed at the top -->
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:background="?attr/colorPrimaryDark">
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<!-- action_menumain content view where fragments are loaded -->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- The navigation drawer that comes from the left -->
|
||||
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/navigation_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
app:menu="@menu/drawer_view" />
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
26
android_app/app/src/main/res/menu/drawer_view.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group android:checkableBehavior="single">
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_overview"
|
||||
android:icon="@drawable/ic_preferences_home"
|
||||
android:title="@string/title_overview" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_graph"
|
||||
android:icon="@drawable/ic_preferences_graph"
|
||||
android:title="@string/title_graph" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_table"
|
||||
android:icon="@drawable/ic_preferences_table"
|
||||
android:title="@string/title_table" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_statistic"
|
||||
android:icon="@drawable/ic_preferences_statistics"
|
||||
android:title="@string/title_statistics" />
|
||||
|
||||
</group>
|
||||
</menu>
|
@ -1,12 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -13,6 +13,8 @@
|
||||
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_bluetooth_status">Bluetooth Status</string>
|
||||
<string name="open_drawer">open</string>
|
||||
<string name="close_drawer">close</string>
|
||||
|
||||
<string name="label_add">Add</string>
|
||||
<string name="label_cancel">Cancel</string>
|
||||
|
@ -1,20 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
<item name="colorPrimary">#000000</item>
|
||||
<item name="colorPrimaryDark">#000000</item>
|
||||
<item name="colorAccent">@android:color/holo_blue_light</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|