MaterialAppBase is a open source project which help android developers to:
- Save much of time to learn Google Material Design (to developers who new to Material Design).
- Help android developers to start a Material Designed android app project very easily.
- Reduce much of codes to do the activity layouts.
Index
Apps use MaterialAppBase
I am a full stack engineer work on mobile apps. I have done many android projects. What I am saying is if you are an android developer you already know that:
- We have to write so much repeated codes to create different look-alike activities.
- We sometimes copy a project just for creating another look-alike project.
But if you do above things, it is very hard to keep the code synchronized between class and even between projects.
This is why I create this app base as a library which shares between projects so that I can prevent for writing repeated codes between projects. More importantly I can keep the shared code synchronized.
I think I should share this projects to anyone who's new to android or JAVA to help them on learning how to cut down the unnecessary codes.
Activities
- [Action bar activity] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseActionbarActivity.java)
- [Navigation drawer activity] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseNavigationDrawerActivity.java)
- [Tab bar activity] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseTabbableActionbarActivity.java)
- [Search bar activity] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseSearchBarActivity.java)
- [Collapsing view activity] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseCollapsingActionbarActivity.java)
Fragments
- [ListView fragment] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseListViewFragment.java)
- [GridView fragment] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseGridViewFragment.java)
- [RecyclerView fragment] (https://github.com/DanielShum/MaterialAppBase/blob/master/library/src/main/java/com/daililol/material/appbase/base/BaseRecyclerViewFragment.java)
Widgets
- MaterialRaisedButton [see usage] (https://github.com/DanielShum/MaterialAppBase/wiki/MaterialRaisedButton)
- MaterialFlatButton
- MaterialImageButton
- MaterialEditText [see usage] (https://github.com/DanielShum/MaterialAppBase/wiki/MaterialEditText)
Components
- FragmentAdapter
- RecyclerViewOnItemClickListener
- GridedRecyclerViewDivider
Requirement
- Min android SDK: 9
- Target SDK: 23+
- Android support library (Support-V7, Support-Design and RecyclerView)
Adding this library to your projects
- Download this project and unzip to you Android studio workpace directory.
- Include the library to your project by editting settings.gradle file. it may look like below
include ':app', '..:MaterialAppBase:materialAppBaseLibrary'
Adding dependence
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile project(':..:MaterialAppBase:materialAppBaseLibrary') //this is the compile code to add this library
}
Setting your app theme
<application
...
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Base.AppTheme.WindowContentTransition">
...
</application>
Create an actionbar activity
public class MyActionbarActivity extends BaseActionbarActivity{
......
@Override
protected void onActivityCreated(Bundle savedInstanceState) {
// TODO this method will be involved when all start-up tasks are done.
// Do your own work here
}
@Override
protected int setupContentVew() {
// TODO return your main content view layout
return R.layout.my_actionbar_activity;
}
@Override
protected Drawable setupThemeColor() {
// TODO return your actionbar background color (or image) here
return new ColorDrawable(Color.RED);
}
@Override
protected boolean onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO inflate your actionbar menu item here
inflater.inflate(R.menu.setting, menu);
//return false to allow normal menu processing to proceed, true to consume it here.
//simplely say that must return true if you want onMenuItemSelected(MenuItem menu)
//be involved when an action bar item is click
return true;
}
@Override
protected void onMenuItemSelected(MenuItem menu) {
// TODO this method will be involved when an menu item is selected or clicked
switch (menu.getItemId()){
case android.R.id.home:
finish();
break;
default:
break;
}
}
......
}
Create a navigation drawer activity
public class DrawerActivity extends BaseNavigationDrawerActivity{
......
@Override
protected void setupNavigationDrawerItem(ExtendableListView listView,
BaseNavigationDrawerListAdapter navigationListAdapter) {
// TODO add the navigation menu item here
listView.setBackgroundColor(Color.WHITE);
navigationListAdapter.addItem("item 1",
DrawableUtil.getDrawable(this, R.drawable.ic_chat_grey600_24dp));
navigationListAdapter.addItem("item 2",
DrawableUtil.getDrawable(this, R.drawable.ic_chat_grey600_24dp));
}
......
}
Create a tabbed swipe view activity
public class MainActivity extends BaseTabbableActionbarActivity{
......
@Override
protected void setupViewPager(ViewPager viewPager) {
// TODO setup contents for viewPage (tab number depands on how many fragment added to the viewPager).
BaseFragmentPagerAdapter adapter = new BaseFragmentPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new TestFragment(), "Section 1");
adapter.addFragment(new TestFragment(), "Section 2");
viewPager.setAdapter(adapter);
}
@Override
protected Drawable setupTabIcon(int pisiton) {
// TODO return an icon for each tab (if necessary)
return null;
}
......
}
Create a search bar activity
public class TestSearchbarActivity extends BaseSearchBarActivity{
......
@Override
protected void onSearch(String Keyword) {
// TODO this method will be involved when the Search button is clicked.
doSearch(Keyword);
}
@Override
protected void onCleanKeyword() {
// TODO this method will be involved when the user clean the search keywords.
}
......
}
Create a collapsing scroll view activity
public class TestCollapsingActictionbarActivity extends BaseCollapsingActionbarActivity{
......
@Override
public View setupCollapsingView() {
// TODO return the header view here (which is under the action bar)
return null;
}
@Override
public View setupContentView() {
// TODO return the main content view here
//(the view must contains a NestedSrollView or RecyclerView.)
return null;
}
......
}
Copyright 2015 Daniel Shum.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.