------------------------

 

Intent

Intent를 간단히 생각하면

트럭이라고생각하면된다

출발지와 목적지를 알려주고 내용을 싣는다

번들객체 - 오브젝트를 싣는 곳

 

입력시  put을 사용한다

 

 

 

 

 

shift 따닥

바이트로 바꾼다! (직렬화)

 

 

 

 

 

 

메인액티비티

 

 

안드로이드 내부에서는 Bundle을 사용하면 된다

 

--------------------------

 

---------

(롬복파일 실행해서 고추)

 

 

롬복

 

 

저장소(리파지토리)추가

 

 

 

 

------------------------

 

 

코드 확인

https://github.com/jaybon1/androidwork/tree/master/instagramRecycleView

 

jaybon1/androidwork

Contribute to jaybon1/androidwork development by creating an account on GitHub.

github.com

 

영화 포스터 앱

item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <ImageView
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:src="@drawable/mov01"
        android:layout_alignParentLeft="true"
        android:scaleType="centerCrop"/>

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="99dp"
        android:text="의미없음"
        android:textSize="30sp"
        android:textStyle="bold"
        android:gravity="center"/>

    <View
        android:layout_below="@id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray"/>

</RelativeLayout>

 

 

alt + insert

 

package com.jaybon.movie;

import android.media.Image;
import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class SingleAdapter extends BaseAdapter {

    private static final String TAG = "SingleAdapter";

    // 데이터
    private List<Movie> items = new ArrayList<>();

    public SingleAdapter() {
        items.add(new Movie("써니",R.drawable.mov01));
        items.add(new Movie("완득이",R.drawable.mov02));
        items.add(new Movie("괴물",R.drawable.mov03));
        items.add(new Movie("라디오스타",R.drawable.mov04));
        items.add(new Movie("비열한거리",R.drawable.mov05));
        items.add(new Movie("왕의남자",R.drawable.mov06));
        items.add(new Movie("아일랜드",R.drawable.mov07));
        items.add(new Movie("웰컴투동막골",R.drawable.mov08));
        items.add(new Movie("헬보이",R.drawable.mov09));
        items.add(new Movie("백투더퓨처",R.drawable.mov10));
        items.add(new Movie("여인의향기",R.drawable.mov11));
        items.add(new Movie("쥬라기공원",R.drawable.mov12));
    }

    // 모든건수 받기
    public void addItems(List<Movie> items){
        this.items = items;
    }

    // 한건씩 받기 생략
    
    // getCount과 getItem는 필수!

    @Override
    public int getCount() { // 데이터 사이즈, 최초에 화면을 몇건 만들 것인지
        Log.d(TAG, "getCount: ");
        return items.size();
    }

    @Override
    public Object getItem(int position) { // 아이템 가져오기
        Log.d(TAG, "getItem: ");
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        Log.d(TAG, "getItemId: ");
        return 0;
    }


    // 집중!
    // 메모리에 인플레이트해서 화면에 뿌려주는 것
    @Override
    public View getView(int position, View convertView, ViewGroup parent) { // 포지션값은 제일 밑에 값
        Log.d(TAG, "getView: " +position);

        // 레이아웃 인플레이터로 인플레이터 객체 접근하기
        LayoutInflater inflater = LayoutInflater.from(parent.getContext()); // 인플레이터

        // 메모리에 아이템 하나를 인플레이터하기
        View itemView = inflater.inflate(R.layout.item, parent, false); //아이템뷰

        // View 찾기
        TextView tv = itemView.findViewById(R.id.tv_title); //뷰에서 텍스트뷰 찾기
        ImageView iv = itemView.findViewById(R.id.iv_img_resource); //뷰에서 이미지뷰 찾기

        String title = ((Movie) getItem(position)).getTitle();
        int imageResource = ((Movie) getItem(position)).getImgResource();

        tv.setText(title);
        iv.setImageResource(imageResource);

        return itemView;
    }
}

 

 

--------------------------

어댑터에 5건이 있다면

리스트뷰 - 화면을 이동할 때마다 인플레이터가 계속 많이 실행된다 (뷰가 계속 생성됨) - 세로만가능

리사이클러뷰 - 만들어진 틀에다가 데이터만 교체(뷰는 유지 데이터변경), 뷰홀더 패턴 - 가로세로가능

 

--------------------------

 

리사이클러 뷰

 

https://codinginflow.com/

 

Tutorials - Coding in Flow

⭐ Newest Tutorials 🔠 Language Tutorials Kotlin Android Tutorials 🏛️ Architecture & Best Practices Room + ViewModel + LiveData + RecyclerView (MVVM) Dagger 2 View Binding Data Binding Testing 📏 ... Read more

codinginflow.com

 

 

 

다운로드

 

 

MovieAdapter

 

 

package com.jaybon.recyclerviewmovieex01;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MovieAdapter extends RecyclerView.Adapter<MovieAdapter.MyViewHolder> {

    private static final String TAG = "MovieAdapter";
    
    // 어댑터는 컬렉션을 들고 있어야한다
    private List<Movie> items = new ArrayList<>();


    // 리스트뷰의 getView와 비슷하다
    // 껍데기만! 만들어줌! 1번으로 실행됨
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item,parent,false);
        return new MyViewHolder(view);
    }

    // 껍데기에 데이터 바인딩 해줌. 2번으로 실행됨
    // holder는 뷰홀더의 주소를 가지고 있다
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        // 아이템의 포지션값을 이용해서 데이터를 가져옴
        Movie movie = items.get(position);
        // 홀더에 아이템넣기
        holder.setItem(movie);
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    // ViewHolder (뷰들의 책꽂이)
    public static class MyViewHolder extends RecyclerView.ViewHolder { // 뷰홀더

        // 규칙1 (xml이 들고있는 뷰)
        private TextView tvTitle;
        private ImageView ivImgResource;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);
            ivImgResource = itemView.findViewById(R.id.iv_img_resource);
        }

        // 규칙3
        public void setItem(Movie movie){
            tvTitle.setText(movie.getTitle());
            ivImgResource.setImageResource(movie.getImgResource());
        }

    }

}

 

MainActivity

package com.jaybon.recyclerviewmovieex01;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";
    private RecyclerView rvMovie;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rvMovie = findViewById(R.id.rv_movie);
        MovieAdapter adapter = new MovieAdapter();

        // 외부에서 데이터 받을때 쓰레드로 받아주면 됨
        adapter.addItem(new Movie("써니",R.drawable.mov01));
        adapter.addItem(new Movie("완득이",R.drawable.mov02));
        adapter.addItem(new Movie("괴물",R.drawable.mov03));
        adapter.addItem(new Movie("라디오스타",R.drawable.mov04));
        adapter.addItem(new Movie("비열한거리",R.drawable.mov05));
        adapter.addItem(new Movie("왕의남자",R.drawable.mov06));
        adapter.addItem(new Movie("아일랜드",R.drawable.mov07));
        adapter.addItem(new Movie("웰컴투동막골",R.drawable.mov08));
        adapter.addItem(new Movie("헬보이",R.drawable.mov09));
        adapter.addItem(new Movie("백투더퓨처",R.drawable.mov10));
        adapter.addItem(new Movie("여인의향기",R.drawable.mov11));
        adapter.addItem(new Movie("쥬라기공원",R.drawable.mov12));

        // 레이아웃매니저 설정(버티컬인지 호라이즌인지)
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        rvMovie.setLayoutManager(layoutManager);
        rvMovie.setAdapter(adapter);
    }
}

 

 

----------------

---------------

 

인스타그램 UI에 리사이클러 뷰 넣기

 

 

 

 

 

리사이클러 뷰 아이템은 merge를 사용하지말것

 

https://github.com/jaybon1/androidwork/tree/master/instagramRecycleView

 

jaybon1/androidwork

Contribute to jaybon1/androidwork development by creating an account on GitHub.

github.com

 

 

--------------

 

 

 

 

 

 

 

 

 

MainActivity

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    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=".MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textSize="60sp"
            android:text="메인 액티비티"/>

    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/nav_menu"
        android:layout_gravity="start|left"/>

</androidx.drawerlayout.widget.DrawerLayout>

무조건! 리니어 레이아웃 아래에 배치

레이아웃 위치에 따라 작동 여부가 되는 경우가 있고 안되는 경우가 있다

 

 

---------------

headerLayout = 유저 정보

---------------

 

 

 

 

 

 

SubActivity

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    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=".SubActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textSize="60sp"
            android:text="서브 액티비티"/>

    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/nav_menu"
        android:layout_gravity="start|left"/>

</androidx.drawerlayout.widget.DrawerLayout>

 

 

https://lktprogrammer.tistory.com/168

 

[Android] 안드로이드 - 네비게이션 드로어(Navigation Drawer)를 활용하여 슬라이드 메뉴 구현하기

내비게이션 드로어(Navigation Drawer)는 앱에서 사용 가능한 기능을 탐색할 수 있도록 Menu를 제공하는 화면입니다. 기본적으로 화면의 가장자리에 숨겨져 있으며 왼쪽에서 오른쪽으로 스와이프 동��

lktprogrammer.tistory.com

 

 

package com.jaybon.navigationintentex01;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.material.navigation.NavigationView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";

    private NavigationView nav;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        nav = findViewById(R.id.nav1);

        nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId())
                {
                    case R.id.nav_menu1:
                        Log.d(TAG, "onNavigationItemSelected: 확인1");
                        break;
                    case R.id.nav_menu2:
                        Log.d(TAG, "onNavigationItemSelected: 확인2");
                        break;
                }
                return false;
            }
        });



    }
}

 

 

 

(이렇게 리스너 달지 않는다 ! 연습용이었다고함)

 

 

 

--------

SQL라이트 - ORM - ROOM

---------

MVVM - AAC - SQL라이트 패틴

--------

FCM

-------

 

헬퍼 클래스를 만들어서 리스너 추가

 

NavigationViewHelper

package com.jaybon.navigationintentex01;

import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;

import androidx.annotation.NonNull;

import com.google.android.material.navigation.NavigationView;

public class NavigationViewHelper {
    public static void enableNavigation(final Context context, NavigationView view){
        view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {

                if(item.getItemId() == R.id.nav_menu1){
                    Intent intent = new Intent(context, MainActivity.class);

                    // 싱글탑 플래그 (무조건 1개) 기존것 사용용
                   intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

                    context.startActivity(intent);
                } else if (item.getItemId() == R.id.nav_menu2){
                    Intent intent = new Intent(context, SubActivity.class);

                    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

                    context.startActivity(intent);
                }

                return true;
            }
        });
    }
}

 플래그도 추가하자

 

 

MainActivity

package com.jaybon.navigationintentex01;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.material.navigation.NavigationView;

public class MainActivity extends AppCompatActivity {

    // 아래 두가지는 무조건 만들자
    private static final String TAG = "Main_Activity";
    private Context mContext = MainActivity.this;

    private NavigationView nav;


    @Override
    protected void onNewIntent(Intent intent) { // 싱글탑 플래그일 경우 사용하던 것을 또 사용
        super.onNewIntent(intent);
        Log.d(TAG, "onNewIntent: 호출됨");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 컴포넌트들 가져오기
        init();

        // 네비게이션 메뉴들에 리스너 추가
        NavigationViewHelper.enableNavigation(mContext, nav);

    }

    private void init(){
        nav = findViewById(R.id.nav1);
    }
}

 

 

현재페이지를 또가면 

 

--------------------

영화 포스터 앱 만들기(미완)

 

https://blog.naver.com/getinthere/221694612498

 

안드로이드 3강 - (1) ListView와 GridView와 어댑터를 이용한 영화 포스터 앱 만들기

1. 리스트뷰 연습1+클릭이벤트- ListTest1 프로젝트activity_main.xmlMainActivity.java2. 리스트뷰 연...

blog.naver.com

 

 

토스트 - 컨텍스트 이용

스낵바 - 뷰를 이용하여 컨텍스트를 찾음

대화상자 - 컨텍스트가 필요 없다 ( 새로운 윈도우가 뜬다 )

 

뷰만 알면 컨텍스트를 알 수 있다

 

 

 

 

Test

더보기

package com.jaybon.listviewex01;

import android.content.Context;
import android.widget.Toast;

public class Test {

public static void callToast(Context context){

Toast.makeText(context, "안녕", Toast.LENGTH_SHORT).show();

}

}

 

MainActivity

package com.jaybon.listviewex01;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Context mContext = MainActivity.this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Test.callToast(mContext);

    }
}

 

 

 

-------------------------------------

 

스낵바는 뷰 위에 

 

 

Test

package com.jaybon.listviewex01;

import android.content.Context;
import android.widget.Toast;

public class Test {

    public static void callToast(Context context){

        Toast.makeText(context, "안녕", Toast.LENGTH_SHORT).show();

    }

}

 

MainActivity

package com.jaybon.listviewex01;

        import androidx.appcompat.app.AppCompatActivity;

        import android.content.Context;
        import android.os.Bundle;
        import android.widget.TextView;
        import android.widget.Toast;

        import com.google.android.material.snackbar.Snackbar;

public class MainActivity extends AppCompatActivity {

    private TextView tv1;

    private Context mContext = MainActivity.this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv1 = findViewById(R.id.tv1);


        // 토스트
        Test.callToast(mContext);

        // 스넥바에 텍스트뷰를 넣어보았다
        Snackbar.make(tv1, "Text to display", Snackbar.LENGTH_LONG).show();

    }
}

 

 

225페이지

 

------------

액티비티 매니저 서비스

애플리케이션 컨텍스트 - 모든 액티비티 컨텍스트를 가지고 있다// 아이디를 가지고 있다

액티비티 컨텍스트 - 액티비티 내의 모든 내용을 가지고 있다

뷰 - 역으로 액티비티 컨텍스트, 애플리케이션 컨텍스트를 알 수 있다

getApplicationContext()

 

컨텐트 프로바이더 - 다른앱이 들고 있는 데이터에 접근 할 수 있다.

내 휴대폰 안의 앱들이 데이터를 공유하도록 하게 하는 것
(연락처에 접근하여 전화번호를 가져오거나 하는 기능)

 

-------

뷰모델 - 여러가지 뷰가 섞인 것

------

 

알림 대화상자

package com.jaybon.listviewex01;

        import androidx.appcompat.app.AlertDialog;
        import androidx.appcompat.app.AppCompatActivity;

        import android.content.Context;
        import android.content.DialogInterface;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.Button;
        import android.widget.TextView;
        import android.widget.Toast;

        import com.google.android.material.snackbar.Snackbar;

public class MainActivity extends AppCompatActivity {

    private TextView tv1;
    private Button button;

    private Context mContext = MainActivity.this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv1 = findViewById(R.id.tv1);
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMessage();
            }
        });


        // 토스트
        Test.callToast(mContext);

        // 스넥바에 텍스트뷰를 넣어보았다
        Snackbar.make(tv1, "Text to display", Snackbar.LENGTH_LONG).show();

    }

    private void showMessage(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("안내");
        builder.setMessage("종료하시겠습니까?");

        builder.setPositiveButton("예", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String message = "예 버튼이 눌렸습니다.";
                tv1.setText(message);
            }
        });

        builder.setNeutralButton("취소", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String message = "취소 버튼이 눌렸습니다.";
                tv1.setText(message);
            }
        });

        builder.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String message = "아니오 버튼이 눌렸습니다.";
                tv1.setText(message);
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();

    }
}

 

 

------------------

 

리스트 뷰

 

영화포스터사진.zip
0.41MB

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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=".MainActivity">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

 

 

 

지금 스크롤뷰가 아닌 리스트뷰를 쓰는 이유

스크롤 뷰는 건수를 다 출력하기 때문에 부하가 너무많다

향상된 버전이 리스트 뷰

리스트 뷰는 화면의 높이를 계산하고 하나의 아이템의 높이를 계산한다

이후에는 리사이클러 뷰를 사용한다 (스크롤뷰 -> 리스트뷰 -> 리사이클러뷰)

 

-----------

어댑터패턴 - 강제성이 없다

-----------

 

어댑터가 들고 있는 것
- 전체 데이터의 컬렉션 (전체 사이즈, 인덱스 번호)
- 화면사이즈와 아이템의 사이즈
- 역할 - 스크롤을 올렸다 내렸다 할때마다 생성된 디자인에다가 데이터를 입혀준다
- 메모리관리

 

스크롤뷰는 리스트뷰에 어댑터 패턴을 쓸 수 있도록 한 것이다

 

MainActivity

package com.jaybon.movie;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";
    private Context mContext = MainActivity.this;
    private ListView listView;

    private ArrayAdapter<String> adapter; // 나중에는 안쓴다
    private List<String> mid = Arrays.asList(
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아"
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = findViewById(R.id.list_view);

        // 어댑터는 액티비티/  디자인(사이즈) / 데이터
        adapter = new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1, mid);
        listView.setAdapter(adapter);

    }
}

 

 

15개의 인플레이터 된 데이터가 있다 (화면에 보이지 않는 것들은 화면을 그쪽으로 이동하면 인플레이터 된다)

 

----------------

 

item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="99dp"
        android:text="의미없음"
        android:textSize="30sp"
        android:textStyle="bold"
        android:gravity="center"/>

    <View
        android:layout_below="@id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="1"
        android:background="@android:color/darker_gray"/>

</RelativeLayout>

 

 

 

SingleAdapter

package com.jaybon.movie;

import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class SingleAdapter extends BaseAdapter {

    private static final String TAG = "SingleAdapter";
    
    // 데이터
    private List<String> items = new ArrayList<>();

    // 모든건수 받기
    public void addItems(List<String> items){
        this.items = items;
    }

    // 한건씩 받기 생략
    
    // getCount과 getItem는 필수!

    @Override
    public int getCount() { // 데이터 사이즈, 최초에 화면을 몇건 만들 것인지
        Log.d(TAG, "getCount: ");
        return items.size();
    }

    @Override
    public Object getItem(int position) { // 아이템 가져오기
        Log.d(TAG, "getItem: ");
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        Log.d(TAG, "getItemId: ");
        return 0;
    }


    // 집중!
    @Override
    public View getView(int position, View convertView, ViewGroup parent) { // 포지션값은 제일 밑에 값
        Log.d(TAG, "getView: " +position);

        LayoutInflater inflater = LayoutInflater.from(parent.getContext()); // 인플레이터
        View itemView = inflater.inflate(R.layout.item, parent, false); //아이템뷰
        TextView tv = itemView.findViewById(R.id.tv_title); //뷰에서 텍스트뷰 찾기
        tv.setText(getItem(position).toString());

        return itemView;
    }
}

 

MainActivity

package com.jaybon.movie;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";
    private Context mContext = MainActivity.this;
    private ListView listView;
    private  SingleAdapter adapter;

    private List<String> mid = Arrays.asList(
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아",
            "가","나","다","라","마","바","사","아"
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = findViewById(R.id.list_view);
        adapter = new SingleAdapter();
        adapter.addItems(mid);
        listView.setAdapter(adapter);

    }
}

 

 

 

 

 

 

 

 

 

바텀네비게이션 코드확인

https://github.com/jaybon1/androidwork/tree/master/bottomNavEx01

 

jaybon1/androidwork

Contribute to jaybon1/androidwork development by creating an account on GitHub.

github.com

 

 

머터리얼 디자인에서 구성하는법 확인

 

https://material.io/develop/android/components/bottom-navigation

 

Material Design

Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.

material.io

 

 

그래들 의존성 추가

    // 나의 라이브러리
    implementation 'com.google.android.material:material:1.1.0-alpha06'

 

 

 

참고

바텀네비게이션 뷰는 5개이상 만들지 말라는 권장사항이 있다

 

 

 

코드분석

 

네비게이션 메뉴 아이콘 생성

 

my_nav_items.xml

res하위 menu에 메뉴아이템들을 설정할 파일을 만든다

위에서 생성한 아이콘을 이용하여 입력

 

 

 

activity_main.xml

아이콘에 글자 안보이게 설정하는 방법

 

 

 

colors.xml

커스텀 컬러를 설정할 수 있다

 

 

 

프래그먼트를 3개 만들어주자

 

 

 

메인액티비티

package com.jaybon.bottomnavex01;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";


    // 자기가 직접 만든건 앞에 m이나 my를 붙이면 구분이 쉽다
    private BottomNavigationView myBottomNavigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myBottomNavigationView = findViewById(R.id.bottom_nav_view);
        myBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {

                Log.d(TAG, "onNavigationItemSelected: "+item.getItemId());
                Log.d(TAG, "onNavigationItemSelected: R값: "+R.id.nav_search);
                
                switch (item.getItemId()){

                }
                
                return false;
            }
        });

    }
}

 

 

중간확인

 

package com.jaybon.bottomnavex01;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";


    // 자기가 직접 만든건 앞에 m이나 my를 붙이면 구분이 쉽다
    private BottomNavigationView myBottomNavigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myBottomNavigationView = findViewById(R.id.bottom_nav_view);
        myBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {

                Log.d(TAG, "onNavigationItemSelected: "+item.getItemId());
                Log.d(TAG, "onNavigationItemSelected: R값: "+R.id.nav_search);
                
                switch (item.getItemId()){
                    case R.id.nav_search:
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new Frag1()).commit();
                        break;
                    case R.id.nav_setting:
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new Frag2()).commit();
                        break;
                    case R.id.nav_nav:
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new Frag3()).commit();
                        break;
                }
                
                return true; // true를 써야 그림이 다시그려진다
            }
        });

    }
}

 

 

 

 

----------------

 

 

 

 

 

 

 

 

파이썬 플라스크 서버(가장 간단한 서버 )

템플레이트를 html로 사용한다

 

 

 

 

 

 

res폴더 안의 폴더명은 이미 정해져 있다

 

 

위처럼 하지 않고 res에서 바로 뉴리소스파일을 선택해도 아래와 같이 가능

 

 

 

 

menu_main.xml

꺾쇠를 닫아놓고 작업해야 에러를 확인 할 수 있다

 

 

 

 

 

 

인플레이터 (메모리에 띄워주는 역할)

- xml파일을 자바코드로 바꾸고 메모리에 올리고, new 해준 것을 그림을 그린다

 

 

 

 

기본 제공 메뉴

액션바는 기본제공 메뉴를 쓰지않고 직접만들어 쓰는 것이 많다고 한다

 

 

 

 

 

 

라이브러리는 androidx 로 되어있는 것을 꼭 쓰자

 

 

androidx가 아닌 라이브러리를 쓰면 플레이스토어에 배포가 되지 않는다

 

 

툴바의 고질적인 문제 왼쪽에 빈공간이 생기는 점

공간 없애는 방법이 있다

 

 

 

 

빈공간이 사라졌다

 

 

이러한 빈공간을 inset이라고 한다

카메라구멍이나 통화 스피커나 키보드 등 화면이 안그려도되는 빈공간을 인셋이라고 한다

 

 

레이아웃이나 일반 컴포넌트면 merge 안에 넣는것이 좋고 Toolbar는 굳이 넣을 필요 없다

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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=".MainActivity">

    <include layout="@layout/toolbar_main"/>

</LinearLayout>

include 하여 툴바를 추가한다

 

 

메인과 합쳐졌다

 

 

 

 

https://material.io/develop/android/components/navigation-view

 

Material Design

Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.

material.io

 

 

옆으로 슬라이딩 되는 메뉴가 있다면 draw layout이라고 보면된다

 

 

 

 

 

 

----------------------

롬복 설치하는 법 file setting 검색

 

 

그래들 디펜던시 추가

--------------------

 

 

머터리얼 api 추가하는 법

 

 

 

 

 

----------------

 

 

 

 

 

----------------------

 

package com.jaybon.app2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";

    private ImageView ivMenu;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        ivMenu = findViewById(R.id.iv_menu);
        
        ivMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "onClick: 클릭됨");
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.menu_main, menu);
        return false;
    }
}

 

 

 

 

슬라이딩 뷰에 접근하려면 드로우 레이아웃의 id가 필요하다

 

 

 

 

ctrl + Q 하면

 

 

 

 

 

 

------------------

툴바를 커스텀해서 넣으면 그 툴바는 액션바로 인식하지 못한다

액션바로 인식하도록 만들어야함

------------------

 

 

 

 

 

 

--------------------------

땡땡땡1

 

 

 

 

 

menu_side로 바꾸기

---------------------------

 

나중에 해보기

https://material.io/components/menus

 

Material Design

Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.

material.io

 

 

http://i5on9i.blogspot.com/2013/12/action-bar-option-menu-icon.html

 

[컴][안드로이드] action bar 위의 option menu icon 바꾸는 방법

option menu icon 바꾸는 방법 / 옵션 메뉴 아이콘 변경 / 액션바의 옵션 메뉴 아이콘 변경 option menu 가 존재하면 action bar 에 icon 이 보여진다. 보통 아래와 같은 모양으로 나타난다. 이 보양을 다른 아.

i5on9i.blogspot.com

 

----------------------------

 

옵션메뉴 버튼 색깔 바꾸기

https://blog.naver.com/PostView.nhn?blogId=greatsk553&logNo=221038610508&parentCategoryNo=&categoryNo=33&viewDate=&isShowPopularPosts=true&from=search

 

안드로이드 옵션 메뉴 버튼 색상 바꾸기

안드로이드 옵션 메뉴 버튼 색상 바꾸기.안드로이드 액티비티 툴바에 보면 화살표로 가리킨 아이콘이 있다....

blog.naver.com

----------------------------

 

 

 

--------------------

 

액티비티를 여러개 만들어서 이동해야하는데

 

액티비티 전환없이 사용

 

화면하나에 여러개의 프래그먼트를 넣고

프래그먼트를 이동하면서 사용하면 하나의 페이지로 여러가지 화면을 사용할 수 있다

-------------------------------

탭 레이아웃

 

 

 

 

 

 

 

https://material.io/develop/android/components/tabs

 

Material Design

Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.

material.io

 

 

 

 

탭레이아웃으로 프래그먼트를 쓰면 해당 아이템들만 뜬다

 

----

자바코드로도 가능

 

 

-----------------

 

뷰페이저는 탭레이아웃과 연결시킬 수 있다

 

 

이 3개는 메모리에 안뜬다 (코드로 띄워야함)

 

 

 

 

프래그먼트도 자기만의 자바파일이 필요하다

 

 

 

 

 

 

프래그먼트를 바꿔주는 어댑터가 필요하다

 

 

ctrl + o

 

 

 

 

 

 

 

 

-------------

안드로이드에서는 데이터를 이용할 때에는 무조건 어댑터를 쓰게되어있다

------------

 

책 287 프래그먼트 확인

--------------

 

프래그먼트 쉬운버전

 

 

 

어댑터를 안만들것이기 때문에 메모리에 띄워줄 애가 필요하다

onCreateView

 

 

자바파일만들기

 

 

 

 

MainActivity.java

package com.jaybon.frag2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button btn1, btn2;
    private Fragment fragment1, fragment2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fragment1 = new Frag1();
        fragment2 = new Frag2();

        btn1 = findViewById(R.id.btn1);
        btn2 = findViewById(R.id.btn2);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // commit이 호출될때 onCreateView가 실행된다
                // onCreateView에 R.id.frame_container가 들어간다
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, fragment1).commit();
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // commit이 호출될때 onCreateView가 실행된다
                // onCreateView에 R.id.frame_container가 들어간다
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, fragment2).commit();
            }
        });

    }
}

 

 

 

 

간단한것은 비긴트랜잭션 // 다양한건 뷰페이저와 어댑터

 

--------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

타입에 따라 기본 키보드가 달라지기 때문에 잘 맟추어서 설정하는 것이 좋다

 

 

----------------

(나중에)

 

 

-----------------

 

 

 

 

 

 

 

 

웹뷰 - 앱안의 웹 브라우저라고 생각하면 된다

 

 

------------

자바코드로만 앱을 만들면 [네이티브 앱]

반응형 웹으로 앱을 만들면 [웹앱]

웹뷰를 이용해서 웹을 보이도록 만들면 [하이브리드 앱]

---------------

 

 

프로그래스바 //별점

 

 

사진이나 영상을 올릴 때 사용

 

 

spinner - flash메시지?

 

 

 

 

 

 

저기들어가면 라이브러리를 어떻게 사용하는지 나옴

 

 

 

 

 

 

 

 

책 189페이지

drawable 상태드로어블 만들어보기

 

 

 

 

 

눌렸을시 꽉찬 하트모양

 

 

버튼 배경에 드로어블설정

 

 

 

 

----------------

 

 

 

xml 규칙 변수명 언더바

 

 

모서리가 둥근버튼

 

 

드로어블

soild 버튼 안의 색깔

stroke 버튼 테두리 색깔

corners 모서리 둥글기

 

 

더보기
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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=".MainActivity">

    <LinearLayout
        android:paddingTop="80dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <ImageView
            android:id="@+id/iv_logo"
            android:layout_width="match_parent"
            android:layout_height="155dp"
            android:layout_marginBottom="10dp"
            app:srcCompat="@drawable/instagram_logo" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/tf_email"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/tf_password"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <androidx.appcompat.widget.AppCompatButton
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/white_rounded_button"
            android:text="Login" />


    </LinearLayout>

</RelativeLayout>

 

 

 

 

 

 

 

 

 

 

 

 

다른 것은 그대로 메인만 언더바 주자(검색 용이)

 

 

 

 

 

 

 

 

메인쓰레드는 UI 쓰레드와 이벤트 분배 쓰레드를 호출하고 죽는다

UI 쓰레드 - 

이벤트 분배 쓰레드 - 버튼 클릭 등 할 때 UI 쓰레드에 콜백

 

다운로드시에도 UI쓰레드는 그림을 그려야 하기 때문에 새로운 쓰레드로 다운로드 해야한다

 

 

더보기
package com.jaybon.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity"; // 다른 것은 그대로 메인만 언더바 주자(검색 용이)
    // 제일 위에 전역으로 적는 것은~
    // 컴포넌트들을 모두 전역으로 올려서 선언한다

    private ProgressBar pgbDownload;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initComponent(); // 컴포넌트 초기화 (개발자 임의 작명)

        imageDownload();

        Log.d(TAG, "onCreate: 테스트1");
    }

    private void  initComponent(){ // 여기서 컴포넌트들을 찾아주고 프로그래밍 한다

        pgbDownload = findViewById(R.id.pgb_download);
        // 화면에 그리지 않으면 연산을 하지 않는다
    }

    private void imageDownload(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "run: 다운로드 쓰레드 시작");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Log.d(TAG, "run: 다운로드 쓰레드 종료");
                pgbDownload.setVisibility(View.INVISIBLE);
            }
        }).start();
    }



}

 

 

 

 

setOn이 안드로이드의 리스너 추가 함수이다

 

 

레벨8 설치햐야 람다식을 사용할 수 있다

 

 

숫자 증감

더보기
<?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=".MainActivity">

    <TextView
        android:id="@+id/tv_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.329" />

    <Button
        android:id="@+id/btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="증가"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintEnd_toStartOf="@+id/btn_minus"
        app:layout_constraintHorizontal_bias="0.477"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/btn_minus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="68dp"
        android:text="감소"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintEnd_toEndOf="parent" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_end="248dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

더보기
package com.jaybon.countingapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";
    private Button btnAdd, btnMinus;
    private TextView tvCount;
    private int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvCount = findViewById(R.id.tv_count);
        tvCount.setText(count+"");

        btnAdd = findViewById(R.id.btn_add);
        btnMinus = findViewById(R.id.btn_minus);

        btnAdd.setOnClickListener((View view)->{
            count++;
            tvCount.setText(count+"");
        });

        btnMinus.setOnClickListener((View view)->{
            if(count > 0){
                count--;
                tvCount.setText(count+"");
            }
        });

//        btnAdd.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                count++;
//                tvCount.setText(count);
//            }
//        });
//
//        btnMinus.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                count--;
//                tvCount.setText(count);
//            }
//        });

    }

}

 

 

 

----------------

 

모든 객체(버튼이나 라디오 박스 등)는 View 를 상속받는다 (View의 자식 )

View는 context를 가지고 있고 context는 OS가 보내준다

 

Button btnTemp = (Button)view; // 버튼의 context를 가져올 수 있다 

 

----------------

계산기 만들기

eval 함수(자바스크립트)

안드로이드에서 자바스크립트 함수를 땡겨 올 수 있다

 

https://github.com/APISENSE/rhino-android

 

APISENSE/rhino-android

Give access to RhinoScriptEngine from the JSR223 interfaces on Android JRE. - APISENSE/rhino-android

github.com

 

build.gradle

더보기
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.jaybon.countingapp"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'io.apisense:rhino-android:1.0'

}

 

activity_main.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=".MainActivity">

    <!--    <LinearLayout-->
    <!--        android:layout_width="wrap_content"-->
    <!--        android:layout_height="wrap_content">-->


    <!--    </LinearLayout>-->


    <EditText
        android:id="@+id/pt_result"
        android:layout_width="358dp"
        android:layout_height="62dp"
        android:layout_marginBottom="40dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text=""
        android:textSize="30sp"
        app:layout_constraintBottom_toTopOf="@+id/tableLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:orientation="vertical"
        android:stretchColumns="0, 1, 2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TableRow>

            <Button
                android:id="@+id/num1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1" />

            <Button
                android:id="@+id/num2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2" />

            <Button
                android:id="@+id/num3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3" />

            <Button
                android:id="@+id/btn_add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+" />

        </TableRow>

        <TableRow>

            <Button
                android:id="@+id/num4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="4" />

            <Button
                android:id="@+id/num5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5" />

            <Button
                android:id="@+id/num6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="6" />

            <Button
                android:id="@+id/btn_minus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="-" />

        </TableRow>

        <TableRow>

            <Button
                android:id="@+id/num7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="7" />

            <Button
                android:id="@+id/num8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="8" />

            <Button
                android:id="@+id/num9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="9" />

            <Button
                android:id="@+id/btn_multi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="*" />

        </TableRow>

        <TableRow>

            <Button
                android:id="@+id/num0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />

            <Button
                android:id="@+id/btn_clear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="C" />

            <Button
                android:id="@+id/btn_devide"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="/" />

            <Button
                android:id="@+id/btn_cal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="=" />

        </TableRow>


    </TableLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

 

eval.java

더보기
package com.jaybon.countingapp;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class eval {
    public static String cal (String result) throws ScriptException {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        try {
            return engine.eval(result).toString();
        }catch(Exception e) {
            e.getStackTrace();
        }
        return null;
    }
}

 

MainActivity.java

더보기
package com.jaybon.countingapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import javax.script.ScriptException;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Main_Activity";

    private EditText ptResult;
    private Button btn[] = new Button[16];
    private int i;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
        initListener();



//        btnAdd.setOnClickListener((View view)->{
//
//            Log.d(TAG, "onCreate: btnAdd:"+view.getId());
//
//            count++;
//            tvCount.setText(count+"");
//        });
//
//        btnMinus.setOnClickListener((View view)->{
//            if(count > 0){
//                count--;
//                tvCount.setText(count+"");
//            }
//        });
    }

    private void init(){
        btn[0] = findViewById(R.id.num0);
        btn[1] = findViewById(R.id.num1);
        btn[2] = findViewById(R.id.num2);
        btn[3] = findViewById(R.id.num3);
        btn[4] = findViewById(R.id.num4);
        btn[5] = findViewById(R.id.num5);
        btn[6] = findViewById(R.id.num6);
        btn[7] = findViewById(R.id.num7);
        btn[8] = findViewById(R.id.num8);
        btn[9] = findViewById(R.id.num9);
        btn[10] = findViewById(R.id.btn_add);
        btn[11] = findViewById(R.id.btn_minus);
        btn[12] = findViewById(R.id.btn_multi);
        btn[13] = findViewById(R.id.btn_devide);
        btn[14] = findViewById(R.id.btn_clear);
        btn[15] = findViewById(R.id.btn_cal);
        ptResult = findViewById(R.id.pt_result);
    }

    private void initListener(){

        for (i=0; i<14; i++){
            btn[i].setOnClickListener((View view)->{
                Button btn = (Button)view;
                ptResult.append(btn.getText().toString());
            });
        }

        btn[14].setOnClickListener((View view)->{
            ptResult.setText("");
        });

        btn[15].setOnClickListener((View view)->{
            String result = ptResult.getText().toString();
            try {
                ptResult.setText(eval.cal(result));
            } catch (ScriptException e) {
                e.printStackTrace();
            }
        });

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

https://blog.naver.com/getinthere/221694606685

 

안드로이드 1강 - (5) Relative 레이아웃

1. Relative 기본 예제activity_main.xmlitem_post1.xml​2. 위의 예제 참고https://blog.naver.com/codin...

blog.naver.com

 

안드로이드 drawable 폴더에 복붙할 시 하위폴더 인식을 못한다 (폴더 복붙 하지말 것)

 

 

layout_profile.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<merge
    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"
    >

    <RelativeLayout
        android:layout_marginLeft="10dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/img_pro1"
            android:layout_width="60dp"
            android:layout_height="60dp"
            app:srcCompat="@drawable/propic1" />

        <TextView
            android:layout_marginTop="5dp"
            android:layout_below="@id/img_pro1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your story" />

    </RelativeLayout>

</merge>

 

더보기

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout

        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <include layout="@layout/layout_profile" />
        <include layout="@layout/layout_profile" />
        <include layout="@layout/layout_profile" />
        <include layout="@layout/layout_profile" />
        <include layout="@layout/layout_profile" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </LinearLayout>

    </ScrollView>

</LinearLayout>

 

 

동그란 이미지를 만들기 위해 라이브러리 추가

https://github.com/hdodenhof/CircleImageView

 

hdodenhof/CircleImageView

A circular ImageView for Android. Contribute to hdodenhof/CircleImageView development by creating an account on GitHub.

github.com

 

 

 

androidx 를 써야한다 !!!! (구버전의 android는 사용못함)

구버전은 compile -> 신버전은 implementation

 

 

 

액션바 없애기

 

 

 

 

 

완성

 

activity_main.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="horizontal">

        <include layout="@layout/layout_profile" />

        <include layout="@layout/layout_profile" />

        <include layout="@layout/layout_profile" />

        <include layout="@layout/layout_profile" />

        <include layout="@layout/layout_profile" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!--            리니어 레이아웃 버티컬-->

            <include layout="@layout/layout_content" />
            <include layout="@layout/layout_content" />
            <include layout="@layout/layout_content" />
            <include layout="@layout/layout_content" />
            <include layout="@layout/layout_content" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

 

layout_profile.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<merge
    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"
    >

    <RelativeLayout
        android:layout_marginLeft="10dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content">

<!--        <ImageView-->
<!--            android:id="@+id/img_pro1"-->
<!--            android:layout_width="60dp"-->
<!--            android:layout_height="60dp"-->
<!--            app:srcCompat="@drawable/propic1" />-->

        <de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/img_pro1"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/propic1"
            app:civ_border_width="2dp"
            app:civ_border_color="#FF000000"/>

        <TextView
            android:layout_marginTop="5dp"
            android:layout_below="@id/img_pro1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your story" />

    </RelativeLayout>

</merge>

 

layout_content.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<merge
    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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp">

            <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/img_pro2"
                android:layout_marginLeft="10dp"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:src="@drawable/propic1"
                app:civ_border_color="#FF000000"
                app:civ_border_width="2dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:layout_toRightOf="@+id/img_pro2"
                android:gravity="center"
                android:text="numbiker.nikkhil"
                android:textSize="18dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="30dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                app:srcCompat="@drawable/ic_more" />


        </RelativeLayout>

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:scaleType="centerCrop"
            app:srcCompat="@drawable/postpic1" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp">

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="10dp"
                app:srcCompat="@drawable/like" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/imageView4"
                app:srcCompat="@drawable/chat_bubble" />


            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/imageView5"
                app:srcCompat="@drawable/send" />

            <ImageView
                android:id="@+id/imageView7"
                android:layout_marginRight="10dp"
                android:layout_width="30dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                app:srcCompat="@drawable/bookmark" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp">

            <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/img_pro3"
                android:layout_marginLeft="10dp"
                android:layout_width="35dp"
                android:layout_height="match_parent"
                android:src="@drawable/propic2"
                app:civ_border_color="#FF000000"
                app:civ_border_width="2dp" />

            <TextView
                android:id="@+id/textView"
                android:layout_toRightOf="@id/img_pro3"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Liked by"
                android:textSize="18dp"/>

            <TextView
                android:id="@+id/textView1"
                android:layout_toRightOf="@id/textView"
                android:gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="bhuvan.van"
                android:textSize="18dp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/textView2"
                android:layout_toRightOf="@id/textView1"
                android:gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="and"
                android:textSize="18dp"/>

            <TextView
                android:id="@+id/textView3"
                android:layout_toRightOf="@id/textView2"
                android:gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="24 others"
                android:textSize="18dp"
                android:textStyle="bold" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="50dp">

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:gravity="center"
                android:text="numbiker.ni"
                android:textSize="18dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView5"
                android:layout_toRightOf="@id/textView4"
                android:gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="#asdf"
                android:textSize="18dp"
                android:textStyle="bold"
                android:textColor="@android:color/holo_blue_dark"/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp">

            <de.hdodenhof.circleimageview.CircleImageView
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/img_pro4"
                android:layout_marginLeft="10dp"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:src="@drawable/propic3"
                app:civ_border_color="#FF000000"
                app:civ_border_width="2dp" />

            <EditText
                android:id="@+id/editTextTextPersonName"
                android:layout_toRightOf="@id/img_pro4"
                android:gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:ems="10"
                android:inputType="textPersonName"
                android:textSize="22dp"
                android:textColor="@android:color/darker_gray"
                android:text="Add Comment..." />

            <!--            <TextView-->
<!--                android:id="@+id/textView6"-->
<!--                android:layout_toRightOf="@id/img_pro4"-->
<!--                android:gravity="center"-->
<!--                android:layout_marginLeft="15dp"-->
<!--                android:layout_width="wrap_content"-->
<!--                android:layout_height="match_parent"-->
<!--                android:text="Add Comment..."-->
<!--                android:textSize="22dp"/>-->

        </RelativeLayout>

        <TextView
            android:id="@+id/textView7"
            android:layout_marginLeft="15dp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="8HOURS AGO"
            android:textSize="16dp"/>

    </LinearLayout>

</merge>

 

<EditText
                android:id="@+id/editTextTextPersonName"
                android:layout_toRightOf="@id/img_pro4"
                android:gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:ems="10"
                android:inputType="textPersonName"
                android:textSize="22dp"
                android:textColor="@android:color/darker_gray"
                android:hint="Add Comment..."
                android:background="@android:color/transparent"/>

 

hint 는 placeholder와 비슷함

background는 밑줄을 없앤다

 

 

+ Recent posts