Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
463
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 1  ProgressBar java.lang.Object ↳android.view.View ↳android.widget.ProgressBar Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar. A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation without an indication of progress. This mode is used by applications when the length of the task is unknown. The indeterminate progress bar can be either a spinning wheel or a horizontal bar. The following code example shows how a progress bar can be used from a worker thread to update the user interface to notify the user of progress: public class MyActivity extends Activity { private static final int PROGRESS = 0x1; private ProgressBar mProgress; private int mProgressStatus = 0; private Handler mHandler = new Handler(); protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.progressbar_activity); mProgress = (ProgressBar) findViewById(R.id.progress_bar); // Start lengthy operation in a background thread new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } }
  • 2. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 2 }).start(); } } To add a progress bar to a layout file, you can use the <ProgressBar> element. By default, the progress bar is a spinning wheel (an indeterminate indicator). To change to a horizontal progress bar, apply the Widget.ProgressBar.Horizontal style, like so: <ProgressBar style="@android:style/Widget.ProgressBar.Horizontal" ... /> If you will use the progress bar to show real progress, you must use the horizontal bar. You can then increment the progress with incrementProgressBy() or setProgress(). By default, the progress bar is full when it reaches 100. If necessary, you can adjust the maximum value (the value for a full bar) using the android:max attribute. Other attributes available are listed in table. Another common style to apply to the progress bar is Widget.ProgressBar.Small, which shows a smaller version of the spinning wheel—useful when waiting for content to load. For example, you can insert this kind of progress bar into your default layout for a view that will be populated by some content fetched from the Internet—the spinning wheel appears immediately and when your application receives the content, it replaces the progress bar with the loaded content. For example: <LinearLayout android:orientation="horizontal" ... > <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.ProgressBar.Small" android:layout_marginRight="5dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/loading" /> </LinearLayout>
  • 3. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 3 Other progress bar styles provided by the system include:  Widget.ProgressBar.Horizontal  Widget.ProgressBar.Small  Widget.ProgressBar.Large  Widget.ProgressBar.Inverse  Widget.ProgressBar.Small.Inverse  Widget.ProgressBar.Large.Inverse Attributes that can be used with a ProgressBar Attribute Description android:max Defines the maximum value the progress can take. android:maxHeight An optional argument to supply a maximum height for this view. android:maxWidth An optional argument to supply a maximum width for this view. android:minHeight Define height android:minWidth Define width android:progress Defines the default progress value, between 0 and max. android:indeterminate Allows to enable the indeterminate mode. Setting Progress in coding mProgress = (ProgressBar) findViewById(R.id.progress_bar); mProgress.setProgress(10); Setting Progress in application title bar requestWindowFeature(Window.FEATURE_INDETERMINANTE_PROGRESS); //to show small circular indicator in title bar requestWindowFeature(Window.FEATURE_PROGRESS); //to show small horizontal progress bar behind title bar setContentView(R.layout.indicators); setProgressBarIndeterminanteVisibility(true); setProgressBarVisiblity(true); setProgress(2000); // Default is 10,000
  • 4. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 4  SeekBar java.lang.Object ↳ android.view.View ↳ android.widget.ProgressBar ↳ android.widget.AbsSeekBar ↳ android.widget.SeekBar A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged. Clients of the SeekBar can attach a SeekBar.OnSeekBarChangeListener to be notified of the user's actions. Public Constructors SeekBar(Context context) SeekBar(Context context, AttributeSet attrs) SeekBar(Context context, AttributeSet attrs, int defStyle) Public Methods void setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener L) Sets a listener to receive notifications of changes to the SeekBar's progress level. abstract void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) Notification that the progress level has changed. abstract void onStartTrackingTouch(SeekBar seekBar) Notification that the user has started a touch gesture. abstract void onStopTrackingTouch(SeekBar seekBar) Notification that the user has finished a touch gesture. Explanation public abstract void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser)
  • 5. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 5 Notification that the progress level has changed. Clients can use the fromUser parameter to distinguish user-initiated changes from those that occurred programmatically. Parameters seekBar The SeekBar whose progress has changed progress The current progress level. This will be in the range 0..max where max was set by setMax(int). (The default value for max is 100.) fromUser True if the progress change was initiated by the user. Demo Code Example  Chronometer java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.Chronometer You can give it a start time in the elapsedRealtime() timebase, and it counts up from that, or if you don't give it a base time, it will use the time at which you call start(). By default it will display the current timer value in the form "MM:SS" or "H:MM:SS", or you can use setFormat(String) to format the timer value into an arbitrary string. Nested Classes interface Chronometer.OnChronometerTickListener A callback that notifies when the chronometer has incremented on its own. Public Constructors Chronometer(Context context) Initialize this Chronometer object. Chronometer(Context context, AttributeSet attrs) Initialize with standard view layout information. Chronometer(Context context, AttributeSet attrs, int defStyle) Initialize with standard view layout information and style. Public Methods long getBase() Return the base time as set through setBase(long). String getFormat() Returns the current format string as set through setFormat(String).
  • 6. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 6 Chronometer.OnChronometerTi ckListener getOnChronometerTickListener() void setBase(long base) Set the time that the count-up timer is in reference to. void setFormat(String format) Sets the format string used for display. void setOnChronometerTickListener(Chronometer.OnChrono meterTickListener listener) Sets the listener to be called when the chronometer changes. void start() Start counting up. void stop() Stop counting up. Demo Code Example
  • 7. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 7  RatingBar java.lang.Object ↳ android.view.View ↳ android.widget.ProgressBar ↳ android.widget.AbsSeekBar ↳ android.widget.RatingBar A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar. The smaller RatingBar style ( ratingBarStyleSmall) and the larger indicator-only style (ratingBarStyleIndicator) do not support user interaction and should only be used as indicators. When using a RatingBar that supports user interaction, placing widgets to the left or right of the RatingBar is discouraged. The number of stars set (via setNumStars(int) or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable). The secondary progress should not be modified by the client as it is used internally as the background for a fractionally filled star. Public Constructors RatingBar(Context context, AttributeSet attrs, int defStyle) RatingBar(Context context, AttributeSet attrs) RatingBar(Context context) Public Methods int getNumStars() Returns the number of stars shown. RatingBar.OnRatingBarChangeL istener getOnRatingBarChangeListener() float getRating() Gets the current rating (number of stars filled).
  • 8. Mobile Computing - MCA 650003 Mr. Pritesh N. Patel Page 8 float getStepSize() Gets the step size of this rating bar. boolean isIndicator() void setIsIndicator(boolean isIndicator) Whether this rating bar should only be an indicator (thus non-changeable by the user). synchronized void setMax(int max) Set the range of the progress bar to 0... void setNumStars(int numStars) Sets the number of stars to show. void setOnRatingBarChangeListener(RatingBar.OnRatingBar ChangeListener listener) Sets the listener to be called when the rating changes. void setRating(float rating) Sets the rating (the number of stars filled). void setStepSize(float stepSize) Sets the step size (granularity) of this rating bar. Demo Code Example  Display Time (DigitalClock/AnalogClock) Digital Clock Analog Clock java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.DigitalClock java.lang.Object ↳ android.view.View ↳ android.widget.AnalogClock Display current time in standard time format or user setting.