GeezerVison is showing github.com — 1.添加 国际化 demo · ftyangjun/SmartRefreshLayout@a138b42
File treeExpand file treeCollapse file tree Open diff view settings java/com/scwang/refreshlayout
refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: app/build.gradle +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ android { | 26 | 26 | keyPassword "android" | 27 | 27 | } | 28 | 28 | } | | 29 | + | 29 | 30 | buildTypes { | 30 | 31 | debug { | 31 | 32 | signingConfig = signingConfigs.debug | @@ -36,10 +37,15 @@ android { | 36 | 37 | signingConfig = signingConfigs.debug | 37 | 38 | } | 38 | 39 | } | | 40 | + | 39 | 41 | lintOptions { | 40 | 42 | abortOnError false | 41 | 43 | } | 42 | 44 |
| | 45 | + compileOptions { | | 46 | + sourceCompatibility JavaVersion.VERSION_1_8 | | 47 | + targetCompatibility JavaVersion.VERSION_1_8 | | 48 | + } | 43 | 49 | } | 44 | 50 |
| 45 | 51 |
| @@ -69,7 +75,7 @@ dependencies { | 69 | 75 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' | 70 | 76 |
| 71 | 77 | implementation 'com.flyco.roundview:FlycoRoundView_Lib:1.1.4@aar' | 72 | | - implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46' | | 78 | + implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' | 73 | 79 | implementation 'com.github.czy1121:loadinglayout:1.0.1' | 74 | 80 | implementation 'com.github.mmin18:realtimeblurview:1.0.6' | 75 | 81 | implementation 'com.google.code.gson:gson:2.8.5' | @@ -81,6 +87,6 @@ dependencies { | 81 | 87 | implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.3' | 82 | 88 | testImplementation 'junit:junit:4.12' | 83 | 89 |
| 84 | | - implementation 'com.github.bumptech.glide:glide:4.8.0' | 85 | | - annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' | | 90 | + implementation 'com.github.bumptech.glide:glide:4.9.0' | | 91 | + annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' | 86 | 92 | } |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/AndroidManifest.xml +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 150 | 150 | <activity android:name=".activity.example.SnapHelperExampleActivity" | 151 | 151 | android:label="@string/title_activity_example_snap_helper" | 152 | 152 | android:screenOrientation="portrait"/> | | 153 | + <activity android:name=".activity.example.I18nExampleActivity" | | 154 | + android:label="@string/title_activity_example_i18n" | | 155 | + android:screenOrientation="portrait" /> | 153 | 156 | </application> | 154 | 157 |
| 155 | 158 | </manifest> |
Collapse file Copy file name to clipboard +106Lines changed: 106 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package com.scwang.refreshlayout.activity.example; | | 2 | + | | 3 | +import android.content.Intent; | | 4 | +import android.content.res.Configuration; | | 5 | +import android.content.res.Resources; | | 6 | +import android.os.Build; | | 7 | +import android.os.Bundle; | | 8 | +import android.support.annotation.Nullable; | | 9 | +import android.support.annotation.StringRes; | | 10 | +import android.support.v7.app.AppCompatActivity; | | 11 | +import android.support.v7.widget.Toolbar; | | 12 | +import android.util.DisplayMetrics; | | 13 | +import android.view.View; | | 14 | +import android.widget.AdapterView; | | 15 | +import android.widget.ListView; | | 16 | + | | 17 | +import com.scwang.refreshlayout.R; | | 18 | +import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; | | 19 | +import com.scwang.refreshlayout.adapter.SmartViewHolder; | | 20 | +import com.scwang.smartrefresh.layout.api.RefreshLayout; | | 21 | +import com.scwang.smartrefresh.layout.header.ClassicsHeader; | | 22 | +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; | | 23 | + | | 24 | +import java.util.ArrayList; | | 25 | +import java.util.Arrays; | | 26 | +import java.util.List; | | 27 | +import java.util.Locale; | | 28 | + | | 29 | +import static android.R.layout.simple_list_item_2; | | 30 | + | | 31 | +public class I18nExampleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { | | 32 | + | | 33 | + private enum Item { | | 34 | + i1(R.string.item_example_i18n_system), | | 35 | + i2(R.string.item_example_i18n_chinese), | | 36 | + i3(R.string.item_example_i18n_english), | | 37 | + ; | | 38 | + public int nameId; | | 39 | + Item(@StringRes int nameId) { | | 40 | + this.nameId = nameId; | | 41 | + } | | 42 | + } | | 43 | + | | 44 | + | | 45 | + @Override | | 46 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | | 47 | + super.onCreate(savedInstanceState); | | 48 | + setContentView(R.layout.activity_example_i18n); | | 49 | + | | 50 | + Toolbar toolbar = findViewById(R.id.toolbar); | | 51 | + toolbar.setNavigationOnClickListener(v -> finish()); | | 52 | + | | 53 | + RefreshLayout refreshLayout = findViewById(R.id.refreshLayout); | | 54 | + if (refreshLayout != null) { | | 55 | + refreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果 | | 56 | + refreshLayout.setRefreshHeader(new ClassicsHeader(this)); | | 57 | + refreshLayout.setOnRefreshListener((OnRefreshListener) layout -> layout.finishRefresh(1000)); | | 58 | + } | | 59 | + | | 60 | + View view = findViewById(R.id.listView); | | 61 | + if (view instanceof ListView) { | | 62 | + ListView listView = ((ListView) view); | | 63 | + List<Item> items = new ArrayList<>(); | | 64 | + items.addAll(Arrays.asList(Item.values())); | | 65 | + items.addAll(Arrays.asList(Item.values())); | | 66 | + listView.setAdapter(new BaseRecyclerAdapter<Item>(items, simple_list_item_2, this) { | | 67 | + @Override | | 68 | + protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { | | 69 | + holder.text(android.R.id.text1, model.nameId); | | 70 | + holder.text(android.R.id.text2, getString(R.string.item_example_i18n_click, getString(model.nameId))); | | 71 | + holder.textColorId(android.R.id.text2, R.color.colorTextAssistant); | | 72 | + } | | 73 | + }); | | 74 | + } | | 75 | + } | | 76 | + | | 77 | + @Override | | 78 | + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | | 79 | + switch (Item.values()[position % Item.values().length].nameId) { | | 80 | + case R.string.item_example_i18n_system: | | 81 | + changeAppLanguage(Locale.getDefault()); | | 82 | + break; | | 83 | + case R.string.item_example_i18n_chinese: | | 84 | + changeAppLanguage(Locale.CHINESE); | | 85 | + break; | | 86 | + case R.string.item_example_i18n_english: | | 87 | + changeAppLanguage(Locale.ENGLISH); | | 88 | + break; | | 89 | + } | | 90 | + } | | 91 | + | | 92 | + private void changeAppLanguage(Locale locale) { | | 93 | + Resources res = getResources(); | | 94 | + DisplayMetrics dm = res.getDisplayMetrics(); | | 95 | + Configuration conf = res.getConfiguration(); | | 96 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { | | 97 | + conf.locale = locale; | | 98 | + } else { | | 99 | + conf.setLocale(locale); | | 100 | + } | | 101 | + res.updateConfiguration(conf, dm); | | 102 | + startActivity(new Intent(this, getClass())); | | 103 | + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); | | 104 | + finish(); | | 105 | + } | | 106 | +} |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshExampleFragment.java +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | import com.scwang.refreshlayout.activity.FragmentActivity; | 22 | 22 | import com.scwang.refreshlayout.activity.example.BasicExampleActivity; | 23 | 23 | import com.scwang.refreshlayout.activity.example.CustomExampleActivity; | | 24 | +import com.scwang.refreshlayout.activity.example.I18nExampleActivity; | 24 | 25 | import com.scwang.refreshlayout.activity.example.ListenerExampleActivity; | 25 | 26 | import com.scwang.refreshlayout.activity.example.NestedLayoutExampleActivity; | 26 | 27 | import com.scwang.refreshlayout.activity.example.SnapHelperExampleActivity; | @@ -58,6 +59,7 @@ private enum Item { | 58 | 59 | PureScroll(R.string.index_example_scroll, PureScrollExampleFragment.class), | 59 | 60 | Listener(R.string.index_example_listener, ListenerExampleActivity.class), | 60 | 61 | Custom(R.string.index_example_custom, CustomExampleActivity.class), | | 62 | + I18N(R.string.index_example_custom, I18nExampleActivity.class), | 61 | 63 | SnapHelper(R.string.index_example_snap_helper, SnapHelperExampleActivity.class), | 62 | 64 | ViewPager(R.string.index_example_pager, ViewPagerExampleFragment.class), | 63 | 65 | BottomSheet(R.string.index_example_bottom_sheet,BottomSheetExampleFragment.class), | |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +<?xml version="1.0" encoding="utf-8"?> | | 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | | 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | | 4 | + xmlns:tools="http://schemas.android.com/tools" | | 5 | + android:layout_width="match_parent" | | 6 | + android:layout_height="match_parent" | | 7 | + android:orientation="vertical" | | 8 | + tools:context="com.scwang.refreshlayout.activity.example.I18nExampleActivity"> | | 9 | + | | 10 | + <android.support.v7.widget.Toolbar style="@style/AppTheme.Toolbar" | | 11 | + android:id="@+id/toolbar" | | 12 | + app:navigationIcon="?attr/homeAsUpIndicator" | | 13 | + app:title="@string/title_activity_example_i18n"/> | | 14 | + | | 15 | + <com.scwang.smartrefresh.layout.SmartRefreshLayout | | 16 | + android:id="@+id/refreshLayout" | | 17 | + android:layout_width="match_parent" | | 18 | + android:layout_height="match_parent"> | | 19 | + <ListView | | 20 | + android:id="@+id/listView" | | 21 | + android:layout_width="match_parent" | | 22 | + android:layout_height="match_parent" | | 23 | + android:background="@android:color/white" | | 24 | + android:overScrollMode="never" | | 25 | + tools:listitem="@android:layout/simple_list_item_2"/> | | 26 | + </com.scwang.smartrefresh.layout.SmartRefreshLayout> | | 27 | + | | 28 | +</LinearLayout> |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/res/values-zh/strings.xml +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 45 | 45 | <string name="title_activity_example_listener">多功能监听器</string> | 46 | 46 | <string name="title_activity_example_custom">自定义Header</string> | 47 | 47 | <string name="title_activity_example_snap_helper">SnapHelper</string> | | 48 | + <string name="title_activity_example_i18n">国际化</string> | 48 | 49 |
| 49 | 50 | <string name="fragment_example_no_more_data">没有更多数据</string> | 50 | 51 | <string name="fragment_example_horizontal">水平滚动模式</string> | | 71 | 72 | <string name="index_example_scroll">纯滚动模式</string> | 72 | 73 | <string name="index_example_listener">多功能监听器</string> | 73 | 74 | <string name="index_example_custom">自定义Header</string> | | 75 | + <string name="index_example_i18n">国际化支持</string> | 74 | 76 | <string name="index_example_snap_helper">结合 SnapHelper 使用</string> | 75 | 77 | <string name="index_example_pager">ViewPager 多页面共用一个 RefreshLayout</string> | 76 | 78 | <string name="index_example_bottom_sheet">BottomSheet内部使用加载更多</string> | | 117 | 119 | <string name="item_example_pager_left">左边</string> | 118 | 120 | <string name="item_example_pager_right">右边</string> | 119 | 121 |
| | 122 | + <string name="item_example_i18n_system">跟随系统</string> | | 123 | + <string name="item_example_i18n_chinese">中文</string> | | 124 | + <string name="item_example_i18n_english">英语</string> | | 125 | + <string name="item_example_i18n_click">点击切换语言为 %s</string> | | 126 | + | 120 | 127 | <string name="github_qq_browser_kernel">网页由 github.com 提供\n已启用QQ浏览器X5内核</string> | 121 | 128 |
| 122 | 129 | <string name="description_set_default_creator">这是使用定制Header和Footer的第一种方法-全局默认\n\n | |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/res/values/strings.xml +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 45 | 45 | <string name="title_activity_example_listener">Multifunction monitor</string> | 46 | 46 | <string name="title_activity_example_custom">Custom Header</string> | 47 | 47 | <string name="title_activity_example_snap_helper">SnapHelper</string> | | 48 | + <string name="title_activity_example_i18n">I18N</string> | 48 | 49 |
| 49 | 50 | <string name="fragment_example_no_more_data">No More Data</string> | 50 | 51 | <string name="fragment_example_horizontal">Horizontal Scroll Mode</string> | | 82 | 83 | <string name="index_example_scroll">The usage of pure rolling mode</string> | 83 | 84 | <string name="index_example_listener">The usage of multifunction listener</string> | 84 | 85 | <string name="index_example_custom">The usage of custom Header</string> | | 86 | + <string name="index_example_i18n">The usage of I18n</string> | 85 | 87 | <string name="index_example_snap_helper">The usage of SnapHelper</string> | 86 | 88 | <string name="index_example_pager">The usage of ViewPager</string> | 87 | 89 | <string name="index_example_bottom_sheet">The usage of BottomSheet</string> | | 118 | 120 | <string name="item_example_pager_left">Left Pager</string> | 119 | 121 | <string name="item_example_pager_right">Right Pager</string> | 120 | 122 |
| | 123 | + <string name="item_example_i18n_system">System</string> | | 124 | + <string name="item_example_i18n_chinese">Chinese</string> | | 125 | + <string name="item_example_i18n_english">English</string> | | 126 | + <string name="item_example_i18n_click">Click to switch the language to %s</string> | | 127 | + | 121 | 128 | <string name="github_qq_browser_kernel">The web page is provided by github.com.\nThe QQ browser X5 kernel has been enabled.</string> | 122 | 129 |
| 123 | 130 | <string name="description_set_default_creator">\n | |
Collapse file Copy file name to clipboardExpand all lines: refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | import android.content.Context; | 4 | 4 | import android.graphics.Bitmap; | 5 | | -import android.graphics.Canvas; | 6 | 5 | import android.graphics.drawable.Animatable; | 7 | 6 | import android.graphics.drawable.BitmapDrawable; | 8 | 7 | import android.graphics.drawable.Drawable; | @@ -116,19 +115,6 @@ protected T self() { | 116 | 115 | return (T) this; | 117 | 116 | } | 118 | 117 |
| 119 | | - /** | 120 | | - * 修复 经典头拉伸状态下显示异常的问题 | 121 | | - * 导致的原因 1.1.0 版本之后 Smart 不推荐 Scale 模式,主推 FixedBehind 模式 | 122 | | - * 并且取消了对 child 的绘制裁剪,所以经典组件需要重写 dispatchDraw 自行裁剪 | 123 | | - */ | 124 | | - @Override | 125 | | - protected void dispatchDraw(Canvas canvas) { | 126 | | - final View rect = this; | 127 | | - canvas.save(); | 128 | | - canvas.clipRect(rect.getLeft(), rect.getTop(), rect.getRight(), rect.getBottom()); | 129 | | - super.dispatchDraw(canvas); | 130 | | - canvas.restore(); | 131 | | - } | 132 | 118 | //</editor-fold> | 133 | 119 |
| 134 | 120 | //<editor-fold desc="RefreshHeader"> | |
Collapse file Copy file name to clipboardExpand all lines: refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -745,7 +745,13 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) { | 745 | 745 | } | 746 | 746 | canvas.drawRect(0, child.getTop(), thisView.getWidth(), bottom, mPaint); | 747 | 747 | } | 748 | | - if (mEnableClipHeaderWhenFixedBehind && mRefreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) { | | 748 | + /* | | 749 | + * 2019-12-24 | | 750 | + * 修复 经典头拉伸状态下显示异常的问题 | | 751 | + * 导致的原因 1.1.0 版本之后 Smart 不推荐 Scale 模式,主推 FixedBehind 模式 | | 752 | + * 并且取消了对 child 的绘制裁剪,所以经典组件需要重写 dispatchDraw 自行裁剪 | | 753 | + */ | | 754 | + if ((mEnableClipHeaderWhenFixedBehind && mRefreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) || mRefreshHeader.getSpinnerStyle().scale) { | 749 | 755 | canvas.save(); | 750 | 756 | canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), bottom); | 751 | 757 | boolean ret = super.drawChild(canvas, child, drawingTime); | @@ -769,7 +775,13 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) { | 769 | 775 | } | 770 | 776 | canvas.drawRect(0, top, thisView.getWidth(), child.getBottom(), mPaint); | 771 | 777 | } | 772 | | - if (mEnableClipFooterWhenFixedBehind && mRefreshFooter.getSpinnerStyle() == SpinnerStyle.FixedBehind) { | | 778 | + /* | | 779 | + * 2019-12-24 | | 780 | + * 修复 经典头拉伸状态下显示异常的问题 | | 781 | + * 导致的原因 1.1.0 版本之后 Smart 不推荐 Scale 模式,主推 FixedBehind 模式 | | 782 | + * 并且取消了对 child 的绘制裁剪,所以经典组件需要重写 dispatchDraw 自行裁剪 | | 783 | + */ | | 784 | + if ((mEnableClipFooterWhenFixedBehind && mRefreshFooter.getSpinnerStyle() == SpinnerStyle.FixedBehind) || mRefreshHeader.getSpinnerStyle().scale) { | 773 | 785 | canvas.save(); | 774 | 786 | canvas.clipRect(child.getLeft(), top, child.getRight(), child.getBottom()); | 775 | 787 | boolean ret = super.drawChild(canvas, child, drawingTime); | |
|