본문 바로가기

Full Stack 교육 회고록

2022-12-01 - 안드로이드스튜디오 컬러팔레트 만들기

728x90
SMALL

프로그래밍 언어!!
사람과 기계가 소통기계어1 or 0 -> 전류를 흐르게 1, 흐르지 않게 01, 0 -> bit
1bit -> 2가지
2bit -> 4가지
3bit -> 8가지 : 2^3IPv4
0 ~ 255 . 0 ~ 255. 0 ~ 255. 0 ~ 255
32bitIPv6
128bit
127.0.0.1int result = a + b;10진수 -> 가능한 숫자표현이 10가지
-> 10이되면 자리가 하나 증가함2진수 -> 가능한 숫자 표현이 2가지
-> 2가되면 자리가 하나 증가함8진수 -> 가능한 숫자 표현이 8가지
-> 8이되면 자리가 하나 증감올해 나이 21
-> 25(8) -> 2 x 8^1 + 5 x 8^0 = 2116진수 -> 가능한 숫자 표현이 16가지
-> 16이 되면 자릿수 증가0 1 2 3 4 5 6 7 8 9 A B C D E F255라는 10진수 -> 16진수
F -> 10 -> 11 -> 12 -> 13 -> .. -> 1F -> 20
20(16) -> 16^0 x 1 + 16^1 x 2 = 33FF256 -> 100(16) - 1 = 0FF1010101110101011
10001011 10101011
00011011 10101011


네트워크 통신 - Client/Server

Volley 동작원리

 

CSV : 용량이 적지만 가독성이 떨어진다

JSON(JavaScript Object Notation) 속상-값 쌍으로 이루어진 데이터를 전달하기 위한 개방형 표준 포맷

 

http://json.parser.online.fr/

 

Json Parser Online

 

json.parser.online.fr

reponse가 JsonObject 타입

 

boxOfficeResult가 JsonObject

 

dailyBoxOfficeList

JsonArray

 

10..array의 크기만큼 접근

 

1. rank

2. rankOldAndNew

3. MovieNm

4. audiAcc

5. openDt

 

 

1. Json 데이터에서 필요한것 꺼내서 movies에 담아놓은 상태 (영화이름, 개봉일, 관객수, old, rank)

 

RecyclerView

1. 어디에 RecyclerView를 넣을지 정하자

2. 한칸에 들어갈 디자인 (Template 만들기) movielist.xml

3. data --> movies

4. adapter 만들기 MovieAdapter

:

5. rc에 adapter 적용

 

 

[영화진흥위원회 오픈 API]

https://kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=f5eef3421c602c6cb7ea224104795888&targetDt=20221130 

 

 

 

[ExamActivity]

package com.example.ex221130

import android.content.Context
import android.content.Intent
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.constraintlayout.widget.ConstraintLayout

class ExamActivity : AppCompatActivity() {

    lateinit var clExam : ConstraintLayout

    override fun onRestart() {
        super.onRestart()
        val sharedPreferences = getSharedPreferences("sp1", Context.MODE_PRIVATE)
        val color = sharedPreferences.getString("bgColor", "white")
        clExam.setBackgroundColor(Color.parseColor(color))
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_exam)

        // 로그인 기능!!
        // 자동 로그인
        // Application을 종료해도
        // 정보가 저장될 필요성이 있다
        // DataBase
        // - RDB (Relational DataBase)
        // - RDBMS
        //  -> OracleDB
        //  -> MySQL
        //  -> MariaDB
        // SQL -> 쿼리문!!
        // NoSQL -> (Key, Value)

        // SQLite -> 실제 데이터베이스 안드로이드 내장
        // SharedPreference -> 환경설정정보들을 공유하기 위해!!
        // NoSQL -> Key, Value
        // 버튼 -> 그리드 -> 리니어 -> 그리드

        val btnRed = findViewById<Button>(R.id.btnRed)
        val btnPink = findViewById<Button>(R.id.btnPink)
        val btnBlack = findViewById<Button>(R.id.btnBlack)
        val btnOther = findViewById<Button>(R.id.btnOther)

        clExam = findViewById<ConstraintLayout>(R.id.clExam)

        // tvResult : 변수!!
        // PI = 3.141592 : 상수!!
        val sharedPreferences = getSharedPreferences("sp1", Context.MODE_PRIVATE)

        // MODE_PRIVATE : 생성한 application 내에서만 공유 가능
        // MODE_WORLD_READABLE : 다른 application 에서 읽을 수 있음
        // MODE_WORLD_WRITEABLE : 다른 application 에서 읽고 쓸 수 있음

        val bgColor:String? = sharedPreferences.getString("bgColor", "white")
        clExam.setBackgroundColor(Color.parseColor(bgColor))

        btnRed.setOnClickListener {
            val editor = sharedPreferences.edit()
            val color:String = "#FF0000"
            editor.putString("bgColor", color)
            editor.commit()

            clExam.setBackgroundColor(Color.parseColor(color))
        }
        btnPink.setOnClickListener {
            val editor = sharedPreferences.edit()
            val color:String = "#E91E63"
            editor.putString("bgColor", color)
            editor.commit()
            clExam.setBackgroundColor(Color.parseColor(color))
        }
        btnBlack.setOnClickListener {
            val editor = sharedPreferences.edit()
            val color:String = "#000000"
            editor.putString("bgColor", color)
            editor.commit()
            clExam.setBackgroundColor(Color.parseColor(color))
        }

        btnOther.setOnClickListener {
            val intent = Intent(this, ColorActivity::class.java)
            startActivity(intent)
        }




    }
}

[activity_exam.xml]

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/clExam"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ExamActivity">

    <Button
        android:id="@+id/btnRed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:text="빨간색"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnPink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:text="핫핑크"
        app:layout_constraintBottom_toBottomOf="@+id/btnRed"
        app:layout_constraintStart_toEndOf="@+id/btnRed"
        app:layout_constraintTop_toTopOf="@+id/btnRed" />

    <Button
        android:id="@+id/btnBlack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:text="검정"
        app:layout_constraintBottom_toBottomOf="@+id/btnPink"
        app:layout_constraintStart_toEndOf="@+id/btnPink"
        app:layout_constraintTop_toTopOf="@+id/btnPink" />

    <Button
        android:id="@+id/btnOther"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="다른 색상"
        app:layout_constraintEnd_toEndOf="@+id/btnBlack"
        app:layout_constraintStart_toStartOf="@+id/btnRed"
        app:layout_constraintTop_toBottomOf="@+id/btnPink" />
</androidx.constraintlayout.widget.ConstraintLayout>

[activity_color.xml]

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ColorActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvColor"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

[color_list.xml]

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/clColor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textView"
        android:layout_width="10dp"
        android:layout_height="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

[ColorActivity]

package com.example.ex221130

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class ColorActivity : AppCompatActivity() {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_color)

        //1. Container 설정
        val rvColor = findViewById<RecyclerView>(R.id.rvColor)

        //2. Template 설정
        //color_List.xml

        //3. Item 설정
        val colorList = ArrayList<ColorVO>()
        var color: String

        // "#" + red(16) + green(16) + blue(16)
        for (i in 0..255 step 32) {
            var red: String = Integer.toHexString(i)

            for (j in 0..255 step 32) {
                var green: String = Integer.toHexString(j)

                for (k in 0..255 step 32) {
                    var blue: String = Integer.toHexString(k)

                    if(red.length == 1){red = "0" + red}
                    if(green.length == 1){green = "0" + green}
                    if(blue.length == 1){blue = "0" + blue}

                    color = "#$red$green$blue"
                    colorList.add(ColorVO(color))
                }

            }

        }



        //4. Adapter 설정
        val adapter = ColorAdapter(this, colorList)

        //5. Container 에 Adapter 부착
        rvColor.adapter = adapter
        //rvColor.layoutManager = GridLayoutManager(this, 10)
        //rvColor.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
        rvColor.layoutManager = GridLayoutManager(this,32)
    }
}

[ColorAdapter]

package com.example.ex221130

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView

class ColorAdapter(val context: Context, val colorList: ArrayList<ColorVO>):
RecyclerView.Adapter<ColorAdapter.ViewHolder>(){

    inner class ViewHolder(itemView : View)
        : RecyclerView.ViewHolder(itemView){
            val clColor : ConstraintLayout

            init {
                clColor = itemView.findViewById<ConstraintLayout>(R.id.clColor)

                itemView.setOnClickListener {
                    val position = adapterPosition
                    val color = colorList.get(position).color
                    val sharedPreferences = context.getSharedPreferences("sp1", Context.MODE_PRIVATE)
                    val editor = sharedPreferences.edit()
                    editor.putString("bgColor", color)
                    editor.commit()
                    (context as Activity).finish()

                    // System.exit(0)
                }
            }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val layoutInflater = LayoutInflater.from(context)
        val view = layoutInflater.inflate(R.layout.color_list, null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val color:String = colorList.get(position).color
        holder.clColor.setBackgroundColor(Color.parseColor(color))
    }

    override fun getItemCount(): Int {
        return colorList.size
    }
}

[ColorVO]

package com.example.ex221130

class ColorVO(val color: String) {
}
728x90
LIST