GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 1.添加 国际化 demo · ftyangjun/SmartRefreshLayout@a138b42

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app
    • build.gradle
    • src/main
      • AndroidManifest.xml
      • java/com/scwang/refreshlayout
        • activity/example
          • I18nExampleActivity.java
        • fragment/index
          • RefreshExampleFragment.java
      • res
        • layout
          • activity_example_i18n.xml
        • values-zh
          • strings.xml
        • values
          • strings.xml
  • refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics
    • ClassicsAbstract.java
  • refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout
    • SmartRefreshLayout.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/build.gradle‎

Copy file name to clipboardExpand all lines: app/build.gradle
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ android {
2626
keyPassword "android"
2727
}
2828
}
29+
2930
buildTypes {
3031
debug {
3132
signingConfig = signingConfigs.debug
@@ -36,10 +37,15 @@ android {
3637
signingConfig = signingConfigs.debug
3738
}
3839
}
40+
3941
lintOptions {
4042
abortOnError false
4143
}
4244

45+
compileOptions {
46+
sourceCompatibility JavaVersion.VERSION_1_8
47+
targetCompatibility JavaVersion.VERSION_1_8
48+
}
4349
}
4450

4551

@@ -69,7 +75,7 @@ dependencies {
6975
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
7076

7177
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'
7379
implementation 'com.github.czy1121:loadinglayout:1.0.1'
7480
implementation 'com.github.mmin18:realtimeblurview:1.0.6'
7581
implementation 'com.google.code.gson:gson:2.8.5'
@@ -81,6 +87,6 @@ dependencies {
8187
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
8288
testImplementation 'junit:junit:4.12'
8389

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'
8692
}
Collapse file

‎app/src/main/AndroidManifest.xml‎

Copy file name to clipboardExpand all lines: app/src/main/AndroidManifest.xml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
<activity android:name=".activity.example.SnapHelperExampleActivity"
151151
android:label="@string/title_activity_example_snap_helper"
152152
android:screenOrientation="portrait"/>
153+
<activity android:name=".activity.example.I18nExampleActivity"
154+
android:label="@string/title_activity_example_i18n"
155+
android:screenOrientation="portrait" />
153156
</application>
154157

155158
</manifest>
Collapse file

‎app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java‎

Copy file name to clipboard
+106Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

‎app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshExampleFragment.java‎

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 numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.scwang.refreshlayout.activity.FragmentActivity;
2222
import com.scwang.refreshlayout.activity.example.BasicExampleActivity;
2323
import com.scwang.refreshlayout.activity.example.CustomExampleActivity;
24+
import com.scwang.refreshlayout.activity.example.I18nExampleActivity;
2425
import com.scwang.refreshlayout.activity.example.ListenerExampleActivity;
2526
import com.scwang.refreshlayout.activity.example.NestedLayoutExampleActivity;
2627
import com.scwang.refreshlayout.activity.example.SnapHelperExampleActivity;
@@ -58,6 +59,7 @@ private enum Item {
5859
PureScroll(R.string.index_example_scroll, PureScrollExampleFragment.class),
5960
Listener(R.string.index_example_listener, ListenerExampleActivity.class),
6061
Custom(R.string.index_example_custom, CustomExampleActivity.class),
62+
I18N(R.string.index_example_custom, I18nExampleActivity.class),
6163
SnapHelper(R.string.index_example_snap_helper, SnapHelperExampleActivity.class),
6264
ViewPager(R.string.index_example_pager, ViewPagerExampleFragment.class),
6365
BottomSheet(R.string.index_example_bottom_sheet,BottomSheetExampleFragment.class),
Collapse file

‎app/src/main/res/layout/activity_example_i18n.xml‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

‎app/src/main/res/values-zh/strings.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/values-zh/strings.xml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<string name="title_activity_example_listener">多功能监听器</string>
4646
<string name="title_activity_example_custom">自定义Header</string>
4747
<string name="title_activity_example_snap_helper">SnapHelper</string>
48+
<string name="title_activity_example_i18n">国际化</string>
4849

4950
<string name="fragment_example_no_more_data">没有更多数据</string>
5051
<string name="fragment_example_horizontal">水平滚动模式</string>
@@ -71,6 +72,7 @@
7172
<string name="index_example_scroll">纯滚动模式</string>
7273
<string name="index_example_listener">多功能监听器</string>
7374
<string name="index_example_custom">自定义Header</string>
75+
<string name="index_example_i18n">国际化支持</string>
7476
<string name="index_example_snap_helper">结合 SnapHelper 使用</string>
7577
<string name="index_example_pager">ViewPager 多页面共用一个 RefreshLayout</string>
7678
<string name="index_example_bottom_sheet">BottomSheet内部使用加载更多</string>
@@ -117,6 +119,11 @@
117119
<string name="item_example_pager_left">左边</string>
118120
<string name="item_example_pager_right">右边</string>
119121

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+
120127
<string name="github_qq_browser_kernel">网页由 github.com 提供\n已启用QQ浏览器X5内核</string>
121128

122129
<string name="description_set_default_creator">这是使用定制Header和Footer的第一种方法-全局默认\n\n
Collapse file

‎app/src/main/res/values/strings.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/values/strings.xml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<string name="title_activity_example_listener">Multifunction monitor</string>
4646
<string name="title_activity_example_custom">Custom Header</string>
4747
<string name="title_activity_example_snap_helper">SnapHelper</string>
48+
<string name="title_activity_example_i18n">I18N</string>
4849

4950
<string name="fragment_example_no_more_data">No More Data</string>
5051
<string name="fragment_example_horizontal">Horizontal Scroll Mode</string>
@@ -82,6 +83,7 @@
8283
<string name="index_example_scroll">The usage of pure rolling mode</string>
8384
<string name="index_example_listener">The usage of multifunction listener</string>
8485
<string name="index_example_custom">The usage of custom Header</string>
86+
<string name="index_example_i18n">The usage of I18n</string>
8587
<string name="index_example_snap_helper">The usage of SnapHelper</string>
8688
<string name="index_example_pager">The usage of ViewPager</string>
8789
<string name="index_example_bottom_sheet">The usage of BottomSheet</string>
@@ -118,6 +120,11 @@
118120
<string name="item_example_pager_left">Left Pager</string>
119121
<string name="item_example_pager_right">Right Pager</string>
120122

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+
121128
<string name="github_qq_browser_kernel">The web page is provided by github.com.\nThe QQ browser X5 kernel has been enabled.</string>
122129

123130
<string name="description_set_default_creator">\n
Collapse file

‎refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java‎

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 numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.content.Context;
44
import android.graphics.Bitmap;
5-
import android.graphics.Canvas;
65
import android.graphics.drawable.Animatable;
76
import android.graphics.drawable.BitmapDrawable;
87
import android.graphics.drawable.Drawable;
@@ -116,19 +115,6 @@ protected T self() {
116115
return (T) this;
117116
}
118117

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-
}
132118
//</editor-fold>
133119

134120
//<editor-fold desc="RefreshHeader">
Collapse file

‎refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java‎

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 numberDiff line numberDiff line change
@@ -745,7 +745,13 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
745745
}
746746
canvas.drawRect(0, child.getTop(), thisView.getWidth(), bottom, mPaint);
747747
}
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) {
749755
canvas.save();
750756
canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), bottom);
751757
boolean ret = super.drawChild(canvas, child, drawingTime);
@@ -769,7 +775,13 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
769775
}
770776
canvas.drawRect(0, top, thisView.getWidth(), child.getBottom(), mPaint);
771777
}
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) {
773785
canvas.save();
774786
canvas.clipRect(child.getLeft(), top, child.getRight(), child.getBottom());
775787
boolean ret = super.drawChild(canvas, child, drawingTime);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.