Skip to content

Commit 27b74a2

Browse files
author
Juan Carlos Vallejo
committed
Initial release
0 parents  commit 27b74a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2485
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*~
2+
*.iml
3+
.gradle
4+
/local.properties
5+
/.idea/workspace.xml
6+
/.idea/libraries
7+
/.idea/vcs.xml
8+
.DS_Store
9+
/build
10+
/captures
11+
.externalNativeBuild

.idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+69
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.0"
6+
defaultConfig {
7+
applicationId "com.urizev.flags.test"
8+
minSdkVersion 21
9+
targetSdkVersion 24
10+
versionCode 100
11+
versionName "0.1"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile project(':flags-lib')
28+
29+
compile 'com.android.support:appcompat-v7:24.2.1'
30+
testCompile 'junit:junit:4.12'
31+
compile 'com.android.support:recyclerview-v7:24.2.1'
32+
compile 'com.android.support:cardview-v7:24.2.1'
33+
}
34+

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/jcvallejo/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.urizev.flags.test;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.urizev.flags.test", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.urizev.flags.test"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN"/>
14+
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>

app/src/main/ic_launcher-web.png

199 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2012 Square, Inc.
2+
package com.urizev.flags.test;
3+
4+
import android.content.Context;
5+
import android.content.res.TypedArray;
6+
import android.util.AttributeSet;
7+
import android.widget.ImageView;
8+
9+
/** Maintains an aspect ratio based on either width or height. Disabled by default. */
10+
public class AspectRatioImageView extends ImageView {
11+
// NOTE: These must be kept in sync with the AspectRatioImageView attributes in attrs.xml.
12+
public static final int MEASUREMENT_WIDTH = 0;
13+
public static final int MEASUREMENT_HEIGHT = 1;
14+
15+
private static final float DEFAULT_ASPECT_RATIO = 1f;
16+
private static final boolean DEFAULT_ASPECT_RATIO_ENABLED = false;
17+
private static final int DEFAULT_DOMINANT_MEASUREMENT = MEASUREMENT_WIDTH;
18+
19+
private float aspectRatio;
20+
private boolean aspectRatioEnabled;
21+
private int dominantMeasurement;
22+
23+
public AspectRatioImageView(Context context) {
24+
this(context, null);
25+
}
26+
27+
public AspectRatioImageView(Context context, AttributeSet attrs) {
28+
super(context, attrs);
29+
30+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AspectRatioImageView);
31+
aspectRatio = a.getFloat(R.styleable.AspectRatioImageView_aspectRatio, DEFAULT_ASPECT_RATIO);
32+
aspectRatioEnabled = a.getBoolean(R.styleable.AspectRatioImageView_aspectRatioEnabled,
33+
DEFAULT_ASPECT_RATIO_ENABLED);
34+
dominantMeasurement = a.getInt(R.styleable.AspectRatioImageView_dominantMeasurement,
35+
DEFAULT_DOMINANT_MEASUREMENT);
36+
a.recycle();
37+
}
38+
39+
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
40+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
41+
if (!aspectRatioEnabled) return;
42+
43+
int newWidth;
44+
int newHeight;
45+
switch (dominantMeasurement) {
46+
case MEASUREMENT_WIDTH:
47+
newWidth = getMeasuredWidth();
48+
newHeight = (int) (newWidth / aspectRatio);
49+
break;
50+
51+
case MEASUREMENT_HEIGHT:
52+
newHeight = getMeasuredHeight();
53+
newWidth = (int) (newHeight * aspectRatio);
54+
break;
55+
56+
default:
57+
throw new IllegalStateException("Unknown measurement with ID " + dominantMeasurement);
58+
}
59+
60+
setMeasuredDimension(newWidth, newHeight);
61+
}
62+
63+
/** Get the aspect ratio for this image view. */
64+
public float getAspectRatio() {
65+
return aspectRatio;
66+
}
67+
68+
/** Set the aspect ratio for this image view. This will update the view instantly. */
69+
public void setAspectRatio(float aspectRatio) {
70+
this.aspectRatio = aspectRatio;
71+
if (aspectRatioEnabled) {
72+
requestLayout();
73+
}
74+
}
75+
76+
/** Get whether or not forcing the aspect ratio is enabled. */
77+
public boolean getAspectRatioEnabled() {
78+
return aspectRatioEnabled;
79+
}
80+
81+
/** set whether or not forcing the aspect ratio is enabled. This will re-layout the view. */
82+
public void setAspectRatioEnabled(boolean aspectRatioEnabled) {
83+
this.aspectRatioEnabled = aspectRatioEnabled;
84+
requestLayout();
85+
}
86+
87+
/** Get the dominant measurement for the aspect ratio. */
88+
public int getDominantMeasurement() {
89+
return dominantMeasurement;
90+
}
91+
92+
/**
93+
* Set the dominant measurement for the aspect ratio.
94+
*
95+
* @see #MEASUREMENT_WIDTH
96+
* @see #MEASUREMENT_HEIGHT
97+
*/
98+
public void setDominantMeasurement(int dominantMeasurement) {
99+
if (dominantMeasurement != MEASUREMENT_HEIGHT && dominantMeasurement != MEASUREMENT_WIDTH) {
100+
throw new IllegalArgumentException("Invalid measurement type.");
101+
}
102+
this.dominantMeasurement = dominantMeasurement;
103+
requestLayout();
104+
}
105+
}

0 commit comments

Comments
 (0)