From 35722e6037a9de7c1ead1d3f139bd0275b3bbce4 Mon Sep 17 00:00:00 2001 From: ergashev Date: Sat, 29 Apr 2017 22:45:19 +0400 Subject: [PATCH] add touchmode --- app/build.gradle | 7 +-- app/src/main/AndroidManifest.xml | 8 ++- .../bifacialview/CustomPagerAdapter.java | 49 +++++++++++++++++++ .../com/ebr163/bifacialview/MainActivity.java | 46 +++++------------ .../ebr163/bifacialview/SimpleActivity.java | 49 +++++++++++++++++++ .../bifacialview/ViewPagerActivity.java | 20 ++++++++ app/src/main/res/layout/activity_main.xml | 36 +++++++------- app/src/main/res/layout/activity_simple.xml | 24 +++++++++ .../main/res/layout/activity_view_pager.xml | 25 ++++++++++ .../main/res/layout/content_view_pager.xml | 10 ++++ app/src/main/res/layout/page.xml | 24 +++++++++ app/src/main/res/values/dimens.xml | 3 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 9 ++++ .../bifacialview/view/BifacialView.java | 26 ++++++++-- .../bifacialview/view/utils/BitmapUtils.java | 36 -------------- library/src/main/res/values/attrs.xml | 5 ++ 17 files changed, 281 insertions(+), 97 deletions(-) create mode 100644 app/src/main/java/com/ebr163/bifacialview/CustomPagerAdapter.java create mode 100644 app/src/main/java/com/ebr163/bifacialview/SimpleActivity.java create mode 100644 app/src/main/java/com/ebr163/bifacialview/ViewPagerActivity.java create mode 100644 app/src/main/res/layout/activity_simple.xml create mode 100644 app/src/main/res/layout/activity_view_pager.xml create mode 100644 app/src/main/res/layout/content_view_pager.xml create mode 100644 app/src/main/res/layout/page.xml create mode 100644 app/src/main/res/values/dimens.xml diff --git a/app/build.gradle b/app/build.gradle index dacdc61..fbac01e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,10 +24,11 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.android.support.constraint:constraint-layout:1.0.2' - testCompile 'junit:junit:4.12' compile project(":library") + compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.github.bumptech.glide:glide:3.7.0' + compile 'com.android.support:design:25.3.1' + testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5f11398..c7a6d74 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,7 @@ - - + + + \ No newline at end of file diff --git a/app/src/main/java/com/ebr163/bifacialview/CustomPagerAdapter.java b/app/src/main/java/com/ebr163/bifacialview/CustomPagerAdapter.java new file mode 100644 index 0000000..dcbcd82 --- /dev/null +++ b/app/src/main/java/com/ebr163/bifacialview/CustomPagerAdapter.java @@ -0,0 +1,49 @@ +package com.ebr163.bifacialview; + +import android.content.Context; +import android.support.v4.view.PagerAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * Created by ergashev on 29.04.17. + */ + +public class CustomPagerAdapter extends PagerAdapter { + + private Context mContext; + + public CustomPagerAdapter(Context context) { + mContext = context; + } + + @Override + public Object instantiateItem(ViewGroup collection, int position) { + LayoutInflater inflater = LayoutInflater.from(mContext); + ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.page, collection, false); + collection.addView(layout); + return layout; + } + + @Override + public void destroyItem(ViewGroup collection, int position, Object view) { + collection.removeView((View) view); + } + + @Override + public int getCount() { + return 3; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + + @Override + public CharSequence getPageTitle(int position) { + return "Title"; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/ebr163/bifacialview/MainActivity.java b/app/src/main/java/com/ebr163/bifacialview/MainActivity.java index 72cc8b9..efac513 100644 --- a/app/src/main/java/com/ebr163/bifacialview/MainActivity.java +++ b/app/src/main/java/com/ebr163/bifacialview/MainActivity.java @@ -1,49 +1,25 @@ package com.ebr163.bifacialview; +import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; -import com.ebr163.bifacialview.view.BifacialView; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - final BifacialView view = (BifacialView) findViewById(R.id.view); - Glide.with(this) - .load("https://files4.adme.ru/files/news/part_149/1494765/29530665-262592-3-0-1491487588-1491487592-650-bf845cd25e-1491558012.jpg") - .listener(new RequestListener() { - @Override - public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { - return false; - } - - @Override - public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { - view.setDrawableLeft(resource); - return false; - } - }).preload(); - - Glide.with(this) - .load("https://files3.adme.ru/files/news/part_149/1494765/29530265-262592-33-0-1491489159-1491489163-650-8edb1df01d-1491558012.jpg") - .listener(new RequestListener() { - @Override - public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { - return false; - } + } - @Override - public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { - view.setDrawableRight(resource); - return false; - } - }).preload(); + @Override + public void onClick(View v) { + if (v.getId() == R.id.simple_screen) { + startActivity(new Intent(this, SimpleActivity.class)); + } else { + startActivity(new Intent(this, ViewPagerActivity.class)); + } } } diff --git a/app/src/main/java/com/ebr163/bifacialview/SimpleActivity.java b/app/src/main/java/com/ebr163/bifacialview/SimpleActivity.java new file mode 100644 index 0000000..4fa9a8d --- /dev/null +++ b/app/src/main/java/com/ebr163/bifacialview/SimpleActivity.java @@ -0,0 +1,49 @@ +package com.ebr163.bifacialview; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.Target; +import com.ebr163.bifacialview.view.BifacialView; + +public class SimpleActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_simple); + final BifacialView view = (BifacialView) findViewById(R.id.view); + Glide.with(this) + .load("https://files4.adme.ru/files/news/part_149/1494765/29530665-262592-3-0-1491487588-1491487592-650-bf845cd25e-1491558012.jpg") + .listener(new RequestListener() { + @Override + public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + view.setDrawableRight(resource); + return false; + } + }).preload(); + + Glide.with(this) + .load("https://files3.adme.ru/files/news/part_149/1494765/29530265-262592-33-0-1491489159-1491489163-650-8edb1df01d-1491558012.jpg") + .listener(new RequestListener() { + @Override + public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + view.setDrawableLeft(resource); + return false; + } + }).preload(); + } +} diff --git a/app/src/main/java/com/ebr163/bifacialview/ViewPagerActivity.java b/app/src/main/java/com/ebr163/bifacialview/ViewPagerActivity.java new file mode 100644 index 0000000..db81e37 --- /dev/null +++ b/app/src/main/java/com/ebr163/bifacialview/ViewPagerActivity.java @@ -0,0 +1,20 @@ +package com.ebr163.bifacialview; + +import android.os.Bundle; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; + +public class ViewPagerActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_view_pager); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + ViewPager view = (ViewPager) findViewById(R.id.viewpager); + view.setAdapter(new CustomPagerAdapter(this)); + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6678b79..ec2940c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,22 +1,22 @@ - + android:orientation="vertical"> - +