├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── AndroidMaterialDesignToolbar.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tekinarslan │ │ └── material │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── tekinarslan │ │ └── material │ │ └── sample │ │ ├── Button.java │ │ ├── FloatingActionButton.java │ │ ├── ProgressBarCircular.java │ │ ├── SampleActivity.java │ │ ├── SampleFragment.java │ │ ├── SlidingTabLayout.java │ │ ├── SlidingTabStrip.java │ │ ├── ToolBarMaterial.java │ │ └── ViewPagerAdapter.java │ └── res │ ├── drawable-hdpi │ ├── background_card.9.png │ ├── ic_ab_drawer.png │ ├── ic_launcher.png │ ├── plus.png │ └── shadow.png │ ├── drawable-xhdpi │ ├── ic_ab_drawer.png │ ├── ic_launcher.png │ ├── plus.png │ └── shadow.png │ ├── drawable-xxhdpi │ ├── ic_ab_drawer.png │ └── ic_launcher.png │ ├── drawable │ └── fab.xml │ ├── layout │ ├── ToolBarMaterial.java │ ├── activity_sample.xml │ └── page.xml │ ├── values-v21 │ └── themes.xml │ └── values │ ├── attrs.xml │ ├── color.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | AndroidMaterialDesignToolbar -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 1.7 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidMaterialDesignToolbar.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED 2 | ============================================ 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidMaterialDesignToolbar-brightgreen.svg?style=flat)](https://android-arsenal.com/details/3/1125) 4 | 5 | Android Sample Project with Material Design and Toolbar. 6 | Project use Appcompat library for material design. 7 | 8 | Project Contain 9 | ============================ 10 | * Material Design Theme 11 | 12 | * Toolbar 13 | 14 | * NavigationDrawer 15 | 16 | * New SlidingTabLayout 17 | 18 | * ViewPager 19 | 20 | * Material FloatingActionButton 21 | 22 | * Material CircularProgressBar 23 | 24 | * SwitchCompat from Appcompat 25 | 26 | * EditText from Appcompat 27 | 28 | * Checkbox from Appcompat 29 | 30 | 31 | ![alt tag](http://www.stdroid.com/img/output_5UTjCv.gif) 32 | 33 | 34 | 35 | License 36 | ============================ 37 | Copyright 2015 Tekinarslan 38 | 39 | Licensed under the Apache License, Version 2.0 (the "License"); 40 | you may not use this file except in compliance with the License. 41 | You may obtain a copy of the License at:- 42 | 43 | http://www.apache.org/licenses/LICENSE-2.0 44 | 45 | Unless required by applicable law or agreed to in writing, software 46 | distributed under the License is distributed on an "AS IS" BASIS, 47 | WITHOUT "WARRANTIES OR CONDITIONS" OF ANY KIND, either express or implied. 48 | See the License for the specific language governing permissions and 49 | limitations under the License. 50 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.tekinarslan.material.sample" 9 | minSdkVersion 16 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.2" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:support-v4:22.1.1' 25 | compile 'com.android.support:appcompat-v7:22.1.1' 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Program Files (x86)\Android\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tekinarslan/material/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/Button.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Bitmap.Config; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.GradientDrawable; 12 | import android.graphics.drawable.LayerDrawable; 13 | import android.util.AttributeSet; 14 | import android.util.TypedValue; 15 | import android.view.MotionEvent; 16 | import android.widget.RelativeLayout; 17 | import android.widget.TextView; 18 | 19 | public abstract class Button extends RelativeLayout { 20 | 21 | final static String MATERIAL_DESIGNXML = "http://schemas.android.com/apk/res-auto"; 22 | final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; 23 | 24 | public boolean isLastTouch = false; 25 | int minWidth; 26 | int minHeight; 27 | int background; 28 | float rippleSpeed = 10f; 29 | int rippleSize = 3; 30 | OnClickListener onClickListener; 31 | int backgroundColor = Color.parseColor("#1E88E5"); 32 | 33 | 34 | // ### RIPPLE EFFECT ### 35 | float x = -1, y = -1; 36 | float radius = -1; 37 | 38 | public Button(Context context, AttributeSet attrs) { 39 | super(context, attrs); 40 | setDefaultProperties(); 41 | } 42 | 43 | protected void setDefaultProperties() { 44 | setMinimumHeight(dpToPx(minHeight, getResources())); 45 | setMinimumWidth(dpToPx(minWidth, getResources())); 46 | setBackgroundResource(background); 47 | setBackgroundColor(backgroundColor); 48 | } 49 | 50 | public int dpToPx(float dp, Resources resources) { 51 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); 52 | return (int) px; 53 | } 54 | // Set atributtes of XML to View 55 | 56 | 57 | @Override 58 | public boolean onTouchEvent(MotionEvent event) { 59 | isLastTouch = true; 60 | if (event.getAction() == MotionEvent.ACTION_DOWN) { 61 | radius = getHeight() / rippleSize; 62 | x = event.getX(); 63 | y = event.getY(); 64 | } else if (event.getAction() == MotionEvent.ACTION_MOVE) { 65 | radius = getHeight() / rippleSize; 66 | x = event.getX(); 67 | y = event.getY(); 68 | if (!((event.getX() <= getWidth() && event.getX() >= 0) && 69 | (event.getY() <= getHeight() && event.getY() >= 0))) { 70 | isLastTouch = false; 71 | x = -1; 72 | y = -1; 73 | } 74 | } else if (event.getAction() == MotionEvent.ACTION_UP) { 75 | if ((event.getX() <= getWidth() && event.getX() >= 0) && 76 | (event.getY() <= getHeight() && event.getY() >= 0)) { 77 | radius++; 78 | } else { 79 | isLastTouch = false; 80 | x = -1; 81 | y = -1; 82 | } 83 | } 84 | return true; 85 | } 86 | 87 | @Override 88 | protected void onFocusChanged(boolean gainFocus, int direction, 89 | Rect previouslyFocusedRect) { 90 | if (!gainFocus) { 91 | x = -1; 92 | y = -1; 93 | } 94 | } 95 | 96 | public Bitmap makeCircle() { 97 | Bitmap output = Bitmap.createBitmap(getWidth() - dpToPx(6, getResources()), 98 | getHeight() - dpToPx(7, getResources()), Config.ARGB_8888); 99 | Canvas canvas = new Canvas(output); 100 | canvas.drawARGB(0, 0, 0, 0); 101 | Paint paint = new Paint(); 102 | paint.setAntiAlias(true); 103 | paint.setColor(makePressColor()); 104 | canvas.drawCircle(x, y, radius, paint); 105 | if (radius > getHeight() / rippleSize) 106 | radius += rippleSpeed; 107 | if (radius >= getWidth()) { 108 | x = -1; 109 | y = -1; 110 | radius = getHeight() / rippleSize; 111 | if (onClickListener != null) 112 | onClickListener.onClick(this); 113 | } 114 | return output; 115 | } 116 | 117 | /** 118 | * Make a dark color to ripple effect 119 | * 120 | * @return 121 | */ 122 | protected int makePressColor() { 123 | int r = (this.backgroundColor >> 16) & 0xFF; 124 | int g = (this.backgroundColor >> 8) & 0xFF; 125 | int b = (this.backgroundColor >> 0) & 0xFF; 126 | r = (r - 30 < 0) ? 0 : r - 30; 127 | g = (g - 30 < 0) ? 0 : g - 30; 128 | b = (b - 30 < 0) ? 0 : b - 30; 129 | return Color.rgb(r, g, b); 130 | } 131 | 132 | @Override 133 | public void setOnClickListener(OnClickListener l) { 134 | onClickListener = l; 135 | } 136 | 137 | // Set color of background 138 | public void setBackgroundColor(int color) { 139 | this.backgroundColor = color; 140 | LayerDrawable layer = (LayerDrawable) getBackground(); 141 | GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); 142 | shape.setColor(backgroundColor); 143 | } 144 | 145 | abstract public TextView getTextView(); 146 | 147 | public void setRippleSpeed(float rippleSpeed) { 148 | this.rippleSpeed = rippleSpeed; 149 | } 150 | 151 | public float getRippleSpeed() { 152 | return this.rippleSpeed; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/FloatingActionButton.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Bitmap.Config; 7 | import android.graphics.Canvas; 8 | import android.graphics.Paint; 9 | import android.graphics.PorterDuff.Mode; 10 | import android.graphics.PorterDuffXfermode; 11 | import android.graphics.Rect; 12 | import android.graphics.drawable.Drawable; 13 | import android.util.AttributeSet; 14 | import android.util.TypedValue; 15 | import android.widget.ImageView; 16 | import android.widget.RelativeLayout; 17 | import android.widget.TextView; 18 | 19 | 20 | public class FloatingActionButton extends Button { 21 | 22 | int sizeIcon = 24; 23 | int sizeRadius = 28; 24 | ImageView icon; // Icon of float button 25 | Drawable drawableIcon; 26 | 27 | public FloatingActionButton(Context context, AttributeSet attributes) { 28 | super(context, attributes); 29 | setBackgroundResource(R.drawable.fab); 30 | sizeRadius = 28; 31 | setDefaultProperties(); 32 | icon = new ImageView(context); 33 | if (drawableIcon != null) { 34 | try { 35 | icon.setBackground(drawableIcon); 36 | } catch (NoSuchMethodError e) { 37 | icon.setBackgroundDrawable(drawableIcon); 38 | } 39 | } 40 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(dpToPx(sizeIcon, getResources()), dpToPx(sizeIcon, getResources())); 41 | params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); 42 | icon.setLayoutParams(params); 43 | addView(icon); 44 | } 45 | 46 | protected void setDefaultProperties() { 47 | rippleSpeed = dpToPx(2, getResources()); 48 | rippleSize = dpToPx(5, getResources()); 49 | super.minWidth = sizeRadius * 2; 50 | super.minHeight = sizeRadius * 2; 51 | super.background = R.drawable.fab; 52 | super.setDefaultProperties(); 53 | } 54 | 55 | @Override 56 | protected void onDraw(Canvas canvas) { 57 | super.onDraw(canvas); 58 | if (x != -1) { 59 | Rect src = new Rect(0, 0, getWidth(), getHeight()); 60 | Rect dst = new Rect(dpToPx(1, getResources()), dpToPx(2, getResources()), getWidth() - dpToPx(1, getResources()), getHeight() - dpToPx(2, getResources())); 61 | canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null); 62 | } 63 | invalidate(); 64 | } 65 | 66 | public int dpToPx(float dp, Resources resources) { 67 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); 68 | return (int) px; 69 | } 70 | 71 | public ImageView getIcon() { 72 | return icon; 73 | } 74 | 75 | public void setIcon(ImageView icon) { 76 | this.icon = icon; 77 | } 78 | 79 | public Drawable getDrawableIcon() { 80 | return drawableIcon; 81 | } 82 | 83 | public void setDrawableIcon(Drawable drawableIcon) { 84 | this.drawableIcon = drawableIcon; 85 | try { 86 | icon.setBackground(drawableIcon); 87 | } catch (NoSuchMethodError e) { 88 | e.printStackTrace(); 89 | } 90 | } 91 | 92 | public Bitmap cropCircle(Bitmap bitmap) { 93 | Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 94 | bitmap.getHeight(), Config.ARGB_8888); 95 | Canvas canvas = new Canvas(output); 96 | 97 | final int color = 0xff424242; 98 | final Paint paint = new Paint(); 99 | final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 100 | 101 | paint.setAntiAlias(true); 102 | canvas.drawARGB(0, 0, 0, 0); 103 | paint.setColor(color); 104 | canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, 105 | bitmap.getWidth() / 2, paint); 106 | paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 107 | canvas.drawBitmap(bitmap, rect, rect, paint); 108 | return output; 109 | } 110 | 111 | @Override 112 | public TextView getTextView() { 113 | return null; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/ProgressBarCircular.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.PorterDuff; 10 | import android.graphics.PorterDuffXfermode; 11 | import android.graphics.RectF; 12 | import android.util.AttributeSet; 13 | import android.util.TypedValue; 14 | import android.widget.RelativeLayout; 15 | 16 | public class ProgressBarCircular extends RelativeLayout { 17 | 18 | 19 | final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; 20 | 21 | int backgroundColor = Color.parseColor("#1E88E5"); 22 | 23 | float radius1 = 0; 24 | float radius2 = 0; 25 | int cont = 0; 26 | boolean firstAnimationOver = false; 27 | 28 | int arcD = 1; 29 | int arcO = 0; 30 | float rotateAngle = 0; 31 | int limite = 0; 32 | 33 | public ProgressBarCircular(Context context, AttributeSet attrs) { 34 | super(context, attrs); 35 | setAttributes(attrs); 36 | 37 | } 38 | 39 | public int dpToPx(float dp, Resources resources) { 40 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); 41 | return (int) px; 42 | } 43 | 44 | // Set atributtes of XML to View 45 | protected void setAttributes(AttributeSet attrs) { 46 | 47 | setMinimumHeight(dpToPx(32, getResources())); 48 | setMinimumWidth(dpToPx(32, getResources())); 49 | 50 | //Set background Color 51 | // Color by resource 52 | int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); 53 | if (bacgroundColor != -1) { 54 | setBackgroundColor(getResources().getColor(bacgroundColor)); 55 | } else { 56 | // Color by hexadecimal 57 | String background = attrs.getAttributeValue(ANDROIDXML, "background"); 58 | if (background != null) 59 | setBackgroundColor(Color.parseColor(background)); 60 | else 61 | setBackgroundColor(Color.parseColor("#1E88E5")); 62 | } 63 | 64 | setMinimumHeight(dpToPx(3, getResources())); 65 | 66 | 67 | } 68 | 69 | /** 70 | * Make a dark color to ripple effect 71 | * 72 | * @return 73 | */ 74 | protected int makePressColor() { 75 | int r = (this.backgroundColor >> 16) & 0xFF; 76 | int g = (this.backgroundColor >> 8) & 0xFF; 77 | int b = (this.backgroundColor >> 0) & 0xFF; 78 | // r = (r+90 > 245) ? 245 : r+90; 79 | // g = (g+90 > 245) ? 245 : g+90; 80 | // b = (b+90 > 245) ? 245 : b+90; 81 | return Color.argb(128, r, g, b); 82 | } 83 | 84 | 85 | @Override 86 | protected void onDraw(Canvas canvas) { 87 | super.onDraw(canvas); 88 | if (!firstAnimationOver) 89 | drawFirstAnimation(canvas); 90 | if (cont > 0) 91 | drawSecondAnimation(canvas); 92 | invalidate(); 93 | 94 | } 95 | 96 | /** 97 | * Draw first animation of view 98 | * 99 | * @param canvas 100 | */ 101 | private void drawFirstAnimation(Canvas canvas) { 102 | if (radius1 < getWidth() / 2) { 103 | Paint paint = new Paint(); 104 | paint.setAntiAlias(true); 105 | paint.setColor(makePressColor()); 106 | radius1 = (radius1 >= getWidth() / 2) ? (float) getWidth() / 2 : radius1 + 1; 107 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius1, paint); 108 | } else { 109 | Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); 110 | Canvas temp = new Canvas(bitmap); 111 | Paint paint = new Paint(); 112 | paint.setAntiAlias(true); 113 | paint.setColor(makePressColor()); 114 | temp.drawCircle(getWidth() / 2, getHeight() / 2, getHeight() / 2, paint); 115 | Paint transparentPaint = new Paint(); 116 | transparentPaint.setAntiAlias(true); 117 | transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); 118 | transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); 119 | if (cont >= 50) { 120 | radius2 = (radius2 >= getWidth() / 2) ? (float) getWidth() / 2 : radius2 + 1; 121 | } else { 122 | radius2 = (radius2 >= getWidth() / 2 - dpToPx(4, getResources())) ? (float) getWidth() / 2 - dpToPx(4, getResources()) : radius2 + 1; 123 | } 124 | temp.drawCircle(getWidth() / 2, getHeight() / 2, radius2, transparentPaint); 125 | canvas.drawBitmap(bitmap, 0, 0, new Paint()); 126 | if (radius2 >= getWidth() / 2 - dpToPx(4, getResources())) 127 | cont++; 128 | if (radius2 >= getWidth() / 2) 129 | firstAnimationOver = true; 130 | } 131 | } 132 | 133 | /** 134 | * Draw second animation of view 135 | * 136 | * @param canvas 137 | */ 138 | private void drawSecondAnimation(Canvas canvas) { 139 | if (arcO == limite) 140 | arcD += 6; 141 | if (arcD >= 290 || arcO > limite) { 142 | arcO += 6; 143 | arcD -= 6; 144 | } 145 | if (arcO > limite + 290) { 146 | limite = arcO; 147 | arcO = limite; 148 | arcD = 1; 149 | } 150 | rotateAngle += 4; 151 | canvas.rotate(rotateAngle, getWidth() / 2, getHeight() / 2); 152 | 153 | Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); 154 | Canvas temp = new Canvas(bitmap); 155 | Paint paint = new Paint(); 156 | paint.setAntiAlias(true); 157 | paint.setColor(backgroundColor); 158 | // temp.drawARGB(0, 0, 0, 255); 159 | temp.drawArc(new RectF(0, 0, getWidth(), getHeight()), arcO, arcD, true, paint); 160 | Paint transparentPaint = new Paint(); 161 | transparentPaint.setAntiAlias(true); 162 | transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); 163 | transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); 164 | temp.drawCircle(getWidth() / 2, getHeight() / 2, (getWidth() / 2) - dpToPx(4, getResources()), transparentPaint); 165 | 166 | canvas.drawBitmap(bitmap, 0, 0, new Paint()); 167 | } 168 | 169 | 170 | // Set color of background 171 | public void setBackgroundColor(int color) { 172 | super.setBackgroundColor(getResources().getColor(android.R.color.transparent)); 173 | this.backgroundColor = color; 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/SampleActivity.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.content.res.Configuration; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.support.v4.view.ViewPager; 7 | import android.support.v4.widget.DrawerLayout; 8 | import android.support.v7.app.ActionBarActivity; 9 | import android.support.v7.app.ActionBarDrawerToggle; 10 | import android.support.v7.widget.Toolbar; 11 | import android.view.Gravity; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.AdapterView; 15 | import android.widget.ArrayAdapter; 16 | import android.widget.ListView; 17 | 18 | 19 | public class SampleActivity extends ActionBarActivity { 20 | 21 | private DrawerLayout mDrawerLayout; 22 | private ActionBarDrawerToggle drawerToggle; 23 | 24 | private ListView mDrawerList; 25 | ViewPager pager; 26 | private String[] titles = new String[]{"Sample Tab 1", "Sample Tab 2", "Sample Tab 3", "Sample Tab 4" 27 | , "Sample Tab 5", "Sample Tab 6", "Sample Tab 7", "Sample Tab 8"}; 28 | private Toolbar toolbar; 29 | 30 | SlidingTabLayout slidingTabLayout; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_sample); 36 | 37 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 38 | mDrawerList = (ListView) findViewById(R.id.navdrawer); 39 | toolbar = (Toolbar) findViewById(R.id.toolbar); 40 | if (toolbar != null) { 41 | setSupportActionBar(toolbar); 42 | toolbar.setNavigationIcon(R.drawable.ic_ab_drawer); 43 | } 44 | pager = (ViewPager) findViewById(R.id.viewpager); 45 | slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); 46 | pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), titles)); 47 | 48 | slidingTabLayout.setViewPager(pager); 49 | slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { 50 | @Override 51 | public int getIndicatorColor(int position) { 52 | return Color.WHITE; 53 | } 54 | }); 55 | drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name); 56 | mDrawerLayout.setDrawerListener(drawerToggle); 57 | String[] values = new String[]{ 58 | "DEFAULT", "RED", "BLUE", "MATERIAL GREY" 59 | }; 60 | ArrayAdapter adapter = new ArrayAdapter<>(this, 61 | android.R.layout.simple_list_item_1, android.R.id.text1, values); 62 | mDrawerList.setAdapter(adapter); 63 | mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 64 | @Override 65 | public void onItemClick(AdapterView parent, View view, 66 | int position, long id) { 67 | switch (position) { 68 | case 0: 69 | mDrawerList.setBackgroundColor(getResources().getColor(R.color.material_deep_teal_500)); 70 | toolbar.setBackgroundColor(getResources().getColor(R.color.material_deep_teal_500)); 71 | slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.material_deep_teal_500)); 72 | mDrawerLayout.closeDrawer(Gravity.START); 73 | break; 74 | case 1: 75 | mDrawerList.setBackgroundColor(getResources().getColor(R.color.red)); 76 | toolbar.setBackgroundColor(getResources().getColor(R.color.red)); 77 | slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.red)); 78 | mDrawerLayout.closeDrawer(Gravity.START); 79 | 80 | break; 81 | case 2: 82 | mDrawerList.setBackgroundColor(getResources().getColor(R.color.blue)); 83 | toolbar.setBackgroundColor(getResources().getColor(R.color.blue)); 84 | slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.blue)); 85 | mDrawerLayout.closeDrawer(Gravity.START); 86 | 87 | break; 88 | case 3: 89 | mDrawerList.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800)); 90 | toolbar.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800)); 91 | slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800)); 92 | mDrawerLayout.closeDrawer(Gravity.START); 93 | 94 | break; 95 | } 96 | 97 | } 98 | }); 99 | } 100 | 101 | @Override 102 | public boolean onOptionsItemSelected(MenuItem item) { 103 | 104 | if (drawerToggle.onOptionsItemSelected(item)) { 105 | return true; 106 | } 107 | 108 | switch (item.getItemId()) { 109 | case android.R.id.home: 110 | mDrawerLayout.openDrawer(Gravity.START); 111 | return true; 112 | } 113 | 114 | return super.onOptionsItemSelected(item); 115 | } 116 | 117 | 118 | @Override 119 | protected void onPostCreate(Bundle savedInstanceState) { 120 | super.onPostCreate(savedInstanceState); 121 | drawerToggle.syncState(); 122 | } 123 | 124 | @Override 125 | public void onConfigurationChanged(Configuration newConfig) { 126 | super.onConfigurationChanged(newConfig); 127 | drawerToggle.onConfigurationChanged(newConfig); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/SampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | public class SampleFragment extends Fragment { 10 | 11 | private static final String ARG_POSITION = "position"; 12 | 13 | private int position; 14 | 15 | public static SampleFragment newInstance(int position) { 16 | SampleFragment f = new SampleFragment(); 17 | Bundle b = new Bundle(); 18 | b.putInt(ARG_POSITION, position); 19 | f.setArguments(b); 20 | return f; 21 | } 22 | 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 25 | position = getArguments().getInt(ARG_POSITION); 26 | View rootView = inflater.inflate(R.layout.page, container, false); 27 | 28 | ProgressBarCircular progressBarCircular = (ProgressBarCircular) rootView.findViewById(R.id.progress); 29 | FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fabButton); 30 | fab.setDrawableIcon(getResources().getDrawable(R.drawable.plus)); 31 | switch (position) { 32 | case 0: 33 | fab.setBackgroundColor(getResources().getColor(R.color.material_deep_teal_500)); 34 | progressBarCircular.setBackgroundColor(getResources().getColor(R.color.material_deep_teal_500)); 35 | break; 36 | case 1: 37 | fab.setBackgroundColor(getResources().getColor(R.color.red)); 38 | progressBarCircular.setBackgroundColor(getResources().getColor(R.color.red)); 39 | 40 | break; 41 | case 2: 42 | progressBarCircular.setBackgroundColor(getResources().getColor(R.color.blue)); 43 | fab.setBackgroundColor(getResources().getColor(R.color.blue)); 44 | 45 | break; 46 | case 3: 47 | fab.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800)); 48 | progressBarCircular.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800)); 49 | 50 | break; 51 | } 52 | 53 | return rootView; 54 | } 55 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/SlidingTabLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.tekinarslan.material.sample; 18 | 19 | import android.content.Context; 20 | import android.graphics.Color; 21 | import android.graphics.Typeface; 22 | import android.support.v4.view.PagerAdapter; 23 | import android.support.v4.view.ViewPager; 24 | import android.util.AttributeSet; 25 | import android.util.SparseArray; 26 | import android.util.TypedValue; 27 | import android.view.Gravity; 28 | import android.view.LayoutInflater; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.widget.HorizontalScrollView; 32 | import android.widget.LinearLayout; 33 | import android.widget.TextView; 34 | 35 | /** 36 | * To be used with ViewPager to provide a tab indicator component which give constant feedback as to 37 | * the user's scroll progress. 38 | *

39 | * To use the component, simply add it to your view hierarchy. Then in your 40 | * {@link android.app.Activity} or {@link android.support.v4.app.Fragment} call 41 | * {@link #setViewPager(android.support.v4.view.ViewPager)} providing it the ViewPager this layout is being used for. 42 | *

43 | * The colors can be customized in two ways. The first and simplest is to provide an array of colors 44 | * via {@link #setSelectedIndicatorColors(int...)}. The 45 | * alternative is via the {@link com.tekinarslan.material.sample.SlidingTabLayout.TabColorizer} interface which provides you complete control over 46 | * which color is used for any individual position. 47 | *

48 | * The views used as tabs can be customized by calling {@link #setCustomTabView(int, int)}, 49 | * providing the layout ID of your custom layout. 50 | */ 51 | public class SlidingTabLayout extends HorizontalScrollView { 52 | /** 53 | * Allows complete control over the colors drawn in the tab layout. Set with 54 | * {@link #setCustomTabColorizer(com.tekinarslan.material.sample.SlidingTabLayout.TabColorizer)}. 55 | */ 56 | public interface TabColorizer { 57 | 58 | /** 59 | * @return return the color of the indicator used when {@code position} is selected. 60 | */ 61 | int getIndicatorColor(int position); 62 | 63 | } 64 | 65 | private static final int TITLE_OFFSET_DIPS = 24; 66 | private static final int TAB_VIEW_PADDING_DIPS = 16; 67 | private static final int TAB_VIEW_TEXT_SIZE_SP = 12; 68 | 69 | private int mTitleOffset; 70 | 71 | private int mTabViewLayoutId; 72 | private int mTabViewTextViewId; 73 | private boolean mDistributeEvenly; 74 | 75 | private ViewPager mViewPager; 76 | private SparseArray mContentDescriptions = new SparseArray<>(); 77 | private ViewPager.OnPageChangeListener mViewPagerPageChangeListener; 78 | 79 | private final SlidingTabStrip mTabStrip; 80 | 81 | public SlidingTabLayout(Context context) { 82 | this(context, null); 83 | } 84 | 85 | public SlidingTabLayout(Context context, AttributeSet attrs) { 86 | this(context, attrs, 0); 87 | } 88 | 89 | public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { 90 | super(context, attrs, defStyle); 91 | 92 | // Disable the Scroll Bar 93 | setHorizontalScrollBarEnabled(false); 94 | // Make sure that the Tab Strips fills this View 95 | setFillViewport(true); 96 | 97 | mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); 98 | 99 | mTabStrip = new SlidingTabStrip(context); 100 | addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 101 | } 102 | 103 | /** 104 | * Set the custom {@link com.tekinarslan.material.sample.SlidingTabLayout.TabColorizer} to be used. 105 | * 106 | * If you only require simple custmisation then you can use 107 | * {@link #setSelectedIndicatorColors(int...)} to achieve 108 | * similar effects. 109 | */ 110 | public void setCustomTabColorizer(TabColorizer tabColorizer) { 111 | mTabStrip.setCustomTabColorizer(tabColorizer); 112 | } 113 | 114 | public void setDistributeEvenly(boolean distributeEvenly) { 115 | mDistributeEvenly = distributeEvenly; 116 | } 117 | 118 | /** 119 | * Sets the colors to be used for indicating the selected tab. These colors are treated as a 120 | * circular array. Providing one color will mean that all tabs are indicated with the same color. 121 | */ 122 | public void setSelectedIndicatorColors(int... colors) { 123 | mTabStrip.setSelectedIndicatorColors(colors); 124 | } 125 | 126 | /** 127 | * Set the {@link android.support.v4.view.ViewPager.OnPageChangeListener}. When using {@link com.tekinarslan.material.sample.SlidingTabLayout} you are 128 | * required to set any {@link android.support.v4.view.ViewPager.OnPageChangeListener} through this method. This is so 129 | * that the layout can update it's scroll position correctly. 130 | * 131 | * @see android.support.v4.view.ViewPager#setOnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) 132 | */ 133 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { 134 | mViewPagerPageChangeListener = listener; 135 | } 136 | 137 | /** 138 | * Set the custom layout to be inflated for the tab views. 139 | * 140 | * @param layoutResId Layout id to be inflated 141 | * @param textViewId id of the {@link android.widget.TextView} in the inflated view 142 | */ 143 | public void setCustomTabView(int layoutResId, int textViewId) { 144 | mTabViewLayoutId = layoutResId; 145 | mTabViewTextViewId = textViewId; 146 | } 147 | 148 | /** 149 | * Sets the associated view pager. Note that the assumption here is that the pager content 150 | * (number of tabs and tab titles) does not change after this call has been made. 151 | */ 152 | public void setViewPager(ViewPager viewPager) { 153 | mTabStrip.removeAllViews(); 154 | 155 | mViewPager = viewPager; 156 | if (viewPager != null) { 157 | viewPager.setOnPageChangeListener(new InternalViewPagerListener()); 158 | populateTabStrip(); 159 | } 160 | } 161 | 162 | /** 163 | * Create a default view to be used for tabs. This is called if a custom tab view is not set via 164 | * {@link #setCustomTabView(int, int)}. 165 | */ 166 | protected TextView createDefaultTabView(Context context) { 167 | TextView textView = new TextView(context); 168 | textView.setGravity(Gravity.CENTER); 169 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); 170 | textView.setTypeface(Typeface.DEFAULT_BOLD); 171 | textView.setLayoutParams(new LinearLayout.LayoutParams( 172 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 173 | 174 | TypedValue outValue = new TypedValue(); 175 | getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, 176 | outValue, true); 177 | textView.setBackgroundResource(outValue.resourceId); 178 | textView.setAllCaps(true); 179 | 180 | int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); 181 | textView.setPadding(padding, padding, padding, padding); 182 | 183 | return textView; 184 | } 185 | 186 | private void populateTabStrip() { 187 | final PagerAdapter adapter = mViewPager.getAdapter(); 188 | final OnClickListener tabClickListener = new TabClickListener(); 189 | 190 | for (int i = 0; i < adapter.getCount(); i++) { 191 | View tabView = null; 192 | TextView tabTitleView = null; 193 | 194 | if (mTabViewLayoutId != 0) { 195 | // If there is a custom tab view layout id set, try and inflate it 196 | tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, 197 | false); 198 | tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); 199 | } 200 | 201 | if (tabView == null) { 202 | tabView = createDefaultTabView(getContext()); 203 | } 204 | 205 | if (tabTitleView == null && TextView.class.isInstance(tabView)) { 206 | tabTitleView = (TextView) tabView; 207 | } 208 | 209 | if (mDistributeEvenly) { 210 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); 211 | lp.width = 0; 212 | lp.weight = 1; 213 | } 214 | 215 | tabTitleView.setText(adapter.getPageTitle(i)); 216 | tabTitleView.setTextColor(Color.WHITE); 217 | tabView.setOnClickListener(tabClickListener); 218 | String desc = mContentDescriptions.get(i, null); 219 | if (desc != null) { 220 | tabView.setContentDescription(desc); 221 | } 222 | 223 | mTabStrip.addView(tabView); 224 | if (i == mViewPager.getCurrentItem()) { 225 | tabView.setSelected(true); 226 | } 227 | } 228 | } 229 | 230 | public void setContentDescription(int i, String desc) { 231 | mContentDescriptions.put(i, desc); 232 | } 233 | 234 | @Override 235 | protected void onAttachedToWindow() { 236 | super.onAttachedToWindow(); 237 | 238 | if (mViewPager != null) { 239 | scrollToTab(mViewPager.getCurrentItem(), 0); 240 | } 241 | } 242 | 243 | private void scrollToTab(int tabIndex, int positionOffset) { 244 | final int tabStripChildCount = mTabStrip.getChildCount(); 245 | if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) { 246 | return; 247 | } 248 | 249 | View selectedChild = mTabStrip.getChildAt(tabIndex); 250 | if (selectedChild != null) { 251 | int targetScrollX = selectedChild.getLeft() + positionOffset; 252 | 253 | if (tabIndex > 0 || positionOffset > 0) { 254 | // If we're not at the first child and are mid-scroll, make sure we obey the offset 255 | targetScrollX -= mTitleOffset; 256 | } 257 | 258 | scrollTo(targetScrollX, 0); 259 | } 260 | } 261 | 262 | private class InternalViewPagerListener implements ViewPager.OnPageChangeListener { 263 | private int mScrollState; 264 | 265 | @Override 266 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 267 | int tabStripChildCount = mTabStrip.getChildCount(); 268 | if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) { 269 | return; 270 | } 271 | 272 | mTabStrip.onViewPagerPageChanged(position, positionOffset); 273 | 274 | View selectedTitle = mTabStrip.getChildAt(position); 275 | int extraOffset = (selectedTitle != null) 276 | ? (int) (positionOffset * selectedTitle.getWidth()) 277 | : 0; 278 | scrollToTab(position, extraOffset); 279 | 280 | if (mViewPagerPageChangeListener != null) { 281 | mViewPagerPageChangeListener.onPageScrolled(position, positionOffset, 282 | positionOffsetPixels); 283 | } 284 | } 285 | 286 | @Override 287 | public void onPageScrollStateChanged(int state) { 288 | mScrollState = state; 289 | 290 | if (mViewPagerPageChangeListener != null) { 291 | mViewPagerPageChangeListener.onPageScrollStateChanged(state); 292 | } 293 | } 294 | 295 | @Override 296 | public void onPageSelected(int position) { 297 | if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { 298 | mTabStrip.onViewPagerPageChanged(position, 0f); 299 | scrollToTab(position, 0); 300 | } 301 | for (int i = 0; i < mTabStrip.getChildCount(); i++) { 302 | mTabStrip.getChildAt(i).setSelected(position == i); 303 | } 304 | if (mViewPagerPageChangeListener != null) { 305 | mViewPagerPageChangeListener.onPageSelected(position); 306 | } 307 | } 308 | 309 | } 310 | 311 | private class TabClickListener implements OnClickListener { 312 | @Override 313 | public void onClick(View v) { 314 | for (int i = 0; i < mTabStrip.getChildCount(); i++) { 315 | if (v == mTabStrip.getChildAt(i)) { 316 | mViewPager.setCurrentItem(i); 317 | return; 318 | } 319 | } 320 | } 321 | } 322 | 323 | } 324 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/SlidingTabStrip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.tekinarslan.material.sample; 18 | 19 | import android.R; 20 | import android.content.Context; 21 | import android.graphics.Canvas; 22 | import android.graphics.Color; 23 | import android.graphics.Paint; 24 | import android.util.AttributeSet; 25 | import android.util.TypedValue; 26 | import android.view.View; 27 | import android.widget.LinearLayout; 28 | 29 | 30 | class SlidingTabStrip extends LinearLayout { 31 | 32 | private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0; 33 | private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26; 34 | private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3; 35 | private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5; 36 | 37 | private final int mBottomBorderThickness; 38 | private final Paint mBottomBorderPaint; 39 | 40 | private final int mSelectedIndicatorThickness; 41 | private final Paint mSelectedIndicatorPaint; 42 | 43 | private final int mDefaultBottomBorderColor; 44 | 45 | private int mSelectedPosition; 46 | private float mSelectionOffset; 47 | 48 | private SlidingTabLayout.TabColorizer mCustomTabColorizer; 49 | private final SimpleTabColorizer mDefaultTabColorizer; 50 | 51 | SlidingTabStrip(Context context) { 52 | this(context, null); 53 | } 54 | 55 | SlidingTabStrip(Context context, AttributeSet attrs) { 56 | super(context, attrs); 57 | setWillNotDraw(false); 58 | 59 | final float density = getResources().getDisplayMetrics().density; 60 | 61 | TypedValue outValue = new TypedValue(); 62 | context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true); 63 | final int themeForegroundColor = outValue.data; 64 | 65 | mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor, 66 | DEFAULT_BOTTOM_BORDER_COLOR_ALPHA); 67 | 68 | mDefaultTabColorizer = new SimpleTabColorizer(); 69 | mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR); 70 | 71 | mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density); 72 | mBottomBorderPaint = new Paint(); 73 | mBottomBorderPaint.setColor(mDefaultBottomBorderColor); 74 | 75 | mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density); 76 | mSelectedIndicatorPaint = new Paint(); 77 | } 78 | 79 | void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) { 80 | mCustomTabColorizer = customTabColorizer; 81 | invalidate(); 82 | } 83 | 84 | void setSelectedIndicatorColors(int... colors) { 85 | // Make sure that the custom colorizer is removed 86 | mCustomTabColorizer = null; 87 | mDefaultTabColorizer.setIndicatorColors(colors); 88 | invalidate(); 89 | } 90 | 91 | void onViewPagerPageChanged(int position, float positionOffset) { 92 | mSelectedPosition = position; 93 | mSelectionOffset = positionOffset; 94 | invalidate(); 95 | } 96 | 97 | @Override 98 | protected void onDraw(Canvas canvas) { 99 | final int height = getHeight(); 100 | final int childCount = getChildCount(); 101 | final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null 102 | ? mCustomTabColorizer 103 | : mDefaultTabColorizer; 104 | 105 | // Thick colored underline below the current selection 106 | if (childCount > 0) { 107 | View selectedTitle = getChildAt(mSelectedPosition); 108 | int left = selectedTitle.getLeft(); 109 | int right = selectedTitle.getRight(); 110 | int color = tabColorizer.getIndicatorColor(mSelectedPosition); 111 | 112 | if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) { 113 | int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1); 114 | if (color != nextColor) { 115 | color = blendColors(nextColor, color, mSelectionOffset); 116 | } 117 | 118 | // Draw the selection partway between the tabs 119 | View nextTitle = getChildAt(mSelectedPosition + 1); 120 | left = (int) (mSelectionOffset * nextTitle.getLeft() + 121 | (1.0f - mSelectionOffset) * left); 122 | right = (int) (mSelectionOffset * nextTitle.getRight() + 123 | (1.0f - mSelectionOffset) * right); 124 | } 125 | 126 | mSelectedIndicatorPaint.setColor(color); 127 | 128 | canvas.drawRect(left, height - mSelectedIndicatorThickness, right, 129 | height, mSelectedIndicatorPaint); 130 | } 131 | 132 | // Thin underline along the entire bottom edge 133 | canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint); 134 | } 135 | 136 | /** 137 | * Set the alpha value of the {@code color} to be the given {@code alpha} value. 138 | */ 139 | private static int setColorAlpha(int color, byte alpha) { 140 | return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); 141 | } 142 | 143 | /** 144 | * Blend {@code color1} and {@code color2} using the given ratio. 145 | * 146 | * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend, 147 | * 0.0 will return {@code color2}. 148 | */ 149 | private static int blendColors(int color1, int color2, float ratio) { 150 | final float inverseRation = 1f - ratio; 151 | float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); 152 | float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); 153 | float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); 154 | return Color.rgb((int) r, (int) g, (int) b); 155 | } 156 | 157 | private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer { 158 | private int[] mIndicatorColors; 159 | 160 | @Override 161 | public final int getIndicatorColor(int position) { 162 | return mIndicatorColors[position % mIndicatorColors.length]; 163 | } 164 | 165 | void setIndicatorColors(int... colors) { 166 | mIndicatorColors = colors; 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/ToolBarMaterial.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Bitmap.Config; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.GradientDrawable; 12 | import android.graphics.drawable.LayerDrawable; 13 | import android.util.AttributeSet; 14 | import android.util.TypedValue; 15 | import android.view.MotionEvent; 16 | import android.widget.RelativeLayout; 17 | import android.widget.TextView; 18 | 19 | 20 | 21 | public class ToolbarMaterial extends AppCompactActivity 22 | { 23 | 24 | public void onCreate(Bundle bundle) 25 | { 26 | super.onCreate(bundle); 27 | setContentView(R.layout.ToolbarMaterial); 28 | 29 | mTopToolbar = (Toolbar) findViewById(R.id.my_toolbar); 30 | setSupportActionBar(mTopToolbar); 31 | } 32 | 33 | 34 | 35 | 36 | 37 | public boolean onCreateOptionsMenu(Menu menu) { 38 | 39 | getMenuInflater().inflate(R.menu.menu_main, menu); 40 | return true; 41 | } 42 | 43 | 44 | public void Item1(View view) 45 | { 46 | Button button1 =findViewById(R.id.button1); 47 | button1.setOnClickListener(new OnClickListener() 48 | { 49 | public void onClick(View view) 50 | { 51 | 52 | Toast.makeText(this,"Hey you Have done this!!",Toast.LENGTH_LONG).show(); 53 | } 54 | }); 55 | } 56 | 57 | 58 | 59 | public void Item1(View view) 60 | { 61 | Button button2=findViewById(R.id.button2); 62 | button2.setOnClickListener(new OnClickListener() 63 | { 64 | public void onClick(View view) 65 | { 66 | 67 | Toast.makeText(this,"Hey you Have done this!!",Toast.LENGTH_LONG).show(); 68 | 69 | Intent intent=new Intent(this,YourNewActivity.class); 70 | startActivity(intent); 71 | finish(); 72 | } 73 | }); 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/tekinarslan/material/sample/ViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tekinarslan.material.sample; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | public class ViewPagerAdapter extends FragmentPagerAdapter { 8 | 9 | final int PAGE_COUNT =8; 10 | private String[] titles; 11 | 12 | public ViewPagerAdapter(FragmentManager fm, String[] titles2) { 13 | super(fm); 14 | titles=titles2; 15 | } 16 | 17 | @Override 18 | public Fragment getItem(int position) { 19 | switch (position) { 20 | // Open FragmentTab1.java 21 | case 0: 22 | return SampleFragment.newInstance(position); 23 | case 1: 24 | return SampleFragment.newInstance(position); 25 | case 2: 26 | return SampleFragment.newInstance(position); 27 | case 3: 28 | return SampleFragment.newInstance(position); 29 | case 4: 30 | return SampleFragment.newInstance(position); 31 | case 5: 32 | return SampleFragment.newInstance(position); 33 | case 6: 34 | return SampleFragment.newInstance(position); 35 | case 7: 36 | return SampleFragment.newInstance(position); 37 | 38 | } 39 | return null; 40 | } 41 | 42 | public CharSequence getPageTitle(int position) { 43 | return titles[position]; 44 | } 45 | 46 | @Override 47 | public int getCount() { 48 | return PAGE_COUNT; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/background_card.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-hdpi/background_card.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_ab_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-hdpi/ic_ab_drawer.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-hdpi/plus.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-hdpi/shadow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_ab_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xhdpi/ic_ab_drawer.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xhdpi/plus.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xhdpi/shadow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_ab_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xxhdpi/ic_ab_drawer.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tekinarslan/AndroidMaterialDesignToolbar/893cc28b24c61c11253ab5b02e77fe41d1f7b49e/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/fab.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/ToolBarMaterial.java: -------------------------------------------------------------------------------- 1 | 5 | 6 |