app seed
5
aplication/.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
19
aplication/.idea/gradle.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
7
aplication/.idea/kotlinCodeInsightSettings.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinCodeInsightWorkspaceSettings">
|
||||
<option name="addUnambiguousImportsOnTheFly" value="true" />
|
||||
<option name="optimizeImportsOnTheFly" value="true" />
|
||||
</component>
|
||||
</project>
|
6
aplication/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,4 @@
|
||||
package com.example.foodinder;
|
||||
|
||||
public class CardItem {
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.example.foodinder
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
||||
class CardsAdapter(private val activity: Activity, private val data: List<CardItem>) :
|
||||
BaseAdapter() {
|
||||
override fun getCount(): Int {
|
||||
return data.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): CardItem {
|
||||
return data[position]
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return position.toLong()
|
||||
}
|
||||
|
||||
override fun getView(
|
||||
position: Int,
|
||||
convertView: View,
|
||||
parent: ViewGroup
|
||||
): View {
|
||||
var convertView = convertView
|
||||
val holder: ViewHolder
|
||||
val inflater =
|
||||
activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
// If holder not exist then locate all view from UI file.
|
||||
if (convertView == null) { // inflate UI from XML file
|
||||
convertView = inflater.inflate(R.layout.item_card, parent, false)
|
||||
// get all UI view
|
||||
holder = ViewHolder(convertView)
|
||||
// set tag for holder
|
||||
convertView.tag = holder
|
||||
} else { // if holder created, get tag from view
|
||||
holder = convertView.tag as ViewHolder
|
||||
}
|
||||
//setting data to views
|
||||
holder.name.text = getItem(position).name
|
||||
holder.location.text = getItem(position).location
|
||||
holder.avatar.setImageBitmap(
|
||||
decodeSampledBitmapFromResource(
|
||||
activity.resources,
|
||||
getItem(position).drawableId,
|
||||
AVATAR_WIDTH,
|
||||
AVATAR_HEIGHT
|
||||
)
|
||||
)
|
||||
return convertView
|
||||
}
|
||||
|
||||
private inner class ViewHolder(view: View) {
|
||||
val avatar: ImageView
|
||||
val name: TextView
|
||||
val location: TextView
|
||||
|
||||
init {
|
||||
avatar = view.findViewById<View>(R.id.avatar) as ImageView
|
||||
name = view.findViewById<View>(R.id.name) as TextView
|
||||
location = view.findViewById<View>(R.id.location) as TextView
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val AVATAR_WIDTH = 150
|
||||
private const val AVATAR_HEIGHT = 300
|
||||
fun decodeSampledBitmapFromResource(
|
||||
res: Resources?,
|
||||
resId: Int,
|
||||
reqWidth: Int,
|
||||
reqHeight: Int
|
||||
): Bitmap { // First decode with inJustDecodeBounds=true to check dimensions
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeResource(res, resId, options)
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize =
|
||||
calculateInSampleSize(options, reqWidth, reqHeight)
|
||||
// Decode bitmap with inSampleSize set
|
||||
options.inJustDecodeBounds = false
|
||||
return BitmapFactory.decodeResource(res, resId, options)
|
||||
}
|
||||
|
||||
fun calculateInSampleSize(
|
||||
options: BitmapFactory.Options,
|
||||
reqWidth: Int,
|
||||
reqHeight: Int
|
||||
): Int { // Raw height and width of image
|
||||
val height = options.outHeight
|
||||
val width = options.outWidth
|
||||
var inSampleSize = 1
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
val halfHeight = height / 2
|
||||
val halfWidth = width / 2
|
||||
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
|
||||
// height and width larger than the requested height and width.
|
||||
while (halfHeight / inSampleSize >= reqHeight
|
||||
&& halfWidth / inSampleSize >= reqWidth
|
||||
) {
|
||||
inSampleSize *= 2
|
||||
}
|
||||
}
|
||||
return inSampleSize
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package info.devexchanges.cardsstack;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import link.fls.swipestack.SwipeStack;
|
||||
|
||||
public class swipper extends AppCompatActivity {
|
||||
|
||||
private SwipeStack cardStack;
|
||||
private CardsAdapter cardsAdapter;
|
||||
private ArrayList<CardItem> cardItems;
|
||||
private View btnCancel;
|
||||
private View btnLove;
|
||||
private int currentPosition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
cardStack = (SwipeStack) findViewById(R.id.container);
|
||||
btnCancel = findViewById(R.id.cancel);
|
||||
btnLove = findViewById(R.id.love);
|
||||
|
||||
setCardStackAdapter();
|
||||
currentPosition = 0;
|
||||
|
||||
//Handling swipe event of Cards stack
|
||||
cardStack.setListener(new SwipeStack.SwipeStackListener() {
|
||||
@Override
|
||||
public void onViewSwipedToLeft(int position) {
|
||||
currentPosition = position + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewSwipedToRight(int position) {
|
||||
currentPosition = position + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackEmpty() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cardStack.swipeTopViewToRight();
|
||||
}
|
||||
});
|
||||
|
||||
btnLove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(swipper.this, "You liked " + cardItems.get(currentPosition).getName(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
cardStack.swipeTopViewToLeft();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setCardStackAdapter() {
|
||||
cardItems = new ArrayList<>();
|
||||
|
||||
cardItems.add(new CardItem(R.drawable.a, "Huyen My", "Hanoi"));
|
||||
cardItems.add(new CardItem(R.drawable.f, "Do Ha", "Nghe An"));
|
||||
cardItems.add(new CardItem(R.drawable.g, "Dong Nhi", "Hue"));
|
||||
cardItems.add(new CardItem(R.drawable.e, "Le Quyen", "Sai Gon"));
|
||||
cardItems.add(new CardItem(R.drawable.c, "Phuong Linh", "Thanh Hoa"));
|
||||
cardItems.add(new CardItem(R.drawable.d, "Phuong Vy", "Hanoi"));
|
||||
cardItems.add(new CardItem(R.drawable.b, "Ha Ho", "Da Nang"));
|
||||
|
||||
cardsAdapter = new CardsAdapter(this, cardItems);
|
||||
cardStack.setAdapter(cardsAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.reset) {
|
||||
cardStack.resetStack();
|
||||
currentPosition = 0;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
BIN
aplication/app/src/main/res/drawable-v24/a.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
aplication/app/src/main/res/drawable-v24/b.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
aplication/app/src/main/res/drawable-v24/c.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
aplication/app/src/main/res/drawable-v24/d.jpg
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
aplication/app/src/main/res/drawable-v24/e.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
aplication/app/src/main/res/drawable-v24/f.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
aplication/app/src/main/res/drawable-v24/g.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
aplication/app/src/main/res/drawable-v24/h.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
aplication/app/src/main/res/drawable-v24/i.jpg
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
aplication/app/src/main/res/drawable-v24/j.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
aplication/app/src/main/res/drawable-v24/k.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
aplication/app/src/main/res/drawable-v24/l.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
aplication/app/src/main/res/drawable-v24/m.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
aplication/app/src/main/res/drawable-v24/n.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
aplication/app/src/main/res/drawable-v24/o.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
aplication/app/src/main/res/drawable-v24/p.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
aplication/app/src/main/res/drawable-v24/r.jpg
Normal file
After Width: | Height: | Size: 10 KiB |
9
aplication/app/src/main/res/layout/activity_swipper.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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=".swipper">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
6
aplication/app/src/main/res/layout/item_card.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</LinearLayout>
|
4
aplication/app/src/main/res/menu/menu_main.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</menu>
|
5
aplication/app/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
14
foodinder_app/.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
116
foodinder_app/.idea/codeStyles/Project.xml
Normal file
@ -0,0 +1,116 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
19
foodinder_app/.idea/gradle.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
9
foodinder_app/.idea/misc.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
12
foodinder_app/.idea/runConfigurations.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
foodinder_app/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
foodinder_app/app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
41
foodinder_app/app/build.gradle
Normal file
@ -0,0 +1,41 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion "28.0.3"
|
||||
defaultConfig {
|
||||
applicationId "com.example.foodinder_app"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'link.fls:swipestack:0.3.0'
|
||||
implementation 'com.android.support:appcompat-v7:25.0.0'
|
||||
implementation 'com.android.support:cardview-v7:25.0.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
}
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://maven.google.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
BIN
foodinder_app/app/libs/android-card-stack-0.1.5.aar
Normal file
21
foodinder_app/app/proguard-rules.pro
vendored
Normal file
@ -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
|
21
foodinder_app/app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.foodinder_app">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".Main2Activity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".swipper">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,34 @@
|
||||
package com.example.foodinder_app;
|
||||
|
||||
public class CardItem {
|
||||
|
||||
private int drawableId;
|
||||
private String name;
|
||||
private String location;
|
||||
|
||||
public CardItem(int drawableId, String name, String location) {
|
||||
this.drawableId = drawableId;
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getDrawableId() {
|
||||
return drawableId;
|
||||
}
|
||||
|
||||
public void setDrawableId(int drawableId) {
|
||||
this.drawableId = drawableId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.example.foodinder_app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CardsAdapter extends BaseAdapter {
|
||||
|
||||
private Activity activity;
|
||||
private final static int AVATAR_WIDTH = 150;
|
||||
private final static int AVATAR_HEIGHT = 300;
|
||||
private List<CardItem> data;
|
||||
|
||||
public CardsAdapter(Activity activity, List<CardItem> data) {
|
||||
this.data = data;
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardItem getItem(int position) {
|
||||
return data.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||
// If holder not exist then locate all view from UI file.
|
||||
if (convertView == null) {
|
||||
// inflate UI from XML file
|
||||
convertView = inflater.inflate(R.layout.item_card, parent, false);
|
||||
// get all UI view
|
||||
holder = new ViewHolder(convertView);
|
||||
// set tag for holder
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
// if holder created, get tag from view
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
//setting data to views
|
||||
holder.name.setText(getItem(position).getName());
|
||||
holder.location.setText(getItem(position).getLocation());
|
||||
holder.avatar.setImageBitmap(decodeSampledBitmapFromResource(activity.getResources(),
|
||||
getItem(position).getDrawableId(), AVATAR_WIDTH, AVATAR_HEIGHT));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder{
|
||||
private ImageView avatar;
|
||||
private TextView name;
|
||||
private TextView location;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
avatar = (ImageView)view.findViewById(R.id.avatar);
|
||||
name = (TextView)view.findViewById(R.id.name);
|
||||
location = (TextView)view.findViewById(R.id.location);
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
|
||||
|
||||
// First decode with inJustDecodeBounds=true to check dimensions
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeResource(res, resId, options);
|
||||
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
|
||||
|
||||
// Decode bitmap with inSampleSize set
|
||||
options.inJustDecodeBounds = false;
|
||||
return BitmapFactory.decodeResource(res, resId, options);
|
||||
}
|
||||
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
// Raw height and width of image
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
|
||||
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
|
||||
// height and width larger than the requested height and width.
|
||||
while ((halfHeight / inSampleSize) >= reqHeight
|
||||
&& (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.example.foodinder_app;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
public class Main2Activity extends AppCompatActivity {
|
||||
|
||||
private View button;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main2);
|
||||
|
||||
button = findViewById(R.id.button);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent intent = new Intent(Main2Activity.this, swipper.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.example.foodinder_app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import link.fls.swipestack.SwipeStack;
|
||||
|
||||
public class swipper extends AppCompatActivity {
|
||||
|
||||
private SwipeStack cardStack;
|
||||
private CardsAdapter cardsAdapter;
|
||||
private ArrayList<CardItem> cardItems;
|
||||
private View btnCancel;
|
||||
private View btnLove;
|
||||
private int currentPosition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
cardStack = (SwipeStack) findViewById(R.id.container);
|
||||
btnCancel = findViewById(R.id.cancel);
|
||||
btnLove = findViewById(R.id.love);
|
||||
|
||||
setCardStackAdapter();
|
||||
currentPosition = 0;
|
||||
|
||||
//Handling swipe event of Cards stack
|
||||
cardStack.setListener(new SwipeStack.SwipeStackListener() {
|
||||
@Override
|
||||
public void onViewSwipedToLeft(int position) {
|
||||
|
||||
Toast.makeText(swipper.this, "You liked " + cardItems.get(currentPosition).getName(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
currentPosition = position + 1;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewSwipedToRight(int position) {
|
||||
|
||||
Toast.makeText(swipper.this, "You DON'T liked " + cardItems.get(currentPosition).getName(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
currentPosition = position + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackEmpty() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cardStack.swipeTopViewToRight();
|
||||
}
|
||||
});
|
||||
|
||||
btnLove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cardStack.swipeTopViewToLeft();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setCardStackAdapter() {
|
||||
cardItems = new ArrayList<>();
|
||||
|
||||
cardItems.add(new CardItem(R.drawable.a, "JedzenieA", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.b, "JedzenieB", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.c, "JedzenieC", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.d, "JedzenieD", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.e, "JedzenieE", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.f, "JedzenieF", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.g, "JedzenieG", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.h, "JedzenieH", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.i, "JedzenieI", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.j, "JedzenieJ", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.k, "JedzenieK", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.l, "JedzenieL", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.m, "JedzenieM", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.n, "JedzenieN", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.o, "JedzenieO", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.p, "JedzenieP", "Jedzenie"));
|
||||
cardItems.add(new CardItem(R.drawable.r, "JedzenieR", "Jedzenie"));
|
||||
|
||||
|
||||
cardsAdapter = new CardsAdapter(this, cardItems);
|
||||
cardStack.setAdapter(cardsAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.reset) {
|
||||
cardStack.resetStack();
|
||||
currentPosition = 0;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
BIN
foodinder_app/app/src/main/res/drawable/a.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
foodinder_app/app/src/main/res/drawable/b.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
foodinder_app/app/src/main/res/drawable/c.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
foodinder_app/app/src/main/res/drawable/d.jpg
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
foodinder_app/app/src/main/res/drawable/e.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
foodinder_app/app/src/main/res/drawable/f.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
foodinder_app/app/src/main/res/drawable/g.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
foodinder_app/app/src/main/res/drawable/h.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
foodinder_app/app/src/main/res/drawable/i.jpg
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
foodinder_app/app/src/main/res/drawable/j.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
foodinder_app/app/src/main/res/drawable/k.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
foodinder_app/app/src/main/res/drawable/l.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
foodinder_app/app/src/main/res/drawable/m.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
foodinder_app/app/src/main/res/drawable/n.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
foodinder_app/app/src/main/res/drawable/o.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
foodinder_app/app/src/main/res/drawable/p.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
foodinder_app/app/src/main/res/drawable/r.jpg
Normal file
After Width: | Height: | Size: 10 KiB |
50
foodinder_app/app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:weightSum="1">
|
||||
|
||||
<link.fls.swipestack.SwipeStack
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="500dp"
|
||||
app:stack_rotation="0" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/love"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toRightOf="@id/empty"
|
||||
android:contentDescription="@null"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_toLeftOf="@id/empty"
|
||||
android:contentDescription="@null"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
19
foodinder_app/app/src/main/res/layout/activity_main2.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout 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=".Main2Activity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="New Activity Click"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
50
foodinder_app/app/src/main/res/layout/item_card.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
android:background="@android:color/white"
|
||||
android:orientation="vertical"
|
||||
app:cardCornerRadius="7dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="350dp"
|
||||
android:layout_marginBottom="75dp"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="75dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="center|left"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/colorPrimaryDark"
|
||||
android:textSize="18dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/location"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/colorPrimaryDark"
|
||||
android:textSize="14dp"
|
||||
android:textStyle="normal" />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</FrameLayout>
|
9
foodinder_app/app/src/main/res/menu/menu_main.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<menu 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"
|
||||
tools:context=".MyActivity">
|
||||
<item
|
||||
android:id="@+id/reset"
|
||||
android:title="Reset"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
BIN
foodinder_app/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
foodinder_app/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
foodinder_app/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
foodinder_app/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
foodinder_app/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 10 KiB |
6
foodinder_app/app/src/main/res/values-w820dp/dimens.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
6
foodinder_app/app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#FF0000</color>
|
||||
<color name="colorPrimaryDark">#FF0000</color>
|
||||
<color name="colorAccent">#FF0000</color>
|
||||
</resources>
|
5
foodinder_app/app/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|