Android development Tips (3)

Source: Internet
Author: User

Android development Tips (3)
1. UIAutomatorViewer

Automated testing is the trend of Android testing. It is stable and reusable. The most common tool is Espresso.
Use UIAutomatorViewer to obtain the resource Id,
Location/android-sdk/tools/uiautomatorviewer, click to use.

2. GitHub tag 3. interesting modifications to the SVG Library

Address: loads images in SVG format and modifies the color attributes.

4. Request and generated Json plug-in

JSONOnlineViewer, network request plug-in, get Json data, locationView-> JSONViewer.
GsonFormat: automatically generates class plug-ins Based on JsonCommand + NInside.

It comes with a plug-in. Others are random.

5. How to set the Interceptor of javasfit2 + Okhttp3

Upgrade fit to beta3 and use the latest Okhttp3 and Interceptor settings.

Old Version

OkHttpClient client = new OkHttpClient().Builder();HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(    BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY);client.interceptors().add(signingInterceptor);client.interceptors().add(loggingInterceptor);

Replacement, new version

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);        MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(                BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY);        OkHttpClient client = new OkHttpClient.Builder()                .addInterceptor(signingInterceptor)                .addInterceptor(loggingInterceptor)                .build();

Otherwise, the following error may occur:HTTP 409 ConflictThe correct authentication method is not entered. The private key is incorrect.

6. okhttp-logging-interceptor output log information

For more information, see <G id = "1"> log Service </G>.

compile "com.squareup.okhttp3:logging-interceptor:${libs.okhttp}"

Output reference:

D/OkHttp: <-- 200 OK http://gateway.marvel.com/v1/public/characters?offset=0&... (1552ms, unknown-length body)
7. Transparent statusbar and full screen ImageView

Set status bar to transparent color.

The root layout of the page isCollapsingToolbarLayout.

<code class="hljs avrasm"><android.support.design.widget.collapsingtoolbarlayout android:fitssystemwindows="true" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">    <imageview android:contentdescription="@null" android:fitssystemwindows="true" android:layout_height="match_parent" android:layout_width="match_parent" android:scaletype="centerCrop" android:src="@drawable/christmas"></imageview></android.support.design.widget.collapsingtoolbarlayout></code>

Effect

8. Android Studio Template

Location: File-> Other Settings-> Default Settings-> Editor-> Live Templates
After being proficientAbbreviation + TabYou can use it. You can also add it yourself.

Custom template:
Abbreviation (Abbreviation), Description, content (Template text), Application Scenario, format.

9. websites that recommend animation Effects

Web site, the website has a lot of fun animation effects, and are all programming implementation, convenient transplantation, such as Snowflake effect.

10. ViewHolder of ListView

Android officially recommends replacing ListView with RecyclerView, but many old-fashioned users do not want to do this. Therefore, ViewHolder must be used to increase loading speed. For more information, see.

Basic usage.

Static class ViewHolder () {TextView testName; TextView testDesc ;}... @ Overridepublic View getView (int position, View convertView, ViewGroup parent) {View rowView = convertView; // initialize ViewHolder if (convertView = null) {LayoutInflater inflater = (LayoutInflater) parent. getContext (). getSystemService (Context. LAYOUT_INFLATER_SERVICE); rowView = inflater. inflate (R. layout. view_test_row, parent, false); ViewHolder viewHolder = new ViewHolder (); viewHolder. testName = (TextView) rowView. findViewById (R. id. test_ TV _name); viewHolder. testDesc = (TextView) rowView. findViewById (R. id. test_ TV _desc); rowView. setTag (viewHolder);} // use ViewHolder holder = (ViewHolder) rowView. getTag (); holder. testName. setText ("Test:" + position); holder. testDesc. setText ("This is number" + position + ". "); return rowView ;}

OK, that's all! Enjoy it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.