Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Android Cheese Sheet

2,992 views

Published on

The Android Cheese Sheet

Published in: Mobile
  • Be the first to comment

The Android Cheese Sheet

  1. 1. ‘L‘ v THE CHEESE ‘”‘1s'u= a'Lc: ‘w mi"
  2. 2. SAMSUNG lunooo 2 V G Android #FYl '3 l‘ ; ::; :,: ,i H I‘ 6% Iewcpe M N I I ~ g C°Tli1'i3Ji11Jlil’JL'r3Wl€~11El'11J1J1’1WJ'13J @icez: nu :5 A | / B auwiuaznfiuwnwswuimsnwiaumingu U" lnstagram , 0 ”By curling the mustache, it shows m facial hair is a conscious stvle choice, >1; §‘§"’: ’‘. |I4l‘~- 9:42 PN. +. ?.QE Home Discover ativity Mashable 16 people were arrested in Ferguson last night, according to police. Of those, only one was from the St. Louis area. onmashto/ l CrUXOY , Sittiphol Phanvilai ‘ “ ciatamiaonufiauiiawwfioufioiiawfi Crash mu 3 ngofia 40% We iOS Lia: #1 Status Bar Show Device’s Status and Notification Can be hidden if needed #2 Hction Bar Up Icon, Flpp Icon and Menu Standard UX by Hndroid’s Guideline #3 Tab Bar Tab Style Navigation Fiction Bar's Tab is deprecated, use S| idingTabLayout instead #4 Content Hrea Show main contents of application Let it always be scrollable
  3. 3. DESIGN PA 1' TERM “Fragmenta| ize Everything” - E’/ lutkulwogd Lo%ic r1it= }reFr‘w<n1t_f4_fctivitv - 0 en epen en 0 civiy — Make it reusable — Hlways use Flndroid Support Library Fragment Hctivity - Do control only in Fragment Level for example, replace Fragment — No need to be reusable - Fllways use FIctionBarFIctivity 600g >E-‘‘‘‘f? :.ili‘ , oog e ay 6 G I Pl CATEGORIES HOME TOPPND TOPFREE Put frequently used Put occasionally used ® smiphowr-anvnai Fragment in Tab Bar Fragment in W GAMES C‘ ED'T°RS‘CH0'CE [S| idingTabLayout] Drawer Menu [DrawerLayout] s‘°'°"°"‘° For your Tablet High Resolution Apps + Games w ‘E My apps A : ::: ::: °°i 2 tttti FREE E Mywishlist Autodesk Sketchsook Express for Tablets 0 Map Vorlasanpisurfldlhis Redeem Settings Cool Parenting For You & Your Loved Ones Help ‘ta 0 0 ‘ About Google - I Sai Fah - The Endless Pango FREE Flood Fighter Alphabet
  4. 4. DESIGN PA TTERN - TABLET Fragment B Fragment R 4 WA V5" TO ROTA TE UI
  5. 5. DP unit px = dp *‘ [dpi / 160] DIMENSION o Idpi(iow)~120dpi x0.75 Densifies o mdpi (medium) ~160dpi x1 px = dp * scaleFactor o hdpi(high)~24odpi X15 o xhdpi (extra-high) ~320dpi x2 0 xxhdpi (extra-extra-high) ~480dpi x3 Screen Size 0 xxxhdpi (extra-extra-extra-high) ~640dpi x4 Actual size (inches) 2 4 7 10 Generalized size é, _4 ‘T4 i_, ___2 s_. j———-—. .—-—-—_. a small W99 normal xlarge Title Bar’s Height = 5bdp AB III as lfl MAGIC NUMBER Smallest Width bO0dp = Tablet TOUCH TARGET SIZE E Q : : q @ 3 My files + Use Goog| e's location ' 7 “ Phoms SGTVICS. em mm Let Google help apps determine location This means sending “ Recipes 35 as anonymous location data to J” H ‘mm Google, even when no apps are llllllllllg Work Jan 28 HIM DISAGREE AGREE Vacation itinerary Jt'1n. '7O, ?0lIl I Kitchen remodel
  6. 6. rurrch this weekend? Ii Connors — Ill be in your rieiqhl)ollmL)<l ummer BBQ 4 o Alert. Scott. Jennifer — wish I could andia Adams 'Do you time Paris taco irthday gift revoi Hansen — Have airy ideas aboul ecipe to try mta Holt »wc sriouia oat triis Grated Veflbal kieyllnes Ind honzormlnvloins veiica key rie at ibduirtw the an awdrqm edges content associated -riitri an icon or avatar al‘g'vst 72du émrc the ieét edge isaa hortzontal maigifls on ma e Venucll Iteyiines and hoviznnul riitugins vcrt ca kzv «eeai consist lficzlhcrnthe citcdcc cmtcrit acacciatad th an cu’: or a. atar a lg“: 72dp Iran‘ we ‘Q51 edge Arr Elila ta, vie ic added azdc «ram the Vighlecqe to alimvthetloat rtg act on mm to a an hit? ! me icons brlow ioda hnrizonlal Talq rt; on man : a KEVLINE cl METRIC Vemcal sucinc 1 24dp 2.56dp 3.48dp A.72dp Image dimesion: 3:2 venrui Solclnq 1 24dp 2.56dp 3.8dp A.72dp Vemal tteyiim -as horizontal margins verticai key‘ we . ‘a- E0715 at l5dDtro1HM‘ett and IIGNCUZQS cantewt assoc ated . » tri an (on G! atazar a‘ gas 72d: z Iran- the 'rfl edge red; hofilonlal Wlaiq as o1 imc le vemui II: /lines and hovixomnl rrurulns Vertical soacanq 1 48dp edges ofthesde wax 2- 3.5bdp vertical itewiae: r‘cr cans at lédp ‘road the iert and r grit corite-it assoc an-d ». -. th an can or avatar al‘g'i: 73¢» tic’? ! the aft edge of the side Hair we irictri ai tric 5 Ce nay c equal to the . -.tdtri of the screen 1- «us iria neiam of me act on bar or In this case 56¢pI'orr therightedge ct tria szieaa Material Design Image aimesioit 16:9 More in http: / / www. goog| e.com / design / spec / layout / metrics-key| ines. htm|
  7. 7. ill All Q E I’ 4 Janet Perkins Mary Johnson , Ali Connors Trevor Hansen 650 5554234 t. f_ ? Q A Aaron Bennett (323) 555-6789 Abbey Christensen ‘V “"‘ A“ Connors , , aliconnors@examp| e.com . _ Ne)‘ N930“ aILt: onnors@example. com -+, a:. »-t-9.. .:-ma. as ‘H on E +; .. .__. 1. zadp 2.o4dp . . H 3. 8dp | V Vacation Itinerary Myfl. s A 4.48dp + 5. 80dp Titie Pics Jr"-“zes 1 V 3’ tion itinerary Available oflline r K? ’ en remodel V — Location i '. ‘ % pf. “ senednle Created r. n ‘ . ii-I ® — P“ ‘ct budget V 6 ‘Private i V1’-dy newsgeue, in H. t¢u‘ mm xJCw§Lf; L» ivioieriol Design More in hfipi / / www. goog| e.com / design / spec / loyoui / metrics-key| ines. h1m|
  8. 8. LineorLoyou’r <LinearLayout android: layout_width= ”match_parent” android: layout_height= "match_parent" LA VOUT TmrtVIPw I iL‘XlVl{'u'4 7 T€X[VlC‘I'l 3 android: orientation= ”[horizontal| vertical]” > </ LinearLayout> LineorLoyou’r with weight Help you distribute views by "/ . <LinearLayout T9xtView Ifexivmw 7TextVre'. '.' 3 1KX'°. . ¢ww5T . |r u 5:>sr>i. i Helloworld Texrview I Texrview 2 TextVrew 3 android: layout_width= ”match_parent” android: layout_height= ”match_parent” android: orientation= ”horizontal” > <TextView andro; andro; andro; andro; O-QQQQ andro; <TextView andro; andro; andro; andro; Q-QCLQQ andro; <TextView andro; andro; andro; andro; Q-QQ-QQ andro; </ LinearLayout> : layout_width= ”Odp” : layout_height= ”match_parent” : layout_weight= ”1” : text= ”TextView 1” : background= "#ffcccc"/ > : layout_width= ”Odp” : layout_height= ”match_parent” : layout_weight= ”l” : teXt= ”TextView 2” : background= "#ccffcc"/ > : layout_width= ”Odp" : layout_height= ”match_parent” : layout_weight= ”1” : text= ”TextView 3” : background= "#ffccff"/ >
  9. 9. LA VOUT Fie| o’riveLoyou’r: Hlign to Parent | uyoUi_o| ignPoreniTop VI 5:00 Helloworld cenierHorizon1o| | oyou’t_o| ignPoren’rLefi Ce. Ioyoui_o| ignPoreniRighi _ cenierverficol cenferHorIzon1o| | oyou1_o| ignPoreniBoifom Fie| o’riveLoyou’r: Hlign ’ro Sibling View[s] | oyoui_o| ignT0p= ”@id/ o" V I 5:00 Helloworld | oyouT_be| ow= ”@id/0" | oyoui_obove= "@id/ b” | oyou1_o| ignLef’r= "@id/ o” | ciyoui_ToRighi0f= ”@id/ o" | oyou’r_’toLeff0f= ”@id/ b” Ncyouta| ignHighT= n@id[On | oyou’r_o| ignBo1fom= ”@id/0"
  10. 10. loyout_grovity top Helloworld center_horizonto| left ------ - - right Center_r= ertico| combine with or [I] for example, layout_gravity= ”center_verticallright”
  11. 11. LA VOUT margin & padding Helloworld Hello android: |ayout_morgin= ”10dp” gravity vs | ayout_gravity Helloworld 5 android: gravity= ”bottom” VI 5:00 Helloworld llollo android: podding= ”10dp" Helloworld andr0id: |ayout_gravity= ”bottom”
  12. 12. nil’ <; i'; ” ""’ "' Lei]: Mobile Portrait Mobile Landscape Tablet Portrait Tablet Landscape ‘V n”, ,_. ‘ . ’ , L. , ii. ’ . .., , .1.-. ‘ J I ‘. fir. ..“ in‘ I. i.* ”f&A~1r1 Hrs. : * V E I Is Works Perfectly Works ‘ 33 Fine - Ul Fit- :2 ‘ ' - Ul Fit - - Fast - Low End 1). : F i[1.fiH; Yfk"iu. Iii’ Froyo 8 062 Gingerbread 10 9 8‘: minSdkVersion = 14 $37-77c"~‘ '5 Jelly Bean is 22 8*. » 17 20 8": 18 7 3“: KIlKal 19 30 2’. Data collected during a 7~day period ending on November 3, 20 74 Any versions i'/ iili less than D 1”: distribution are not show/ i
  13. 13. (I1: Structure . 1: Project l ild Variants arites ‘' Build Variants CODE STRUCTURE DjPro1ect V C3 % §' E" D SIC - a Cl androidTest :1 main Djava E <om. thecheesefa fthecheese B] activity 3:: Singleton with mini controller E fragment E manager El htt 9° : °"“"’“°' Singleton without controller 9 0 lmageLoaderMana Eiutis / Custom View {Db Utils E view © ‘:2 CustomViewGroupTei _ _ 9 in CustomViewTernp| at( © '9 MainApp| ication fires ‘ff; Put Drawable XML here El drawable . . . En, ,mb, ,_, _hdpi Put image files here with scaleFactor X2 E drawable~mdpi . . E dmblmdpi Put icons in every drawable folder El rawa e~)o< i E : youtb DefCU” IGYOUT I El layout-land 4—j_jLayout for mobile landscape l: i layout-sw600dp {en-jmyout for tablet portrait E‘ "Y°“"“”"°°“P"‘"‘ 4?? Layout for tablet landscape B fl'IEl'1|. l EIVBWES 4-T-—— Split every single value to values [string, dimen, color, etc. ] El values-w820dp E AndroidManifest. xm| El . gitignore 9| app. im| ® bui| d.grad| e El proguard-rules. pro
  14. 14. AC TII/ IT V Template Use FictionBarFlctivity from Hndroid Support Library v7 public class ActivityTemplate extends ActionBarActivity { @Override protected void onCreate(Bundle savedlnstancestate) { super. onCreate(savedlnstancestate); setContentView(R. layout. activity_main); Change sty| es. xm| to Theme. HppCompat. “ "< resources) initInstances(); sstyle rpa‘renc= "Thene . AppConpat. . Light . Daruxccionflar“ > private void initInstances() { / / init instance with findViewById here @Override public boolean onCreateOptionsMenu(Menu menu) { / / Inflate the menu; this adds items to the action bar / / if it is present. getMenuInflater(). inflate(R. menu. menu_main, menu); return true; @Override public boolean onOptionsItemSelected(Menultem item) { / / Handle action bar item clicks here. The action bar will / / automatically handle clicks on the Home/ Up button, so long / / as you specify a parent activity in AndroidManifest. xml. int id = item. getItemId(); / /noinspection Simplifiablelfstatement switch (id) { case R. id. action_settings: return true; default: break; } return super. onoptionsltemselected(item);
  15. 15. AEWWW’ -H MFE€Vf£E ep created 3951:, -2‘ ‘L Stopped Rasu med ‘VVs‘b‘e) 1 “S9. 1 Destroyed . V., 2 r()'v: A r V Cmalnd e 3 : v1r"1-: s'C(-3“S‘[4"CeSil‘C‘1 + @Override protected void onStart() { super. onStart(); @Override protected void onStop() { super. onStop(); @Override public void onsavelnstancestate(Bundle outstate) { super. onSaveInstanceState(outstate); @Override protected void onRestoreInstanceState(Bundle savedlnstancestate) { super. onRestoreInstanceState(savedlnstancestate);
  16. 16. CUSTOM APPLICA T ION Template public class MainApplication extends Application { @Override public void onCreate() { super. onCreate(); Contextor. getInstance(). init(getApplicationContext()); Make Context Global Define in HndroidManifest. xml sucva aw. . ./ ./4.1-A| /A4— u. g.. um. ,1 <uses -permission android : name= "android. } public class Contextor { <app1ication android : name= " . HainApp1ication" android : a11owBackup= " true" private static Contextor instance; public static Contextor getInstance() { am”§”Q°W”““F%"”T android : J. <:on= " édrawable/1c_1auncher‘ if (instance = = null) instance = new Contextor(); return instance; private Context mcontext; public Contextor() {} public void init(Context context) { mcontext = context; public Context getContext() { return mcontext;
  17. 17. SINGLE TON Template public class SingletonTemplate { private static SingletonTemplate instance; public static SingletonTemplate getInstance() { if (instance = = null) instance = new SingletonTemplate(); return instance; } private Context mContext; private SingletonTemplate() { mContext = Contextor. getInstance(). getContext(); } Best Practices: - Use Singleton as Model in MVC - Singleton with mini controller inside = Manager _ _ _ Put in separate folder - Singleton without controller = Utils
  18. 18. FRA GMENT Template Use Fragment from Hndroid Support Library VA public class FragmentTemplate extends Fragment { public FragmentTemplate() { super<); public FragmentTemplate newInstance() { FragmentTemplate fragment = new FragmentTemplate(); Bundle args = new Bundle(); fragment. setArguments(args); return fragment; @Override public View onCreateView(Layoutlnflater inflater, ViewGroup container, Bundle savedlnstancestate) { View rootview = inflater. inflate(R. layout. fragment_main, container, false); initInstances(rootView); return rootview; private void initInstances(View rootview) { / / init instance with rootView. findViewById here @Override public void onStart() { super. onStart(); @Override public void onStop() { super. onStop();
  19. 19. FRA GMENT - LIFECVCLE Template Activity State Fragment Callbacks @Override public View onCreateView( Cmam zmmmmo Layoutlnflater inflater, ' ViewGroup container, mmwmfl) Bundle savedlnstancestate) { View rootView = inflater. inflate( V , onCreateView() R. layout. fragment_main, container, V f a 1 S e ) ; onActivityCrealed() initInstances(rootView); // Restore Instance State here V Starred onStan() return rootView; V } Resumec onflesumeo @Override ' protected void onStart() { Pawed mmmmeo super. onStart(); } V Stopped 0"5‘0P0 @Override protected void onStop() { y Super - Onstop () ; Desuoyed onDesIroyView() } V _ onDestroy() @Override public void onSaveInstanceState( ' onDeIach() Bundle outstate) { super. onsavelnstancestate(outstate); // Save Instance State here
  20. 20. USE OF FR/ I GMENT 1] Replace ¢ Declare Container in xml <FrameLayout android: id= ”@+id/ container” android: layout_width= ”match_parent” android: layout_height= ”match_parent” / > 0 Hdd First Fragment in Flctivity’s onCreate if (savedlnstancestate = = null) { / / Check if it is the first launch getSupportFragmentManager(). beginTransaction() . add(R. id. container, FragmentA. newInstance()) . commit(); 6 Replace new tab with “replace” Fragment fragment = getsupportFragmentManager(). findFragmentById(R. id. container); if (fragment = = null ll ! (fragment instanceof FragmentA)) getSupportFragmentManager(). beginTransaction() . replace(R. id. container, FragmentA. newInstance()) . commit(); “ Or use NonSwipeab| eViewPager for better experience ’
  21. 21. 6 Q & Back [or Up] ogre“ ‘L gs _» o s Q 4*‘; : <y§§ er“ s+~‘°° * ‘ I <2?’ ‘ 4+‘ e°° / >~ ‘, "~, : 5 f 4 , . re‘ ‘irfl ~ <v §$ K1 I . $($; >' Qé, o’° ‘. - 4" I ¢> . go“ ca Declare fragment in xml <fragment android: id= ”@+id/ fragment” android: layout_width= ”match_parent” android: layout_height= ”match_parent” android: name= ”com. thecheesefactory. lab. fragment. FragmentA” / > >9‘ Rdd Rnother Fragment to Backstack Fragment fragment getSupportFragmentManager(). findFragmentById(R. id. fragment); null ll getSupportFragmentManager(). beginTransaction() if (fragment ! (fragment instanceof FragmentB)) . replace(R. id. fragment, .addToBackstack(null) . commit(); FragmentB. newInstance())
  22. 22. VIE WPA GER ° 9 _i ,4 Apps HOME TOP PAID SAMSUNG >8 ‘= TOP FREE lli‘ TOP GRDSSI , ex V, mm_, ; mm“, 1. The World It Hunting BOSS 1. Messenger 1. LlNE: Free Calls & Messages ' ' 1. Kingdom Rush Orig . mood mm 5 '; X'. l(<1J'iir: Zitlll D . . lC“ 'nri" Elf, ‘ mm 2 cl: :, ktffii nu-in MORE llli33’_' ll H-H£—l»LLL! l fllNESl»‘xLLLLi ‘'5'’ A995 * Games 2 2. Kingdom Rush Origins 2. Facebook 2. LINE Lets Get Rich 2 Five Nights at Fred ll lllllli'[i_ll‘l( : ;i ‘l'l l 0 nit : i.n; uut: i:, - slim i‘. ir-. -im-- 3l<'3‘Cl1B00l< vmtwv wt: -1 «mun «mun Exfffi hm llITiUR§’U a risui l to rnrr ‘ V V V W V W k 3. Gangstar Vegas 3. Candy Crush Soda Saga 3. Kung Fu House-iilnfiaiitdtfin 3. The World It Huntiri 'W"9~ - *1 i 0" : ,. is-li: t ~ l<' ' i, F“. :: l)( : U, -efifixfllr. ~. ., VlW'= *‘i'0'Tr*= ‘l*’l ~ L}u. .V a‘9:: n time; .L. {. my 555 . Nap Val/ asanptxulvltlllrix Wm‘) an W“ W“ 4 Minecraft - Pocket Edition _ 4. Camera36O Ultimate 4. Clash of Clans 4 Dirt Trackin . . " PM in ll iii-ii)-l‘ e lull li»'l‘u‘li‘tllrillit'l‘» ming 0 «van «arm «can )UrLO/ ed Ones iiitiiuniiu 0 N‘: l»lllU H-(LL 5. Football Manager Handhe| d.. 5. LINE: Free Calls & Messages ; 5. Summoners War 5. Battleheart Legacy wHu‘« wimnm. » lltlt» i-mmim i; »,m, iis o ai kn lfvliln «run «run «nut mun lHH37}li‘: 'N5l»‘lHJ llllrlr 6. Camfrog Video Chat Pro 6 Clea Master (Speed Booste, 6. Dot Arena 6. Secret of Mana cc. .', liJ’i: ll‘E ' rm miiln: LU. i'u-‘L Lll < L: rm :1 Endless Pango FREE 0 H Alphabet *"**‘ "**"‘ Swipeable Swipeable - Use as Page [Normal Use] oom- UME TOP PAID . ,, ||: ::: ‘ _ i042 PM Apps Q TOP FREE TOP CROSSING 1 . Messenger r_w. ~n. ~,ri< o tit! lNSTAl l m 2.Facebook iacolmok <1 taut: lNSl/ LLt, Ll 3. Candy Crush Soda Saga Klllt; 0 «tun Fill E 4. Camera36O Ultimate l’lii(}. l0 ‘tin onnnw Q WSTALLED 5. LINE: Free Calls & Messages l‘lxF i‘, m,: m. , it-it-ti awsi/ ittio 6. Clean Master (Speed Booste. . Ulletlldil ‘lz, l:il»v t mu 1 Define ViewPager and use it in normal way You can use S| idingTabLayout to make Tab Bar looks like this Nonswipeable - Use as Tab Switching Override ViewPager to disable swipe [search for Non Swipeable ViewPager] and use that in xml To change tab, call viewPager. setCurrentItem (tablndex, false); % nichieme O 17 likes nichieme iiinuamiint-ii tmtDJ'" i ll auninin bebnyzself titan ‘name;
  23. 23. VIE WPA GER - USEAS TAB SWITCHING Define NonSwipeab| eViewPager public class NonSwipeableViewPager extends ViewPager { public NonSwipeableViewPager(Context context) { super(context); public NonSwipeableViewPager(Context context, Attributeset attrs) ( super(context, attrs); @Override public boolean onInterceptTouch3vent(MotionEvent argO) { / / Never allow swiping to switch between pages return false; @Override public boolean onTouchEvent(MotionEvent event) { / / Never allow swiping to switch between pages return false; } } Use it in <| ayout>. xm| instead of normal ViewPager <com. thecheesefactory. lab. view. NonSwipeableViewPager android: id= ”+@id/ ViewPager” android: layout_width: ”match_parent” android: layout_height= "match_parent” / > Change Tab without swiping animation via command viewPager. setCurrentItem(tabIndex, false);
  24. 24. public class CustomViewTemplate extends View I public CustomViewTemplate(Context context) { super(context); init(); public CustomViewTemplate(Context context, Attributeset attrs) { super(context, attrs); init(); initWithAttrs(attrs); public CustomViewTemplate(Context context, Attributeset attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initWithAttrs(attrs); init(); private void init() I setWillNotDraw(false); 30 Nov 20M 12.3‘ private void initWithAttrs(Attributeset attrs) { SETINDEX L5g3g1 . ’. Mi’) ‘ ' 463 59l —O 37’: } 1,601 00 I I I I 159700 I @Override “%W i 1.59300 protected void onDraw(Canvas canvas) { iwwm10 H 12 H 16 W super. onDraw(canvas); awm } 2,2o4M } ‘I 0M_in; u' 'h”: JW In 11 I2 15 I6 I7 High 1,600.65 ‘O as Low 1,591.71 —a. ii H d 1, Vol(l<) Value(M) 46,831.75 SET100 2,365.39 —9,90 -0.42% » — Custom Draw - Custom Input Handling in seii~= =ef= V~ . I _i_ . .'i 1, ; . 14 . .-I . r {Eu
  25. 25. private TextView tvName; public CustomViewGroupTemplate(Context context) { I wmmmm super (context) ; ' 1.CandyCrushSodaSaga Rdvanta e I initInflate(); —Ie——? Eg— _ I: §%I“*“ . . _ - ayou roumng ‘ 4 lnltlnstances ’ _V_ 2. Plantsvs. Zombies FREE — Reuseable l_': ljl1‘i_N i; /»'l' s, fikiti —Cudom| nputHandHng 3. Darkness Reborn tjt‘. $.'i . l 'I a y a ir 1 public CustomViewGroupTemplate(Context context, Attributeset attrs) { super(context, attrs); initInflate(); initInstances(); initWithAttrs(attrs); —‘ 4. Race War N20 , »i-; ~<‘~i~: r-ii, i~-~i. -ii-at fiikfii my (‘—: r'v‘m. icv' I too iitlri } T t ‘/ t 6. Curio Quest am I'>»il‘I>‘ i: .. ".4. ’ W’ fittt Enifi ’ public CustomViewGroupTemplate(Context context, Attributeset attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initInflate(); initInstances(); initWithAttrs(attrs); private void initInflate() { Layoutlnflater inflater = (LayoutInflater)getContext() . getSystemService(Context. LAYOUT_INFLATER_SERVICE); inflater. inflate(R. layout. blog_list_item, this); private void initInstances() { tvName = (TextView) findViewById(R. id. tvName); private void initWithAttrs(Attributeset attrs) { } 5. Sniper 3D Assassin: Free Ga. .
  26. 26. 9-PA T CH "‘ Rdd a pixel to every single edge. Mark with black [#000000] Marker Pafiem color. The rest must be transparent [#00OOOO00] pixel. Stratchable area Padding box taptioiialj The way it is scaled is just “streching”, so use only plain color or gradient Filetype must be a PNG file with .9.png file extension Button with 8sp textSize Button with 30sp textSize Biiiiiiig text! I Tin)‘ I Simple Nine-patch Generator http: / / romannurik. github. io/ RndroidRssetStudio/ nine-patches. htm|
  27. 27. Send SMS SmsManager m String destination "Hello, m. sendTextMessage(destination, String text C ODE SNIPPE T "+66812345678"; Johnl"; null, Open URL in Browser String url Intent browserlntent "http: //www. google. com"; new Intent(Intent. ACTION_VIEW, Uri. parse(url)); startActivity(browserlntent); Send Text Content to Rnother Rpp Intent sendlntent sendIntent. setAction(Intent. ACTION_S sendIntent. put3xtra(Intent. EXTRA_T3XT, new Intent(); .1 sendIntent. setType("text/ plain"); startActivity(sendIntent); Send Image to Rnother Rpp Intent shareIntent shareIntent. setAction(Intent. ACTIONiSEND); shareIntent. put new Intent(); SmsManager. getDefault(); text, END); 3xtra(Intent. EXTRAiSTR shareIntent. setType("image/ jpeg"); startActivity(shareIntent); Vibrate SAM, null, null); "This is my text to send. "); uriToImage); (Vibrator)getsystemservice(Context. VIBRATORiS3RVICE). vibrate(milliseconds);
  28. 28. C ODE SNIPPE T Rlert Dialog AlertDialog. Builder alert alert. setTitle(title); alert. setMessage(message); new AlertDialog. Builder(this); / / You can set an EditText view to get user input besides / / which button was pressed. final EditText(this); 3ditText input new alert. setView(input); alert. setPositiveButton("Ok", new Dialoglnterface. OnClickListener() int whichButton) { { public void onClick(DialogInterface dialog, String value input. getText(); // Do something with value! I l); alert. setNegativeButton("Cancel", new Dialoglnterface. OnClickListener() public void onClick(DialogInterface dialog, int whichButton) { / / Canceled. I } I); alert. show(); Enable/ Disable WiFi WifiManager wifi (WifiManager) wifi. setWifiEnabled(enabled); Enable / Disable Ringer AudioManager mAudio (AudioManager) getsystemservice(Context. WIFIiSERVICE); getsystemservice(Activity. AUDIO_SERVICE mAudio. setRingerMode(AudioManager. RINGER_MOD / / or. .. mAudio. setRingerMode(AudioManager. RINGER_MODE_NORMAL); 3_SILENT);
  29. 29. C ODE SNIPPE T HTML in TextView textView. setText(Html. fromHtml("<h2>Title</ h2><br><p>Description here</ p>")); Take a picture with Intent Intent intent = new Intent("android. media. action. IMAGE_CAPTURE"); startActivityForResult(intent, 123456); / / @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode = = Activity. R3SULT_OK && requestCode = = 123456) ( String result = data. toURI(); // Phone Dial . ,_, ._, _. Intent intent = new Intent(Intent. ACTIONiDIAL); intent. setData(Uri. parse(”tel: //0812345678”)); startActivity(intent); Make a phone call Intent intent = new Intent(Intent. ACTIONiCALL); intent. setData(Uri. parse(”tel: //0812345678")); startActivity(intent); <uses—permission android: name= "android. permission. CALLiPHONE"/ > More about Intent Action: http: //developer. android. com/ reference/ android/ content/ Intent. html
  30. 30. Trigger Pros Limitations / Drawbacks When to use? THREAD FlsyncTask RsyncTaskLoader Rnywhere from Rctivity or Main Thread Fragment Can communicate with main thread to publish progress Changed Rutomatically terminated along with Rctivity / Frag ment Can’t communicate with main thread during execution Can be executed only one instance a time May cause memory leak May cause error when screen rotated Small Task [A-5 secs] Flsync Data Loading that have to for Rctivity/ Fragment communicate with main thread Can replace [update progressbar] FlsyncTask that needs to be terminated along with Rctivity [with Otto for communicate back] IntentService Main Thread [through Intent] Handle Configuration Good for a Long Task Can’t communicate to main thread straightforwardly Multiple lntents are queued Long Task usually with no communication to main thread [can do anyway via Broadcast Intent or Otto]

×