Skip to content

Commit 72ad58e

Browse files
Add files via upload
1 parent e783989 commit 72ad58e

38 files changed

+895
-0
lines changed

app/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.example.carousel'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
applicationId "com.example.carousel"
11+
minSdk 24
12+
targetSdk 33
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.9.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
testImplementation 'junit:junit:4.13.2'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
39+
implementation 'com.github.bumptech.glide:glide:4.16.0'
40+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.carousel;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.example.carousel", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:dataExtractionRules="@xml/data_extraction_rules"
10+
android:fullBackupContent="@xml/backup_rules"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.Carousel"
16+
tools:targetApi="31">
17+
<activity
18+
android:name=".ImageViewActivity"
19+
android:exported="false" />
20+
<activity
21+
android:name=".MainActivity"
22+
android:exported="true">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
</application>
30+
31+
</manifest>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.example.carousel;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.ImageView;
8+
9+
import androidx.annotation.NonNull;
10+
import androidx.recyclerview.widget.RecyclerView;
11+
12+
import com.bumptech.glide.Glide;
13+
14+
import java.util.ArrayList;
15+
16+
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
17+
Context context;
18+
ArrayList<String> arrayList;
19+
OnItemClickListener onItemClickListener;
20+
21+
public ImageAdapter(Context context, ArrayList<String> arrayList) {
22+
this.context = context;
23+
this.arrayList = arrayList;
24+
}
25+
26+
@NonNull
27+
@Override
28+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
29+
View view = LayoutInflater.from(context).inflate(R.layout.image_list_item, parent, false);
30+
return new ViewHolder(view);
31+
}
32+
33+
@Override
34+
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
35+
Glide.with(context).load(arrayList.get(position)).into(holder.imageView);
36+
holder.itemView.setOnClickListener(view -> onItemClickListener.onClick(holder.imageView, arrayList.get(position)));
37+
}
38+
39+
@Override
40+
public int getItemCount() {
41+
return arrayList.size();
42+
}
43+
44+
public static class ViewHolder extends RecyclerView.ViewHolder {
45+
ImageView imageView;
46+
public ViewHolder(@NonNull View itemView) {
47+
super(itemView);
48+
imageView = itemView.findViewById(R.id.list_item_image);
49+
}
50+
}
51+
52+
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
53+
this.onItemClickListener = onItemClickListener;
54+
}
55+
56+
public interface OnItemClickListener {
57+
void onClick(ImageView imageView, String path);
58+
}
59+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.carousel;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.widget.ImageView;
7+
8+
import com.bumptech.glide.Glide;
9+
10+
public class ImageViewActivity extends AppCompatActivity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_image_view);
16+
17+
ImageView imageView = findViewById(R.id.imageView);
18+
19+
Glide.with(ImageViewActivity.this).load(getIntent().getStringExtra("image")).into(imageView);
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.example.carousel;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
import androidx.recyclerview.widget.RecyclerView;
5+
6+
import android.app.ActivityOptions;
7+
import android.content.Intent;
8+
import android.os.Bundle;
9+
import android.widget.ImageView;
10+
11+
import java.util.ArrayList;
12+
13+
public class MainActivity extends AppCompatActivity {
14+
15+
@Override
16+
protected void onCreate(Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.activity_main);
19+
20+
RecyclerView recyclerView = findViewById(R.id.recycler);
21+
ArrayList<String> arrayList = new ArrayList<>();
22+
23+
arrayList.add("https://images.unsplash.com/photo-1692528131755-d4e366b2adf0?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzNXx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60");
24+
arrayList.add("https://images.unsplash.com/photo-1692862582645-3b6fd47b7513?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw0MXx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60");
25+
arrayList.add("https://images.unsplash.com/photo-1692584927805-d4096552a5ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw0Nnx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60");
26+
arrayList.add("https://images.unsplash.com/photo-1692854236272-cc49076a2629?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw1MXx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60");
27+
arrayList.add("https://images.unsplash.com/photo-1681207751526-a091f2c6a538?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyODF8fHxlbnwwfHx8fHw%3D&auto=format&fit=crop&w=500&q=60");
28+
arrayList.add("https://images.unsplash.com/photo-1692610365998-c628604f5d9f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyODZ8fHxlbnwwfHx8fHw%3D&auto=format&fit=crop&w=500&q=60");
29+
30+
ImageAdapter adapter = new ImageAdapter(MainActivity.this, arrayList);
31+
recyclerView.setAdapter(adapter);
32+
33+
adapter.setOnItemClickListener(new ImageAdapter.OnItemClickListener() {
34+
@Override
35+
public void onClick(ImageView imageView, String path) {
36+
startActivity(new Intent(MainActivity.this, ImageViewActivity.class).putExtra("image", path), ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, imageView, "image").toBundle());
37+
}
38+
});
39+
}
40+
}

0 commit comments

Comments
 (0)