DataLoadingLayoutAndroid


Source link: https://github.com/lvleo/DataLoadingLayoutAndroid

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

Usage

###Step 1:Add the dependency:

open the build.gradle file of your module, at the dependencies function add the below code:

 compile 'com.lvleo:data-loading-layout:0.1.2'

###Step 2:Add the view to your layout.xml file:

<com.lvleo.dataloadinglayout.DataLoadingLayout

android:id="@+id/loading_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_below="@id/layout_buttons"

android:background="@android:color/darker_gray"

app:loadingBarColor="@android:color/holo_purple"

app:statusText="????"

app:statusTextColor="@android:color/black"

app:statusTextSize="16sp"

/>

###Step 3: The activity implements DataLoadingLayout.OnViewTouchListener, after init the view setDataView(view) and setOnMyViewTouchListener(this),final Override the onTouchUp() function. like this:

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

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 at
  http://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. 

Resources

Detect device shake in background (if you want), specifying sensitivity, range, counts.

This library helps android developers to implement something like iOS key value observer pattern (KVO).

A library that implements Google Play like PersistentSearch view.

  • 3 modes: Toolbar with drawer button, MenuItem and Toolbar with back button
  • MenuItem mode reveal animation
  • Voice recognition support.
  • Use android.support.v7.widget.CardView to draw background and shadow, you can set persistentSV_searchCardElevation to modify shadow size.

JPagerSlidingTabStrip - deeply modified PagerSlidingTabStrip.

  • Added 3 tabStyles and possibility to customize tabStyles (JTabStyle).
  • Added possibility to show unread messages (like weichat).

This demo aims shows practical way of clean architecture, MVP.

Android floating window permission compatibility library.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes