Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA Tutorial
  • Data Structures
  • Algorithms
  • Array
  • Strings
  • Linked List
  • Stack
  • Queue
  • Tree
  • Graph
  • Searching
  • Sorting
  • Recursion
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Heap
  • Hashing
  • Divide & Conquer
  • Mathematical
  • Geometric
  • Bitwise
  • Greedy
  • Backtracking
  • Branch and Bound
  • Matrix
  • Pattern Searching
  • Randomized
Open In App
Next Article:
ProtractorView in Android
Next article icon

ProtractorView in Android

Last Updated : 23 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, ProtractorView is added to android. ProtractorView is a semicircular Seekbar view for selecting an angle from 0° to 180. Seek bar is a type of progress bar. Change the cursor from 0° to 180 for selecting an angle. Below is the image of ProtractorView.

ProtractorView in Android

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.

Step 2: Add the Required Dependencies

Navigate to the Gradle Scripts > build.gradle(Module:app) and Add the Below Dependency in the Dependencies section.

implementation 'com.github.GoodieBag:ProtractorView:v1.2'

Add the Support Library in your settings.gradle File. This library Jitpack is a novel package repository. It is made for JVM so that any library which is present in Github and Bitbucket can be directly used in the application.

dependencyResolutionManagement {     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)     repositories {         google()         mavenCentral()                  // add the following         maven { url "https://jitpack.io" }     } }

After adding this Dependency, Sync the Project and now we will move towards its implementation.

Step 3: Working with the XML Files

Next, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

XML
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">      <com.goodiebag.protractorview.ProtractorView         android:id="@+id/protractorview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toTopOf="parent"         app:textProgressColor="#FF00"         app:tickProgressColor="#abe6" />      <TextView         android:id="@+id/textView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginBottom="136dp"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="0.498"         app:layout_constraintStart_toStartOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 

Step 4: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail. In this file, add interval, color, and setOnProtractorViewChangeListener to our ProtractorView. Whenever progress is changed setOnProtractorViewChangeListener is get invoked automatically. Here the changed angle value is shown in TextView. 

Java
import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import com.goodiebag.protractorview.ProtractorView;  public class MainActivity extends AppCompatActivity {      TextView textView;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          ProtractorView protractorView = (ProtractorView) findViewById(R.id.protractorview);                    textView = findViewById(R.id.textView);         protractorView.setTickIntervals(15);                protractorView.setArcColor(getColor(R.color.colorAccent));         protractorView.setProgressColor(getColor(R.color.myColor));                protractorView.setOnProtractorViewChangeListener(new ProtractorView.OnProtractorViewChangeListener() {             @Override             public void onProgressChanged(ProtractorView pv, int progress, boolean b) {                 textView.setText("" + progress);             }              @Override             public void onStartTrackingTouch(ProtractorView pv) {              }              @Override             public void onStopTrackingTouch(ProtractorView pv) {              }         });     } } 
Kotlin
import android.os.Build import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.goodiebag.protractorview.ProtractorView  class MainActivity : AppCompatActivity() {          private lateinit var textView: TextView      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)                  val protractorView = findViewById<ProtractorView>(R.id.protractorview)                  textView = findViewById(R.id.textView)         protractorView.setTickIntervals(15)          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {             protractorView.setArcColor(getColor(R.color.colorAccent))             protractorView.setProgressColor(getColor(R.color.myColor))         }                  protractorView.setOnProtractorViewChangeListener(object : OnProtractorViewChangeListener() {             fun onProgressChanged(pv: ProtractorView?, progress: Int, b: Boolean) {                 textView.text = "" + progress             }                          fun onStartTrackingTouch(pv: ProtractorView?) {                              }                          fun onStopTrackingTouch(pv: ProtractorView?) {                              }         })     } } 

Output:


Next Article
ProtractorView in Android

M

madhavmaheshwarimm20
Improve
Article Tags :
  • Java
  • Kotlin
  • Android
  • DSA
  • Android-View
Practice Tags :
  • Java

Similar Reads

    PopView in Android
    In this article, PopView is added to android. When users tap on the view a pop animation with a circular dust effect will appear. A new view can also appear after the popping of the older view. PopView can be used to hide the view or change the view. It makes the user interface more attractive. Supp
    3 min read
    Android RecyclerView in Kotlin
    In this article, you will know how to implement RecyclerView in Android using Kotlin . Before moving further let us know about RecyclerView. A RecyclerView is an advanced version of ListView with improved performance. When you have a long list of items to show you can use RecyclerView. It has the ab
    4 min read
    Android ListView in Kotlin
    ListView in Android is a ViewGroup which is used to display a scrollable list of items arranged in multiple rows. It is attached to an adapter which dynamically inserts the items into the list. The main purpose of the adapter is to retrieve data from an array or a database and efficiently push every
    3 min read
    Android View Hierarchy
    A block of the screen which is responsible for the UI of the application is called a View. An android app UI consists of views and ViewGroups. View refers to android.view.View class of android, with the help of this class all the other GUI elements are drawn. It is responsible for drawing and event
    3 min read
    Spotlight in Android
    Android applications have so many options present within them, so users can interact with the features within the application. Many application provides a spotlight on some of the important features within the application to grab user attention. In this article, we will take a look at How to add Spo
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences