Skip to content

Commit

Permalink
Merge pull request #36 from kioko/master
Browse files Browse the repository at this point in the history
Create Intro for ToolBar MenuItem
  • Loading branch information
iammert committed May 18, 2016
2 parents 19febd4 + 7660665 commit 3cc5cbc
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 22 deletions.
Binary file added art/art_toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="co.mobiwise.sample"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.mobiwise.sample">

<application
android:allowBackup="true"
Expand All @@ -13,11 +13,13 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".ToolbarMenuItemActivity" />
</application>

</manifest>
38 changes: 21 additions & 17 deletions sample/src/main/java/co/mobiwise/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.mobiwise.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
Expand Down Expand Up @@ -75,27 +76,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();


if (id == R.id.nav_demo) {
getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit();
} else if (id == R.id.nav_gravity) {
getSupportFragmentManager().beginTransaction().replace(R.id.container, new GravityFragment()).commit();
} else if (id == R.id.nav_focus) {
getSupportFragmentManager().beginTransaction().replace(R.id.container, new FocusFragment()).commit();
} else if (id == R.id.nav_recyclerview) {
getSupportFragmentManager().beginTransaction().replace(R.id.container, new RecyclerviewFragment()).commit();
} else if (id == R.id.nav_toolbar) {

} else if (id == R.id.nav_tab) {

switch (item.getItemId()) {
case R.id.nav_demo:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit();
break;
case R.id.nav_gravity:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new GravityFragment()).commit();
break;
case R.id.nav_focus:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new FocusFragment()).commit();
break;
case R.id.nav_recyclerview:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new RecyclerviewFragment()).commit();
break;
case R.id.nav_toolbar:
startActivity(new Intent(getApplicationContext(), ToolbarMenuItemActivity.class));
break;
case R.id.nav_tab:
break;
default:
break;
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
Expand Down
166 changes: 166 additions & 0 deletions sample/src/main/java/co/mobiwise/sample/ToolbarMenuItemActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package co.mobiwise.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
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.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import co.mobiwise.materialintro.animation.MaterialIntroListener;
import co.mobiwise.materialintro.shape.Focus;
import co.mobiwise.materialintro.shape.FocusGravity;
import co.mobiwise.materialintro.view.MaterialIntroView;
import co.mobiwise.sample.fragment.FocusFragment;
import co.mobiwise.sample.fragment.GravityFragment;
import co.mobiwise.sample.fragment.MainFragment;
import co.mobiwise.sample.fragment.RecyclerviewFragment;

/**
* This activity demonstrates how to implement Material introView on ToolBar MenuItems
*
* @author Thomas Kioko
*/
public class ToolbarMenuItemActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, MaterialIntroListener {

private static final String MENU_SHARED_ID_TAG = "menuSharedIdTag";
private static final String MENU_ABOUT_ID_TAG = "menuAboutIdTag";
private static final String MENU_SEARCH_ID_TAG = "menuSearchIdTag";
private ImageView mIvShare, mIvAbout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toolbar);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//User toolbar to access the views
ImageView ivSearch = (ImageView) toolbar.findViewById(R.id.ivToolbarSearch);
mIvShare = (ImageView) toolbar.findViewById(R.id.ivToolbarShare);
mIvAbout = (ImageView) toolbar.findViewById(R.id.ivToolbarAbout);

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);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

//show the intro view
showIntro(ivSearch, MENU_SEARCH_ID_TAG, getString(R.string.guide_setup_profile), FocusGravity.CENTER);

}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@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);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
switch (item.getItemId()) {
case R.id.nav_demo:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit();
break;
case R.id.nav_gravity:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new GravityFragment()).commit();
break;
case R.id.nav_focus:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new FocusFragment()).commit();
break;
case R.id.nav_recyclerview:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new RecyclerviewFragment()).commit();
break;
case R.id.nav_toolbar:
startActivity(new Intent(getApplicationContext(), ToolbarMenuItemActivity.class));
break;
case R.id.nav_tab:
break;
default:
break;
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

/**
* Method that handles display of intro screens
*
* @param view View to show guide
* @param id Unique ID
* @param text Display message
* @param focusGravity Focus Gravity of the display
*/
public void showIntro(View view, String id, String text, FocusGravity focusGravity) {
new MaterialIntroView.Builder(ToolbarMenuItemActivity.this)
.enableDotAnimation(true)
.setFocusGravity(focusGravity)
.setFocusType(Focus.MINIMUM)
.setDelayMillis(100)
.enableFadeAnimation(true)
.performClick(true)
.setInfoText(text)
.setTarget(view)
.setListener(this)
.setUsageId(id)
.show();
}

@Override
public void onUserClicked(String materialIntroViewId) {
switch (materialIntroViewId) {
case MENU_SEARCH_ID_TAG:
showIntro(mIvAbout, MENU_ABOUT_ID_TAG, getString(R.string.guide_setup_profile), FocusGravity.LEFT);
break;
case MENU_ABOUT_ID_TAG:
showIntro(mIvShare, MENU_SHARED_ID_TAG, getString(R.string.guide_setup_profile), FocusGravity.LEFT);
break;
case MENU_SHARED_ID_TAG:
Toast.makeText(ToolbarMenuItemActivity.this, "Complete!", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}
40 changes: 40 additions & 0 deletions sample/src/main/res/layout/activity_toolbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="co.mobiwise.sample.ToolbarMenuItemActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<include layout="@layout/toolbar" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/container"/>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
64 changes: 64 additions & 0 deletions sample/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright (C) 2014 Thomas Kioko.
~
~ 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.
-->

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<ImageView
android:id="@+id/ivToolbarShare"
android:layout_width="@dimen/toolbar_image_dimens"
android:layout_height="@dimen/toolbar_image_dimens"
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="?selectableItemBackground"
android:contentDescription="@string/image_view_description"
android:src="@mipmap/ic_share_white" />

<ImageView
android:id="@+id/ivToolbarAbout"
android:layout_width="@dimen/toolbar_image_dimens"
android:layout_height="@dimen/toolbar_image_dimens"
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="?selectableItemBackground"
android:contentDescription="@string/image_view_description"
android:src="@mipmap/ic_help_outline" />

<ImageView
android:id="@+id/ivToolbarSearch"
android:layout_width="@dimen/toolbar_image_dimens"
android:layout_height="@dimen/toolbar_image_dimens"
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="?selectableItemBackground"
android:contentDescription="@string/image_view_description"
android:src="@mipmap/ic_search" />


</android.support.v7.widget.Toolbar>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/src/main/res/mipmap-hdpi/ic_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/src/main/res/mipmap-hdpi/ic_share_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

<dimen name="item_card_width">160dp</dimen>
<dimen name="item_card_height">220dp</dimen>
<dimen name="toolbar_image_dimens">28dp</dimen>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<string name="navigation_drawer_close">Close navigation drawer</string>

<string name="action_settings">Settings</string>
<string name="image_view_description">ImageView</string>

<!-- TourGuide Text -->
<string name="guide_setup_profile">Welcome. Let\'s setup your profile. Just tap on the circle.</string>
</resources>
2 changes: 1 addition & 1 deletion sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down

0 comments on commit 3cc5cbc

Please sign in to comment.