Android简明开发教程十八:自定义对话框 Transform

【我的Android开发】之Transform实现自动化业务处理流程 Transform的机制基于Gradle插件的Transform API,在打包构建过程中插件通过该API提供一个Transform来拦截原始的class文件和资源,对其进行处理并返回给Gradle插件。在应用构建过程中,Gradle编译器将会遍历所有的Transform,将应用程序输出的字节码和资源递交给每个Transform进行处理,并将处理结果提交到后续Transform进行处理。首先,需要梳理出需要自动化的具体业务处理流程,明确每个步骤的输入、输出、执行方式和要求等等。 阅读详情

Android自带的AlertDialog,ProgressDialog,DatePickerDialog,TimePickerDialog 可以用于简单的对话框显示。当还是有这些对话框不能满足应用需要的时候,这时就可以使用一些自定义的对话框。有多种方法可以实现自定义对话框。一是使用Activity作为Dialog,可以通过设置Activity显示Dialog风格,使得该Activity在外观上和Dialog一致:显示在其它Activity前面且半透明。 

<Activity android:name=”MyDialogActivity” Android:theme=”@android:style/Theme.Dialog“></Activity> 

本例采用另外两种方法来使用自定义对话框,将用这个对话框来最为图形变换(Transform)的选项: 

Primitive: Rectange, Ellipse,Text
Pen: Thin,Thick,Dashed
Brush: Solid, Gradient,Texture
Transform: Identity, Rotate, Scale, Shear
Rendering: Stroke, Fill, Stoke and Fill 

 首先在res/layout 下新建transformoption.xml 作为自定义对话框布局: 

<?xml version=”1.0″ encoding=”utf-8″?> 

<LinearLayout
  xmlns:android=”http://schemas.android.com/apk/res/android”
  android:layout_width=”fill_parent”
  android:layout_height=”fill_parent” 

  >
<ScrollView
  android:layout_width=”fill_parent”
  android:layout_height=”fill_parent”>
<LinearLayout
  android:layout_width=”fill_parent”
  android:layout_height=”fill_parent”
  android:orientation=”vertical”
  >
<TextView
   android:text=”Primitive”
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”>
 </TextView>
 <RadioGroup
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”> 

<RadioButton
android:text=”Rectangle”
android:id=”@+id/radioRectangle”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Ellipse”
android:id=”@+id/radioEllipse”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Text”
android:id=”@+id/radioText”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
 </RadioGroup> 

<TextView
   android:text=”Pen”
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”>
 </TextView>
 <RadioGroup
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”> 

<RadioButton
android:text=”Thin”
android:id=”@+id/radioThin”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Thick”
android:id=”@+id/radioThick”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Dashed”
android:id=”@+id/radioDashed”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
 </RadioGroup>
 
<TextView
   android:text=”Brush”
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”>
 </TextView>
 <RadioGroup
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”> 

<RadioButton
android:text=”Solid”
android:id=”@+id/radioSolid”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Gradient”
android:id=”@+id/radioGradient”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Texture”
android:id=”@+id/radioTexture”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
 </RadioGroup>
 
 <TextView
   android:text=”Transform”
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”>
 </TextView>
 <RadioGroup
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”> 

<RadioButton
android:text=”Identity”
android:id=”@+id/radioIdentity”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Rotate”
android:id=”@+id/radioRotate”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Scale”
android:id=”@+id/radioScale”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Shear”
android:id=”@+id/radioShear”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
 </RadioGroup>
 
 <TextView
   android:text=”Rendering”
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”>
 </TextView>
 <RadioGroup
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”> 

<RadioButton
android:text=”Stroke”
android:id=”@+id/radioStroke”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Fill”
android:id=”@+id/radioFill”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
<RadioButton
android:text=”Stroke and Fill”
android:id=”@+id/radioStrokeFill”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</RadioButton>
 </RadioGroup>
 </LinearLayout>
</ScrollView>
</LinearLayout> 

 一种方法是重新定制AlertDialog ,基本步骤和Android简明开发教程十七:Dialog 显示图像类似,但是在protected Dialog onCreateDialog(int id) ,需要重新设定Dialog的Content View并给RadioButton添加事件处理: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
protected Dialog onCreateDialog( int id) {
  final Dialog dialog;
  switch (id) {
  case OPTION_DIALOG:
   LayoutInflater li
     = LayoutInflater.from( this );
   View optionView
     = li.inflate(R.layout.transformoption, null );
   AlertDialog.Builder optionDialog
     = new AlertDialog.Builder( this );
   optionDialog.setTitle( "Options" );
   optionDialog.setView(optionView);
   dialog = optionDialog.create();
   RadioButton button = (RadioButton) optionView
     .findViewById(R.id.radioRectangle);
   button.setOnClickListener( new Button.OnClickListener() { 
  
    public void onClick(View v) {
     primitiveIndex = PRIMITIVE_RECTANGLE;
     drawImage();
     dialog.dismiss(); 
  
    }
   });
    
   ... 
  
   button = (RadioButton) optionView
     .findViewById(R.id.radioStrokeFill);
   button.setOnClickListener( new Button.OnClickListener() { 
  
    public void onClick(View v) {
     renderingIndex = RENDERING_STROKE_AND_FILL;
     drawImage();
     dialog.dismiss(); 
  
    }
   });
   return dialog;
  } 
  
  return null ; 
  
}

第二种是通过派生Dialog ,定义了一个OptionDialog类作为Dialog子类。 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class OptionDialog extends Dialog { 
  
  public OptionDialog(Context context) {
   super (context);
   // TODO Auto-generated constructor stub
  }
    
  protected void onCreate(Bundle savedInstanceState) {
   super .onCreate(savedInstanceState);
   setContentView(R.layout.transformoption);
   setTitle( "Options" );
   RadioButton button
      = (RadioButton) findViewById(R.id.radioRectangle);
   button.setOnClickListener( new Button.OnClickListener() { 
  
    public void onClick(View v) {
     primitiveIndex = PRIMITIVE_RECTANGLE;
     drawImage();
     dismiss(); 
  
    }
   });
   ...
   button = (RadioButton) findViewById(R.id.radioStrokeFill);
   button.setOnClickListener( new Button.OnClickListener() { 
  
    public void onClick(View v) {
     renderingIndex = RENDERING_STROKE_AND_FILL;
     drawImage();
     dismiss(); 
  
    }
   });
  } 
  
}

这两种方法在显示Dialog时有所不同: 

1
2
3
4
5
6
7
8
9
10
11
12
13
private OptionDialog optionDialog;
static final private int OPTION_DIALOG = 1 ;
  
...
optionDialog = new OptionDialog( this );
  
...
@Override
public void onClick(View view) {
  // optionDialog.show();
  showDialog(OPTION_DIALOG);
  
}

下面是完整代码: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
public class Transform extends Graphics2DActivity
   implements OnClickListener { 
  
  static int PRIMITIVE_RECTANGLE = 0 ;
  static int PRIMITIVE_ELLIPSE = 1 ;
  static int PRIMITIVE_TEXT = 2 ;
  static int PEN_THIN = 0 ;
  static int PEN_THICK = 1 ;
  static int PEN_DASHED = 2 ;
  static int BRUSH_SOLID = 0 ;
  static int BRUSH_GRADIENT = 1 ;
  static int BRUSH_TEXTURE = 2 ;
  static int TRANSFORM_IDENTITY = 0 ;
  static int TRANSFORM_ROTATE = 1 ;
  static int TRANSFORM_SCALE = 2 ;
  static int TRANSFORM_SHEAR = 3 ;
  static int RENDERING_STROKE = 0 ;
  static int RENDERING_FILL = 1 ;
  static int RENDERING_STROKE_AND_FILL = 2 ;
  int primitiveIndex;
  int penIndex;
  int brushIndex;
  int transformIndex;
  int renderingIndex;
  int [] rgbData;
  int bitmapWidth;
  int bitmapHeight; 
  
  class OptionDialog extends Dialog { 
  
   public OptionDialog(Context context) {
    super (context);
    // TODO Auto-generated constructor stub
   } 
  
   protected void onCreate(Bundle savedInstanceState) {
    super .onCreate(savedInstanceState);
    setContentView(R.layout.transformoption);
    setTitle( "Options" );
    RadioButton button
       = (RadioButton) findViewById(R.id.radioRectangle);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_RECTANGLE;
      drawImage();
      dismiss(); 
  
     }
    });
    button = (RadioButton) findViewById(R.id.radioEllipse);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_ELLIPSE;
      drawImage();
      dismiss(); 
  
     }
    });
    button = (RadioButton) findViewById(R.id.radioText);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_TEXT;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioThin);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_THIN;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioThick);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_THICK;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioDashed);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_DASHED;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioSolid);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_SOLID;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioGradient);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_GRADIENT;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioTexture);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_TEXTURE;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioIdentity);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_IDENTITY;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioRotate);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_ROTATE;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioScale);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_SCALE;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioShear);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_SHEAR;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioStroke);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_STROKE;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioFill);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_FILL;
      drawImage();
      dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) findViewById(R.id.radioStrokeFill);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_STROKE_AND_FILL;
      drawImage();
      dismiss(); 
  
     }
    });
   } 
  
  } 
  
  private OptionDialog optionDialog;
  private Button btnOptions; 
  
  static final private int OPTION_DIALOG = 1 ; 
  
  private AffineTransform at = new AffineTransform();
  private int w, h;
  private IShape shapes[] = new IShape[ 3 ]; 
  
  private boolean firstTime = true ;
  private FontEx font = FontEx.getSystemFont(); 
  
  @Override
  protected void drawImage() {
   drawTransform(); 
  
  } 
  
  protected Dialog onCreateDialog( int id) {
   final Dialog dialog;
   switch (id) {
   case OPTION_DIALOG:
    LayoutInflater li
      = LayoutInflater.from( this );
    View optionView
      = li.inflate(R.layout.transformoption, null );
    AlertDialog.Builder optionDialog
      = new AlertDialog.Builder( this );
    optionDialog.setTitle( "Options" );
    optionDialog.setView(optionView);
    dialog = optionDialog.create();
    RadioButton button = (RadioButton) optionView
      .findViewById(R.id.radioRectangle);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_RECTANGLE;
      drawImage();
      dialog.dismiss(); 
  
     }
    });
    button = (RadioButton)
        optionView.findViewById(R.id.radioEllipse);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_ELLIPSE;
      drawImage();
      dialog.dismiss(); 
  
     }
    });
    button = (RadioButton)
      optionView.findViewById(R.id.radioText);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      primitiveIndex = PRIMITIVE_TEXT;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
       optionView.findViewById(R.id.radioThin);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_THIN;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
       optionView.findViewById(R.id.radioThick);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_THICK;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioDashed);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      penIndex = PEN_DASHED;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioSolid);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_SOLID;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioGradient);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_GRADIENT;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioTexture);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      brushIndex = BRUSH_TEXTURE;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioIdentity);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_IDENTITY;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioRotate);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_ROTATE;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioScale);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_SCALE;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
       optionView.findViewById(R.id.radioShear);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      transformIndex = TRANSFORM_SHEAR;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioStroke);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_STROKE;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton)
        optionView.findViewById(R.id.radioFill);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_FILL;
      drawImage();
      dialog.dismiss(); 
  
     }
    }); 
  
    button = (RadioButton) optionView
      .findViewById(R.id.radioStrokeFill);
    button.setOnClickListener( new Button.OnClickListener() { 
  
     public void onClick(View v) {
      renderingIndex = RENDERING_STROKE_AND_FILL;
      drawImage();
      dialog.dismiss(); 
  
     }
    });
    return dialog;
   } 
  
   return null ; 
  
  } 
  
  public void onCreate(Bundle savedInstanceState) {
   super .onCreate(savedInstanceState);
   setContentView(R.layout.transform);
   graphic2dView = (GuidebeeGraphics2DView)
      findViewById(R.id.graphics2dview);
   btnOptions = (Button) findViewById(R.id.btnOption);
   btnOptions.setOnClickListener( this );
   shapes[ 0 ] = new Rectangle( 0 , 0 , 100 , 100 );
   shapes[ 1 ] = new Ellipse( 0 , 0 , 100 , 100 );
   IShape[] fontShapes = font.getGlyphArray( 96 ,
          "TEXT" .toCharArray(), 0 ,
     4 , FontEx.TEXT_DIR_LR);
   shapes[ 2 ] = new Area(fontShapes[ 0 ]);
   for ( int i = 1 ; i < fontShapes.length; i++) {
    ((Area) shapes[ 2 ]).add( new Area(fontShapes[i]));
   }
   Bitmap bitmap = BitmapFactory.decodeResource(
           getResources(),
     R.drawable.brick);
   bitmapWidth = bitmap.getWidth();
   bitmapHeight = bitmap.getHeight(); 
  
   rgbData = new int [bitmapWidth * bitmapHeight];
   bitmap.getPixels(rgbData, 0 , bitmapWidth, 0 , 0 ,
      bitmapWidth,
     bitmapHeight);
   w = SharedGraphics2DInstance.CANVAS_WIDTH;
   h = SharedGraphics2DInstance.CANVAS_HEIGHT;
   optionDialog = new OptionDialog( this ); 
  
  } 
  
  private void setTrans( int transIndex) {
   // Sets the AffineTransform.
   switch (transIndex) {
   case 0 :
    at.setToIdentity();
    at.translate(w / 2 , h / 2 );
    break ;
   case 1 :
    at.rotate(Math.toRadians( 45 ));
    break ;
   case 2 :
    at.scale( 0.5 , 0.5 );
    break ;
   case 3 :
    at.shear( 0.5 , 0.0 );
    break ;
   }
  } 
  
  private void drawTransform() {
   graphics2D.clear(Color.WHITE);
   graphics2D.Reset();
   setTrans(transformIndex);
   graphics2D.setAffineTransform(at); 
  
   // Initialize the transform.
   if (firstTime) {
    at.setToIdentity();
    at.translate(w / 2 , h / 2 ); 
  
    firstTime = false ;
   } 
  
   // Sets the Stroke.
   Pen pen = null ; 
  
   switch (penIndex) {
   case 0 :
    pen = new Pen(Color.BLACK, 1 );
    break ;
   case 1 :
    pen = new Pen(Color.BLACK, 8 );
    break ;
   case 2 : {
    int dash[] = { 10 , 10 };
    pen = new Pen(Color.BLACK, 1 , Pen.CAP_BUTT,
      Pen.JOIN_MITER, dash, 0 );
   }
    break ;
   } 
  
   // Sets the Paint.
   Brush brush = null ; 
  
   switch (brushIndex) {
   case 0 :
    brush = new SolidBrush(Color.BLUE);
    break ;
   case 1 : {
    int [] fractions = new int [] { 13 , 242 };
    Color[] colors = new Color[] { new Color( 0xffff6600 ),
      new Color( 0xffffff66 ) };
    brush = new LinearGradientBrush( 50 , 50 , 150 ,
      125 , fractions,
      colors, Brush.REPEAT);
   } 
  
    break ;
   case 2 :
    try { 
  
     brush = new TextureBrush(rgbData,
       bitmapWidth, bitmapHeight);
    } catch (Exception e) {
    }
    break ;
   } 
  
   // Sets the Shape.
   IShape shape = shapes[primitiveIndex];
   Rectangle r = shape.getBounds();
   AffineTransform toCenterAt = new AffineTransform();
   toCenterAt.concatenate(at);
   toCenterAt.translate(-(r.width / 2 ), -(r.height / 2 )); 
  
   graphics2D.setAffineTransform(toCenterAt);
   // Sets the rendering method.
   switch (renderingIndex) {
   case 0 :
    graphics2D.setDefaultPen(pen);
    graphics2D.draw( null , shape);
    break ;
   case 1 :
    graphics2D.setDefaultBrush(brush);
    graphics2D.fill( null , shape);
    break ;
   case 2 :
    graphics2D.setPenAndBrush(pen, brush);
    graphics2D.fill( null , shape);
    graphics2D.draw( null , shape);
    break ;
   }
   graphic2dView.refreshCanvas(); 
  
  } 
  
  @Override
  public void onClick(View view) {
   // optionDialog.show();
   showDialog(OPTION_DIALOG); 
  
  }
}

上面代码中包含了两种方法的代码,实际应用中可以任选其一。
Android代码-变化过度效果的 Dialog Box,动画效果很棒。 Morphing Material Dialogs A library for fab-to-dialog morphing (as in Nick Butcher's Plaid) with Aidan Follestad's Material Dialogs. Table of Contents Setup Instructions Usage Instructions Customization Misc Setup Instructions Add the following to your root (project) level build.gradle: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } Add the library to your app's build.gradle dependencies { implementation 'c 立即下载

相关推荐

xlinx项目系列之基于zynq-7020ISP图像处理

本Demo基于zynq-7020(正点原子启明星+OV5640+4.3'800x480)实现了ISP图像处理(将ov5640的isp关闭,在7020上实现ISP功能),输出到LCD和HDMI,软件基于SDK裸机开发,2592x1944@15fp。位置: xil_ip_repo/xil_isp_lite_1.0。项目获取链接:2.基于zynq-7020实现ISP图像处理。位置: xil_ip_repo/xil_vip_1.0。

JY6669991010的博客 2637

android窗口动画和过渡动画(activity和dialog)

from:http://blog.sina.com.cn/s/blog_ba23fa6f0102v32g.html 窗口动画和过渡动画是指在窗口(activity或dialog)切换时的显示动画,窗口动画的范围相对较广,包括activity和dialog,而过渡动画只包括activity。 第一种方法是调用overridePendingTransition的方法,记得要在startActivi...

djzhao的专栏 1万+

10分钟上手YOLOv11:最强姿态估计模型来了,代码开源,效果炸裂!

【10分钟玩转YOLOv11实时姿态估计】🚀 YOLOv11作为YOLO家族最新成员,在速度、精度和易用性上全面升级,尤其适用于姿态估计等复杂视觉任务。本文带您快速掌握: 1️⃣ 核心概念:姿态估计即识别人体17个关键点(如关节部位)并连接成数字骨架,是智能健身、体感游戏等应用的基础。 2️⃣ 技术优势: 超轻量级(最小仅2.9M参数) 极速推理(GPU仅1.7ms) 高精度(COCO mAP@50-95达50%) 3️⃣ 三步实操: ① 安装:pip install ultralytics ② 准备人物

weixin_41246802的博客 1790

android 同根动画_Android Transition(Android过渡动画)

在Android 4.4 Transition 就已经引入了,但在Android 5.0(API 21)之后,Transition 被更多的应用起来。相对于View Animation或Property Animator,Transition动画更加具有特殊性,Transition可以看作对Property Animator的高度封装。不同于Animator,Transition动画具有视觉连续性...

weixin_39922374的博客 515

基于STM32的家用新风系统智能控制器 | 保姆式教程 开源可复刻

本项目基于STM32F103C8T6核心控制器,完整实现了家用新风系统智能控制器的全功能开发,覆盖多传感器数据采集、双模式控制、PID调速、异常报警、掉电记忆等核心功能,全程采用保姆式无跳步教学,从硬件选型、接线、CubeMX配置、代码开发、调试排坑全流程拆解,跟着步骤一步步操作,就能顺利完成项目复刻

ZhongWeiXiang9的博客 471

Qwen3-VL、Qwen3-Next与Qwen3.5多模态架构深度解剖

多模态大模型的核心不在参数规模,而在于视觉与文本如何协同建模。本文从基础概念切入,解析视觉语言模型中视觉编码器、跨模态注意力、特征对齐与token压缩等关键原理;阐述ViT、CLIP-ViT及动态压缩模块(HDTC)在语义表征、空间感知与计算效率上的技术权衡;强调结构设计如何决定模型在医学影像、工业质检、遥感分析等高要求场景中的真实能力边界;最终聚焦通义千问最新三套VL架构——Qwen3-VL、Qwen3-Next与Qwen3.5——揭示其背后迥异的融合哲学与工程取舍,为选型、微调与推理优化提供底层依据。

weixin_33778544的博客 818

android转场动画&共享元素&另外一种动画Transition

动画发展史:  从API 1就存在的Drawable Animation和View Animation,以及API 11(Android 3.0)以后加入的Property Animation。而过渡动画Transition是在API 19(Android 4.4.2)中加入  的。

musk6的博客 1900

别再纠结了!车规MCU选M7还是R52?一张图看懂你的车身控制器/域控制器该用谁

本文深入探讨车规MCU选型中Cortex-M7与Cortex-R52的核心差异,提供基于安全等级与实时性需求的选型决策图。通过对比ASIL认证、实时性能及成本效益,帮助工程师在车身控制器/域控制器设计中做出精准选择,避免潜在风险与隐性成本。

weixin_42628688的博客 398

Android Gradle Transform 创建自定义插件

Android Gradle Transform 创建自定义插件

风言风语 655

关于爬虫源影视资源设置

本文介绍了Omnibox 2.1.3版本的爬虫脚本配置方法,重点演示了如何添加猫眼资源数据源。脚本包含完整的API请求处理、数据格式化、视频详情获取和弹幕匹配等功能模块。通过环境变量配置采集站API地址和弹幕API地址,支持视频列表获取、分类检索、详情查询和播放地址解析等功能。脚本采用模块化设计,包含完善的错误处理和日志记录机制,能够将采集站返回的数据转换为标准格式,并支持批量获取视频详情来丰富数据。同时提供了弹幕匹配功能,可根据视频文件名或播放地址自动匹配相关弹幕资源。

欢迎来到鸾姝淡月博客,专为程序员和编程爱好者打造的技术博客。我们分享编程语言趋势、开发工具、编程哲学、职业发展等,助你掌握新技术,优化技能,激发编程热情。 4697

基于深度学习YOLOv8的花卉检测与识别系统(附完整资源+PySide6界面+训练代码)

通过本项目,我们成功实现了基于YOLOv8的花卉检测与识别系统,涵盖了数据预处理、模型训练、推理与实时检测、以及GUI界面的实现。YOLOv8在花卉检测中的高效性和准确性为实际应用提供了强有力的支持。

斌擎科技 716

Android Gradle(九)自定义Transform,使用Javassist工具插入和删除代码

安卓自定义Transform任务,使用Javassist对代码进行插入和删除。

写好每一篇文章 2810

QGIS安装与使用教程

QGIS安装与使用教程

weixin_46713695的博客 2万+

暴力突破 Gradle 自动化项目构建(八)- Android 对 Gradle 的扩展:Variants、Transform

一、前言

lerendan的博客 3697

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Android Transform + ASM 初探,看完就能找到工作

简历首选内推方式,速度快,效率高啊!然后可以在拉钩,boss,脉脉,大街上看看。简历上写道熟悉什么技术就一定要去熟悉它,不然被问到不会很尴尬!做过什么项目,即使项目体量不大,但也一定要熟悉实现原理!不是你负责的部分,也可以看看同事是怎么实现的,换你来做你会怎么做?做过什么,会什么是广度问题,取决于项目内容。但做过什么,达到怎样一个境界,这是深度问题,和个人学习能力和解决问题的态度有关了。大公司看深度,小公司看广度。大公司面试你会的,小公司面试他们用到的你会不会,也就是岗位匹配度。

m0_61041374的博客 1086

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Android Gradle——自定义Transform,使用Javassist工具插入和删除代码

在安卓中,难免会碰到需要动态插入代码,或者删除代码。这时候就需要用到自定义Transform任务,来对Class文件进行扫描和获取。可以插入的代码场景有哪些?例如:打印方法的执行时间等。可以删除的代码场景有哪些?例如:把代码中Log.e日志打印的代码去掉等先看下代码前后效果,原始代码如下:经过修改后(通过反编译apk得到源码):接下来,让我们看看如何对以上两个场景进行代码的插入和删除。

Dream It Possible 426

Android Gralde插件平台开发系列四:自定义Gradle Transform

自定义Gradle Transform

u011630465的博客 1377

ASM和自定义Transform的应用实践

上篇文章学习了下如何自定义gradle插件《自定义gradle》,在实际应用中一般都会结合自定义的Transform和字节码操作框架(像ASM、Javassist)通过操作字节码来实现自己的业务逻辑,Transform是Android Gradle 在1.5.0 版本后提供的, 它允许第三方的Plugin插件在打包成 dex 文件之前的编译过程中操作 class 文件,对于一些重复性的操作,程序员...

zhaonhui的博客 1543

android dialog 源码,Android Dialog源码分析

1.当我们查看android dialog源码,首先查看dialog的构造方法,初始化相关数据。由源码可知Dialog获取当前的themeId,通过 new ContextThemeWrapper(context, themeResId);设置主题返回Context对象。通过new PhoneWindow()创建Window对象,设置Window相关方法,public Dialog(@NonNul...

weixin_36378222的博客 546

Android Gradle 中的Transform(六)

前言 逐步整理的一系列的总结: Android Gradle插件开发初次交手(一) Android Gradle的基本概念梳理(二) Android 自定义Gradle插件的完整流程(三) Android 自定义Task添加到任务队列(四) Android 自定义Gradle插件的Extension类(五) Android Gradle 中的Transform(六) A...

chuyouyinghe的专栏 2654

Android Transform API 从原理到实战

Transform API 从 1.5.0-beta1 开始,Gradle 插件包含一个 Transform API,允许第三方插件在将已编译的类文件转换为 dex 文件之前对其进行操作。(该 API 已存在于 1.4.0-beta2 中,但已在 1.5.0-beta1 中进行了彻底修改) Transform API 的目标是简化注入自定义类的操作而不必处理任务,并为操作内容提供更大的灵活性。内部代码处理(jacoco,progard,multi-dex)已经在 1.5.0-beta1 中转移到了这一新机

卜大爷的博客 6570
上一篇: Android简明开发教程十七:Dialog 显示图像
下一篇: Android简明开发教程十九:线程 Bezier曲线
引路蜂
博客等级 码龄16年 3122粉丝 711原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值