├── TextAndGraphics ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── dimens.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── load_error.jpg │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── anim │ │ │ │ │ ├── fading_in.xml │ │ │ │ │ └── fading_out.xml │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ └── layout │ │ │ │ │ ├── item_pager_image.xml │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ └── activity_imagepager.xml │ │ │ ├── assets │ │ │ │ ├── local_picture1.png │ │ │ │ └── local_picture2.png │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── linchuan │ │ │ │ └── textandgraphics │ │ │ │ ├── MainActivity.java │ │ │ │ ├── ImageViewPager │ │ │ │ ├── HackyViewPager.java │ │ │ │ └── ImagePagerActivity.java │ │ │ │ ├── DataUtil.java │ │ │ │ └── TextAndGraphicsView.java │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── linchuan │ │ │ │ └── textandgraphics │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── linchuan │ │ │ └── textandgraphics │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── settings.gradle ├── .idea │ ├── copyright │ │ └── profiles_settings.xml │ ├── vcs.xml │ ├── modules.xml │ ├── runConfigurations.xml │ ├── gradle.xml │ ├── compiler.xml │ └── misc.xml ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradlew.bat └── gradlew ├── .gitattributes ├── .gitignore └── README.md /TextAndGraphics/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TextAndGraphics/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TextAndGraphics 3 | 4 | -------------------------------------------------------------------------------- /TextAndGraphics/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/assets/local_picture1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/assets/local_picture1.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/assets/local_picture2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/assets/local_picture2.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-hdpi/load_error.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-hdpi/load_error.jpg -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinleyLC/TextAndGraphics/HEAD/TextAndGraphics/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /TextAndGraphics/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/anim/fading_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/anim/fading_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /TextAndGraphics/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #000000 7 | 8 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6dp 6 | 6dp 7 | 8 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/test/java/com/linchuan/textandgraphics/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/layout/item_pager_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 14 | -------------------------------------------------------------------------------- /TextAndGraphics/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /TextAndGraphics/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\adt-bundle-windows-x86_64_20140101\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TextAndGraphics/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /TextAndGraphics/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "com.linchuan.textandgraphics" 8 | minSdkVersion 14 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.github.bumptech.glide:glide:3.7.0' 25 | compile 'com.commit451:PhotoView:1.2.4' 26 | compile 'com.android.support:appcompat-v7:23.4.0' 27 | } 28 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/res/layout/activity_imagepager.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 21 | 22 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/androidTest/java/com/linchuan/textandgraphics/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.linchuan.textandgraphics", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/java/com/linchuan/textandgraphics/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.ScrollView; 6 | 7 | /** 8 | * 主页 9 | * Created by 林川 on 2016/12/6. 10 | */ 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | private ScrollView sv_main; 14 | private String[] mData;//图文数据的列表 15 | private TextAndGraphicsView mTextAndGraphicsView; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | parseData();//解析数据 23 | initView();//初始化ui 24 | } 25 | 26 | private void parseData() { 27 | //根据分割线来把文字和图片地址存入数组中 28 | mData = DataUtil.getData().split(DataUtil.SPLIT_TAG); 29 | } 30 | 31 | private void initView() { 32 | sv_main = (ScrollView) findViewById(R.id.sv_main); 33 | mTextAndGraphicsView = new TextAndGraphicsView(this,mData); 34 | sv_main.addView(mTextAndGraphicsView); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/java/com/linchuan/textandgraphics/ImageViewPager/HackyViewPager.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics.ImageViewPager; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | 8 | /** 9 | * Found at http://stackoverflow.com/questions/7814017/is-it-possible-to-disable-scrolling-on-a-viewpager. 10 | * Convenient way to temporarily disable ViewPager navigation while interacting with ImageView. 11 | * 12 | * Julia Zudikova 13 | */ 14 | 15 | /** 16 | * Hacky fix for Issue #4 and 17 | * http://code.google.com/p/android/issues/detail?id=18990 18 | *

19 | * ScaleGestureDetector seems to mess up the touch events, which means that 20 | * ViewGroups which make use of onInterceptTouchEvent throw a lot of 21 | * IllegalArgumentException: pointerIndex out of range. 22 | *

23 | * There's not much I can do in my code for now, but we can mask the result by 24 | * just catching the problem and ignoring it. 25 | * 26 | * @author Chris Banes 27 | */ 28 | public class HackyViewPager extends ViewPager { 29 | 30 | private boolean isLocked; 31 | 32 | public HackyViewPager(Context context) { 33 | super(context); 34 | isLocked = false; 35 | } 36 | 37 | public HackyViewPager(Context context, AttributeSet attrs) { 38 | super(context, attrs); 39 | isLocked = false; 40 | } 41 | 42 | @Override 43 | public boolean onInterceptTouchEvent(MotionEvent ev) { 44 | if (!isLocked) { 45 | try { 46 | return super.onInterceptTouchEvent(ev); 47 | } catch (IllegalArgumentException e) { 48 | //e.printStackTrace(); 49 | return false; 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | @Override 56 | public boolean onTouchEvent(MotionEvent event) { 57 | return !isLocked && super.onTouchEvent(event); 58 | } 59 | 60 | 61 | 62 | public void toggleLock() { 63 | isLocked = !isLocked; 64 | } 65 | 66 | public void setLocked(boolean isLocked) { 67 | this.isLocked = isLocked; 68 | } 69 | 70 | public boolean isLocked() { 71 | return isLocked; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/java/com/linchuan/textandgraphics/DataUtil.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics; 2 | 3 | /**图文的数据工具类 4 | * Created by 林川 on 2016/12/6. 5 | */ 6 | 7 | public class DataUtil { 8 | 9 | public static final String TEXT_TAG = "[#TEXT#]";//文字标识 10 | public static final String IMAGE_NET_TAG = "[#IMAGE_NET#]";//网络图片标识 11 | public static final String IMAGE_LOCAL_TAG = "[#IMAGE_LOCAL#]";//本地图片标识(assets目录下) 12 | public static final String SPLIT_TAG = "\\[\\#SPLIT\\#\\]";//分割处标识 13 | 14 | /** 15 | * 获取图文的数据,这些数据可以从服务端取,或者写在本地的某个文件也可以 16 | * @return 图文数据 17 | */ 18 | public static String getData(){ 19 | //格式:文字开头用TEXT_TAG标识,网络图片地址用IMAGE_NET_TAG标识,本地图片用IMAGE_LOCAL_TAG标识,每两个标识内容之间要用SPLIT_TAG分隔 20 | String content = 21 | "[#TEXT#]2016是VR年,各路巨头都积极布局VR,科技老大哥谷歌的发力当然不容小觑谷歌5月份推出了移动VR平台Daydream,10月份又推出了该平台的硬件新品Daydream View头戴,至于最后谷歌能否在“大鱼小虾混战”的行业现状下实现像安卓一样的大一统,就不得而知了。" 22 | +"[#SPLIT#]" 23 | +"[#IMAGE_NET#]http://imgsrc.baidu.com/forum/w%3D580/sign=57d48f1b5edf8db1bc2e7c6c3922dddb/064c05f3d7ca7bcb01f249acbe096b63f724a86e.jpg" 24 | +"[#SPLIT#]" 25 | +"[#TEXT#]Daydream View这款头显使用了尼龙材质的两点式松紧头带,佩戴舒服,让用户不需要频繁调整头戴;它拥有NFC芯片,手机一刷就能进入VR模式,同时还有自动图像校准系统,不需要用户去进行多余的设置调整;\n 另外,它拥有配套的控制器手柄,可以用控制器来进行交互式游戏和操作,不需要频繁通过头部进行交互。" 26 | +"[#SPLIT#]" 27 | +"[#IMAGE_NET#]http://p4.so.qhmsg.com/bdr/_240_/t01284c1252d9bb3f59.jpg" 28 | +"[#SPLIT#]" 29 | +"[#TEXT#]从今天开始,谷歌Daydream View头显将会推出两种新的颜色:深红色和雪白色。现在用户已经可以通过谷歌的在线商店购买到这两种颜色,售价跟岩灰色头显一样是79美元,发货日期为12月8日。不知道三种颜色哪种才是你的所爱呢?" 30 | +"[#SPLIT#]" 31 | +"[#IMAGE_NET#]http://p2.so.qhmsg.com/bdr/_240_/t01ffcdaedde9bcb74c.jpg" 32 | +"[#SPLIT#]" 33 | +"[#TEXT#]网易科技讯12月6日消息,据外媒报道,谷歌正式推出搭载Android7.1.操作系统的Pixel手机新品,Nougat系统也进行了相应的更新。谷歌同时宣布Android7.1.1系统已经开始推广到其他Android手机,为广大用户提供更多新功能。这些即将运行最新版本Android系统的手机包括Nexus 6,Nexus 5X,Nexus 6P,Nexus 9,Pixel,Pixel XL,Nexus Player,Pixel C和General Mobile 4G(Android One)。" 34 | +"[#SPLIT#]" 35 | +"[#TEXT#]程序员的日常" 36 | +"[#SPLIT#]" 37 | +"[#IMAGE_LOCAL#]file:///android_asset/local_picture1.png" 38 | +"[#SPLIT#]" 39 | +"[#IMAGE_LOCAL#]file:///android_asset/local_picture2.png" 40 | +"[#SPLIT#]" 41 | +"[#TEXT#]程序员的日常扫码"; 42 | 43 | return content; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /TextAndGraphics/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /TextAndGraphics/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TextAndGraphics 2 | 好用的图文混排框架,仿新闻页面。只需简单配置就能实现页面布局,支持网络图片和本地图片 3 | 4 | ![textandgraphics4](https://cloud.githubusercontent.com/assets/18639409/20962076/cea2c8ec-bca2-11e6-91e4-720812951163.gif) 5 | 6 | ##使用方式 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | private ScrollView sv_main;//TextAndGraphicsView的父控件必须是ScrollView 11 | private String[] mData;//图文数据的列表 12 | private TextAndGraphicsView mTextAndGraphicsView; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | 19 | parseData();//解析数据 20 | initView();//初始化ui 21 | } 22 | 23 | private void parseData() { 24 | //根据分割线来把文字和图片地址存入数组中 25 | mData = DataUtil.getData().split(DataUtil.SPLIT_TAG); 26 | } 27 | 28 | private void initView() { 29 | sv_main = (ScrollView) findViewById(R.id.sv_main); 30 | mTextAndGraphicsView = new TextAndGraphicsView(this,mData); 31 | sv_main.addView(mTextAndGraphicsView); 32 | } 33 | } 34 | 35 | ##主页布局 36 | 37 | 43 | 44 | 50 | 51 | 52 | 53 | ##图文数据格式 54 | 55 | public class DataUtil { 56 | 57 | public static final String TEXT_TAG = "[#TEXT#]";//文字标识 58 | public static final String IMAGE_NET_TAG = "[#IMAGE_NET#]";//网络图片标识 59 | public static final String IMAGE_LOCAL_TAG = "[#IMAGE_LOCAL#]";//本地图片标识(assets目录下) 60 | public static final String SPLIT_TAG = "\\[\\#SPLIT\\#\\]";//分割处标识 61 | 62 | /** 63 | * 获取图文的数据,这些数据可以从服务端取,或者写在本地的某个文件也可以 64 | * @return 图文数据 65 | */ 66 | public static String getData(){ 67 | //格式:文字开头用TEXT_TAG标识,网络图片地址用IMAGE_NET_TAG标识 68 | //本地图片用IMAGE_LOCAL_TAG标识,每两个标识内容之间要用SPLIT_TAG分隔 69 | 70 | String content = 71 | "[#TEXT#]这里是第一段文字"+ 72 | "[#SPLIT#]"+ 73 | "[#IMAGE_NET#]http://www.picture.com"+ /*网络图片*/ 74 | "[#SPLIT#]"+ 75 | "[#TEXT#]这里是第二段文字"+ 76 | "[#SPLIT#]"+ 77 | "[#IMAGE_LOCAL#]file:///android_asset/local_picture2.png"; /*本地图片*/ 78 | 79 | return content; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /TextAndGraphics/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/java/com/linchuan/textandgraphics/TextAndGraphicsView.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Color; 7 | import android.graphics.drawable.BitmapDrawable; 8 | import android.graphics.drawable.Drawable; 9 | import android.view.Gravity; 10 | import android.view.View; 11 | import android.view.WindowManager; 12 | import android.widget.ImageView; 13 | import android.widget.LinearLayout; 14 | import android.widget.TextView; 15 | 16 | import com.bumptech.glide.Glide; 17 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 18 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 19 | import com.bumptech.glide.request.animation.GlideAnimation; 20 | import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; 21 | import com.linchuan.textandgraphics.ImageViewPager.ImagePagerActivity; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * 图文布局,该布局是用LinearLayout布局的 30 | * Created by 林川 on 2016/12/6. 31 | */ 32 | 33 | public class TextAndGraphicsView extends LinearLayout { 34 | 35 | private Context context; 36 | private String[] mData; 37 | private final int PADDING_SIZE = 20;//边距 38 | private final int IMAGE_MAX_HEIGHT = 1000;//图片最大的高度限制 39 | private ImagePagerActivity.ImageSize imageSize; 40 | private List ListPhotos; 41 | private int screenWidth;//屏幕宽度 42 | 43 | public TextAndGraphicsView(Context context, String[] mData) { 44 | super(context); 45 | this.setOrientation(VERTICAL); 46 | this.context = context; 47 | this.mData = mData; 48 | if (mData == null || mData.length == 0) { 49 | mData = new String[1]; 50 | } 51 | ListPhotos = new ArrayList<>(); 52 | imageSize = new ImagePagerActivity.ImageSize(50, 50); 53 | screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); 54 | 55 | initView(); 56 | } 57 | 58 | private void initView() { 59 | 60 | //根据数据动态创建TextView和ImageView并添加点击事件和属性 61 | for (int i = 0; i < mData.length; i++) { 62 | if (mData[i].contains(DataUtil.TEXT_TAG)) { 63 | TextView tv = new TextView(context); 64 | tv.setText(mData[i].replace(DataUtil.TEXT_TAG, "")); 65 | tv.setGravity(Gravity.CENTER_VERTICAL); 66 | tv.setIncludeFontPadding(false); 67 | tv.setPadding(PADDING_SIZE, PADDING_SIZE, PADDING_SIZE, PADDING_SIZE); 68 | tv.setTextSize(17); 69 | tv.setLineSpacing(10, 1.2f);// 参数:1、行间距 2、倍数 70 | tv.setTextColor(Color.BLACK); 71 | addView(tv); 72 | } else if (mData[i].contains(DataUtil.IMAGE_NET_TAG)) { 73 | final ImageView iv = new ImageView(context); 74 | iv.setScaleType(ImageView.ScaleType.CENTER_CROP); 75 | iv.setPadding(PADDING_SIZE, PADDING_SIZE, PADDING_SIZE, PADDING_SIZE); 76 | 77 | final String url = mData[i].replace(DataUtil.IMAGE_NET_TAG, ""); 78 | ListPhotos.add(url); 79 | 80 | //使用这个需要在gradle中添加Glide库 81 | Glide.with(context).load(url).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(Color.WHITE).into(new GlideDrawableImageViewTarget(iv) { 82 | @Override 83 | public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { 84 | super.onResourceReady(drawable, anim); 85 | int maxHeight = dp2px(context, IMAGE_MAX_HEIGHT); 86 | int height = (int) ((float) iv.getWidth() / drawable.getMinimumWidth() * drawable.getMinimumHeight()); 87 | if (height > maxHeight) height = maxHeight; 88 | iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height)); 89 | } 90 | }); 91 | 92 | iv.setOnClickListener(new OnClickListener() { 93 | @Override 94 | public void onClick(View v) { 95 | imageSize = new ImagePagerActivity.ImageSize(50, 50); 96 | ImagePagerActivity.startImagePagerActivity(context, ListPhotos, getUrlPosition(url), imageSize); 97 | } 98 | }); 99 | addView(iv); 100 | } else if (mData[i].contains(DataUtil.IMAGE_LOCAL_TAG)) { 101 | final ImageView iv = new ImageView(context); 102 | iv.setScaleType(ImageView.ScaleType.CENTER_CROP); 103 | iv.setPadding(PADDING_SIZE, PADDING_SIZE, PADDING_SIZE, PADDING_SIZE); 104 | 105 | final String localPath = mData[i].replace(DataUtil.IMAGE_LOCAL_TAG, ""); 106 | ListPhotos.add(localPath); 107 | 108 | InputStream is = null; 109 | try { 110 | is = context.getAssets().open(localPath.replace("file:///android_asset/","")); 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } 114 | if (is == null) return; 115 | 116 | BitmapFactory.Options options = new BitmapFactory.Options(); 117 | Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); 118 | iv.setImageBitmap(bitmap); 119 | Drawable drawable = new BitmapDrawable(bitmap); 120 | 121 | int maxHeight = dp2px(context, IMAGE_MAX_HEIGHT); 122 | int height = (int) ((float) screenWidth / drawable.getMinimumWidth() * drawable.getMinimumHeight()); 123 | if (height > maxHeight) height = maxHeight; 124 | iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height)); 125 | 126 | iv.setOnClickListener(new OnClickListener() { 127 | @Override 128 | public void onClick(View v) { 129 | ImagePagerActivity.startImagePagerActivity(context, ListPhotos, getUrlPosition(localPath), imageSize); 130 | } 131 | }); 132 | addView(iv); 133 | } else { 134 | //扩展包含其他类型 135 | } 136 | } 137 | } 138 | 139 | //返回url在ListPhotos中的下标位置 140 | private int getUrlPosition(String url) { 141 | for (int i = 0; i < ListPhotos.size(); i++) { 142 | if (url.equals(ListPhotos.get(i))) { 143 | return i; 144 | } 145 | } 146 | return -1; 147 | } 148 | 149 | //dp转为像素 150 | private int dp2px(Context context, int dp) { 151 | float scale = context.getResources().getDisplayMetrics().density; 152 | return (int) (dp * scale + 0.5f); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /TextAndGraphics/app/src/main/java/com/linchuan/textandgraphics/ImageViewPager/ImagePagerActivity.java: -------------------------------------------------------------------------------- 1 | package com.linchuan.textandgraphics.ImageViewPager; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.graphics.drawable.Drawable; 7 | import android.os.Bundle; 8 | import android.os.Parcelable; 9 | import android.support.v4.view.PagerAdapter; 10 | import android.support.v4.view.ViewPager; 11 | import android.view.Gravity; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.FrameLayout; 16 | import android.widget.ImageView; 17 | import android.widget.LinearLayout; 18 | import android.widget.ProgressBar; 19 | 20 | import com.bumptech.glide.Glide; 21 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 22 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 23 | import com.bumptech.glide.request.animation.GlideAnimation; 24 | import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; 25 | import com.linchuan.textandgraphics.R; 26 | 27 | import java.io.Serializable; 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | import uk.co.senab.photoview.PhotoView; 32 | import uk.co.senab.photoview.PhotoViewAttacher; 33 | 34 | import static com.linchuan.textandgraphics.R.anim.fading_in; 35 | 36 | /**图片查看器 37 | * Created by 林川 on 2016/12/6. 38 | */ 39 | public class ImagePagerActivity extends Activity { 40 | public static final String INTENT_IMGURLS = "imgurls"; 41 | public static final String INTENT_POSITION = "position"; 42 | public static final String INTENT_IMAGESIZE = "imagesize"; 43 | 44 | private String curImageUrl = ""; 45 | 46 | private List guideViewList = new ArrayList(); 47 | private LinearLayout guideGroup; 48 | public ImageSize imageSize; 49 | private int startPos; 50 | private ArrayList imgUrls; 51 | 52 | public static void startImagePagerActivity(Context context, List imgUrls, int position, ImageSize imageSize) { 53 | Intent intent = new Intent(context, ImagePagerActivity.class); 54 | intent.putStringArrayListExtra(INTENT_IMGURLS, new ArrayList(imgUrls)); 55 | intent.putExtra(INTENT_POSITION, position); 56 | intent.putExtra(INTENT_IMAGESIZE, imageSize); 57 | context.startActivity(intent); 58 | } 59 | 60 | @Override 61 | protected void onCreate(Bundle savedInstanceState) { 62 | super.onCreate(savedInstanceState); 63 | setContentView(R.layout.activity_imagepager); 64 | overridePendingTransition(R.anim.fading_out, fading_in); 65 | 66 | HackyViewPager viewPager = (HackyViewPager) findViewById(R.id.pager); 67 | guideGroup = (LinearLayout) findViewById(R.id.guideGroup); 68 | 69 | getIntentData(); 70 | 71 | ImageAdapter mAdapter = new ImageAdapter(this); 72 | mAdapter.setDatas(imgUrls); 73 | mAdapter.setImageSize(imageSize); 74 | viewPager.setAdapter(mAdapter); 75 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 76 | 77 | @Override 78 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 79 | 80 | } 81 | 82 | @Override 83 | public void onPageSelected(int position) { 84 | for (int i = 0; i < guideViewList.size(); i++) { 85 | guideViewList.get(i).setSelected(i == position ? true : false); 86 | } 87 | } 88 | 89 | @Override 90 | public void onPageScrollStateChanged(int state) { 91 | 92 | } 93 | }); 94 | 95 | viewPager.setCurrentItem(startPos); 96 | 97 | addGuideView(guideGroup, startPos, imgUrls); 98 | } 99 | 100 | private void getIntentData() { 101 | startPos = getIntent().getIntExtra(INTENT_POSITION, 0); 102 | imgUrls = getIntent().getStringArrayListExtra(INTENT_IMGURLS); 103 | imageSize = (ImageSize) getIntent().getSerializableExtra(INTENT_IMAGESIZE); 104 | } 105 | 106 | private void addGuideView(LinearLayout guideGroup, int startPos, ArrayList imgUrls) { 107 | if (imgUrls != null && imgUrls.size() > 0) { 108 | guideViewList.clear(); 109 | for (int i = 0; i < imgUrls.size(); i++) { 110 | View view = new View(this); 111 | view.setSelected(i == startPos ? true : false); 112 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.gudieview_width), 113 | getResources().getDimensionPixelSize(R.dimen.gudieview_heigh)); 114 | layoutParams.setMargins(10, 0, 0, 0); 115 | guideGroup.addView(view, layoutParams); 116 | guideViewList.add(view); 117 | } 118 | } 119 | } 120 | 121 | private class ImageAdapter extends PagerAdapter { 122 | 123 | private List datas = new ArrayList(); 124 | private LayoutInflater inflater; 125 | private Context context; 126 | private ImageSize imageSize; 127 | private ImageView smallImageView = null; 128 | 129 | public void setDatas(List datas) { 130 | if (datas != null) 131 | this.datas = datas; 132 | } 133 | 134 | public void setImageSize(ImageSize imageSize) { 135 | this.imageSize = imageSize; 136 | } 137 | 138 | public ImageAdapter(Context context) { 139 | this.context = context; 140 | this.inflater = LayoutInflater.from(context); 141 | } 142 | 143 | @Override 144 | public int getCount() { 145 | if (datas == null) return 0; 146 | return datas.size(); 147 | } 148 | 149 | 150 | @Override 151 | public Object instantiateItem(ViewGroup container, final int position) { 152 | View view = inflater.inflate(R.layout.item_pager_image, container, false); 153 | 154 | if (view != null) { 155 | final PhotoView imageView = (PhotoView) view.findViewById(R.id.image); 156 | imageView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() { 157 | @Override 158 | public void onPhotoTap(View view, float v, float v2) { 159 | finish(); 160 | overridePendingTransition(R.anim.fading_out, R.anim.fading_in); 161 | } 162 | }); 163 | 164 | // 长按事件 165 | // imageView.setOnLongClickListener(new View.OnLongClickListener() { 166 | // @Override 167 | // public boolean onLongClick(View v) { 168 | // 169 | // } 170 | // }); 171 | 172 | if (imageSize != null) { 173 | //预览imageView 174 | smallImageView = new ImageView(context); 175 | FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(imageSize.getWidth(), imageSize.getHeight()); 176 | layoutParams.gravity = Gravity.CENTER; 177 | smallImageView.setLayoutParams(layoutParams); 178 | smallImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 179 | 180 | ((FrameLayout) view).addView(smallImageView); 181 | } 182 | 183 | //loading 184 | final ProgressBar loading = new ProgressBar(context); 185 | FrameLayout.LayoutParams loadingLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 186 | ViewGroup.LayoutParams.WRAP_CONTENT); 187 | loadingLayoutParams.gravity = Gravity.CENTER; 188 | loading.setLayoutParams(loadingLayoutParams); 189 | ((FrameLayout) view).addView(loading); 190 | 191 | final String imgurl = datas.get(position); 192 | 193 | Glide.with(context) 194 | .load(imgurl) 195 | .diskCacheStrategy(DiskCacheStrategy.ALL)//缓存多个尺寸 196 | //.thumbnail(0.1f)//先显示缩略图 缩略图为原图的1/10 197 | .error(R.mipmap.load_error) 198 | .into(new GlideDrawableImageViewTarget(imageView) { 199 | @Override 200 | public void onLoadStarted(Drawable placeholder) { 201 | super.onLoadStarted(placeholder); 202 | loading.setVisibility(View.VISIBLE); 203 | } 204 | 205 | @Override 206 | public void onLoadFailed(Exception e, Drawable errorDrawable) { 207 | super.onLoadFailed(e, errorDrawable); 208 | loading.setVisibility(View.GONE); 209 | } 210 | 211 | @Override 212 | public void onResourceReady(GlideDrawable resource, GlideAnimation animation) { 213 | super.onResourceReady(resource, animation); 214 | loading.setVisibility(View.GONE); 215 | 216 | Drawable drawable = imageView.getDrawable(); 217 | if (drawable != null && drawable.getIntrinsicWidth() != 0) { 218 | double rate = (double) drawable.getIntrinsicHeight() / (double) drawable.getIntrinsicWidth(); 219 | if (rate > 2.2) 220 | imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 221 | } 222 | } 223 | }); 224 | 225 | container.addView(view, 0); 226 | } 227 | return view; 228 | } 229 | 230 | @Override 231 | public void destroyItem(ViewGroup container, int position, Object object) { 232 | container.removeView((View) object); 233 | } 234 | 235 | @Override 236 | public boolean isViewFromObject(View view, Object object) { 237 | return view.equals(object); 238 | } 239 | 240 | @Override 241 | public void restoreState(Parcelable state, ClassLoader loader) { 242 | } 243 | 244 | @Override 245 | public Parcelable saveState() { 246 | return null; 247 | } 248 | 249 | 250 | } 251 | 252 | public static class ImageSize implements Serializable { 253 | 254 | private int width; 255 | private int height; 256 | 257 | public ImageSize(int width, int height) { 258 | this.width = width; 259 | this.height = height; 260 | } 261 | 262 | public int getHeight() { 263 | return height; 264 | } 265 | 266 | public void setHeight(int height) { 267 | this.height = height; 268 | } 269 | 270 | public int getWidth() { 271 | return width; 272 | } 273 | 274 | public void setWidth(int width) { 275 | this.width = width; 276 | } 277 | } 278 | } 279 | --------------------------------------------------------------------------------