-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector drawables #2
base: master
Are you sure you want to change the base?
Changes from 6 commits
303f0b8
248bfe0
19bace9
9d6dc0c
b8f7e62
c792366
35cc361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import android.view.View; | ||
|
||
import fmuntenescu.playground.animations.AnimationPlaygroundActivity; | ||
import fmuntenescu.playground.vectordrawables.VectorDrawablesPlaygroundActivity; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
|
@@ -15,10 +16,18 @@ protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
View view = findViewById(R.id.animations_playground_button); | ||
View viewAnimationPlaygroundButton = findViewById(R.id.animations_playground_button); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about startPlaygroundButton? |
||
|
||
assert view != null; | ||
view.setOnClickListener(v -> startActivity(AnimationPlaygroundActivity.class)); | ||
assert viewAnimationPlaygroundButton != null; | ||
viewAnimationPlaygroundButton | ||
.setOnClickListener(v -> startActivity(AnimationPlaygroundActivity.class)); | ||
|
||
View viewVectorDrawablesPlaygroundButton = findViewById( | ||
R.id.vector_drawables_playground_button); | ||
|
||
assert viewVectorDrawablesPlaygroundButton != null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you really need those asserts in your playground app? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code looks... coloured otherwise.. |
||
viewVectorDrawablesPlaygroundButton | ||
.setOnClickListener(v -> startActivity(VectorDrawablesPlaygroundActivity.class)); | ||
} | ||
|
||
private void startActivity(@NonNull final Class<?> cls) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fmuntenescu.playground.vectordrawables; | ||
|
||
/** | ||
* Listener that notifies when a view has been redrawn | ||
*/ | ||
public interface DrawListener { | ||
|
||
/** | ||
* Called when the view has been redrawn | ||
* | ||
* @param miliseconds the time took to draw the view. | ||
*/ | ||
void viewDrawn(long miliseconds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dpreussler - ah! amazingly simple! thanks! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fmuntenescu.playground.vectordrawables; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.widget.ImageView; | ||
|
||
/** | ||
* ImageView that measures the time took to draw. | ||
*/ | ||
public class MeasurableImageView extends ImageView { | ||
|
||
@Nullable | ||
private DrawListener mDrawListener; | ||
|
||
public MeasurableImageView(final Context context) { | ||
super(context); | ||
} | ||
|
||
public MeasurableImageView(final Context context, final AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public MeasurableImageView(final Context context, final AttributeSet attrs, | ||
final int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public void setDrawListener(@NonNull final DrawListener drawListener) { | ||
assert drawListener != null; | ||
|
||
mDrawListener = drawListener; | ||
} | ||
|
||
@Override | ||
protected void onDraw(final Canvas canvas) { | ||
long startTime = System.currentTimeMillis(); | ||
|
||
super.onDraw(canvas); | ||
|
||
long endTime = System.currentTimeMillis(); | ||
notifyDraw(startTime, endTime); | ||
} | ||
|
||
private void notifyDraw(final long startTime, final long endTime) { | ||
long duration = endTime - startTime; | ||
|
||
Log.d("playground", "rendering took " + duration); | ||
|
||
if (mDrawListener != null) { | ||
mDrawListener.viewDrawn(duration); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package fmuntenescu.playground.vectordrawables; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.IdRes; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.RadioGroup; | ||
import android.widget.TextView; | ||
|
||
import fmuntenescu.playground.R; | ||
|
||
/** | ||
* Playground for Vector Drawables. | ||
*/ | ||
public class VectorDrawablesPlaygroundActivity extends AppCompatActivity { | ||
|
||
@Nullable | ||
private TextView mDurationText; | ||
|
||
@Nullable | ||
private MeasurableImageView mMeasurableImageView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.vector_drawables_playground_activity); | ||
|
||
mDurationText = (TextView) findViewById(R.id.draw_duration_text); | ||
mMeasurableImageView = (MeasurableImageView) findViewById( | ||
R.id.measurable_image); | ||
|
||
assert mMeasurableImageView != null; | ||
mMeasurableImageView.setDrawListener(this::updateDuration); | ||
|
||
RadioGroup group = (RadioGroup) findViewById(R.id.drawable_choice); | ||
assert group != null; | ||
group.setOnCheckedChangeListener((group1, checkedId) -> checkedChanged(checkedId)); | ||
group.check(R.id.vector_drawable_button); | ||
} | ||
|
||
private void updateDuration(final long miliseconds) { | ||
assert mDurationText != null; | ||
|
||
mDurationText.setText(getString(R.string.duration, miliseconds)); | ||
} | ||
|
||
private void checkedChanged(@IdRes final int checkedId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onImageModeChanged? |
||
switch (checkedId) { | ||
case R.id.vector_drawable_button: | ||
vectorDrawableSelected(); | ||
break; | ||
case R.id.png_button: | ||
pngSelected(); | ||
break; | ||
} | ||
} | ||
|
||
private void vectorDrawableSelected() { | ||
assert mMeasurableImageView != null; | ||
mMeasurableImageView.setImageResource(R.drawable.placeholder); | ||
} | ||
|
||
private void pngSelected() { | ||
assert mMeasurableImageView != null; | ||
mMeasurableImageView.setImageResource(R.drawable.placeholder_png); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="336dp" | ||
android:height="548dp" | ||
android:viewportHeight="548" | ||
android:viewportWidth="336"> | ||
|
||
<group | ||
android:translateX="-12.000000" | ||
android:translateY="-36.000000"> | ||
<group | ||
android:translateX="12.000000" | ||
android:translateY="36.000000"> | ||
<path | ||
android:name="Mask" | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M 4 0 L 332 0 Q 336 0 336 4 L 336 544 Q 336 548 332 548 L 4 548 Q 0 548 0 544 L 0 4 Q 0 0 4 0 Z" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 280 H 312 V 292 H 16 V 280 Z" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 304 H 267 V 316 H 16 V 304 Z" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 328 H 307 V 340 H 16 V 328 Z" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 354 H 213 V 366 H 16 V 354 Z" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillAlpha="0.9" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 207 H 316 V 227 H 16 V 207 Z" | ||
android:strokeAlpha="0.9" /> | ||
<path | ||
android:name="Rectangle-1709" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 16 240 H 284 V 260 H 16 V 240 Z" /> | ||
<path | ||
android:name="Mask" | ||
android:fillColor="#DF6B9ED1" | ||
android:pathData="M 4 0 L 332 0 Q 336 0 336 4 L 336 188 Q 336 192 332 192 L 4 192 Q 0 192 0 188 L 0 4 Q 0 0 4 0 Z" /> | ||
</group> | ||
</group> | ||
</vector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<fmuntenescu.playground.vectordrawables.MeasurableImageView | ||
android:id="@+id/measurable_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_above="@+id/draw_duration_text" /> | ||
|
||
<RadioGroup | ||
android:id="@+id/drawable_choice" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:textSize="@dimen/text_size_normal"> | ||
|
||
<RadioButton | ||
android:id="@+id/vector_drawable_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/vector_drawable" | ||
android:textSize="@dimen/text_size_normal" /> | ||
|
||
<RadioButton | ||
android:id="@+id/png_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/activity_vertical_margin" | ||
android:text="@string/png" | ||
android:textSize="@dimen/text_size_normal" /> | ||
</RadioGroup> | ||
|
||
<TextView | ||
android:id="@+id/draw_duration_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="@dimen/animating_view_height" | ||
android:layout_alignParentBottom="true" | ||
android:background="@color/colorPrimary" | ||
android:gravity="center_vertical" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:textColor="@android:color/white" | ||
android:textSize="@dimen/text_size_normal" /> | ||
</RelativeLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it simply, make your min sdk 4.4. then you dont need this anymore as long as you stick to getExternalFilesDir())
https://developer.android.com/guide/topics/manifest/uses-permission-element.html