Waylan Punch

WP


  • Home

  • Categories

  • Tags

  • Archives

  • About

  • Commonweal 404

  • Search

基于LeanCloud Restful API的Retrofit编程

Posted on 2017-03-12 | | Visitors:

基于LeanCloud Restful API的Retrofit编程

BaaS提供商LeanCloud提供了Restful API,没有提供Retrofit使用教程。

  • 注册用户

注册API设计:

1
2
3
4
5
6
curl -X POST \
-H "X-LC-Id: y0crQpaNCKUq9WFaSMLByoKo-gzGzoHsz" \
-H "X-LC-Key: ihdOweBmtk9yrDbuPEbJfyBb" \
-H "Content-Type: application/json" \
-d '{"username":"hjiang","password":"f32@ds*@&dsa","phone":"18612340000"}' \
https://api.leancloud.cn/1.1/users

登录API设计:

1
2
3
4
5
6
curl -X POST \
-H "Content-Type: application/json" \
-H "X-LC-Id: y0crQpaNCKUq9WFaSMLByoKo-gzGzoHsz" \
-H "X-LC-Key: ihdOweBmtk9yrDbuPEbJfyBb" \
-d '{"username":"hjiang","password":"f32@ds*@&dsa"}' \
https://api.leancloud.cn/1.1/login
Read more »

ButterKnife vs RoboGuice

Posted on 2017-03-12 | | Visitors:

ButterKnife vs RoboGuice

当涉及到Android上的依赖注入(DI)类库的时候,存在不少的选择,我在公司项目中用了RoboGuice,现在非常后悔。最开始认为RoboGuice节约了大量的时间。较少的代码意味着较少的错误,较少的样板代码意味着可以把更多的时间放到应用的核心逻辑上。

比较 RoboGuice ButterKnife
所需的最少jar包 3 (roboguice-2.0.jar, javax.inject-1.jar and guice-3.0-no_aop.jar) 1 (butterknife-4.0.1.jar)
是否需要替代Activity 需要,RoboActivity替代Activity 不需要
与ActionBarSherlock的兼容性 兼容,需添加roboguice-sherlock-1.5.jar包到应用并且用RoboSherlockActivity替换SherlockActivity 兼容,不需要额外jars包
单击监听器的注入 不支持 支持
性能 运行时采取反射机制有性能影响 没有采取反射而使用了预编译技术,因为基于反射的DI非常占用资源和耗时
POJO注入 支持 不支持
Fragments注入 支持 支持
适配器注入 不支持 支持
代码协议 Apache License 2.0 Apache License 2.0
链接 Rroboguice Link Butterknife Link

Fragment操作宿主Activity

Posted on 2016-12-17 | | Visitors:

宿主 Activity 实现 Fragment 定义的对外接口 IOneFragmentClickListener,便可以实现 Fragment 调用 Activity 的功能。

public class OneFragment extends Fragment implements View.OnClickListener{

    private IOneFragmentClickListener clickListener;

    public interface IOneFragmentClickListener{
        void onOneFragmentClick();
    }

    public void setClickListener(IOneFragmentClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_one, null);
        contentView.findViewById(R.id.edt_one).setOnClickListener(this);
        return contentView;
    }

    @Override
    public void onClick(View v) {
        clickListener.onOneFragmentClick();
    }

}
Read more »

如何反编译apk文件

Posted on 2016-12-15 | | Visitors:

准备三个工具:Apktool、dex2jar、jd-gui

  • Apktool

    • 下载:downloads

    • 安装:install

      **Windows:**
      1.Download Windows wrapper script (Right click, Save Link As apktool.bat)
      2.Download apktool-2 (find newest here)
      3.Rename downloaded jar to apktool.jar
      4.Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
      5.If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
      6.Try running apktool via command prompt
      
    • 使用:documentation

Read more »

Visual Studio Code进行Python编程输出中文乱码问题

Posted on 2016-12-12 | | Visitors:

代码:

print(b'ABC'.decode('ascii'))
print( b'\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8'))

输出:

Output

解决方法:

import io
import sys
#改变标准输出的默认编码
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')

输出:

Output

即可。

WeakRefrence Demo

Posted on 2016-12-10 | | Visitors:

Strong reference(强引用)

在Java中,非静态内部类会在其整个生命周期中持有对它外部类的强引用。

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new MyAsyncTask(this).execute();
    }

    private class MyAsyncTask extends AsyncTask { 

        @Override
        protected Object doInBackground(Object[] params) {

            // 模拟耗时任务
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            return doSomeStuff();
        }
        private Object doSomeStuff() {
            return new Object();
        }
        @Override
        protected void onPostExecute(Object object) {
            super.onPostExecute(object);
            // 更新UI
        }
    }
}
Read more »

Android提供的下载类DownloadManager

Posted on 2016-10-18 | | Visitors:

Android提供的下载类DownloadManager


  • Usage
String downUrl = "http://downloads.jianshu.io/apps/haruki/JianShu-1.11.2.apk";


 /**获得系统下载器*/ 
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
/**设置下载地址*/ 
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downUrl));
/**设置下载文件的类型*/ 
request.setMimeType("application/vnd.android.package-archive");
/**设置下载存放的文件夹和文件名字*/ 
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "JianShu-1.11.2.apk");
/**设置下载时或者下载完成时,通知栏是否显示*/ 
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("Download");
/**执行下载,并返回任务唯一id*/ 
long enqueue = dm.enqueue(request);

透明的系统状态栏SystemBar

Posted on 2016-10-18 | | Visitors:

透明的系统状态栏SystemBar


  • values/styles.xml

    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <!-- Customize your theme here. -->
        </style>
    
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    
    </resources>
    
Read more »

使用AppCompat-21适配Material Design

Posted on 2016-09-30 | | Visitors:

使用AppCompat-21适配Material Design


设置compileSdkVersion为21

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.0"

    defaultConfig {
        applicationId "com.way.material"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
     ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.+'
}
Read more »

TextInput使用知识

Posted on 2016-09-26 | | Visitors:

TextInput使用知识


TextInput

XML属性&常用方法

  • counterEnabled:false or true,用于设置字符计数器的开启或关闭。

    对应方法:setCounterEnabled(boolean)

  • counterMaxLength:设置字符计数器的最大长度。(仅用于设置计数器最大值,并不影响文本实际能输入的最大长度)

    对应方法:setCounterMaxLength(int)

  • errorEnabled:false or true,用于设置错误提示是否开启。

    对应方法:setErrorEnabled(boolean)

Read more »
1234…7
Waylan Punch

Waylan Punch

Keep Calm And Code On.

66 posts
2 categories
66 tags
RSS
GitHub E-Mail Weibo StackOverflow
Links
  • StackOverflow
  • LeanCloud
  • 云栖社区
  • GitHub
  • 掘金网
  • 知乎
© 2014 — 2019 Waylan Punch
Powered by Hexo
|
Theme — NexT.Mist v5.1.4