Skip to content

Commit 5e38bef

Browse files
author
Nilanchal Panigrahy
committed
Consolidated all UI examples into single repo
1 parent a9b1fff commit 5e38bef

33 files changed

+1044
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="Android-GridView-Example" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Android-GridView-Advance-Tutorial" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":app" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
13+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
14+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15+
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
16+
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
17+
<afterSyncTasks>
18+
<task>generateDebugAndroidTestSources</task>
19+
<task>generateDebugSources</task>
20+
</afterSyncTasks>
21+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
22+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
23+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
24+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
25+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
26+
</configuration>
27+
</facet>
28+
</component>
29+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
30+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
31+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
32+
<exclude-output />
33+
<content url="file://$MODULE_DIR$">
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
44+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
67+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
69+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
70+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
71+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/jars" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
90+
</content>
91+
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
92+
<orderEntry type="sourceFolder" forTests="false" />
93+
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
94+
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
95+
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
96+
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
97+
</component>
98+
</module>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 21
5+
buildToolsVersion "21.1.2"
6+
7+
defaultConfig {
8+
applicationId "com.javatechig.gridviewexample"
9+
minSdkVersion 14
10+
targetSdkVersion 21
11+
versionCode 1
12+
versionName "1.0"
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(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:appcompat-v7:21.0.3'
25+
compile 'com.squareup.picasso:picasso:2.5.2'
26+
}
Lines changed: 17 additions & 0 deletions
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 /Applications/adt-bundle-mac-x86_64-20140702/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,13 @@
1+
package com.javatechig.gridviewexample;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.gridviewexample">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".GridViewActivity"
14+
android:label="@string/app_name">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
22+
<activity android:name=".DetailsActivity"
23+
android:theme="@style/Transparent"
24+
/>
25+
</application>
26+
27+
</manifest>
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package com.javatechig.gridviewexample;
2+
3+
import android.animation.ObjectAnimator;
4+
import android.animation.TimeInterpolator;
5+
import android.graphics.Color;
6+
import android.graphics.drawable.ColorDrawable;
7+
import android.os.Bundle;
8+
import android.support.v7.app.ActionBar;
9+
import android.support.v7.app.ActionBarActivity;
10+
import android.text.Html;
11+
import android.view.ViewTreeObserver;
12+
import android.view.animation.AccelerateInterpolator;
13+
import android.view.animation.DecelerateInterpolator;
14+
import android.widget.FrameLayout;
15+
import android.widget.ImageView;
16+
import android.widget.TextView;
17+
18+
import com.squareup.picasso.Picasso;
19+
20+
public class DetailsActivity extends ActionBarActivity {
21+
private static final int ANIM_DURATION = 600;
22+
private TextView titleTextView;
23+
private ImageView imageView;
24+
25+
private int mLeftDelta;
26+
private int mTopDelta;
27+
private float mWidthScale;
28+
private float mHeightScale;
29+
30+
private FrameLayout frameLayout;
31+
private ColorDrawable colorDrawable;
32+
33+
private int thumbnailTop;
34+
private int thumbnailLeft;
35+
private int thumbnailWidth;
36+
private int thumbnailHeight;
37+
38+
@Override
39+
protected void onCreate(Bundle savedInstanceState) {
40+
super.onCreate(savedInstanceState);
41+
42+
//Setting details screen layout
43+
setContentView(R.layout.activity_details_view);
44+
45+
ActionBar actionBar = getSupportActionBar();
46+
actionBar.hide();
47+
48+
//retrieves the thumbnail data
49+
Bundle bundle = getIntent().getExtras();
50+
thumbnailTop = bundle.getInt("top");
51+
thumbnailLeft = bundle.getInt("left");
52+
thumbnailWidth = bundle.getInt("width");
53+
thumbnailHeight = bundle.getInt("height");
54+
55+
String title = bundle.getString("title");
56+
String image = bundle.getString("image");
57+
58+
//initialize and set the image description
59+
titleTextView = (TextView) findViewById(R.id.title);
60+
titleTextView.setText(Html.fromHtml(title));
61+
62+
//Set image url
63+
imageView = (ImageView) findViewById(R.id.grid_item_image);
64+
Picasso.with(this).load(image).into(imageView);
65+
66+
//Set the background color to black
67+
frameLayout = (FrameLayout) findViewById(R.id.main_background);
68+
colorDrawable = new ColorDrawable(Color.BLACK);
69+
frameLayout.setBackground(colorDrawable);
70+
71+
// Only run the animation if we're coming from the parent activity, not if
72+
// we're recreated automatically by the window manager (e.g., device rotation)
73+
if (savedInstanceState == null) {
74+
ViewTreeObserver observer = imageView.getViewTreeObserver();
75+
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
76+
77+
@Override
78+
public boolean onPreDraw() {
79+
imageView.getViewTreeObserver().removeOnPreDrawListener(this);
80+
81+
// Figure out where the thumbnail and full size versions are, relative
82+
// to the screen and each other
83+
int[] screenLocation = new int[2];
84+
imageView.getLocationOnScreen(screenLocation);
85+
mLeftDelta = thumbnailLeft - screenLocation[0];
86+
mTopDelta = thumbnailTop - screenLocation[1];
87+
88+
// Scale factors to make the large version the same size as the thumbnail
89+
mWidthScale = (float) thumbnailWidth / imageView.getWidth();
90+
mHeightScale = (float) thumbnailHeight / imageView.getHeight();
91+
92+
enterAnimation();
93+
94+
return true;
95+
}
96+
});
97+
}
98+
}
99+
100+
/**
101+
* The enter animation scales the picture in from its previous thumbnail
102+
* size/location.
103+
*/
104+
public void enterAnimation() {
105+
106+
// Set starting values for properties we're going to animate. These
107+
// values scale and position the full size version down to the thumbnail
108+
// size/location, from which we'll animate it back up
109+
imageView.setPivotX(0);
110+
imageView.setPivotY(0);
111+
imageView.setScaleX(mWidthScale);
112+
imageView.setScaleY(mHeightScale);
113+
imageView.setTranslationX(mLeftDelta);
114+
imageView.setTranslationY(mTopDelta);
115+
116+
// interpolator where the rate of change starts out quickly and then decelerates.
117+
TimeInterpolator sDecelerator = new DecelerateInterpolator();
118+
119+
// Animate scale and translation to go from thumbnail to full size
120+
imageView.animate().setDuration(ANIM_DURATION).scaleX(1).scaleY(1).
121+
translationX(0).translationY(0).setInterpolator(sDecelerator);
122+
123+
// Fade in the black background
124+
ObjectAnimator bgAnim = ObjectAnimator.ofInt(colorDrawable, "alpha", 0, 255);
125+
bgAnim.setDuration(ANIM_DURATION);
126+
bgAnim.start();
127+
128+
}
129+
130+
/**
131+
* The exit animation is basically a reverse of the enter animation.
132+
* This Animate image back to thumbnail size/location as relieved from bundle.
133+
*
134+
* @param endAction This action gets run after the animation completes (this is
135+
* when we actually switch activities)
136+
*/
137+
public void exitAnimation(final Runnable endAction) {
138+
139+
TimeInterpolator sInterpolator = new AccelerateInterpolator();
140+
imageView.animate().setDuration(ANIM_DURATION).scaleX(mWidthScale).scaleY(mHeightScale).
141+
translationX(mLeftDelta).translationY(mTopDelta)
142+
.setInterpolator(sInterpolator).withEndAction(endAction);
143+
144+
// Fade out background
145+
ObjectAnimator bgAnim = ObjectAnimator.ofInt(colorDrawable, "alpha", 0);
146+
bgAnim.setDuration(ANIM_DURATION);
147+
bgAnim.start();
148+
}
149+
150+
@Override
151+
public void onBackPressed() {
152+
exitAnimation(new Runnable() {
153+
public void run() {
154+
finish();
155+
}
156+
});
157+
}
158+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.javatechig.gridviewexample;
2+
3+
public class GridItem {
4+
private String image;
5+
private String title;
6+
7+
public GridItem() {
8+
super();
9+
}
10+
11+
public String getImage() {
12+
return image;
13+
}
14+
15+
public void setImage(String image) {
16+
this.image = image;
17+
}
18+
19+
public String getTitle() {
20+
return title;
21+
}
22+
23+
public void setTitle(String title) {
24+
this.title = title;
25+
}
26+
}

0 commit comments

Comments
 (0)