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.
Related
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
I was wondering if anyone can provide hint or source to achieve following slider widget used in "Circle – Who's Around?" This is the first time I have ever came across this and I am not sure what to exactly name this widget.:
I was thinking of using custom seekbar background to do this but, I am not sure how do I figure out exact pixels that the seekbar will reach of next step. Since, that will be independent to devices. In my case I am planning to use images, rather than the indicators.
Please don't point to this link http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ because this is not what I want to achieve. They seem to have used static image footer to show D,W,K. I have tried that app and it doesn't even step to the exact dots or D,W,K. I have looked at AT&T Android Slider Controls but, they don't seem to provide any source for it. I have found some iOS devs achieving that but, I don't really understand obj C code in order to achieve that in Android.
This is just a seekbar with a custom thumb and background. You could use a 9patch for the background so it fills nicely and just set them in your styles
Following #Milanix answer using the library at https://github.com/karabaralex/android-comboseekbar here it is a minimum example code that worked for me:
<com.infteh.comboseekbar.ComboSeekBar
android:id="#+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
custom:color="#000"
custom:textSize="12sp"
custom:multiline="false"
/>
Then in the Activity
private ComboSeekBar mSeekBar;
List<String> seekBarStep = Arrays.asList("All","1","5","10","20");
mDistanceSeekBar.setAdapter(seekBarStep);
This will create a black segmented seekbar using default drawables. If you need to add some customization have a look at ComboSeekBar.onDraw(), CustomDrawable.draw() and CustomThumbDrawable.draw().
This project is all but finished but still a solid starting point.
#Giulio thank you for your post, I have the same problem as Ron Eskinder.
I heve fixed it by removing :"custom:color" , "custom:textsize" and "custom:multiline" in xml file. then in Java I put this:
mSeekBar = (ComboSeekBar) findViewById(R.id.seekbar);
List<String> seekBarStep = Arrays.asList("All","1","5","10","20");
mSeekBar.setAdapter(seekBarStep);
Hope this will help
I need to create a simple progress bar using two drawable images.
One is the background of course.
The other I need to scale according to a percentage float.
Is it possible using Java code only? I tried the setBounds() method with no avail... :(
thanks
You can perfectly and easily do that using only XML code.
First, in the layout of your activity specify the XML in where you declare the style of the progressbar, in this case #drawable/custom_progressbar:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="#drawable/custom_progressbar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/progress_bar_background" >
</ProgressBar>
Then, in #drawable/custom_progressbar declare that the progress will be expressed with a bitmap that clips according to the progress. The id is important as it is used by Android's ProgressBar widget.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<clip>
<bitmap android:src="#drawable/progress_bar_foreground" />
</clip>
</item>
</layer-list>
Then, in the declaration of the progress bat in the layout specify the background of the progressbar.
The background should be specified in theory in the progressbar layer list with the id android:id="#android:id/background, but it didn't work for me in this case. I think Android designers thought of that to be used as a stretchable 9patch or a tiled bitmap. I wanted to do the same as you and I only got it by declaring the background as usually in the view in the layout.
Hope that helps.
As I am sure you are aware, custom elements in Android take a significant amount of effort compared to the pre-compiled api's. If I were to do something like this, I'd create a custom class that extends View, and scale my progress image bitmap or canvas inside onDraw() method. And call PostInvalidate() for each time I need to update it. However, generally custom progress bars are done a bit differently in Android. Instead of scaling the progress drawable it simply reveals a portion of it depending on the percentage.
To get an idea on how to do a custom progressbar take a look at this.
I am trying to create a custom title bar strictly for Android 2.1 that somewhat emulates the ActionBar found in Android 3.0 and up.
So far I've had fairly decent luck, but I cannot find an easy way to make the drop-down lists that can appear below the icon / buttons in the ActionBar.
I would like these drop-down lists to be able to cross the boundary between the title layout and the content layout without being clipped / cut off. I would also like the drop-down lists to be positioned relatively below the icons / buttons in the ActionBar. I've seen advice to use FrameLayouts and RelativeLayouts already but these did not seem to solve my particular problem (unless I'm looking at it wrong). I keep thinking it must be possible since I believe the newer versions of Android have support for exactly this type of behavior.
Here is a screenshot of what I am trying to accomplish with some notes.
http://img217.imageshack.us/img217/3279/67343249.png
Please help. Thanks!!!
I think best way to do that is to create a linear layout and add your drop-down list item into that linear layout. Then add linear layout on button click and display it just below to the button by using relative layout layoutparams.
You need to hold your content with a FrameLayout. A FrameLayout can hold more than one child, and it will allow them to overlap on each other.
A possible layout xml could look like:
<FrameLayout>
<LinearLayout android:margin_top="30dip">...</LinearLayout>
<CustomActionBar />
</FrameLayout>
The 30dip is just the height of your ActionBar, you might want to define it in values. And the LienarLayout you can replace with anything which is just for holding the other content in your application.
PS. I am not sure if FrameLayout renders first child first or last. In case you found the linearlayout stuff overlaps the customactionbar, swap their position.
=== Edit ===
To make the code much cleaner, one can do in this way:
<CustomActionBar>
<LinearLayout/>
</CustomActionBar>
Which replaced the custom action bar to be the "root" element of any xml layout that utilized the action bar. When doing the custom action bar, you need to extend it from FrameLayout, and assign the child's margin accordingly. Which the idea is much the same as the one I presented above.
After a few days of research I found the best way to implement this is to use a custom dialog box with a custom theme that contains a listView. When the user clicks on the button the dialog should be displayed directly below the button. This provides a good user experience and also means you don't have to completely change your basic layout structure to accomodate this functionality. (This is basically the same approach that ActionBar Sherlocke uses for their backwards compatibility menus)
Here is a code snippet of what I'm describing (this is written in C# using Mono for Android but it should be easy to translate to Java):
Dialog dlgHome = new Dialog(this, Resource.Style.ActionBarMenu);
dlgHome.SetCanceledOnTouchOutside(true);
dlgHome.SetContentView(Resource.Layout.ActionBarMenu);
ListView lsvHome = (ListView)dlgHome.FindViewById(Resource.Id.lsvHome);
lsvHome.Adapter = new ArrayAdapter<string>(this, Resource.Layout.ActionBarMenuItem, new string[] { "Add Activity", "Edit Log", "Program Details" });
Rect r = new Rect();
btnHome.GetLocalVisibleRect(r);
int x = r.Left + (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics);
int y = r.Bottom;
WindowManagerLayoutParams param = dlgHome.Window.Attributes;
param.Gravity = (int)(GravityFlags.Top | GravityFlags.Left);
param.X = x;
param.Y = y;
dlgHome.Window.Attributes = param;
Also, here is the style xml (goes in style.xml)
<style name="ActionBarMenu" parent="android:Theme.Dialog">
<item name="android:windowBackground">#color/actionbar_menu_bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
I'm using undetermined ProgressDialog with text 'Loading...' and other similar texts.
I decided to remove texts and leave plain progres indicator.
Unexpectedly sizde of indicator remain big enought to contain text inside.
How to remove it?
Update:
m_progressBar = new ProgressDialog(LoginForm.this);
m_progressBar.setIndeterminate(true);
m_progressBar.setCancelable(true);
m_progressBar.setProgressStyle(android.R.attr.progressBarStyleSmall);
Try editing your xml
<ProgressBar
style="?android:attr/progressBarStyleSmall"
You have to use custom ProgressBar google it there are a lot of example of creating custom ProgressBar. you cant do with android own ProgressBar
Unfortunately only custom progress solves this.
There are a lot of samples here in stackoverflow.com