-
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
Open
florina-muntenescu
wants to merge
7
commits into
master
Choose a base branch
from
vector_drawables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
303f0b8
Comparing the duration of drawing a vector drawable vs a png
florina-muntenescu 248bfe0
Removed setting a default image
florina-muntenescu 19bace9
placeholders added
florina-muntenescu 9d6dc0c
Changing the order of the calls.
florina-muntenescu b8f7e62
Small updates of images and string.
florina-muntenescu c792366
permissions commented out
florina-muntenescu 35cc361
code review fixes
florina-muntenescu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/fmuntenescu/playground/vectordrawables/MeasurableImageView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ViewRedrawnListener mViewRedrawnListener; | ||
|
||
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 setViewRedrawnListener(@NonNull final ViewRedrawnListener viewRedrawnListener) { | ||
assert viewRedrawnListener != null; | ||
|
||
mViewRedrawnListener = viewRedrawnListener; | ||
} | ||
|
||
@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 (mViewRedrawnListener != null) { | ||
mViewRedrawnListener.onRedraw(duration); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...c/main/java/fmuntenescu/playground/vectordrawables/VectorDrawablesPlaygroundActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.setViewRedrawnListener(this::updateDuration); | ||
|
||
RadioGroup group = (RadioGroup) findViewById(R.id.drawable_choice); | ||
assert group != null; | ||
group.setOnCheckedChangeListener((group1, checkedId) -> onImageTypeChanged(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 onImageTypeChanged(@IdRes final int checkedId) { | ||
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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/fmuntenescu/playground/vectordrawables/ViewRedrawnListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ViewRedrawnListener { | ||
|
||
/** | ||
* Called when the view has been redrawn | ||
* | ||
* @param miliseconds the time took to draw the view. | ||
*/ | ||
void onRedraw(long miliseconds); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/res/layout/vector_drawables_playground_activity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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