1. Konfigurasi HP Android Kamu Menjadi Develover
2. Konekan HP Android Kamu Ke Komputer
3. Installkan Driver di SO Windows anda
4. Instalkan Aplikasi Yang udah di buat di HP Android kamu
Kalo Kurang Jelas Lihat Video dar Google di bawah ini
<?xml version="1.0" encoding="utf-8"?>
<!-Setting the linear layout with horizontal orientation-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- Button1 -->
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple" />
<!-- Button2 -->
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Codestuffs" />
<!-- Button3 -->
<Button
android:id="@+id/button3"
android:layout_width="0dip"
android:layout_height="0dip"
android:text=".com"
android:layout_weight="1"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-Setting the linear layout with vertical orientation-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Button1 -->
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple" />
<!-- Button2 -->
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Codestuffs" />
<!-- Button3 -->
<Button
android:id="@+id/button3"
android:layout_width="0dip"
android:layout_height="0dip"
android:text=".com"
android:layout_weight="1"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-Setting the relative layout with horizontal orientation--><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Button1 -->
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple"/>
<!-- Button2 -->
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Codestuffs"<!-- Use of rightof to place button2 to right of button 1 -->
android:layout_toRightOf="@+id/button1"/>
<!-- Button3 -->
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=".com"<!-- Use of below to place button3 below button 2 -->
android:layout_below="@+id/button2"/>
</RelativeLayout>
1. implementation 'com.android.support:appcompat-v7:27.1.1'
2. implementation 'com.android.support:design:27.1.1'
3.
4. //anko
5. implementation "org.jetbrains.anko:anko:$anko_version"
6. implementation "org.jetbrains.anko:anko-design:$anko_version"
7.
8. // RecyclerView-v7
9. implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
10. implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"
11.
12. implementation 'com.squareup.picasso:picasso:2.71828'
13. implementation 'com.google.code.gson:gson:2.8.5'
1. private lateinit var listTeam: RecyclerView
2. private lateinit var progressBar: ProgressBar
3. private lateinit var swipeRefresh: SwipeRefreshLayout
4. private lateinit var spinner: Spinner
1. linearLayout {
2. lparams (width = matchParent, height = wrapContent)
3. orientation = LinearLayout.VERTICAL
4. topPadding = dip(16)
5. leftPadding = dip(16)
6. rightPadding = dip(16)
7.
8. spinner = spinner ()
9. swipeRefresh = swipeRefreshLayout {
10. setColorSchemeResources(colorAccent,
11. android.R.color.holo_green_light,
12. android.R.color.holo_orange_light,
13. android.R.color.holo_red_light)
14.
15. relativeLayout{
16. lparams (width = matchParent, height = wrapContent)
17.
18. listTeam = recyclerView {
19. lparams (width = matchParent, height = wrapContent)
20. layoutManager = LinearLayoutManager(ctx)
21. }
22.
23. progressBar = progressBar {
24. }.lparams{
25. centerHorizontally()
26. }
27. }
28. }
29. }
1. buildConfigField "String", "BASE_URL", "\"https://www.thesportsdb.com/\""
2. buildConfigField "String", "TSDB_API_KEY", "\"1\""
1. class ApiRepository {
2.
3. fun doRequest(url: String): String {
4. return URL(url).readText()
5. }
6. }
1. object TheSportDBApi {
2. fun getTeams(league: String?): String {
3. return BuildConfig.BASE_URL + "api/v1/json/${BuildConfig.TSDB_API_KEY}" + "/search_all_teams.php?l=" + league
4. }
5. }
1. fun getTeams(league: String?): String {
2. return Uri.parse(BuildConfig.BASE_URL).buildUpon()
3. .appendPath("api")
4. .appendPath("v1")
5. .appendPath("json")
6. .appendPath(BuildConfig.TSDB_API_KEY)
7. .appendPath("search_all_teams.php")
8. .appendQueryParameter("l", league)
9. .build()
10. .toString()
11. }
1. data class Team(
2. @SerializedName("idTeam")
3. var teamId: String? = null,
4.
5. @SerializedName("strTeam")
6. var teamName: String? = null,
7.
8. @SerializedName("strTeamBadge")
9. var teamBadge: String? = null
10. )
1. data class TeamResponse(
2. val teams: List<Team>)
1. interface MainView {
2. fun showLoading()
3. fun hideLoading()
4. fun showTeamList(data: List<Team>)
5. }
1. class MainPresenter(private val view: MainView,
2. private val apiRepository: ApiRepository,
3. private val gson: Gson) {
4. }
1. fun getTeamList(league: String?) {
2. view.showLoading()
3. doAsync {
4. val data = gson.fromJson(apiRepository
5. .doRequest(TheSportDBApi.getTeams(league)),
6. TeamResponse::class.java
7. )
8.
9. uiThread {
10. view.hideLoading()
11. view.showTeamList(data.teams)
12. }
13. }
14. }
1. class MainAdapter (private val teams: List<Team>) {
2.
3. }
1. class MainAdapter (private val teams: List<Team>)
2. : RecyclerView.Adapter<TeamViewHolder>(){
3.
4.
5. }
6.
7. class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view){
8.
9.
10. fun bindItem(teams: Team) {
11.
12. }
13. }
1. class MainAdapter (private val teams: List<Te>am)
2. : RecyclerView.Adapter<TeamViewHolder>(){
3. override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): TeamViewHolder {
4. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
5. }
6.
7. override fun getItemCount(): Int {
8. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
9. }
10.
11. override fun onBindViewHolder(holder: TeamViewHolder?, position: Int) {
12. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
13. }
14.
15. }
16.
17. class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view){
18.
19.
20. fun bindItem(teams: Team) {
21.
22. }
23. }
1. class TeamUI : AnkoComponent<ViewGroup> {
2. override fun createView(ui: AnkoContext<ViewGroup>): View {
3. return with(ui) {
4. linearLayout {
5. lparams(width = matchParent, height = wrapContent)
6. padding = dip(16)
7. orientation = LinearLayout.HORIZONTAL
8.
9. imageView {
10. id = R.id.team_badge
11. }.lparams{
12. height = dip(50)
13. width = dip(50)
14. }
15.
16. textView {
17. id = R.id.team_name
18. textSize = 16f
19. }.lparams{
20. margin = dip(15)
21. }
22.
23. }
24. }
25. }
26.
27. }
1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
3. <item name="team_badge" type="id" />
4. <item name="team_name" type="id" />
5. </resources>
1. private val teamBadge: ImageView = view.find(team_badge)
2. private val teamName: TextView = view.find(team_name)
1. fun bindItem(teams: Team) {
2. Picasso.get().load(teams.teamBadge).into(teamBadge)
3. teamName.text = teams.teamName
4. }
1. override fun getItemCount(): Int = teams.size
1. holder.bindItem(teams[position])
1. class MainAdapter(private val teams: List<Team>)
2. : RecyclerView.Adapter<TeamViewHolder>() {
3.
4. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TeamViewHolder {
5. return TeamViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent)))
6. }
7.
8. override fun onBindViewHolder(holder: TeamViewHolder, position: Int) {
9. holder.bindItem(teams[position])
10. }
11.
12. override fun getItemCount(): Int = teams.size
13.
14. }
15.
16. class TeamUI : AnkoComponent<ViewGroup> {
17. override fun createView(ui: AnkoContext<ViewGroup>): View {
18. return with(ui) {
19. linearLayout {
20. lparams(width = matchParent, height = wrapContent)
21. padding = dip(16)
22. orientation = LinearLayout.HORIZONTAL
23.
24. imageView {
25. id = R.id.team_badge
26. }.lparams{
27. height = dip(50)
28. width = dip(50)
29. }
30.
31. textView {
32. id = R.id.team_name
33. textSize = 16f
34. }.lparams{
35. margin = dip(15)
36. }
37.
38. }
39. }
40. }
41.
42. }
43.
44. class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view){
45.
46. private val teamBadge: ImageView = view.find(team_badge)
47. private val teamName: TextView = view.find(team_name)
48.
49. fun bindItem(teams: Team) {
50. Picasso.get().load(teams.teamBadge).into(teamBadge)
51. teamName.text = teams.teamName
52. }
53. }
1. private var teams: MutableList<Team> = mutableListOf()
2. private lateinit var presenter: MainPresenter
3. private lateinit var adapter: MainAdapter
1. adapter = MainAdapter(teams)
2. listTeam.adapter = adapter
3.
4. val request = ApiRepository()
5. val gson = Gson()
6. presenter = MainPresenter(this, request, gson)
1. private lateinit var leagueName: String
1. val spinnerItems = resources.getStringArray(league)
2. val spinnerAdapter = ArrayAdapter(ctx, android.R.layout.simple_spinner_dropdown_item, spinnerItems)
3. spinner.adapter = spinnerAdapter
1. <array name="league">
2. <item>English Premier League</item>
3. <item>English League Championship</item>
4. <item>German Bundesliga</item>
5. <item>Italian Serie A</item>
6. <item>French Ligue 1</item>
7. <item>Spanish La Liga</item>
8. </array>
1. spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
2. override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
3. leagueName = spinner.selectedItem.toString()
4. presenter.getTeamList(leagueName)
5. }
6.
7. override fun onNothingSelected(parent: AdapterView<*>) {}
8. }
1. class MainActivity : AppCompatActivity(), MainView {
2.
3. private var teams: MutableList<Team> = mutableListOf()
4. private lateinit var presenter: MainPresenter
5. private lateinit var adapter: MainAdapter
6. private lateinit var listTeam: RecyclerView
7. private lateinit var progressBar: ProgressBar
8. private lateinit var swipeRefresh: SwipeRefreshLayout
9. private lateinit var spinner: Spinner
10. private lateinit var leagueName: String
11.
12.
13. override fun onCreate(savedInstanceState: Bundle?) {...}
14.
15.
16. override fun showLoading() {
17. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
18. }
19.
20. override fun hideLoading() {
21. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
22. }
23.
24. override fun showTeamList(data: List<Team>) {
25. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
26. }
27.
28. }
1. fun View.visible() {
2. visibility = View.VISIBLE
3. }
4.
5. fun View.invisible() {
6. visibility = View.INVISIBLE
7. }
1. override fun showLoading() {
2. progressBar.visible()
3. }
4.
5. override fun hideLoading() {
6. progressBar.invisible()
7. }
1. override fun showTeamList(data: List<Team>) {
2. swipeRefresh.isRefreshing = false
3. teams.clear()
4. teams.addAll(data)
5. adapter.notifyDataSetChanged()
6. }
1. swipeRefresh.onRefresh {
2. presenter.getTeamList(leagueName)
3. }
1. class MainActivity : AppCompatActivity(), MainView {
2. private var teams: MutableList<Team> = mutableListOf()
3. private lateinit var presenter: MainPresenter
4. private lateinit var adapter: MainAdapter
5. private lateinit var listTeam: RecyclerView
6. private lateinit var progressBar: ProgressBar
7. private lateinit var swipeRefresh: SwipeRefreshLayout
8. private lateinit var spinner: Spinner
9. private lateinit var leagueName: String
10.
11. override fun onCreate(savedInstanceState: Bundle?) {
12. super.onCreate(savedInstanceState)
13. linearLayout {
14. lparams (width = matchParent, height = wrapContent)
15. orientation = LinearLayout.VERTICAL
16. topPadding = dip(16)
17. leftPadding = dip(16)
18. rightPadding = dip(16)
19.
20. spinner = spinner ()
21. swipeRefresh = swipeRefreshLayout {
22. setColorSchemeResources(colorAccent,
23. android.R.color.holo_green_light,
24. android.R.color.holo_orange_light,
25. android.R.color.holo_red_light)
26.
27. relativeLayout{
28. lparams (width = matchParent, height = wrapContent)
29.
30. listTeam = recyclerView {
31. lparams (width = matchParent, height = wrapContent)
32. layoutManager = LinearLayoutManager(ctx)
33. }
34.
35. progressBar = progressBar {
36. }.lparams{
37. centerHorizontally()
38. }
39. }
40. }
41. }
42.
43. val spinnerItems = resources.getStringArray(league)
44. val spinnerAdapter = ArrayAdapter(ctx, android.R.layout.simple_spinner_dropdown_item, spinnerItems)
45. spinner.adapter = spinnerAdapter
46.
47. adapter = MainAdapter(teams)
48. listTeam.adapter = adapter
49.
50. val request = ApiRepository()
51. val gson = Gson()
52. presenter = MainPresenter(this, request, gson)
53.
54. spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
55. override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
56. leagueName = spinner.selectedItem.toString()
57. presenter.getTeamList(leagueName)
58. }
59.
60. override fun onNothingSelected(parent: AdapterView<*>) {}
61. }
62.
63. swipeRefresh.onRefresh {
64. presenter.getTeamList(leagueName)
65. }
66. }
67.
68. override fun showLoading() {
69. progressBar.visible()
70. }
71.
72. override fun hideLoading() {
73. progressBar.invisible()
74. }
75.
76. override fun showTeamList(data: List<Team>) {
77. swipeRefresh.isRefreshing = false
78. teams.clear()
79. teams.addAll(data)
80. adapter.notifyDataSetChanged()
81. }
82.
83. }
1. <uses-permission android:name="android.permission.INTERNET"/>