Android: Countdown with circular progessbar is NOT CLOCKWISE - android

I created a cotuntdown with a start and stop button. The textview should be centered in the middle of the screen and around this textview is a circular progressbar displayed.
My Problem is, that the progress of the progressbar is anti clockwise and starts not at the top (12 o clock position of a watch) and that the background is not displayed.
The design of the progressbar should be a light grey background and a darkgrey progress.
Here is my main_activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="letscho.timer.MainActivity">
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="300dip"
android:layout_height="300dip"
android:indeterminate="false"
android:progressDrawable="#drawable/circularprogressbar"
android:background="#drawable/circularprogressbar_background"
style="?android:attr/progressBarStyleHorizontal"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:max="60"
android:progress="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textViewTime"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="80sp"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnStart"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:textAlignment="center"
android:text="Start"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnStop"
android:layout_below="#+id/textViewTime"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="12dp"
android:text="Stop"
/>
</LinearLayout>
</RelativeLayout>
And my progressbar drawables:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="19.0"
android:useLevel="true"
>
<gradient
android:startColor="#444444"
android:endColor="#444444"
android:type="sweep" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="19.0"
android:useLevel="true"
>
<gradient
android:startColor="#bbbbbb"
android:endColor="#bbbbbb"
android:centerColor="#bbbbbb"
android:type="sweep" />
</shape>
</item>
</layer-list>
And the java main:
package letscho.timer;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.concurrent.TimeUnit;
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#SuppressLint("NewApi")
public class MainActivity extends AppCompatActivity {
int i=-1;
Button btnStart, btnStop;
TextView textViewTime;
ProgressBar mProgressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStart = (Button) findViewById(R.id.btnStart);
btnStop = (Button) findViewById(R.id.btnStop);
textViewTime = (TextView) findViewById(R.id.textViewTime);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
textViewTime.setText("60");
final CounterClass timer = new CounterClass(60000, 1000);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
timer.start();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
timer.cancel();
}
});
}
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#SuppressLint("NewApi")
public class CounterClass extends CountDownTimer {
/**
* #param millisInFuture The number of millis in the future from the call
* to {#link #start()} until the countdown is done and {#link #onFinish()}
* is called.
* #param countDownInterval The interval along the way to receive
* {#link #onTick(long)} callbacks.
*/
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
#SuppressLint("NewApi")
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#Override
public void onTick(long millisUntilFinished) {
long millis = millisUntilFinished;
String s = String.format("%02d", TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
System.out.println(s);
textViewTime.setText(s);
mProgressBar.setProgress((int)(millisUntilFinished / 1000));
}
#Override
public void onFinish() {
textViewTime.setText("00");
}
}
}
Thx for your help!

Related

How to create Diamond Progress Bar Android

My Client wants a diamond shaped progress that looks like this:
My first attempt was to use a library, but I can't find one that exists
My next attempt was to learn how to use the ProgressBar view that comes with android, and set my own drawable using this answer (the closest thing to an answer on stack overflow), but the answer only works on ring shapes, not rectangles.
What is the best way to create a diamond-shaped progress view? (By any means: custom view, progressDrawable) and how do I do that?
After some more tests, I came up with a hacky answer. It's just 4 progress bars aligned to the edge of a Relative layout, and a CardView on top of them. Rotate the whole thing, and wrap it in a class and bam, you got yourself a diamond progress bar. (Use math to calculate the progress of each bar)
It can be a little weird on the corners (where the progress bars overlap) but overall it works well enough
Usage:
ViewGroup background;
int count = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Something to add the progress bar to
background = (ViewGroup) findViewById(R.id.relative);
//initializing the progress bar
final DiamondProgress diamondProgress = new DiamondProgress(this);
diamondProgress.setMax(1000);
//adding the progress bar
background.addView(diamondProgress.getView());
/* Sample Code for animating the progress bar*/
new Timer().scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
diamondProgress.setProgress(count++);
}
});
}
}, 0, 25);
}
Code:
XML: layout/diamond_view
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:rotation="45"
android:padding="43dp"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp">
<RelativeLayout
android:layout_width="wrap_content"
android:rotation="90"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="8dp"
android:layout_alignParentBottom="true"
android:rotation="180">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_marginLeft="3dp"
android:id="#+id/dp_progress4"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="#drawable/progress_drawable"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="8dp"
android:layout_alignParentBottom="true"
android:rotation="180">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_marginLeft="3dp"
android:progress="50"
android:id="#+id/dp_progress3"
android:progressDrawable="#drawable/progress_drawable"
style="?android:attr/progressBarStyleHorizontal"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:rotation="90"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_marginLeft="3dp"
android:progress="100"
android:id="#+id/dp_progress2"
android:progressDrawable="#drawable/progress_drawable"
style="?android:attr/progressBarStyleHorizontal" />
</RelativeLayout>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_marginLeft="3dp"
android:progress="100"
android:progressDrawable="#drawable/progress_drawable"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/dp_progress1"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_margin="4dp"
android:id="#+id/dp_card"
android:elevation="10dp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:rotation="-45"
android:id="#+id/dp_addView"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Sample Inside Content"
android:id="#+id/dp_text"
android:gravity="center"
android:textSize="24sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</RelativeLayout>
XML: drawable/progress_drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- background -->
<item android:id="#android:id/background">
<shape>
<corners android:radius="3dp"/>
<solid android:color="#f2f2f2" />
</shape>
</item>
<!-- for the actual progress bar -->
<item android:id="#android:id/progress">
<clip android:gravity="left">
<shape>
<corners android:radius="3dp"/>
<solid android:color="#color/colorAccent" />
</shape>
</clip>
</item>
</layer-list>
Java Class
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
/**
* Created by Pythogen on 9/27/2017.
*/
public class DiamondProgress {
Context context;
View view;
RelativeLayout addView;
int progress = 0;
int max = 100;
ProgressBar p1;
ProgressBar p2;
ProgressBar p3;
ProgressBar p4;
public DiamondProgress(Context context) {
this.context = context;
view = LayoutInflater.from(context).inflate(R.layout.diamond_view, null);
addView = ((RelativeLayout) view.findViewById(R.id.dp_addView));
p1 = (ProgressBar) view.findViewById(R.id.dp_progress1);
p2 = (ProgressBar) view.findViewById(R.id.dp_progress2);
p3 = (ProgressBar) view.findViewById(R.id.dp_progress3);
p4 = (ProgressBar) view.findViewById(R.id.dp_progress4);
}
public View getView() {
return view;
}
public RelativeLayout getHostOfInsideContent() {
return addView;
}
public void setProgress(int progress) {
this.progress = progress;
updateProgressBar();
}
public void setMax(int max) {
this.max = max;
p1.setMax(max);
p2.setMax(max);
p3.setMax(max);
p4.setMax(max);
}
public void updateProgressBar() {
double prog = ((double)progress)/max;
if (prog<.25) {
p1.setProgress(this.progress*4);
p2.setProgress(0);
p3.setProgress(0);
p4.setProgress(0);
} else {
p1.setProgress(max);
if (prog<.5) {
p2.setProgress((this.progress*4)-max);
p3.setProgress(0);
p4.setProgress(0);
} else {
p2.setProgress(max);
if (prog<.75) {
p3.setProgress((this.progress*4)-max*2);
p4.setProgress(0);
} else {
p3.setProgress(max);
p4.setProgress((this.progress*4)-max*3);
}
}
}
}
}
Oh, and if you plan on using this, be sure to add the CardView dependancy to your build.grade compile 'com.android.support:cardview-v7:25.1.1'

How to move current time position from 0.00 sec when played

Here is the java file:
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class AudioPlayer extends AppCompatActivity {
ImageView mIvPlayControl;
TextView mTvTotalDuration;
TextView mTvCurrentPosition;
MediaPlayer mp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.music_player2);
mIvPlayControl= (ImageView) findViewById(R.id.iv_play);
mTvTotalDuration= (TextView) findViewById(R.id.tv_total);
mTvCurrentPosition= (TextView) findViewById(R.id.tv_progress);
mp = MediaPlayer.create(AudioPlayer.this, R.raw.sleep_away);
int mCurrentPosition=mp.getCurrentPosition();
int duration=mp.getDuration(); // miliseconds time
//convert into seconds
duration=duration/1000;
mCurrentPosition=mp.getCurrentPosition()/1000;
Log.e("value","value: "+duration);
mTvTotalDuration.setText(String.valueOf(duration));
mTvCurrentPosition.setText(String.valueOf(mCurrentPosition));
mIvPlayControl.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mp.isPlaying()) {
mp.pause();
mIvPlayControl.setImageResource(R.mipmap.play_small);
} else {
mp.start();
mIvPlayControl.setImageResource(R.mipmap.pause_small);
}
}
});
And here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:gravity="center"
>
<TextView
android:id="#+id/tv_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="0.00"
/>
<ImageView
android:id="#+id/iv_play"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#mipmap/play_small"
/>
<TextView
android:id="#+id/tv_total"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="0.00"
/>
</LinearLayout>
</LinearLayout>
How do i move the beginning time 0 and onwards when played? Do i have to add seek bar to get moving time? Can somebody please help here? The song can be played but timer doesn't work. And more details or questions are in the comments.
Suppose mTvCurrentPlayTime is TesxtView representing current play-time on the screen then you can use following code to update the view:
Handler mHandler = new Handler();
//Make sure you update TextView on UI thread
AudioPlayer.this.runOnUiThread(new Runnable() {
#Override
public void run() {
if(mp!= null){
int mCurrentPosition = mp.getCurrentPosition() / 1000;
mTvCurrentPosition.setText(String.valueOf(mCurrentPosition));
}
mHandler.postDelayed(this, 1000);
}
});

Change a ImageView by a time interval when a button is clicked

I'm trying to make a workout like App. I have a full screen ImageView and a ImageButton with a play icon. I want that when I click on the ImageButton the icon changes to a stop icon immediately, and the ImageView shows the image of the first exercise that will change after lets say 20secs to the image of the second exercise, but if a want to pause the counter I click again on the ImageButton to stop it.
My layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF5722"
android:orientation="vertical"
android:id="#+id/linearLayout">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Inicio"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="8dp"
android:layout_marginLeft="16dp"
android:id="#+id/Boton1"
android:onClick="sendMessage"
android:clickable="true"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:layout_below="#+id/linearLayout"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imagenRutina"
android:layout_marginBottom="45dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff5722"
android:orientation="horizontal"
android:id="#+id/linearLayout3">
</LinearLayout>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageButton"
android:layout_alignTop="#+id/linearLayout3"
android:layout_centerHorizontal="true"
android:background="#ff5722"
android:clickable="true"
android:layout_marginTop="5dp"
/>
</RelativeLayout>
</RelativeLayout>
And this is my java file
import android.content.Intent;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Rutina1Reproduccion extends AppCompatActivity {
ImageButton mPlayButton;
boolean isPlay = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rutina1_reproduccion);
mPlayButton = (ImageButton) findViewById(R.id.imageButton);
background="#drawable/default"
mPlayButton.setBackgroundResource(R.drawable.playicon);
mPlayButton.setOnClickListener(mTogglePlayButton);
}
View.OnClickListener mTogglePlayButton = new View.OnClickListener(){
final int[] imageArray = {R.drawable.imagengemelos, R.drawable.imagengluteos, R.drawable.imagenbrazos};
final ImageView imageView = (ImageView) findViewById(R.id.imagenRutina);
final Handler handler = new Handler();
#Override
public void onClick(View v) {
if (isPlay) {
v.setBackgroundResource(R.drawable.playicon);
Runnable runnable = new Runnable() {
int i = 0;
public void run() {
imageView.setImageResource(imageArray[i]);
i++;
if (i > imageArray.length - 1) {
i = 0;
}
handler.postDelayed(this, 3000); //for interval...
}
};
handler.postDelayed(runnable, 2000); //for initial delay..
}else{
v.setBackgroundResource(R.drawable.stopicon);
}
isPlay = !isPlay; // reverse
}
};
public void sendMessage(View view){
Intent intent=new Intent(Rutina1Reproduccion.this,Rutina1.class);
startActivity(intent);
}}
The error I'm getting its fatal exception whenIi open the activity.
If I also want to play some sound when the ImageButton is clicked, how can I do it?

android app crashes after several clicks on a button

could anyone help to solve the below problem:
I created a simple activity contains 2 buttons, every time i start clicking randomly on the buttons (even when slow clicking), the app crashes when the total clicks reach exactly 30 clicks.
Java:
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View button_1=(findViewById(R.id.button_1));
button_1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AudioManager am = (AudioManager) getSystemService(MainActivity.AUDIO_SERVICE);
int volume_level= am.getStreamVolume(AudioManager.STREAM_RING);
final ToneGenerator mToneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, volume_level * 14);
mToneGenerator.stopTone();
mToneGenerator.startTone(ToneGenerator.TONE_DTMF_1, 100);
}
});
final View button_2=(findViewById(R.id.button_2));
button_2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AudioManager am = (AudioManager) getSystemService(MainActivity.AUDIO_SERVICE);
int volume_level= am.getStreamVolume(AudioManager.STREAM_RING);
final ToneGenerator mToneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, volume_level * 14);
mToneGenerator.stopTone();
mToneGenerator.startTone(ToneGenerator.TONE_DTMF_9, 100);
}
});
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button_1"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button_2"
android:layout_below="#+id/button_1"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Why isn't my progress bar showing anything?

I have a custom progress bar and basically when I enter a value and then press a button, I would like to have that progress bar update. My progress bar is going to have only three values basically it can be 0 percent, 33 percent, 66 percent, or 100 percent. For some reason when I do go to the page with the progress bar and even enter the value into the TextView and then enter the button, it's just showing a loading circle for some reason that never ends. I've posted my all the code needed for the progress bar, so does anyone know why it's not showing the correct progress bar and why it's just showing that loading circle?
custom_progressBar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
progressBarShirts.java
package ankitkaushal.app.healthysizing;
import android.graphics.drawable.Drawable;
import android.sax.TextElementListener;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class progressBarShirts extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_bar_shirts);
final DatabaseHelper db = new DatabaseHelper(this);
final TextView currentSizeDisplay = (TextView) findViewById(R.id.currentSizeShirts);
Button enterNewSizeButton = (Button) findViewById(R.id.newSizeEnterButtonShirts);
final EditText newSize = (EditText) findViewById(R.id.newSizeShirts);
final String currentSize = db.getCurrentShirtSize();
currentSizeDisplay.setText("Your current size: " + currentSize);
Drawable draw = getResources().getDrawable(R.drawable.custom_progressbar);
enterNewSizeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String size = newSize.getText().toString().toUpperCase();
currentSizeDisplay.setText("Your current size: " + size);
db.updateSizeShirts(size);
}
});
ProgressBar shirts = (ProgressBar) findViewById(R.id.progressBarShirts);
shirts.setProgressDrawable(draw);
String startSize = db.getStartSizeShirts();
String newCurrentSize = db.getCurrentShirtSize();
String limit = db.getLimit("setLimitShirts");
shirts.setMax(100);
if (startSize.equals("XL") && limit.equals("S")) {
if (newCurrentSize.equals("L")) {
// Fill progress bar by 1/3
shirts.setProgress(33);
}
if (newCurrentSize.equals("M")) {
// Fill progress bar by 2/3
shirts.setProgress(66);
}
if (newCurrentSize.equals("S")) {
// Fill progress bar 100 percent
shirts.setProgress(100);
// Give a toast saying you've reached your limit
Toast.makeText(this, "You've reached your limit! ", Toast.LENGTH_LONG).show();
// Set all values in database to null
db.removeLImit("setLimitShirts");
}
}
}
}
activity_progress_bar_shirts.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#29A9D2"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Track your progress"
android:id="#+id/TrackProgressShirts"
android:layout_gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="30dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Current Size: Large"
android:id="#+id/currentSizeShirts"
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:layout_marginTop="80dp"
android:textColor="#FFFFFF" />
<EditText
android:layout_width="350dp"
android:layout_height="wrap_content"
android:id="#+id/newSizeShirts"
android:layout_marginTop="20dp"
android:hint="Enter your new size"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="30dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter new size"
android:id="#+id/newSizeEnterButtonShirts"
android:layout_gravity="center_horizontal" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="300dp"
android:progressDrawable="#drawable/custom_progressbar"
android:layout_height="wrap_content"
android:id="#+id/progressBarShirts"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginTop="170dp"
android:max="100"
android:minWidth="300dp"
android:minHeight="100dp"
android:maxWidth="300dp"
android:maxHeight="100dp"
android:indeterminateOnly="true"
android:progress="0" />
</LinearLayout>

Categories

Resources