├── .gitignore ├── AndroidManifest.xml ├── LICENSE ├── ProgressButton.gif ├── README.md ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── lint.xml ├── proguard-project.txt ├── project.properties ├── res ├── anim │ ├── scale_in.xml │ └── scale_out.xml ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── drawable │ └── circle.xml ├── layout │ └── activity_main.xml ├── menu │ └── main.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml └── values │ ├── color.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── screenshots ├── progressshot1.png ├── progressshot2.png ├── progressshot3.png └── progressshot4.png └── src └── com └── thbs └── progressbutton ├── CusImage.java ├── MainActivity.java └── MasterLayout.java /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Vyshakh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /ProgressButton.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/ProgressButton.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TH-ProgressButton 2 | ============ 3 | Circular progress View button inspired by [FFCircularProgressView](https://github.com/elbryan/FFCircularProgressView) 4 | 5 | ![alt text](https://raw.github.com/Vyshakh-K/TH-ProgressButton/master/screenshots/progressshot1.png "Start state") 6 | 7 | ![alt text](https://raw.github.com/Vyshakh-K/TH-ProgressButton/master/screenshots/progressshot2.png "Running state") 8 | 9 | ![alt text](https://raw.github.com/Vyshakh-K/TH-ProgressButton/master/screenshots/progressshot3.png "Progress state") 10 | 11 | ![alt text](https://raw.github.com/Vyshakh-K/TH-ProgressButton/master/screenshots/progressshot4.png "End state") 12 | 13 | ![alt text](https://raw.github.com/Vyshakh-K/TH-ProgressButton/master/ProgressButton.gif "Progress Button") 14 | 15 | ##How to use: 16 | 1. Deployment target should be Api level 13 or above. 17 | 18 | 2. Add `com.thbs.progressbutton.MasterLayout.java` and `com.thbs.progressbutton.CusImage.java` to your project. 19 | 20 | 21 | 3. ##Layout: 22 | 23 | 30 | 31 | 32 | 33 | 34 | 35 | 4. ##Activity 36 | 37 | static MasterLayout masterLayout; //Should be static 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | 42 | masterLayout = (MasterLayout) findViewById(R.id.MasterLayout01); 43 | 44 | //Onclick listener of the progress button 45 | masterLayout.setOnClickListener(new OnClickListener() { 46 | 47 | @Override 48 | public void onClick(View v) { 49 | // TODO Auto-generated method stub 50 | 51 | masterLayout.animation(); //Need to call this method for animation and progression 52 | 53 | switch (masterLayout.flg_frmwrk_mode) { 54 | 55 | case 1: 56 | //Start state. Call your method 57 | break; 58 | case 2: 59 | 60 | //Running state. Call your method 61 | break; 62 | 63 | case 3: 64 | 65 | //End state. Call your method 66 | break; 67 | } 68 | } 69 | }); 70 | } 71 | 72 | 73 | 74 | 75 | 76 | 5. ##Updating the progress 77 | 78 | 79 | Send the progress to MasterLayout's "cusview.setupprogress()" method from AsyncTask's "onProgressUpdate()". 80 | 81 | @Override 82 | protected void onProgressUpdate(Integer... progress) 83 | { 84 | 85 | //publishing progress to progress arc 86 | masterLayout.cusview.setupprogress(progress[0]); 87 | 88 | } 89 | 90 | 91 | 92 | 93 | 94 | 6. ##Customization 95 | 96 | - Basic customization can be done in "com.thbs.progressbutton.MasterLayout.java". 97 | 98 | Circle related customization: 99 | 100 | stroke_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change the circle color 101 | 102 | fill_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change the circle fill color 103 | 104 | 105 | Icon related customization: 106 | 107 | icon_color.setStyle(Paint.Style.FILL_AND_STROKE); // Edit this to change the icon color 108 | 109 | 110 | final_icon_color.setColor(Color.WHITE); // Edit this to change the final icon color 111 | 112 | 113 | 114 | Create new icons using path or use the existing icons in method "iconCreate()" 115 | 116 | 117 | 118 | - Progress arc color can be changed from "com.thbs.progressbutton.CusImage.java" using: 119 | 120 | 121 | 122 | myPaint.setColor(Color.rgb(0, 161, 234)); 123 | 124 | 125 | ##Are you using this framework? 126 | 127 | - If you are using this framework please feel free to add your app to the [wiki](https://github.com/torryharris/TH-ProgressButton/wiki/Apps). 128 | 129 | 130 | ##Demo 131 | Please download and run the [project](https://github.com/torryharris/TH-ProgressButton) to view demo. 132 | 133 | ##License 134 | ProgressButton is licensed under the terms of the MIT License. Please see the [License](https://github.com/torryharris/TH-ProgressButton/blob/master/LICENSE) file for full details. 135 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/libs/android-support-v4.jar -------------------------------------------------------------------------------- /lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-18 15 | android.library=false 16 | -------------------------------------------------------------------------------- /res/anim/scale_in.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /res/anim/scale_out.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #00ACEE 4 | 5 | 6 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProgressFramework 5 | Settings 6 | Hello world! 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /screenshots/progressshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/screenshots/progressshot1.png -------------------------------------------------------------------------------- /screenshots/progressshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/screenshots/progressshot2.png -------------------------------------------------------------------------------- /screenshots/progressshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/screenshots/progressshot3.png -------------------------------------------------------------------------------- /screenshots/progressshot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torryharris/TH-ProgressButton/d51fae694e4fded155dfb366f3ad9e2c99d837b3/screenshots/progressshot4.png -------------------------------------------------------------------------------- /src/com/thbs/progressbutton/CusImage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.thbs.progressbutton; 3 | 4 | /** 5 | * @author Vyshakh, Rahul 6 | * 7 | */ 8 | import android.content.Context; 9 | import android.graphics.Canvas; 10 | import android.graphics.Color; 11 | import android.graphics.Paint; 12 | import android.graphics.RectF; 13 | import android.util.AttributeSet; 14 | import android.util.DisplayMetrics; 15 | import android.view.View; 16 | import android.widget.TextView; 17 | 18 | public class CusImage extends View { 19 | 20 | private Paint myPaint; 21 | private Paint myFramePaint; 22 | public TextView value; 23 | private float startAngle; 24 | public float temp; 25 | float sweepAngle; 26 | private int flag = 0; 27 | RectF rect; 28 | private MasterLayout m; 29 | int pix = 0; 30 | 31 | public CusImage(Context context, AttributeSet attrs, MasterLayout m) { 32 | super(context, attrs); 33 | this.m = m; 34 | init(); 35 | } 36 | 37 | public CusImage(Context context, MasterLayout m) { 38 | super(context); 39 | this.m = m; 40 | init(); 41 | } 42 | 43 | private void init() { 44 | 45 | myPaint = new Paint(); 46 | DisplayMetrics metrics = getContext().getResources() 47 | .getDisplayMetrics(); 48 | int width = metrics.widthPixels; 49 | int height = metrics.heightPixels; 50 | float scarea = width * height; 51 | pix = (int) Math.sqrt(scarea * 0.0217); 52 | 53 | myPaint.setAntiAlias(true); 54 | myPaint.setStyle(Paint.Style.STROKE); 55 | myPaint.setColor(Color.rgb(0, 161, 234)); //Edit this to change progress arc color. 56 | myPaint.setStrokeWidth(7); 57 | 58 | myFramePaint = new Paint(); 59 | myFramePaint.setAntiAlias(true); 60 | myFramePaint.setColor(Color.TRANSPARENT); 61 | 62 | float startx = (float) (pix * 0.05); 63 | float endx = (float) (pix * 0.95); 64 | float starty = (float) (pix * 0.05); 65 | float endy = (float) (pix * 0.95); 66 | rect = new RectF(startx, starty, endx, endy); 67 | } 68 | 69 | public void setupprogress(int progress) { 70 | 71 | //Updating progress arc 72 | 73 | sweepAngle = (float) (progress * 3.6); 74 | 75 | } 76 | 77 | public void reset() { 78 | 79 | //Resetting progress arc 80 | 81 | sweepAngle = 0; 82 | startAngle = -90; 83 | flag = 1; 84 | } 85 | 86 | @Override 87 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 88 | 89 | int desiredWidth = pix; 90 | int desiredHeight = pix; 91 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 92 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 93 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 94 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); 95 | 96 | int width; 97 | int height; 98 | 99 | 100 | if (widthMode == MeasureSpec.EXACTLY) { 101 | 102 | width = widthSize; 103 | } else if (widthMode == MeasureSpec.AT_MOST) { 104 | 105 | width = Math.min(desiredWidth, widthSize); 106 | } else { 107 | 108 | width = desiredWidth; 109 | } 110 | 111 | 112 | if (heightMode == MeasureSpec.EXACTLY) { 113 | 114 | height = heightSize; 115 | } else if (heightMode == MeasureSpec.AT_MOST) { 116 | 117 | height = Math.min(desiredHeight, heightSize); 118 | } else { 119 | 120 | height = desiredHeight; 121 | } 122 | 123 | 124 | setMeasuredDimension(width, height); 125 | } 126 | 127 | @Override 128 | protected void onDraw(Canvas canvas) { 129 | 130 | canvas.drawArc(rect, startAngle, sweepAngle, false, myPaint); 131 | startAngle = -90; 132 | 133 | if (sweepAngle < 360 && flag == 0) { 134 | 135 | invalidate(); 136 | 137 | } else if (flag == 1) { 138 | 139 | sweepAngle = 0; 140 | startAngle = -90; 141 | flag = 0; 142 | invalidate(); 143 | } else { 144 | 145 | sweepAngle = 0; 146 | startAngle = -90; 147 | m.finalAnimation(); 148 | 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/com/thbs/progressbutton/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.thbs.progressbutton; 2 | 3 | import com.example.progressframework.R; 4 | 5 | import android.app.Activity; 6 | import android.graphics.Canvas; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.view.View; 10 | import android.view.View.OnClickListener; 11 | import android.widget.Toast; 12 | 13 | public class MainActivity extends Activity { 14 | 15 | 16 | static MasterLayout masterLayout; 17 | 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | 24 | 25 | masterLayout = (MasterLayout) findViewById(R.id.MasterLayout01); 26 | 27 | //Onclick listener of the progress button 28 | masterLayout.setOnClickListener(new OnClickListener() { 29 | 30 | @Override 31 | public void onClick(View v) { 32 | // TODO Auto-generated method stub 33 | 34 | 35 | masterLayout.animation(); //Need to call this method for animation and progression 36 | 37 | if (masterLayout.flg_frmwrk_mode == 1) { 38 | 39 | //Start state. Call any method that you want to execute 40 | 41 | runOnUiThread(new Runnable() { 42 | 43 | @Override 44 | public void run() { 45 | // TODO Auto-generated method stub 46 | Toast.makeText(MainActivity.this, 47 | "Starting download", Toast.LENGTH_SHORT) 48 | .show(); 49 | } 50 | }); 51 | new DownLoadSigTask().execute(); 52 | } 53 | if (masterLayout.flg_frmwrk_mode == 2) { 54 | 55 | //Running state. Call any method that you want to execute 56 | 57 | new DownLoadSigTask().cancel(true); 58 | masterLayout.reset(); 59 | runOnUiThread(new Runnable() { 60 | 61 | @Override 62 | public void run() { 63 | // TODO Auto-generated method stub 64 | Toast.makeText(MainActivity.this, 65 | "Download stopped", Toast.LENGTH_SHORT) 66 | .show(); 67 | } 68 | }); 69 | } 70 | if (masterLayout.flg_frmwrk_mode == 3) { 71 | 72 | //End state. Call any method that you want to execute. 73 | 74 | runOnUiThread(new Runnable() { 75 | 76 | @Override 77 | public void run() { 78 | // TODO Auto-generated method stub 79 | Toast.makeText(MainActivity.this, 80 | "Download complete", Toast.LENGTH_SHORT) 81 | .show(); 82 | } 83 | }); 84 | } 85 | } 86 | }); 87 | 88 | } 89 | 90 | static class DownLoadSigTask extends AsyncTask { 91 | 92 | 93 | @Override 94 | protected void onPreExecute() { 95 | 96 | } 97 | 98 | 99 | @Override 100 | protected String doInBackground(final String... args) { 101 | 102 | //Creating dummy task and updating progress 103 | 104 | for (int i = 0; i <= 100; i++) { 105 | try { 106 | Thread.sleep(50); 107 | 108 | } catch (InterruptedException e) { 109 | 110 | e.printStackTrace(); 111 | } 112 | publishProgress(i); 113 | 114 | } 115 | 116 | 117 | return null; 118 | } 119 | 120 | 121 | @Override 122 | protected void onProgressUpdate(Integer... progress) { 123 | 124 | //publishing progress to progress arc 125 | 126 | masterLayout.cusview.setupprogress(progress[0]); 127 | } 128 | 129 | 130 | 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/com/thbs/progressbutton/MasterLayout.java: -------------------------------------------------------------------------------- 1 | package com.thbs.progressbutton; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.Path; 9 | import android.graphics.RectF; 10 | import android.util.AttributeSet; 11 | import android.util.DisplayMetrics; 12 | import android.view.View; 13 | import android.view.View.OnClickListener; 14 | import android.view.animation.AccelerateDecelerateInterpolator; 15 | import android.view.animation.AlphaAnimation; 16 | import android.view.animation.Animation; 17 | import android.view.animation.Animation.AnimationListener; 18 | import android.view.animation.AnimationSet; 19 | import android.view.animation.RotateAnimation; 20 | import android.view.animation.ScaleAnimation; 21 | import android.widget.FrameLayout; 22 | import android.widget.ImageView; 23 | 24 | public class MasterLayout extends FrameLayout implements OnClickListener { 25 | 26 | public CusImage cusview; 27 | public int pix = 0; 28 | public RectF rect; 29 | 30 | private ImageView buttonimage, fillcircle, full_circle_image, arc_image; 31 | 32 | private Path stop, tick, play, download_triangle, download_rectangle; 33 | 34 | private Bitmap third_icon_bmp, second_icon_bmp, first_icon_bmp; 35 | 36 | private Paint stroke_color, fill_color, icon_color, final_icon_color; 37 | 38 | private AnimationSet in, out; 39 | 40 | private RotateAnimation arcRotation; 41 | 42 | private ScaleAnimation new_scale_in, scale_in, scale_out; 43 | 44 | private AlphaAnimation fade_in, fade_out; 45 | 46 | int flg_frmwrk_mode = 0; 47 | boolean first_click = false; 48 | 49 | public MasterLayout(Context context, AttributeSet attrs) { 50 | super(context, attrs); 51 | // TODO Auto-generated constructor stub 52 | setOnClickListener(this); 53 | 54 | initialise(); 55 | setpaint(); 56 | setAnimation(); 57 | displayMetrics(); 58 | iconCreate(); 59 | init(); 60 | 61 | } 62 | 63 | public MasterLayout(Context context) { 64 | super(context); 65 | // TODO Auto-generated constructor stub 66 | setOnClickListener(this); 67 | setBackgroundColor(Color.CYAN); 68 | initialise(); 69 | setpaint(); 70 | setAnimation(); 71 | displayMetrics(); 72 | iconCreate(); 73 | init(); 74 | 75 | } 76 | 77 | private void initialise() { 78 | cusview = new CusImage(getContext(), this); 79 | buttonimage = new ImageView(getContext()); 80 | full_circle_image = new ImageView(getContext()); 81 | arc_image = new ImageView(getContext()); 82 | 83 | fillcircle = new ImageView(getContext()); 84 | cusview.setClickable(false); 85 | buttonimage.setClickable(false); 86 | full_circle_image.setClickable(false); 87 | arc_image.setClickable(false); 88 | 89 | cusview.setClickable(false); 90 | setClickable(true); 91 | fillcircle.setClickable(false); 92 | 93 | } 94 | 95 | private void setpaint() { 96 | 97 | // Setting up color 98 | 99 | stroke_color = new Paint(Paint.ANTI_ALIAS_FLAG); 100 | stroke_color.setAntiAlias(true); 101 | stroke_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change 102 | // the circle color 103 | stroke_color.setStrokeWidth(3); 104 | stroke_color.setStyle(Paint.Style.STROKE); 105 | 106 | icon_color = new Paint(Paint.ANTI_ALIAS_FLAG); 107 | icon_color.setColor(Color.rgb(0, 161, 234)); 108 | icon_color.setStyle(Paint.Style.FILL_AND_STROKE); // Edit this to change 109 | // the icon color 110 | icon_color.setAntiAlias(true); 111 | 112 | final_icon_color = new Paint(Paint.ANTI_ALIAS_FLAG); 113 | final_icon_color.setColor(Color.WHITE); // Edit this to change the final 114 | // icon color 115 | final_icon_color.setStrokeWidth(12); 116 | final_icon_color.setStyle(Paint.Style.STROKE); 117 | final_icon_color.setAntiAlias(true); 118 | 119 | fill_color = new Paint(Paint.ANTI_ALIAS_FLAG); 120 | fill_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change the 121 | // circle fill color 122 | fill_color.setStyle(Paint.Style.FILL_AND_STROKE); 123 | fill_color.setAntiAlias(true); 124 | 125 | } 126 | 127 | private void setAnimation() { 128 | 129 | // Setting up and defining view animations. 130 | 131 | arcRotation = new RotateAnimation(0.0f, 360.0f, 132 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 133 | 0.5f); 134 | arcRotation.setDuration(1000); 135 | 136 | in = new AnimationSet(true); 137 | out = new AnimationSet(true); 138 | 139 | out.setInterpolator(new AccelerateDecelerateInterpolator()); 140 | in.setInterpolator(new AccelerateDecelerateInterpolator()); 141 | 142 | scale_in = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, 143 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 144 | 0.5f); 145 | scale_out = new ScaleAnimation(1.0f, 3.0f, 1.0f, 3.0f, 146 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 147 | 0.5f); 148 | new_scale_in = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, 149 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 150 | 0.5f); 151 | 152 | new_scale_in.setDuration(200); 153 | 154 | fade_in = new AlphaAnimation(0.0f, 1.0f); 155 | fade_out = new AlphaAnimation(1.0f, 0.0f); 156 | 157 | scale_in.setDuration(150); 158 | scale_out.setDuration(150); 159 | fade_in.setDuration(150); 160 | fade_out.setDuration(150); 161 | 162 | in.addAnimation(scale_in); 163 | in.addAnimation(fade_in); 164 | out.addAnimation(fade_out); 165 | out.addAnimation(scale_out); 166 | 167 | arcRotation.setAnimationListener(new AnimationListener() { 168 | 169 | @Override 170 | public void onAnimationStart(Animation arg0) { 171 | // TODO Auto-generated method stub 172 | 173 | } 174 | 175 | @Override 176 | public void onAnimationRepeat(Animation arg0) { 177 | // TODO Auto-generated method stub 178 | 179 | } 180 | 181 | @Override 182 | public void onAnimationEnd(Animation arg0) { 183 | // TODO Auto-generated method stub 184 | 185 | first_click = false; 186 | buttonimage.startAnimation(out); 187 | 188 | } 189 | }); 190 | 191 | out.setAnimationListener(new AnimationListener() { 192 | 193 | @Override 194 | public void onAnimationStart(Animation animation) { 195 | // TODO Auto-generated method stub 196 | System.out.println("print this"); 197 | } 198 | 199 | @Override 200 | public void onAnimationRepeat(Animation animation) { 201 | // TODO Auto-generated method stub 202 | 203 | } 204 | 205 | @Override 206 | public void onAnimationEnd(Animation animation) { 207 | // TODO Auto-generated method stub 208 | 209 | buttonimage.setVisibility(View.GONE); 210 | buttonimage.setImageBitmap(second_icon_bmp); 211 | buttonimage.setVisibility(View.VISIBLE); 212 | buttonimage.startAnimation(in); 213 | arc_image.setVisibility(View.GONE); 214 | full_circle_image.setVisibility(View.VISIBLE); 215 | cusview.setVisibility(View.VISIBLE); 216 | 217 | flg_frmwrk_mode = 2; 218 | 219 | System.out.println("flg_frmwrk_mode" + flg_frmwrk_mode); 220 | 221 | 222 | } 223 | }); 224 | 225 | new_scale_in.setAnimationListener(new AnimationListener() { 226 | 227 | @Override 228 | public void onAnimationStart(Animation animation) { 229 | // TODO Auto-generated method stub 230 | 231 | } 232 | 233 | @Override 234 | public void onAnimationRepeat(Animation animation) { 235 | // TODO Auto-generated method stub 236 | 237 | } 238 | 239 | @Override 240 | public void onAnimationEnd(Animation animation) { 241 | // TODO Auto-generated method stub 242 | cusview.setVisibility(View.GONE); 243 | buttonimage.setVisibility(View.VISIBLE); 244 | buttonimage.setImageBitmap(third_icon_bmp); 245 | flg_frmwrk_mode = 3; 246 | buttonimage.startAnimation(in); 247 | 248 | 249 | } 250 | }); 251 | 252 | } 253 | 254 | private void displayMetrics() { 255 | 256 | // Responsible for calculating the size of views and canvas based upon 257 | // screen resolution. 258 | 259 | DisplayMetrics metrics = getContext().getResources() 260 | .getDisplayMetrics(); 261 | 262 | int width = metrics.widthPixels; 263 | int height = metrics.heightPixels; 264 | float scarea = width * height; 265 | pix = (int) Math.sqrt(scarea * 0.0217); 266 | 267 | } 268 | 269 | private void iconCreate() { 270 | 271 | // Creating icons using path 272 | // Create your own icons or feel free to use these 273 | 274 | play = new Path(); 275 | play.moveTo(pix * 40 / 100, pix * 36 / 100); 276 | play.lineTo(pix * 40 / 100, pix * 63 / 100); 277 | play.lineTo(pix * 69 / 100, pix * 50 / 100); 278 | play.close(); 279 | 280 | stop = new Path(); 281 | stop.moveTo(pix * 38 / 100, pix * 38 / 100); 282 | stop.lineTo(pix * 62 / 100, pix * 38 / 100); 283 | stop.lineTo(pix * 62 / 100, pix * 62 / 100); 284 | stop.lineTo(pix * 38 / 100, pix * 62 / 100); 285 | stop.close(); 286 | 287 | download_triangle = new Path(); 288 | download_triangle.moveTo(pix * 375 / 1000, (pix / 2) 289 | + (pix * 625 / 10000) - (pix * 3 / 100)); 290 | download_triangle.lineTo(pix / 2, (pix * 625 / 1000) 291 | + (pix * 625 / 10000) - (pix * 3 / 100)); 292 | download_triangle.lineTo(pix * 625 / 1000, (pix / 2) 293 | + (pix * 625 / 10000) - (pix * 3 / 100)); 294 | download_triangle.close(); 295 | 296 | download_rectangle = new Path(); 297 | download_rectangle.moveTo(pix * 4375 / 10000, (pix / 2) 298 | + (pix * 625 / 10000) - (pix * 3 / 100)); 299 | download_rectangle.lineTo(pix * 5625 / 10000, (pix / 2) 300 | + (pix * 625 / 10000) - (pix * 3 / 100)); 301 | download_rectangle.lineTo(pix * 5625 / 10000, (pix * 375 / 1000) 302 | + (pix * 625 / 10000) - (pix * 3 / 100)); 303 | download_rectangle.lineTo(pix * 4375 / 10000, (pix * 375 / 1000) 304 | + (pix * 625 / 10000) - (pix * 3 / 100)); 305 | download_rectangle.close(); 306 | 307 | tick = new Path(); 308 | tick.moveTo(pix * 30 / 100, pix * 50 / 100); 309 | tick.lineTo(pix * 45 / 100, pix * 625 / 1000); 310 | tick.lineTo(pix * 65 / 100, pix * 350 / 1000); 311 | 312 | } 313 | 314 | public void init() { 315 | 316 | // Defining and drawing bitmaps and assigning views to the layout 317 | 318 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( 319 | FrameLayout.LayoutParams.WRAP_CONTENT, 320 | FrameLayout.LayoutParams.WRAP_CONTENT); 321 | 322 | lp.setMargins(10, 10, 10, 10); 323 | 324 | fillcircle.setVisibility(View.GONE); 325 | 326 | Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types 327 | Bitmap full_circle_bmp = Bitmap.createBitmap(pix, pix, conf); 328 | Bitmap arc_bmp = Bitmap.createBitmap(pix, pix, conf); 329 | Bitmap fill_circle_bmp = Bitmap.createBitmap(pix, pix, conf); 330 | 331 | first_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw 332 | // first icon( 333 | // Default - 334 | // Play ) 335 | 336 | second_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw 337 | // second icon( 338 | // Default - 339 | // Stop ) 340 | 341 | third_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw 342 | // third icon( 343 | // Default - 344 | // Tick ) 345 | 346 | Canvas first_icon_canvas = new Canvas(first_icon_bmp); 347 | Canvas second_icon_canvas = new Canvas(second_icon_bmp); 348 | Canvas third_icon_canvas = new Canvas(third_icon_bmp); 349 | Canvas fill_circle_canvas = new Canvas(fill_circle_bmp); 350 | Canvas full_circle_canvas = new Canvas(full_circle_bmp); 351 | Canvas arc_canvas = new Canvas(arc_bmp); 352 | 353 | float startx = (float) (pix * 0.05); 354 | float endx = (float) (pix * 0.95); 355 | System.out.println("full circle " + full_circle_canvas.getWidth() 356 | + full_circle_canvas.getHeight()); 357 | float starty = (float) (pix * 0.05); 358 | float endy = (float) (pix * 0.95); 359 | rect = new RectF(startx, starty, endx, endy); 360 | 361 | first_icon_canvas.drawPath(play, fill_color); // Draw second icon on canvas( Default - Stop ). 362 | // *****Set your second icon here**** 363 | 364 | 365 | second_icon_canvas.drawPath(stop, icon_color); // Draw second icon on canvas( Default - Stop ). 366 | // *****Set your second icon here**** 367 | 368 | third_icon_canvas.drawPath(tick, final_icon_color); // Draw second icon on canvas( Default - Stop ). 369 | // *****Set your second icon here**** 370 | 371 | 372 | full_circle_canvas.drawArc(rect, 0, 360, false, stroke_color); 373 | fill_circle_canvas.drawArc(rect, 0, 360, false, fill_color); 374 | arc_canvas.drawArc(rect, -80, 340, false, stroke_color); 375 | 376 | buttonimage.setImageBitmap(first_icon_bmp); 377 | flg_frmwrk_mode = 1; 378 | fillcircle.setImageBitmap(fill_circle_bmp); 379 | full_circle_image.setImageBitmap(full_circle_bmp); 380 | arc_image.setImageBitmap(arc_bmp); 381 | 382 | cusview.setVisibility(View.GONE); 383 | 384 | addView(full_circle_image, lp); 385 | addView(arc_image, lp); 386 | addView(fillcircle, lp); 387 | addView(buttonimage, lp); 388 | addView(cusview, lp); 389 | 390 | } 391 | 392 | public void animation() { 393 | 394 | // Starting view animation and setting flag values 395 | 396 | if (first_click == false) { 397 | if (flg_frmwrk_mode == 1) { 398 | first_click = true; 399 | full_circle_image.setVisibility(View.GONE); 400 | arc_image.setVisibility(View.VISIBLE); 401 | arc_image.startAnimation(arcRotation); 402 | } 403 | } 404 | 405 | } 406 | 407 | public void finalAnimation() { 408 | 409 | // Responsible for final fill up animation 410 | 411 | buttonimage.setVisibility(View.GONE); 412 | fillcircle.setVisibility(View.VISIBLE); 413 | fillcircle.startAnimation(new_scale_in); 414 | 415 | } 416 | 417 | public void reset() { 418 | 419 | // Responsible for resetting the state of view when Stop is clicked 420 | 421 | cusview.reset(); 422 | cusview.setVisibility(View.GONE); 423 | buttonimage.setImageBitmap(first_icon_bmp); 424 | flg_frmwrk_mode = 1; 425 | 426 | } 427 | 428 | @Override 429 | public void onClick(View v) { 430 | // TODO Auto-generated method stub 431 | 432 | animation(); 433 | System.out.println("Action onclick..."); 434 | } 435 | 436 | } 437 | --------------------------------------------------------------------------------