Skip to content

Commit

Permalink
EasyFlipableView
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalsonic committed Oct 16, 2024
1 parent 49e76eb commit 026a1d3
Show file tree
Hide file tree
Showing 28 changed files with 1,220 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2020 Hypersoft

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.
5 changes: 5 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Apache CustomBadge
Copyright 2020 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
47 changes: 47 additions & 0 deletions app/src/main/java/com/hypersoft/flipableview/FlipOnceActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.hypersoft.flipableview

import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.hypersoft.easyviewflip.EasyViewFlip
import com.hypersoft.flipableview.databinding.ActivityFlipOnceBinding

class FlipOnceActivity : AppCompatActivity() {

private var binding: ActivityFlipOnceBinding? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityFlipOnceBinding.inflate(layoutInflater)
setContentView(binding?.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

binding?.apply {
cardFlipView.setFlipDuration(1000)
cardFlipView.setFlipEnabled(true)
kingBackSide.setOnClickListener { cardFlipView.flipTheView() }
kingFrontSide.setOnClickListener { cardFlipView.flipTheView() }

cardFlipView.setOnFlipListener(object : EasyViewFlip.OnFlipAnimationListener{
override fun onViewFlipCompleted(
easyFlipView: EasyViewFlip?,
newCurrentSide: EasyViewFlip.FlipState?
) {
Toast.makeText(
this@FlipOnceActivity,
"Flipped once ! Ace revealed $newCurrentSide", Toast.LENGTH_LONG
).show()
}
})
}

}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/hypersoft/flipableview/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.hypersoft.flipableview

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.hypersoft.flipableview.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private var binding: ActivityMainBinding? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding?.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

binding?.apply {
mbSimpleView.setOnClickListener { startActivity(Intent(this@MainActivity, SimpleViewActivity::class.java))}
mbRecyclerView.setOnClickListener { startActivity(Intent(this@MainActivity, RecyclerViewActivity::class.java)) }
mbFlipOnceExample.setOnClickListener { startActivity(Intent(this@MainActivity, FlipOnceActivity::class.java)) }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hypersoft.flipableview

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.hypersoft.flipableview.databinding.ActivityRecyclerViewBinding

class RecyclerViewActivity : AppCompatActivity() {

private var binding: ActivityRecyclerViewBinding? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityRecyclerViewBinding.inflate(layoutInflater)
setContentView(binding?.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
// val list: List<TestModel> = ArrayList()
val list = mutableListOf<TestModel>()
binding?.apply {
recyclerView.layoutManager = GridLayoutManager(this@RecyclerViewActivity, 2)

for (i in 0..19) {
val model = TestModel()
model.isFlipped = false
list.add(model)
}

recyclerView.adapter = SampleAdapter(list)

}
}
}
46 changes: 46 additions & 0 deletions app/src/main/java/com/hypersoft/flipableview/SampleAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hypersoft.flipableview

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.hypersoft.easyviewflip.EasyViewFlip
import com.hypersoft.flipableview.databinding.ItemRecyclerviewBinding

class SampleAdapter(): RecyclerView.Adapter<SampleAdapter.CustomViewHolder>() {

private lateinit var list: List<TestModel>

constructor(list: List<TestModel>): this() {
this.list = list
}

inner class CustomViewHolder(val binding: ItemRecyclerviewBinding): RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = ItemRecyclerviewBinding.inflate(layoutInflater, parent, false)
return CustomViewHolder(binding)
}

override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
holder.binding.apply {
if (flipView.getCurrentFlipState() == EasyViewFlip.FlipState.FRONT_SIDE && list[position].isFlipped) {
flipView.setFlipDuration(0)
flipView.flipTheView()
} else if (flipView.getCurrentFlipState() == EasyViewFlip.FlipState.BACK_SIDE && !list[position].isFlipped) {
flipView.setFlipDuration(0)
flipView.flipTheView()
}

flipView.setOnClickListener {
list[position].isFlipped = !list[position].isFlipped
flipView.setFlipDuration(700)
flipView.flipTheView()
}
}
}

override fun getItemCount(): Int {
return list.size
}
}
48 changes: 48 additions & 0 deletions app/src/main/java/com/hypersoft/flipableview/SimpleViewActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.hypersoft.flipableview

import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.hypersoft.easyviewflip.EasyViewFlip
import com.hypersoft.flipableview.databinding.ActivitySimpleViewBinding

class SimpleViewActivity : AppCompatActivity() {

private var binding: ActivitySimpleViewBinding? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivitySimpleViewBinding.inflate(layoutInflater)
setContentView(binding?.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

binding?.apply {
easyFlipView.setFlipDuration(1000)
easyFlipView.setFlipEnabled(true)
imgFrontCard.setOnClickListener { easyFlipView.flipTheView() }
imgBackCard.setOnClickListener { easyFlipView.flipTheView() }

easyFlipView2.setFlipDuration(5000)
easyFlipView2.setToHorizontalType()
easyFlipView2.setFlipTypeFromLeft()

easyFlipView.setOnFlipListener(object: EasyViewFlip.OnFlipAnimationListener {
override fun onViewFlipCompleted(
easyFlipView: EasyViewFlip?,
newCurrentSide: EasyViewFlip.FlipState?
) {
Toast.makeText(this@SimpleViewActivity,
"Flip Completed! New Side is: " + newCurrentSide, Toast.LENGTH_LONG).show()
}
})
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/hypersoft/flipableview/TestModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.hypersoft.flipableview

class TestModel {
var isFlipped: Boolean = false
}
1 change: 1 addition & 0 deletions flipableview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions flipableview/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
id("maven-publish")
}

android {
namespace = "com.hypersoft.easyviewflip"
compileSdk = 34

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}

}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
}

publishing {
publications {
create<MavenPublication>("release") {
groupId = "com.hypersoft.easyviewflip"
artifactId = "easyviewflip"
version = "1.0.1"

afterEvaluate {
from(components["release"])
}
}
}
}
Empty file added flipableview/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions flipableview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions flipableview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Loading

0 comments on commit 026a1d3

Please sign in to comment.