Android gallery app with source code
Android gallery app source code
Main activity.layout
custom_decorator.xml
Mainfest
java file| <?xml version="1.0" encoding="utf-8"?><!-- | |
| ~ Copyright (c) 2021 Anupgorai. | |
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | |
| ~ you may not use this file except in compliance with the License. | |
| ~ You may obtain a copy of the License at | |
| ~ http://www.apache.org/licenses/LICENSE-2.0 | |
| ~ Unless required by applicable law or agreed to in writing, software | |
| ~ distributed under the License is distributed on an "AS IS" BASIS, | |
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| ~ See the License for the specific language governing permissions and | |
| ~ limitations under the License. | |
| --> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| package="com.jesusd0897.gallerydroid.sample"> | |
| <uses-permission android:name="android.permission.INTERNET" /> | |
| <application | |
| android:allowBackup="true" | |
| android:icon="@mipmap/ic_launcher" | |
| android:label="@string/app_name" | |
| android:roundIcon="@mipmap/ic_launcher_round" | |
| android:supportsRtl="true" | |
| android:theme="@style/Theme.MaterialComponents.Light.NoActionBar" | |
| tools:replace="android:theme"> | |
| <activity android:name=".MainActivity"> | |
| <intent-filter> | |
| <action android:name="android.intent.action.MAIN" /> | |
| <category android:name="android.intent.category.LAUNCHER" /> | |
| </intent-filter> | |
| </activity> | |
| <activity | |
| android:name="com.jesusd0897.gallerydroid.view.activity.PictureDetailActivity" | |
| android:configChanges="orientation|screenSize" | |
| android:theme="@style/Theme.MaterialComponents.NoActionBar" /> | |
| </application> | |
| </manifest> |
| /* | |
| * Copyright (c) 2021 Anupgorai. | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.jesusd0897.gallerydroid.sample | |
| import com.jesusd0897.gallerydroid.model.GalleryDroid | |
| import com.jesusd0897.gallerydroid.model.Picture | |
| val GALLERY_DROID = GalleryDroid( | |
| items = listOf( | |
| Picture( | |
| fileURL = "https://picsum.photos/id/10/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/10/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/11/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/11/200/400", | |
| fileName = "Lorem ipsum 1", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/12/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/12/200/250", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/13/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/13/200/400", | |
| fileName = "Lorem ipsum 2", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/14/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/14/200/450", | |
| fileName = "Lorem ipsum 3", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/15/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/15/200/500", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/16/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/16/200/280", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/17/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/17/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/18/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/18/200/400", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/19/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/19/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/20/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/20/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/21/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/21/200/420", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/22/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/22/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/23/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/23/200/500", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/24/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/24/200/520", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/25/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/25/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/26/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/26/200/400", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/27/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/27/200/350", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/28/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/28/200/600", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/29/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/29/200/250", | |
| ), | |
| Picture( | |
| fileURL = "https://picsum.photos/id/30/720/1000", | |
| fileThumbURL = "https://picsum.photos/id/30/200/300", | |
| ), | |
| ) | |
| ) |
Main activity.java
| /* | |
| * Copyright (c) 2021 Anupgorai. | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.jesusd0897.gallerydroid.sample | |
| import android.os.Bundle | |
| import android.widget.Toast | |
| import androidx.appcompat.app.AppCompatActivity | |
| import androidx.core.content.ContextCompat | |
| import androidx.fragment.app.Fragment | |
| import androidx.fragment.app.FragmentTransaction | |
| import com.jesusd0897.gallerydroid.model.GalleryDroid | |
| import com.jesusd0897.gallerydroid.model.Picture | |
| import com.jesusd0897.gallerydroid.sample.databinding.ActivityMainBinding | |
| import com.jesusd0897.gallerydroid.view.fragment.GalleryFragment | |
| import com.jesusd0897.gallerydroid.view.fragment.OnPictureItemClickListener | |
| class MainActivity : AppCompatActivity() { | |
| private lateinit var binding: ActivityMainBinding | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| binding = ActivityMainBinding.inflate(layoutInflater) | |
| setSupportActionBar(binding.toolbar) | |
| setContentView(binding.root) | |
| supportFragmentManager.beginTransaction() | |
| .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) | |
| .replace(R.id.container, GalleryFragment.newInstance()) | |
| .commit() | |
| } | |
| override fun onAttachFragment(fragment: Fragment) { | |
| super.onAttachFragment(fragment) | |
| if (fragment is GalleryFragment) { | |
| fragment.injectGallery( | |
| GALLERY_DROID | |
| .layoutManager(GalleryDroid.LAYOUT_STAGGERED_GRID) | |
| .loadingPlaceholder( | |
| ContextCompat.getDrawable(this, R.drawable.ic_custom_loading_placeholder) | |
| ) | |
| .errorPlaceholder( | |
| ContextCompat.getDrawable(this, R.drawable.ic_custom_error_placeholder) | |
| ) | |
| .pictureCornerRadius(16f) | |
| .pictureElevation(8f) | |
| .transformer(GalleryDroid.TRANSFORMER_CUBE_OUT) | |
| .spacing(12) | |
| .portraitColumns(2) | |
| .landscapeColumns(4) | |
| .emptyTitle("Upps") | |
| .emptySubTitle(getString(R.string.no_items_found)) | |
| .emptyIcon(ContextCompat.getDrawable(this, R.drawable.ic_round_find_in_page)) | |
| .decoratorLayout(R.layout.custom_decorator) | |
| .autoClickHandler(true) | |
| .useLabels(false) | |
| ) | |
| fragment.onItemClickListener = object : OnPictureItemClickListener { | |
| override fun onClick(picture: Picture, position: Int) { | |
| Toast.makeText(this@MainActivity, "onClick = $picture", Toast.LENGTH_SHORT) | |
| .show() | |
| } | |
| override fun onLongClick(picture: Picture, position: Int) { | |
| Toast.makeText(this@MainActivity, "onLongClick = $picture", Toast.LENGTH_SHORT) | |
| .show() | |
| } | |
| } | |
| } | |
| } | |
| } |
| <?xml version="1.0" encoding="utf-8"?><!-- | |
| ~ Copyright (c) 2021 Anupgorai. | |
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | |
| ~ you may not use this file except in compliance with the License. | |
| ~ You may obtain a copy of the License at | |
| ~ http://www.apache.org/licenses/LICENSE-2.0 | |
| ~ Unless required by applicable law or agreed to in writing, software | |
| ~ distributed under the License is distributed on an "AS IS" BASIS, | |
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| ~ See the License for the specific language governing permissions and | |
| ~ limitations under the License. | |
| --> | |
| <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <com.google.android.material.appbar.AppBarLayout | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" | |
| app:liftOnScroll="true"> | |
| <com.google.android.material.appbar.MaterialToolbar | |
| android:id="@+id/toolbar" | |
| android:layout_width="match_parent" | |
| android:layout_height="?attr/actionBarSize" | |
| app:title="@string/app_name" /> | |
| </com.google.android.material.appbar.AppBarLayout> | |
| <FrameLayout | |
| android:id="@+id/container" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> | |
| </androidx.coordinatorlayout.widget.CoordinatorLayout> Sector.xml |
| <?xml version="1.0" encoding="utf-8"?><!-- | |
| ~ Copyright Anupgorai | |
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | |
| ~ you may not use this file except in compliance with the License. | |
| ~ You may obtain a copy of the License at | |
| ~ http://www.apache.org/licenses/LICENSE-2.0 | |
| ~ Unless required by applicable law or agreed to in writing, software | |
| ~ distributed under the License is distributed on an "AS IS" BASIS, | |
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| ~ See the License for the specific language governing permissions and | |
| ~ limitations under the License. | |
| --> | |
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:id="@+id/background_view" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_gravity="bottom" | |
| android:background="@drawable/gradient_bottom" | |
| android:orientation="vertical" | |
| android:padding="@dimen/dim_padding"> | |
| <TextView | |
| android:id="@+id/label_view" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:ellipsize="end" | |
| android:maxLines="2" | |
| android:textColor="@color/white" | |
| android:textStyle="bold" | |
| tools:text="@tools:sample/lorem/random" /> | |
| </LinearLayout> |
Comments
Post a Comment