mirror of
https://github.com/wesaphzt/privatelock.git
synced 2025-04-19 05:59:09 +00:00
animation scaling issues fixed
This commit is contained in:
parent
cd8226cddc
commit
87e349d02a
3 changed files with 45 additions and 15 deletions
|
@ -22,10 +22,11 @@ import androidx.fragment.app.FragmentTransaction;
|
|||
|
||||
import android.os.CountDownTimer;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -126,10 +127,30 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
//https://stackoverflow.com/questions/29381474/how-to-draw-a-circle-with-animation-in-android-with-circle-size-based-on-a-value
|
||||
circle = findViewById(R.id.circle);
|
||||
circle_bg = findViewById(R.id.circle_bg);
|
||||
|
||||
final RelativeLayout relativeLayout = findViewById(R.id.content_main);
|
||||
final RelativeLayout rlCircle = findViewById(R.id.rlCircle);
|
||||
|
||||
//scale height/width of animation
|
||||
relativeLayout.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
//only want to do this once
|
||||
relativeLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
|
||||
circle.setRect((circle.getHeight() / 2), (circle.getHeight()) / 2);
|
||||
circle_bg.setRect((circle_bg.getHeight() / 2), (circle_bg.getHeight()) / 2);
|
||||
|
||||
circle.setX((rlCircle.getWidth() - circle.getRect()) / 2);
|
||||
circle_bg.setX((rlCircle.getWidth() - circle.getRect()) / 2);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
circle.setColor(circleDefaultR, circleDefaultG, circleDefaultB);
|
||||
//set background circle
|
||||
CircleAngleAnimation animation = new CircleAngleAnimation(circle_bg, 360);
|
||||
|
|
|
@ -13,15 +13,14 @@ public class Circle extends View {
|
|||
private static final int START_ANGLE_POINT = 90;
|
||||
|
||||
private final Paint paint;
|
||||
private final RectF rect;
|
||||
private RectF rect;
|
||||
|
||||
private float angle;
|
||||
private final int strokeWidth = 10;
|
||||
|
||||
public Circle(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
final int strokeWidth = 10;
|
||||
|
||||
paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
|
@ -29,8 +28,8 @@ public class Circle extends View {
|
|||
//circle color (currently set upon instance)
|
||||
//paint.setColor(Color.BLUE);
|
||||
|
||||
//size
|
||||
rect = new RectF(strokeWidth, strokeWidth, 600 + strokeWidth, 600 + strokeWidth);
|
||||
//size (currently set upon instance)
|
||||
//rect = new RectF(strokeWidth, strokeWidth, 230 + strokeWidth, 230 + strokeWidth);
|
||||
|
||||
//initial angle (optional)
|
||||
angle = 0;
|
||||
|
@ -53,4 +52,12 @@ public class Circle extends View {
|
|||
public void setAngle(float angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public void setRect(int right, int bottom) {
|
||||
this.rect = new RectF(strokeWidth, strokeWidth, right, bottom);
|
||||
}
|
||||
|
||||
public float getRect() {
|
||||
return rect.right;
|
||||
}
|
||||
}
|
|
@ -142,22 +142,24 @@
|
|||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/rlCircle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/activity_margin_large"
|
||||
android:layout_gravity="center_horizontal">
|
||||
|
||||
<com.wesaphzt.privatelock.animation.Circle
|
||||
android:id="@+id/circle_bg"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="240dp"
|
||||
android:layout_centerHorizontal="true" />
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
<com.wesaphzt.privatelock.animation.Circle
|
||||
android:id="@+id/circle"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="240dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Add table
Reference in a new issue