How to make a filled circular progress bar? (without using external libraries) - android

I want to make a circular filled progress bar in Android Studio.
My goal is to achieve something like this;
The first image would have the progress value of for example, 100, then every second a bit of the circle will disappear until its nothing left.
I tried this but I couldn't get my repositories to work, therefore I'm looking for a more "non external" way to do it.

With the Material Components library you can use the official CircularProgressIndicator.
Something like:
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:trackThickness="20dp"
/>
If you are using jetpack Compose you can use CircularProgressIndicator:
CircularProgressIndicator(
strokeWidth = 20.dp,
progress = animatedProgress.value)

Related

Show Circular progress bar on android (filled circle)

How to show a filled circular progress bar on android?
The progress bar should be filled like a circle not like a ring and it should have customizable features like animation timings animation interpolators etc.
This project helps display a simple filled circular progress bar on android 5 (lolipop) and above.
It is extremely customizable all the custom attributes are shown in the code sample below.
This is an open source project, feel free to look into code or clone it and modify it per your requirements.
Follow the GitHub instructions to get started
<com.jeet.circularprogressbar.CircularProgressBar
android:id="#+id/customRoundProgressBar"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:maxProgressLimit="60"
app:progress="50"
app:maxAnimationDuration="2500"
app:animationInterpolator="AccelerateDecelerateInterpolator"
app:showProgressText="true"
app:progressTextSize="16sp"
app:progressTextColor="#color/black"
app:progressBarColor="#android:color/holo_red_dark" />
Max progress limit by default is 100 and min progress limit by default is 0, none of the parameters are required other than width and height.
You can play with different interpolators to animate the progress values, **default is acceleratedecelateinterpolator**
The maximum Animation Duration can also be changed.
All the properties shown in xml can be changed from code as well
For example:
setProgress(progressValue)
can be called from code to set the current progress of the progress bar.
Result

Android Progress Circle With Multiple Colors

I'm trying to draw a indeterminate (circular) progress bar that is white and then fades into purple.
This is my ProgressBar:
<ProgressBar
android:id="#+id/mainProgressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="#dimen/progressbar_size"
android:layout_height="#dimen/progressbar_size"
android:layout_gravity="center" />
Then I paint it white:
mainProgressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
Do I need add another ColorFilter? Set a style or theme on the progressbar? No idea what to do here.
DonutProgressView is a configurable doughnut-like graph view capable of displaying multiple datasets with assignable colors. It supports animations and features a gap at the top, which makes it look like a gauge (or tasty bitten-off donut - that's why the name).
Click Here to See Git Lib

Change spinning wheel style from ProgressBar Android

I have a ProgressBar with the attribute
style="?android:attr/progressBarStyleLarge"
which shows the next spinning wheel:
But to keep the same style in all my application, I wanted to use, in my ProgressBar, the spinning wheel shown on SwipeRefreshLayout by default:
How can I achieve this? Thanks!
[ADDED]
I'm looking for the spinning style, its movement and how is it shown. It works something like this:
while turning around, the black "bar" gets longer and then shorter and then again longer and so on,.. changes its size always in the same direction that the bar moves (really difficult to explain how it works, that's why I refered to SwipeRefreshLayout's spinning wheel)
Try using this persons progress bar
https://android-arsenal.com/details/1/1141
you will need to call .Spin() in your code to start it.
Add This to you gradle build file as followed
repositories {
maven { url "https://jitpack.io" }
compile 'com.pnikosis:materialish-progress:1.7'
}
If you just want to change the color / style, try this (Android Lollipop + ) :
progCircle.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.myXMLColor), PorterDuff.Mode.SRC_IN);
More information about PorterDuff here
I think this is what you are looking for
style="#style/Base.Widget.AppCompat.ProgressBar"

How do I create the semi-transparent grey tutorial overlay in Android?

You know when you run an Android device for the first time (something you see a lot if you use the emulator) that there's a helpful little tutorial about how to use the launcher and add widgets, etc. I'm trying to find an example of this on Google, but I can't. I'm hoping you know what I mean. It's the one with the blue "okay" buttons at each step.
Anyway, I want to create one for my app, but I'm not sure which is the best way to go about doing it.
Do I create a Fragment that I can make semi-transparent on top of my regular activity and have it show up on only the first run?
Do I make a semi-transparent .png for each section of the tutorial and overlay it over the regular launcher activity on the first run?
If I do the latter, how can I adjust for all the various screen sizes? I could just render the image in Photoshop to various dimensions, but that won't cover all of them. If I go the fragment route, I can just say "match_parent" and not worry about it. But then I have to figure out how Fragments work, and they confuse the hell out of me.
I think this open-source library is exactly what you're looking for:
Showcase View
You can grab the source code and setup instructions from GitHub.
Use a hexadecimal color code, which consists of two digits for alpha and six for the color itself, like this:
android:background="#22FFFFFF"
It'll make it semi-transparent.
android:background="#c0000000" for more darkness
Edited
Generally hexadecimak color code structure is like '#FFFF'
For attaining transparency add two digits after '#' to any color code.
Eg : #110000, #220000, #330000.
The greater those two digits, the lesser transparency.
You can try something like this
<LinearLayout ... >
<!-- your Normal layout goes here -->
<RelativeLayout android:id="#+id/tutorialView" android:background="#D0000000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:src="#drawable/hint_menu" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
And in your onCreate method
View tutorialView = findViewById(R.id.tutorialView);
boolean tutorialShown = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getBoolean(Constants.PREF_KEY_TUT_MAIN, false);
if (!tutorialShown) {
tutorialView.setVisibility(View.VISIBLE);
} else {
tutorialView.setVisibility(View.GONE);
}
tutorialView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.setVisibility(View.GONE);
PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit().putBoolean(Constants.PREF_KEY_TUT_MAIN, true).commit();
}
});
There is an award-winning library for this called "FancyShowcaseView":
https://github.com/faruktoptas/FancyShowCaseView
Add to your project like this:
In the top-level build.gradle (not the module level):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
In the module-level (app) build.gradle
dependencies {
compile 'com.github.faruktoptas:FancyShowCaseView:1.0.0'
}
Then you can call:
new FancyShowCaseView.Builder(this)
.focusOn(view)
.title("Focus on View")
.build()
.show();
You don't need to use Photoshop. You can Use for example a LinearLayout with android:background="#50134BE8". This will make it transparent blue. You can place the layout on top of everything and hide it when the user is done. You can use any background color, but to make it transparent, place a number from 01 to FE, after the "#" symbol to change its transparency. Set the width and the height to fill_parent to occupy the whole area. Place this view directly in the main layout. Hope this helps.

How to use setprogressbar() on a progressbar with style Widget.ProgressBar.Large

I want to show progress in a widget via a wheel-progressbar (not the horizontal one).
This is the progressbar in the xml layoutfile, that shows the content to the user:
<ProgressBar
android:id="#+id/progressBar1"
style="#android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateOnly="false"/>
In the appwidget_provider implementation I wanted to set the progressbar like this:
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.sample_widget);
views.setProgressBar(R.id.progressBar1, 2, 1, false);
appWidgetManager.updateAppWidget(appWidgetId, views);
(sample_widget being the layout shown to the user)
Now, if progressBar1 is a horizontal progressBar, everything is displayed as you would expect.
But if I use any other style, like here, the progressbar is not displayed as soon as setProgressBar() sets indeterminate to false.
I presume that is because the wheel-progressbars are apparently designed to show only indeterminate behaviour, so the drawable for determinate behaviour does not exist, which
leads to the progressbar not being displayed.("If you will use the progress bar to show real progress, you must use the horizontal bar.", according to the documentation here)
My question is now how I would go about making a wheel-progressbar that is capable of
showing actual progress ? Furthermore I wanted to be able to customize the progressbar based
on user preferences or how much progress has currently been made ( maybe dynamically change the colour of the bar, make it brighter/darker, bolder/thinner, etc.).
I would really appreciate it if someone could point me in the right direction, because I assume I am pretty much overthinking it now.I believe there must be a simple way of doing it, I just did not find anything on the matter.

Categories

Resources