Commit a6c9e8c8 authored by Roger Barton's avatar Roger Barton
Browse files

Added pageview, toolbar, UI additions

parent 1bfb032a
......@@ -14,14 +14,14 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:label=""
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppThemeLight">
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:label=""
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
......@@ -29,16 +29,19 @@
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppThemeLight.NoActionBar">
android:theme="@style/AppThemeLight"
android:label="">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:label="@string/title_activity_login"></activity>
android:label="">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ch.amiv.android_app.MainActivity" />
</activity>
</application>
</manifest>
\ No newline at end of file
package ch.amiv.android_app;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
......@@ -16,12 +21,18 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private TextView mTextMessage;
RecyclerView mRecylerView;
RecyclerView.Adapter mRecylcerAdaper;
RecyclerView.LayoutManager mRecyclerLayoutAdapter;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
......@@ -30,13 +41,10 @@ public class MainActivity extends AppCompatActivity
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_articles);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_events);
return true;
}
return false;
......@@ -48,8 +56,6 @@ public class MainActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
......@@ -60,9 +66,11 @@ public class MainActivity extends AppCompatActivity
}
});*/
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
......@@ -71,9 +79,34 @@ public class MainActivity extends AppCompatActivity
new Settings(getApplicationContext());
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.bottomNav);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
//Recyclerview
InitialiseListView();
}
private void InitialiseListView() {
MyAdapter pagerAdapter = new MyAdapter(getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.viewPager);
viewPager.setAdapter(pagerAdapter);
viewPager.setPageTransformer(true, new DepthPageTransformer());
/*mRecylerView = findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecylerView.setHasFixedSize(true);
// use a linear layout manager
mRecyclerLayoutAdapter = new LinearLayoutManager(this);
mRecylerView.setLayoutManager(mRecyclerLayoutAdapter);
// specify an adapter (see also next example)
mRecylcerAdaper = new MemberListAdapter(EventDatabase.instance.members, EventDatabase.instance.stats, EventDatabase.instance.eventData.GetInfosAsKeyValuePairs());
mRecylerView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(this, R.anim.layout_anim_falldown));
mRecylerView.setAdapter(mRecylcerAdaper);*/
}
//=====Changing Activity====
......@@ -92,23 +125,11 @@ public class MainActivity extends AppCompatActivity
//startActivity(browserIntent);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
//=====TOOLBAR=====
@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.toolbar_menu_main, menu);
return true;
}
......@@ -120,12 +141,26 @@ public class MainActivity extends AppCompatActivity
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
if (id == R.id.action_favorite) {
Toast.makeText(MainActivity.this, "Action clicked", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
//=====END OF TOOLBAR=============
//========START OF DRAWER=========
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
......@@ -149,4 +184,111 @@ public class MainActivity extends AppCompatActivity
drawer.closeDrawer(GravityCompat.START);
return true;
}
//=====END OF DRAWER==================
//=====START OF PAGEVIEW==============
public static class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return 3;
}
@Override
public Fragment getItem(int position) {
return ArrayListFragment.newInstance(position);
}
}
/**
* An examply fragment, the central view in MainActivity, for showing a list, should be replaced by a standard fragment with a custom recyclerView, create one different class for different views
*/
public static class ArrayListFragment extends ListFragment {
int mNum;
/**
* Create a new instance of CountingFragment, providing "num"
* as an argument.
*/
static ArrayListFragment newInstance(int num) {
ArrayListFragment f = new ArrayListFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
/**
* When creating, retrieve this instance's number from its arguments.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
}
/**
* The Fragment's UI is just a simple text view showing its
* instance number.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.main_page1, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("Fragment #" + mNum);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new String[]{"A", "B", "C"}));
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Log.i("FragmentList", "Item clicked: " + id);
}
}
/**
* Use to *animate* the transition nicely when swiping between the pages of the pagerView
*/
public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
public void transformPage(@NonNull View view, float position) { //position defines how far through the transition we are, -1= fully left, +1=fully right, 0= fully centered
int pageWidth = view.getWidth();
if (position < -1) { // This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 0) { // Use the default slide transition when moving to the left page
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
} else if (position <= 1) { // Fade the page out.
view.setAlpha(1 - position);
// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);
// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
} else { // This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
//=====END OF PAGEVIEW================
}
......@@ -2,7 +2,7 @@
android:shape="rectangle">
<gradient
android:angle="135"
android:startColor="#415eb0"
android:startColor="#415eb0"
android:centerColor="#1F2D54"
android:endColor="#1F2D54"
android:type="linear" />
......
......@@ -15,16 +15,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="@string/title_home"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@id/bottomNav"
app:layout_constraintTop_toBottomOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNav"
......@@ -39,7 +35,7 @@
</android.support.constraint.ConstraintLayout>
<include
layout="@layout/app_bar_main"
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
......
......@@ -6,6 +6,6 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">
tools:showIn="@layout/toolbar_main">
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:drawable/gallery_thumb">
<TextView android:id="@+id/text"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Hello Woorld"/>
<!-- The frame layout is here since we will be showing either
the empty view or the list view. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<!-- Here is the list. Since we are using a ListActivity, we
have to call it "@android:id/list" so ListActivity will
find it -->
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
<!-- Here is the view to show if the list is emtpy -->
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="No items."/>
</FrameLayout>
</LinearLayout>
\ No newline at end of file
......@@ -16,7 +16,20 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppThemeLight.PopupOverlay" />
app:popupTheme="@style/AppThemeLight.PopupOverlay" >
<ImageView
android:id="@+id/toolbar_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="Logo"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:src="@mipmap/amiv_logo"
android:tint="@color/white" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
......@@ -24,6 +37,7 @@
android:id="@+id/include"
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:visibility="visible" />
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_favorite"
android:orderInCategory="300"
android:title="User"
android:icon="@drawable/ic_menu_account"
android:iconTint="@color/white"
app:showAsAction="ifRoom" />
</menu>
\ No newline at end of file
<resources>
<style name="AppThemeLight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
......@@ -4,6 +4,6 @@
<color name="colorSecondary">#1F2D54</color>
<color name="colorAccent">#5D78C1</color>
<color name="colorAccentDark">#374773</color>
<color name="coloTextLight">#ffffff</color>
<color name="backgroundDark">#131826</color>
<color name="white">#FFFFFF</color>
</resources>
......@@ -5,8 +5,6 @@
<string name="title_events">Events</string>
<string name="title_activity_settings">Settings</string>
<!-- Strings related to Settings -->
<!-- Example General settings -->
<string name="pref_header_general">General</string>
......
......@@ -4,6 +4,8 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorSecondary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
......@@ -12,29 +14,12 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">@color/backgroundDark</item>
<item name="android:colorForeground">@android:color/background_light</item>
</style>
<style name="AppThemeLight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppThemeLight.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppThemeLight.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Fullscreen" parent="AppThemeLight">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorBackground">@color/colorPrimary</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccentDark</item>
<item name="android:textColorPrimary">@color/primary_text_material_dark</item>
<item name="android:textColorSecondary">@color/coloTextLight</item>
<item name="android:textColorSecondaryInverse">@color/primary_text_material_dark</item>
<item name="android:textColorPrimaryInverse">@color/primary_text_material_dark</item>
<item name="android:colorButtonNormal">@color/colorAccentDark</item>
</style>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment