Skip to content

Commit a63a458

Browse files
committed
Merge pull request #7 from lewismcgeary/improve-java-efficiency
improve-java-efficiency
2 parents 4ac44c6 + 86a4f45 commit a63a458

File tree

3 files changed

+14
-58
lines changed

3 files changed

+14
-58
lines changed

app/app.iml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,17 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
6767
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
68-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
6968
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
70-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
69+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
7170
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7271
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
73-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
7472
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
76-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
77-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
78-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
7973
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
80-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
8174
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
82-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
8375
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8476
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8577
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
8679
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
8780
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8881
</content>

app/src/main/java/com/mcgearybros/androidtoapplevectorlogo/MainActivity.java

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
public class MainActivity extends Activity {
1010

11-
AnimatedVectorDrawable mightyMorphinAnimatedVectorDrawable;
12-
AnimatedVectorDrawable mightyMorphinAnimatedVectorDrawableReversed;
13-
ImageView animatorImageView;
14-
11+
private AnimatedVectorDrawable mightyMorphinAnimatedVectorDrawable;
12+
private AnimatedVectorDrawable mightyMorphinAnimatedVectorDrawableReversed;
13+
private ImageView animatorImageView;
14+
private boolean isShowingAndroid = true;
1515

1616
@Override
1717
protected void onCreate(Bundle savedInstanceState) {
@@ -21,39 +21,19 @@ protected void onCreate(Bundle savedInstanceState) {
2121
animatorImageView = (ImageView) findViewById(R.id.path_morph_animated_vector);
2222
mightyMorphinAnimatedVectorDrawable = (AnimatedVectorDrawable) getDrawable(R.drawable.consolidated_animated_vector);
2323
mightyMorphinAnimatedVectorDrawableReversed = (AnimatedVectorDrawable) getDrawable(R.drawable.consolidated_animated_vector_reverse);
24-
animatorImageView.setImageDrawable(getDrawable(R.drawable.android_logo_vector_morphable));
25-
26-
final ImageView toAppleButton = (ImageView) findViewById(R.id.to_apple_button);
27-
final ImageView toAndroidButton = (ImageView) findViewById(R.id.to_android_button);
28-
toAndroidButton.setEnabled(false);
29-
toAppleButton.setOnClickListener(new View.OnClickListener() {
30-
@Override
31-
public void onClick(View v) {
32-
toAndroidButton.setEnabled(true);
33-
toAppleButton.setEnabled(false);
34-
animateToApple();
35-
}
36-
});
37-
toAndroidButton.setOnClickListener(new View.OnClickListener() {
24+
animatorImageView.setOnClickListener(new View.OnClickListener() {
3825
@Override
3926
public void onClick(View v) {
40-
toAppleButton.setEnabled(true);
41-
toAndroidButton.setEnabled(false);
42-
animateToAndroid();
27+
morph();
4328
}
4429
});
4530
}
4631

47-
public void animateToApple(){
48-
mightyMorphinAnimatedVectorDrawable.stop();
49-
animatorImageView.setImageDrawable(mightyMorphinAnimatedVectorDrawable);
50-
mightyMorphinAnimatedVectorDrawable.start();
51-
}
52-
53-
public void animateToAndroid(){
54-
mightyMorphinAnimatedVectorDrawableReversed.stop();
55-
animatorImageView.setImageDrawable(mightyMorphinAnimatedVectorDrawableReversed);
56-
mightyMorphinAnimatedVectorDrawableReversed.start();
32+
public void morph(){
33+
AnimatedVectorDrawable currentDrawable = isShowingAndroid ? mightyMorphinAnimatedVectorDrawable : mightyMorphinAnimatedVectorDrawableReversed;
34+
animatorImageView.setImageDrawable(currentDrawable);
35+
currentDrawable.start();
36+
isShowingAndroid = !isShowingAndroid;
5737
}
5838

5939
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,10 @@
88

99
<ImageView
1010
android:id="@+id/path_morph_animated_vector"
11+
android:src="@drawable/android_logo_vector_morphable"
1112
android:layout_width="match_parent"
1213
android:layout_height="match_parent"
1314
android:clickable="true"
1415
android:scaleType="fitCenter"
1516
android:layout_centerHorizontal="true"/>
16-
<ImageView
17-
android:id="@+id/to_android_button"
18-
android:layout_width="96dp"
19-
android:layout_height="96dp"
20-
android:src="@drawable/android_logo_vector_morphable"
21-
android:layout_alignParentBottom="true"
22-
android:layout_alignParentLeft="true"/>
23-
<ImageView
24-
android:id="@+id/to_apple_button"
25-
android:layout_width="96dp"
26-
android:layout_height="96dp"
27-
android:src="@drawable/apple_logo_vector_morphable"
28-
android:layout_alignParentBottom="true"
29-
android:layout_alignParentRight="true"
30-
android:paddingBottom="16dp"/>
31-
32-
33-
3417
</RelativeLayout>

0 commit comments

Comments
 (0)