#day1 of java
Explore tagged Tumblr posts
spydekkn-blog · 27 days ago
Text
🔰 Starting out in Java? You’ve probably seen this line over and over: public static void main(String[] args) { // your code here } But did you know Java allows several valid variations of the main method? Let’s break it down for clarity! 👇 ✅ 𝑜𝒂𝒍𝒊𝒅 𝒎𝒂𝒊𝒏 𝑎𝒆𝒕𝒉𝒐𝒅 𝑺𝒚𝒏𝒕𝒂𝒙𝒆𝒔: 1⃣ public static void main(String[] args) → Standard & most widely used 2⃣ public static void main(String args[]) → Old-school array syntax (still valid) 3⃣ public static void main(String... args) → Uses varargs — flexible and works the same 4⃣ public static void main(String[] myCustomName) → Parameter name can be anything! ❌ 𝙄𝙣𝙫𝙖𝙡𝙞𝙙 𝙎𝙮𝙣𝙩𝙖𝙭𝙚𝙚: 🚫 public void main(String[] args) → Missing static 🚫 static void main(String[] args) → Missing public 🚫 public static void main(int[] args) → Wrong parameter type 🔎 The JVM specifically looks for: public static void main(String[] args) 🧠 𝙁𝙪𝙣 𝙁𝙖𝙘𝙩: You can overload the main method, but only the correct one (String[] args) will run by default! 📚 𝗡𝗲𝘄 𝘁𝗌 𝗝𝗮𝘃𝗮? Check out my full beginner-friendly blog post on this topic: 👉 https://wp.me/paNbWh-2l 💬 Got any Java tricks you wish you knew earlier? Drop them below 👇 Let’s grow together. #Java #100DaysOfCode #FullStackDevelopment #CodingJourney #LinkedInLearning #Beginners
0 notes
javabalitrips · 6 months ago
Text
Six Days Java Bali Tour Package
Get the details of Six Days Java Bali Tour Package for your best holiday travels to Java and Bali islands. This best starter exploration of Indonesia should be continued to make other great journeys! Day1: Arrival at Yogyakarta International Airport (YIA) Our team is happy to welcome you and escort your visiting the huge temple complex of Prambanan. It depends on your flight time; we will have a

0 notes
seanblanchard · 6 years ago
Photo
Tumblr media
"Love recognizes no barriers. It jumps hurdles, leaps fences, penetrates walls to arrive at its destination full of hope." . #mayaangelou #faith #hope #love . Always taking care of business! . #bass #bassist #bassplayer #food #foodie #whole30 #day1 #coffee #java #espresso (at Seguin, Texas) https://www.instagram.com/p/BvvDBOBllm9/?utm_source=ig_tumblr_share&igshid=uwdgcnjvnri8
1 note · View note
bastamanography · 5 years ago
Photo
Tumblr media
selamat pagi dunia ... #siapsiap #prepare #start #tour #duty #tourofduty #banyuwangi #eastjava #java #trip #twowheels #culture #culturetrip #culinary #food #foodporn #day1 #monday #desalogi #bastamanography (at Banyuwangi, Jawa Timur, Indonesia) https://www.instagram.com/p/B8XSbuqAAVw/?igshid=yqzh5vdk16mv
0 notes
crazycatcodes · 5 years ago
Text
Hey tumblr!
So I don't know if it counts but here is how my first day went into the challenge. So I tried waking up at 4 am and I did but i dozed off again as the weather was quite cold.
Then I woke up by 9 am and took lecture 1 from Cs50 about SCRATCH. Then I built a Scratch project, a rough fruit ninja game. "I'll share link to my projects here soon."
I tried listening to another lecture, but I felt quite unmotivated.
Highly disappointed by DAY1 but won't drop here. So I am listing my Day 2 targets here.
1. Complete Python course on Sololearn and Kaggle both.
2. Complete Java course on Sololearn and w3s.
3. See Android studio basics.(YOUTUBE)
4. Complete one certification on freecodecamp.
It's lot and unrealistic but this way i can get atleast half done. 😂😂
Also waking up at 4 am for sure.
P.s. Taking writing challenge too, will share poems and short stories shortly.
13 notes · View notes
yoshimura-eto10-blog · 4 years ago
Photo
Tumblr media
On every night during 11 pm, I will updating about my day and how Ive been doing with my activities.
I will use the hashtag
#dailyreport #day1 #improvising #ctf #java #website #religion #python
0 notes
mellamo-eason · 7 years ago
Photo
Tumblr media
倪久沒有當孞生orientation day1坐圚教宀內聜了䞀個小時的介玹就超想睡。結果第二倩就考了敎倩的詊考完埌的心埗只有問自己為什麌圚這個地方😂 經濟統蚈財管會蚈考的郜䞍難郜是6幎前孞過䜆珟圚忘光光的東西䜆是Java的考詊寊圚是讓每個人出䟆郜是䞀臉傻県黑人問號90分鐘內芁回答完30題遞擇題加䞊寊䜜䞀個import/sort/query from .txt的project寊圚是倪震撌教育了沒蟊法圢容拿到考題當䞋有倚黑人問號考完倧抂只剩圚倖面曬曬倪陜走走路攟空的想法😭 而䞔也埈明顯可以看出皋床差異陀了幟個超匷印床人60分鐘內寫完党郚党班倧抂只有幟個人可以䞀盎圚鍵盀䞊打字其他人完党想打字連䞀個function郜䞍知道該怎麌寫😱出䟆埌芋面打招呌只剩see you guys in the class 教授還說這只是a piece of cake comparing with the final exam?!?!?!Damn...... #walkingtothesky #welcometocmu #longday #20180515
1 note · View note
thecodersgig · 4 years ago
Photo
Tumblr media
Day 1 : 7 Days 7 Project Challenge Full demo available here : https://thecodersgig-7dayproject-day1.web.app/ For complete source code dm us #coder #frontend #devops #madeinindia #nodejs #aws #gcp #docker #reactjs #java #c #c++ (at India) https://www.instagram.com/p/CKuHrIsgdCS/?igshid=1ogukkkwq62ap
0 notes
kasfyallama · 8 years ago
Photo
Tumblr media
Day 1: Home made
This snack is home made. Not by mine but another.
In frame: Rempeyek – a traditional snack from Java. Usually, one of its ingredients is peanut but in this frame was exchanged with dried shrimp. So crunchy and salty!
What is your snack(s) today?
0 notes
toastkidjp · 7 years ago
Text
2017幎終了今幎は䜕があったか
抂芁
今幎䜕をやったのかを振り返る。努力しおいないわけではないが、あたり成長のない1幎だった。䜕かやったずいう実感も特になかった。
今幎始めたこず
公開甚の Android アプリ開発
Kotlin
GitHub 緑化掻動
転職ドラフト
ノヌ残業  4月から9か月連続でれロだった。なお幎収は
Tumblr
むンプット
読曞
今幎は IPA の情報凊理技術者詊隓を受けなかったので、それだけ倚く本を読むこずができた。 囜立囜䌚図曞通に行くこずを芚えお、そこで本を無料で読むようになったのも良かった。
『レガシヌ゜フトりェア改善ガむド』
『ケント・ベックのSmallTalkベストプラクティス・パタヌン』
『オブゞェクト指向ワヌクブック』
『リファクタリング』
『Javaパフォヌマンス』
『Java本栌入門』
『Android Pattern Cookbook』
『Androidアプリ開発の極意』
『Effective Debugging』
『Kotlinスタヌトブック』
『RxJavaリアクティブプログラミング』
『情熱プログラマヌ』
"Reactive Java Programming"
『コヌディングを支える技術』
『Androidアプリ開発 74のアンチパタヌン』
『Androidを支える技術(II)』
『実装パタヌン』
『ThoughtWorksアン゜ロゞヌ』
『Javaによる関数型プログラミング』
特に『リファクタリング』には感銘を受けた。もっず早く読むべきだった。旧版でも十分な䟡倀がある。 『Androidアプリ開発の極意』『Androidアプリ開発 74のアンチパタヌン』『Androidを支える技術(II)』 の3冊は私の Android 芳を再構成するのに非垞に有益だった。『ThoughtWorksアン゜ロゞヌ』はさすがに今ずなっおは叀い本だが、 オブゞェクト指向゚クササむズやファヌストクラスコレクション、StringUtilsがなぜ埮劙なのか、などただただ圹立぀内容が茉っおいた。 圓時の ThoughtWorks が Groovy/JRuby/Jaskell をやたらず掚しおいたのを再確認するのにも圹立った。
カンファレンス聎講
自費(箄60䞇円)有絊䌑暇5日を䜿っお海倖カンファレンスに行くずいう経隓をしお、海倖カンファレンスは䌚瀟の金で行くものだずいう認識を匷めるこずができた。
DroidKaigi 2017
Devoxx US 2017
Droidcon Vietnam 2017
JavaOne 2017
レポヌト
Devoxx US 2017
https://reminiscencesoftoastkid.tumblr.com/post/160693403713/devoxx-us-2017-short-report
Droidcon Vietnam 2018
https://reminiscencesoftoastkid.tumblr.com/post/159716738388/droidcon-vietnam-2017-flash-report
なお2018も開催予定ずのこず
JavaOne 2017
JavaOne 2017 Day1 Flash Report
JavaOne 2017 Day2 Flash Report
JavaOne 2017 Day3 Flash Report
JavaOne 2017 Day4 Flash Report
JavaOne 2017 Day5 Flash Report
アりトプット
曞いた蚘事
今幎は Qiita に 24 の蚘事を投皿した。 NIO2 の初歩的な内容の蚘事だけはいいねが30を超えたが、あずはどれも1桁だった。仕事で知芋を溜められるようにならないずダメだず痛感した。
Date Title 2017/01/03(Tue) Gradle プロゞェクトで静的解析ツヌルを䜿う 2017/01/17(Tue) TestFX で JavaFX アプリケヌションのテストを曞く 2017/01/31(Tue) java.io.File のコヌドを java.nio.Path ず java.nio.Files を䜿っお曞き盎す 2017/02/16(Thu) JavaFX でスラむドショヌツヌルを䜜る 2017/02/20(Mon) Googleの入瀟詊隓(非公匏)にGroovyでチャレンゞしおみる 2017/04/03(Mon) minimal-json で JSON を扱う 2017/04/05(Wed) 正匏リリヌス前に Eclipse で JUnit 5を愉しむ 2017/04/08(Sat) Optional の7぀のルヌルに぀いお考える 2017/06/02(Fri) JavaFX の Clipboard API を䜿う 2017/06/13(Tue) Android の AppWidget で Snackbar を䜿う 2017/07/17(Mon) 特定の Fragment でだけ䜿うメニュヌ項目を共甚の Toolbar に inflate する 2017/07/30(Sun) RecyclerView の芁玠を埪環させる 2017/08/12(Sat) Moshi を䜿っお Java オブゞェクトず JSON を盞互倉換する 2017/08/14(Mon) enum の定数倀ごずに振る舞いを倉えるのを Kotlin でやっおみる 2017/08/21(Mon) Android アプリの Java ゜ヌスコヌドを Kotlin に倉換しお躓いた点をたずめる 2017/09/15(Fri) android.text.TextUtils のメ゜ッドを調べる 2017/09/23(Sat) Android 甚の ColorPicker を探す 2017/10/09(Mon) Android プロゞェクトで JUnit5 を䜿う 2017/10/31(Tue) Kotlin の sealed クラスを䜿う 2017/11/05(Sun) Android Studio のメニュヌ文字サむズを倉える 2017/12/01(Fri) RxPermissions で Runtime Permission の凊理をする 2017/12/03(Sun) RxJava を非同期凊理を曞きやすくするラむブラリずしお考える 2017/12/19(Tue) プログラムで生成した TextInputLayout に EditText をセットする 2017/12/30(Sat) TextView の CompoundDrawable に ColorFilter をかける
曜日で芋るず半分を月曜ず火曜に投皿しおいる。䌑日はいいねをもらいにくいずいうむメヌゞがあるのず、 䌑み䞭に完成しなかった蚘事を月・火に投皿しおいたのずでこうなったのかず思う。
Day of week Count Mon 6 Tue 6 Wed 1 Thu 1 Fri 3 Sat 4 Sun 3
Tumblr
春くらいにQiitaの芏玄改正があっお、それを機に勉匷䌚のメモをQiitaに投皿するのを止め、完党にプログラミングのネタだけを投皿するこずにした。 そしお別に Tumblr を始めおみたずころ、本圓に誰も読んでいなくお草も生えない。Tumblr は画像を投皿したり、 気になった蚘事のメモをちょっず曞いおおくずいう䜿い方なら適しおいるのだが、ブログを曞くサヌビスずしおは埮劙なずころがあり、 特にコヌドブロックが暙準だず党然ダメなのが本圓に困る。 たたに Qiita に曞くほどでもないなず思ったネタを Tumblr に曞いおいたが、すぐにやめおしたった。 今ではお昌の画像をアップするのず、気になったWeb蚘事のクリッピング皋床にしか䜿っおいない。
Android アプリ
趣味のプログラミングでも Android アプリの開発をやらないず孊習量が党然足らないず感じ、今幎の6月からやり始めた。 孊習効果が高たったのず、流甚できるコヌド矀をストックできるようになったのずで、仕事にプラスになったのは倧きかった。
なお公開に぀いおは、いく぀か䜜っおはみたが党然ダメだった。唯䞀、Wi-Fi の状態を切り替えるりィゞェットはちょっずだけ受けおいた。 䞀番力を入れおいるWeb怜玢アプリが党然むンストヌルされなくお、 その前に䜜っおいたしょがいアプリの方が3倍むンストヌルされおいる。 よくわからない。
https://play.google.com/store/apps/developer?id=toastkidjp
ちなみにいくら皌いだか曞いおおくず、4か月で14円である。ティッシュも買えない。
Kotlin
これたで情報収集しかしおこなかったが、Google I/O 以降䞀気に䞖間が傟き始めた。 転職ドラフト等でも 「Kotlin やっおたす」ずいう䌁業ばかりになっおきお、いい加枛やらないずたずいず感じ、 趣味のプログラミングで䜿い始めた。
最初は違和感が匷かったが、すべおのコヌドを䞀括で Kotlin 倉換する、ずいうスパルタ匏孊習法により2週間皋床で逆転した。 JavaOne では Kotlin のセッションを䞭心に聞きたくっお、やや物足りなさを感じるくらいにはなっおいた (圓然だが JavaOne では Kotlin を知らない人向けのセッションが倚いためである)。
もう Kotlin しか䜿っおいない䌁業でもやっおいけるずいう根拠のない自信ができた。
GitHub 緑化掻動
転職で有利だずいうので、軜薄な気持ちで始めたずころ100日以䞊続いた。 commit数が䌚瀟の GitHub Enterprise のアカりントより倚かったずいう。
これをやるこずで日垞的にコヌドを改善する習慣が身に぀いた。が、䞀方で、1日で終わらないような倧掛かりな修正を(心理的に) しにくくなったず感じる。
買ったもの
ThinkPad X1 Carbon
高性胜だが、無難で面癜いずころはなく、ThinkPad X1 Tablet ずかに比べるず情熱は感じないマシンだった。
Covia L7
Android アプリ開発を趣味で始めるのに実機が必芁だったので賌入した。
長所
1䞇円皋床で入手可胜
非垞に軜い
短所
安っぜい
性胜が貧匱
解像床が䜎め  逆に狭い画面の確認には䜿える
OS 6.0、Runtime Permission の怜蚌がギリギリできる皋床
Galaxy Feel
たしな怜蚌端末が欲しいず思っお探したずころ、某キャリアの販売戊略により圚庫がダブ぀いおいるらしく、Amazon のマヌケットプレむスで25,000円皋床で賌入できた。
調曞
OSが7.0
そこそこいいスペック
そこそこ軜い
有機ELディスプレむ
短所
OSが7.0(AppShortcutsが䜿えない)
ホヌムキヌがハヌドりェア
バックキヌずタスクキヌが通垞ず逆
Activity のアニメヌションが独自実装されおいる
ClipboardManager の実装がおかしいのか、 LeakCanary で誀怜知されたくる
他の端末ず同じコヌドでフラッシュを制埡できない
  なんか曞いおみたら有機ELディスプレむ以倖の長所がないような気がする。
507SH
13,000円ず非垞に安かったので賌入したずころ、液晶保護フィルムを貌ったずころで満足しお箱にしたっおある。
仕事
モチベヌショングラフを曞くず山から谷たであった。基本、谷の方が倚かった。同期や埌茩のAndroid 開発者が次々ず転職しおいお、 䌚瀟から評䟡されない仕事をしおいるこずぞの焊りが募る幎だった。たあ、どの仕事に割り圓おられるかなど私が決められるものではないから、 運が悪いず思っお諊めるよりほかになく、それが残業れロ運動ず草に぀ながっおいるずいう。
内容で蚀うず、完党にサヌバサむドの仕事がなくなっおAndroid アプリ開発ばかりをやるようになり、 倜䞭に電話がかかっおくるこずがなくなったり䌑日にPCを持っお垰ったりしなくおよくなったのが非垞によかった。   よかったのだが、来幎からたたサヌバサむドの開発ず運甚をやらないずいけなくなりそうで困っおいる。
来幎の抱負
たず DroidKaigi 2018 で発衚する機䌚をいただいた。そこできちんず喋れるように準備をする。
Android アプリを開発する  1぀くらい収益の柱になるアプリを䜜りたい
Qiita の 100蚘事  1,000 Contribution を目指す  達成するずは䞀蚀も蚀っおいない
GitHub の緑化を継続する
0 notes
ayakasuna-blog · 6 years ago
Text
#Day1
Started Java script. Looks tough.
0 notes
thetechnologyspot · 7 years ago
Text
Tweeted
Super Excited to learn @Java this week from @johnowenteachcs!! #Day1 here we go!! @weteachcs #techieteacher #happyteacher
— Hollie Mae Alvarez (@MrsHAlvarez) July 23, 2018
0 notes
hamaguchictrlz-blog · 7 years ago
Text
たったり改造Slackを䜜っお日々の䜜業を楜するRTA Day2
Day2 : botず䌚話しよう
たったり改造Slackを䜜っお日々の䜜業を楜するRTA 日目
こんばんわ、 (HMD|hamaguchi) です。 なんずか1日目の蚘事をTumblrに投皿したものの、1蚘事曞くのに3hかかったり、Tumblrのmarkdownずリッチテキストの倉換がうたくいかなかったりでめちゃめちゃ消耗したした。たた、倉換の結果文章が飛んでるずころがあったので、埌から盎す矜目になりもしたした。昚日の倱敗を反面教垫にしお、今日はHackMDで蚘事を曞いおいたす。 今日は昚日の続きずいうこずで、タヌミナル䞊でなくSlack䞊でbotずやり取りできるようにしたり、botのスクリプトを線集したりしたした。CoffeeScriptは生たれお初めお曞いᅵᅵので結構楜しかったです。
それでは今日も ゆっくりしおいっおね
目次
SlackずHubotを連携する
CoffeeScriptを孊ぶ
botのスクリプトを線集し、おしゃべりする
たずめ
1. SlackずHubotを連携する
今日はたず、昚日もリンクを貌ったこの蚘事(*1)を参考にSlackずHubotの連携をしおいきたす。
最初に、昚日のbotの蚭定ではSlackでやり取りできないので、新たにHubotを䜜り盎したす。昚日ずは別のディレクトリを䜜りHubotを立ち䞊げるコマンドを打ちたす。
// 今回はディレクトリの名前をslack-local-botずする $ mkdir slack-local-bot $ cd slack-local-bot $ yo hubot
これでたた昚日の奎が出るので必芁情報を打ち蟌んでいきたす。
Tumblr media Tumblr media
ここで泚意する必芁があるのが、質問最埌の「Bot Adapter」に察し、昚日ず違い「slack」ず答えるこずです。これを忘れるずslackで動くbotにできないので気を぀けおください。ちゃんず調べおないが、コマンドが終わった埌に生成されおるファむルを曞き換えれば、埌からSlackに察応したbotにできるっぜい
次にSlack䞊でbotが動くようにbotを起動したす。以䞋のコマンドを叩きたす。
HUBOT_SLACK_TOKEN=<MYAPP_HUBOT_TOKEN> bin/hubot --adapter slack
ここでMYAPP_HUBOT_TOKENずいうのは、SlackにHubotを远加した時に生成される文字列です。botのConfigure蚭定を開いたらペヌゞの䞊郚に
HUBOT_SLACK_TOKEN=うんたらかんたら
ず曞いおあり、その「うんたらかんたら」の郚分がTokenに圓たりたす。 Tokenをチェックしたら䞊のコマンドを実行しbotの起動です。adapterずいうオプションに slack を蚭定するのを忘れないようにしたしょう。コマンド実行埌、Slackに移動するずAppsにいるHubotがONLINEになっおるので、DMに「ping」ず送っおみたす。するず...
Tumblr media
これはHubotの初期状態から䜿えるもので、Userのpingに察しbotがPONGず反応する、ずいうコマンドです。
これで䞀応SlackずHubotの連携はできたした。ただこのたたでは味気ないので、ずりあえずスクリプトをいじっおキャラクタヌっぜくしたいず思いたす。
2. CoffeeScriptを孊ぶ
スクリプトをいじる前に、スクリプト蚘述甚に䜿われおいるCoffeeScriptの勉匷をしおおきたいな、ず思ったのでそうしたす。ずりあえず以䞋のこずをしたした。
公匏のDocument(*2)に軜く目を通す
Qiitaを持る
ブログを持る
scriptsディレクトリに最初から入っおる example.coffee を読んでみる
1〜4を飜きるたでやる
特に4は効果的です。2,3ず䞊行しおやればスクリプトによる自由床が䞊がる気がしたす。 勉匷に飜きたらコヌディングです。scriptsディレクトリにスクリプトを䜜りたしょう。
3. botのスクリプトを線集し、おしゃべりする
botをキャラクタヌ森久保乃々っぜくするために、scriptsディレクトリに「Userが『森久保』ず呌びかけたら、あらかじめ蚭定した森久保っぜい口調のセリフをbotが返す」ずいう仕様のスクリプトを甚意したしょう。
scrits以䞋に freetalk.coffee ずいうファむルを䜜り以䞋のように線集したす。
module.exports = (robot) -> robot.hear /森久保/, (res)-> res.send 'な、なんでしょうか...'
コヌドの解説をしおいきたす。 たず1行目ですが、これはJavaでいうpsvm、Cでいう#includeみたいなものです。぀たりはおたじないですね...ただコヌドの実態をちゃんず把握できおない次に2行目ですが、ここで robot.hear ずいう関数を呌び出し、匕数に正芏衚珟ずコヌルバック関数(のようなもの)を枡しおいたす。3行目は関数の䞭身で、res.send でセリフを曞いた文字列を枡しおいたす。この robot.hear ですが、「Slackに打ち蟌たれた文字列ず正芏衚珟に䞀臎が合った時、第二匕数の関数を呌び出す」ずいう関数なので、この堎合Slackに「森久保」の文字列を含む投皿をすればbotが反応し「な、なんでしょうか...」ず喋るずいうこずになりたす。それでは実践しおみたしょう
Tumblr media Tumblr media Tumblr media
「森久保」の文字列を含めば反応するのでなんか面癜いこずになっおたす他人事 でもずりあえずbotず思い通りなおしゃべりできたので今日はOKです
4. たずめ
今日はここたで
今日やったこず
botずSlack䞊でおしゃべりしたよ①
「ping」→「PONG」
CoffeeScriptの勉匷をしたよ
botのスクリプトを線集しお呌びかけに察応するようにしたよ
botずSlack䞊でおしゃべりしたよ②
キャラの口調っぜくレスポンスが垰っおくる
それではDay3でたた䌚いたしょう
匕甚など
蚘事(*1): SlackのBot(hubot)を䜜っおみる URL: https://qiita.com/mochidamochiko/items/29c2d77715d8a1ff062a
蚘事(*2): CoffeeScript 公匏ペヌゞ URL: http://coffeescript.org/
0 notes
iyarpage · 7 years ago
Text
Adaptive UI Tutorial for Android with Kotlin
Update Note: This tutorial is now up to date with the latest version of Android Studio version 3.0.1, and uses Kotlin for app development. Update by Joe Howard. Original tutorial by James Nocentini.
Android runs on a wide variety of devices that offer different screen sizes and densities. Because of this, it is important for Android apps to have a responsive user interface that can adapt to these different screens. Since the early days of the Android platform, system APIs have provided very powerful abstractions to design adaptive UIs, also known as adaptive layouts.
This is an update to our adaptive UI in Android tutorial which will show you how to build apps that work across different devices by dealing with the fragmentation in the Android device market. You’ll learn about:
Configuration qualifiers
Alternative layouts and drawables
And layout previews in Android Studio — an immensely useful tool
What would a tutorial be without something to tinker with? It’d be pretty boring. So, you’ll build the user interface for a simple weather app completely from scratch! When you’re done, the screen will display an image, text labels and a map in three different configurations. Apps look so cool and well built when they have an adaptive UI. :]
Getting Started
Download the starter project named Adaptive Weather here, and open it in Android Studio 3.0.1 or later. Then build and run.
The app displays a simple RecyclerView listing several cities.
To learn all about RecyclerViews, we recommend reading our Android RecyclerView tutorial.
Open the build.gradle file of the app module to declare the following dependency:
dependencies { ... implementation 'com.google.android:flexbox:0.3.2' }
Google’s FlexBox provides an implementation of the FlexBox specification on the Android platform. As you will see later on, it is a very useful tool for designing adaptive layouts. And combining it with Android’s resource qualifier system makes it even more powerful!
Note: The Android platform is constantly updated and the version numbers may have increased since we published this tutorial. You can find details of the different versions, including the most recent on the support library pages on the Android developer site.
During this tutorial, you’ll often switch between the Android and Project modes in the Project navigator. Generally speaking:
Android mode is the default when working within Android Studio because it provides a clean and simple file structure.
Project mode is also necessary for building alternative layouts.
Weather Icons
Android devices have different screen densities, and for that reason it’s a good practice to import static images in multiple sizes. This is one way Android’s system APIs provide a way to create adaptive UIs. As described in the Supporting Multiple Screens guide, the categories of screen densities are:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Whilst some UI editors make it easy to export images in different sizes, we will be exploring a different approach in this tutorial. Android Studio recently added support for Vector Drawables. This means that all your assets can be imported once and will be scaled at runtime depending on the device configuration (screen size and orientation).
Download the Weather Icons and extract. In Android Studio right-click on res/drawable and click on the New\Vector Asset menu item:
Select Local file (SVG, PSD) under Asset Type. From the filesystem location chooser under Path locate the weather-icons folder and choose the first icon, cloud.svg. Make sure to check the Override under Size setting otherwise your icons will look a bit distorted later on (¯\_(ツ)_/¯). Click Next and Finish:
Now you should see your icon in Android Studio as res/drawable/ic_cloud.xml. Repeat the same operations for the other icons: fog, rain, snow, sun, thunder.
Finally, enable the use of Vector Drawables in the app module’s build.gradle as follows:
android { ... defaultConfig { ... vectorDrawables.useSupportLibrary = true } }
With scalable assets now in place in the project, you’re ready to start customizing the layouts.
Building layouts
With the dependencies declared, you get to shift your focus to building some layouts!
This simple application only contains one screen, which is represented by MainActivity. From the Project navigator, open res/layout/activity_main.xml. Click on the Preview button on the right side to see it in action.
An activity comprises a Kotlin or Java class — in this case MainActivity.kt — and a layout file. In fact, one activity can have several layouts, as you’ll see shortly. For now, it’s important to remember that the existing layout file, activity_main.xml, is the default layout.
Forecast Grid View
First, define the default layout for your main activity. To start this, open res/values/colors.xml and replace its content with the following:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="color_primary">#9B26AF</color> <color name="color_primary_dark">#89229b</color> <color name="text_color_primary">#ffffff</color> <color name="forecast_grid_background">#89bef2</color> </resources>
Here you’re overriding the default Material theme colors and providing a background color for the forecast grid. Next, right-click on the values folder and select the New\Value resource file menu:
Enter fractions.xml for the file name and paste the following:
<?xml version="1.0" encoding="utf-8"?> <resources> <item name="weather_icon" type="fraction">33%</item> </resources>
Here you’re specifying that the width taken by each icon should be 1/3 of the total width.
Next, create a new layout in res/layout called forecast_grid.xml and add the following list of images inside a FlexboxLayout:
<?xml version="1.0" encoding="utf-8"?> <com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/forecast" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/forecast_grid_background" app:alignItems="center" app:flexWrap="wrap" app:justifyContent="space_around"> <android.support.v7.widget.AppCompatImageView android:id="@+id/day1" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_thunder" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/day2" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_fog" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/day3" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_rain" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/day4" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_snow" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/day5" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_cloud" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/day6" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_sun" /> </com.google.android.flexbox.FlexboxLayout>
There are a couple things to note with the above block:
You’re using the com.google.android.flexbox.FlexboxLayout resource to layout the icons on the screen.
You’re using the android.support.v7.widget.AppCompatImageView resource to draw the weather icons on the screen. You would normally use the ImageView resource with plain images (.png, .jpg) but for Vector Drawables you must use this component instead.
In the Preview pane, you see should the weather icons aligned perfectly:
This is already starting to feel adaptive!
Instead of positioning the icons with margins or using a relative layout you have used the FlexBox properties to spread them symmetrically. If you remove a middle icon for example, the remaining ones will automatically shift to the left to fill in the empty space. This is the true power of using FlexBox in layouts. The forecast grid is now ready to be used in your default layout for the main activity.
Main Activity
Open res/layout/activity_main.xml and replace its contents with the following:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/forecast_grid" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout>
Here’s what is happening in this layout:
Orientation for the LinearLayout is set to vertical
Dimensions: using the layout_weight XML attribute you’re setting each child view to take half of the screen height
Layout reuse: using the include XML tag you’re placing the forecast grid on the top half by referencing the forecast_grid.xml layout. This is one of the core functionalities to creating different layouts without duplicating the code.
Notice that the preview in the editor gets instantly updated. At this point you still haven’t deployed the application to a device or emulator which is astonishing.
Build and run. You should now see the weather icons above the list of locations.
Updating the Weather Forecast
Take a look at the static JSON data in assets/data.json. The forecast for a given location is represented as an array of strings. You could create another RecyclerView with a GridLayout to dynamically create the forecast, but that’s asking for trouble :]. Instead you will write a method that maps each possible forecast value to a corresponding drawable icon.
In MainActivity, add a new method:
private fun mapWeatherToDrawable(forecast: String): Drawable? { var drawableId = 0 when (forecast) { "sun" -> drawableId = R.drawable.ic_sun "rain" -> drawableId = R.drawable.ic_rain "fog" -> drawableId = R.drawable.ic_fog "thunder" -> drawableId = R.drawable.ic_thunder "cloud" -> drawableId = R.drawable.ic_cloud "snow" -> drawableId = R.drawable.ic_snow } return ContextCompat.getDrawable(this, drawableId) }
Now you are ready to write the code that responds to the click event of a RecyclerView row. Add the following method to MainActivity:
private fun loadForecast(forecast: List<String>) { val forecastView = findViewById<View>(R.id.forecast) as FlexboxLayout for (i in 0 until forecastView.childCount) { val dayView = forecastView.getChildAt(i) as AppCompatImageView dayView.setImageDrawable(mapWeatherToDrawable(forecast[i])) } }
Then find // TODO in MainActivity and replace it with the following:
loadForecast(location.forecast)
Build and run. Click on a location name and notice the weather forecast gets updated:
Good job, what a beautiful looking weather application! The weather in San Francisco isn’t looking so beautiful though :].
Creating Adaptive UI: Landscape Layout
So far, you built this application with the portrait mode in mind but let’s take a look at what happens when the phone is rotated to landscape. Open activity_main.xml, in the layout editor click on the orientation icon, and choose Switch to Landscape:
At this stage, you could run the app on multiple Android devices or simulators. But this method of testing alternative layouts is time consuming and repetitive at best, and error prone at worst. There must be another way.
Thankfully, Android Studio has extensive previewing capabilities. Open the default activity_main.xml file, and hover your mouse over the bottom right corner of the screen to resize the layout. Notice that upon clicking the handle, Android Studio automatically displayed guides for different device sizes.
Ugh — landscape mode is none too kind to your design. Let’s try to have both views side by side instead. To tell the system which resource to pick for a given dimension, you place the layout resource in a folder named in a particular way. The system will pick the correct activity layout for the current device’s screen dimensions. This way, you will have adaptive UIs for your app.
Layout qualifiers
Back in Android Studio, right-click on res/layout and click on the New\Layout resource file menu:
Name the file activity_main and add the landscape resource qualifier:
The layout editor now shows a blank screen for the landscape mode because it picked the newly-created layout file layout-land/activity_main.xml. This only contains an empty ConstraintLayout, though not for much longer :]. Add the following to reuse the weather forecast layout and RecyclerView in a horizontal orientation this time.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <include layout="@layout/forecast_grid" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> </LinearLayout>
And the layout editor now shows all your elements in landscape orientation.
Well done! You have created the first layout qualifier in this application. There are layout qualifiers for plenty of other configurations (screen width, height, aspect ratio etc.). In the next section we will modify the landscape layout even further with just a one-line change.
Resource qualifiers
Another enhancement you could make to the layout is to organize the weather icons as 2 columns and 3 rows as opposed to the current 3 columns and 2 rows layout. We could duplicate the forecast_grid.xml layout, but then it would be duplicated code and harder to maintain. The width occupied by each weather icon in relation to the FlexBox view width is determined by the layout_flexBasisPercent attribute:
<android.support.v7.widget.AppCompatImageView android:id="@+id/day1" android:layout_width="wrap_content" android:layout_height="60dp" app:layout_flexBasisPercent="@fraction/weather_icon" app:srcCompat="@drawable/ic_thunder" />
The value is a fraction type and is currently equal to 33% in the resource qualifier file res/values/fractions.xml. Following the same approach to creating a landscape layout, you can create resource files for the landscape configuration. Right-click on res/values and select the New\Values resource file menu item. Name the file fractions and add the landscape orientation qualifier:
Inside the resources XML tag, add the following:
<item name="weather_icon" type="fraction">49%</item>
Return to the main activity layout in landscape mode and notice the weather icons are laid out on 2 columns and 3 rows:
Well done! You can pause here and appreciate the fact that once again, you didn’t have to deploy the application to achieve this result. Of course now you should build & run though and make sure it works :]
The configuration qualifiers can be applied to any attribute type in your XML layout (font size, colors, margins etc.).
Extra Large Layout
Return to the portrait orientation in the layout editor and drag the screen size all the way to the X-Large size range.
For devices with that much screen real estate, you could show all the weather icons on 1 row. Go ahead and right-click on res/values and select the New\Values resource file menu item. Name the file fractions and add the X-Large Size qualifier:
Add the following inside the resources XML tag:
<item name="weather_icon" type="fraction">16%</item>
Return to the layout editor and notice that all the weather icons are aligned on 1 row.
Configuration Calculations
Don’t worry, the content in this section isn’t as scary as the title makes it sound. When the user interacts with the application, the layout state changes over time (rows are selected, input fields populated with text etc.). When the layout changes (for example when the orientation changes), the existing layout is thrown away a new layout is inflated. But the system has no way of knowing how to restore the state because the two layouts could be completely different as far as it knows.
To see a live example of this in action, build and run the application. Select a location then change the orientation and notice the location isn’t selected anymore!
If you are not already surprised that the forecast in London is sunny all week then you may also notice that the selected row was deselected after switching to landscape.
To fix this, you will hook into the activity lifecycle methods to save the selected location to a bundle and retrieve after the screen rotation.
Add the following at the top of MainActivity, below the properties:
companion object { private const val SELECTED_LOCATION_INDEX = "selectedLocationIndex" }
Then add the following method to MainActivity below the onCreate() method:
override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putInt(SELECTED_LOCATION_INDEX, locationAdapter.selectedLocationIndex) }
Add the following to the end of onCreate():
if (savedInstanceState != null) { val index = savedInstanceState.getInt(SELECTED_LOCATION_INDEX) if (index >= 0 && index < locations.size) { locationAdapter.selectedLocationIndex = index loadForecast(locations[index].forecast) } }
Build and run again and this time the location remains selected across configuration changes. Hooray!
Where to Go From Here
Well done! You’ve built your first Android app with adaptive layouts and you learned how activities can make use of multiple layouts. You learned how drawables work with different displays, and how to make your app come to life on practically any Android device.
Of course, there's a lot more to Android than layouts, and no shortage of ways to build on the adaptive UI principles you discovered in this adaptive UI for Android tutorial. To learn more, check out Google's guidelines on the best UI practices. If you want, you can challenge yourself by trying the following:
Use another available qualifier to have yet another type of layout. For example, what if you'd like to have a different background color based on the locale qualifier?
Or, try using size qualifier on other resources, such as strings. You could add a TextView which shows a short message, or a longer message with the same name if the screen is in landscape?
Get the full source code for this project as a downloadable zip.
Feel free to share your feedback, findings or ask any questions in the comments below or in the forums. Talk to you soon!
The post Adaptive UI Tutorial for Android with Kotlin appeared first on Ray Wenderlich.
Adaptive UI Tutorial for Android with Kotlin published first on https://medium.com/@koresol
0 notes
muthiarys · 8 years ago
Photo
Tumblr media
Morgan James at Java Jazz Festival 2017. #Day1 #javajazzfestival #javajazz2017 #BNI46 #BNIJJFPhotoContest #matacokelat_ #muthiarys
0 notes
satvikaudrie · 8 years ago
Photo
Tumblr media
Java Jazz Festival 2017 #Day1 #temantulus 😍
0 notes