-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
587 lines (434 loc) · 29.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>刘彬的个人博客</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="刘彬的个人博客">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="刘彬的个人博客">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="刘彬的个人博客">
<meta name="twitter:description">
<link rel="alternative" href="/atom.xml" title="刘彬的个人博客" type="application/atom+xml">
<link rel="icon" href="/favicon.png">
<link rel="stylesheet" href="/css/style.css" type="text/css">
</head>
<body>
<div id="container">
<div class="left-col">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img lazy-src="img/autor.png" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">LiuBin</a></h1>
</hgroup>
<div class="switch-btn">
<div class="icon">
<div class="icon-ctn">
<div class="icon-wrap icon-house" data-idx="0">
<div class="birdhouse"></div>
<div class="birdhouse_holes"></div>
</div>
<div class="icon-wrap icon-ribbon hide" data-idx="1">
<div class="ribbon"></div>
</div>
<div class="icon-wrap icon-link hide" data-idx="2">
<div class="loopback_l"></div>
<div class="loopback_r"></div>
</div>
<div class="icon-wrap icon-me hide" data-idx="3">
<div class="user"></div>
<div class="shoulder"></div>
</div>
</div>
</div>
<div class="tips-box hide">
<div class="tips-arrow"></div>
<ul class="tips-inner">
<li>菜单</li>
<li>标签</li>
<li>友情链接</li>
<li>关于我</li>
</ul>
</div>
</div>
<div class="switch-area">
<div class="switch-wrap">
<section class="switch-part switch-part1">
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
<li><a href="/tags/随笔">随笔</a></li>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="/#" title="github">github</a>
<a class="weibo" target="_blank" href="/#" title="weibo">weibo</a>
<a class="rss" target="_blank" href="/#" title="rss">rss</a>
<a class="zhihu" target="_blank" href="/#" title="zhihu">zhihu</a>
</div>
</nav>
</section>
<section class="switch-part switch-part2">
<div class="widget tagcloud" id="js-tagcloud">
</div>
</section>
<section class="switch-part switch-part3">
<div id="js-friends">
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">奥巴马的博客</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">卡卡的美丽传说</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">本泽马的博客</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">吉格斯的博客</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">习大大大不同</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">托蒂的博客</a>
</div>
</section>
<section class="switch-part switch-part4">
<div id="js-aboutme">je t'aime,je t'adore</div>
</section>
</div>
</div>
</header>
</div>
</div>
<div class="mid-col">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"></div>
<h1 class="header-author js-mobile-header hide">LiuBin</h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img lazy-src="img/autor.png" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author">LiuBin</h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
<li><a href="/tags/随笔">随笔</a></li>
<div class="clearfix"></div>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="/#" title="github">github</a>
<a class="weibo" target="_blank" href="/#" title="weibo">weibo</a>
<a class="rss" target="_blank" href="/#" title="rss">rss</a>
<a class="zhihu" target="_blank" href="/#" title="zhihu">zhihu</a>
</div>
</nav>
</header>
</div>
</nav>
<div class="body-wrap">
<article id="post-Android自定义View-绘制扇形实现圆形进度" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/03/04/Android自定义View-绘制扇形实现圆形进度/" class="article-date">
<time datetime="2016-03-04T02:45:03.266Z" itemprop="datePublished">2016-03-04</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<div class="article-entry" itemprop="articleBody">
<p><img src="https://lh3.googleusercontent.com/iSfjd4o67_oa-MJULqO1Cn1T1VaPaQm0bJPpCr9hooBIuT_rPXldrmJYQr3yjiUT4saoj7-nTZkUvN0t9Aff0yJbZ79kGWyMu3bgdrFDFkV3JC2vbJ_lV8k-1htaFF8uMV2FTqSkUnL7Rwl4FTueVZFO8wMvgwb3USMGMqwR4cxgM8yIdp1cBTFzKIa-EeCrZpkbU5x4_ySp1vsZkoiM_9XJQpRsD9l9Sq4Kl20HnIbS2jWu1l3fuEl69OVX5OZou0tr2jnCtZO9kUE2wnHSE-fiZAWJwCb8H8nb4pe13nMKupmMZISAgxWColCBvqBfmDWxvR8oO7vAukaq2z67BhMx7gSdw8KKBKcT5p8t2mPhdk_YYnM1T0lUftRHE1VbbHW3O-ElKV9Q8ScuLSFKDNry-sXDIqrpTiQh3LZFK5vrjd49E571jrPeASCJ-dOU8uY8ck74ATPqXtQ9qLKIpAxNDwF2r5BT0Ar_BaPFjTG3A8dQamyxEDsJJs8IT72hv_rjH1b9bTBWlFEGketGA6H_BgNZ-4FaFbvQU_QhZemE8UCtG6RIdFE-UHykcZv6aDY=w432-h768-no" alt=""><br><img src="https://lh3.googleusercontent.com/vafiwosLnh_F8IibzAFjGjT4tMw5WUYkWqlUrLS-7Vq3htTX1npXp9kGAleFjv8rkDpZ9VuiZw0JH91kmmnhPdN4afwl8Lcde3LROtLqaVCjE80ygKlkVgmtwnMEPWNWO25vunchvvLgrB8pGhxa278xL0ZfVUUUC03ATGO5GcAkGgMDvb8g9rPzjw6b5LG2QJgECUw0igUgGqxtIJASyT-1qyC_VrkGJaoOW6IPyKr4T-AjpP2FSubL_LE8S5Xva6QZKXKj0KEE4d5o-_KcH6nItpLErmyjK8NLvy792Gn8GHjH19NdypHBc_v5FooHzfmz0Mh5AhGSi0PYsHX_cIkkaPMf7daMT3aGR9koWl9pOcT5U2fQuo5CbGDo6u_Heu_Bdh04v4bwfcb7ruOTvcaMiazk3a-kxNXuA-4dkgOaPdq8YLozlOfETM6dS0a72anKVJQZEsMsM6HWCKZMyM8yutT2HqdvH6s_LRJ1Luke1nas2dEFGeOtqeB15iuSk7tKeg_cgQa0pP95Imu2b0isizwwGmPj4PIM8xwfbVeBL_Kymx17EVcG-sNONT4DWyQ=w432-h768-no" alt=""></p>
<p>先上图,这是要实现的效果,根据音量的大小中间的进度调节。麦克风部分是透明的,所以原理就是在蒙层的底部画白色的扇形。如下图所示</p>
<p><img src="https://lh3.googleusercontent.com/bOnxmg6z8xaj44PMrT4tuiowIHDTHMem_0utpvXm31ndAYmNv7hCbvaPeFGpIftNkRKW5VpxqtVXXfDk0Hykd3EhNH_3A-sQGDlP5sVmvd7gIFolOvT8Ogwdc21tlsjOykRDn5Ly7HB-xhTLS31KFR62gTPp4UPVa2GewT5cC1ZxZCGEFNQ1Ls-CTylx9jFf34r77fPq69cEiQuWFSQ4FC5-X-_c5sehspK_au1_p6Nevm8fwKVRpHR72b6M2lbbji4bDlY3xUBpo5HAwXdsq-Q-jgfmeZZjgerd02hGVPuszHaAWyn-fP_DKKzTvVGiU0RmhqNSiU4uSgEJEFfnEIlpJuVJ-J5X7ekydxLWomdKxODAMvnAR3EDfffqK3RUm4DHDatUP90NHzu1OM7TzNukrsPpbQZ_Vt4KcPVPk1nzW9ZGKXIa9SIq35tYz6fAILU51nbVpuVkWzNXXbw980HuAhOUYOlY45NP7FP2ZKgLteT2Skd71i4snZ1pmn6jl_1cvBP-C34666Vq2c8zfMpQ51iRObTrFCCYEyCvfelGWK-dEGsOXX5bpbLTbMypFIc=w783-h303-no" alt=""></p>
<p>这样就能实现圆形像水瓮一样的进度。<br>实现方法:<br>通过Canvas的drawArc方法实现。<br>public void drawArc(@NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter ,<br> @NonNull Paint paint)<br>oval 指定圆弧的外轮廓矩形区域<br>startAngle 开始的角度<br>sweepAngle 扫过的角度<br>useCenter 是否使用圆心,true为使用,画扇形的时候使用,false不使用,画上图类型的图形时应不使用圆心<br>paint 画笔<br>关于起始角度:水平的右侧为0度,顺时针增加,0度上方的度数可以写作-30度,也可以是330度<br>关于扫过角度:如果要画左侧与右侧水平的扇形,若起始角度为x,扫过角度为y,则y=(90-x)*2;</p>
<p><img src="https://lh3.googleusercontent.com/EgAvI61T8tbBq0Ld2AAO1r0lQXM7SCC5kHWeBu_7BD7S-47xouZ8-ie0oNELyWBmd_IjoxVTKa4yE0FOA_blmCCbsIE6AmRF2r4ilCw19wAw3VkiVXvB7PJUCJUv_WI5KuIKvimepUmL1oIcv6sqtDvSIXe9kU1nPclEWsfO6LDeEHwZhyVjAy-EbHGPcCqWXB64XOCzW7LSzat-gdJkLJctf8jSUsB1mJp9yLGrTjifguKTSp2biwZsFuNzlXS2ijpNnp4QPnGUi2XETgcgkVYKa6JIMcrW8WcPkV0LuN0BTt8lhXkGw_jNPbmZfBbmVHXeOYN8oDSV-DXsZS1eBuDBZyD9IcC6CgqBNjlRd1EFdUoxujH5I2raUTqpYtxTU00r3qz0O4rdb4zxXS9QCwikvkD7oQ8lSMcaJWqBwpKIyF9Dv_iULPyFqMqgC01_4OiRqRia7gmIzBZNHAUYIfBu-hWcCXuAfokreSKoIC0GCKDIi9gjzwvyzJeA2bnzJf-75eYQSMptD-XvgbepEq9TESpP5PavDvMHfQX1U7a_lAEJ9wOF_uu8Ob-Kk2mIxXw=w312-h181-no" alt=""></p>
<p><img src="https://lh3.googleusercontent.com/71_pfSu-pF9q3UbqOPCM12kB-P3_e8bsTv9HGmbU4pA8bh0GMNoJM8NoEqLE3eEFqU9q_XrP6UPVm_Sc1B6nFkrfTerswW02hdajIe59JPDrCptZxCAT7L7uNiZ1ghIQz-Q60qu5aWeC14Qwak9IcKwUOK9I1MK5XaNrsNTsCmE-S4zggGRbqa1F1N7Cj02gScLhPm2zhb7oFwrFqwGdtLWiHkJqnPDmkdoyYaGWRTVOF5Cww5dihPoRqjTS7phzihe6OJ1DqcXEI06A-cr6bSujCAPfzVa6UuUh-60PxJCufeaIJxT5NMfwkrsrpbWDoqL3rHdfHBRh0b3G2OYPZDPLo_sXrz7s1zTWlLZqN3rG0rtcTH0yE9iqx71gN-LuN4qs4zt1s2yZhVwnp-X1icZuNE6t3Veem1rLFnRiFcuSTHiNNtn19-NIlUiPEErSuHtvGNKkEWyBw4mozLqIYXP8rdlSRoxlzEXvUcHJYdmsYRaMLkVvWsAxhLkc_T4fJ4CZXfmBcstM9RbBSB5zUPrxMpXDNRnMePPTO6LJKyzG4YqBt8xuWqNM8qfco_p2qRE=w1227-h795-no" alt=""></p>
<p>核心代码<br>@Override<br>protected void onDraw(Canvas canvas) {<br> super .onDraw(canvas);<br> // 创建画笔<br> Paint paint = new Paint();<br> paint.setColor(Color. BLUE);<br> paint.setStrokeJoin(Paint.Join. ROUND);<br> paint.setStrokeCap(Paint.Cap. ROUND);<br> paint.setStyle(Paint.Style. FILL);</p>
<pre><code>RectF <span class="built_in">rect</span> = <span class="keyword">new</span> RectF(<span class="number">0</span> , <span class="number">0</span>, getMeasuredWidth(), getMeasuredHeight()) ;
<span class="built_in">int</span> a = - <span class="number">45</span>;
canvas.drawArc(<span class="built_in">rect</span> , <span class="comment">//弧线所使用的矩形区域大小</span>
a , <span class="comment">//开始角度</span>
( <span class="number">90</span> - a) * <span class="number">2</span> , <span class="comment">//扫过的角度</span>
<span class="keyword">false</span>, <span class="comment">//是否使用中心</span>
paint) ;
</code></pre><p>}</p>
<p>根据传值设置进度<br>设进度总和为100,当前进度为current,该图形起始的角度为90度,最大的角度为-90度,所以角度总和为180度,设当前current对应的起始角度为y,current为x<br>则起始角度y=90-(x/100)*180<br>代码如下<br>@Override<br>protected void onDraw(Canvas canvas) {<br> super .onDraw(canvas);<br> // 创建画笔<br> if (mPaint == null )<br> mPaint = new Paint();<br> mPaint .setColor(Color.WHITE);</p>
<pre><code><span class="keyword">if</span> ( mProgress > MAX_VOLUME) {
mProgress = MAX_VOLUME;
}
<span class="comment">// 得到当前音量占最大音量的百分比</span>
<span class="keyword">double</span> percent = ((<span class="keyword">double</span>) mProgress) / MAX_VOLUME;
<span class="comment">// 得到当前音量画扇形时从起始角度应该转过的角度</span>
<span class="keyword">double</span> degree = volume_sum_degree * percent ;
<span class="comment">// 画扇形时的起始角度</span>
<span class="keyword">double</span> drawStartDegree = volume_down_degree - degree ;
RectF <span class="built_in">rect</span> = <span class="keyword">new</span> RectF(<span class="number">0</span> , <span class="number">0</span>, getMeasuredWidth(), getMeasuredHeight()) ;
canvas.drawArc(<span class="built_in">rect</span> , <span class="comment">//弧线所使用的矩形区域大小</span>
( <span class="built_in">float</span>) drawStartDegree, <span class="comment">//开始角度</span>
( <span class="built_in">float</span>) ((<span class="number">90</span> - drawStartDegree) * <span class="number">2</span>) , <span class="comment">//扫过的角度</span>
<span class="keyword">false</span>, <span class="comment">//是否使用中心</span>
mPaint );
</code></pre><p>}</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-2015.7.21-create-my-blog" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/09/09/2015.7.21-create-my-blog/" class="article-date">
<time datetime="2015-09-09T10:31:57.420Z" itemprop="datePublished">2015-09-09</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2015/09/09/2015.7.21-create-my-blog/">使用GitHub-Pages和Hexo搭建自己的个人博客</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="使用GitHub-Pages和Hexo搭建自己的个人博客">使用GitHub-Pages和Hexo搭建自己的个人博客</h2><hr>
<ul>
<li>公司使用GitHub托管代码,无意间发现有Pages这样一个东东,搭建博客再好不过。GitHub提供了Pages功能,允许用户自定义项目主页,用于替代默认的源码列表。所以,github Pages可以被认为是用户编写的、托管在github上的静态网页。相关介绍可以看其官网<a href="https://pages.github.com/" target="_blank" rel="external">GithubPages官网主页</a>上面有简单的介绍和教程,可以研读一下。</li>
<li>Hexo是什么,A fast, simple & powerful blog framework,一个简单便捷并且很强大的博客框架。支持MarkDown语法并提供很多个性化的主题,使用起来也比较简单,与Pages搭配搭建自己的个人主页是一个不错的选择。</li>
</ul>
<p>下面简介一下自己的简单搭建过程:<br><strong>工具原料(需要自己安装的和注册的账号等)</strong></p>
<ul>
<li>Git <a href="http://msysgit.github.io/" target="_blank" rel="external">官网地址</a></li>
<li>Node.js<a href="https://nodejs.org/" target="_blank" rel="external">Node.js官网地址</a></li>
<li>GitHub账号</li>
</ul>
<p>安装过程</p>
<ul>
<li>Hexo安装及初始化过程</li>
</ul>
<blockquote>
<p>打开git-bash<br>npm install hexo-cli -g<br>hexo init blog<br>cd blog<br>npm install<br>hexo server<br>hexo server是将hexo服务跑起来,如果成功的话则可以访问<a href="http://localhost:4000/成功" target="_blank" rel="external">http://localhost:4000/成功</a><br>期间遇到过一次插件的问题显示的页面没有样式,重新安装下插件就好了<br>如果遇到插件相关的error请先执行下面的指令安装必须的plugins</p>
</blockquote>
<pre><code>npm <span class="operator"><span class="keyword">install</span> hexo-renderer-ejs <span class="comment">--save</span>
npm <span class="keyword">install</span> hexo-renderer-marked <span class="comment">--save</span>
npm <span class="keyword">install</span> hexo-renderer-stylus <span class="comment">--save</span></span>
</code></pre><ul>
<li>修改Hexo主题</li>
</ul>
<blockquote>
<p>打开blog目录下的_config.yml文件,该文件为配置文件,详细请看官网介绍<br>在blog目录下打开git-bash<br>在官网找到喜欢的主题并得到其github路径,执行类似命令<br><code>git clone https://github.com/wuchong/jacman.git themes/jacman</code><br>查看themes目录,会多一个jacman的目录<br>找到theme:字段, 修改后面的值为新的主题jacman<br>执行命令<code>hexo generate</code><br>执行命令<code>hexo server</code></p>
</blockquote>
<ul>
<li><p>分布到GitHub—配置SSHkey<br>分布到github的时候由于http的路径不能用,只能用ssh链接,所以需要配置sshkey,详细教程参照<br><a href="https://help.github.com/articles/generating-ssh-keys/" target="_blank" rel="external">https://help.github.com/articles/generating-ssh-keys/</a></p>
</li>
<li><p>分布到github-修改配置文件<br>在github新创建的Repository中找到ssh链接如图<br><img src="https://lh3.googleusercontent.com/33VssE6y0p4UNZkI3z9kvx60mH-efWRnq-Vrp500rg=s0" alt="enter image description here" title="QQ截图20150721155733.png"></p>
</li>
</ul>
<pre><code><span class="attribute">deploy</span>:
<span class="attribute">type</span>: git
<span class="attribute">repository</span>: git<span class="variable">@github</span>.<span class="attribute">com</span>:lb0820ynn/lb0820ynn.github.io.git
<span class="attribute">branch</span>: master
</code></pre><ul>
<li>分布到github-执行指令</li>
</ul>
<pre><code><span class="title">hexo</span> clean
hexo generate
hexo deploy
</code></pre>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-多渠道打包-2015.9.9" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2015/09/09/多渠道打包-2015.9.9/" class="article-date">
<time datetime="2015-09-09T10:29:35.650Z" itemprop="datePublished">2015-09-09</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<div class="article-entry" itemprop="articleBody">
<h2 id="Android_Studio多渠道打包及自定义打包名称">Android Studio多渠道打包及自定义打包名称</h2><p>作为Android开发,在项目上线的时候多数会遇到多渠道包的情况,,因为国内Android市场分发渠道太多,经常一个Apk需要打十几个到几十个渠道包,还好Gradle可以帮我们解决这个问题。</p>
<h4 id="Umeng多渠道打包">Umeng多渠道打包</h4><p>以Umeng统计为例,清单文件中会有这样一段</p>
<blockquote>
<pre><code><meta-data
android:<span class="variable">name=</span><span class="string">"UMENG_CHANNEL"</span>
android:<span class="variable">value=</span><span class="string">"<span class="subst">${UMENG_CHANNEL_VALUE}</span>"</span>/>
</code></pre></blockquote>
<p>value值就是渠道值,每个渠道包都有一个单独的值对应,所以需要这个值可以根据不同的渠道变化</p>
<ul>
<li>1.在清单文件umeng渠道value处配置,如下</li>
</ul>
<pre><code><meta-data
android:<span class="variable">name=</span><span class="string">"UMENG_CHANNEL"</span>
android:<span class="variable">value=</span><span class="string">"<span class="subst">${UMENG_CHANNEL_VALUE}</span>"</span>/>
</code></pre><ul>
<li>2.在app下的build.gradle中设置productFlavors</li>
</ul>
<pre><code><span class="title">productFlavors</span> {
<span class="title">GooglePlay</span> {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"649"</span>]
}
hiapk {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"101"</span>]
}
shichang91 {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"102"</span>]
}
gfan {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"103"</span>]
}
shichang360 {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"104"</span>]
}
qq {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"105"</span>]
}
xiaomi {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"106"</span>]
}
goapk {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"107"</span>]
}
baidu {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"108"</span>]
}
appchina {
<span class="title">manifestPlaceholders</span> = [UMENG_CHANNEL_VALUE: <span class="string">"109"</span>]
}
}
</code></pre><ul>
<li>3.对于渠道值与其Name不一样的采取上面的方式,若一样可以采取下面的简单方式</li>
</ul>
<pre><code><span class="keyword">android </span>{
productFlavors {
xiaomi {}
_360 {}
<span class="keyword">baidu </span>{}
wandoujia {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
</code></pre><ul>
<li><p>4.这个时候在android studio的build中的Generate Signed Apk选项中的Flavors中就可以看到在productFlavors中添加的这些渠道,若全部打出的话则全部选定点击Finish即可</p>
</li>
<li><p>5.同样可以使用Gradle的命令方式来打包在AndroidStudio的命令行里面可以执行<code>gradlew assembleRelease</code>这句命令,(gradlew是gradle wrapper的意思,个人理解为AndroidStudio对Gradle在本地的一层包装)就可以慢慢等apk打包成功了。关于这个命令下面解释一下。</p>
</li>
</ul>
<h4 id="assemble_命令">assemble 命令</h4><pre><code>gradlew assembleDebug 编译并打<span class="keyword">Debug</span>包
gradlew assembleRelease 编译并打<span class="keyword">Release</span>的包
</code></pre><p>除此之外 assemble 还能和 Product Flavor 结合创建新的任务,其实 assemble 是和 Build Variants 一起结合使用的,而 Build Variants = Build Type + Product Flavor , 举个例子大家就明白了:</p>
<p>如果我们想打包wandoujia渠道的release版本,执行如下命令就好了:</p>
<p>./gradlew assembleWandoujiaRelease<br>如果我们只打wandoujia渠道版本,则:</p>
<p>./gradlew assembleWandoujia<br>此命令会生成wandoujia渠道的Release和Debug版本</p>
<p>同理我想打全部Release版本:</p>
<p>./gradlew assembleRelease<br>这条命令会把Product Flavor下的所有渠道的Release版本都打出来。<br>打出包的目录在这个位置<code>\app\build\outputs\apk</code></p>
<h4 id="自定义输出的Apk的包的名称">自定义输出的Apk的包的名称</h4><p>上线时候遇到一个问题,AndroidStudio打出来的Apk默认都是英文名字,但是上线的工作是运营MM负责,让他们对着英文的apk并准确的上线到各大Android市场,也是难为他们了。但几十个Apk需要自己一个个重命名为以汉字为名的apk,也是很难为我们的,所以gradle的强大之处就显现出来了,看下面代码。</p>
<pre><code>applicationVariants.all { variant ->
variant.outputs.<span class="keyword">each</span> { output ->
<span class="keyword">def</span> oldFile = output.outputFile
<span class="keyword">if</span> (variant.buildType.name.equals(<span class="string">'release'</span>)) {
<span class="keyword">def</span> releaseApkName = <span class="string">''</span>
<span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'uc'</span>)) {
releaseApkName = <span class="string">'UC'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'GooglePlay'</span>)) {
releaseApkName = <span class="string">'谷歌商店'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'hiapk'</span>)) {
releaseApkName = <span class="string">'安卓市场'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'shichang91'</span>)) {
releaseApkName = <span class="string">'91助手'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'gfan'</span>)) {
releaseApkName = <span class="string">'机锋网'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'shichang360'</span>)) {
releaseApkName = <span class="string">'360手机助手'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'qq'</span>)) {
releaseApkName = <span class="string">'应用宝(QQ市场)'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'xiaomi'</span>)) {
releaseApkName = <span class="string">'小米'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'goapk'</span>)) {
releaseApkName = <span class="string">'安智市场'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'baidu'</span>)) {
releaseApkName = <span class="string">"百度"</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'appchina'</span>)) {
releaseApkName = <span class="string">'应用汇市场'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'xcar'</span>)) {
releaseApkName = <span class="string">'M页面'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'other'</span>)) {
releaseApkName = <span class="string">'其他'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'sogou'</span>)) {
releaseApkName = <span class="string">'搜狗市场'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'jinshan'</span>)) {
releaseApkName = <span class="string">'金山手机助手'</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (variant.productFlavors[<span class="number">0</span>].name.equals(<span class="string">'leshangdian'</span>)) {
releaseApkName = <span class="string">'乐商店cpt'</span>
}
releaseApkName = releaseApkName + <span class="string">".apk"</span>
output.outputFile = <span class="keyword">new</span> <span class="keyword">File</span>(oldFile.parent, releaseApkName)
}
}
}
</code></pre><p>variant.productFlavors[0].name就是上面所写的productFlavor的Name<br>这段代码放在app下面的build.gradle文件下android标签里面。当然这还是最简单的应用,不过确实能节省一些时间,通过productFlavor还能实现每个渠道包某些更大方面的不同,包括包名,签名key之类的都可以实现。</p>
</div>
<div class="article-info article-info-index">
<div class="clearfix"></div>
</div>
</div>
</article>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2016 LiuBin
</div>
<div class="footer-right">
<a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
</div>
</div>
</div>
</footer>
</div>
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
<script>
var yiliaConfig = {
fancybox: true,
mathjax: true,
animate: true,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
open_in_new: false
}
</script>
<script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/js/main.js" type="text/javascript"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</div>
</body>
</html>