反编译工具:我一般用来快速progurd
jadx
gif录制
LICEcap+GIF Movice Gear
adb 连接问题
*1.*netstat -aon|findstr "5037"
*2.*tasklist|findstr "8156"
*3.*adb kill-server
*4.*adb start-server
svn+as 设置ignore
新建项目->设置ignore file->share project->commit
drawble着色
Drawable tintLeftIcon = DrawableCompat.wrap(icon);
DrawableCompat.setTint(tintLeftIcon, color);
获取字符宽度
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
获取屏幕内容高度
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Rect rect = new Rect();
getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(rect);
int toolbarHeight = getResources().getDimensionPixelSize(R.dimen.toolbar);
L.ii("view height:" + rect.height() + ",toolbar:" + toolbarHeight);
ViewGroup.LayoutParams params = bottomLayout.getLayoutParams();
params.height = rect.height() - toolbarHeight;
bottomLayout.setLayoutParams(params);
}
TextView添加圆形背景span
public class CircleSpan implements LineBackgroundSpan {
public static final float DEFAULT_RADIUS = 3;
private float radius;
private int color;
public CircleSpan(float radius, int color) {
this.radius = radius;
this.color = color;
}
@Override
public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
int oldColor = p.getColor();
if (color != 0) {
p.setColor(color);
}
c.drawCircle((left + right) / 2, (bottom + top) / 2, Math.min(bottom, right) / 2, p);
p.setColor(oldColor);
}
}
google地图文字marker
private Bitmap generateTextBitmap(String text, int textSize) {
Paint paint = new Paint();
paint.setTextSize(textSize);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
int x = 20;
int y = 20;
Bitmap.Config conf = Bitmap.Config.ARGB_4444;
Bitmap bmp = Bitmap.createBitmap(bounds.width() + x, bounds.height() + y, conf);
Canvas canvas = new Canvas(bmp);
paint.setColor(Color.parseColor(Constants.MATERIAL));
canvas.drawText(text, x / 2, bounds.height() + y / 2, paint);
return bmp;
}
FragmentPagerAdapter更新问题
notity-getItemPos-return NONE-instanceItem-(有缓存set数据)-(无缓存new fragment)
public class DevicePagerAdapter extends FragmentPagerAdapter {
private List<DeviceInfo> data;
private Context context;
public DevicePagerAdapter(FragmentManager fm, Context context, List<DeviceInfo> list) {
super(fm);
this.context = context;
this.data = list;
}
public void update(List<DeviceInfo> list) {
data.clear();
data.addAll(list);
this.notifyDataSetChanged();
}
public List<DeviceInfo> getAll() {
return this.data;
}
public DeviceInfo getItemData(int pos) {
return data.get(pos);
}
@Override
public Fragment getItem(int position) {
DeviceTabFragment fragment = new DeviceTabFragment();
fragment.setListener((HomeBaseActivity) context);
return fragment;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
DeviceTabFragment f = (DeviceTabFragment) super.instantiateItem(container, position);
f.setInfo(data.get(position));
return f;
}
@Override
public int getCount() {
return data.size();
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
public View getTabView(int position) {
DeviceInfo deviceInfo = data.get(position);
View view = LayoutInflater.from(context).inflate(R.layout.common_tab_header, null);
ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
TextView title = (TextView) view.findViewById(R.id.header_title);
icon.setImageResource(deviceInfo.getSelectorDrawable());
title.setText(deviceInfo.getShortName());
return view;
}
}
TabLayout
1.修改拦截tab点击事件
onTabClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = (int) v.getTag();
TabLayout.Tab tab = tabLayout.getTabAt(pos);
if (tab != null) {
tab.select();
DeviceInfo info = data.get(pos);
moveCenter(info.getUid());
}
}
};
tabLayout.setupWithViewPager(viewPager);
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
tab.setCustomView(adapter.getTabView(i));
View tabView = (View) tab.getCustomView().getParent();
tabView.setTag(i);
tabView.setOnClickListener(onTabClickListener);
}
if (!isDataNull) {
tabLayout.getTabAt(lastSelectedPos).getCustomView().setSelected(true);
viewPager.setCurrentItem(lastSelectedPos);
loadAddress(list.get(0));
}
日常项目配置
1.gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
android.useDeprecatedNdk=true
#keystore
KEYSTORE_FILE=D\:\\devWork\\keystore\\jzb_release.jks
KEYSTORE_PASSWORD=123456
KEY_ALIAS=key
KEY_PASSWORD=123456
2.build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.uu.uu"
minSdkVersion 15
targetSdkVersion 22
versionCode 15
versionName "2.2.0"
// manifestPlaceholders = [app_label: "@string/app_name"]
ndk {
moduleName "protocolParser"
stl "c++_static"
setcFlags "-std=c++11"
ldLibs "atomic"
}
}
/* productFlavors {
local {
applicationId "com.ybit.jzb"
buildConfigField 'String', 'API_URL', '"http://192.168.2.177:9900/assets/"'
resValue "string", "app_name", "Jzb"
}
us {
applicationId "com.ybit.jzb.us"
buildConfigField 'String', 'API_URL', '"http://183.233.129.45:9900/assets/"'
resValue "string", "app_name", "Jzb_us"
}
za {
applicationId "com.ybit.jzb.za"
buildConfigField 'String', 'API_URL', '"http://gissetsa.gigaiot.com:9900/assets/"'
resValue "string", "app_name", "Jzb_za"
}
}*/
signingConfigs {
debug {
storeFile file("D:/devWork/keystore/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file(KEYSTORE_FILE)
storePassword KEYSTORE_PASSWORD
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
}
}
buildTypes {
debug {
buildConfigField "boolean", "LOG_DEBUG", "true"
manifestPlaceholders = [baiduMapKey: "lGOttbnLskUmWPTHHahoI8bz", googleMapKey: "AIzaSyCvl4cEojxrrD-oH_hMPkUHY_6FU0POohM"]
versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled true
shrinkResources false
signingConfig signingConfigs.debug
applicationVariants.all { variant ->
variant.outputs.each { output ->
def date = new Date();
def formattedDate = date.format('MMdd')
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-debug", "-debug-" + formattedDate)
)
}
}
}
release {
buildConfigField "boolean", "LOG_DEBUG", "false"
manifestPlaceholders = [baiduMapKey: "sPCYeXc7uc4BRaGc0Flewh4Y", googleMapKey: "AIzaSyCvl4cEojxrrD-oH_hMPkUHY_6FU0POohM"]
zipAlignEnabled true
shrinkResources true //去除无用的资源
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def date = new Date();
def formattedDate = date.format('MMdd')
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-release", "-release-" + formattedDate)
)
}
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dexOptions {
jumboMode = true
}
lintOptions {
abortOnError false
}
}
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':materialCalendarView')
compile project(':seekBarHint')
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:percent:23.3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.orhanobut:logger:1.11'
// compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
//osm
compile(name: 'osmbonuspack_v5.3', ext: 'aar')
compile 'org.osmdroid:osmdroid-android:4.3'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'
compile 'org.apache.commons:commons-lang3:3.3.2'
//baidu
compile files('libs/BaiduLBS_Android.jar')
compile 'net.danlew:android.joda:2.8.2'
compile 'de.greenrobot:eventbus:2.4.0'
//network sqlite3 debug
compile 'com.facebook.stetho:stetho:1.2.0'
//google map
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.github.jakob-grabner:Circle-Progress-View:v1.2.9'
}
apply plugin: 'com.google.gms.google-services'