Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Saturday, September 10, 2016

fragment的懒加载实现

我们在做应用开发的时候,一个Activity里面可能会以viewpager(或其他容器)与多个Fragment来组合使用,而如果每个fragment都需要去加载数据,或从本地加载,或从网络加载,那么在这个activity刚创建的时候就变成需要初始化大量资源。这样的结果,我们当然不会满意。那么,能不能做到当切换到这个fragment的时候,它才去初始化呢?
答案就在Fragment里的setUserVisibleHint这个方法里。请看关于Fragment里这个方法的API文档(国内镜像地址:Fragment api):
  1. Set a hint to the system about whether this fragment's UI is currently visible to the user. This hint defaults to true and is persistent across fragment instance state save and restore.
  2. An app may set this to false to indicate that the fragment's UI is scrolled out of visibility or is otherwise not directly visible to the user. This may be used by the system to prioritize operations such as fragment lifecycle updates or loader ordering behavior.
  3. Parameters
  4. isVisibleToUser true if this fragment's UI is currently visible to the user (default), false if it is not.

该方法用于告诉系统,这个Fragment的UI是否是可见的。所以我们只需要继承Fragment并重写该方法,即可实现在fragment可见时才进行数据加载操作,即Fragment的懒加载。
代码如下:

  1. /*
  2.  * Date: 14-7-17
  3.  * Project: Access-Control-V2
  4.  */
  5. package cn.irains.access_control_v2.common;
  6. import android.support.v4.app.Fragment;
  7. /**
  8.  * Author: msdx (645079761@qq.com)
  9.  * Time: 14-7-17 下午5:46
  10.  */
  11. public abstract class LazyFragment extends Fragment {
  12.     protected boolean isVisible;
  13.     /**
  14.      * 在这里实现Fragment数据的缓加载.
  15.      * @param isVisibleToUser
  16.      */
  17.     @Override
  18.     public void setUserVisibleHint(boolean isVisibleToUser) {
  19.         super.setUserVisibleHint(isVisibleToUser);
  20.         if(getUserVisibleHint()) {
  21.             isVisible = true;
  22.             onVisible();
  23.         } else {
  24.             isVisible = false;
  25.             onInvisible();
  26.         }
  27.     }
  28.     protected void onVisible(){
  29.         lazyLoad();
  30.     }
  31.     protected abstract void lazyLoad();
  32.     protected void onInvisible(){}
  33. }
在LazyFragment,我增加了三个方法,一个是onVisiable,即fragment被设置为可见时调用,一个是onInvisible,即fragment被设置为不可见时调用。另外再写了一个lazyLoad的抽象方法,该方法在onVisible里面调用。你可能会想,为什么不在getUserVisibleHint里面就直接调用呢?
我这么写是为了代码的复用。因为在fragment中,我们还需要创建视图(onCreateView()方法),可能还需要在它不可见时就进行其他小量的初始化操作(比如初始化需要通过AIDL调用的远程服务)等。而setUserVisibleHint是在onCreateView之前调用的,那么在视图未初始化的时候,在lazyLoad当中就使用的话,就会有空指针的异常。而把lazyLoad抽离成一个方法,那么它的子类就可以这样做:
  1. public class OpenResultFragment extends LazyFragment{
  2.     // 标志位,标志已经初始化完成。
  3.     private boolean isPrepared;
  4.     @Override
  5.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  6.         Log.d(LOG_TAG, "onCreateView");
  7.         View view = inflater.inflate(R.layout.fragment_open_result, container, false);
  8.         //XXX初始化view的各控件
  9.     isPrepared = true;
  10.         lazyLoad();
  11.         return view;
  12.     }
  13.     @Override
  14.     protected void lazyLoad() {
  15.         if(!isPrepared || !isVisible) {
  16.             return;
  17.         }
  18.         //填充各控件的数据
  19.     }
  20. }
在上面的类当中,我们增加了一个标志位isPrepared,用于标志是否初始化完成。然后在我们所需要的初始化操作完成之后调用,如上面的例子当中,在初始化view之后,设置 isPrepared为true,同时调用lazyLoad()方法。而在lazyLoad()当中,判断isPrepared和isVisible只要有一个不为true就不往下执行。也就是仅当初始化完成,并且可见的时候才继续加载,这样的避免了未初始化完成就使用而带来的问题。
在这里我对fragment的懒加载实现的介绍就到此为止,如果你有兴趣,可以基于此再深入探究,比如写一个带有缓初始化和可见时刷新的特性的Fragment。

Friday, August 26, 2016

node.js - Gradle "... occurred starting process 'command 'npm''" on Mac

When  you use the react-native  build release APK;

if you meet this question:

node.js - Gradle "... occurred starting process 'command 'npm''" on Mac

you must use this command in the Root Project

react-native start      or   npm start

If the terminal always show:  the error infos:

you must in the android/dir  use this  command:
./gradlew --stop

Thursday, August 25, 2016

Notification using setFullScreenIntent() for BigTextStyle opening Activity automatically


昨天,遇到一个很头疼的问题。收到服务器的推送之后,APP重新启动了。但是,测试里面还不报错。

找了半天,找到问题的根源是因为 Notifacation 的问题:

用了 serFullScreenIntent();

这个方法在Android6.0 以下没有任何的问题。 但是在Android 6.0 中的,小米的手机上面,至于其他的手机,我只测试了三星没有问题。至于其他的手机,没有测过。

所以这个地方昨个版本判断就好了:
if(Build.VERSION.SDK_INT < 23){
    //Android 6.0 一下的版本没什么问题。 可以正常弹窗    mBuilder.setFullScreenIntent(pendingIntent, true);}else{
    //Android 6.0 小米貌似做了深度的定制,然后会重新启动APP. 三星的没有问题, 其他的机型不详}


待优化:   这个地方,这样做有点暴力。应该是,那个版本有问题就解决那个,我现在是把Android6.0 一棒子全部打死了。你可以尝试自己写一个工具类: 判定用户的手机是不是小米的手机, 如果是小米的手机,就不设置serFullScreenIntent();

解决问题很简单,但是,时间基本上都花在了寻找问题上。定位问题上面了!


很多的时候,都是这个样子。解决起来很快,但是定位问题比较的麻烦!

Wednesday, August 24, 2016

android how to resolve compile release APK, Proguard error: "Warning:"


  今天在打正式包的时候,突然报错了。 让我有点懵逼了。然后, 打正式包的时候报错了。

解决方案:
就是在代码混淆的时候,去掉这些 waring:


例如 :
# android 6.0 SDK 23 start-dontwarn com.nhaarman.listviewanimations.** { *; }
-dontwarn com.solok.datetime.** { *; }
-dontwarn com.tencent.connect.avatar.** { *; }
-dontwarn com.viewpagerindicator.LinePageIndicator.** { *; }
-dontwarn uk.co.senab.photoview.** { *; }



# android 6.0 SDK 23 end


OK 你看一下你的报错的信息里面,需要注释的 warning 一一添加就可以了!

这里解析一下:
因为,我把编译的版本提高了23,所以,就会出现一些工具方法过时的问题。因为, Android 6.0 废弃了很多没有用的方法。所以,导致了我们在适配6.0 的时候,很多依赖的第三方可能还没有适配6.0 ,所以出现了这么多的warning!

其实,很多的第三方的一些类,我们根本没有用到。这里直接在混淆文件里面直接 使用 dontwarn  就可以了,但是,如果自己的写的依赖库, 可能用到了 过时的方法。这个时候,我们就要手动的去修改依赖库的代码了!


这样说吧:
--dontwarn  只是不报错,只是治标不治本
修改原生代码,  根治这个问题


error info:

Initializing...
Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Note: the configuration refers to the unknown class 'com.facebook.react.uimanager.UIProp'
Note: the configuration refers to the unknown class 'sun.misc.Unsafe'
Note: the configuration refers to the unknown class 'com.eallcn.rentagent.orm.SugarRecord'
      Maybe you meant the fully qualified name 'com.orm.SugarRecord'?
Note: the configuration refers to the unknown class 'com.eallcn.chow.entity.RepTrend'
      Maybe you meant the fully qualified name 'com.eallcn.rentagent.entity.common.RepTrend'?
Note: the configuration refers to the unknown class 'com.nhaarman.listviewanimations.itemmanipulation.dragdrop.DynamicListViewTestActivity'
Note: the configuration refers to the unknown class 'com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.SwipeTouchListenerTestActivity'
Note: the configuration refers to the unknown class 'se.emilsjolander.stickylistheaders.StickyListHeadersListView'
      Maybe you meant the fully qualified name 'com.eallcn.rentagent.widget.sticky.StickyListHeadersListView'?
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find superclass or interface se.emilsjolander.stickylistheaders.StickyListHeadersAdapter
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersAdapter
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersAdapter
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersAdapter
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersAdapter
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.appearance.StickyListHeadersAdapterDecorator: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.nhaarman.listviewanimations.util.StickyListHeadersListViewWrapper: can't find referenced class se.emilsjolander.stickylistheaders.StickyListHeadersListView
Warning: com.solok.datetime.WheelImageView: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath
Warning: com.solok.datetime.WheelView: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath
Warning: com.tencent.connect.avatar.c: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMath
Warning: com.viewpagerindicator.LinePageIndicator: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath
Warning: uk.co.senab.photoview.PhotoViewAttacher: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMath
Warning: uk.co.senab.photoview.gestures.CupcakeGestureDetector: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMath
Note: android.support.v4.media.IMediaBrowserServiceCallbacksAdapterApi21: can't find dynamically referenced class android.service.media.IMediaBrowserServiceCallbacks
Note: android.support.v4.media.IMediaBrowserServiceCallbacksAdapterApi21: can't find dynamically referenced class android.content.pm.ParceledListSlice
Note: android.support.v4.media.IMediaBrowserServiceCallbacksAdapterApi21$Stub: can't find dynamically referenced class android.service.media.IMediaBrowserServiceCallbacks$Stub
Note: android.support.v4.media.ParceledListSliceAdapterApi21: can't find dynamically referenced class android.content.pm.ParceledListSlice
Note: android.support.v4.text.ICUCompatApi23: can't find dynamically referenced class libcore.icu.ICU
Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
Note: android.support.v7.widget.DrawableUtils: can't find dynamically referenced class android.graphics.Insets
Note: com.alibaba.fastjson.parser.ParserConfig: can't find dynamically referenced class java.awt.Point
Note: com.alibaba.fastjson.parser.ParserConfig: can't find dynamically referenced class java.awt.Font
Note: com.alibaba.fastjson.parser.ParserConfig: can't find dynamically referenced class java.awt.Rectangle
Note: com.alibaba.fastjson.parser.ParserConfig: can't find dynamically referenced class java.awt.Color
Note: com.alibaba.fastjson.serializer.SerializeConfig: can't find dynamically referenced class java.awt.Color
Note: com.alibaba.fastjson.serializer.SerializeConfig: can't find dynamically referenced class java.awt.Font
Note: com.alibaba.fastjson.serializer.SerializeConfig: can't find dynamically referenced class java.awt.Point
Note: com.alibaba.fastjson.serializer.SerializeConfig: can't find dynamically referenced class java.awt.Rectangle
Note: com.baidu.location.b.d$a: can't find dynamically referenced class android.os.SystemProperties
Note: com.baidu.location.b.e: can't find dynamically referenced class android.os.storage.StorageVolume
Note: com.baidu.platform.comapi.util.e: can't find dynamically referenced class android.os.storage.StorageVolume
Note: com.facebook.common.webp.WebpSupportStatus: can't find dynamically referenced class com.facebook.webpsupport.WebpBitmapFactoryImpl
Note: com.facebook.imagepipeline.animated.factory.AnimatedFactoryProvider: can't find dynamically referenced class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImplSupport
Note: com.facebook.imagepipeline.animated.factory.AnimatedFactoryProvider: can't find dynamically referenced class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl
Note: com.facebook.imagepipeline.nativecode.WebpTranscoderFactory: can't find dynamically referenced class com.facebook.imagepipeline.nativecode.WebpTranscoderImpl
Note: com.google.common.util.concurrent.MoreExecutors: can't find dynamically referenced class com.google.appengine.api.ThreadManager
Note: com.google.common.util.concurrent.MoreExecutors: can't find dynamically referenced class com.google.apphosting.api.ApiProxy
Note: com.google.gson.internal.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
Note: com.hyphenate.chat.EMPushHelper: can't find dynamically referenced class com.google.android.gms.common.GooglePlayServicesUtil
Note: com.hyphenate.chat.EMPushHelper: can't find dynamically referenced class com.xiaomi.mipush.sdk.MiPushClient
Note: com.parse.ParseHttpClient: can't find dynamically referenced class com.squareup.okhttp.OkHttpClient
Note: com.sina.weibo.sdk.utils.AidTask: can't find dynamically referenced class android.os.SystemProperties
Note: com.tencent.mm.sdk.platformtools.NetStatusUtil: can't find dynamically referenced class android.app.ActivityManagerNative
Note: com.tencent.mm.sdk.platformtools.NetStatusUtil: can't find dynamically referenced class android.net.NetworkPolicyManager
Note: de.devland.esperandro.Esperandro: can't find dynamically referenced class de.devland.esperandro.serialization.GsonSerializer
Note: okhttp3.internal.platform.AndroidPlatform: can't find dynamically referenced class com.android.org.conscrypt.SSLParametersImpl
Note: okhttp3.internal.platform.AndroidPlatform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Note: okhttp3.internal.platform.Platform: can't find dynamically referenced class sun.security.ssl.SSLContextImpl
Note: org.jivesoftware.smack.XMPPConnection: can't find dynamically referenced class sun.security.pkcs11.SunPKCS11
Note: org.jivesoftware.smack.compression.JzlibInputOutputStream: can't find dynamically referenced class com.jcraft.jzlib.ZOutputStream
Note: org.jivesoftware.smack.compression.JzlibInputOutputStream: can't find dynamically referenced class com.jcraft.jzlib.ZInputStream
Note: there were 9 references to unknown classes.
      You should check your configuration for typos.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 38 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Warning: there were 21 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 6 unresolved references to library class members.
         You probably need to update the library versions.
         Alternatively, you may have to specify the option
         '-dontskipnonpubliclibraryclassmembers'.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForMlwRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForMlwRelease'.
> java.io.IOException: Please correct the above warnings first.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED


Tuesday, August 2, 2016

ProductFlavors 和 debug release

Android Studio  如果做了多个项目的区分, 就是你的项目,被多家公司使用,使用的包名不唯一。  这个时候,你没有办法通过名字区分  是正式版本 还是测试版本?

但是,有的时候 需求需要, 当你的测试包和正式包 包名一样的时候,你真的没有办法处理!

解决方案:

在build.gradle 中 使用 resValue

这样设置你的build.gradle
apply plugin: 'com.android.application'
android {
    println("===============  android")

    compileSdkVersion 23    buildToolsVersion "23.0.2"
    defaultConfig {

        println("===============  defaultConfig")

        applicationId "test.geekhades.com.productflavorsanddebug"        minSdkVersion 19        targetSdkVersion 23        versionCode 1        versionName "1.0"    }

    signingConfigs {

        debug {
            println("===============  signingConfigs.debug")

        }

        release {
            println("===============  signingConfigs.release")
        }
    }

    buildTypes {

        debug {
            println("===============  buildTypes.debug")

            applicationIdSuffix project.APP_IS_DEBUG            resValue 'string', 'app_name', "测试版"            buildConfigField "boolean", "IS_DEBUG", "true"            IS_RELEASE=false            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)
        }

        release {
            println("===============  buildTypes.release")

            minifyEnabled false            IS_RELEASE=true            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            buildConfigField "boolean", "IS_DEBUG", "false"            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }

    productFlavors {



        mlw {
            println("===============  productFlavors.mlw")

            //mlw  美丽屋            applicationId project.MLW_PACKAGE_NAME            versionCode Integer.parseInt(project.MLW_VERSION_NAME.replace(".",""))
            versionName project.MLW_VERSION_NAME            manifestPlaceholders = [umengHolder: "anzhi"]

            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            resValue 'string', 'app_name', "美丽屋经纪人"        }

        gjb {
            println("===============  productFlavors.gjb")

            //gjb  管家宝            applicationId project.GJB_PACKAGE_NAME            versionCode Integer.parseInt(project.GJB_VERSION_NAME.replace(".",""))
            versionName project.GJB_VERSION_NAME
            manifestPlaceholders = [umengHolder: "anzhi"]

            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            resValue 'string', 'app_name',  "管家宝"        }

    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0'}


在buildType.debug 中设置 app_name

这个时候设置的 debug的版本


在 ProductFlavors 中设置的是正式版本的label

解决!




Thursday, July 28, 2016

Activity 嵌套的Fragment onActivityResult() 没有调用

当我们在Activity 里面嵌套 fragment 的时候。 我们从fragment 跳转的别的Activity   startActivityForResult() ,返回的时候无法回调 Fragment 中的 onActivityResult() 

解决方案很简单:


在你的嵌套Fragment 中的Activity 分发一下 onActivityResult 即可:


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);    FragmentManager fragmentManager = getSupportFragmentManager();    List<Fragment> fragmentList = fragmentManager.getFragments();    if (fragmentList != null) {
        for (Fragment fragment : fragmentList) {
            fragment.onActivityResult(requestCode, resultCode, data);        }
    }
}



Wednesday, July 27, 2016

Android Viewpager 预加载

有的时候,我们为了保持App的流畅性,我们可能希望我们的APP 可以提前加载数据。这个时候可以使用ViewPager的预加载。

ViewPager 默认是加载2页的!

你可以设置
PRELOAD_NUMBER =3

你想设置多少根据实际情况

viewPager.setOffscreenPageLimit(PRELOAD_NUMBER);


关于懒加载:
但是有的时候,我们只想加载一页数据的时候,我们使用
viewPager.setOffscreenPageLimit(0);
这个是不行的。

个人测试过了。

关于懒加载,你Google一下有的是!

Tuesday, July 26, 2016

Android Gradle:resolve dependancies too slow?

我最近遇到这个问题。

you can see this link:

http://stackoverflow.com/questions/23837465/android-studio-stuck-on-gradle-resolve-dependancies-debugcompile-or-detac


I thinking that:  
1 The most question is the Internet.  Your company internet is too slow. For that when Android studio download  denpendances file spend much time! I often spend two hours in the company. But in my home just some minutes!

2  the second question
you add too many dependency to your program.

Monday, July 25, 2016

Android gradle 每次切换分支和同步第三方代码的时候 特别的缓慢?


最近,发现同步第三方依赖库的时候,太慢了! 我今天花了2个小时的时间同步第三方的依赖库。  平时开发我可以使用  offline 的方式来处理这种问题。 

但是,当我每次修改 依赖的时候,要同步依赖库,我不可能花费同样的时间来做这件事情,因为如果急着发包的话,你觉得老板会等你2个小时吗?

肯定不行,

今天,我查看了一下 

log  日志:



看到日志的时候,我发现,每一次同步代码的时候,都会去下载一次 .deal/libraries  下面的 保存了 所有依赖库的信息 如图:



.gitignore   file




解决方案:

在 .gitignore 删除 /.ideal   .ideal/libraries





之后清除一下 git 的缓存信息

git rm -r -f --cached ./

git add .

git push


这样子就可以了。



但是,我尝试了一下 在  不是 离线的状态下的   同步第三方依赖库, 她会自动的把 .ideal/libraries 所有的 信息删除了。 这也许是 AS 同步的策略吧!

同步,是为了 解决 依赖库版本修改的 问题。 这里,As  无法判断修改了那些 依赖库,索性直接删除了所有的依赖库的关联信息。 重新关联, 这个在网速好的情况下 没什么问题。但是,在网络很差的公司,比如我们公司 就是很蛋疼的问题。我也是醉了!


网络这个东西。 我已经跟老大反映了很长时间了。没有好的网速 做什么开发呀?

不吐槽了!












Thursday, July 14, 2016

有的时候 重写比改更快

看之前写的代码就像吃屎一样难。

其实,看别人写的代码,跟吃屎差不多。

就连自己几个月之前的代码也是一样的呀。真是醉了, 有的时候,看了半天也不知道为什么的时候,干脆就别看了,直接干掉吧。改成自己的风格。真是醉了,修改以前的代码,还不如自己的直接重写来的更快呢!

不是针对你,我是说在做的各位全他妈的是垃圾!

Sunday, June 12, 2016

how to use gradle compile to delete google-play-service ads module?

The way:

compile ('com.google.android.gms:play-services:9.0.2'){
exclude module: 'play-services-ads'
}

EditText设置/隐藏光标位置、选中文本和获取/清除焦点

有时候需要让光标显示在EditText的指定位置或者选中某些文本。同样,为了方便用户输入以提升用户体验,可能需要使EditText获得或失去焦点。
1. 设置光标到指定位置
1 
2 
EditText et  =  (EditText ) findViewById (R. id. etTest ) ; 
et. setSelection ( 2 ) ;
Android中EditText设置光标到指定位置
PS:当内容过多时,可通过设置光标位置来让该位置的内容显示在屏幕上。
2. 隐藏光标
1 
2 
3 
EditText et  =  (EditText ) findViewById (R. id. etTest ) ; 
//设置光标不显示,但不能设置光标颜色 
et. setCursorVisible ( false ) ;
3. 获得焦点时全选文本
1 
2 
EditText et  =  (EditText ) findViewById (R. id. etTest ) ; 
et. setSelectAllOnFocus ( true ) ;
Android中EditText获得焦点时全选文本
PS:此方法可用来在用户点击EditText时,选中默认内容。
4. 获取和失去焦点
1 
2 
3 
EditText et  =  (EditText ) findViewById (R. id. etTest ) ; 
et. requestFocus ( ) ;  //请求获取焦点 
et. clearFocus ( ) ;  //清除焦点