text
stringlengths
9
39.2M
dir
stringlengths
25
226
lang
stringclasses
163 values
created_date
timestamp[s]
updated_date
timestamp[s]
repo_name
stringclasses
751 values
repo_full_name
stringclasses
752 values
star
int64
1.01k
183k
len_tokens
int64
1
18.5M
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[ neuron/.style={circle,draw,inner sep=0pt,minimum size=6mm} ] \foreach \y in {0,...,7} \node(i\y) [neuron] at (0,\y * 0.9 + 0.45) {}; \foreach \y in {0,...,8} \node(h1\y) [neuron] at (3,\y * 0.9) {}; \foreach \y in {0,...,8} \node(h2\y) [neuron] at (6,\y * 0.9) {}; \foreach \y in {0,...,8} \node(h3\y) [neuron] at (9,\y * 0.9) {}; \foreach \y in {0,...,3} \node(o\y) [neuron] at (12,\y * 0.9 + 2.25) {}; \node [above=0.5 of i7] {input layer}; \node [above=0.5 of h18] {hidden layer 1}; \node [above=0.5 of h28] {hidden layer 2}; \node [above=0.5 of h38] {hidden layer 3}; \node [above=0.5 of o3] {output layer}; \foreach \x in {0,...,7} \foreach \y in {0,...,8} \draw[->] (i\x) to (h1\y); \foreach \x in {0,...,8} \foreach \y in {0,...,8} \draw[->] (h1\x) to (h2\y); \foreach \x in {0,...,8} \foreach \y in {0,...,8} \draw[->] (h2\x) to (h3\y); \foreach \x in {0,...,8} \foreach \y in {0,...,3} \draw[->] (h3\x) to (o\y); \foreach \y in {0,...,3} \draw[->] (o\y) -- ++(1,0); \end{tikzpicture} \end{document} ```
/content/code_sandbox/images/tikz36.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
572
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[ neuron/.style={circle,draw,inner sep=0pt,minimum size=10mm}, font=\footnotesize ] \node(i) [neuron] {}; \node(o) [neuron,right=2 of i] {}; \draw[->] (i) -- node [above] { $\frac{\partial C}{\partial w} = a_{\rm in} \delta_{\rm out}$ } (o); \end{tikzpicture} \end{document} ```
/content/code_sandbox/images/tikz20.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
174
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[ neuron/.style={circle,draw,inner sep=0pt,minimum size=10mm}, font=\footnotesize ] \node (neuron) [neuron] {$b$}; \node (x2) [left=1.5 of neuron] {$x_2$}; \node (x1) [left=1.5 of neuron,yshift=1cm] {$x_1$}; \node (x3) [left=1.5 of neuron,yshift=-1cm] {$x_3$}; \node (output) [right=of neuron] {$a = \sigma(z)$}; \draw[->] (x1) to node [above,yshift=-3.5mm] {$w_1$} (neuron); \draw[->] (x2) to node [above,yshift=-3.5mm] {$w_2$} (neuron); \draw[->] (x3) to node [above,yshift=-3.5mm] {$w_3$} (neuron); \draw[->] (neuron) to (output); \end{tikzpicture} \end{document} ```
/content/code_sandbox/images/tikz29.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
324
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usepackage{pgfplots} \usetikzlibrary{positioning} \usepackage{cjkfonts} \input{../plots} \begin{document} \manipulateTwoTower{0.7}{0.5} \end{document} ```
/content/code_sandbox/images/the_two_towers.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
94
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usetikzlibrary{positioning} \usetikzlibrary{backgrounds,math} \input{../plots} \begin{document} \crossEntropyCostLearning{0.6}{0.9}{0.005}{300} \end{document} ```
/content/code_sandbox/images/saturation3-300.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
94
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ axis x line=middle, axis y line=left, ymin=-2.2, ymax=2.2, xmax=1.1, xlabel=$x$, xtick distance=1, declare function={ sigma(\z) = 1/(1 + exp(-\z)); f(\x,\h,\s,\e) = \h * (sigma(300 * (\x - \s)) - sigma(300 * (\x - \e))); }] \addplot[red!50,thick,domain=0.0:0.22,samples=51] { f(x, -1.3, 0.0, 0.2) }; \addplot[green!50,thick,domain=0.18:0.42,samples=51] { f(x, -1.8, 0.2, 0.4) }; \addplot[blue!50,thick,domain=0.38:0.62,samples=51] { f(x, -0.5, 0.4, 0.6) }; \addplot[violet!50,thick,domain=0.58:0.82,samples=51] { f(x, -0.9, 0.6, 0.8) }; \addplot[orange!50,thick,domain=0.78:0.99,samples=51] { f(x, 0.3, 0.8, 1.0) }; \end{axis} \end{tikzpicture} \end{document} ```
/content/code_sandbox/images/series_of_bumps.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
432
```postscript %!PS-Adobe-3.0 EPSF-3.0 %%Title: /home/zhanggyb/more_data1.eps %%Creator: matplotlib version 1.3.1, path_to_url %%CreationDate: Thu Feb 18 08:56:02 2016 %%Orientation: portrait %%BoundingBox: 13 175 598 616 %%EndComments %%BeginProlog /mpldict 8 dict def mpldict begin /m { moveto } bind def /l { lineto } bind def /r { rlineto } bind def /c { curveto } bind def /cl { closepath } bind def /box { m 1 index 0 r 0 exch r neg 0 r cl } bind def /clipbox { box clip newpath } bind def %!PS-Adobe-3.0 Resource-Font %%Title: DejaVu Sans %%Creator: Converted from TrueType to type 3 by PPR 25 dict begin /_d{bind def}bind def /_m{moveto}_d /_l{lineto}_d /_cl{closepath eofill}_d /_c{curveto}_d /_sc{7 -1 roll{setcachedevice}{pop pop pop pop pop pop}ifelse}_d /_e{exec}_d /FontName /DejaVuSans def /PaintType 0 def /FontMatrix[.001 0 0 .001 0 0]def /FontBBox[-1021 -415 1681 1167]def /FontType 3 def /Encoding [ /space /percent /parenleft /parenright /zero /one /two /three /four /five /six /seven /eight /nine /A /T /a /c /d /e /g /h /i /l /n /o /r /s /t /u /v /y /z ] def /FontInfo 10 dict dup begin /FamilyName (DejaVu Sans) def /FullName (DejaVu Sans) def /Weight (Book) def /Version (Version 2.34) def /ItalicAngle 0.0 def /isFixedPitch false def /UnderlinePosition -130 def /UnderlineThickness 90 def end readonly def /CharStrings 33 dict dup begin /space{318 0 0 0 0 0 _sc }_d /percent{{950 0 55 -13 895 742 _sc 727 321 _m 699 321 676 309 660 285 _c 644 261 636 227 636 184 _c 636 142 644 108 660 84 _c 676 60 699 48 727 48 _c 755 48 777 60 793 84 _c 809 108 817 142 817 184 _c 817 226 809 260 793 284 _c 777 308 755 321 727 321 _c 727 383 _m 778 383 819 365 849 329 _c 879 293 895 244 895 184 _c 895 123 879 75 849 40 _c 819 4 778 -13 727 -13 _c }_e{675 -13 633 4 603 40 _c 573 75 558 123 558 184 _c 558 245 573 293 603 329 _c 633 365 675 383 727 383 _c 223 680 _m 195 680 173 667 157 643 _c 141 619 133 586 133 544 _c 133 500 141 467 157 443 _c 173 419 195 407 223 407 _c 251 407 274 419 290 443 _c 306 467 314 500 314 544 _c 314 586 305 619 289 643 _c 273 667 251 680 223 680 _c 664 742 _m 742 742 _l 286 -13 _l }_e{208 -13 _l 664 742 _l 223 742 _m 274 742 315 724 346 688 _c 376 652 392 604 392 544 _c 392 482 376 434 346 398 _c 316 362 275 345 223 345 _c 171 345 130 362 100 398 _c 70 434 55 482 55 544 _c 55 604 70 652 100 688 _c 130 724 171 742 223 742 _c _cl}_e}_d /parenleft{390 0 86 -131 310 759 _sc 310 759 _m 266 683 234 609 213 536 _c 191 463 181 389 181 314 _c 181 238 191 164 213 91 _c 234 17 266 -56 310 -131 _c 232 -131 _l 183 -54 146 20 122 94 _c 98 168 86 241 86 314 _c 86 386 98 459 122 533 _c 146 607 182 682 232 759 _c 310 759 _l _cl}_d /parenright{390 0 80 -131 304 759 _sc 80 759 _m 158 759 _l 206 682 243 607 267 533 _c 291 459 304 386 304 314 _c 304 241 291 168 267 94 _c 243 20 206 -54 158 -131 _c 80 -131 _l 123 -56 155 17 177 91 _c 198 164 209 238 209 314 _c 209 389 198 463 177 536 _c 155 609 123 683 80 759 _c _cl}_d /zero{636 0 66 -13 570 742 _sc 318 664 _m 267 664 229 639 203 589 _c 177 539 165 464 165 364 _c 165 264 177 189 203 139 _c 229 89 267 64 318 64 _c 369 64 407 89 433 139 _c 458 189 471 264 471 364 _c 471 464 458 539 433 589 _c 407 639 369 664 318 664 _c 318 742 _m 399 742 461 709 505 645 _c 548 580 570 486 570 364 _c 570 241 548 147 505 83 _c 461 19 399 -13 318 -13 _c 236 -13 173 19 130 83 _c 87 147 66 241 66 364 _c 66 486 87 580 130 645 _c 173 709 236 742 318 742 _c _cl}_d /one{636 0 110 0 544 729 _sc 124 83 _m 285 83 _l 285 639 _l 110 604 _l 110 694 _l 284 729 _l 383 729 _l 383 83 _l 544 83 _l 544 0 _l 124 0 _l 124 83 _l _cl}_d /two{{636 0 73 0 536 742 _sc 192 83 _m 536 83 _l 536 0 _l 73 0 _l 73 83 _l 110 121 161 173 226 239 _c 290 304 331 346 348 365 _c 380 400 402 430 414 455 _c 426 479 433 504 433 528 _c 433 566 419 598 392 622 _c 365 646 330 659 286 659 _c 255 659 222 653 188 643 _c 154 632 117 616 78 594 _c 78 694 _l 118 710 155 722 189 730 _c 223 738 255 742 284 742 _c }_e{359 742 419 723 464 685 _c 509 647 532 597 532 534 _c 532 504 526 475 515 449 _c 504 422 484 390 454 354 _c 446 344 420 317 376 272 _c 332 227 271 164 192 83 _c _cl}_e}_d /three{{636 0 76 -13 556 742 _sc 406 393 _m 453 383 490 362 516 330 _c 542 298 556 258 556 212 _c 556 140 531 84 482 45 _c 432 6 362 -13 271 -13 _c 240 -13 208 -10 176 -4 _c 144 1 110 10 76 22 _c 76 117 _l 103 101 133 89 166 81 _c 198 73 232 69 268 69 _c 330 69 377 81 409 105 _c 441 129 458 165 458 212 _c 458 254 443 288 413 312 _c 383 336 341 349 287 349 _c }_e{202 349 _l 202 430 _l 291 430 _l 339 430 376 439 402 459 _c 428 478 441 506 441 543 _c 441 580 427 609 401 629 _c 374 649 336 659 287 659 _c 260 659 231 656 200 650 _c 169 644 135 635 98 623 _c 98 711 _l 135 721 170 729 203 734 _c 235 739 266 742 296 742 _c 370 742 429 725 473 691 _c 517 657 539 611 539 553 _c 539 513 527 479 504 451 _c 481 423 448 403 406 393 _c _cl}_e}_d /four{636 0 49 0 580 729 _sc 378 643 _m 129 254 _l 378 254 _l 378 643 _l 352 729 _m 476 729 _l 476 254 _l 580 254 _l 580 172 _l 476 172 _l 476 0 _l 378 0 _l 378 172 _l 49 172 _l 49 267 _l 352 729 _l _cl}_d /five{{636 0 77 -13 549 729 _sc 108 729 _m 495 729 _l 495 646 _l 198 646 _l 198 467 _l 212 472 227 476 241 478 _c 255 480 270 482 284 482 _c 365 482 429 459 477 415 _c 525 370 549 310 549 234 _c 549 155 524 94 475 51 _c 426 8 357 -13 269 -13 _c 238 -13 207 -10 175 -6 _c 143 -1 111 6 77 17 _c 77 116 _l 106 100 136 88 168 80 _c 199 72 232 69 267 69 _c }_e{323 69 368 83 401 113 _c 433 143 450 183 450 234 _c 450 284 433 324 401 354 _c 368 384 323 399 267 399 _c 241 399 214 396 188 390 _c 162 384 135 375 108 363 _c 108 729 _l _cl}_e}_d /six{{636 0 70 -13 573 742 _sc 330 404 _m 286 404 251 388 225 358 _c 199 328 186 286 186 234 _c 186 181 199 139 225 109 _c 251 79 286 64 330 64 _c 374 64 409 79 435 109 _c 461 139 474 181 474 234 _c 474 286 461 328 435 358 _c 409 388 374 404 330 404 _c 526 713 _m 526 623 _l 501 635 476 644 451 650 _c 425 656 400 659 376 659 _c 310 659 260 637 226 593 _c }_e{192 549 172 482 168 394 _c 187 422 211 444 240 459 _c 269 474 301 482 336 482 _c 409 482 467 459 509 415 _c 551 371 573 310 573 234 _c 573 159 550 99 506 54 _c 462 9 403 -13 330 -13 _c 246 -13 181 19 137 83 _c 92 147 70 241 70 364 _c 70 479 97 571 152 639 _c 206 707 280 742 372 742 _c 396 742 421 739 447 735 _c 472 730 498 723 526 713 _c _cl}_e}_d /seven{636 0 82 0 551 729 _sc 82 729 _m 551 729 _l 551 687 _l 286 0 _l 183 0 _l 432 646 _l 82 646 _l 82 729 _l _cl}_d /eight{{636 0 68 -13 568 742 _sc 318 346 _m 271 346 234 333 207 308 _c 180 283 167 249 167 205 _c 167 161 180 126 207 101 _c 234 76 271 64 318 64 _c 364 64 401 76 428 102 _c 455 127 469 161 469 205 _c 469 249 455 283 429 308 _c 402 333 365 346 318 346 _c 219 388 _m 177 398 144 418 120 447 _c 96 476 85 511 85 553 _c 85 611 105 657 147 691 _c 188 725 245 742 318 742 _c }_e{390 742 447 725 489 691 _c 530 657 551 611 551 553 _c 551 511 539 476 515 447 _c 491 418 459 398 417 388 _c 464 377 501 355 528 323 _c 554 291 568 251 568 205 _c 568 134 546 80 503 43 _c 459 5 398 -13 318 -13 _c 237 -13 175 5 132 43 _c 89 80 68 134 68 205 _c 68 251 81 291 108 323 _c 134 355 171 377 219 388 _c 183 544 _m 183 506 194 476 218 455 _c }_e{242 434 275 424 318 424 _c 360 424 393 434 417 455 _c 441 476 453 506 453 544 _c 453 582 441 611 417 632 _c 393 653 360 664 318 664 _c 275 664 242 653 218 632 _c 194 611 183 582 183 544 _c _cl}_e}_d /nine{{636 0 63 -13 566 742 _sc 110 15 _m 110 105 _l 134 93 159 84 185 78 _c 210 72 235 69 260 69 _c 324 69 374 90 408 134 _c 442 178 462 244 468 334 _c 448 306 424 284 396 269 _c 367 254 335 247 300 247 _c 226 247 168 269 126 313 _c 84 357 63 417 63 494 _c 63 568 85 628 129 674 _c 173 719 232 742 306 742 _c 390 742 455 709 499 645 _c 543 580 566 486 566 364 _c }_e{566 248 538 157 484 89 _c 429 21 356 -13 264 -13 _c 239 -13 214 -10 189 -6 _c 163 -2 137 5 110 15 _c 306 324 _m 350 324 385 339 411 369 _c 437 399 450 441 450 494 _c 450 546 437 588 411 618 _c 385 648 350 664 306 664 _c 262 664 227 648 201 618 _c 175 588 162 546 162 494 _c 162 441 175 399 201 369 _c 227 339 262 324 306 324 _c _cl}_e}_d /A{684 0 8 0 676 729 _sc 342 632 _m 208 269 _l 476 269 _l 342 632 _l 286 729 _m 398 729 _l 676 0 _l 573 0 _l 507 187 _l 178 187 _l 112 0 _l 8 0 _l 286 729 _l _cl}_d /T{611 0 -2 0 614 729 _sc -2 729 _m 614 729 _l 614 646 _l 355 646 _l 355 0 _l 256 0 _l 256 646 _l -2 646 _l -2 729 _l _cl}_d /a{{613 0 60 -13 522 560 _sc 343 275 _m 270 275 220 266 192 250 _c 164 233 150 205 150 165 _c 150 133 160 107 181 89 _c 202 70 231 61 267 61 _c 317 61 357 78 387 114 _c 417 149 432 196 432 255 _c 432 275 _l 343 275 _l 522 312 _m 522 0 _l 432 0 _l 432 83 _l 411 49 385 25 355 10 _c 325 -5 287 -13 243 -13 _c 187 -13 142 2 109 33 _c 76 64 60 106 60 159 _c }_e{60 220 80 266 122 298 _c 163 329 224 345 306 345 _c 432 345 _l 432 354 _l 432 395 418 427 391 450 _c 364 472 326 484 277 484 _c 245 484 215 480 185 472 _c 155 464 127 453 100 439 _c 100 522 _l 132 534 164 544 195 550 _c 226 556 256 560 286 560 _c 365 560 424 539 463 498 _c 502 457 522 395 522 312 _c _cl}_e}_d /c{{550 0 55 -13 488 560 _sc 488 526 _m 488 442 _l 462 456 437 466 411 473 _c 385 480 360 484 334 484 _c 276 484 230 465 198 428 _c 166 391 150 339 150 273 _c 150 206 166 154 198 117 _c 230 80 276 62 334 62 _c 360 62 385 65 411 72 _c 437 79 462 90 488 104 _c 488 21 _l 462 9 436 0 410 -5 _c 383 -10 354 -13 324 -13 _c 242 -13 176 12 128 64 _c }_e{79 115 55 185 55 273 _c 55 362 79 432 128 483 _c 177 534 244 560 330 560 _c 358 560 385 557 411 551 _c 437 545 463 537 488 526 _c _cl}_e}_d /d{{635 0 55 -13 544 760 _sc 454 464 _m 454 760 _l 544 760 _l 544 0 _l 454 0 _l 454 82 _l 435 49 411 25 382 10 _c 353 -5 319 -13 279 -13 _c 213 -13 159 13 117 65 _c 75 117 55 187 55 273 _c 55 359 75 428 117 481 _c 159 533 213 560 279 560 _c 319 560 353 552 382 536 _c 411 520 435 496 454 464 _c 148 273 _m 148 207 161 155 188 117 _c 215 79 253 61 301 61 _c }_e{348 61 385 79 413 117 _c 440 155 454 207 454 273 _c 454 339 440 390 413 428 _c 385 466 348 485 301 485 _c 253 485 215 466 188 428 _c 161 390 148 339 148 273 _c _cl}_e}_d /e{{615 0 55 -13 562 560 _sc 562 296 _m 562 252 _l 149 252 _l 153 190 171 142 205 110 _c 238 78 284 62 344 62 _c 378 62 412 66 444 74 _c 476 82 509 95 541 113 _c 541 28 _l 509 14 476 3 442 -3 _c 408 -9 373 -13 339 -13 _c 251 -13 182 12 131 62 _c 80 112 55 181 55 268 _c 55 357 79 428 127 481 _c 175 533 241 560 323 560 _c 397 560 455 536 498 489 _c }_e{540 441 562 377 562 296 _c 472 322 _m 471 371 457 410 431 440 _c 404 469 368 484 324 484 _c 274 484 234 469 204 441 _c 174 413 156 373 152 322 _c 472 322 _l _cl}_e}_d /g{{635 0 55 -207 544 560 _sc 454 280 _m 454 344 440 395 414 431 _c 387 467 349 485 301 485 _c 253 485 215 467 188 431 _c 161 395 148 344 148 280 _c 148 215 161 165 188 129 _c 215 93 253 75 301 75 _c 349 75 387 93 414 129 _c 440 165 454 215 454 280 _c 544 68 _m 544 -24 523 -93 482 -139 _c 440 -184 377 -207 292 -207 _c 260 -207 231 -204 203 -200 _c 175 -195 147 -188 121 -178 _c }_e{121 -91 _l 147 -105 173 -115 199 -122 _c 225 -129 251 -133 278 -133 _c 336 -133 380 -117 410 -87 _c 439 -56 454 -10 454 52 _c 454 96 _l 435 64 411 40 382 24 _c 353 8 319 0 279 0 _c 211 0 157 25 116 76 _c 75 127 55 195 55 280 _c 55 364 75 432 116 483 _c 157 534 211 560 279 560 _c 319 560 353 552 382 536 _c 411 520 435 496 454 464 _c 454 547 _l 544 547 _l }_e{544 68 _l _cl}_e}_d /h{634 0 91 0 549 760 _sc 549 330 _m 549 0 _l 459 0 _l 459 327 _l 459 379 448 417 428 443 _c 408 469 378 482 338 482 _c 289 482 251 466 223 435 _c 195 404 181 362 181 309 _c 181 0 _l 91 0 _l 91 760 _l 181 760 _l 181 462 _l 202 494 227 519 257 535 _c 286 551 320 560 358 560 _c 420 560 468 540 500 501 _c 532 462 549 405 549 330 _c _cl}_d /i{278 0 94 0 184 760 _sc 94 547 _m 184 547 _l 184 0 _l 94 0 _l 94 547 _l 94 760 _m 184 760 _l 184 646 _l 94 646 _l 94 760 _l _cl}_d /l{278 0 94 0 184 760 _sc 94 760 _m 184 760 _l 184 0 _l 94 0 _l 94 760 _l _cl}_d /n{634 0 91 0 549 560 _sc 549 330 _m 549 0 _l 459 0 _l 459 327 _l 459 379 448 417 428 443 _c 408 469 378 482 338 482 _c 289 482 251 466 223 435 _c 195 404 181 362 181 309 _c 181 0 _l 91 0 _l 91 547 _l 181 547 _l 181 462 _l 202 494 227 519 257 535 _c 286 551 320 560 358 560 _c 420 560 468 540 500 501 _c 532 462 549 405 549 330 _c _cl}_d /o{612 0 55 -13 557 560 _sc 306 484 _m 258 484 220 465 192 427 _c 164 389 150 338 150 273 _c 150 207 163 156 191 118 _c 219 80 257 62 306 62 _c 354 62 392 80 420 118 _c 448 156 462 207 462 273 _c 462 337 448 389 420 427 _c 392 465 354 484 306 484 _c 306 560 _m 384 560 445 534 490 484 _c 534 433 557 363 557 273 _c 557 183 534 113 490 63 _c 445 12 384 -13 306 -13 _c 227 -13 165 12 121 63 _c 77 113 55 183 55 273 _c 55 363 77 433 121 484 _c 165 534 227 560 306 560 _c _cl}_d /r{411 0 91 0 411 560 _sc 411 463 _m 401 469 390 473 378 476 _c 366 478 353 480 339 480 _c 288 480 249 463 222 430 _c 194 397 181 350 181 288 _c 181 0 _l 91 0 _l 91 547 _l 181 547 _l 181 462 _l 199 495 224 520 254 536 _c 284 552 321 560 365 560 _c 371 560 378 559 386 559 _c 393 558 401 557 411 555 _c 411 463 _l _cl}_d /s{{521 0 54 -13 472 560 _sc 443 531 _m 443 446 _l 417 458 391 468 364 475 _c 336 481 308 485 279 485 _c 234 485 200 478 178 464 _c 156 450 145 430 145 403 _c 145 382 153 366 169 354 _c 185 342 217 330 265 320 _c 296 313 _l 360 299 405 279 432 255 _c 458 230 472 195 472 151 _c 472 100 452 60 412 31 _c 372 1 316 -13 246 -13 _c 216 -13 186 -10 154 -5 _c }_e{122 0 89 8 54 20 _c 54 113 _l 87 95 120 82 152 74 _c 184 65 216 61 248 61 _c 290 61 323 68 346 82 _c 368 96 380 117 380 144 _c 380 168 371 187 355 200 _c 339 213 303 226 247 238 _c 216 245 _l 160 257 119 275 95 299 _c 70 323 58 356 58 399 _c 58 450 76 490 112 518 _c 148 546 200 560 268 560 _c 301 560 332 557 362 552 _c 391 547 418 540 443 531 _c }_e{_cl}_e}_d /t{392 0 27 0 368 702 _sc 183 702 _m 183 547 _l 368 547 _l 368 477 _l 183 477 _l 183 180 _l 183 135 189 106 201 94 _c 213 81 238 75 276 75 _c 368 75 _l 368 0 _l 276 0 _l 206 0 158 13 132 39 _c 106 65 93 112 93 180 _c 93 477 _l 27 477 _l 27 547 _l 93 547 _l 93 702 _l 183 702 _l _cl}_d /u{634 0 85 -13 543 560 _sc 85 216 _m 85 547 _l 175 547 _l 175 219 _l 175 167 185 129 205 103 _c 225 77 255 64 296 64 _c 344 64 383 79 411 110 _c 439 141 453 183 453 237 _c 453 547 _l 543 547 _l 543 0 _l 453 0 _l 453 84 _l 431 50 405 26 377 10 _c 348 -5 315 -13 277 -13 _c 214 -13 166 6 134 45 _c 101 83 85 140 85 216 _c 311 560 _m 311 560 _l _cl}_d /v{592 0 30 0 562 547 _sc 30 547 _m 125 547 _l 296 88 _l 467 547 _l 562 547 _l 357 0 _l 235 0 _l 30 547 _l _cl}_d /y{592 0 30 -207 562 547 _sc 322 -50 _m 296 -114 271 -157 247 -177 _c 223 -197 191 -207 151 -207 _c 79 -207 _l 79 -132 _l 132 -132 _l 156 -132 175 -126 189 -114 _c 203 -102 218 -75 235 -31 _c 251 9 _l 30 547 _l 125 547 _l 296 119 _l 467 547 _l 562 547 _l 322 -50 _l _cl}_d /z{525 0 43 0 482 547 _sc 55 547 _m 482 547 _l 482 465 _l 144 72 _l 482 72 _l 482 0 _l 43 0 _l 43 82 _l 381 475 _l 55 475 _l 55 547 _l _cl}_d end readonly def /BuildGlyph {exch begin CharStrings exch 2 copy known not{pop /.notdef}if true 3 1 roll get exec end}_d /BuildChar { 1 index /Encoding get exch get 1 index /BuildGlyph get exec }_d FontName currentdict end definefont pop end %%EndProlog mpldict begin 13.5 175.5 translate 585 441 0 0 clipbox gsave 0 0 m 585 0 l 585 441 l 0 441 l cl 1.000 setgray fill grestore gsave 73.125 44.1 m 526.5 44.1 l 526.5 396.9 l 73.125 396.9 l cl 1.000 setgray fill grestore 1.000 setlinewidth 1 setlinejoin 2 setlinecap [] 0 setdash 0.165 0.431 0.651 setrgbcolor gsave 453.4 352.8 73.12 44.1 clipbox 74.0318 124.274 m 74.9385 188.483 l 77.6587 267.158 l 82.1925 298.557 l 91.26 319.901 l 118.463 337.277 l 163.8 351.83 l 254.475 360.297 l 526.5 361.355 l stroke grestore 0.500 setlinewidth 0 setlinecap 0.000 setgray gsave 453.4 352.8 73.12 44.1 clipbox /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 -3 m 0.795609 -3 1.55874 -2.6839 2.12132 -2.12132 c 2.6839 -1.55874 3 -0.795609 3 0 c 3 0.795609 2.6839 1.55874 2.12132 2.12132 c 1.55874 2.6839 0.795609 3 0 3 c -0.795609 3 -1.55874 2.6839 -2.12132 2.12132 c -2.6839 1.55874 -3 0.795609 -3 0 c -3 -0.795609 -2.6839 -1.55874 -2.12132 -2.12132 c -1.55874 -2.6839 -0.795609 -3 0 -3 c cl gsave 1.000 0.663 0.200 setrgbcolor fill grestore stroke grestore } bind def 74.0318 124.274 o 74.9385 188.483 o 77.6587 267.158 o 82.1925 298.557 o 91.26 319.901 o 118.463 337.277 o 163.8 351.83 o 254.475 360.297 o 526.5 361.355 o grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 44.1 m 73.125 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 396.9 o grestore /DejaVuSans findfont 12.000 scalefont setfont gsave 70.101562 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 163.8 44.1 m 163.8 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 163.8 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 163.8 396.9 o grestore gsave 145.753125 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /one glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow 22.904297 0.000000 m /zero glyphshow 30.539062 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 254.475 44.1 m 254.475 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 254.475 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 254.475 396.9 o grestore gsave 236.209375 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /two glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow 22.904297 0.000000 m /zero glyphshow 30.539062 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 345.15 44.1 m 345.15 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 345.15 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 345.15 396.9 o grestore gsave 326.907813 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /three glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow 22.904297 0.000000 m /zero glyphshow 30.539062 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 435.825 44.1 m 435.825 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 435.825 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 435.825 396.9 o grestore gsave 417.418750 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /four glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow 22.904297 0.000000 m /zero glyphshow 30.539062 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 526.5 44.1 m 526.5 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 396.9 o grestore gsave 508.257812 30.975000 translate 0.000000 rotate 0.000000 0.000000 m /five glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow 22.904297 0.000000 m /zero glyphshow 30.539062 0.000000 m /zero glyphshow grestore gsave 251.812500 14.350000 translate 0.000000 rotate 0.000000 0.000000 m /T glyphshow 5.580078 0.000000 m /r glyphshow 10.513672 0.000000 m /a glyphshow 17.867188 0.000000 m /i glyphshow 21.201172 0.000000 m /n glyphshow 28.806641 0.000000 m /i glyphshow 32.140625 0.000000 m /n glyphshow 39.746094 0.000000 m /g glyphshow 47.363281 0.000000 m /space glyphshow 51.177734 0.000000 m /s glyphshow 57.429688 0.000000 m /e glyphshow 64.812500 0.000000 m /t glyphshow 69.517578 0.000000 m /space glyphshow 73.332031 0.000000 m /s glyphshow 79.583984 0.000000 m /i glyphshow 82.917969 0.000000 m /z glyphshow 89.216797 0.000000 m /e glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 44.1 m 526.5 44.1 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 44.1 o grestore gsave 55.484375 40.787500 translate 0.000000 rotate 0.000000 0.000000 m /six glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 88.2 m 526.5 88.2 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 88.2 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 88.2 o grestore gsave 55.734375 84.887500 translate 0.000000 rotate 0.000000 0.000000 m /six glyphshow 7.634766 0.000000 m /five glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 132.3 m 526.5 132.3 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 132.3 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 132.3 o grestore gsave 55.625000 128.987500 translate 0.000000 rotate 0.000000 0.000000 m /seven glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 176.4 m 526.5 176.4 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 176.4 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 176.4 o grestore gsave 55.875000 173.087500 translate 0.000000 rotate 0.000000 0.000000 m /seven glyphshow 7.634766 0.000000 m /five glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 220.5 m 526.5 220.5 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 220.5 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 220.5 o grestore gsave 55.453125 217.187500 translate 0.000000 rotate 0.000000 0.000000 m /eight glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 264.6 m 526.5 264.6 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 264.6 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 264.6 o grestore gsave 55.703125 261.287500 translate 0.000000 rotate 0.000000 0.000000 m /eight glyphshow 7.634766 0.000000 m /five glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 308.7 m 526.5 308.7 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 308.7 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 308.7 o grestore gsave 55.390625 305.387500 translate 0.000000 rotate 0.000000 0.000000 m /nine glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 352.8 m 526.5 352.8 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 352.8 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 352.8 o grestore gsave 55.640625 349.487500 translate 0.000000 rotate 0.000000 0.000000 m /nine glyphshow 7.634766 0.000000 m /five glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 396.9 m 526.5 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 396.9 o grestore gsave 48.312500 393.587500 translate 0.000000 rotate 0.000000 0.000000 m /one glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow grestore 1.000 setlinewidth gsave 73.125 396.9 m 526.5 396.9 l stroke grestore gsave 526.5 44.1 m 526.5 396.9 l stroke grestore gsave 73.125 44.1 m 526.5 44.1 l stroke grestore gsave 73.125 44.1 m 73.125 396.9 l stroke grestore /DejaVuSans findfont 14.400 scalefont setfont gsave 171.414062 401.900000 translate 0.000000 rotate 0.000000 0.000000 m /A glyphshow 9.594360 0.000000 m /c glyphshow 17.506393 0.000000 m /c glyphshow 25.418427 0.000000 m /u glyphshow 34.539047 0.000000 m /r glyphshow 40.455505 0.000000 m /a glyphshow 49.273972 0.000000 m /c glyphshow 57.186005 0.000000 m /y glyphshow 65.702332 0.000000 m /space glyphshow 70.276688 0.000000 m /parenleft glyphshow 75.890991 0.000000 m /percent glyphshow 89.564896 0.000000 m /parenright glyphshow 95.179199 0.000000 m /space glyphshow 99.753555 0.000000 m /o glyphshow 108.557968 0.000000 m /n glyphshow 117.678589 0.000000 m /space glyphshow 122.252945 0.000000 m /t glyphshow 127.895355 0.000000 m /h glyphshow 137.015976 0.000000 m /e glyphshow 145.869583 0.000000 m /space glyphshow 150.443939 0.000000 m /v glyphshow 158.960266 0.000000 m /a glyphshow 167.778732 0.000000 m /l glyphshow 171.776901 0.000000 m /i glyphshow 175.775070 0.000000 m /d glyphshow 184.909744 0.000000 m /a glyphshow 193.728210 0.000000 m /t glyphshow 199.370621 0.000000 m /i glyphshow 203.368790 0.000000 m /o glyphshow 212.173203 0.000000 m /n glyphshow 221.293823 0.000000 m /space glyphshow 225.868179 0.000000 m /d glyphshow 235.002853 0.000000 m /a glyphshow 243.821320 0.000000 m /t glyphshow 249.463730 0.000000 m /a glyphshow grestore end showpage ```
/content/code_sandbox/images/more_data.eps
postscript
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
13,791
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \begin{document} \begin{tikzpicture}[ neuron/.style={circle,draw,inner sep=0pt,minimum size=10mm} ] \node (perceptron) at (0, 0) [neuron] {}; \node (output) at (2.25, 0) {\ output}; \node (x1) at (-2.25, 1) {$x_1$}; \node (x2) at (-2.25, 0) {$x_2$}; \node (x3) at (-2.25, -1) {$x_3$}; \draw [->] (x1) to (perceptron); \draw [->] (x2) to (perceptron); \draw [->] (x3) to (perceptron); \draw [->] (perceptron) to (output); \end{tikzpicture} \end{document} ```
/content/code_sandbox/images/tikz0.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
255
```tex %!TEX TS-program = xelatex %!TEX encoding = UTF-8 Unicode \documentclass[11pt,tikz,border=1]{standalone} \usetikzlibrary{positioning} \usetikzlibrary{backgrounds,math} \input{../plots} \begin{document} \quadraticCostLearning{0.6}{0.9}{0.15}{250} \end{document} ```
/content/code_sandbox/images/saturation1-250.tex
tex
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
94
```postscript %!PS-Adobe-3.0 EPSF-3.0 %%Title: /home/zhanggyb/more_data3.eps %%Creator: matplotlib version 1.3.1, path_to_url %%CreationDate: Thu Feb 18 08:56:27 2016 %%Orientation: portrait %%BoundingBox: 13 175 598 616 %%EndComments %%BeginProlog /mpldict 8 dict def mpldict begin /m { moveto } bind def /l { lineto } bind def /r { rlineto } bind def /c { curveto } bind def /cl { closepath } bind def /box { m 1 index 0 r 0 exch r neg 0 r cl } bind def /clipbox { box clip newpath } bind def %!PS-Adobe-3.0 Resource-Font %%Title: DejaVu Sans %%Creator: Converted from TrueType to type 3 by PPR 25 dict begin /_d{bind def}bind def /_m{moveto}_d /_l{lineto}_d /_cl{closepath eofill}_d /_c{curveto}_d /_sc{7 -1 roll{setcachedevice}{pop pop pop pop pop pop}ifelse}_d /_e{exec}_d /FontName /DejaVuSans def /PaintType 0 def /FontMatrix[.001 0 0 .001 0 0]def /FontBBox[-1021 -415 1681 1167]def /FontType 3 def /Encoding [ /space /percent /parenleft /parenright /zero /one /two /three /four /five /six /seven /eight /nine /M /N /S /T /V /a /c /e /g /i /k /l /n /o /r /s /t /u /w /y /z ] def /FontInfo 10 dict dup begin /FamilyName (DejaVu Sans) def /FullName (DejaVu Sans) def /Weight (Book) def /Version (Version 2.34) def /ItalicAngle 0.0 def /isFixedPitch false def /UnderlinePosition -130 def /UnderlineThickness 90 def end readonly def /CharStrings 35 dict dup begin /space{318 0 0 0 0 0 _sc }_d /percent{{950 0 55 -13 895 742 _sc 727 321 _m 699 321 676 309 660 285 _c 644 261 636 227 636 184 _c 636 142 644 108 660 84 _c 676 60 699 48 727 48 _c 755 48 777 60 793 84 _c 809 108 817 142 817 184 _c 817 226 809 260 793 284 _c 777 308 755 321 727 321 _c 727 383 _m 778 383 819 365 849 329 _c 879 293 895 244 895 184 _c 895 123 879 75 849 40 _c 819 4 778 -13 727 -13 _c }_e{675 -13 633 4 603 40 _c 573 75 558 123 558 184 _c 558 245 573 293 603 329 _c 633 365 675 383 727 383 _c 223 680 _m 195 680 173 667 157 643 _c 141 619 133 586 133 544 _c 133 500 141 467 157 443 _c 173 419 195 407 223 407 _c 251 407 274 419 290 443 _c 306 467 314 500 314 544 _c 314 586 305 619 289 643 _c 273 667 251 680 223 680 _c 664 742 _m 742 742 _l 286 -13 _l }_e{208 -13 _l 664 742 _l 223 742 _m 274 742 315 724 346 688 _c 376 652 392 604 392 544 _c 392 482 376 434 346 398 _c 316 362 275 345 223 345 _c 171 345 130 362 100 398 _c 70 434 55 482 55 544 _c 55 604 70 652 100 688 _c 130 724 171 742 223 742 _c _cl}_e}_d /parenleft{390 0 86 -131 310 759 _sc 310 759 _m 266 683 234 609 213 536 _c 191 463 181 389 181 314 _c 181 238 191 164 213 91 _c 234 17 266 -56 310 -131 _c 232 -131 _l 183 -54 146 20 122 94 _c 98 168 86 241 86 314 _c 86 386 98 459 122 533 _c 146 607 182 682 232 759 _c 310 759 _l _cl}_d /parenright{390 0 80 -131 304 759 _sc 80 759 _m 158 759 _l 206 682 243 607 267 533 _c 291 459 304 386 304 314 _c 304 241 291 168 267 94 _c 243 20 206 -54 158 -131 _c 80 -131 _l 123 -56 155 17 177 91 _c 198 164 209 238 209 314 _c 209 389 198 463 177 536 _c 155 609 123 683 80 759 _c _cl}_d /zero{636 0 66 -13 570 742 _sc 318 664 _m 267 664 229 639 203 589 _c 177 539 165 464 165 364 _c 165 264 177 189 203 139 _c 229 89 267 64 318 64 _c 369 64 407 89 433 139 _c 458 189 471 264 471 364 _c 471 464 458 539 433 589 _c 407 639 369 664 318 664 _c 318 742 _m 399 742 461 709 505 645 _c 548 580 570 486 570 364 _c 570 241 548 147 505 83 _c 461 19 399 -13 318 -13 _c 236 -13 173 19 130 83 _c 87 147 66 241 66 364 _c 66 486 87 580 130 645 _c 173 709 236 742 318 742 _c _cl}_d /one{636 0 110 0 544 729 _sc 124 83 _m 285 83 _l 285 639 _l 110 604 _l 110 694 _l 284 729 _l 383 729 _l 383 83 _l 544 83 _l 544 0 _l 124 0 _l 124 83 _l _cl}_d /two{{636 0 73 0 536 742 _sc 192 83 _m 536 83 _l 536 0 _l 73 0 _l 73 83 _l 110 121 161 173 226 239 _c 290 304 331 346 348 365 _c 380 400 402 430 414 455 _c 426 479 433 504 433 528 _c 433 566 419 598 392 622 _c 365 646 330 659 286 659 _c 255 659 222 653 188 643 _c 154 632 117 616 78 594 _c 78 694 _l 118 710 155 722 189 730 _c 223 738 255 742 284 742 _c }_e{359 742 419 723 464 685 _c 509 647 532 597 532 534 _c 532 504 526 475 515 449 _c 504 422 484 390 454 354 _c 446 344 420 317 376 272 _c 332 227 271 164 192 83 _c _cl}_e}_d /three{{636 0 76 -13 556 742 _sc 406 393 _m 453 383 490 362 516 330 _c 542 298 556 258 556 212 _c 556 140 531 84 482 45 _c 432 6 362 -13 271 -13 _c 240 -13 208 -10 176 -4 _c 144 1 110 10 76 22 _c 76 117 _l 103 101 133 89 166 81 _c 198 73 232 69 268 69 _c 330 69 377 81 409 105 _c 441 129 458 165 458 212 _c 458 254 443 288 413 312 _c 383 336 341 349 287 349 _c }_e{202 349 _l 202 430 _l 291 430 _l 339 430 376 439 402 459 _c 428 478 441 506 441 543 _c 441 580 427 609 401 629 _c 374 649 336 659 287 659 _c 260 659 231 656 200 650 _c 169 644 135 635 98 623 _c 98 711 _l 135 721 170 729 203 734 _c 235 739 266 742 296 742 _c 370 742 429 725 473 691 _c 517 657 539 611 539 553 _c 539 513 527 479 504 451 _c 481 423 448 403 406 393 _c _cl}_e}_d /four{636 0 49 0 580 729 _sc 378 643 _m 129 254 _l 378 254 _l 378 643 _l 352 729 _m 476 729 _l 476 254 _l 580 254 _l 580 172 _l 476 172 _l 476 0 _l 378 0 _l 378 172 _l 49 172 _l 49 267 _l 352 729 _l _cl}_d /five{{636 0 77 -13 549 729 _sc 108 729 _m 495 729 _l 495 646 _l 198 646 _l 198 467 _l 212 472 227 476 241 478 _c 255 480 270 482 284 482 _c 365 482 429 459 477 415 _c 525 370 549 310 549 234 _c 549 155 524 94 475 51 _c 426 8 357 -13 269 -13 _c 238 -13 207 -10 175 -6 _c 143 -1 111 6 77 17 _c 77 116 _l 106 100 136 88 168 80 _c 199 72 232 69 267 69 _c }_e{323 69 368 83 401 113 _c 433 143 450 183 450 234 _c 450 284 433 324 401 354 _c 368 384 323 399 267 399 _c 241 399 214 396 188 390 _c 162 384 135 375 108 363 _c 108 729 _l _cl}_e}_d /six{{636 0 70 -13 573 742 _sc 330 404 _m 286 404 251 388 225 358 _c 199 328 186 286 186 234 _c 186 181 199 139 225 109 _c 251 79 286 64 330 64 _c 374 64 409 79 435 109 _c 461 139 474 181 474 234 _c 474 286 461 328 435 358 _c 409 388 374 404 330 404 _c 526 713 _m 526 623 _l 501 635 476 644 451 650 _c 425 656 400 659 376 659 _c 310 659 260 637 226 593 _c }_e{192 549 172 482 168 394 _c 187 422 211 444 240 459 _c 269 474 301 482 336 482 _c 409 482 467 459 509 415 _c 551 371 573 310 573 234 _c 573 159 550 99 506 54 _c 462 9 403 -13 330 -13 _c 246 -13 181 19 137 83 _c 92 147 70 241 70 364 _c 70 479 97 571 152 639 _c 206 707 280 742 372 742 _c 396 742 421 739 447 735 _c 472 730 498 723 526 713 _c _cl}_e}_d /seven{636 0 82 0 551 729 _sc 82 729 _m 551 729 _l 551 687 _l 286 0 _l 183 0 _l 432 646 _l 82 646 _l 82 729 _l _cl}_d /eight{{636 0 68 -13 568 742 _sc 318 346 _m 271 346 234 333 207 308 _c 180 283 167 249 167 205 _c 167 161 180 126 207 101 _c 234 76 271 64 318 64 _c 364 64 401 76 428 102 _c 455 127 469 161 469 205 _c 469 249 455 283 429 308 _c 402 333 365 346 318 346 _c 219 388 _m 177 398 144 418 120 447 _c 96 476 85 511 85 553 _c 85 611 105 657 147 691 _c 188 725 245 742 318 742 _c }_e{390 742 447 725 489 691 _c 530 657 551 611 551 553 _c 551 511 539 476 515 447 _c 491 418 459 398 417 388 _c 464 377 501 355 528 323 _c 554 291 568 251 568 205 _c 568 134 546 80 503 43 _c 459 5 398 -13 318 -13 _c 237 -13 175 5 132 43 _c 89 80 68 134 68 205 _c 68 251 81 291 108 323 _c 134 355 171 377 219 388 _c 183 544 _m 183 506 194 476 218 455 _c }_e{242 434 275 424 318 424 _c 360 424 393 434 417 455 _c 441 476 453 506 453 544 _c 453 582 441 611 417 632 _c 393 653 360 664 318 664 _c 275 664 242 653 218 632 _c 194 611 183 582 183 544 _c _cl}_e}_d /nine{{636 0 63 -13 566 742 _sc 110 15 _m 110 105 _l 134 93 159 84 185 78 _c 210 72 235 69 260 69 _c 324 69 374 90 408 134 _c 442 178 462 244 468 334 _c 448 306 424 284 396 269 _c 367 254 335 247 300 247 _c 226 247 168 269 126 313 _c 84 357 63 417 63 494 _c 63 568 85 628 129 674 _c 173 719 232 742 306 742 _c 390 742 455 709 499 645 _c 543 580 566 486 566 364 _c }_e{566 248 538 157 484 89 _c 429 21 356 -13 264 -13 _c 239 -13 214 -10 189 -6 _c 163 -2 137 5 110 15 _c 306 324 _m 350 324 385 339 411 369 _c 437 399 450 441 450 494 _c 450 546 437 588 411 618 _c 385 648 350 664 306 664 _c 262 664 227 648 201 618 _c 175 588 162 546 162 494 _c 162 441 175 399 201 369 _c 227 339 262 324 306 324 _c _cl}_e}_d /M{863 0 98 0 765 729 _sc 98 729 _m 245 729 _l 431 233 _l 618 729 _l 765 729 _l 765 0 _l 669 0 _l 669 640 _l 481 140 _l 382 140 _l 194 640 _l 194 0 _l 98 0 _l 98 729 _l _cl}_d /N{748 0 98 0 650 729 _sc 98 729 _m 231 729 _l 554 119 _l 554 729 _l 650 729 _l 650 0 _l 517 0 _l 194 610 _l 194 0 _l 98 0 _l 98 729 _l _cl}_d /S{{635 0 66 -13 579 742 _sc 535 705 _m 535 609 _l 497 627 462 640 429 649 _c 395 657 363 662 333 662 _c 279 662 237 651 208 631 _c 179 610 165 580 165 542 _c 165 510 174 485 194 469 _c 213 452 250 439 304 429 _c 364 417 _l 437 403 491 378 526 343 _c 561 307 579 260 579 201 _c 579 130 555 77 508 41 _c 460 5 391 -13 300 -13 _c 265 -13 228 -9 189 -2 _c }_e{150 5 110 16 69 32 _c 69 134 _l 109 111 148 94 186 83 _c 224 71 262 66 300 66 _c 356 66 399 77 430 99 _c 460 121 476 152 476 194 _c 476 230 465 258 443 278 _c 421 298 385 313 335 323 _c 275 335 _l 201 349 148 372 115 404 _c 82 435 66 478 66 534 _c 66 598 88 649 134 686 _c 179 723 242 742 322 742 _c 356 742 390 739 426 733 _c 461 727 497 717 535 705 _c }_e{_cl}_e}_d /T{611 0 -2 0 614 729 _sc -2 729 _m 614 729 _l 614 646 _l 355 646 _l 355 0 _l 256 0 _l 256 646 _l -2 646 _l -2 729 _l _cl}_d /V{684 0 8 0 676 729 _sc 286 0 _m 8 729 _l 111 729 _l 342 115 _l 573 729 _l 676 729 _l 398 0 _l 286 0 _l _cl}_d /a{{613 0 60 -13 522 560 _sc 343 275 _m 270 275 220 266 192 250 _c 164 233 150 205 150 165 _c 150 133 160 107 181 89 _c 202 70 231 61 267 61 _c 317 61 357 78 387 114 _c 417 149 432 196 432 255 _c 432 275 _l 343 275 _l 522 312 _m 522 0 _l 432 0 _l 432 83 _l 411 49 385 25 355 10 _c 325 -5 287 -13 243 -13 _c 187 -13 142 2 109 33 _c 76 64 60 106 60 159 _c }_e{60 220 80 266 122 298 _c 163 329 224 345 306 345 _c 432 345 _l 432 354 _l 432 395 418 427 391 450 _c 364 472 326 484 277 484 _c 245 484 215 480 185 472 _c 155 464 127 453 100 439 _c 100 522 _l 132 534 164 544 195 550 _c 226 556 256 560 286 560 _c 365 560 424 539 463 498 _c 502 457 522 395 522 312 _c _cl}_e}_d /c{{550 0 55 -13 488 560 _sc 488 526 _m 488 442 _l 462 456 437 466 411 473 _c 385 480 360 484 334 484 _c 276 484 230 465 198 428 _c 166 391 150 339 150 273 _c 150 206 166 154 198 117 _c 230 80 276 62 334 62 _c 360 62 385 65 411 72 _c 437 79 462 90 488 104 _c 488 21 _l 462 9 436 0 410 -5 _c 383 -10 354 -13 324 -13 _c 242 -13 176 12 128 64 _c }_e{79 115 55 185 55 273 _c 55 362 79 432 128 483 _c 177 534 244 560 330 560 _c 358 560 385 557 411 551 _c 437 545 463 537 488 526 _c _cl}_e}_d /e{{615 0 55 -13 562 560 _sc 562 296 _m 562 252 _l 149 252 _l 153 190 171 142 205 110 _c 238 78 284 62 344 62 _c 378 62 412 66 444 74 _c 476 82 509 95 541 113 _c 541 28 _l 509 14 476 3 442 -3 _c 408 -9 373 -13 339 -13 _c 251 -13 182 12 131 62 _c 80 112 55 181 55 268 _c 55 357 79 428 127 481 _c 175 533 241 560 323 560 _c 397 560 455 536 498 489 _c }_e{540 441 562 377 562 296 _c 472 322 _m 471 371 457 410 431 440 _c 404 469 368 484 324 484 _c 274 484 234 469 204 441 _c 174 413 156 373 152 322 _c 472 322 _l _cl}_e}_d /g{{635 0 55 -207 544 560 _sc 454 280 _m 454 344 440 395 414 431 _c 387 467 349 485 301 485 _c 253 485 215 467 188 431 _c 161 395 148 344 148 280 _c 148 215 161 165 188 129 _c 215 93 253 75 301 75 _c 349 75 387 93 414 129 _c 440 165 454 215 454 280 _c 544 68 _m 544 -24 523 -93 482 -139 _c 440 -184 377 -207 292 -207 _c 260 -207 231 -204 203 -200 _c 175 -195 147 -188 121 -178 _c }_e{121 -91 _l 147 -105 173 -115 199 -122 _c 225 -129 251 -133 278 -133 _c 336 -133 380 -117 410 -87 _c 439 -56 454 -10 454 52 _c 454 96 _l 435 64 411 40 382 24 _c 353 8 319 0 279 0 _c 211 0 157 25 116 76 _c 75 127 55 195 55 280 _c 55 364 75 432 116 483 _c 157 534 211 560 279 560 _c 319 560 353 552 382 536 _c 411 520 435 496 454 464 _c 454 547 _l 544 547 _l }_e{544 68 _l _cl}_e}_d /i{278 0 94 0 184 760 _sc 94 547 _m 184 547 _l 184 0 _l 94 0 _l 94 547 _l 94 760 _m 184 760 _l 184 646 _l 94 646 _l 94 760 _l _cl}_d /k{579 0 91 0 576 760 _sc 91 760 _m 181 760 _l 181 311 _l 449 547 _l 564 547 _l 274 291 _l 576 0 _l 459 0 _l 181 267 _l 181 0 _l 91 0 _l 91 760 _l _cl}_d /l{278 0 94 0 184 760 _sc 94 760 _m 184 760 _l 184 0 _l 94 0 _l 94 760 _l _cl}_d /n{634 0 91 0 549 560 _sc 549 330 _m 549 0 _l 459 0 _l 459 327 _l 459 379 448 417 428 443 _c 408 469 378 482 338 482 _c 289 482 251 466 223 435 _c 195 404 181 362 181 309 _c 181 0 _l 91 0 _l 91 547 _l 181 547 _l 181 462 _l 202 494 227 519 257 535 _c 286 551 320 560 358 560 _c 420 560 468 540 500 501 _c 532 462 549 405 549 330 _c _cl}_d /o{612 0 55 -13 557 560 _sc 306 484 _m 258 484 220 465 192 427 _c 164 389 150 338 150 273 _c 150 207 163 156 191 118 _c 219 80 257 62 306 62 _c 354 62 392 80 420 118 _c 448 156 462 207 462 273 _c 462 337 448 389 420 427 _c 392 465 354 484 306 484 _c 306 560 _m 384 560 445 534 490 484 _c 534 433 557 363 557 273 _c 557 183 534 113 490 63 _c 445 12 384 -13 306 -13 _c 227 -13 165 12 121 63 _c 77 113 55 183 55 273 _c 55 363 77 433 121 484 _c 165 534 227 560 306 560 _c _cl}_d /r{411 0 91 0 411 560 _sc 411 463 _m 401 469 390 473 378 476 _c 366 478 353 480 339 480 _c 288 480 249 463 222 430 _c 194 397 181 350 181 288 _c 181 0 _l 91 0 _l 91 547 _l 181 547 _l 181 462 _l 199 495 224 520 254 536 _c 284 552 321 560 365 560 _c 371 560 378 559 386 559 _c 393 558 401 557 411 555 _c 411 463 _l _cl}_d /s{{521 0 54 -13 472 560 _sc 443 531 _m 443 446 _l 417 458 391 468 364 475 _c 336 481 308 485 279 485 _c 234 485 200 478 178 464 _c 156 450 145 430 145 403 _c 145 382 153 366 169 354 _c 185 342 217 330 265 320 _c 296 313 _l 360 299 405 279 432 255 _c 458 230 472 195 472 151 _c 472 100 452 60 412 31 _c 372 1 316 -13 246 -13 _c 216 -13 186 -10 154 -5 _c }_e{122 0 89 8 54 20 _c 54 113 _l 87 95 120 82 152 74 _c 184 65 216 61 248 61 _c 290 61 323 68 346 82 _c 368 96 380 117 380 144 _c 380 168 371 187 355 200 _c 339 213 303 226 247 238 _c 216 245 _l 160 257 119 275 95 299 _c 70 323 58 356 58 399 _c 58 450 76 490 112 518 _c 148 546 200 560 268 560 _c 301 560 332 557 362 552 _c 391 547 418 540 443 531 _c }_e{_cl}_e}_d /t{392 0 27 0 368 702 _sc 183 702 _m 183 547 _l 368 547 _l 368 477 _l 183 477 _l 183 180 _l 183 135 189 106 201 94 _c 213 81 238 75 276 75 _c 368 75 _l 368 0 _l 276 0 _l 206 0 158 13 132 39 _c 106 65 93 112 93 180 _c 93 477 _l 27 477 _l 27 547 _l 93 547 _l 93 702 _l 183 702 _l _cl}_d /u{634 0 85 -13 543 560 _sc 85 216 _m 85 547 _l 175 547 _l 175 219 _l 175 167 185 129 205 103 _c 225 77 255 64 296 64 _c 344 64 383 79 411 110 _c 439 141 453 183 453 237 _c 453 547 _l 543 547 _l 543 0 _l 453 0 _l 453 84 _l 431 50 405 26 377 10 _c 348 -5 315 -13 277 -13 _c 214 -13 166 6 134 45 _c 101 83 85 140 85 216 _c 311 560 _m 311 560 _l _cl}_d /w{818 0 42 0 776 547 _sc 42 547 _m 132 547 _l 244 120 _l 356 547 _l 462 547 _l 574 120 _l 686 547 _l 776 547 _l 633 0 _l 527 0 _l 409 448 _l 291 0 _l 185 0 _l 42 547 _l _cl}_d /y{592 0 30 -207 562 547 _sc 322 -50 _m 296 -114 271 -157 247 -177 _c 223 -197 191 -207 151 -207 _c 79 -207 _l 79 -132 _l 132 -132 _l 156 -132 175 -126 189 -114 _c 203 -102 218 -75 235 -31 _c 251 9 _l 30 547 _l 125 547 _l 296 119 _l 467 547 _l 562 547 _l 322 -50 _l _cl}_d /z{525 0 43 0 482 547 _sc 55 547 _m 482 547 _l 482 465 _l 144 72 _l 482 72 _l 482 0 _l 43 0 _l 43 82 _l 381 475 _l 55 475 _l 55 547 _l _cl}_d end readonly def /BuildGlyph {exch begin CharStrings exch 2 copy known not{pop /.notdef}if true 3 1 roll get exec end}_d /BuildChar { 1 index /Encoding get exch get 1 index /BuildGlyph get exec }_d FontName currentdict end definefont pop end %%EndProlog mpldict begin 13.5 175.5 translate 585 441 0 0 clipbox gsave 0 0 m 585 0 l 585 441 l 0 441 l cl 1.000 setgray fill grestore gsave 73.125 44.1 m 526.5 44.1 l 526.5 396.9 l 73.125 396.9 l cl 1.000 setgray fill grestore 1.000 setlinewidth 1 setlinejoin 2 setlinecap [] 0 setdash 0.165 0.431 0.651 setrgbcolor gsave 453.4 352.8 73.12 44.1 clipbox 73.125 251.499 m 123.692 285.744 l 190.539 327.704 l 241.106 344.45 l 291.673 355.834 l 358.519 365.101 l 409.086 372.863 l 459.654 377.378 l 526.5 377.943 l stroke grestore 0.500 setlinewidth 0 setlinecap 0.000 setgray gsave 453.4 352.8 73.12 44.1 clipbox /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 -3 m 0.795609 -3 1.55874 -2.6839 2.12132 -2.12132 c 2.6839 -1.55874 3 -0.795609 3 0 c 3 0.795609 2.6839 1.55874 2.12132 2.12132 c 1.55874 2.6839 0.795609 3 0 3 c -0.795609 3 -1.55874 2.6839 -2.12132 2.12132 c -2.6839 1.55874 -3 0.795609 -3 0 c -3 -0.795609 -2.6839 -1.55874 -2.12132 -2.12132 c -1.55874 -2.6839 -0.795609 -3 0 -3 c cl gsave 0.165 0.431 0.651 setrgbcolor fill grestore stroke grestore } bind def 73.125 251.499 o 123.692 285.744 o 190.539 327.704 o 241.106 344.45 o 291.673 355.834 o 358.519 365.101 o 409.086 372.863 o 459.654 377.378 o 526.5 377.943 o grestore 1.000 setlinewidth 2 setlinecap 1.000 0.663 0.200 setrgbcolor gsave 453.4 352.8 73.12 44.1 clipbox 73.125 44.4293 m 123.692 156.667 l 190.539 279.912 l 241.106 321.024 l 291.673 342.757 l 358.519 356.728 l 409.086 361.385 l 459.654 366.183 l 526.5 370.934 l stroke grestore 0.500 setlinewidth 0 setlinecap 0.000 setgray gsave 453.4 352.8 73.12 44.1 clipbox /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 -3 m 0.795609 -3 1.55874 -2.6839 2.12132 -2.12132 c 2.6839 -1.55874 3 -0.795609 3 0 c 3 0.795609 2.6839 1.55874 2.12132 2.12132 c 1.55874 2.6839 0.795609 3 0 3 c -0.795609 3 -1.55874 2.6839 -2.12132 2.12132 c -2.6839 1.55874 -3 0.795609 -3 0 c -3 -0.795609 -2.6839 -1.55874 -2.12132 -2.12132 c -1.55874 -2.6839 -0.795609 -3 0 -3 c cl gsave 1.000 0.663 0.200 setrgbcolor fill grestore stroke grestore } bind def 73.125 44.4293 o 123.692 156.667 o 190.539 279.912 o 241.106 321.024 o 291.673 342.757 o 358.519 356.728 o 409.086 361.385 o 459.654 366.183 o 526.5 370.934 o grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 44.1 m 73.125 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 396.9 o grestore gsave 62.125000 27.600000 translate 0.000000 rotate /DejaVuSans findfont 12.0 scalefont setfont 0.000000 0.828125 moveto /one glyphshow 7.634766 0.828125 moveto /zero glyphshow /DejaVuSans findfont 8.4 scalefont setfont 15.269531 7.765625 moveto /two glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 241.106 44.1 m 241.106 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 241.106 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 241.106 396.9 o grestore gsave 230.105748 27.600000 translate 0.000000 rotate /DejaVuSans findfont 12.0 scalefont setfont 0.000000 0.828125 moveto /one glyphshow 7.634766 0.828125 moveto /zero glyphshow /DejaVuSans findfont 8.4 scalefont setfont 15.269531 7.765625 moveto /three glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 409.086 44.1 m 409.086 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 409.086 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -4 l gsave 0.000 setgray fill grestore stroke grestore } bind def 409.086 396.9 o grestore gsave 398.086496 27.600000 translate 0.000000 rotate /DejaVuSans findfont 12.0 scalefont setfont 0.000000 0.937500 moveto /one glyphshow 7.634766 0.937500 moveto /zero glyphshow /DejaVuSans findfont 8.4 scalefont setfont 15.269531 7.875000 moveto /four glyphshow grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 123.692 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 123.692 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 153.272 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 153.272 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 174.259 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 174.259 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 190.539 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 190.539 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 203.839 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 203.839 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 215.085 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 215.085 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 224.827 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 224.827 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 233.419 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 233.419 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 291.673 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 291.673 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 321.253 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 321.253 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 342.24 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 342.24 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 358.519 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 358.519 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 371.82 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 371.82 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 383.066 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 383.066 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 392.807 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 392.807 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 401.4 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 401.4 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 459.654 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 459.654 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 489.234 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 489.234 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 510.221 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 510.221 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 44.1 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 0 -2 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 396.9 o grestore /DejaVuSans findfont 12.000 scalefont setfont gsave 251.812500 10.975000 translate 0.000000 rotate 0.000000 0.000000 m /T glyphshow 5.580078 0.000000 m /r glyphshow 10.513672 0.000000 m /a glyphshow 17.867188 0.000000 m /i glyphshow 21.201172 0.000000 m /n glyphshow 28.806641 0.000000 m /i glyphshow 32.140625 0.000000 m /n glyphshow 39.746094 0.000000 m /g glyphshow 47.363281 0.000000 m /space glyphshow 51.177734 0.000000 m /s glyphshow 57.429688 0.000000 m /e glyphshow 64.812500 0.000000 m /t glyphshow 69.517578 0.000000 m /space glyphshow 73.332031 0.000000 m /s glyphshow 79.583984 0.000000 m /i glyphshow 82.917969 0.000000 m /z glyphshow 89.216797 0.000000 m /e glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 67.62 m 526.5 67.62 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 67.62 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 67.62 o grestore gsave 55.562500 64.307500 translate 0.000000 rotate 0.000000 0.000000 m /three glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 114.66 m 526.5 114.66 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 114.66 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 114.66 o grestore gsave 55.234375 111.347500 translate 0.000000 rotate 0.000000 0.000000 m /four glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 161.7 m 526.5 161.7 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 161.7 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 161.7 o grestore gsave 55.562500 158.387500 translate 0.000000 rotate 0.000000 0.000000 m /five glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 208.74 m 526.5 208.74 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 208.74 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 208.74 o grestore gsave 55.484375 205.427500 translate 0.000000 rotate 0.000000 0.000000 m /six glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 255.78 m 526.5 255.78 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 255.78 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 255.78 o grestore gsave 55.625000 252.467500 translate 0.000000 rotate 0.000000 0.000000 m /seven glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 302.82 m 526.5 302.82 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 302.82 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 302.82 o grestore gsave 55.453125 299.507500 translate 0.000000 rotate 0.000000 0.000000 m /eight glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 349.86 m 526.5 349.86 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 349.86 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 349.86 o grestore gsave 55.390625 346.547500 translate 0.000000 rotate 0.000000 0.000000 m /nine glyphshow 7.634766 0.000000 m /zero glyphshow grestore [1 3] 0 setdash gsave 453.4 352.8 73.12 44.1 clipbox 73.125 396.9 m 526.5 396.9 l stroke grestore [] 0 setdash gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m 4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 73.125 396.9 o grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 0 m -4 0 l gsave 0.000 setgray fill grestore stroke grestore } bind def 526.5 396.9 o grestore gsave 48.312500 393.587500 translate 0.000000 rotate 0.000000 0.000000 m /one glyphshow 7.634766 0.000000 m /zero glyphshow 15.269531 0.000000 m /zero glyphshow grestore 1.000 setlinewidth gsave 73.125 396.9 m 526.5 396.9 l stroke grestore gsave 526.5 44.1 m 526.5 396.9 l stroke grestore gsave 73.125 44.1 m 526.5 44.1 l stroke grestore gsave 73.125 44.1 m 73.125 396.9 l stroke grestore gsave 259.397 51.3 m 519.3 51.3 l 519.3 97.1137 l 259.397 97.1137 l 259.397 51.3 l cl gsave 1.000 setgray fill grestore stroke grestore 0.500 setlinewidth gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 -3 m 0.795609 -3 1.55874 -2.6839 2.12132 -2.12132 c 2.6839 -1.55874 3 -0.795609 3 0 c 3 0.795609 2.6839 1.55874 2.12132 2.12132 c 1.55874 2.6839 0.795609 3 0 3 c -0.795609 3 -1.55874 2.6839 -2.12132 2.12132 c -2.6839 1.55874 -3 0.795609 -3 0 c -3 -0.795609 -2.6839 -1.55874 -2.12132 -2.12132 c -1.55874 -2.6839 -0.795609 -3 0 -3 c cl gsave 0.165 0.431 0.651 setrgbcolor fill grestore stroke grestore } bind def 269.477 85.7531 o 289.637 85.7531 o grestore /DejaVuSans findfont 14.400 scalefont setfont gsave 305.477500 80.713125 translate 0.000000 rotate 0.000000 0.000000 m /N glyphshow 10.764862 0.000000 m /e glyphshow 19.618469 0.000000 m /u glyphshow 28.739090 0.000000 m /r glyphshow 34.655548 0.000000 m /a glyphshow 43.474014 0.000000 m /l glyphshow 47.472183 0.000000 m /space glyphshow 52.046539 0.000000 m /n glyphshow 61.167160 0.000000 m /e glyphshow 70.020767 0.000000 m /t glyphshow 75.663177 0.000000 m /w glyphshow 87.432846 0.000000 m /o glyphshow 96.237259 0.000000 m /r glyphshow 102.153717 0.000000 m /k glyphshow 110.487350 0.000000 m /space glyphshow 115.061707 0.000000 m /a glyphshow 123.880173 0.000000 m /c glyphshow 131.792206 0.000000 m /c glyphshow 139.704239 0.000000 m /u glyphshow 148.824860 0.000000 m /r glyphshow 154.741318 0.000000 m /a glyphshow 163.559784 0.000000 m /c glyphshow 171.471817 0.000000 m /y glyphshow 179.988144 0.000000 m /space glyphshow 184.562500 0.000000 m /parenleft glyphshow 190.176804 0.000000 m /percent glyphshow 203.850708 0.000000 m /parenright glyphshow grestore gsave /o { gsave newpath translate 0.5 setlinewidth 1 setlinejoin 0 setlinecap 0 -3 m 0.795609 -3 1.55874 -2.6839 2.12132 -2.12132 c 2.6839 -1.55874 3 -0.795609 3 0 c 3 0.795609 2.6839 1.55874 2.12132 2.12132 c 1.55874 2.6839 0.795609 3 0 3 c -0.795609 3 -1.55874 2.6839 -2.12132 2.12132 c -2.6839 1.55874 -3 0.795609 -3 0 c -3 -0.795609 -2.6839 -1.55874 -2.12132 -2.12132 c -1.55874 -2.6839 -0.795609 -3 0 -3 c cl gsave 1.000 0.663 0.200 setrgbcolor fill grestore stroke grestore } bind def 269.477 65.0062 o 289.637 65.0062 o grestore gsave 305.477500 59.966250 translate 0.000000 rotate 0.000000 0.000000 m /S glyphshow 9.134674 0.000000 m /V glyphshow 18.979034 0.000000 m /M glyphshow 31.395157 0.000000 m /space glyphshow 35.969513 0.000000 m /a glyphshow 44.787979 0.000000 m /c glyphshow 52.700012 0.000000 m /c glyphshow 60.612045 0.000000 m /u glyphshow 69.732666 0.000000 m /r glyphshow 75.649124 0.000000 m /a glyphshow 84.467590 0.000000 m /c glyphshow 92.379623 0.000000 m /y glyphshow 100.895950 0.000000 m /space glyphshow 105.470306 0.000000 m /parenleft glyphshow 111.084610 0.000000 m /percent glyphshow 124.758514 0.000000 m /parenright glyphshow grestore end showpage ```
/content/code_sandbox/images/more_data_comparison.eps
postscript
2016-01-20T08:40:07
2024-08-15T16:40:43
nndl
zhanggyb/nndl
1,208
17,200
```gradle android { signingConfigs { release { Properties signingProperties = new Properties() signingProperties.load(rootProject.file('signing.properties').newDataInputStream()) storeFile rootProject.file(signingProperties.get('storeFile')) storePassword signingProperties.get('storePassword') ?: System.getenv('STORE_PASSWORD') ?: System.console()?.readLine('\nStore password: ') keyAlias signingProperties.get('keyAlias') keyPassword signingProperties.get('keyPassword') ?: System.getenv('KEY_PASSWORD') ?: System.console()?.readLine('\nKey password: ') } } } ```
/content/code_sandbox/signing.gradle
gradle
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
121
```qmake # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /opt/android-sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # path_to_url # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # EventBus -keepattributes *Annotation* -keepclassmembers class ** { @org.greenrobot.eventbus.Subscribe <methods>; } -keep enum org.greenrobot.eventbus.ThreadMode { *; } -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent { <init>(java.lang.Throwable); } # Glide -keep public class * implements com.bumptech.glide.module.GlideModule -keep public class * extends com.bumptech.glide.module.AppGlideModule -keep public enum com.bumptech.glide.load.ImageHeaderParser$** { **[] $VALUES; public *; } # For DexGuard only #-keepresourcexmlelements manifest/application/meta-data@value=GlideModule # Gson -keepattributes Signature # For using GSON @Expose annotation -keepattributes *Annotation* # Gson specific classes -keep class sun.misc.Unsafe { *; } #-keep class com.google.gson.stream.** { *; } # Application classes that will be serialized/deserialized over Gson -keep class me.zhanghai.android.douya.network.api.info.** { *; } # Prevent proguard from stripping interface information from TypeAdapterFactory, # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) -keep class * implements com.google.gson.TypeAdapterFactory -keep class * implements com.google.gson.JsonSerializer -keep class * implements com.google.gson.JsonDeserializer # Retrofit # Platform calls Class.forName on types which do not exist on Android to determine platform. -dontnote retrofit2.Platform # Platform used when running on Java 8 VMs. Will not be used at runtime. -dontwarn retrofit2.Platform$Java8 # Retain generic type information for use by reflection by converters and adapters. -keepattributes Signature # Retain declared checked exceptions for use by a Proxy instance. -keepattributes Exceptions # Okhttp -dontwarn okio.** -dontwarn javax.annotation.Nullable -dontwarn javax.annotation.ParametersAreNonnullByDefault ```
/content/code_sandbox/app/proguard-rules.pro
qmake
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
559
```xml <?xml version="1.0" encoding="utf-8"?> <!-- ~ All Rights Reserved. --> <manifest xmlns:android="path_to_url" xmlns:tools="path_to_url" package="me.zhanghai.android.douya"> <uses-feature android:name="android.hardware.camera" android:required="false"/> <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" android:maxSdkVersion="22" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" android:maxSdkVersion="22" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" android:maxSdkVersion="22" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" android:maxSdkVersion="22" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:name=".DouyaApplication" android:allowBackup="true" android:fullBackupContent="true" android:icon="@mipmap/launcher_icon" android:label="@string/app_name" android:roundIcon="@mipmap/launcher_icon_round" android:theme="@style/Theme.Douya" android:usesCleartextTraffic="true" tools:ignore="UnusedAttribute"> <activity android:name=".account.ui.AuthenticatorActivity" android:label="@string/auth_title_new" android:launchMode="singleTop" android:theme="@style/Theme.Douya.PrimaryColorBackground" /> <activity android:name=".account.ui.AddAccountActivity" android:launchMode="singleTop" android:noHistory="true" android:theme="@style/Theme.Douya.Translucent" /> <activity android:name=".account.ui.SelectAccountActivity" android:launchMode="singleTop" android:noHistory="true" android:theme="@style/Theme.Douya.Translucent" /> <activity android:name=".link.UriHandlerActivity" android:launchMode="singleTop" android:noHistory="true" android:theme="@style/Theme.Douya.Translucent"> <intent-filter android:scheme="http"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="douban" android:host="douban.com" /> <data android:scheme="https" android:host="www.douban.com" /> <data android:scheme="http" android:host="www.douban.com" /> <data android:scheme="https" android:host="book.douban.com" /> <data android:scheme="http" android:host="book.douban.com" /> <data android:scheme="https" android:host="movie.douban.com" /> <data android:scheme="http" android:host="movie.douban.com" /> <data android:scheme="https" android:host="music.douban.com" /> <data android:scheme="http" android:host="music.douban.com" /> <data android:scheme="https" android:host="m.douban.com" /> <data android:scheme="http" android:host="m.douban.com" /> <data android:scheme="https" android:host="frodo.douban.com" /> <data android:scheme="http" android:host="frodo.douban.com" /> </intent-filter> </activity> <activity android:name=".ui.WebViewActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/webview_title" /> <activity android:name=".gallery.ui.GalleryActivity" android:label="@string/gallery_title" android:theme="@style/Theme.Douya.Gallery" /> <activity android:name=".main.ui.MainActivity" android:label="@string/app_name" android:launchMode="singleTop" android:theme="@style/Theme.Douya.MainActivity.ColdStart"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".broadcast.ui.BroadcastListActivity" android:theme="@style/Theme.Douya" /> <activity android:name=".broadcast.ui.SendBroadcastActivity" android:label="@string/broadcast_send_intent_filter_title" android:theme="@style/Theme.Douya.DialogWhenLarge" android:windowSoftInputMode="adjustResize|stateVisible"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/*" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="message/rfc822"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND_MULTIPLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity> <activity android:name=".broadcast.ui.BroadcastActivity" android:theme="@style/Theme.Douya.BroadcastActivity" android:windowSoftInputMode="adjustResize|stateHidden" /> <activity android:name=".broadcast.ui.RebroadcastBroadcastActivity" android:label="@string/broadcast_rebroadcast_title" android:theme="@style/Theme.Douya.DialogWhenLarge" android:windowSoftInputMode="adjustResize|stateVisible" /> <activity android:name=".broadcast.ui.SendCommentActivity" android:label="@string/broadcast_send_comment_title" android:theme="@style/Theme.Douya.DialogWhenLarge" android:windowSoftInputMode="adjustResize|stateVisible" /> <activity android:name=".profile.ui.ProfileActivity" android:theme="@style/Theme.Douya.TransparentBackground" android:windowSoftInputMode="adjustResize|stateHidden" /> <activity android:name=".followship.ui.FollowerListActivity" android:label="@string/profile_follower_list_title" android:theme="@style/Theme.Douya" /> <activity android:name=".followship.ui.FollowingListActivity" android:label="@string/profile_following_list_title" android:theme="@style/Theme.Douya" /> <activity android:name=".item.ui.BookActivity" android:label="@string/item_book_title" android:theme="@style/Theme.Douya.Book" /> <activity android:name=".item.ui.MovieActivity" android:label="@string/item_movie_title" android:theme="@style/Theme.Douya.Movie" /> <activity android:name=".item.ui.MusicActivity" android:label="@string/item_music_title" android:theme="@style/Theme.Douya.Music" /> <activity android:name=".item.ui.GameActivity" android:label="@string/item_game_title" android:theme="@style/Theme.Douya.GameApp" /> <activity android:name=".item.ui.ItemCollectionActivity" android:label="@string/item_collection_title" android:theme="@style/Theme.Douya.DialogWhenLarge" /> <activity android:name=".item.ui.ItemIntroductionActivity" android:label="@string/item_introduction_title" android:theme="@style/Theme.Douya.Light.DialogWhenLarge" /> <activity android:name=".item.ui.TableOfContentsActivity" android:label="@string/item_table_of_contents_title" android:theme="@style/Theme.Douya.Light.DialogWhenLarge" /> <activity android:name=".calendar.ui.CalendarActivity" android:label="@string/calendar_title" android:launchMode="singleTop" android:theme="@style/Theme.Douya.Light.DialogWhenLarge" /> <activity android:name=".settings.ui.SettingsActivity" android:exported="false" android:label="@string/settings_title" android:launchMode="singleTop" android:theme="@style/Theme.Douya"> <intent-filter> <action android:name="android.intent.action.APPLICATION_PREFERENCES" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".main.ui.MainActivity" /> </activity> <activity android:name=".settings.ui.AboutActivity" android:label="@string/about_title" android:launchMode="singleTop" android:theme="@style/Theme.Douya.PrimaryColorBackground"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".settings.ui.SettingsActivity" /> </activity> <service android:name=".account.app.AuthenticatorService" tools:ignore="ExportedService"> <intent-filter> <action android:name="android.accounts.AccountAuthenticator" /> </intent-filter> <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" /> </service> <service android:name=".content.ResourceWriterService" /> <service android:name=".gallery.app.SaveImageService" /> <service android:name=".media.PlayMusicService" /> <receiver android:name=".media.MediaButtonReceiver"> <intent-filter> <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent-filter> </receiver> <!--<receiver android:name=".calendar.app.CalendarAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/calendar_appwidget" /> </receiver>--> <provider android:name=".app.ImageTypeFileProvider" android:authorities="@string/file_provider_authority" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths" /> </provider> <meta-data android:name="io.fabric.ApiKey" android:value="dc160e13d1b3c3e917e331e8b272c51a523d8599" /> </application> </manifest> ```
/content/code_sandbox/app/src/main/AndroidManifest.xml
xml
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
2,391
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.content.Context; import me.zhanghai.android.douya.BuildConfig; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.broadcast.ui.SendBroadcastActivity; import me.zhanghai.android.douya.settings.info.Settings; import me.zhanghai.android.douya.util.ToastUtils; public class NotImplementedManager { private NotImplementedManager() {} public static void editProfile(Context context) { UrlHandler.open("path_to_url", context); } public static void openDoumail(Context context) { UrlHandler.open("path_to_url", context); } public static void sendDoumail(String userIdOrUid, Context context) { UrlHandler.open("path_to_url" + userIdOrUid, context); } public static void openSearch(Context context) { if (Settings.PROGRESSIVE_THIRD_PARTY_APP.getValue() && FrodoBridge.search(null, null, null, context)) { return; } UrlHandler.open("path_to_url", context); } public static void showNotYetImplementedToast(Context context) { ToastUtils.show(R.string.not_yet_implemented, context); } public static void signUp(Context context) { UrlHandler.open("path_to_url", context); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/NotImplementedManager.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
289
```java /* * All Rights Reserved. */ package androidx.swiperefreshlayout.widget; import android.content.Context; import androidx.appcompat.widget.TintTypedArray; import android.util.AttributeSet; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; /** * Offers <code>app:progressOffset</code>, <code>app:progressDistanceOffset</code>. */ public class FriendlySwipeRefreshLayout extends ThemedSwipeRefreshLayout { private static final int CIRCLE_DIAMETER_DP = CIRCLE_DIAMETER; private static final int CIRCLE_DIAMETER_LARGE_DP = CIRCLE_DIAMETER_LARGE; private static final int CIRCLE_SHADOW_DP = 7; private static final int DEFAULT_CIRCLE_DISTANCE_DP = 64; // DEFAULT_CIRCLE_TARGET private int mSize = DEFAULT; private int mCircleDiameter; private int mDefaultCircleDistance; private CanChildScrollUpCallback mCanChildScrollUpCallback; public FriendlySwipeRefreshLayout(Context context) { super(context); init(null); } public FriendlySwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); init(attrs); } @SuppressWarnings("RestrictedApi") private void init(AttributeSet attrs) { updateCircleDiameter(); Context context = getContext(); mDefaultCircleDistance = ViewUtils.dpToPxOffset(DEFAULT_CIRCLE_DISTANCE_DP, context); TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, R.styleable.FriendlySwipeRefreshLayout, 0, 0); int progressOffset = a.getDimensionPixelOffset( R.styleable.FriendlySwipeRefreshLayout_progressOffset, 0); int progressDistanceOffset = a.getDimensionPixelOffset( R.styleable.FriendlySwipeRefreshLayout_progressDistanceOffset, 0); a.recycle(); if (progressOffset != 0 || progressDistanceOffset != 0) { setProgressViewOffset(progressOffset, progressDistanceOffset); } } @Override public void setSize(int size) { super.setSize(size); if (size == LARGE || size == DEFAULT) { mSize = size; updateCircleDiameter(); } } private void updateCircleDiameter() { int circleDiameterDp = mSize == DEFAULT ? CIRCLE_DIAMETER_DP : CIRCLE_DIAMETER_LARGE_DP; circleDiameterDp += CIRCLE_SHADOW_DP; mCircleDiameter = ViewUtils.dpToPxSize(circleDiameterDp, getContext()); } public void setProgressViewOffset(int offset, int distanceOffset) { int progressStart = offset - mCircleDiameter; int progressEnd = progressStart + mDefaultCircleDistance + distanceOffset; setProgressViewOffset(false, progressStart, progressEnd); } public void setProgressViewOffset(int offset) { setProgressViewOffset(offset, 0); } @Override public int getProgressCircleDiameter() { return mCircleDiameter; } public CanChildScrollUpCallback getCanChildScrollUpCallback() { return mCanChildScrollUpCallback; } public void setCanChildScrollUpCallback(CanChildScrollUpCallback canChildScrollUpCallback) { mCanChildScrollUpCallback = canChildScrollUpCallback; } @Override public boolean canChildScrollUp() { if (mCanChildScrollUpCallback != null) { return mCanChildScrollUpCallback.canChildScrollUp(); } return super.canChildScrollUp(); } public interface CanChildScrollUpCallback { boolean canChildScrollUp(); } } ```
/content/code_sandbox/app/src/main/java/androidx/swiperefreshlayout/widget/FriendlySwipeRefreshLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
769
```java /* * All Rights Reserved. */ package androidx.appcompat.app; import androidx.annotation.NonNull; public class NightModeAccessor { private NightModeAccessor() {} public static int mapNightMode(@NonNull AppCompatDelegate delegate, int mode) { return ((AppCompatDelegateImpl) delegate).mapNightMode(mode); } } ```
/content/code_sandbox/app/src/main/java/androidx/appcompat/app/NightModeAccessor.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
67
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.content.Context; import android.net.Uri; public class UriHandler { private UriHandler() {} public static void open(Uri uri, Context context) { if (DoubanUriHandler.open(uri, context)) { return; } if (FrodoBridge.openFrodoUri(uri, context)) { return; } UrlHandler.open(uri, context); } public static void open(String url, Context context) { open(Uri.parse(url), context); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/UriHandler.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
126
```shell #!/bin/bash set -e repo="$1" shift echo "Repo: ${repo}" >&2 version="$1" shift echo "Version: ${version}" >&2 tag="v${version}" echo "Tag: ${tag}" >&2 body="$1" shift echo "Body: ${body}" >&2 # Get old release by tag echo "Getting old release by tag..." >&2 response="$(curl -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" "path_to_url{repo}/releases/tags/${tag}")" echo "${response}" >&2 old_release_id="$(echo "${response}" | jq -r '.id')" if [[ "${old_release_id}" != "null" ]]; then # Delete old release echo "Deleting old release..." >&2 response="$(curl -X 'DELETE' -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" "path_to_url{repo}/releases/${old_release_id}")" echo "${response}" >&2 fi # Create release echo "Creating release..." >&2 response="$(curl -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" -H 'Content-Type: application/json' --data "{ \"tag_name\": $(echo -n "${tag}" | jq -s -R -r @json), \"name\": $(echo -n "${tag}" | jq -s -R -r @json), \"body\": $(echo -n "${body}" | jq -s -R -r @json) }" "path_to_url{repo}/releases")" echo "${response}" >&2 upload_url="$(echo "${response}" | jq -r '.upload_url' | sed 's/{?name,label}$//g')" echo "Upload url: ${upload_url}" >&2 for file in "$@"; do # Upload file echo "Uploading file: ${file}" >&2 name="$(basename "${file}")" response="$(curl -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" -H "Content-Type: $(file -b --mime-type "${file}")" --data-binary "@${file}" "${upload_url}?name=$(echo -n "${name}" | jq -s -R -r @uri)")" echo "${response}" >&2 done ```
/content/code_sandbox/upload-to-releases.sh
shell
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
489
```java /* * All Rights Reserved. */ package com.google.android.material.textfield; import android.annotation.SuppressLint; import android.content.Context; import android.util.AttributeSet; import android.widget.EditText; import me.zhanghai.android.douya.R; @SuppressLint("RestrictedApi") public class ExpandedHintTextInputLayout extends TextInputLayout { private EditText mHasTextEditText; public ExpandedHintTextInputLayout(Context context) { super(context); init(); } public ExpandedHintTextInputLayout(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ExpandedHintTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { collapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_AppCompat_Caption); mHasTextEditText = new EditText(getContext()); mHasTextEditText.setText(" "); } @Override void updateLabelState(boolean animate) { EditText realEditText = editText; editText = mHasTextEditText; super.updateLabelState(animate); editText = realEditText; } } ```
/content/code_sandbox/app/src/main/java/com/google/android/material/textfield/ExpandedHintTextInputLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
231
```ini # 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 # path_to_url # 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 # path_to_url#sec:decoupled_projects # org.gradle.parallel=true android.enableJetifier=true android.useAndroidX=true ```
/content/code_sandbox/gradle.properties
ini
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
199
```unknown #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # For Cygwin, ensure paths are in UNIX format before anything is touched. if $cygwin ; then [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ```
/content/code_sandbox/gradlew
unknown
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,552
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.scalpel; import android.content.Context; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import me.zhanghai.android.douya.app.RetainedFragment; import me.zhanghai.android.douya.eventbus.EventBusUtils; public class ScalpelHelperFragment extends RetainedFragment { private static final String FRAGMENT_TAG = ScalpelHelperFragment.class.getName(); private boolean mEnabled; private boolean mActivityCreated; private boolean mInjected; /** * @deprecated Use {@link #attachToActivity(Fragment)} instead. */ public static ScalpelHelperFragment attachTo(FragmentActivity activity) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); ScalpelHelperFragment fragment = (ScalpelHelperFragment) fragmentManager .findFragmentByTag(FRAGMENT_TAG); if (fragment == null) { fragment = new ScalpelHelperFragment(); fragmentManager.beginTransaction() .add(fragment, FRAGMENT_TAG) .commit(); } return fragment; } public static ScalpelHelperFragment attachToActivity(Fragment fragment) { //noinspection deprecation return attachTo(fragment.getActivity()); } public static void setEnabled(boolean enabled) { EventBusUtils.postAsync(new SetEnabledEvent(enabled)); } @Override public void onAttach(Context context) { super.onAttach(context); EventBusUtils.register(this); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mActivityCreated = true; if (mEnabled) { enable(); } } @Override public void onDetach() { super.onDetach(); EventBusUtils.unregister(this); mActivityCreated = false; mInjected = false; } private void setEnabledForActivity(boolean enabled) { if (mActivityCreated) { if (enabled) { enable(); } else if (mInjected) { ScalpelUtils.setEnabled(getActivity(), false); } } mEnabled = enabled; } private void enable() { if (!mInjected) { ScalpelUtils.inject(getActivity()); mInjected = true; } ScalpelUtils.setEnabled(getActivity(), true); } @Subscribe(threadMode = ThreadMode.POSTING) public void onSetEnabled(SetEnabledEvent event) { setEnabledForActivity(event.enabled); } private static class SetEnabledEvent { public boolean enabled; public SetEnabledEvent(boolean enabled) { this.enabled = enabled; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/scalpel/ScalpelHelperFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
577
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.recyclerview.widget.DefaultItemAnimator; /** * A DefaultItemAnimator with setSupportsChangeAnimations(false). */ public class NoChangeAnimationItemAnimator extends DefaultItemAnimator { public NoChangeAnimationItemAnimator() { setSupportsChangeAnimations(false); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/NoChangeAnimationItemAnimator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
74
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import me.zhanghai.android.douya.account.util.AccountUtils; public class UriHandlerActivity extends AppCompatActivity { public static Intent makeIntent(Uri uri, Context context) { return new Intent(context, UriHandlerActivity.class) .setData(uri); } public static Intent makeIntent(String url, Context context) { return makeIntent(Uri.parse(url), context); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = getIntent().getData(); if (uri == null) { finish(); return; } if (!AccountUtils.ensureActiveAccountAvailability(this)) { finish(); return; } UriHandler.open(uri, this); finish(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/UriHandlerActivity.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
205
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.home; import android.os.Bundle; import androidx.annotation.Nullable; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.broadcast.ui.HomeBroadcastListFragment; import me.zhanghai.android.douya.ui.AppBarHost; import me.zhanghai.android.douya.ui.AppBarWrapperLayout; import me.zhanghai.android.douya.ui.DoubleClickToolbar; import me.zhanghai.android.douya.ui.NotYetImplementedFragment; import me.zhanghai.android.douya.ui.TabFragmentPagerAdapter; public class HomeFragment extends Fragment implements AppBarHost { @BindView(R.id.appBarWrapper) AppBarWrapperLayout mAppBarWrapperLayout; @BindView(R.id.toolbar) DoubleClickToolbar mToolbar; @BindView(R.id.tab) TabLayout mTabLayout; @BindView(R.id.viewPager) ViewPager mViewPager; private TabFragmentPagerAdapter mTabAdapter; public static HomeFragment newInstance() { //noinspection deprecation return new HomeFragment(); } /** * @deprecated Use {@link #newInstance()} instead. */ public HomeFragment() {} @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.home_fragment, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(mToolbar); mTabAdapter = new TabFragmentPagerAdapter(this); mTabAdapter.addTab(HomeBroadcastListFragment::newInstance, getString(R.string.home_broadcast)); mTabAdapter.addTab(NotYetImplementedFragment::newInstance, getString(R.string.home_discover)); mTabAdapter.addTab(NotYetImplementedFragment::newInstance, getString(R.string.home_topic)); mTabAdapter.addTab(NotYetImplementedFragment::newInstance, getString(R.string.home_online)); mViewPager.setOffscreenPageLimit(mTabAdapter.getCount() - 1); mViewPager.setAdapter(mTabAdapter); mTabLayout.setupWithViewPager(mViewPager); } @Override public void showAppBar() { mAppBarWrapperLayout.show(); } @Override public void hideAppBar() { mAppBarWrapperLayout.hide(); } @Override public void setToolBarOnDoubleClickListener(DoubleClickToolbar.OnDoubleClickListener listener) { mToolbar.setOnDoubleClickListener(listener); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/home/HomeFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
607
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya; import android.app.Application; import android.os.Build; import androidx.annotation.NonNull; import android.webkit.WebView; import com.bumptech.glide.request.target.ViewTarget; import com.facebook.stetho.Stetho; import com.jakewharton.threetenabp.AndroidThreeTen; import me.zhanghai.android.douya.fabric.FabricUtils; import me.zhanghai.android.douya.util.NightModeHelper; public class DouyaApplication extends Application { @NonNull private static DouyaApplication sInstance; public DouyaApplication() { sInstance = this; } @NonNull public static DouyaApplication getInstance() { return sInstance; } @Override public void onCreate() { super.onCreate(); NightModeHelper.setup(this); AndroidThreeTen.init(this); FabricUtils.init(this); ViewTarget.setTagId(R.id.glide_view_target_tag); Stetho.initializeWithDefaults(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/DouyaApplication.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
257
```java /* * All Rights Reserved. */ package androidx.swiperefreshlayout.widget; import android.content.Context; import android.graphics.drawable.ShapeDrawable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.util.AttributeSet; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; public class ThemedSwipeRefreshLayout extends SwipeRefreshLayout { public ThemedSwipeRefreshLayout(@NonNull Context context) { super(context); init(); } public ThemedSwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { Context context = getContext(); ((ShapeDrawable) mCircleView.getBackground()).getPaint().setColor( ViewUtils.getColorFromAttrRes(R.attr.colorBackgroundFloating, 0, context)); setColorSchemeColors(ViewUtils.getColorFromAttrRes(R.attr.colorAccent, 0, context)); } } ```
/content/code_sandbox/app/src/main/java/androidx/swiperefreshlayout/widget/ThemedSwipeRefreshLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
208
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.scalpel; import android.app.Activity; import android.view.View; import android.view.ViewGroup; import com.jakewharton.scalpel.ScalpelFrameLayout; public class ScalpelUtils { private ScalpelUtils() {} public static void inject(Activity activity) { ViewGroup contentLayout = findContentLayout(activity); ScalpelFrameLayout scalpelLayout = new ScalpelFrameLayout(activity); while (contentLayout.getChildCount() > 0) { View view = contentLayout.getChildAt(0); contentLayout.removeViewAt(0); scalpelLayout.addView(view); } contentLayout.addView(scalpelLayout); } public static void setEnabled(Activity activity, boolean enabled) { findScalpelLayout(activity).setLayerInteractionEnabled(enabled); } private static ViewGroup findContentLayout(Activity activity) { return (ViewGroup) activity.findViewById(android.R.id.content); } private static ScalpelFrameLayout findScalpelLayout(Activity activity) { return (ScalpelFrameLayout) findContentLayout(activity).getChildAt(0); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/scalpel/ScalpelUtils.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
242
```unknown storeFile=travis.jks storePassword= keyAlias=douya keyPassword= ```
/content/code_sandbox/signing.properties.travis
unknown
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
21
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.viewpager.widget.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; // @see path_to_url public class FixIllegalArgumentExceptionViewPager extends ViewPager { public FixIllegalArgumentExceptionViewPager(@NonNull Context context) { super(context); } public FixIllegalArgumentExceptionViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(@NonNull MotionEvent event) { try { return super.onInterceptTouchEvent(event); } catch (IllegalArgumentException e) { e.printStackTrace(); return false; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FixIllegalArgumentExceptionViewPager.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
160
```batchfile @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ```
/content/code_sandbox/gradlew.bat
batchfile
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
632
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.content.Context; import android.content.Intent; import android.content.UriMatcher; import android.net.Uri; import android.text.TextUtils; import java.util.regex.Pattern; import me.zhanghai.android.douya.broadcast.ui.BroadcastActivity; import me.zhanghai.android.douya.broadcast.ui.BroadcastListActivity; import me.zhanghai.android.douya.followship.ui.FollowerListActivity; import me.zhanghai.android.douya.followship.ui.FollowingListActivity; import me.zhanghai.android.douya.item.ui.BookActivity; import me.zhanghai.android.douya.item.ui.GameActivity; import me.zhanghai.android.douya.item.ui.MovieActivity; import me.zhanghai.android.douya.item.ui.MusicActivity; import me.zhanghai.android.douya.profile.ui.ProfileActivity; import me.zhanghai.android.douya.util.UriUtils; public class DoubanUriHandler { private static final Pattern DISPATCH_URI_PATTERN = Pattern.compile( "path_to_url"); private static final String DISPATCH_URI_QUERY_PARAMETER_URI = "uri"; private static final String DISPATCH_URI_QUERY_PARAMETER_URI_PREFIX = "douban://douban.com"; private static final String AUTHORITY = "www.douban.com"; private static final String AUTHORITY_BOOK = "book.douban.com"; private static final String AUTHORITY_MOVIE = "movie.douban.com"; private static final String AUTHORITY_MUSIC = "music.douban.com"; private static final String AUTHORITY_FRODO = "douban.com"; private enum UriType { // NOTE: * must come before # if they are at the same position, or UriMatcher tree won't // backtrack. TOPIC_BROADCAST_LIST("update/topic/*"), // Handled below. //TOPIC_BROADCAST_LIST_FRODO(AUTHORITY_FRODO, "status/topic?name=*"), BROADCAST("people/*/status/#"), BROADCAST_FRODO(AUTHORITY_FRODO, "status/#"), BROADCAST_CHILD_FRODO(AUTHORITY_FRODO,"status/#/*"), // Reordered for correct behavior TOPIC_BROADCAST_LIST_FRODO(AUTHORITY_FRODO, "status/*"), USER("people/*"), USER_FRODO(AUTHORITY_FRODO, "user/*"), USER_FOLLOWER_LIST("people/*/rev_contacts"), USER_FOLLOWER_LIST_FRODO(AUTHORITY_FRODO, "user/*/follower"), USER_FOLLOWING_LIST("people/*/contacts"), USER_FOLLOWING_LIST_FRODO(AUTHORITY_FRODO, "user/*/following"), // Reordered for correct behavior // Not handling "people/*/statuses" because Frodo API cannot handle it. USER_BROADCAST_LIST("people/#/statuses"), BOOK(AUTHORITY_BOOK, "subject/#"), BOOK_FRODO(AUTHORITY_FRODO, "book/#"), MOVIE(AUTHORITY_MOVIE, "subject/#"), MOVIE_FRODO(AUTHORITY_FRODO, "movie/#"), MUSIC(AUTHORITY_MUSIC, "subject/#"), MUSIC_FRODO(AUTHORITY_FRODO, "music/#"), GAME("game/#"), GAME_FRODO(AUTHORITY_FRODO, "game/#"); String mAuthority; String mPath; UriType(String authority, String path) { mAuthority = authority; mPath = path; } UriType(String path) { this(AUTHORITY, path); } public String getAuthority() { return mAuthority; } public String getPath() { return mPath; } } private static final UriMatcher MATCHER; static { MATCHER = new UriMatcher(UriMatcher.NO_MATCH); for (UriType uriType : UriType.values()) { MATCHER.addURI(uriType.getAuthority(), uriType.getPath(), uriType.ordinal()); } } private DoubanUriHandler() {} public static boolean open(Uri uri, Context context) { if (DISPATCH_URI_PATTERN.matcher(uri.toString()).matches()) { uri = Uri.parse(DISPATCH_URI_QUERY_PARAMETER_URI_PREFIX + uri.getQueryParameter( DISPATCH_URI_QUERY_PARAMETER_URI)); } int code = MATCHER.match(uri); if (code == UriMatcher.NO_MATCH) { return false; } UriType uriType = UriType.values()[code]; Intent intent; switch (uriType) { case USER_BROADCAST_LIST: intent = BroadcastListActivity.makeIntent(uri.getPathSegments().get(1), context); break; case TOPIC_BROADCAST_LIST: intent = BroadcastListActivity.makeTopicIntent(uri.getLastPathSegment(), context); break; case TOPIC_BROADCAST_LIST_FRODO: { if (!TextUtils.equals(uri.getLastPathSegment(), "topic")) { return false; } intent = BroadcastListActivity.makeTopicIntent(uri.getQueryParameter("name"), context); break; } case BROADCAST: case BROADCAST_FRODO: intent = BroadcastActivity.makeIntent(UriUtils.parseId(uri), context); break; case BROADCAST_CHILD_FRODO: { long broadcastId = Long.parseLong(uri.getPathSegments().get(1)); intent = BroadcastActivity.makeIntent(broadcastId, context); break; } case USER: case USER_FRODO: intent = ProfileActivity.makeIntent(uri.getLastPathSegment(), context); break; case USER_FOLLOWER_LIST: case USER_FOLLOWER_LIST_FRODO: intent = FollowerListActivity.makeIntent(uri.getPathSegments().get(1), context); break; case USER_FOLLOWING_LIST: case USER_FOLLOWING_LIST_FRODO: intent = FollowingListActivity.makeIntent(uri.getPathSegments().get(1), context); break; case BOOK: case BOOK_FRODO: intent = BookActivity.makeIntent(UriUtils.parseId(uri), context); break; case MOVIE: case MOVIE_FRODO: intent = MovieActivity.makeIntent(UriUtils.parseId(uri), context); break; case MUSIC: case MUSIC_FRODO: intent = MusicActivity.makeIntent(UriUtils.parseId(uri), context); break; case GAME: case GAME_FRODO: intent = GameActivity.makeIntent(UriUtils.parseId(uri), context); break; default: return false; } context.startActivity(intent); return true; } public static boolean open(String uri, Context context) { return open(Uri.parse(uri), context); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/DoubanUriHandler.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,416
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; import java.util.List; import me.zhanghai.android.douya.util.AppUtils; import me.zhanghai.android.douya.util.MoreTextUtils; public class FrodoBridge { private static final String FRODO_SCHEME = "douban"; private static final String FACADE_ACTION = "com.douban.frodo"; private static final String FRODO_PACKAGE_NAME = "com.douban.frodo"; private static final String SEARCH_CLASS_NAME = ".activity.SearchActivity"; private static final String SEARCH_EXTRA_QUERY = "query"; private static final String SEARCH_EXTRA_TYPE = "com.douban.frodo.QUERY_TYPE"; private static final String SEARCH_EXTRA_ENTRY = "search_entry"; private static final String SEND_STATUS_CLASS_NAME = ".status.activity.StatusEditActivity"; private static final String SEND_STATUS_EXTRA_HASHTAG_NAME = "hashtag_name"; private FrodoBridge() {} public static boolean openUri(Uri uri, Context context) { if (!isUriHandled(uri)) { return false; } Intent intent = makeFacadeIntent(uri); return AppUtils.isIntentHandled(intent, context) && startActivity(intent, context); } /** * Whether an uri is likely to be handled by native in Frodo. We don't need Frodo's WebActivity. */ private static boolean isUriHandled(Uri uri) { String scheme = uri.getScheme(); if (TextUtils.equals(scheme, FRODO_SCHEME)) { return true; } else if (MoreTextUtils.equalsAny(scheme, "https", "http")) { // Data updated at 2016-09. String host = uri.getHost(); if (!TextUtils.isEmpty(host) && MoreTextUtils.equalsAny(host, "www.douban.com", "m.douban.com", "book.douban.com", "movie.douban.com", "music.douban.com", "dongxi.douban.com")) { List<String> pathSegments = uri.getPathSegments(); String pathSegment0 = pathSegments.size() >= 1 ? pathSegments.get(0) : null; if (!TextUtils.isEmpty(pathSegment0)) { if (MoreTextUtils.equalsAny(pathSegment0, "group", "theme", "update", "hashtag", "app_topic", "subject", "book", "music", "movie", "game", "mobileapp", "event", "note", "show", "doulist", "review", "photos", "celebrity")) { return true; } else if (TextUtils.equals(pathSegment0, "people")) { String pathSegment2 = pathSegments.size() >= 3 ? pathSegments.get(2) : null; if (TextUtils.isEmpty(pathSegment2)) { return true; } else if (MoreTextUtils.equalsAny(pathSegment2, "reviews", "wish", "collect", "games", "apps", "status")) { return true; } } } } } return false; } private static Intent makeFacadeIntent(Uri uri) { return new Intent(FACADE_ACTION, uri); } public static boolean openFrodoUri(Uri uri, Context context) { return isFrodoUri(uri) && openUri(uri, context); } public static boolean isFrodoUri(Uri uri) { return TextUtils.equals(uri.getScheme(), FRODO_SCHEME); } public static boolean search(String query, String type, String entry, Context context) { return startActivity(makeSearchIntent(query, type, entry), context); } private static Intent makeSearchIntent(String query, String type, String entry) { return makeClassIntent(SEARCH_CLASS_NAME) .putExtra(SEARCH_EXTRA_QUERY, query) .putExtra(SEARCH_EXTRA_TYPE, type) .putExtra(SEARCH_EXTRA_ENTRY, entry); } public static boolean sendBroadcast(String topic, Context context) { return startActivity(makeSendBroadcastIntent(topic), context); } private static Intent makeSendBroadcastIntent(String hashTagName) { return makeClassIntent(SEND_STATUS_CLASS_NAME) .putExtra(SEND_STATUS_EXTRA_HASHTAG_NAME, hashTagName); } private static Intent makeClassIntent(String className) { return new Intent() .setComponent(new ComponentName(FRODO_PACKAGE_NAME, FRODO_PACKAGE_NAME + className)); } // Different from AppUtils.startActivity(), this one won't show a toast when failed. private static boolean startActivity(Intent intent, Context context) { try { context.startActivity(intent); return true; } catch (ActivityNotFoundException | IllegalArgumentException e) { return false; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/FrodoBridge.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,047
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.link; import android.app.Activity; import android.content.Context; import android.net.Uri; import android.text.TextUtils; import org.chromium.customtabsclient.CustomTabsActivityHelper; import me.zhanghai.android.douya.settings.info.Settings; import me.zhanghai.android.douya.util.AppUtils; import me.zhanghai.android.douya.util.UrlUtils; public class UrlHandler { private static final CustomTabsActivityHelper.CustomTabsFallback sFallback = new CustomTabsActivityHelper.CustomTabsFallback() { @Override public void openUri(Activity activity, Uri uri) { open(uri, activity, false); } }; private UrlHandler() {} private static void open(Uri uri, Context context, boolean enableCustomTabs) { if (Settings.PROGRESSIVE_THIRD_PARTY_APP.getValue() && FrodoBridge.openUri(uri, context)) { return; } String scheme = uri.getScheme(); if (!TextUtils.isEmpty(scheme)) { switch (uri.getScheme()) { case "http": case "https": case "ftp": break; default: UrlUtils.openWithIntent(uri, context); return; } } switch (Settings.OPEN_URL_WITH_METHOD.getEnumValue()) { case CUSTOM_TABS: if (enableCustomTabs) { Activity activity = AppUtils.getActivityFromContext(context); if (activity != null) { UrlUtils.openWithCustomTabs(uri, sFallback, activity); } break; } // Fall through! case WEBVIEW: UrlUtils.openWithWebViewActivity(uri, context); break; case INTENT: UrlUtils.openWithIntent(uri, context); break; } } public static void open(Uri uri, Context context) { open(uri, context, true); } public static void open(String url, Context context) { open(Uri.parse(url), context); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/link/UrlHandler.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
422
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.core.view.GestureDetectorCompat; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; public abstract class OnGestureTouchListener implements View.OnTouchListener { private final GestureDetectorCompat mGestureDetector; public OnGestureTouchListener(Context context, boolean isLongPressEnabled) { mGestureDetector = new GestureDetectorCompat(context, new OnGestureListener()); mGestureDetector.setIsLongpressEnabled(isLongPressEnabled); } @Override public boolean onTouch(View view, MotionEvent event) { return mGestureDetector.onTouchEvent(event); } // SimpleOnGestureListener conditionally implements OnContextClickListener. private final class OnGestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onDown(MotionEvent event) { // Return true because we want system to report subsequent events to us. return true; } @Override public void onShowPress(MotionEvent event) { OnGestureTouchListener.this.onShowPress(event); } @Override public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) { return OnGestureTouchListener.this.onScroll(event1, event2, distanceX, distanceY); } @Override public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { return OnGestureTouchListener.this.onFling(event1, event2, velocityX, velocityY); } @Override public void onLongPress(MotionEvent event) { OnGestureTouchListener.this.onLongPress(event); } @Override public boolean onSingleTapUp(MotionEvent event) { return OnGestureTouchListener.this.onSingleTapUp(event); } @Override public boolean onSingleTapConfirmed(MotionEvent event) { return OnGestureTouchListener.this.onSingleTapConfirmed(event); } @Override public boolean onDoubleTap(MotionEvent event) { return OnGestureTouchListener.this.onDoubleTap(event); } @Override public boolean onDoubleTapEvent(MotionEvent event) { return OnGestureTouchListener.this.onDoubleTapEvent(event); } @Override public boolean onContextClick(MotionEvent event) { return OnGestureTouchListener.this.onContextClick(event); } } public void onShowPress(MotionEvent event) {} public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) { return false; } public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { return false; } public void onLongPress(MotionEvent event) {} public boolean onSingleTapUp(MotionEvent event) { return false; } public boolean onSingleTapConfirmed(MotionEvent event) { return false; } public boolean onDoubleTap(MotionEvent event) { return false; } public boolean onDoubleTapEvent(MotionEvent event) { return false; } // Will only be called on API level >= 23. public boolean onContextClick(MotionEvent event) { return false; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/OnGestureTouchListener.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
694
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; import android.util.AttributeSet; import android.util.DisplayMetrics; public class FastSmoothScrollStaggeredGridLayoutManager extends StaggeredGridLayoutManager { public FastSmoothScrollStaggeredGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public FastSmoothScrollStaggeredGridLayoutManager(int spanCount, int orientation) { super(spanCount, orientation); } @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { FastLinearSmoothScroller scroller = new FastLinearSmoothScroller(recyclerView.getContext()); scroller.setTargetPosition(position); startSmoothScroll(scroller); } private static class FastLinearSmoothScroller extends LinearSmoothScroller { private static final float MILLISECONDS_PER_INCH = 10f; public FastLinearSmoothScroller(Context context) { super(context); } @Override protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { return MILLISECONDS_PER_INCH / displayMetrics.densityDpi; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FastSmoothScrollStaggeredGridLayoutManager.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
285
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import android.util.AttributeSet; import android.widget.FrameLayout; public class TallFrameLayout extends FrameLayout { public TallFrameLayout(@NonNull Context context) { super(context); } public TallFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public TallFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public TallFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); int height = getMeasuredHeight(); if (height < width) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/TallFrameLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
268
```java package me.zhanghai.android.douya.ui; import android.content.Context; import android.os.Build; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import android.util.AttributeSet; import android.widget.LinearLayout; public class GetOnLongClickListenerLinearLayout extends LinearLayout { private OnLongClickListener mOnLongClickListener; public GetOnLongClickListenerLinearLayout(Context context) { super(context); } public GetOnLongClickListenerLinearLayout(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public GetOnLongClickListenerLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public GetOnLongClickListenerLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public OnLongClickListener getOnLongClickListener() { return mOnLongClickListener; } @Override public void setOnLongClickListener(@Nullable OnLongClickListener listener) { super.setOnLongClickListener(listener); mOnLongClickListener = listener; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/GetOnLongClickListenerLinearLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
238
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.text.TextPaint; import android.text.style.ClickableSpan; import android.view.View; import me.zhanghai.android.douya.link.UriHandler; public class UriSpan extends ClickableSpan { private String mUri; public UriSpan(String uri) { mUri = uri; } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } @Override public void onClick(View widget) { UriHandler.open(mUri, widget.getContext()); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/UriSpan.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
139
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; import androidx.annotation.NonNull; import android.util.AttributeSet; import android.view.View; import android.widget.RelativeLayout; @SuppressLint("MissingSuperCall") @TargetApi(Build.VERSION_CODES.M) public class ForegroundRelativeLayout extends RelativeLayout { private ForegroundHelper mForegroundHelper = new ForegroundHelper( new ForegroundHelper.Delegate() { @Override public View getOwner() { return ForegroundRelativeLayout.this; } @Override public int superGetForegroundGravity() { return ForegroundRelativeLayout.super.getForegroundGravity(); } @Override public void superSetForegroundGravity(int foregroundGravity) { ForegroundRelativeLayout.super.setForegroundGravity(foregroundGravity); } @Override public void superSetVisibility(int visibility) { ForegroundRelativeLayout.super.setVisibility(visibility); } @Override public boolean superVerifyDrawable(Drawable who) { return ForegroundRelativeLayout.super.verifyDrawable(who); } @Override public void superJumpDrawablesToCurrentState() { ForegroundRelativeLayout.super.jumpDrawablesToCurrentState(); } @Override public void superDrawableStateChanged() { ForegroundRelativeLayout.super.drawableStateChanged(); } @Override public void superDrawableHotspotChanged(float x, float y) { ForegroundRelativeLayout.super.drawableHotspotChanged(x, y); } @Override public void superSetForeground(Drawable foreground) { ForegroundRelativeLayout.super.setForeground(foreground); } @Override public Drawable superGetForeground() { return ForegroundRelativeLayout.super.getForeground(); } @Override @SuppressLint("WrongCall") public void superOnLayout(boolean changed, int left, int top, int right, int bottom) { ForegroundRelativeLayout.super.onLayout(changed, left, top, right, bottom); } @Override public void superOnSizeChanged(int w, int h, int oldw, int oldh) { ForegroundRelativeLayout.super.onSizeChanged(w, h, oldw, oldh); } @Override public void superDraw(@NonNull Canvas canvas) { ForegroundRelativeLayout.super.draw(canvas); } }); public ForegroundRelativeLayout(Context context) { super(context); init(null, 0, 0); } public ForegroundRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); init(attrs, 0, 0); } public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr, 0); } public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(attrs, defStyleAttr, defStyleRes); } private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { mForegroundHelper.init(getContext(), attrs, defStyleAttr, defStyleRes); } /** * {@inheritDoc} */ @Override public int getForegroundGravity() { return mForegroundHelper.getForegroundGravity(); } /** * {@inheritDoc} */ @Override public void setForegroundGravity(int foregroundGravity) { if (mForegroundHelper == null) { // Can be null during super class initialization. In this case framework has support for // foreground, so simply call super. super.setForegroundGravity(foregroundGravity); } else { mForegroundHelper.setForegroundGravity(foregroundGravity); } } /** * {@inheritDoc} */ @Override public void setVisibility(int visibility) { mForegroundHelper.setVisibility(visibility); } /** * {@inheritDoc} */ @Override protected boolean verifyDrawable(Drawable who) { return mForegroundHelper.verifyDrawable(who); } /** * {@inheritDoc} */ @Override public void jumpDrawablesToCurrentState() { mForegroundHelper.jumpDrawablesToCurrentState(); } /** * {@inheritDoc} */ @Override protected void drawableStateChanged() { mForegroundHelper.drawableStateChanged(); } /** * {@inheritDoc} */ @Override public void drawableHotspotChanged(float x, float y) { mForegroundHelper.drawableHotspotChanged(x, y); } /** * {@inheritDoc} */ @Override public void setForeground(Drawable foreground) { if (mForegroundHelper == null) { // Can be null during super class initialization. In this case framework has support for // foreground, so simply call super. super.setForeground(foreground); } else { mForegroundHelper.setForeground(foreground); } } /** * {@inheritDoc} */ @Override public Drawable getForeground() { return mForegroundHelper.getForeground(); } /** * {@inheritDoc} */ @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { mForegroundHelper.onLayout(changed, left, top, right, bottom); } /** * {@inheritDoc} */ @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mForegroundHelper.onSizeChanged(w, h, oldw, oldh); } /** * {@inheritDoc} */ @Override public void draw(@NonNull Canvas canvas) { mForegroundHelper.draw(canvas); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ForegroundRelativeLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,223
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.net.Uri; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; public class HorizontalUploadImageAdapter extends ClickableSimpleAdapter<Uri, HorizontalUploadImageAdapter.ViewHolder> { private OnRemoveImageListener mOnRemoveImageListener; public HorizontalUploadImageAdapter() { setHasStableIds(true); } public void setOnRemoveImageListener(OnRemoveImageListener listener) { mOnRemoveImageListener = listener; } @Override public long getItemId(int position) { return getItem(position).hashCode(); } @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { UploadImageLayout itemView = (UploadImageLayout) ViewUtils.inflate( R.layout.horizontal_upload_image_item, parent); itemView.setInImageList(true); return new ViewHolder(itemView); } @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { holder.uploadImageLayout.loadImage(getItem(position)); holder.uploadImageLayout.setRemoveButtonOnClickListener(view -> { if (mOnRemoveImageListener != null) { mOnRemoveImageListener.onRemoveImage(holder.getAdapterPosition()); } }); } public interface OnRemoveImageListener { void onRemoveImage(int position); } static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.image) public UploadImageLayout uploadImageLayout; public ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/HorizontalUploadImageAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
379
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.ImageViewState; import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; public class SaveStateSubsamplingScaleImageView extends SubsamplingScaleImageView { private ImageViewState mPendingSavedState; public SaveStateSubsamplingScaleImageView(@NonNull Context context) { super(context); } public SaveStateSubsamplingScaleImageView(@NonNull Context context, @Nullable AttributeSet attr) { super(context, attr); } public void setImageRestoringSavedState(@NonNull ImageSource imageSource) { setImage(imageSource, mPendingSavedState); mPendingSavedState = null; } @NonNull @Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState savedState = new SavedState(superState); savedState.state = getState(); return savedState; } @Override protected void onRestoreInstanceState(@NonNull Parcelable state) { SavedState savedState = (SavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); mPendingSavedState = savedState.state; } private static class SavedState extends BaseSavedState { public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() { @Override public SavedState createFromParcel(Parcel source) { return new SavedState(source); } @Override public SavedState[] newArray(int size) { return new SavedState[size]; } }; public ImageViewState state; public SavedState(Parcel in) { super(in); state = (ImageViewState) in.readSerializable(); } public SavedState(Parcelable superState) { super(superState); } @Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); dest.writeSerializable(state); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/SaveStateSubsamplingScaleImageView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
471
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import androidx.annotation.NonNull; import androidx.viewpager.widget.PagerAdapter; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; public class TabViewPagerAdapter extends PagerAdapter { private static final String KEY_PREFIX = TabViewPagerAdapter.class.getName() + '.'; private static final String STATE_HIERARCHY_STATE_FORMAT = KEY_PREFIX + "hierarchy_state_%1$d"; private View[] mViews; private CharSequence[] mTitles; public TabViewPagerAdapter(View[] views, CharSequence[] titles) { init(views, titles); } public TabViewPagerAdapter(View[] views, int[] titleResIds, Context context) { CharSequence[] titles = new CharSequence[titleResIds.length]; for (int i = 0; i < titleResIds.length; ++i) { titles[i] = context.getText(titleResIds[i]); } init(views, titles); } private void init(View[] views, CharSequence[] titles) { if (views.length != titles.length) { throw new IllegalArgumentException("View size and title size mismatch"); } mViews = views; mTitles = titles; } @Override public int getCount() { return mViews.length; } @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { View view = mViews[position]; container.addView(view); return view; } @Override public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { container.removeViewAt(position); } @Override public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @Override public CharSequence getPageTitle(int position) { return mTitles[position]; } @Override public Parcelable saveState() { Bundle state = new Bundle(); for (int i = 0; i < mViews.length; ++i) { SparseArray<Parcelable> hierarchyState = new SparseArray<>(); mViews[i].saveHierarchyState(hierarchyState); state.putSparseParcelableArray(makeHierarchyStateKey(i), hierarchyState); } return state; } @Override public void restoreState(Parcelable state, ClassLoader loader) { if (state == null) { return; } Bundle stateBundle = (Bundle) state; stateBundle.setClassLoader(loader); for (int i = 0; i < mViews.length; ++i) { SparseArray<Parcelable> hierarchyState = stateBundle.getSparseParcelableArray( makeHierarchyStateKey(i)); if (hierarchyState == null) { continue; } mViews[i].restoreHierarchyState(hierarchyState); } } private String makeHierarchyStateKey(int position) { return String.format(STATE_HIERARCHY_STATE_FORMAT, position); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/TabViewPagerAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
655
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.recyclerview.widget.RecyclerView; import android.view.ViewConfiguration; public abstract class OnVerticalScrollWithPagingTouchSlopListener extends OnVerticalScrollListener { private final int mPagingTouchSlop; // Distance in y since last idle or direction change. private int mDy; public OnVerticalScrollWithPagingTouchSlopListener(Context context) { mPagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop(); } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { mDy = 0; } } @Override public final void onScrolledUp(int dy) { mDy = mDy < 0 ? mDy + dy : dy; if (mDy < -mPagingTouchSlop) { onScrolledUp(); } } @Override public final void onScrolledDown(int dy) { mDy = mDy > 0 ? mDy + dy : dy; if (mDy > mPagingTouchSlop) { onScrolledDown(); } } public void onScrolledUp() {} public void onScrolledDown() {} } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/OnVerticalScrollWithPagingTouchSlopListener.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
309
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.view.ViewCompat; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatButton; import android.util.AttributeSet; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; public class ColoredBorderButton extends AppCompatButton { public ColoredBorderButton(Context context) { super(context); init(); } public ColoredBorderButton(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ColoredBorderButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { Context context = getContext(); Drawable background = AppCompatResources.getDrawable(context, R.drawable.colored_border_button_background); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { background = DrawableCompat.wrap(background); DrawableCompat.setTint(background, ViewUtils.getColorFromAttrRes(R.attr.colorAccent, 0, context)); } ViewCompat.setBackground(this, background); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ColoredBorderButton.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
273
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.annotation.NonNull; import androidx.viewpager.widget.ViewPager; import android.view.View; // @see path_to_url public class ViewPagerTransformers { private ViewPagerTransformers() {} public static ViewPager.PageTransformer DEPTH = new Depth(); public static ViewPager.PageTransformer ZOOM_OUT = new ZoomOut(); private static class Depth implements ViewPager.PageTransformer { private static final float MIN_SCALE = 0.75f; public void transformPage(@NonNull View view, float position) { int pageWidth = view.getWidth(); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. view.setAlpha(0); } else if (position <= 0) { // [-1,0] // Use the default slide transition when moving to the left page view.setAlpha(1); view.setTranslationX(0); view.setScaleX(1); view.setScaleY(1); } else if (position <= 1) { // (0,1] // Fade the page out. view.setAlpha(1 - position); // Counteract the default slide transition view.setTranslationX(pageWidth * -position); // Scale the page down (between MIN_SCALE and 1) float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); } else { // (1,+Infinity] // This page is way off-screen to the right. view.setAlpha(0); } } } private static class ZoomOut implements ViewPager.PageTransformer { private static final float MIN_SCALE = 0.85f; private static final float MIN_ALPHA = 0.5f; public void transformPage(@NonNull View view, float position) { int pageWidth = view.getWidth(); int pageHeight = view.getHeight(); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. view.setAlpha(0); } else if (position <= 1) { // [-1,1] // Modify the default slide transition to shrink the page as well float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); float verticalMargin = pageHeight * (1 - scaleFactor) / 2; float horizontalMargin = pageWidth * (1 - scaleFactor) / 2; if (position < 0) { view.setTranslationX(horizontalMargin - verticalMargin / 2); } else { view.setTranslationX(-horizontalMargin + verticalMargin / 2); } // Scale the page down (between MIN_SCALE and 1) view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); // Fade the page relative to its size. view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); } else { // (1,+Infinity] // This page is way off-screen to the right. view.setAlpha(0); } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ViewPagerTransformers.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
693
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Paint; import android.graphics.Path; import android.graphics.drawable.shapes.Shape; import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; public class PolygonShape extends Shape { private int mNumSides; private Path mPolygon = new Path(); public PolygonShape(int numSides) { mNumSides = numSides; } @Override protected void onResize(float width, float height) { mPolygon.rewind(); double radianPerSide = 2 * Math.PI / mNumSides; float halfWidth = width / 2; float halfHeight = height / 2; mPolygon.moveTo(halfWidth, 0); for (int i = 1; i < mNumSides; ++i) { mPolygon.lineTo(halfWidth + (float) Math.sin(i * radianPerSide) * halfWidth, halfHeight - (float) Math.cos(i * radianPerSide) * halfHeight); } mPolygon.close(); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(@NonNull Outline outline) { outline.setConvexPath(mPolygon); } @Override public void draw(Canvas canvas, Paint paint) { canvas.drawPath(mPolygon, paint); } @Override public PolygonShape clone() throws CloneNotSupportedException { PolygonShape polygonShape = (PolygonShape) super.clone(); polygonShape.mPolygon = new Path(mPolygon); return polygonShape; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/PolygonShape.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
363
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.appcompat.widget.AppCompatTextView; import android.util.AttributeSet; import me.zhanghai.android.douya.util.SpanUtils; import me.zhanghai.android.douya.util.ViewUtils; public class AutoLinkTextView extends AppCompatTextView { public AutoLinkTextView(Context context) { super(context); init(); } public AutoLinkTextView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public AutoLinkTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { if (getAutoLinkMask() != 0) { throw new IllegalStateException("Don't set android:autoLink"); } ViewUtils.setTextViewLinkClickable(this); } @Override public void setText(CharSequence text, BufferType type) { super.setText(SpanUtils.addLinks(text), BufferType.SPANNABLE); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/AutoLinkTextView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
221
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.util.AttributeSet; @SuppressWarnings("deprecation") public class NestedRatioHeightRecyclerView extends RatioHeightRecyclerView { public NestedRatioHeightRecyclerView(Context context) { super(context); init(); } public NestedRatioHeightRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public NestedRatioHeightRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { setFocusableInTouchMode(false); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/NestedRatioHeightRecyclerView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
135
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.recyclerview.widget.RecyclerView; import android.view.View; import java.util.List; public abstract class ClickableSimpleAdapter<T, VH extends RecyclerView.ViewHolder> extends SimpleAdapter<T, VH> { private OnItemClickListener<T> mOnItemClickListener; private RecyclerView mRecyclerView; public ClickableSimpleAdapter() {} public ClickableSimpleAdapter(List<T> list, OnItemClickListener<T> onItemClickListener) { super(list); mOnItemClickListener = onItemClickListener; } public OnItemClickListener<T> getOnItemClickListener() { return mOnItemClickListener; } public void setOnItemClickListener(OnItemClickListener<T> onItemClickListener) { mOnItemClickListener = onItemClickListener; } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); mRecyclerView = recyclerView; } @Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { super.onDetachedFromRecyclerView(recyclerView); mRecyclerView = null; } @Override public void onBindViewHolder(final VH holder, int position, List<Object> payloads) { super.onBindViewHolder(holder, position, payloads); T item = getItem(position); holder.itemView.setOnClickListener(view -> { if (mOnItemClickListener == null) { return; } mOnItemClickListener.onItemClick(mRecyclerView, holder.itemView, item, holder.getAdapterPosition()); }); } public interface OnItemClickListener<T> { void onItemClick(RecyclerView parent, View itemView, T item, int position); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ClickableSimpleAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
336
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.SortedList; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; public abstract class SortedListAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> { @NonNull private final List<T> mList = new ArrayList<>(); @NonNull private SortedList<T> mSortedList; protected void init(@NonNull Class<T> classOfT, @NonNull SortedList.Callback<T> callback) { mSortedList = new SortedList<>(classOfT, callback); } public void refresh() { mSortedList.beginBatchedUpdates(); mSortedList.clear(); mSortedList.addAll(mList); mSortedList.endBatchedUpdates(); } public void replace(@NonNull List<T> list) { mList.clear(); mList.addAll(list); mSortedList.replaceAll(mList); } public void clear() { mList.clear(); mSortedList.clear(); } @Nullable protected T getItem(int position) { return mSortedList.get(position); } @Override public int getItemCount() { return mSortedList.size(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/SortedListAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
273
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.text.Layout; import android.text.Selection; import android.text.Spannable; import android.text.method.BaseMovementMethod; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.MotionEvent; import android.widget.TextView; /** * A movement method that traverses links in the text buffer and fires clicks. Unlike * {@link LinkMovementMethod}, this will not consume touch events outside {@link ClickableSpan}s. */ public class ClickableMovementMethod extends BaseMovementMethod { @Nullable private static ClickableMovementMethod sInstance; @NonNull public static ClickableMovementMethod getInstance() { if (sInstance == null) { sInstance = new ClickableMovementMethod(); } return sInstance; } @Override public boolean canSelectArbitrarily() { return false; } @Override public boolean onTouchEvent(@NonNull TextView widget, @Nullable Spannable buffer, @NonNull MotionEvent event) { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); Layout layout = widget.getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); if (link.length > 0) { if (action == MotionEvent.ACTION_UP) { link[0].onClick(widget); } else { Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])); } return true; } else { Selection.removeSelection(buffer); } } return false; } @Override public void initialize(@NonNull TextView widget, @NonNull Spannable text) { Selection.removeSelection(text); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ClickableMovementMethod.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
473
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.os.Build; import android.util.AttributeSet; import android.widget.Checkable; import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; public class CheckableFrameLayout extends FrameLayout implements Checkable { private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked }; private boolean mChecked; public CheckableFrameLayout(@NonNull Context context) { super(context); } public CheckableFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public CheckableFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public CheckableFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public void toggle() { setChecked(!mChecked); } public boolean isChecked() { return mChecked; } public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } @Override protected int[] onCreateDrawableState(int extraSpace) { int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/CheckableFrameLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
348
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; public interface FlexibleSpaceContentView { int getScroll(); void scrollTo(int scroll); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FlexibleSpaceContentView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
37
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.view.MotionEvent; import android.view.ViewConfiguration; public abstract class OnSwipeGestureTouchListener extends OnGestureTouchListener { private final int mMinSwipeDelta; private final int mMinSwipeVelocity; private final int mMaxSwipeVelocity; public OnSwipeGestureTouchListener(Context context, boolean isLongPressEnabled) { super(context, isLongPressEnabled); ViewConfiguration configuration = ViewConfiguration.get(context); // We think a swipe flings a full page. //mMinSwipeDelta = configuration.getScaledTouchSlop(); mMinSwipeDelta = configuration.getScaledPagingTouchSlop(); mMinSwipeVelocity = configuration.getScaledMinimumFlingVelocity(); mMaxSwipeVelocity = configuration.getScaledMaximumFlingVelocity(); } // NOTE: see path_to_url @Override public final boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { boolean result = false; try { float deltaX = event2.getX() - event1.getX(); float deltaY = event2.getY() - event1.getY(); float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(velocityY); float absDeltaX = Math.abs(deltaX); float absDeltaY = Math.abs(deltaY); if (absDeltaX > absDeltaY) { if (absDeltaX > mMinSwipeDelta && absVelocityX > mMinSwipeVelocity && absVelocityX < mMaxSwipeVelocity) { if (deltaX < 0) { onSwipeLeft(); } else { onSwipeRight(); } } result = true; } else if (absDeltaY > mMinSwipeDelta && absVelocityY > mMinSwipeVelocity && absVelocityY < mMaxSwipeVelocity) { if (deltaY < 0) { onSwipeUp(); } else { onSwipeDown(); } } result = true; } catch (Exception e) { e.printStackTrace(); } return result; } public void onSwipeLeft() {} public void onSwipeRight() {} public void onSwipeUp() {} public void onSwipeDown() {} } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/OnSwipeGestureTouchListener.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
500
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.util.Property; /** * From {@code android.util.IntProperty}. * * An implementation of {@link Property} to be used specifically with fields of type * <code>int</code>. This type-specific subclass enables performance benefit by allowing * calls to a {@link #set(Object, Integer) set()} function that takes the primitive * <code>int</code> type and avoids autoboxing and other overhead associated with the * <code>Integer</code> class. * * @param <T> The class on which the Property is declared. */ public abstract class IntProperty<T> extends Property<T, Integer> { public IntProperty(String name) { super(Integer.class, name); } /** * A type-specific override of the {@link #set(Object, Integer)} that is faster when dealing * with fields of type <code>int</code>. */ public abstract void setValue(T object, int value); @Override final public void set(T object, Integer value) { setValue(object, value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/IntProperty.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
244
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.MotionEvent; import butterknife.BindInt; import butterknife.ButterKnife; import me.zhanghai.android.douya.util.ColorUtils; import me.zhanghai.android.douya.util.ViewUtils; public class TransparentDoubleClickToolbar extends DoubleClickToolbar { @BindInt(android.R.integer.config_shortAnimTime) int mAnimationDuration; private int mTitleTextColor; private boolean mTransparent; private int mAlpha = 255; private ValueAnimator mAnimator; public TransparentDoubleClickToolbar(Context context) { super(context); init(); } public TransparentDoubleClickToolbar(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } public TransparentDoubleClickToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { ButterKnife.bind(this); mTitleTextColor = ViewUtils.getColorFromAttrRes(android.R.attr.textColorPrimary, 0, getContext()); ViewCompat.setBackground(this, getBackground().mutate()); } public void setTransparent(boolean transparent) { if (mTransparent == transparent) { return; } mTransparent = transparent; if (mAnimator != null) { mAnimator.cancel(); mAnimator = null; } setToolbarAlpha(mTransparent ? 0 : 255); } public void animateToTransparent(boolean transparent) { if (mTransparent == transparent) { return; } mTransparent = transparent; if (mAnimator != null) { mAnimator.cancel(); mAnimator = null; } mAnimator = ValueAnimator.ofInt(mAlpha, mTransparent ? 0 : 255) .setDuration(mAnimationDuration); mAnimator.setInterpolator(new FastOutSlowInInterpolator()); mAnimator.addUpdateListener(animation -> { int alpha = (int) animation.getAnimatedValue(); setToolbarAlpha(alpha); }); mAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { mAnimator = null; } @Override public void onAnimationEnd(Animator animation) { mAnimator = null; } }); mAnimator.start(); } private void setToolbarAlpha(int alpha) { if (mAlpha == alpha) { return; } mAlpha = alpha; setTitleTextColor(ColorUtils.blendAlphaComponent(mTitleTextColor, mAlpha)); getBackground().setAlpha(mAlpha); } @Override public boolean onTouchEvent(MotionEvent event) { if (mAlpha == 0) { // We don't want to consume touch event if we are transparent. return false; } return super.onTouchEvent(event); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/TransparentDoubleClickToolbar.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
656
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import androidx.annotation.IntDef; import androidx.appcompat.widget.TintTypedArray; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; public class ContentStateLayout extends FrameLayout { @IntDef({STATE_LOADING, STATE_CONTENT, STATE_EMPTY, STATE_ERROR}) @Retention(RetentionPolicy.SOURCE) public @interface State {} public static final int STATE_LOADING = 0; public static final int STATE_CONTENT = 1; public static final int STATE_EMPTY = 2; public static final int STATE_ERROR = 3; private int mLoadingViewId; private int mContentViewId; private int mEmptyViewId; private int mErrorViewId; private View mLoadingView; private View mContentView; private View mEmptyView; private View mErrorView; private boolean mAnimationEnabled; public ContentStateLayout(Context context) { super(context); init(null, 0, 0); } public ContentStateLayout(Context context, AttributeSet attrs) { super(context, attrs); init(attrs, 0, 0); } public ContentStateLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr, 0); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public ContentStateLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(attrs, defStyleAttr, defStyleRes); } @SuppressLint("RestrictedApi") private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, R.styleable.ContentStateLayout, defStyleAttr, defStyleRes); mLoadingViewId = a.getResourceId(R.styleable.ContentStateLayout_loadingView, R.id.loading); mContentViewId = a.getResourceId(R.styleable.ContentStateLayout_contentView, R.id.content); mEmptyViewId = a.getResourceId(R.styleable.ContentStateLayout_emptyView, R.id.empty); mErrorViewId = a.getResourceId(R.styleable.ContentStateLayout_errorView, R.id.error); mAnimationEnabled = a.getBoolean(R.styleable.ContentStateLayout_animationEnabled, true); a.recycle(); } @Override protected void onFinishInflate() { super.onFinishInflate(); mLoadingView = findChildById(mLoadingViewId); mContentView = findChildById(mContentViewId); mEmptyView = findChildById(mEmptyViewId); mErrorView = findChildById(mErrorViewId); if (mLoadingView == null) { mLoadingView = LayoutInflater.from(getContext()) .inflate(R.layout.content_state_layout_default_loading_view, this, false); addView(mLoadingView); } if (mEmptyView == null) { mEmptyView = LayoutInflater.from(getContext()) .inflate(R.layout.content_state_layout_default_empty_view, this, false); addView(mEmptyView); } if (mErrorView == null) { mErrorView = LayoutInflater.from(getContext()) .inflate(R.layout.content_state_layout_default_error_view, this, false); addView(mErrorView); } setViewVisible(mLoadingView, false, false); setViewVisible(mContentView, false, false); setViewVisible(mEmptyView, false, false); setViewVisible(mErrorView, false, false); } private View findChildById(int id) { return findChildById(this, id); } private View findChildById(ViewGroup viewGroup, int id) { for (int i = 0, count = viewGroup.getChildCount(); i < count; ++i) { View child = viewGroup.getChildAt(i); int childId = child.getId(); if (childId == id) { return child; } else if (child instanceof ViewGroup && childId != mLoadingViewId && childId != mContentViewId && childId != mEmptyViewId && childId != mErrorViewId) { child = findChildById((ViewGroup) child, id); if (child != null) { return child; } } } return null; } public View getLoadingView() { return mLoadingView; } public View getContentView() { return mContentView; } public View getEmptyView() { return mEmptyView; } public View getErrorView() { return mErrorView; } public boolean isAnimationEnabled() { return mAnimationEnabled; } public void setAnimationEnabled(boolean enabled) { mAnimationEnabled = enabled; } public void setState(@State int state) { setViewVisible(mLoadingView, state == STATE_LOADING); setViewVisible(mContentView, state == STATE_CONTENT); setViewVisible(mEmptyView, state == STATE_EMPTY); setViewVisible(mErrorView, state == STATE_ERROR); } public void setLoading() { setState(STATE_LOADING); } public void setLoaded(boolean hasContent) { setState(hasContent ? STATE_CONTENT : STATE_EMPTY); } public void setError() { setState(STATE_ERROR); } private void setViewVisible(View view, boolean visible, boolean animate) { if (view == null) { if (visible) { // TODO: Be more detailed. throw new IllegalStateException("Missing view when setting to visible"); } else { return; } } if (animate) { ViewUtils.fadeToVisibility(view, visible); } else { ViewUtils.setVisibleOrGone(view, visible); } } private void setViewVisible(View view, boolean visible) { setViewVisible(view, visible, mAnimationEnabled); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ContentStateLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,328
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.appcompat.app.AppCompatDialogFragment; import de.psdev.licensesdialog.NoticesXmlParser; import de.psdev.licensesdialog.model.Notice; import de.psdev.licensesdialog.model.Notices; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; private static final String STATE_NOTICES = KEY_PREFIX + "NOTICES"; @NonNull private Notices mNotices; @NonNull //noinspection deprecation } public static void show(@NonNull Fragment fragment) { .show(fragment.getChildFragmentManager(), null); } /** * @deprecated Use {@link #newInstance()} instead. */ @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mNotices = savedInstanceState.getParcelable(STATE_NOTICES); } else { try { mNotices = NoticesXmlParser.parse(requireContext().getResources().openRawResource( R.raw.licenses)); } catch (Exception e) { throw new IllegalStateException(e); } } } @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(STATE_NOTICES, mNotices); } @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { Notices notices = new Notices(); for (Notice notice : mNotices.getNotices()) { notices.addNotice(notice); } Context context = requireContext(); int htmlStyleRes = ViewUtils.isLightTheme(context) ? R.string.settings_open_source_licenses_html_style_light : R.string.settings_open_source_licenses_html_style_dark; .setThemeResourceId(getTheme()) .setTitle(R.string.settings_open_source_licenses_title) .setNotices(notices) .setNoticesCssStyle(htmlStyleRes) .setCloseText(R.string.close) .build() .create(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/LicensesDialogFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
481
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import androidx.appcompat.content.res.AppCompatResources; import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.LinearLayout; /** * Draws divider before items except the first. * * @see androidx.recyclerview.widget.DividerItemDecoration */ public class DividerItemDecoration extends RecyclerView.ItemDecoration { public static final int HORIZONTAL = LinearLayout.HORIZONTAL; public static final int VERTICAL = LinearLayout.VERTICAL; /** * Current orientation. Either {@link #HORIZONTAL} or {@link #VERTICAL}. */ private int mOrientation; private Drawable mDivider; private final Rect mBounds = new Rect(); public DividerItemDecoration(int orientation, Drawable divider) { setOrientation(orientation); setDivider(divider); } public DividerItemDecoration(int orientation, int dividerRes, Context context) { this(orientation, AppCompatResources.getDrawable(context, dividerRes)); } public void setOrientation(int orientation) { if (orientation != HORIZONTAL && orientation != VERTICAL) { throw new IllegalArgumentException( "Invalid orientation. It should be either HORIZONTAL or VERTICAL"); } mOrientation = orientation; } public void setDivider(Drawable drawable) { mDivider = drawable; } @Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { if (parent.getLayoutManager() == null || mDivider == null) { return; } if (mOrientation == VERTICAL) { drawVertical(canvas, parent); } else { drawHorizontal(canvas, parent); } } private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); int left; int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } for (int i = 0, count = parent.getChildCount(); i < count; ++i) { View child = parent.getChildAt(i); if (parent.getChildAdapterPosition(child) == 0) { continue; } parent.getDecoratedBoundsWithMargins(child, mBounds); int top = mBounds.top + Math.round(child.getTranslationY()); int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } canvas.restore(); } private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); int top; int bottom; if (parent.getClipToPadding()) { top = parent.getPaddingTop(); bottom = parent.getHeight() - parent.getPaddingBottom(); canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom); } else { top = 0; bottom = parent.getHeight(); } for (int i = 0, count = parent.getChildCount(); i < count; ++i) { View child = parent.getChildAt(i); if (parent.getChildAdapterPosition(child) == 0) { continue; } parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds); int left = mBounds.left + Math.round(child.getTranslationX()); int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } canvas.restore(); } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (mDivider == null || parent.getChildAdapterPosition(view) == 0) { outRect.set(0, 0, 0, 0); return; } if (mOrientation == VERTICAL) { outRect.set(0, mDivider.getIntrinsicHeight(), 0, 0); } else { outRect.set(mDivider.getIntrinsicWidth(), 0, 0, 0); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/DividerItemDecoration.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
915
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.graphics.drawable.shapes.Shape; import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; public class CircleRectShape extends Shape { private RectF mTempRectForCanvasAddRoundRect; private Path mPath = new Path(); public CircleRectShape() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { mTempRectForCanvasAddRoundRect = new RectF(); } } @Override protected void onResize(float width, float height) { mPath.rewind(); float radius = Math.min(width, height) / 2; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mPath.addRoundRect(0, 0, width, height, radius, radius, Path.Direction.CW); } else { mTempRectForCanvasAddRoundRect.set(0, 0, width, height); mPath.addRoundRect(mTempRectForCanvasAddRoundRect, radius, radius, Path.Direction.CW); } } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(@NonNull Outline outline) { outline.setConvexPath(mPath); } @Override public void draw(Canvas canvas, Paint paint) { canvas.drawPath(mPath, paint); } @Override public CircleRectShape clone() throws CloneNotSupportedException { CircleRectShape circleRectShape = (CircleRectShape) super.clone(); circleRectShape.mPath = new Path(mPath); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { circleRectShape.mTempRectForCanvasAddRoundRect = new RectF(); } return circleRectShape; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/CircleRectShape.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
423
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Outline; import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.graphics.drawable.DrawableCompat; /** * Drawable container with only one child element. */ public abstract class DrawableWrapperCompat extends Drawable implements Drawable.Callback { private DrawableWrapperState mState; private Drawable mDrawable; private boolean mMutated; protected DrawableWrapperCompat(DrawableWrapperState state, Resources res) { mState = state; updateLocalState(res); } /** * Creates a new wrapper around the specified drawable. * * @param dr the drawable to wrap */ public DrawableWrapperCompat(@Nullable Drawable dr) { mState = mutateConstantState(); setDrawable(dr); } /** * Initializes local dynamic properties from state. This should be called * after significant state changes, e.g. from the One True Constructor and * after inflating or applying a theme. */ private void updateLocalState(Resources res) { if (mState != null && mState.mDrawableState != null) { final Drawable dr = mState.mDrawableState.newDrawable(res); setDrawable(dr); } } /** * Sets the wrapped drawable. * * @param dr the wrapped drawable */ public void setDrawable(@Nullable Drawable dr) { if (mDrawable != null) { mDrawable.setCallback(null); } mDrawable = dr; if (dr != null) { dr.setCallback(this); // Only call setters for data that's stored in the base Drawable. dr.setVisible(isVisible(), true); dr.setState(getState()); dr.setLevel(getLevel()); dr.setBounds(getBounds()); DrawableCompat.setLayoutDirection(dr, DrawableCompat.getLayoutDirection(this)); if (mState != null) { mState.mDrawableState = dr.getConstantState(); } } invalidateSelf(); } /** * @return the wrapped drawable */ @Nullable public Drawable getDrawable() { return mDrawable; } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void applyTheme(@NonNull Resources.Theme t) { super.applyTheme(t); if (mDrawable != null && mDrawable.canApplyTheme()) { mDrawable.applyTheme(t); } } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public boolean canApplyTheme() { return (mState != null && mState.canApplyTheme()) || super.canApplyTheme(); } @Override public void invalidateDrawable(@NonNull Drawable who) { final Callback callback = getCallback(); if (callback != null) { callback.invalidateDrawable(this); } } @Override public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) { final Callback callback = getCallback(); if (callback != null) { callback.scheduleDrawable(this, what, when); } } @Override public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) { final Callback callback = getCallback(); if (callback != null) { callback.unscheduleDrawable(this, what); } } @Override public void draw(@NonNull Canvas canvas) { if (mDrawable != null) { mDrawable.draw(canvas); } } @Override public int getChangingConfigurations() { return super.getChangingConfigurations() | (mState != null ? mState.getChangingConfigurations() : 0) | mDrawable.getChangingConfigurations(); } @Override public boolean getPadding(@NonNull Rect padding) { return mDrawable != null && mDrawable.getPadding(padding); } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void setHotspot(float x, float y) { if (mDrawable != null) { mDrawable.setHotspot(x, y); } } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void setHotspotBounds(int left, int top, int right, int bottom) { if (mDrawable != null) { mDrawable.setHotspotBounds(left, top, right, bottom); } } @Override @RequiresApi(Build.VERSION_CODES.M) public void getHotspotBounds(@NonNull Rect outRect) { if (mDrawable != null) { mDrawable.getHotspotBounds(outRect); } else { outRect.set(getBounds()); } } @Override public boolean setVisible(boolean visible, boolean restart) { final boolean superChanged = super.setVisible(visible, restart); final boolean changed = mDrawable != null && mDrawable.setVisible(visible, restart); return superChanged || changed; } @Override public void setAlpha(int alpha) { if (mDrawable != null) { mDrawable.setAlpha(alpha); } } @Override @RequiresApi(Build.VERSION_CODES.KITKAT) public int getAlpha() { return mDrawable != null ? mDrawable.getAlpha() : 255; } @Override public void setColorFilter(@Nullable ColorFilter colorFilter) { if (mDrawable != null) { mDrawable.setColorFilter(colorFilter); } } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void setTintList(@Nullable ColorStateList tint) { if (mDrawable != null) { mDrawable.setTintList(tint); } } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void setTintMode(@Nullable PorterDuff.Mode tintMode) { if (mDrawable != null) { mDrawable.setTintMode(tintMode); } } @Override @RequiresApi(Build.VERSION_CODES.M) public boolean onLayoutDirectionChanged(int layoutDirection) { return mDrawable != null && mDrawable.setLayoutDirection(layoutDirection); } @Override public int getOpacity() { return mDrawable != null ? mDrawable.getOpacity() : PixelFormat.TRANSPARENT; } @Override public boolean isStateful() { return mDrawable != null && mDrawable.isStateful(); } @Override protected boolean onStateChange(int[] state) { if (mDrawable != null && mDrawable.isStateful()) { final boolean changed = mDrawable.setState(state); if (changed) { onBoundsChange(getBounds()); } return changed; } return false; } @Override protected boolean onLevelChange(int level) { return mDrawable != null && mDrawable.setLevel(level); } @Override protected void onBoundsChange(@NonNull Rect bounds) { if (mDrawable != null) { mDrawable.setBounds(bounds); } } @Override public int getIntrinsicWidth() { return mDrawable != null ? mDrawable.getIntrinsicWidth() : -1; } @Override public int getIntrinsicHeight() { return mDrawable != null ? mDrawable.getIntrinsicHeight() : -1; } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public void getOutline(@NonNull Outline outline) { if (mDrawable != null) { mDrawable.getOutline(outline); } else { super.getOutline(outline); } } @Override @Nullable public ConstantState getConstantState() { if (mState != null && mState.canConstantState()) { mState.mChangingConfigurations = getChangingConfigurations(); return mState; } return null; } @Override @NonNull public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = mutateConstantState(); if (mDrawable != null) { mDrawable.mutate(); } if (mState != null) { mState.mDrawableState = mDrawable != null ? mDrawable.getConstantState() : null; } mMutated = true; } return this; } /** * Mutates the constant state and returns the new state. Responsible for * updating any local copy. * <p> * This method should never call the super implementation; it should always * mutate and return its own constant state. * * @return the new state */ protected DrawableWrapperState mutateConstantState() { return mState; } protected abstract static class DrawableWrapperState extends ConstantState { private int[] mThemeAttrs; int mChangingConfigurations; ConstantState mDrawableState; DrawableWrapperState(@Nullable DrawableWrapperState orig, @Nullable Resources res) { if (orig != null) { mThemeAttrs = orig.mThemeAttrs; mChangingConfigurations = orig.mChangingConfigurations; mDrawableState = orig.mDrawableState; } } @Override @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public boolean canApplyTheme() { return mThemeAttrs != null || (mDrawableState != null && mDrawableState.canApplyTheme()) || super.canApplyTheme(); } @NonNull @Override public Drawable newDrawable() { return newDrawable(null); } @NonNull @Override public abstract Drawable newDrawable(@Nullable Resources res); @Override public int getChangingConfigurations() { return mChangingConfigurations | (mDrawableState != null ? mDrawableState.getChangingConfigurations() : 0); } public boolean canConstantState() { return mDrawableState != null; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/DrawableWrapperCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
2,185
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import androidx.appcompat.widget.AppCompatCheckBox; import androidx.appcompat.widget.TintTypedArray; import android.text.TextUtils; import android.util.AttributeSet; public class PreferenceCheckBox extends AppCompatCheckBox { private static final int[] STYLEABLE = { android.R.attr.key, android.R.attr.defaultValue, android.R.attr.persistent }; private static final int STYLEABLE_ANDROID_KEY = 0; private static final int STYLEABLE_ANDROID_DEFAULT_VALUE = 1; private static final int STYLEABLE_ANDROID_PERSISTENT = 2; private String mKey; private boolean mHasDefaultValue; private boolean mDefaultValue; private boolean mPersistent; private SharedPreferences mSharedPreferences; private boolean mCheckedSet; public PreferenceCheckBox(Context context) { super(context); init(null, 0); } public PreferenceCheckBox(Context context, AttributeSet attrs) { super(context, attrs); init(attrs, 0); } public PreferenceCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr); } @SuppressLint("RestrictedApi") private void init(AttributeSet attrs, int defStyleAttr) { Context context = getContext(); TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, STYLEABLE, defStyleAttr, 0); mKey = a.getString(STYLEABLE_ANDROID_KEY); mHasDefaultValue = a.hasValue(STYLEABLE_ANDROID_DEFAULT_VALUE); mDefaultValue = a.getBoolean(STYLEABLE_ANDROID_DEFAULT_VALUE, false); mPersistent = a.getBoolean(STYLEABLE_ANDROID_PERSISTENT, true); a.recycle(); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); dispatchSetInitialValue(); } public boolean hasKey() { return !TextUtils.isEmpty(mKey); } public String getKey() { return mKey; } public void setKey(String key) { mKey = key; } public boolean hasDefaultValue() { return mHasDefaultValue; } public boolean getDefaultValue() { return mDefaultValue; } public void setDefaultValue(boolean defaultValue) { mDefaultValue = defaultValue; mHasDefaultValue = true; } public boolean isPersistent() { return mPersistent; } public void setPersistent(boolean persistent) { mPersistent = persistent; } public SharedPreferences getSharedPreferences() { return mSharedPreferences; } protected boolean shouldPersist() { return getSharedPreferences() != null && isPersistent() && hasKey(); } private void dispatchSetInitialValue() { boolean shouldPersist = shouldPersist(); if (!shouldPersist || !getSharedPreferences().contains(mKey)) { if (mHasDefaultValue) { onSetInitialValue(false, mDefaultValue); } } else { onSetInitialValue(true, false); } } protected void onSetInitialValue(boolean restorePersistedValue, boolean defaultValue) { setChecked(restorePersistedValue ? getPersistedBoolean(isChecked()) : defaultValue); } @Override public void setChecked(boolean checked) { // Always persist/notify the first time; don't assume the field's default of false. boolean changed = isChecked() != checked; if (changed || !mCheckedSet) { super.setChecked(checked); mCheckedSet = true; persistBoolean(checked); } } protected boolean getPersistedBoolean(boolean defaultReturnValue) { if (!shouldPersist()) { return defaultReturnValue; } return getSharedPreferences().getBoolean(mKey, defaultReturnValue); } protected boolean persistBoolean(boolean value) { if (!shouldPersist()) { return false; } if (value == getPersistedBoolean(!value)) { // It's already there, so the same as persisting return true; } SharedPreferences.Editor editor = getSharedPreferences().edit(); editor.putBoolean(mKey, value); tryCommit(editor); return true; } private void tryCommit(@NonNull SharedPreferences.Editor editor) { editor.apply(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/PreferenceCheckBox.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
897
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; public interface AppBarHost { void showAppBar(); void hideAppBar(); void setToolBarOnDoubleClickListener(DoubleClickToolbar.OnDoubleClickListener listener); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/AppBarHost.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
50
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import me.zhanghai.android.materialprogressbar.IndeterminateCircularProgressDrawable; public class WhiteIndeterminateProgressIconDrawable extends Drawable implements Animatable { private static final int ICON_SIZE_DP = 24; private static final int ICON_PADDING_DP = 2; private int mIntrinsicSize; private int mIntrinsicPadding; private ProgressDrawable mProgressDrawable; public WhiteIndeterminateProgressIconDrawable(Context context) { mProgressDrawable = new ProgressDrawable(context); float density = context.getResources().getDisplayMetrics().density; mIntrinsicSize = Math.round(ICON_SIZE_DP * density); mIntrinsicPadding = Math.round(ICON_PADDING_DP * density); setTint(Color.WHITE); } @Override @SuppressLint("NewApi") public int getAlpha() { return mProgressDrawable.getAlpha(); } /** * {@inheritDoc} */ @Override public void setAlpha(int alpha) { mProgressDrawable.setAlpha(alpha); } /** * {@inheritDoc} */ @Override @SuppressLint("NewApi") public ColorFilter getColorFilter() { return mProgressDrawable.getColorFilter(); } /** * {@inheritDoc} */ @Override public void setColorFilter(@Nullable ColorFilter colorFilter) { mProgressDrawable.setColorFilter(colorFilter); } /** * {@inheritDoc} */ @Override @SuppressLint("NewApi") public void setTint(@ColorInt int tintColor) { mProgressDrawable.setTint(tintColor); } /** * {@inheritDoc} */ @Override @SuppressLint("NewApi") public void setTintList(@Nullable ColorStateList tint) { mProgressDrawable.setTintList(tint); } /** * {@inheritDoc} */ @Override @SuppressLint("NewApi") public void setTintMode(@NonNull PorterDuff.Mode tintMode) { mProgressDrawable.setTintMode(tintMode); } /** * {@inheritDoc} */ @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public void start() { mProgressDrawable.start(); } @Override public void stop() { mProgressDrawable.stop(); } @Override public boolean isRunning() { return mProgressDrawable.isRunning(); } @Override public int getIntrinsicWidth() { return mIntrinsicSize; } @Override public int getIntrinsicHeight() { return mIntrinsicSize; } @Override public void setBounds(int left, int top, int right, int bottom) { super.setBounds(left, top, right, bottom); int paddingHorizontal = (right - left) * mIntrinsicPadding / mIntrinsicSize; int paddingVertical = (bottom - top) * mIntrinsicPadding / mIntrinsicSize; mProgressDrawable.setBounds(left + paddingHorizontal, top + paddingVertical, right - paddingHorizontal, bottom - paddingVertical); } @Override public void draw(Canvas canvas) { mProgressDrawable.draw(canvas); } public class ProgressDrawable extends IndeterminateCircularProgressDrawable { public ProgressDrawable(Context context) { super(context); } @Override public void invalidateSelf() { super.invalidateSelf(); WhiteIndeterminateProgressIconDrawable.this.invalidateSelf(); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/WhiteIndeterminateProgressIconDrawable.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
838
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.os.Build; import android.util.AttributeSet; import android.view.View; import android.view.WindowInsets; import androidx.annotation.RequiresApi; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ViewUtils; @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public class StatusBarBackgroundView extends View { @NonNull private Drawable mStatusBarBackground; @Nullable private WindowInsets mInsets; public StatusBarBackgroundView(@NonNull Context context) { super(context); init(); } public StatusBarBackgroundView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } public StatusBarBackgroundView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public StatusBarBackgroundView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(); } private void init() { int darkPrimaryColor = ViewUtils.getColorFromAttrRes(R.attr.colorPrimaryDark, 0, getContext()); mStatusBarBackground = new ColorDrawable(darkPrimaryColor); @SuppressLint("PrivateResource") int appBarElevation = getResources().getDimensionPixelSize(R.dimen.design_appbar_elevation); setElevation(appBarElevation); setFitsSystemWindows(true); setWillNotDraw(true); } @NonNull @Override public WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { mInsets = insets; setWillNotDraw(mInsets.getSystemWindowInsetTop() == 0); return insets; } @Override @SuppressLint("MissingSuperCall") public void draw(@NonNull Canvas canvas) { if (mInsets == null) { return; } int left = mInsets.getSystemWindowInsetLeft(); int right = getWidth() - left - mInsets.getSystemWindowInsetRight(); mStatusBarBackground.setBounds(left, 0, right, mInsets.getSystemWindowInsetTop()); mStatusBarBackground.draw(canvas); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/StatusBarBackgroundView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
513
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; public interface SizedImageItem extends ImageItem { int getLargeWidth(); int getLargeHeight(); int getMediumWidth(); int getMediumHeight(); int getSmallWidth(); int getSmallHeight(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/SizedImageItem.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
65
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.preference.DialogPreference; import me.zhanghai.android.douya.util.FragmentUtils; public class RingtonePreferenceActivityFragmentCompat extends Fragment { // @see PreferenceDialogFragmentCompat#ARG_KEY private static final String ARGUMENT_KEY = "key"; private static final int REQUEST_CODE_PICKER = 1; private RingtonePreference mPreference; private boolean mShouldStartPicker; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle arguments = getArguments(); String preferenceKey = arguments.getString(ARGUMENT_KEY); Fragment fragment = getTargetFragment(); if (!(fragment instanceof DialogPreference.TargetFragment)) { throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface"); } DialogPreference.TargetFragment targetFragment = (DialogPreference.TargetFragment) fragment; if (savedInstanceState == null) { mPreference = (RingtonePreference) targetFragment.findPreference(preferenceKey); } } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState == null) { mShouldStartPicker = true; } } @Override public void onStart() { super.onStart(); if (mShouldStartPicker) { startActivityForResult(mPreference.makeRingtonePickerIntent(), REQUEST_CODE_PICKER); mShouldStartPicker = false; } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_PICKER) { if (data != null) { Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (mPreference.callChangeListener(uri)) { mPreference.setRingtoneUri(uri); } } FragmentUtils.remove(this); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/RingtonePreferenceActivityFragmentCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
448
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import com.google.android.material.navigation.NavigationView; import android.util.AttributeSet; /** * A {@link NavigationView} that draws no scrim and dispatches window insets correctly. * <p> * {@code android:fitsSystemWindows="true"} will be ignored. * </p> */ public class FullscreenNavigationView extends NavigationView { public FullscreenNavigationView(Context context) { super(context); init(); } public FullscreenNavigationView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public FullscreenNavigationView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) private void init() { // Required to revert the value of fitsSystemWindows set in super constructor. setFitsSystemWindows(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { setOnApplyWindowInsetsListener((view, insets) -> { if (getHeaderCount() == 0) { return FullscreenNavigationView.this.onApplyWindowInsets(insets); } return getHeaderView(0).onApplyWindowInsets(insets); }); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FullscreenNavigationView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
293
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import androidx.core.view.GravityCompat; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; import android.widget.FrameLayout; /** * @see DispatchInsetsHelper */ public class DispatchInsetsFrameLayout extends FrameLayout { private DispatchInsetsHelper mInsetsHelper = new DispatchInsetsHelper( new DispatchInsetsHelper.Delegate() { @Override public int getGravityFromLayoutParams(ViewGroup.LayoutParams layoutParams) { int gravity = ((LayoutParams) layoutParams).gravity; // See FrameLayout.layoutChildren(). return gravity != -1 ? gravity : Gravity.TOP | GravityCompat.START; } @Override public ViewGroup getOwner() { return DispatchInsetsFrameLayout.this; } @Override public void superAddView(View child, int index, ViewGroup.LayoutParams params) { DispatchInsetsFrameLayout.super.addView(child, index, params); } @Override public boolean superAddViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) { return DispatchInsetsFrameLayout.super.addViewInLayout(child, index, params, preventRequestLayout); } }); public DispatchInsetsFrameLayout(Context context) { super(context); } public DispatchInsetsFrameLayout(Context context, AttributeSet attrs) { super(context, attrs); } public DispatchInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public DispatchInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { return mInsetsHelper.dispatchApplyWindowInsets(insets); } @Override public void addView(View child, int index, ViewGroup.LayoutParams params) { mInsetsHelper.addView(child, index, params); } @Override protected boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) { return mInsetsHelper.addViewInLayout(child, index, params, preventRequestLayout); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/DispatchInsetsFrameLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
504
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.Build; import android.view.animation.DecelerateInterpolator; import android.widget.ProgressBar; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.AppUtils; import me.zhanghai.android.douya.util.MathUtils; import me.zhanghai.android.materialedittext.internal.FloatProperty; public class ProgressBarCompat { private static final int MAX_LEVEL = 10000; private static final int PROGRESS_ANIM_DURATION = 80; private static final DecelerateInterpolator PROGRESS_ANIM_INTERPOLATOR = new DecelerateInterpolator(); private static final FloatProperty<ProgressBar> VISUAL_PROGRESS = new FloatProperty<ProgressBar>("visual_progress") { @Override public void setValue(ProgressBar object, float value) { ProgressBarCompat.setVisualProgressCompat(object, android.R.id.progress, value); } @Override public Float get(ProgressBar object) { return getVisualProgressCompat(object, android.R.id.progress); } }; private ProgressBarCompat() {} public static void setProgress(final ProgressBar progressBar, int progress, boolean animate) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { progressBar.setProgress(progress, animate); return; } if (!animate) { progressBar.setProgress(progress); return; } if (progressBar.isIndeterminate()) { return; } progress = MathUtils.constrain(progress, 0, progressBar.getMax()); if (progress == progressBar.getProgress()) { // No change from current. return; } final int finalProgress = progress; AppUtils.runOnUiThread(new Runnable() { @Override public void run() { float savedVisualProgress = getVisualProgressCompat(progressBar, android.R.id.progress); progressBar.setProgress(finalProgress); setVisualProgressCompat(progressBar, android.R.id.progress, savedVisualProgress); int max = progressBar.getMax(); float scale = max > 0 ? (float) finalProgress / max : 0; ObjectAnimator animator = ObjectAnimator.ofFloat(progressBar, VISUAL_PROGRESS, scale); animator.setDuration(PROGRESS_ANIM_DURATION); animator.setInterpolator(PROGRESS_ANIM_INTERPOLATOR); //animator.setAutoCancel(true); ObjectAnimator oldAnimator = (ObjectAnimator) progressBar.getTag( R.id.progress_bar_compat_object_animator_tag); if (oldAnimator != null) { oldAnimator.cancel(); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { progressBar.setTag(R.id.progress_bar_compat_object_animator_tag, null); } }); progressBar.setTag(R.id.progress_bar_compat_object_animator_tag, animator); animator.start(); } }); } private static float getVisualProgressCompat(ProgressBar progressBar, int id) { Drawable drawable = getVisualProgressDrawable(progressBar, id); if (drawable != null) { return (float) drawable.getLevel() / MAX_LEVEL; } else if (id == android.R.id.secondaryProgress) { return (float) progressBar.getSecondaryProgress() / progressBar.getMax(); } else { return (float) progressBar.getProgress() / progressBar.getMax(); } } /* * @see ProgressBar#setVisualProgress(int, float) */ private static void setVisualProgressCompat(ProgressBar progressBar, int id, float progress) { Drawable drawable = getVisualProgressDrawable(progressBar, id); if (drawable != null) { int level = (int) (progress * MAX_LEVEL); drawable.setLevel(level); } else { progressBar.invalidate(); } } private static Drawable getVisualProgressDrawable(ProgressBar progressBar, int id) { Drawable currentDrawable = progressBar.isIndeterminate() ? progressBar.getIndeterminateDrawable() : progressBar.getProgressDrawable(); Drawable drawable = currentDrawable; if (drawable instanceof LayerDrawable) { drawable = ((LayerDrawable) drawable).findDrawableByLayerId(id); if (drawable == null) { // If we can't find the requested layer, fall back to setting // the level of the entire drawable. This will break if // progress is set on multiple elements, but the theme-default // drawable will always have all layer IDs present. drawable = currentDrawable; } } return drawable; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ProgressBarCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
973
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import me.zhanghai.android.douya.R; public class NotYetImplementedFragment extends Fragment { public static NotYetImplementedFragment newInstance() { //noinspection deprecation return new NotYetImplementedFragment(); } /** * @deprecated Use {@link #newInstance()} instead. */ public NotYetImplementedFragment() {} @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.not_yet_implemented_fragment, container, false); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/NotYetImplementedFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
167
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.material.appbar.AppBarLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.ViewCompat; import android.util.AttributeSet; import android.view.View; public class FixNestedScrollAppBarLayout extends AppBarLayout implements CoordinatorLayout.AttachedBehavior { public FixNestedScrollAppBarLayout(@NonNull Context context) { super(context); } public FixNestedScrollAppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @NonNull @Override public CoordinatorLayout.Behavior getBehavior() { return new Behavior(); } // path_to_url // Workaround for path_to_url private static class Behavior extends AppBarLayout.Behavior { public Behavior() {} public Behavior(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull AppBarLayout child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type); stopNestedScrollIfNeeded(dyUnconsumed, child, target, type); } @Override public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull AppBarLayout child, @NonNull View target, int dx, int dy, int[] consumed, int type) { super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); stopNestedScrollIfNeeded(dy, child, target, type); } private void stopNestedScrollIfNeeded(int dy, @NonNull AppBarLayout child, @NonNull View target, int type) { if (type == ViewCompat.TYPE_NON_TOUCH) { int currOffset = getTopAndBottomOffset(); if ((dy < 0 && currOffset == 0) || (dy > 0 && currOffset == -child.getTotalScrollRange())) { ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH); } } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FixNestedScrollAppBarLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
512
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.app.Dialog; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; import android.widget.TextView; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.ClipboardUtils; import me.zhanghai.android.douya.util.FragmentUtils; public class CopyTextDialogFragment extends AppCompatDialogFragment { private static final String KEY_PREFIX = CopyTextDialogFragment.class.getName() + '.'; private static final String EXTRA_TEXT = KEY_PREFIX + "text"; private String mText; /** * @deprecated Use {@link #newInstance(String)} instead. */ public CopyTextDialogFragment() {} public static CopyTextDialogFragment newInstance(String text) { //noinspection deprecation CopyTextDialogFragment fragment = new CopyTextDialogFragment(); FragmentUtils.getArgumentsBuilder(fragment) .putString(EXTRA_TEXT, text); return fragment; } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mText = getArguments().getString(EXTRA_TEXT); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity(), getTheme()) .setMessage(mText) .setPositiveButton(R.string.copy_to_clipboard, (dialog, which) -> ClipboardUtils.copyText(null, mText, getActivity())) .create(); } @Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog != null) { TextView messageText = (TextView) dialog.findViewById(android.R.id.message); if (messageText != null) { messageText.setTextIsSelectable(true); } } } public static void show(String text, Fragment fragment) { CopyTextDialogFragment.newInstance(text) .show(fragment.getChildFragmentManager(), null); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/CopyTextDialogFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
433
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import androidx.core.view.ViewCompat; import androidx.appcompat.widget.TintTypedArray; import android.util.AttributeSet; import android.view.WindowInsets; import android.widget.FrameLayout; import me.zhanghai.android.douya.R; /** * A {@link FrameLayout} that draws background for system window insets. */ public class InsetBackgroundFrameLayout extends FrameLayout { private Drawable mInsetBackground; private Rect mInsets; public InsetBackgroundFrameLayout(Context context) { super(context); init(null, 0, 0); } public InsetBackgroundFrameLayout(Context context, AttributeSet attrs) { super(context, attrs); init(attrs, 0, 0); } public InsetBackgroundFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr, 0); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public InsetBackgroundFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(attrs, defStyleAttr, defStyleRes); } @SuppressLint("RestrictedApi") private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, R.styleable.InsetBackgroundFrameLayout, defStyleAttr, defStyleRes); mInsetBackground = a.getDrawable(R.styleable.InsetBackgroundFrameLayout_insetBackground); a.recycle(); // Will not draw until insets are set. setWillNotDraw(true); } @Override @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) public WindowInsets onApplyWindowInsets(WindowInsets insets) { if (mInsets == null) { mInsets = new Rect(); } mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); if (willNotDraw()) { setWillNotDraw(!mInsets.isEmpty() && mInsetBackground != null); } ViewCompat.postInvalidateOnAnimation(this); return super.onApplyWindowInsets(insets); } @Override protected void onDraw(Canvas canvas) { int count = canvas.save(); canvas.translate(getScrollX(), getScrollY()); int width = getWidth(); int height = getHeight(); if (mInsets != null && mInsetBackground != null) { // Top mInsetBackground.setBounds(0, 0, width, mInsets.top); mInsetBackground.draw(canvas); // Bottom mInsetBackground.setBounds(0, height - mInsets.bottom, width, height); mInsetBackground.draw(canvas); // Left mInsetBackground.setBounds(0, mInsets.top, mInsets.left, height - mInsets.bottom); mInsetBackground.draw(canvas); // Right mInsetBackground.setBounds(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); mInsetBackground.draw(canvas); } canvas.restoreToCount(count); super.onDraw(canvas); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mInsetBackground != null) { mInsetBackground.setCallback(this); } } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mInsetBackground != null) { mInsetBackground.setCallback(null); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/InsetBackgroundFrameLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
798
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.appcompat.widget.AppCompatTextView; import android.util.AttributeSet; import org.threeten.bp.ZonedDateTime; import org.threeten.bp.format.DateTimeParseException; import me.zhanghai.android.douya.util.LogUtils; import me.zhanghai.android.douya.util.TimeUtils; public class TimeTextView extends AppCompatTextView { private static final int UPDATE_TIME_TEXT_INTERVAL_MILLI = 30 * 1000; private final Runnable mUpdateTimeTextRunnable = new Runnable() { @Override public void run() { updateTimeText(); } }; private ZonedDateTime mTime; public TimeTextView(Context context) { super(context); } public TimeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public TimeTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public ZonedDateTime getTime() { return mTime; } public void setTime(ZonedDateTime time) { mTime = time; updateTimeText(); } /** * Should behave the same as {@link TimeUtils#formatDoubanDateTime(String, Context)}. */ public void setDoubanTime(String doubanTime) { try { setTime(TimeUtils.parseDoubanDateTime(doubanTime)); } catch (DateTimeParseException e) { LogUtils.e("Unable to parse date time: " + doubanTime); e.printStackTrace(); setText(doubanTime); } } protected void updateTimeText() { removeCallbacks(mUpdateTimeTextRunnable); if (mTime != null) { setTimeText(formatTime(mTime)); postDelayed(mUpdateTimeTextRunnable, UPDATE_TIME_TEXT_INTERVAL_MILLI); } } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mTime != null) { updateTimeText(); } } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); removeCallbacks(mUpdateTimeTextRunnable); } protected String formatTime(ZonedDateTime time) { return TimeUtils.formatDateTime(time, getContext()); } protected void setTimeText(String timeText) { setText(timeText); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/TimeTextView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
500
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.view.MotionEvent; public abstract class KonamiCodeDetector extends OnSwipeGestureTouchListener { private enum Action { LEFT, RIGHT, UP, DOWN, A, B } private enum State { INITIAL(Action.UP), UP(Action.UP), UP_UP(Action.DOWN), UP_UP_DOWN(Action.DOWN), UP_UP_DOWN_DOWN(Action.LEFT), UP_UP_DOWN_DOWN_LEFT(Action.RIGHT), UP_UP_DOWN_DOWN_LEFT_RIGHT(Action.LEFT), UP_UP_DOWN_DOWN_LEFT_RIGHT_LEFT(Action.RIGHT), UP_UP_DOWN_DOWN_LEFT_RIGHT_LEFT_RIGHT(Action.B), UP_UP_DOWN_DOWN_LEFT_RIGHT_LEFT_RIGHT_B(Action.A), FINAL(null); private Action mNextAction; State(Action nextAction) { mNextAction = nextAction; } public State next(Action action) { return mNextAction != null && action == mNextAction ? values()[ordinal() + 1] : INITIAL; } } private final float mHalfScreenWidth; private State mState = State.INITIAL; public KonamiCodeDetector(Context context) { super(context, false); mHalfScreenWidth = (float) context.getResources().getDisplayMetrics().widthPixels / 2; } @Override public void onSwipeLeft() { onAction(Action.LEFT); } @Override public void onSwipeRight() { onAction(Action.RIGHT); } @Override public void onSwipeUp() { onAction(Action.UP); } @Override public void onSwipeDown() { onAction(Action.DOWN); } @Override public boolean onSingleTapConfirmed(MotionEvent event) { if (event.getX() < mHalfScreenWidth) { onAction(Action.A); } else { onAction(Action.B); } return true; } private void onAction(Action action) { mState = mState.next(action); if (mState == State.FINAL) { onDetected(); mState = mState.next(null); } } public abstract void onDetected(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/KonamiCodeDetector.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
470
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.text.style.ReplacementSpan; public class IconSpan extends ReplacementSpan { private Drawable mDrawable; private int topFix; private int bottomFix; public IconSpan(Drawable drawable) { mDrawable = drawable; } @Override public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm) { if (fm != null) { // Important in the case when icon is the first character. int oldTop = fm.top; int oldBottom = fm.bottom; paint.getFontMetricsInt(fm); topFix = fm.top - oldTop; bottomFix = fm.bottom - oldBottom; int height = fm.descent - fm.ascent; int width; if (mDrawable.getIntrinsicHeight() > 0) { width = Math.round((float) height / mDrawable.getIntrinsicHeight() * mDrawable.getIntrinsicWidth()); } else { //noinspection SuspiciousNameCombination width = height; } mDrawable.setBounds(0, 0, width, height); // fm.ascent and fm.descent can affect top and bottom in draw(). fm.ascent = fm.top; fm.descent = fm.bottom; } return mDrawable.getBounds().right; } @Override public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) { canvas.save(); Rect bounds = mDrawable.getBounds(); top += topFix; bottom += bottomFix; // Center between top and bottom. canvas.translate(x, (top + bottom - bounds.top - bounds.bottom) / 2); mDrawable.draw(canvas); canvas.restore(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/IconSpan.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
437
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.ObjectAnimator; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.os.Build; import androidx.core.view.InputDeviceCompat; import androidx.core.view.MotionEventCompat; import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.core.widget.EdgeEffectCompat; import android.util.AttributeSet; import android.util.TypedValue; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.LinearLayout; import android.widget.Scroller; import butterknife.BindInt; import butterknife.ButterKnife; public class FlexibleSpaceLayout extends LinearLayout { private static final int INVALID_POINTER_ID = -1; @BindInt(android.R.integer.config_mediumAnimTime) int mMediumAnimationTime; private int mTouchSlop; private int mMinimumFlingVelocity; private int mMaximumFlingVelocity; private FlexibleSpaceHeaderView mHeaderView; private FlexibleSpaceContentView mContentView; private int mScroll; private boolean mHeaderCollapsed; private boolean mIsBeingDragged; private int mActivePointerId; private float mLastMotionY; private VelocityTracker mVelocityTracker; private Scroller mScroller; private EdgeEffectCompat mEdgeEffectBottom; private float mView_verticalScrollFactor = Float.MIN_VALUE; public FlexibleSpaceLayout(Context context) { super(context); init(getContext(), null, 0, 0); } public FlexibleSpaceLayout(Context context, AttributeSet attrs) { super(context, attrs); init(getContext(), attrs, 0, 0); } public FlexibleSpaceLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(getContext(), attrs, defStyleAttr, 0); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public FlexibleSpaceLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(getContext(), attrs, defStyleAttr, defStyleRes); } private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { ButterKnife.bind(this); setFocusable(true); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setOrientation(VERTICAL); setWillNotDraw(false); ViewConfiguration viewConfiguration = ViewConfiguration.get(context); mTouchSlop = viewConfiguration.getScaledTouchSlop(); mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity(); mScroller = new Scroller(context); mEdgeEffectBottom = new EdgeEffectCompat(context); } @Override protected void onFinishInflate() { super.onFinishInflate(); mHeaderView = findHeaderView(this); if (mHeaderView == null) { throw new IllegalStateException("Cannot find a FlexibleSpaceHeaderView"); } mContentView = findContentView(this); if (mContentView == null) { throw new IllegalStateException("Cannot find a FlexibleSpaceContentView"); } } private FlexibleSpaceHeaderView findHeaderView(View view) { if (view instanceof FlexibleSpaceHeaderView) { return (FlexibleSpaceHeaderView) view; } else if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; ++i) { FlexibleSpaceHeaderView headerView = findHeaderView(viewGroup.getChildAt(i)); if (headerView != null) { return headerView; } } } return null; } private FlexibleSpaceContentView findContentView(View view) { if (view instanceof FlexibleSpaceContentView) { return (FlexibleSpaceContentView) view; } else if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; ++i) { FlexibleSpaceContentView contentView = findContentView(viewGroup.getChildAt(i)); if (contentView != null) { return contentView; } } } return null; } public int getScroll() { return mScroll; } public void scrollTo(int scroll) { if (mScroll == scroll) { return; } mHeaderView.scrollTo(scroll); scroll = Math.max(0, scroll - mHeaderView.getScroll()); mContentView.scrollTo(scroll); int headerScroll = mHeaderView.getScroll(); mScroll = headerScroll + mContentView.getScroll(); if (headerScroll == 0) { mHeaderCollapsed = false; } else if (headerScroll == mHeaderView.getScrollExtent()) { mHeaderCollapsed = true; } } public void scrollBy(int delta) { scrollTo(mScroll + delta); } private void fling(float velocity) { // From AOSP MultiShrinkScroller // TODO: Is this true? // For reasons I do not understand, scrolling is less janky when maxY=Integer.MAX_VALUE // then when maxY is set to an actual value. mScroller.fling(0, mScroll, 0, (int) velocity, 0, 0, -Integer.MAX_VALUE, Integer.MAX_VALUE); ViewCompat.postInvalidateOnAnimation(this); } public boolean isHeaderOpen() { return mScroll == 0; } public boolean isHeaderCollapsed() { return mHeaderCollapsed; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: if (!mScroller.isFinished()) { return true; // updateActivePointerId(event) and clearVelocityTrackerIfHas() should be called // in onTouchEvent(). } else { updateActivePointerId(event); clearVelocityTrackerIfHas(); } break; case MotionEvent.ACTION_MOVE: if (mIsBeingDragged) { return true; } else if (Math.abs(getMotionEventY(event) - mLastMotionY) > mTouchSlop) { return true; } break; case MotionEventCompat.ACTION_POINTER_DOWN: onPointerDown(event); break; case MotionEventCompat.ACTION_POINTER_UP: onPointerUp(event); break; } // updateLastMotion() is called here if the touch event is not to be intercepted, so // otherwise it should always be called in onTouchEvent(). updateLastMotion(event); return false; } @Override public boolean onTouchEvent(MotionEvent event) { switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: updateActivePointerId(event); clearVelocityTrackerIfHas(); if (!mIsBeingDragged) { startDrag(); } else { restartDrag(); } break; case MotionEvent.ACTION_MOVE: { float deltaY = getMotionEventY(event) - mLastMotionY; if (deltaY == 0) { break; } if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) { startDrag(); if (deltaY > 0) { deltaY -= mTouchSlop; } else { deltaY += mTouchSlop; } } if (mIsBeingDragged) { onDrag(event, deltaY); } break; } case MotionEvent.ACTION_UP: endDrag(false); break; case MotionEvent.ACTION_CANCEL: endDrag(true); break; case MotionEventCompat.ACTION_POINTER_DOWN: onPointerDown(event); break; case MotionEventCompat.ACTION_POINTER_UP: onPointerUp(event); break; } updateLastMotion(event); return true; } private void onPointerDown(MotionEvent event) { int pointerIndex = MotionEventCompat.getActionIndex(event); mActivePointerId = MotionEventCompat.getPointerId(event, pointerIndex); mLastMotionY = MotionEventCompat.getY(event, pointerIndex); } private void onPointerUp(MotionEvent event) { int pointerIndex = MotionEventCompat.getActionIndex(event); int pointerId = MotionEventCompat.getPointerId(event, pointerIndex); if (pointerId == mActivePointerId) { int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(event, newPointerIndex); mLastMotionY = MotionEventCompat.getY(event, newPointerIndex); } } @Override public boolean onGenericMotionEvent(MotionEvent event) { if (MotionEventCompat_isFromSource(event, InputDeviceCompat.SOURCE_CLASS_POINTER)) { if (event.getActionMasked() == MotionEvent.ACTION_SCROLL) { if (!mIsBeingDragged) { float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (vscroll != 0) { float deltaY = vscroll * View_getScrollFactor(); int oldScrollY = getScrollY(); scrollBy(0, (int) -deltaY); return getScrollY() != oldScrollY; } } } } return super.onGenericMotionEvent(event); } private void startDrag() { abortScrollerAnimation(); requestParentDisallowInterceptTouchEventIfHas(true); mIsBeingDragged = true; } private void restartDrag() { abortScrollerAnimation(); } protected void onDrag(MotionEvent event, float delta) { int oldScroll = mScroll; scrollBy((int) -delta); delta += mScroll - oldScroll; if (delta < 0) { pullEdgeEffectBottom(event, delta); } } protected void pullEdgeEffectBottom(MotionEvent event, float delta) { mEdgeEffectBottom.onPull(-delta / getHeight(), 1f - getMotionEventX(event) / getWidth()); if (!mEdgeEffectBottom.isFinished()) { ViewCompat.postInvalidateOnAnimation(this); } } private void endDrag(boolean cancelled) { if (!mIsBeingDragged) { return; } mIsBeingDragged = false; mEdgeEffectBottom.onRelease(); onDragEnd(cancelled); mActivePointerId = INVALID_POINTER_ID; recycleVelocityTrackerIfHas(); } protected void onDragEnd(boolean cancelled) { boolean startedFling = false; if (!cancelled) { float velocity = getCurrentVelocity(); if (Math.abs(velocity) > mMinimumFlingVelocity) { fling(-velocity); startedFling = true; } } if (!startedFling && mScroll > 0 && mScroll < mHeaderView.getScrollExtent()) { snapHeaderView(); } } @Override public void computeScroll() { if (mScroller.computeScrollOffset()) { int oldScroll = mScroll; int scrollerCurrY = mScroller.getCurrY(); scrollTo(scrollerCurrY); int headerScrollExtent = mHeaderView.getScrollExtent(); int scrollerFinalY = mScroller.getFinalY(); if (mScroll > 0 && mScroll < headerScrollExtent && scrollerFinalY > 0 && scrollerFinalY < headerScrollExtent) { forceScrollerFinished(); snapHeaderView(); } else { if (mScroll > oldScroll && scrollerCurrY > mScroll) { // We did scroll down for some y and the target y is beyond our range. mEdgeEffectBottom.onAbsorb((int) mScroller.getCurrVelocity()); } if (scrollerCurrY < 0 || scrollerCurrY > mScroll) { abortScrollerAnimation(); } ViewCompat.postInvalidateOnAnimation(this); } } } private void snapHeaderView() { animateHeaderViewScroll(!mHeaderCollapsed); } public void animateHeaderViewScroll(boolean toCollapsed) { ObjectAnimator animator = ObjectAnimator.ofInt(this, SCROLL, mScroll, toCollapsed ? mHeaderView.getScrollExtent() : 0); animator.setDuration(mMediumAnimationTime); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.start(); } @Override public void draw(Canvas canvas) { super.draw(canvas); if (shouldDrawEdgeEffectBottom() && !mEdgeEffectBottom.isFinished()) { int count = canvas.save(); int width = getWidth(); int height = getHeight(); canvas.translate(-width, height); canvas.rotate(180, width, 0); mEdgeEffectBottom.setSize(width, height); if (mEdgeEffectBottom.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); } canvas.restoreToCount(count); } } protected boolean shouldDrawEdgeEffectBottom() { return true; } private void updateActivePointerId(MotionEvent event) { // ACTION_DOWN always refers to pointer index 0. mActivePointerId = MotionEventCompat.getPointerId(event, 0); } private void updateLastMotion(MotionEvent event) { mLastMotionY = getMotionEventY(event); ensureVelocityTracker().addMovement(event); } private float getMotionEventX(MotionEvent event) { if (mActivePointerId != INVALID_POINTER_ID) { int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId); if (pointerIndex != -1) { return MotionEventCompat.getX(event, pointerIndex); } else { // Error! } } return event.getX(); } private float getMotionEventY(MotionEvent event) { if (mActivePointerId != INVALID_POINTER_ID) { int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId); if (pointerIndex != -1) { return MotionEventCompat.getY(event, pointerIndex); } else { // Error! } } return event.getY(); } private VelocityTracker ensureVelocityTracker() { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } return mVelocityTracker; } private void clearVelocityTrackerIfHas() { if (mVelocityTracker != null) { mVelocityTracker.clear(); } } protected void recycleVelocityTrackerIfHas() { if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } } private float getCurrentVelocity() { if (mVelocityTracker == null) { return 0; } mVelocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); return mVelocityTracker.getYVelocity(mActivePointerId); } protected void abortScrollerAnimation() { mScroller.abortAnimation(); } private void forceScrollerFinished() { mScroller.forceFinished(true); } private void requestParentDisallowInterceptTouchEventIfHas(boolean disallowIntercept) { ViewParent viewParent = getParent(); if (viewParent != null) { viewParent.requestDisallowInterceptTouchEvent(disallowIntercept); } } public static final IntProperty<FlexibleSpaceLayout> SCROLL = new IntProperty<FlexibleSpaceLayout>("scroll") { @Override public Integer get(FlexibleSpaceLayout object) { return object.getScroll(); } @Override public void setValue(FlexibleSpaceLayout object, int value) { object.scrollTo(value); } }; private float View_getScrollFactor() { if (mView_verticalScrollFactor == Float.MIN_VALUE) { Context context = getContext(); TypedValue outValue = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, outValue, true)) { mView_verticalScrollFactor = outValue.getDimension( context.getResources().getDisplayMetrics()); } else { throw new IllegalStateException( "Expected theme to define listPreferredItemHeight."); } } return mView_verticalScrollFactor; } private boolean MotionEventCompat_isFromSource(MotionEvent event, int source) { return (MotionEventCompat.getSource(event) & source) == source; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FlexibleSpaceLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
3,511
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.os.Parcelable; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.ScrollView; public class FlexibleSpaceContentScrollView extends ScrollView implements FlexibleSpaceContentView { public FlexibleSpaceContentScrollView(Context context) { super(context); } public FlexibleSpaceContentScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public FlexibleSpaceContentScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public FlexibleSpaceContentScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public int getScroll() { return getScrollY(); } @Override public void scrollTo(int scroll) { scrollTo(0, scroll); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } @Override public boolean onTouchEvent(MotionEvent ev) { return false; } @Override protected Parcelable onSaveInstanceState() { // Do not save the current scroll position. Always store scrollY as 0 and delegate // responsibility of saving state to FlexibleSpaceLayout. int scrollY = getScrollY(); setScrollY(0); Parcelable savedState = super.onSaveInstanceState(); setScrollY(scrollY); return savedState; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FlexibleSpaceContentScrollView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
344
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.recyclerview.widget.RecyclerView; public abstract class BarrierDataAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> { private int mBoundItemCount; public BarrierDataAdapter() { setHasStableIds(true); } @Override public int getItemCount() { int count = 0; for (int totalCount = getTotalItemCount(); count < totalCount; ++count) { if (!isItemLoaded(count)) { break; } } return count; } @Override public long getItemId(int position) { return position; } @Override public int getItemViewType(int position) { return position; } public abstract int getTotalItemCount(); protected abstract boolean isItemLoaded(int position); protected void notifyDataChanged() { int newItemCount = getItemCount(); if (newItemCount <= mBoundItemCount) { return; } notifyItemRangeInserted(mBoundItemCount, newItemCount - mBoundItemCount); mBoundItemCount = newItemCount; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/BarrierDataAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
237
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.Manifest; import android.accounts.Account; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.net.Uri; import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.ViewGroup; import android.webkit.JsPromptResult; import android.webkit.JsResult; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import butterknife.BindDimen; import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.account.info.AccountContract; import me.zhanghai.android.douya.account.util.AccountUtils; import me.zhanghai.android.douya.link.DoubanUriHandler; import me.zhanghai.android.douya.link.FrodoBridge; import me.zhanghai.android.douya.network.Http; import me.zhanghai.android.douya.network.api.credential.ApiCredential; import me.zhanghai.android.douya.network.api.info.UrlGettable; import me.zhanghai.android.douya.settings.info.Settings; import me.zhanghai.android.douya.util.AppUtils; import me.zhanghai.android.douya.util.ArrayUtils; import me.zhanghai.android.douya.util.ClipboardUtils; import me.zhanghai.android.douya.util.CollectionUtils; import me.zhanghai.android.douya.util.NightModeHelper; import me.zhanghai.android.douya.util.ShareUtils; import me.zhanghai.android.douya.util.StringUtils; import me.zhanghai.android.douya.util.ToastUtils; import me.zhanghai.android.douya.util.UriUtils; import me.zhanghai.android.douya.util.UrlUtils; import me.zhanghai.android.douya.util.ViewUtils; import me.zhanghai.android.douya.util.WebViewUtils; import me.zhanghai.android.effortlesspermissions.AfterPermissionDenied; import me.zhanghai.android.effortlesspermissions.EffortlessPermissions; import me.zhanghai.android.effortlesspermissions.OpenAppDetailsDialogFragment; import pub.devrel.easypermissions.AfterPermissionGranted; public class WebViewActivity extends AppCompatActivity { private static final String KEY_PREFIX = WebViewActivity.class.getName() + '.'; private static final String EXTRA_DISABLE_LOAD_OVERRIDING_URLS = KEY_PREFIX + "disable_load_overriding_urls"; private static final int REQUEST_CODE_FILE_CHOOSER = 1; private static final int REQUEST_CODE_DOWNLOAD_PERMISSION = 2; private static final String[] PERMISSIONS_DOWNLOAD = { Manifest.permission.WRITE_EXTERNAL_STORAGE }; private static final Pattern DOUBAN_HOST_PATTERN = Pattern.compile(".*\\.douban\\.(com|fm)"); private static final String DOUBAN_OAUTH2_REDIRECT_URL_FORMAT = "path_to_url"; @BindDimen(R.dimen.toolbar_height) int mToolbarHeight; @BindView(R.id.appBarWrapper) AppBarWrapperLayout mAppbarWrapperLayout; @BindView(R.id.toolbar) Toolbar mToolbar; @BindView(R.id.toolbar_progress) ProgressBar mProgress; @BindView(R.id.web) WebView mWebView; private MenuItem mGoForwardMenuItem; private MenuItem mOpenWithNativeMenuItem; private MenuItem mRequestDesktopSiteMenuItem; private Set<String> mDisableLoadOverridingUrls; private ValueCallback<Uri> mUploadFile; private ValueCallback<Uri[]> mFilePathCallback; private DownloadInfo mDownloadInfo; private String mTitleOrError; private boolean mProgressVisible; private String mDefaultUserAgent; private String mDesktopUserAgent; public static Intent makeIntent(Uri uri, Context context) { Intent intent = new Intent(context, WebViewActivity.class) .setData(uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Settings.CREATE_NEW_TASK_FOR_WEBVIEW.getValue()) { intent .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT) .addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } } return intent; } /** * @deprecated You probably want to use {@link #makeIntent(String, boolean, Context)} instead. */ public static Intent makeIntent(String uri, Context context) { return makeIntent(Uri.parse(uri), context); } public static Intent makeIntent(String uri, String[] disableLoadOverridingUrls, Context context) { //noinspection deprecation return makeIntent(uri, context) .putExtra(EXTRA_DISABLE_LOAD_OVERRIDING_URLS, disableLoadOverridingUrls); } public static Intent makeIntent(String uri, String disableLoadOverridingUrl, Context context) { return makeIntent(uri, new String[] { disableLoadOverridingUrl }, context); } public static Intent makeIntent(String uri, boolean disableLoadOverriding, Context context) { if (!disableLoadOverriding) { throw new IllegalArgumentException("disableLoadOverriding should always be true"); } return makeIntent(uri, new String[] { uri }, context); } public static Intent makeIntent(UrlGettable urlGettable, Context context) { return makeIntent(urlGettable.getUrl(), true, context); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] disableLoadOverridingUrls = getIntent().getStringArrayExtra( EXTRA_DISABLE_LOAD_OVERRIDING_URLS); mDisableLoadOverridingUrls = new HashSet<>(); if (disableLoadOverridingUrls != null) { mDisableLoadOverridingUrls.addAll(Arrays.asList(disableLoadOverridingUrls)); } setContentView(R.layout.webview_activity); ButterKnife.bind(this); setupToolbar(); setupWebView(); } @Override protected void onDestroy() { super.onDestroy(); ((ViewGroup) mWebView.getParent()).removeView(mWebView); mWebView.destroy(); mWebView = null; } @Override public void onConfigurationChanged(Configuration newConfig) { // Need to do this before calling super to avoid activity recreation by AppCompat. NightModeHelper.onConfigurationChanged(this, this::onApplyThemeResource, R.style.Theme_Douya); super.onConfigurationChanged(newConfig); Context themedContext = new ContextThemeWrapper(this, ViewUtils.getResIdFromAttrRes( R.attr.actionBarTheme, 0, this)); Toolbar newToolbar = (Toolbar) LayoutInflater.from(themedContext).inflate( R.layout.webview_acitivity_toolbar, mAppbarWrapperLayout, false); ViewUtils.replaceChild(mAppbarWrapperLayout, mToolbar, newToolbar); ButterKnife.bind(this); setupToolbar(); ViewUtils.setVisibleOrGone(mProgress, mProgressVisible); ViewUtils.setMarginTop(mWebView, mToolbarHeight); mWebView.requestLayout(); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.webview, menu); mGoForwardMenuItem = menu.findItem(R.id.action_go_forward); updateGoForward(); mOpenWithNativeMenuItem = menu.findItem(R.id.action_open_with_native); updateOpenWithNative(); mRequestDesktopSiteMenuItem = menu.findItem(R.id.action_request_desktop_site); updateRequestDesktopSite(); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; case R.id.action_go_forward: goForward(); return true; case R.id.action_reload: reloadWebView(); return true; case R.id.action_copy_url: copyUrl(); return true; case R.id.action_share: share(); return true; case R.id.action_open_with_native: toggleOpenWithNative(); return true; case R.id.action_request_desktop_site: toggleRequestDesktopSite(); return true; case R.id.action_open_in_browser: openInBrowser(); return true; default: return super.onOptionsItemSelected(item); } } @Override public void onBackPressed() { if (mWebView.canGoBack()) { mWebView.goBack(); } else { super.onBackPressed(); } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); EffortlessPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE_FILE_CHOOSER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (mFilePathCallback != null) { // This cannot handle multiple URIs. //Uri[] value = WebChromeClient.FileChooserParams.parseResult(resultCode, // data); Uri[] value = WebViewUtils.parseFileChooserResult(resultCode, data); mFilePathCallback.onReceiveValue(value); mFilePathCallback = null; } } else { if (mUploadFile != null) { Uri[] value = WebViewUtils.parseFileChooserResult(resultCode, data); mUploadFile.onReceiveValue(!ArrayUtils.isEmpty(value) ? value[0] : null); mUploadFile = null; } } break; default: super.onActivityResult(requestCode, resultCode, data); } } protected void onLoadUri(WebView webView) { String url = getIntent().getData().toString(); if (Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.getValue()) { url = getDoubanDesktopSiteUrl(url); } Map<String, String> headers = null; if (isDoubanUrl(url)) { Account account = AccountUtils.getActiveAccount(); if (account != null) { String authToken = AccountUtils.peekAuthToken(account, AccountContract.AUTH_TOKEN_TYPE_FRODO); if (!TextUtils.isEmpty(authToken)) { url = StringUtils.formatUs(DOUBAN_OAUTH2_REDIRECT_URL_FORMAT, Uri.encode(url), Uri.encode(ApiCredential.API_V2_KEY)); headers = new HashMap<>(); headers.put(Http.Headers.AUTHORIZATION, Http.Headers.makeBearerAuthorization(authToken)); } } } webView.loadUrl(url, headers); } private boolean isDoubanUrl(String url) { return DOUBAN_HOST_PATTERN.matcher(Uri.parse(url).getHost()).matches(); } protected void onPageStared(WebView webView, String url, Bitmap favicon) { updateGoForward(); updateToolbarTitleAndSubtitle(); } protected void onPageFinished(WebView webView, String url) {} protected boolean shouldOverrideUrlLoading(WebView webView, String url) { Uri uri = Uri.parse(url); if (mDisableLoadOverridingUrls.contains(UriUtils.withoutQueryAndFragment(uri).toString())) { return false; } return (Settings.OPEN_WITH_NATIVE_IN_WEBVIEW.getValue() && DoubanUriHandler.open(uri, this)) || FrodoBridge.openFrodoUri(uri, this) || (Settings.PROGRESSIVE_THIRD_PARTY_APP.getValue() && FrodoBridge.openUri(uri, this)); } protected void reloadWebView() { mWebView.reload(); } private void setupToolbar() { if (Settings.CREATE_NEW_TASK_FOR_WEBVIEW.getValue()) { mToolbar.setNavigationIcon(R.drawable.close_icon_white_24dp); } setSupportActionBar(mToolbar); updateToolbarTitleAndSubtitle(); } private void updateToolbarTitleAndSubtitle() { String url = mWebView.getUrl(); if (TextUtils.isEmpty(url)) { return; } if (TextUtils.isEmpty(mTitleOrError)) { mTitleOrError = Uri.parse(url).getHost(); } ActionBar actionBar = getSupportActionBar(); if (TextUtils.isEmpty(actionBar.getSubtitle())) { mToolbar.setTitleTextAppearance(mToolbar.getContext(), R.style.TextAppearance_Widget_Douya_Toolbar_Title_WebView); mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), R.style.TextAppearance_Widget_Douya_Toolbar_Subtitle_WebView); } setTitle(mTitleOrError); if (Settings.CREATE_NEW_TASK_FOR_WEBVIEW.getValue()) { AppUtils.setTaskDescriptionLabel(this, mTitleOrError); } actionBar.setSubtitle(url); } private void setProgressVisible(boolean visible) { if (mProgressVisible != visible) { mProgressVisible = visible; ViewUtils.setVisibleOrGone(mProgress, visible); } } @SuppressLint("SetJavaScriptEnabled") private void setupWebView() { WebSettings webSettings = mWebView.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setDomStorageEnabled(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { webSettings.setDatabasePath(WebViewUtils.getDatabasePath(this)); } webSettings.setDatabaseEnabled(true); webSettings.setLoadWithOverviewMode(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); } webSettings.setJavaScriptEnabled(true); initializeUserAgents(); updateUserAgent(); // NOTE: This gives double tap zooming. webSettings.setUseWideViewPort(true); mWebView.setWebChromeClient(new ChromeClient()); mWebView.setWebViewClient(new ViewClient()); mWebView.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> download(url, userAgent, contentDisposition, mimeType)); onLoadUri(mWebView); } private void goForward() { mWebView.goForward(); // Handled in onPageStared(). //updateGoForward(); } private void updateGoForward() { if (mGoForwardMenuItem == null) { return; } mGoForwardMenuItem.setEnabled(mWebView.canGoForward()); } private void copyUrl() { String url = mWebView.getUrl(); if (TextUtils.isEmpty(url)) { ToastUtils.show(R.string.webview_error_url_empty, this); return; } ClipboardUtils.copyText(mWebView.getTitle(), url, this); } private void share() { String url = mWebView.getUrl(); if (TextUtils.isEmpty(url)) { ToastUtils.show(R.string.webview_error_url_empty, this); return; } ShareUtils.shareText(url, this); } private void toggleOpenWithNative() { Settings.OPEN_WITH_NATIVE_IN_WEBVIEW.putValue( !Settings.OPEN_WITH_NATIVE_IN_WEBVIEW.getValue()); updateOpenWithNative(); } private void updateOpenWithNative() { if (mOpenWithNativeMenuItem == null) { return; } mOpenWithNativeMenuItem.setChecked(Settings.OPEN_WITH_NATIVE_IN_WEBVIEW.getValue()); } private void toggleRequestDesktopSite() { Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.putValue( !Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.getValue()); updateRequestDesktopSite(); updateUserAgent(); } private void updateRequestDesktopSite() { if (mRequestDesktopSiteMenuItem == null) { return; } mRequestDesktopSiteMenuItem.setChecked(Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.getValue()); } private void initializeUserAgents() { mDefaultUserAgent = mWebView.getSettings().getUserAgentString(); mDesktopUserAgent = mDefaultUserAgent .replaceFirst("\\(Linux;.*?\\)", "(X11; Linux x86_64)") .replace("Mobile Safari/", "Safari/"); } private void updateUserAgent() { boolean requestDesktopSite = Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.getValue(); WebSettings webSettings = mWebView.getSettings(); String oldUserAgent = webSettings.getUserAgentString(); boolean changed = false; if (requestDesktopSite && !TextUtils.equals(oldUserAgent, mDesktopUserAgent)) { webSettings.setUserAgentString(mDesktopUserAgent); changed = true; } else if (!requestDesktopSite && !TextUtils.equals(oldUserAgent, mDefaultUserAgent)) { // This will requrie API level 17. //webSettings.setUserAgentString(WebSettings.getDefaultUserAgent(this)); webSettings.setUserAgentString(mDefaultUserAgent); changed = true; } String url = mWebView.getUrl(); if (!TextUtils.isEmpty(url) && changed) { if (requestDesktopSite) { String doubanDesktopSiteUrl = getDoubanDesktopSiteUrl(url); if (!TextUtils.equals(url, doubanDesktopSiteUrl)) { mWebView.loadUrl(doubanDesktopSiteUrl); } else { mWebView.reload(); } } else { mWebView.reload(); } } } private String getDoubanDesktopSiteUrl(String url) { Uri uri = Uri.parse(url); if (!TextUtils.equals(uri.getHost(), "m.douban.com") || TextUtils.equals(CollectionUtils.firstOrNull(uri.getPathSegments()), "page")) { return url; } return uri.buildUpon() .path("/to_pc/") .appendQueryParameter("url", url) .build() .toString(); } private void openInBrowser() { String url = mWebView.getUrl(); if (!TextUtils.isEmpty(url)) { UrlUtils.openWithIntent(url, this); } else { ToastUtils.show(R.string.webview_error_url_empty, this); } } private void download(String url, String userAgent, String contentDisposition, String mimeType) { mDownloadInfo = new DownloadInfo(url, userAgent, contentDisposition, mimeType); download(); } @AfterPermissionGranted(REQUEST_CODE_DOWNLOAD_PERMISSION) private void download() { if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_DOWNLOAD)) { downloadWithPermission(); } else { EffortlessPermissions.requestPermissions(this, R.string.webview_download_permission_request_message, REQUEST_CODE_DOWNLOAD_PERMISSION, PERMISSIONS_DOWNLOAD); } } @AfterPermissionDenied(REQUEST_CODE_DOWNLOAD_PERMISSION) private void onDownloadPermissionDenied() { if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_DOWNLOAD)) { OpenAppDetailsDialogFragment.show( R.string.webview_download_permission_permanently_denied_message, R.string.open_settings, this); } else { ToastUtils.show(R.string.webview_download_permission_denied, this); } } private void downloadWithPermission() { WebViewUtils.download(mDownloadInfo.mUrl, mDownloadInfo.mUserAgent, mDownloadInfo.mContentDisposition, mDownloadInfo.mMimeType, this); mDownloadInfo = null; } private class ChromeClient extends WebChromeClient { // NOTE: WebView can be trying to show an AlertDialog after the activity is finished, which // will result in a WindowManager$BadTokenException. @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return WebViewActivity.this.isFinishing() || super.onJsAlert(view, url, message, result); } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { return WebViewActivity.this.isFinishing() || super.onJsConfirm(view, url, message, result); } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { return WebViewActivity.this.isFinishing() || super.onJsPrompt(view, url, message, defaultValue, result); } @Override public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) { return WebViewActivity.this.isFinishing() || super.onJsBeforeUnload(view, url, message, result); } @Override public void onProgressChanged(WebView view, int newProgress) { setProgressVisible(newProgress != 100); } @Override public void onReceivedTitle(WebView view, String title) { mTitleOrError = title; updateToolbarTitleAndSubtitle(); } // For API level <= 15. //@Override @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) { if (mUploadFile != null) { mUploadFile.onReceiveValue(null); } mUploadFile = uploadFile; AppUtils.startActivityForResultWithChooser(WebViewUtils.createFileChooserIntent( acceptType), REQUEST_CODE_FILE_CHOOSER, WebViewActivity.this); } // For 16 <= API level <= 19. //@Override @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) { openFileChooser(uploadFile, acceptType); } // For API level >= 21. @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; AppUtils.startActivityForResultWithChooser(WebViewUtils.createFileChooserIntent( fileChooserParams), REQUEST_CODE_FILE_CHOOSER, WebViewActivity.this); return true; } } private class ViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { WebViewActivity.this.onPageStared(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { WebViewActivity.this.onPageFinished(view, url); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { mTitleOrError = description; updateToolbarTitleAndSubtitle(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return WebViewActivity.this.shouldOverrideUrlLoading(view, url); } } private static class DownloadInfo { public String mUrl; public String mUserAgent; public String mContentDisposition; public String mMimeType; public DownloadInfo(String url, String userAgent, String contentDisposition, String mimeType) { mUrl = url; mUserAgent = userAgent; mContentDisposition = contentDisposition; mMimeType = mimeType; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/WebViewActivity.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
4,928
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.annotation.SuppressLint; import android.content.Context; import android.os.Build; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.view.ViewCompat; import androidx.appcompat.widget.TintTypedArray; import android.util.AttributeSet; import android.view.View; public class PercentageWidthView extends View { private static final int[] STYLEABLE = { android.R.attr.maxWidth }; private static final int STYLEABLE_ANDROID_MAX_WIDTH = 0; private boolean mMaxWidthEnabled = true; private int mMaxWidth; private float mWidthPercentage; public PercentageWidthView(Context context) { super(context); } public PercentageWidthView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(attrs, 0, 0); } public PercentageWidthView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr, 0); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public PercentageWidthView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(attrs, defStyleAttr, defStyleRes); } @SuppressLint("RestrictedApi") private void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, STYLEABLE, defStyleAttr, defStyleRes); mMaxWidth = a.getDimensionPixelSize(STYLEABLE_ANDROID_MAX_WIDTH, mMaxWidth); a.recycle(); } public void setMaxWidthEnabled(boolean maxWidthEnabled) { if (mMaxWidthEnabled == maxWidthEnabled) { return; } mMaxWidthEnabled = maxWidthEnabled; requestLayout(); } public void setMaxWidth(int maxWidth) { if (mMaxWidth == maxWidth) { return; } mMaxWidth = maxWidth; if (mMaxWidthEnabled) { requestLayout(); } } public void setWidthPercentage(float widthPercentage) { if (mWidthPercentage == widthPercentage) { return; } mWidthPercentage = widthPercentage; requestLayout(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = mMaxWidth; if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) { mMaxWidth = Math.min(mMaxWidth, MeasureSpec.getSize(widthMeasureSpec)); } width = Math.round(mWidthPercentage * width); width = Math.max(width, ViewCompat.getMinimumWidth(this)); widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/PercentageWidthView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
601
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; import android.util.TypedValue; import android.view.KeyEvent; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.util.FragmentUtils; @SuppressWarnings("unused") public class SimpleDialogFragment extends AppCompatDialogFragment { private static final String ARGUMENT_REQUEST_CODE = "request_code"; private static final String ARGUMENT_THEME = "theme"; private static final String ARGUMENT_ICON_ID = "icon_id"; private static final String ARGUMENT_TITLE = "tle"; private static final String ARGUMENT_MESSAGE = "message"; private static final String ARGUMENT_ITEMS = "items"; private static final String ARGUMENT_IS_SINGLE_CHOICE = "is_single_choice"; private static final String ARGUMENT_CHOICE_ITEMS = "choice_items"; private static final String ARGUMENT_CHOICE_CHECKED_ITEM = "checked_item"; private static final String ARGUMENT_POSITIVE_BUTTON_TEXT = "positive_button_text"; private static final String ARGUMENT_NEUTRAL_BUTTON_TEXT = "neutral_button_text"; private static final String ARGUMENT_NEGATIVE_BUTTON_TEXT = "negative_button_text"; private static final String ARGUMENT_CANCELABLE = "cancelable"; public static final int REQUEST_CODE_INVALID = -1; private Listener mListener; private int mRequestCode; private static SimpleDialogFragment makeClose(int requestCode, Integer titleId, int messageId, Context context) { return new Builder(context) .setRequestCode(requestCode) .setTitle(titleId) .setMessage(messageId) .setPositiveButtonText(R.string.close) .build(); } public static SimpleDialogFragment makeClose(Integer titleId, int messageId, Context context) { return makeClose(REQUEST_CODE_INVALID, titleId, messageId, context); } public static SimpleDialogFragment makeClose(int requestCode, Integer titleId, int messageId, Fragment fragment) { return makeClose(requestCode, titleId, messageId, fragment.getActivity()); } public static SimpleDialogFragment makeClose(Integer titleId, int messageId, Fragment fragment) { return makeClose(REQUEST_CODE_INVALID, titleId, messageId, fragment); } private static SimpleDialogFragment makeOkCancel(int requestCode, Integer titleId, int messageId, Context context) { return new Builder(context) .setRequestCode(requestCode) .setTitle(titleId) .setMessage(messageId) .setPositiveButtonText(R.string.ok) .setNegativeButtonText(R.string.cancel) .build(); } public static SimpleDialogFragment makeOkCancel(Integer titleId, int messageId, Context context) { return makeOkCancel(REQUEST_CODE_INVALID, titleId, messageId, context); } public static SimpleDialogFragment makeOkCancel(int requestCode, Integer titleId, int messageId, Fragment fragment) { return makeOkCancel(requestCode, titleId, messageId, fragment.getActivity()); } public static SimpleDialogFragment makeOkCancel(Integer titleId, int messageId, Fragment fragment) { return makeOkCancel(REQUEST_CODE_INVALID, titleId, messageId, fragment); } private static SimpleDialogFragment makeYesNo(int requestCode, Integer titleId, int messageId, Context context) { return new Builder(context) .setRequestCode(requestCode) .setTitle(titleId) .setMessage(messageId) .setPositiveButtonText(R.string.yes) .setNegativeButtonText(R.string.no) .build(); } public static SimpleDialogFragment makeYesNo(Integer titleId, int messageId, Context context) { return makeYesNo(REQUEST_CODE_INVALID, titleId, messageId, context); } public static SimpleDialogFragment makeYesNo(int requestCode, Integer titleId, int messageId, Fragment fragment) { return makeYesNo(requestCode, titleId, messageId, fragment.getActivity()); } public static SimpleDialogFragment makeYesNo(Integer titleId, int messageId, Fragment fragment) { return makeYesNo(REQUEST_CODE_INVALID, titleId, messageId, fragment); } public static SimpleDialogFragment makeList(int requestCode, Integer titleId, CharSequence[] items, Context context) { return new Builder(context) .setRequestCode(requestCode) .setTitle(titleId) .setList(items) .setNegativeButtonText(R.string.cancel) .build(); } public static SimpleDialogFragment makeList(Integer titleId, CharSequence[] items, Context context) { return makeList(REQUEST_CODE_INVALID, titleId, items, context); } public static SimpleDialogFragment makeList(int requestCode, Integer titleId, CharSequence[] items, Fragment fragment) { return makeList(requestCode, titleId, items, fragment.getActivity()); } public static SimpleDialogFragment makeList(Integer titleId, CharSequence[] items, Fragment fragment) { return makeList(REQUEST_CODE_INVALID, titleId, items, fragment); } public static SimpleDialogFragment makeSingleChoice(int requestCode, Integer titleId, CharSequence[] items, int checkedItem, Context context) { return new Builder(context) .setRequestCode(requestCode) .setTitle(titleId) .setSingleChoice(items, checkedItem) .setNegativeButtonText(R.string.cancel) .build(); } public static SimpleDialogFragment makeSingleChoice(Integer titleId, CharSequence[] items, int checkedItem, Context context) { return makeSingleChoice(REQUEST_CODE_INVALID, titleId, items, checkedItem, context); } public static SimpleDialogFragment makeSingleChoice(int requestCode, Integer titleId, CharSequence[] items, int checkedItem, Fragment fragment) { return makeSingleChoice(requestCode, titleId, items, checkedItem, fragment.getActivity()); } public static SimpleDialogFragment makeSingleChoice(Integer titleId, CharSequence[] items, int checkedItem, Fragment fragment) { return makeSingleChoice(REQUEST_CODE_INVALID, titleId, items, checkedItem, fragment); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Fragment parentFragment = getParentFragment(); if (parentFragment == null) { Activity activity = getActivity(); if (activity instanceof ListenerProvider) { mListener = ((ListenerProvider) activity).getDialogListener(); } } else { if (parentFragment instanceof ListenerProvider) { mListener = ((ListenerProvider) parentFragment).getDialogListener(); } } mRequestCode = getArguments().getInt(ARGUMENT_REQUEST_CODE); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder alertDialogBuilder; Bundle arguments = getArguments(); int theme = arguments.getInt(ARGUMENT_THEME); if (theme == 0) { alertDialogBuilder = new AlertDialog.Builder(getActivity()); } else { alertDialogBuilder = new AlertDialog.Builder(getActivity(), theme); } alertDialogBuilder .setIcon(arguments.getInt(ARGUMENT_ICON_ID)) .setTitle(arguments.getCharSequence(ARGUMENT_TITLE)) .setMessage(arguments.getCharSequence(ARGUMENT_MESSAGE)); CharSequence[] items = arguments.getCharSequenceArray(ARGUMENT_ITEMS); if (items != null) { alertDialogBuilder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { if (mListener != null) { mListener.onListItemClicked(mRequestCode, which); } } }); } else if (arguments.getBoolean(ARGUMENT_IS_SINGLE_CHOICE)) { alertDialogBuilder.setSingleChoiceItems( arguments.getCharSequenceArray(ARGUMENT_CHOICE_ITEMS), arguments.getInt(ARGUMENT_CHOICE_CHECKED_ITEM), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) { mListener.onSingleChoiceItemClicked(mRequestCode, which); } } }); } alertDialogBuilder .setPositiveButton(arguments.getCharSequence(ARGUMENT_POSITIVE_BUTTON_TEXT), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) { mListener.onPositiveButtonClicked(mRequestCode); } } }) .setNeutralButton(arguments.getCharSequence(ARGUMENT_NEUTRAL_BUTTON_TEXT), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) { mListener.onNeutralButtonClicked(mRequestCode); } } }) .setNegativeButton(arguments.getCharSequence(ARGUMENT_NEGATIVE_BUTTON_TEXT), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) { mListener.onNegativeButtonClicked(mRequestCode); } } }) .setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent keyEvent) { //noinspection SimplifiableIfStatement if (mListener != null) { return mListener.onKey(mRequestCode, keyCode, keyEvent); } else { return false; } } }) .setCancelable(arguments.getBoolean(ARGUMENT_CANCELABLE)); return alertDialogBuilder.create(); } /* * NOTE: * From DialogFragment.onCreateDialog documentation: * DialogFragment own the Dialog.setOnCancelListener and Dialog.setOnDismissListener callbacks. * You must not set them yourself. * To find out about these events, override onCancel(DialogInterface) and * onDismiss(DialogInterface). */ @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); if (mListener != null) { mListener.onCancel(mRequestCode); } } @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); if (mListener != null) { mListener.onDismiss(mRequestCode); } } public AlertDialog getAlertDialog() { return (AlertDialog) getDialog(); } @Deprecated public void show(FragmentManager manager) { show(manager, null); } public void show(FragmentActivity activity) { //noinspection deprecation show(activity.getSupportFragmentManager()); } public void show(Fragment fragment) { //noinspection deprecation show(fragment.getChildFragmentManager()); } public static class Listener { public void onListItemClicked(int requestCode, int index) {} public void onSingleChoiceItemClicked(int requestCode, int index) {} public void onPositiveButtonClicked(int requestCode) {} public void onNeutralButtonClicked(int requestCode) {} public void onNegativeButtonClicked(int requestCode) {} public void onCancel(int requestCode) {} public void onDismiss(int requestCode) {} public boolean onKey(int requestCode, int keyCode, KeyEvent keyEvent) { return false; } } public interface ListenerProvider { Listener getDialogListener(); } public static class Builder { private Context mContext; private int mRequestCode; private int mTheme; private int mIconId; private CharSequence mTitle; private CharSequence mMessage; private CharSequence[] mItems; private boolean mIsSingleChoice; private CharSequence[] mChoiceItems; private int mChoiceCheckedItem; private CharSequence mNegativeButtonText; private CharSequence mNeutralButtonText; private CharSequence mPositiveButtonText; private boolean mCancelable; public Builder(Context context) { mContext = context; } public Builder setRequestCode(int requestCode) { mRequestCode = requestCode; return this; } public Builder setTheme(int theme) { mTheme = theme; return this; } public Builder setIcon(int iconId) { mIconId = iconId; return this; } public Builder setIconAttribute(int attrId) { TypedValue typedValue = new TypedValue(); mContext.getTheme().resolveAttribute(attrId, typedValue, true); return setIcon(typedValue.resourceId); } public Builder setTitle(CharSequence title) { mTitle = title; return this; } public Builder setTitle(int titleId) { return setTitle(mContext.getText(titleId)); } public Builder setTitle(Integer titleId) { if (titleId != null) { setTitle((int) titleId); } return this; } public Builder setMessage(CharSequence message) { mMessage = message; return this; } public Builder setMessage(int messageId) { return setMessage(mContext.getText(messageId)); } public Builder setList(CharSequence[] items) { mItems = items; return this; } public Builder setSingleChoice(CharSequence[] items, int checkedItem) { mIsSingleChoice = true; mChoiceItems = items; mChoiceCheckedItem = checkedItem; return this; } public Builder setPositiveButtonText(CharSequence text) { mPositiveButtonText = text; return this; } public Builder setPositiveButtonText(int textId) { return setPositiveButtonText(mContext.getText(textId)); } public Builder setNeutralButtonText(CharSequence text) { mNeutralButtonText = text; return this; } public Builder setNeutralButtonText(int textId) { return setNeutralButtonText(mContext.getText(textId)); } public Builder setNegativeButtonText(CharSequence text) { mNegativeButtonText = text; return this; } public Builder setNegativeButtonText(int textId) { return setNegativeButtonText(mContext.getText(textId)); } public Builder setCancelable(boolean cancelable) { mCancelable = cancelable; return this; } public SimpleDialogFragment build() { SimpleDialogFragment fragment = new SimpleDialogFragment(); FragmentUtils.getArgumentsBuilder(fragment) .putInt(ARGUMENT_REQUEST_CODE, mRequestCode) .putInt(ARGUMENT_THEME, mTheme) .putInt(ARGUMENT_ICON_ID, mIconId) .putCharSequence(ARGUMENT_TITLE, mTitle) .putCharSequence(ARGUMENT_MESSAGE, mMessage) .putCharSequenceArray(ARGUMENT_ITEMS, mItems) .putBoolean(ARGUMENT_IS_SINGLE_CHOICE, mIsSingleChoice) .putCharSequenceArray(ARGUMENT_CHOICE_ITEMS, mChoiceItems) .putInt(ARGUMENT_CHOICE_CHECKED_ITEM, mChoiceCheckedItem) .putCharSequence(ARGUMENT_POSITIVE_BUTTON_TEXT, mPositiveButtonText) .putCharSequence(ARGUMENT_NEUTRAL_BUTTON_TEXT, mNeutralButtonText) .putCharSequence(ARGUMENT_NEGATIVE_BUTTON_TEXT, mNegativeButtonText) .putBoolean(ARGUMENT_CANCELABLE, mCancelable); return fragment; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/SimpleDialogFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
3,131
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.util.AttributeSet; import android.widget.TextView; import java.lang.reflect.Field; import me.zhanghai.android.douya.util.ViewUtils; public class CrossfadeSubtitleToolbar extends Toolbar { @NonNull private ObjectAnimator mSubtitleAnimator; @Nullable private CharSequence mNextSubtitle; public CrossfadeSubtitleToolbar(@NonNull Context context) { super(context); init(); } public CrossfadeSubtitleToolbar(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } public CrossfadeSubtitleToolbar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { mSubtitleAnimator = ObjectAnimator.ofFloat(null, ALPHA, 1, 0, 1) .setDuration(2 * ViewUtils.getShortAnimTime(this)); mSubtitleAnimator.setInterpolator(new FastOutSlowInInterpolator()); AnimatorListener listener = new AnimatorListener(); mSubtitleAnimator.addUpdateListener(listener); mSubtitleAnimator.addListener(listener); } @Nullable @Override public CharSequence getSubtitle() { if (mNextSubtitle != null) { return mNextSubtitle; } return super.getSubtitle(); } @Override public void setSubtitle(@Nullable CharSequence subtitle) { if (TextUtils.equals(getSubtitle(), subtitle)) { return; } mNextSubtitle = subtitle; ensureSubtitleAnimatorTarget(); if (mSubtitleAnimator.getTarget() == null) { // Subtitle text view not available (yet), just delegate to super. super.setSubtitle(subtitle); return; } if (!mSubtitleAnimator.isRunning()) { mSubtitleAnimator.start(); } } private void ensureSubtitleAnimatorTarget() { if (mSubtitleAnimator.getTarget() != null) { return; } TextView subtitleTextView; //noinspection TryWithIdenticalCatches try { Field subtitleTextViewField = Toolbar.class.getDeclaredField("mSubtitleTextView"); subtitleTextViewField.setAccessible(true); subtitleTextView = (TextView) subtitleTextViewField.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); return; } catch (IllegalAccessException e) { e.printStackTrace(); return; } if (subtitleTextView == null) { return; } // HACK: Prevent setText() from calling requestLayout() during animation which triggers // re-layout of the entire view hierarchy and breaks the ripple of BreadcrumbLayout. ViewUtils.setWidth(subtitleTextView, LayoutParams.MATCH_PARENT); mSubtitleAnimator.setTarget(subtitleTextView); } private class AnimatorListener extends AnimatorListenerAdapter implements ValueAnimator.AnimatorUpdateListener { private boolean mTextUpdated; @Override public void onAnimationUpdate(@NonNull ValueAnimator animator) { if (animator.getAnimatedFraction() < 0.5) { mTextUpdated = false; } else { ensureTextUpdated(); } } @Override public void onAnimationEnd(@NonNull Animator animator) { ensureTextUpdated(); if (mNextSubtitle != null) { mTextUpdated = false; animator.start(); } } private void ensureTextUpdated() { if (!mTextUpdated) { if (mNextSubtitle != null) { CrossfadeSubtitleToolbar.super.setSubtitle(mNextSubtitle); mNextSubtitle = null; } mTextUpdated = true; } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/CrossfadeSubtitleToolbar.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
828
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.text.Layout; import android.text.NoCopySpan; import android.text.Selection; import android.text.Spannable; import android.text.method.ArrowKeyMovementMethod; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; /** * @see LinkMovementMethod * @see ArrowKeyMovementMethod */ public class LinkArrowKeyMovementMethod extends ArrowKeyMovementMethod { private static final int CLICK = 1; private static final int UP = 2; private static final int DOWN = 3; private static final Object FROM_BELOW = new NoCopySpan.Concrete(); @Nullable private static LinkArrowKeyMovementMethod sInstance; @NonNull public static LinkArrowKeyMovementMethod getInstance() { if (sInstance == null) { sInstance = new LinkArrowKeyMovementMethod(); } return sInstance; } @Override public void initialize(@Nullable TextView widget, @NonNull Spannable text) { super.initialize(widget, text); text.removeSpan(FROM_BELOW); } @Override public void onTakeFocus(@NonNull TextView view, @NonNull Spannable text, int dir) { super.onTakeFocus(view, text, dir); if ((dir & View.FOCUS_BACKWARD) != 0) { text.setSpan(FROM_BELOW, 0, 0, Spannable.SPAN_POINT_POINT); } else { text.removeSpan(FROM_BELOW); } } @Override protected boolean handleMovementKey(@NonNull TextView widget, @NonNull Spannable buffer, int keyCode, int movementMetaState, @NonNull KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) { return true; } } break; } return super.handleMovementKey(widget, buffer, keyCode, movementMetaState, event); } @Override protected boolean up(@NonNull TextView widget, @NonNull Spannable buffer) { if (action(UP, widget, buffer)) { return true; } return super.up(widget, buffer); } @Override protected boolean down(@NonNull TextView widget, @NonNull Spannable buffer) { if (action(DOWN, widget, buffer)) { return true; } return super.down(widget, buffer); } @Override protected boolean left(@NonNull TextView widget, @NonNull Spannable buffer) { if (action(UP, widget, buffer)) { return true; } return super.left(widget, buffer); } @Override protected boolean right(@NonNull TextView widget, @NonNull Spannable buffer) { if (action(DOWN, widget, buffer)) { return true; } return super.right(widget, buffer); } private boolean action(int what, @NonNull TextView widget, @NonNull Spannable buffer) { Layout layout = widget.getLayout(); int padding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom(); int areaTop = widget.getScrollY(); int areaBot = areaTop + widget.getHeight() - padding; int lineTop = layout.getLineForVertical(areaTop); int lineBot = layout.getLineForVertical(areaBot); int first = layout.getLineStart(lineTop); int last = layout.getLineEnd(lineBot); ClickableSpan[] candidates = buffer.getSpans(first, last, ClickableSpan.class); int a = Selection.getSelectionStart(buffer); int b = Selection.getSelectionEnd(buffer); int selStart = Math.min(a, b); int selEnd = Math.max(a, b); if (selStart < 0) { if (buffer.getSpanStart(FROM_BELOW) >= 0) { selStart = selEnd = buffer.length(); } } if (selStart > last) selStart = selEnd = Integer.MAX_VALUE; if (selEnd < first) selStart = selEnd = -1; switch (what) { case CLICK: if (selStart == selEnd) { return false; } ClickableSpan[] link = buffer.getSpans(selStart, selEnd, ClickableSpan.class); if (link.length != 1) return false; link[0].onClick(widget); break; case UP: int bestStart, bestEnd; bestStart = -1; bestEnd = -1; for (int i = 0; i < candidates.length; i++) { int end = buffer.getSpanEnd(candidates[i]); if (end < selEnd || selStart == selEnd) { if (end > bestEnd) { bestStart = buffer.getSpanStart(candidates[i]); bestEnd = end; } } } if (bestStart >= 0) { Selection.setSelection(buffer, bestEnd, bestStart); return true; } break; case DOWN: bestStart = Integer.MAX_VALUE; bestEnd = Integer.MAX_VALUE; for (int i = 0; i < candidates.length; i++) { int start = buffer.getSpanStart(candidates[i]); if (start > selStart || selStart == selEnd) { if (start < bestStart) { bestStart = start; bestEnd = buffer.getSpanEnd(candidates[i]); } } } if (bestEnd < Integer.MAX_VALUE) { Selection.setSelection(buffer, bestStart, bestEnd); return true; } break; } return false; } @Override public boolean onTouchEvent(@NonNull TextView widget, @NonNull Spannable buffer, @NonNull MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); Layout layout = widget.getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); ClickableSpan[] links = buffer.getSpans(off, off, ClickableSpan.class); if (links.length != 0) { if (action == MotionEvent.ACTION_UP) { links[0].onClick(widget); } else if (action == MotionEvent.ACTION_DOWN) { Selection.setSelection(buffer, buffer.getSpanStart(links[0]), buffer.getSpanEnd(links[0])); } return true; } // Removed //else { // Selection.removeSelection(buffer); //} } return super.onTouchEvent(widget, buffer, event); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/LinkArrowKeyMovementMethod.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,540
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatTextView; import android.text.TextUtils; import android.util.AttributeSet; import me.zhanghai.android.douya.util.ViewUtils; /** * TextView that automatically sets its visibility to View.GONE when empty. */ public class AutoGoneTextView extends AppCompatTextView { public AutoGoneTextView(@NonNull Context context) { super(context); } public AutoGoneTextView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public AutoGoneTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void setText(@Nullable CharSequence text, @NonNull BufferType type) { super.setText(text, type); ViewUtils.setVisibleOrGone(this, !TextUtils.isEmpty(text)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/AutoGoneTextView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
209
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import android.os.Build; import android.util.AttributeSet; import android.view.WindowInsets; import android.widget.FrameLayout; public class PassWindowInsetsFrameLayout extends FrameLayout { public PassWindowInsetsFrameLayout(@NonNull Context context) { super(context); } public PassWindowInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public PassWindowInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public PassWindowInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @NonNull @Override public WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { return insets; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/PassWindowInsetsFrameLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
231
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; public class LayerDrawableCompat extends LayerDrawable { public LayerDrawableCompat(Drawable[] layers) { super(layers); } @Override public boolean isStateful() { for (int i = 0, size = getNumberOfLayers(); i < size; ++i) { if (getDrawable(i).isStateful()) { return true; } } return false; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/LayerDrawableCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
120
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.viewpager.widget.PagerAdapter; public abstract class ViewPagerAdapter extends PagerAdapter { @NonNull @Override public final View instantiateItem(@NonNull ViewGroup container, int position) { return onCreateView(container, position); } @NonNull protected abstract View onCreateView(@NonNull ViewGroup container, int position); @Override public final void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { View view = (View) object; onDestroyView(container, position, view); container.removeView(view); } protected abstract void onDestroyView(@NonNull ViewGroup container, int position, @NonNull View view); @Override public final boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @Override public final int getItemPosition(@NonNull Object object) { View view = (View) object; return getViewPosition(view); } protected int getViewPosition(@NonNull View view) { return POSITION_UNCHANGED; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ViewPagerAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
257
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.viewpager.widget.ViewPager; import android.util.AttributeSet; import android.view.View; public class WrapContentHeightViewPager extends ViewPager { public WrapContentHeightViewPager(Context context) { super(context); } public WrapContentHeightViewPager(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = 0; for (int i = 0, count = getChildCount(); i < count; ++i) { View child = getChildAt(i); child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int childHeight = child.getMeasuredHeight(); if (childHeight > height) { height = childHeight; } } heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/WrapContentHeightViewPager.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
221
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.os.Bundle; import android.os.Parcelable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.collection.ArrayMap; import androidx.collection.SparseArrayCompat; import androidx.viewpager.widget.PagerAdapter; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; public abstract class ViewStatePagerAdapter extends PagerAdapter { private static final String KEY_PREFIX = ViewStatePagerAdapter.class.getName() + '.'; private static final String STATE_VIEW_STATES_SIZE = KEY_PREFIX + "VIEW_STATES_SIZE"; private static final String STATE_VIEW_STATE_PREFIX = KEY_PREFIX + "VIEW_STATE_"; @NonNull private final SparseArrayCompat<View> mViews = new SparseArrayCompat<>(); @NonNull private final ArrayMap<String, SparseArray<Parcelable>> mViewStates = new ArrayMap<>(); @NonNull @Override public final View instantiateItem(@NonNull ViewGroup container, int position) { View view = onCreateView(container, position); restoreViewState(position, view); mViews.put(position, view); return view; } @NonNull protected abstract View onCreateView(@NonNull ViewGroup container, int position); @Override public final void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { View view = (View) object; saveViewState(position, view); onDestroyView(container, position, view); mViews.remove(position); container.removeView(view); } protected abstract void onDestroyView(@NonNull ViewGroup container, int position, @NonNull View view); @Override public final boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @Override public final int getItemPosition(@NonNull Object object) { View view = (View) object; return getViewPosition(view); } protected int getViewPosition(@NonNull View view) { return POSITION_UNCHANGED; } @NonNull @Override public Parcelable saveState() { mViewStates.clear(); for (int i = 0, size = mViews.size(); i < size; ++i) { saveViewState(mViews.keyAt(i), mViews.valueAt(i)); } Bundle bundle = new Bundle(); int size = mViewStates.size(); bundle.putInt(STATE_VIEW_STATES_SIZE, size); for (int i = 0; i < size; ++i) { bundle.putSparseParcelableArray(mViewStates.keyAt(i), mViewStates.valueAt(i)); } return bundle; } @Override public void restoreState(@NonNull Parcelable state, @Nullable ClassLoader loader) { Bundle bundle = (Bundle) state; bundle.setClassLoader(loader); int size = bundle.getInt(STATE_VIEW_STATES_SIZE); for (int i = 0; i < size; ++i) { String key = getViewStateKey(i); SparseArray<Parcelable> viewState = bundle.getSparseParcelableArray(key); mViewStates.put(key, viewState); } } private void saveViewState(int position, @NonNull View view) { String key = getViewStateKey(position); SparseArray<Parcelable> viewState = new SparseArray<>(); view.saveHierarchyState(viewState); mViewStates.put(key, viewState); } private void restoreViewState(int position, @NonNull View view) { String key = getViewStateKey(position); SparseArray<Parcelable> viewState = mViewStates.get(key); if (viewState != null) { view.restoreHierarchyState(viewState); } } @NonNull private String getViewStateKey(int position) { return STATE_VIEW_STATE_PREFIX + getViewStateKeySuffix(position); } @NonNull protected String getViewStateKeySuffix(int position) { return Integer.toString(position); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ViewStatePagerAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
820
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.recyclerview.widget.RecyclerView; import android.view.View; import java.util.List; public abstract class LongClickableSimpleAdapter<T, VH extends RecyclerView.ViewHolder> extends ClickableSimpleAdapter<T, VH> { private OnItemLongClickListener<T> mOnItemLongClickListener; private RecyclerView mRecyclerView; public LongClickableSimpleAdapter() {} public LongClickableSimpleAdapter(List<T> list, OnItemClickListener<T> onItemClickListener, OnItemLongClickListener<T> onItemLongClickListener) { super(list, onItemClickListener); mOnItemLongClickListener = onItemLongClickListener; } public OnItemLongClickListener<T> getOnItemLongClickListener() { return mOnItemLongClickListener; } public void setOnItemLongClickListener(OnItemLongClickListener<T> onItemLongClickListener) { mOnItemLongClickListener = onItemLongClickListener; } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); mRecyclerView = recyclerView; } @Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { super.onDetachedFromRecyclerView(recyclerView); mRecyclerView = null; } @Override public void onBindViewHolder(final VH holder, int position, List<Object> payloads) { super.onBindViewHolder(holder, position, payloads); T item = getItem(position); holder.itemView.setOnLongClickListener(view -> { if (mOnItemLongClickListener == null) { return false; } return mOnItemLongClickListener.onItemLongClick(mRecyclerView, holder.itemView, item, holder.getAdapterPosition()); }); } public interface OnItemLongClickListener<T> { boolean onItemLongClick(RecyclerView parent, View itemView, T item, int position); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/LongClickableSimpleAdapter.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
392
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.transitionseverywhere.Transition; import com.transitionseverywhere.TransitionValues; public class CrossfadeText extends Transition { private static final String PROPNAME_TEXT = "android:crossfadeText:text"; public CrossfadeText() {} public CrossfadeText(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void captureStartValues(TransitionValues transitionValues) { captureValues(transitionValues); } @Override public void captureEndValues(TransitionValues transitionValues) { captureValues(transitionValues); } private void captureValues(TransitionValues transitionValues) { if (!(transitionValues.view instanceof TextView)) { throw new IllegalArgumentException("Target should be a TextView instead of " + transitionValues.view.getClass().getName()); } TextView view = (TextView) transitionValues.view; transitionValues.values.put(PROPNAME_TEXT, view.getText()); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { TextView view = (TextView) startValues.view; CharSequence startText = (CharSequence) startValues.values.get(PROPNAME_TEXT); CharSequence endText = (CharSequence) endValues.values.get(PROPNAME_TEXT); view.setText(startText); ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1, 0, 1); AnimatorListener listener = new AnimatorListener(view, endText); animator.addListener(listener); animator.addUpdateListener(listener); return animator; } private class AnimatorListener extends AnimatorListenerAdapter implements ValueAnimator.AnimatorUpdateListener { private TextView mTextView; private CharSequence mEndText; private boolean mTextUpdated; public AnimatorListener(TextView textView, CharSequence endText) { mTextView = textView; mEndText = endText; } @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { if (valueAnimator.getAnimatedFraction() >= 0.5) { ensureTextUpdated(); } } @Override public void onAnimationEnd(Animator animation) { ensureTextUpdated(); } private void ensureTextUpdated() { if (!mTextUpdated) { mTextView.setText(mEndText); mTextUpdated = true; } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/CrossfadeText.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
565
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.app.Dialog; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; import me.zhanghai.android.douya.R; public class ConfirmDiscardContentDialogFragment extends AppCompatDialogFragment { /** * @deprecated Use {@link #newInstance()} instead. */ public ConfirmDiscardContentDialogFragment() {} public static ConfirmDiscardContentDialogFragment newInstance() { //noinspection deprecation return new ConfirmDiscardContentDialogFragment(); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity(), getTheme()) .setMessage(R.string.confirm_close_discarding_content) .setPositiveButton(R.string.discard, (dialog, which) -> getListener().discardContent()) .setNegativeButton(R.string.keep_editing, null) .create(); } private Listener getListener() { return (Listener) getParentFragment(); } public static void show(Fragment fragment) { ConfirmDiscardContentDialogFragment.newInstance() .show(fragment.getChildFragmentManager(), null); } public interface Listener { void discardContent(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/ConfirmDiscardContentDialogFragment.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
274
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; import android.util.AttributeSet; /** * Fixes setAdjustViewBounds() and onMeasure() not respecting minimum sizes when adjusting view * bounds. */ public class AdjustViewBoundsImageView extends AppCompatImageView { public AdjustViewBoundsImageView(Context context) { super(context); } public AdjustViewBoundsImageView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public AdjustViewBoundsImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void setAdjustViewBounds(boolean adjustViewBounds) { ScaleType scaleType = getScaleType(); super.setAdjustViewBounds(adjustViewBounds); setScaleType(scaleType); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int measuredWidth = getMeasuredWidth(); int width = Math.max(measuredWidth, getSuggestedMinimumWidth()); int measuredHeight = getMeasuredHeight(); int height = Math.max(measuredHeight, getSuggestedMinimumHeight()); if (measuredWidth != width || measuredHeight != height) { setMeasuredDimension(width, height); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/AdjustViewBoundsImageView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
295
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import androidx.recyclerview.widget.RecyclerView; public abstract class OnVerticalScrollListener extends RecyclerView.OnScrollListener { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (!recyclerView.canScrollVertically(-1)) { onScrolledToTop(); } else if (!recyclerView.canScrollVertically(1)) { onScrolledToBottom(); } if (dy < 0) { onScrolledUp(dy); } else if (dy > 0) { onScrolledDown(dy); } onScrolled(dy); } public void onScrolled(int dy) {} public void onScrolledUp(int dy) {} public void onScrolledDown(int dy) {} public void onScrolledToTop() {} public void onScrolledToBottom() {} } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/OnVerticalScrollListener.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
200
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import androidx.recyclerview.widget.RecyclerView; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; /** * RecyclerView always returns true for its {@link RecyclerView#onTouchEvent(MotionEvent)}. This * subclass passes the same touch event up to it's parent view and cancels if user starts dragging. */ public class DispatchTouchEventToParentNestedRecyclerView extends NestedRecyclerView { public DispatchTouchEventToParentNestedRecyclerView(Context context) { super(context); } public DispatchTouchEventToParentNestedRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public DispatchTouchEventToParentNestedRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if (getScrollState() != SCROLL_STATE_DRAGGING) { ((View) getParent()).onTouchEvent(event); } else { int oldAction = event.getAction(); event.setAction(MotionEvent.ACTION_CANCEL | (oldAction & ~MotionEvent.ACTION_MASK)); ((View) getParent()).onTouchEvent(event); event.setAction(oldAction); } return true; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/DispatchTouchEventToParentNestedRecyclerView.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
270
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.animation.Animator; import android.animation.ObjectAnimator; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.stateful.ExtendableSavedState; import androidx.interpolator.view.animation.FastOutLinearInInterpolator; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.ViewGroup; import butterknife.BindInt; import butterknife.ButterKnife; import me.zhanghai.android.douya.util.BundleBuilder; import me.zhanghai.android.douya.util.ViewUtils; public class FriendlyFloatingActionButton extends FloatingActionButton { private static final String EXTENDABLE_STATE_KEY = FriendlyFloatingActionButton.class.getName(); private static final String STATE_KEY_SHOWING = "SHOWING"; @BindInt(android.R.integer.config_shortAnimTime) int mAnimationDuration; private boolean mShowing = true; private Animator mAnimator; public FriendlyFloatingActionButton(Context context) { super(context); init(); } public FriendlyFloatingActionButton(Context context, AttributeSet attrs) { super(context, attrs); init(); } public FriendlyFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { ButterKnife.bind(this); } @Override protected Parcelable onSaveInstanceState() { ExtendableSavedState state = (ExtendableSavedState) super.onSaveInstanceState(); state.extendableStates.put(EXTENDABLE_STATE_KEY, new BundleBuilder() .putBoolean(STATE_KEY_SHOWING, mShowing) .build()); return state; } @Override protected void onRestoreInstanceState(Parcelable state) { super.onRestoreInstanceState(state); ExtendableSavedState extendableSavedState = (ExtendableSavedState) state; Bundle extendableState = extendableSavedState.extendableStates.get(EXTENDABLE_STATE_KEY); boolean showing = extendableState.getBoolean(STATE_KEY_SHOWING); if (!showing) { hideImmediately(); } } public void hide() { if (!mShowing) { return; } mShowing = false; cancelAnimator(); mAnimator = ObjectAnimator.ofFloat(this, TRANSLATION_Y, getTranslationY(), getHideTranslationY()) .setDuration(mAnimationDuration); mAnimator.setInterpolator(new FastOutLinearInInterpolator()); mAnimator.start(); } public void hideImmediately() { if (!mShowing) { return; } float hideTranslationY = getHideTranslationY(); if (hideTranslationY != 0) { mShowing = false; setTranslationY(hideTranslationY); } else { ViewUtils.postOnPreDraw(this, new Runnable() { @Override public void run() { hideImmediately(); } }); } } private int getHideTranslationY() { return ((ViewGroup) getParent()).getHeight() - getTop(); } public void show() { if (mShowing) { return; } mShowing = true; cancelAnimator(); mAnimator = ObjectAnimator.ofFloat(this, TRANSLATION_Y, getTranslationY(), 0) .setDuration(mAnimationDuration); mAnimator.setInterpolator(new FastOutSlowInInterpolator()); mAnimator.start(); } public void showImmediately() { if (mShowing) { return; } mShowing = true; setTranslationY(0); } private void cancelAnimator() { if (mAnimator != null) { mAnimator.cancel(); mAnimator = null; } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/FriendlyFloatingActionButton.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
798
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import androidx.annotation.AttrRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.StyleRes; import androidx.appcompat.content.res.AppCompatResources; import androidx.recyclerview.widget.RecyclerView; import android.util.AttributeSet; import android.widget.LinearLayout; import me.zhanghai.android.douya.util.ViewUtils; public class AdapterGridLinearLayout extends AdapterLinearLayout { private int mColumnCount = 1; private Drawable mHorizontalDivider; public AdapterGridLinearLayout(@NonNull Context context) { super(context); } public AdapterGridLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public AdapterGridLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public AdapterGridLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public int getColumnCount() { return mColumnCount; } public void setColumnCount(int columnCount) { if (mColumnCount != columnCount) { mColumnCount = columnCount; onDataSetChanged(); } } public void setHorizontalDivider(@DrawableRes int dividerRes) { mHorizontalDivider = AppCompatResources.getDrawable(getContext(), dividerRes); } @Override protected void onDataSetChanged() { if (mAdapter == null) { return; } removeAllViews(); for (int rowPosition = 0, count = mAdapter.getItemCount(); rowPosition < count; rowPosition += mColumnCount) { LinearLayout rowLayout = new LinearLayout(getContext()); if (mHorizontalDivider != null) { rowLayout.setDividerDrawable(mHorizontalDivider); rowLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); } for (int position = rowPosition, nextRowPosition = rowPosition + mColumnCount; position < nextRowPosition && position < count; ++position) { int viewType = mAdapter.getItemViewType(position); RecyclerView.ViewHolder holder = mAdapter.createViewHolder(rowLayout, viewType); //noinspection unchecked mAdapter.bindViewHolder(holder, position); ViewUtils.setWeight(holder.itemView, 1); rowLayout.addView(holder.itemView); } LayoutParams rowLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); addView(rowLayout, rowLayoutParams); } } @Override protected void onItemRangeChanged(int positionStart, int itemCount) { throw new UnsupportedOperationException(); } @Override protected void onItemRangeInserted(int positionStart, int itemCount) { throw new UnsupportedOperationException(); } @Override protected void onItemRangeRemoved(int positionStart, int itemCount) { throw new UnsupportedOperationException(); } @Override protected void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { throw new UnsupportedOperationException(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/ui/AdapterGridLinearLayout.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
684