Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lvleo/DataLoadingLayoutAndroid
A custom view for data loading status on Android
https://github.com/lvleo/DataLoadingLayoutAndroid
Last synced: 3 months ago
JSON representation
A custom view for data loading status on Android
- Host: GitHub
- URL: https://github.com/lvleo/DataLoadingLayoutAndroid
- Owner: lvleo
- License: apache-2.0
- Created: 2016-10-09T09:17:57.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-26T08:40:20.000Z (over 7 years ago)
- Last Synced: 2024-06-16T01:33:40.354Z (5 months ago)
- Language: Java
- Homepage:
- Size: 493 KB
- Stars: 16
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - DataLoadingLayoutAndroid - 展示当前数据加载状态的库 (空白页)
README
# DataLoadingLayout
## Description
DataLoadingLayout is a simple library for Android. It's a layout to show current data loading status(loading, load success,load error)##Screenshots
![](https://github.com/lvleo/DataLoadingLayoutAndroid/blob/master/screen/screen.gif)## Usage
###Step 1:Add the dependency:
open the build.gradle file of your module, at the dependencies function add the below code:
```groovy
compile 'com.lvleo:data-loading-layout:0.1.2'
```###Step 2:Add the view to your layout.xml file:
```groovy
```
###Step 3: The activity implements DataLoadingLayout.OnViewTouchListener, after init the view setDataView(view) and setOnMyViewTouchListener(this),final Override the onTouchUp() function. like this:```groovy
public class MainActivity extends AppCompatActivity implements DataLoadingLayout.OnViewTouchListener {private static final String TAG = MainActivity.class.getSimpleName();
private Button btnNoData, btnDataLoadingSuccess, btnDataLoadingError;
private TextView txtResult;
private DataLoadingLayout mLoadingLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);btnNoData = (Button) findViewById(R.id.btn_data_empty);
btnDataLoadingSuccess = (Button) findViewById(R.id.btn_data_success);
btnDataLoadingError = (Button) findViewById(R.id.btn_data_error);txtResult = (TextView) findViewById(R.id.txt_result);
mLoadingLayout = (DataLoadingLayout) findViewById(R.id.loading_layout);
// TextView textView = mLoadingLayout.getTextViewStatus();
// textView.setTextColor(Color.RED);
// textView.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_sad, 0, 0);mLoadingLayout.setDataView(txtResult);
mLoadingLayout.setOnMyViewTouchListener(this);
btnNoData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getData("http://api.map.baidu.com/telematics/v3/weather?location=");
}
});
btnDataLoadingSuccess.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getData("http://api.map.baidu.com/telematics/v3/weather?location=无锡");
}
});
btnDataLoadingError.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getData("http://api.map.baidu.com/telematics/v3/weathersssss?location=无锡");
}
});txtResult.setText("点击切换上方的按钮查看实际效果");
mLoadingLayout.setStatusTopIcon(R.mipmap.ic_sad);
}@Override
public void onTouchUp() {
// if data load Error or data is empty, can get data again by touch the view
getData("http://api.map.baidu.com/telematics/v3/weather?location=无锡");
}private void getData(String subUrl) {
mLoadingLayout.loading();String url = subUrl + "&output=json&ak=6gYxFLrG9vipiq1bkQLnHhUH&" +
"mcode=4C:45:2B:FC:13:89:0F:76:88:A8:D3:9F:69:F6:51:9C:BC:F6:9E:65;baidumapsdk.demo";AsyncHttpClient client = new AsyncHttpClient();
client.setTimeout(20 * 1000);
client.setConnectTimeout(20 * 1000);
client.setResponseTimeout(20 * 1000);
client.setMaxRetriesAndTimeout(3, 20 * 1000);
client.allowRetryExceptionClass(SocketTimeoutException.class);
client.allowRetryExceptionClass(ConnectTimeoutException.class);
client.get(url, new JsonHttpResponseHandler() {@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
Log.i(TAG, "onSuccess: response==" + response);
if (response.optInt("error") == 0) {
mLoadingLayout.loadSuccess();JSONObject object = response.optJSONArray("results").optJSONObject(0).
optJSONArray("weather_data").optJSONObject(0);String weather = "今日天气\r\n" + object.optString("date") + "\r\n 温度:" +
object.optString("temperature") + "\r\n 风向:" + object.optString("wind");txtResult.setText(weather);
} else {
mLoadingLayout.loadSuccess("暂无数据\n点击屏幕 重新加载 ");
}
}@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
mLoadingLayout.loadError("服务器连接失败\n点击屏幕 重新加载");
}
});
}
}
```## XML attributes
| Name | Type | Default | Description |
|:----:|:----:|:-------:|:-----------:|
|statusTextSize|dimension|14|the status string's font size|
|statusTextColor|color|Color.GRAY|the status string's color|
|statusText|string|No Data|the status default content|
|loadingBarColor|color|Color.BLUE|the ProgressBar's color|
|loadingBarSize|dimension|48|the ProgressBar's size|##About me
[Weibo](http://weibo.com/2265549640)License
-------Copyright 2016 lvleo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.