Skip to content

Commit 2ed301d

Browse files
committed
Chapter 2
1 parent 5d17b1b commit 2ed301d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1138
-0
lines changed

LoginUIforTouchListener/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

LoginUIforTouchListener/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoginUIforTouchListener/.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoginUIforTouchListener/.idea/gradle.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoginUIforTouchListener/.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoginUIforTouchListener/.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoginUIforTouchListener/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.2"
8+
9+
defaultConfig {
10+
applicationId "com.merttan.loginuifortouchlistener"
11+
minSdkVersion 30
12+
targetSdkVersion 30
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.2.0'
34+
implementation 'com.google.android.material:material:1.3.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36+
testImplementation 'junit:junit:4.+'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
39+
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.merttan.loginuifortouchlistener;
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.merttan.loginuifortouchlistener", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.merttan.loginuifortouchlistener">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.LoginUIforTouchListener">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
<meta-data
20+
android:name="preloaded_fonts"
21+
android:resource="@array/preloaded_fonts" />
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.merttan.loginuifortouchlistener;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.Window;
7+
import android.view.WindowManager;
8+
import android.widget.ImageView;
9+
import android.widget.TextView;
10+
11+
public class MainActivity extends AppCompatActivity {
12+
ImageView imageView;
13+
TextView textView;
14+
int count = 0;
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
requestWindowFeature(Window.FEATURE_NO_TITLE);
20+
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
21+
setContentView(R.layout.activity_main);
22+
imageView = findViewById(R.id.imageView);
23+
textView = findViewById(R.id.textView);
24+
imageView.setOnTouchListener(new TouchListener(getApplicationContext()) {
25+
public void onSwipeTop() {
26+
}
27+
28+
public void onSwipeRight() {
29+
if (count == 0) {
30+
imageView.setImageResource(R.drawable.ninht);
31+
textView.setText("Night");
32+
count = 1;
33+
} else {
34+
imageView.setImageResource(R.drawable.morning);
35+
textView.setText("Morning");
36+
count = 0;
37+
}
38+
}
39+
40+
public void onSwipeLeft() {
41+
if (count == 0) {
42+
imageView.setImageResource(R.drawable.ninht);
43+
textView.setText("Night");
44+
count = 1;
45+
} else {
46+
imageView.setImageResource(R.drawable.morning);
47+
textView.setText("Morning");
48+
count = 0;
49+
}
50+
}
51+
52+
public void onSwipeBottom() {
53+
}
54+
55+
});
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.merttan.loginuifortouchlistener;
2+
3+
import android.content.Context;
4+
import android.view.GestureDetector;
5+
import android.view.MotionEvent;
6+
import android.view.View;
7+
8+
public class TouchListener implements View.OnTouchListener {
9+
10+
private final GestureDetector gestureDetector;
11+
12+
public TouchListener(Context ctx){
13+
gestureDetector =new GestureDetector(ctx, new GestureListener());
14+
}
15+
@Override
16+
public boolean onTouch(View v, MotionEvent event){
17+
return gestureDetector.onTouchEvent(event);
18+
}
19+
private final class GestureListener extends GestureDetector.SimpleOnGestureListener{
20+
private static final int SWIPE_THRESHOLD = 100;
21+
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
22+
23+
@Override
24+
public boolean onDown(MotionEvent e) {
25+
return true;
26+
}
27+
@Override
28+
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
29+
boolean result = false;
30+
try {
31+
float diffY = e2.getY() - e1.getY();
32+
float diffX = e2.getX() - e1.getX();
33+
if (Math.abs(diffX) > Math.abs(diffY)) {
34+
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
35+
if (diffX > 0) {
36+
onSwipeRight();
37+
} else {
38+
onSwipeLeft();
39+
}
40+
result = true;
41+
}
42+
}
43+
else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
44+
if (diffY > 0) {
45+
onSwipeBottom();
46+
} else {
47+
onSwipeTop();
48+
}
49+
result = true;
50+
}
51+
} catch (Exception exception) {
52+
exception.printStackTrace();
53+
}
54+
return result;
55+
}
56+
}
57+
58+
public void onSwipeRight() {
59+
}
60+
61+
public void onSwipeLeft() {
62+
}
63+
64+
public void onSwipeTop() {
65+
}
66+
67+
public void onSwipeBottom() {
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<shape android:shape="rectangle">
5+
<corners android:radius="8dp" />
6+
<solid android:color="@android:color/transparent"/>
7+
<stroke android:color="#96ffffff"
8+
android:width="2dp"/>
9+
</shape>
10+
</item>
11+
</selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FEFDFF"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
5+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FEFDFF"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
5+
</vector>

0 commit comments

Comments
 (0)