-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from kioko/master
Create Intro for ToolBar MenuItem
- Loading branch information
Showing
12 changed files
with
303 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
sample/src/main/java/co/mobiwise/sample/ToolbarMenuItemActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters