Type : GET


Url : https://www.googleapis.com/youtube/v3/search?part=snippet&q={검색어}&key={API_KEY}&maxResults={응답 개수}&pageToken={페이지 토큰}


페이지 토큰으로 페이지를 변경할 수 있다.


https://developers.google.com/youtube/v3/docs/search/list?hl=ko


'Android' 카테고리의 다른 글

[Android] Tab 사용법  (0) 2019.03.27
[Android] RecyclerView 예제  (0) 2019.03.26
YouTube Android Player API - Download  (0) 2019.03.20
[Android] DrawerLayout 사용하기  (0) 2019.03.19
[Android] AutoCompleteTextView 사용하기  (0) 2019.03.14

안드로이드 유튜브 API 다운로드


libs 폴더에 추가하고 gradle - dependencies 추가한다

implementation files('libs/YouTubeAndroidPlayerApi.jar')


'Android' 카테고리의 다른 글

[Android] RecyclerView 예제  (0) 2019.03.26
[Android] YouTube Api call Url  (0) 2019.03.22
[Android] DrawerLayout 사용하기  (0) 2019.03.19
[Android] AutoCompleteTextView 사용하기  (0) 2019.03.14
[Android] EditText 사용하기  (0) 2019.03.13


먼저 레이아웃을 DrawerLayout으로 변경한다.


DrawerLayout 안에 메인 화면(FrameLayout)과 메뉴(ListView)를 추가한다.


activity_main.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<android.support.v4.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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
 
    <!-- 메인콘텐츠용 레이아웃 -->
 
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
 
        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="20sp" />
    </FrameLayout>
 
    <!-- 슬라이드 메뉴용 레이아웃 -->
 
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/background_light" />
 
</android.support.v4.widget.DrawerLayout>
cs


레이아웃을 호출하기 위한 클래스 변수를 선언하고 각각 레이아웃을 호출한다.


MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
 
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    private TextView mTextView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mTextView = (TextView) findViewById(R.id.text);
 
        setupNavigationDrawer();
 
        // 목록 데이터를 설정
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1);
        adapter.add("Menu1");
        adapter.add("Menu2");
        adapter.add("Menu3");
        mDrawerList.setAdapter(adapter);
 
        if (savedInstanceState == null) {
            selectItem(0);
        }
    }
cs


Drawer를 열고 닫을 때의 이벤트를 설정한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    private void setupNavigationDrawer() {
        // NavigationDrawer의 그림자로 설정할 Drawable을 지정
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                GravityCompat.START);
        mDrawerList.setOnItemClickListener(this);
 
        // 드로워를 개폐 시에 이벤트를 받을 수 있게 함
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
                R.string.drawer_close) {
            @Override
            public void onDrawerClosed(View view) {
            }
 
            @Override
            public void onDrawerOpened(View drawerView) {
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // DrawerToggle측의 옵션 메뉴 선택을 처리할 수 있도록
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
 
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // DrawerToggle측의 옵션 메뉴를 제어할 수 있도록
        mDrawerToggle.syncState();
    }
 
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // DrawerToggle측에서 위/아래 변경을 제어할 수 있도록
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
 
    @Override
    public void onItemClick(AdapterView<?> adapterView, View parent,
                            int position, long id) {
        selectItem(position);
    }
 
    private void selectItem(int position) {
        ListAdapter adapter = mDrawerList.getAdapter();
        String item = (String) adapter.getItem(position);
        mTextView.setText("선택한 항목: " + item);
        mDrawerLayout.closeDrawer(mDrawerList);
    }
cs


'Android' 카테고리의 다른 글

[Android] YouTube Api call Url  (0) 2019.03.22
YouTube Android Player API - Download  (0) 2019.03.20
[Android] AutoCompleteTextView 사용하기  (0) 2019.03.14
[Android] EditText 사용하기  (0) 2019.03.13
[Android] SeekBar 사용  (0) 2019.03.12

자동 완성 기능은 AutoCompleteTextView를 사용한다.


1
2
3
4
5
    <AutoCompleteTextView
        android:id="@+id/autocomplete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"/>
cs


AutoCompleteTextView에 자동 완성 리스트를 연결하여 주면 자동 완성이 표시된다.


1
2
3
4
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this
                                    android.R.layout.simple_dropdown_item_1line, androids);
    textView.setAdapter(adapter);
cs


ArrayAdapter<String>을 상속받는 Adapter 클래스를 만들어서 쉽게 제어도 가능하다.


1
2
3
4
5
6
7
8
    List<String> androids = new ArrayList<>();
    androids.add("좋아하는 색은 빨간색");
    androids.add("좋아하는 색은 파란색");
    androids.add("좋아하는 색은 노란색");
 
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    SuggestAdapter adapter = new SuggestAdapter(this, androids);
    textView.setAdapter(adapter);
cs


SuggestAdapter.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class SuggestAdapter extends ArrayAdapter<String> implements SpinnerAdapter {
    private LayoutInflater mInflator;
    private List<String> mItems;
 
    SuggestAdapter(Context context, List<String> objects) {
        super(context, R.layout.item_suggest, objects);
        mInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mItems = objects;
    }
 
    @Override
    public int getCount() {
        return mItems.size();
    }
 
    @Override
    public String getItem(int position) {
        return mItems.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
 
        if (convertView == null) {
            convertView = mInflator.inflate(R.layout.item_suggest, nullfalse);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.spinnerText);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
 
        holder.textView.setText(mItems.get(position));
 
        return convertView;
    }
 
    private class ViewHolder {
        TextView textView;
    }
}
cs


item_suggest.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <TextView
        android:id="@+id/spinnerText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/FlatDarkRed"
        android:padding="@dimen/padding_large"
        android:textColor="@color/FlatLightBlue"
        android:textSize="18sp" />
</LinearLayout>
cs


'Android' 카테고리의 다른 글

YouTube Android Player API - Download  (0) 2019.03.20
[Android] DrawerLayout 사용하기  (0) 2019.03.19
[Android] EditText 사용하기  (0) 2019.03.13
[Android] SeekBar 사용  (0) 2019.03.12
[Android] 라디오 버튼(RadioButton) 사용  (0) 2019.03.11

게임 오브젝트에 사운드를 넣는 방법


Add Component에 Audio Source를 추가한다.


AudioClip에 원하는  사운드를 추가한다.


Play On Awake가 기본적으로 체크되어 있어서 게임상에 오브젝트가 생성될 때 자동으로 소리가 난다.


이 기능을 원하지 않을 경우 체크를 해제 하고 사용한다.



'유니티' 카테고리의 다른 글

[유니티] 폭발 이펙트 추가  (0) 2019.03.12
[유니티] Object 충돌  (0) 2019.03.08
[유니티] Random 위치에 Object 이동  (0) 2019.03.07
[유니티] Object 생성  (0) 2019.03.05
[유니티]Object 삭제  (0) 2019.03.04

EditText의 입력문자는 InputType 속성을 사용하여 변경할 수 있다.


InputType에는 text, textPassword, date, datetime, phone 등 여러 type들을 제공한다.


힌트를 표시하고 싶은 경우 hint 속성을 사용한다.


1
2
3
4
5
6
    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:hint="비밀번호를 입력하세요" />
cs


EditText의 문자 제한은 InputFilter를 사용한다.


입력을 제한하는 내용의 InputFilter를 생성하고 생성한 InputFilter는 InputFilter의 배열에 저장하여


setFilters 메소드를 사용해 적용한다.


1
2
3
4
5
6
    <EditText
        android:id="@+id/restriction"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="이메일을 입력하세요"
        android:textSize="16sp"/>
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        EditText editText = (EditText) findViewById(R.id.restriction);
 
        InputFilter inputFilter = new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end,
                                             Spanned dest, int dstart, int dend) {
                if (source.toString().matches("^[0-9a-zA-Z@\\.\\_\\-]+$")) {
                    return source;
                } else {
                    return "";
                }
            }
        };
 
        InputFilter lengthFilter = new InputFilter.LengthFilter(10);
 
        InputFilter[] filters = new InputFilter[] { inputFilter , lengthFilter };
        editText.setFilters(filters);
    }
cs


'Android' 카테고리의 다른 글

[Android] DrawerLayout 사용하기  (0) 2019.03.19
[Android] AutoCompleteTextView 사용하기  (0) 2019.03.14
[Android] SeekBar 사용  (0) 2019.03.12
[Android] 라디오 버튼(RadioButton) 사용  (0) 2019.03.11
[Android] CheckBox 사용  (0) 2019.03.08

Asset Store에서 원하는 폭발 이펙트를 검색하여 Import 한다.


추가하였다면 Prefabs폴더에 추가하고 한번만 폭발하도록 Script를 추가한다.


충돌하였을 때 폭발 하도록 충돌 이벤트에 폭발 이펙트를 생성시켜준다.





1
2
3
4
5
6
7
8
9
10
11
public class DestroyAtTime : MonoBehaviour
{
    public float Time = 0.5f;
 
    // Start is called before the first frame update
    void Start()
    {
        //Time 후 Object 삭제
        Destroy(gameObject, Time);
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class EnemyControl : MonoBehaviour
{
    public float Speed = 50.0f;
    private Transform myTransform = null;
    
    //폭발 Object
    public GameObject Explosion = null;
 
    // Start is called before the first frame update
    void Start()
    {
        myTransform = GetComponent<Transform>();
    }
 
    // Update is called once per frame
    void Update()
    {
        Vector3 moveAmount = Speed * Vector3.back * Time.deltaTime;
        myTransform.Translate(moveAmount);
 
        if(myTransform.position.y <= -60.0f)
        {
            InitPosition();
        }
    }
 
    /// <summary>
    /// 위치 초기화
    /// </summary>
    void InitPosition()
    {
        myTransform.position = new Vector3(Random.Range(-60.0f, 60.0f), 60.0f, 0.0f);
    }
 
    //충돌 이벤트 함수
    void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Bullet")
        {
            Debug.Log("Bullet Trigger Enter");
            //폭발 Object 생성
            Instantiate(Explosion, myTransform.position, Quaternion.identity);
 
            InitPosition();
            Destroy(other.gameObject);
        }
    }
}
cs


'유니티' 카테고리의 다른 글

[유니티] 사운드 삽입  (0) 2019.03.13
[유니티] Object 충돌  (0) 2019.03.08
[유니티] Random 위치에 Object 이동  (0) 2019.03.07
[유니티] Object 생성  (0) 2019.03.05
[유니티]Object 삭제  (0) 2019.03.04

SeekBar는 progress 속성을 사용하여 초기값을 설정할수 있다.


SeekBar 이벤트는 setOnSeekBarChangeListener를 사용한다.


세 가지 이벤트를 사용할 수 있다.

 - onStartTrackingTouch : SeekBar에 터치하는 순간 이벤트 발생

 - onStopTrackingTouch : SeekBar에 터치가 끝나는 순간 이벤트 발생

 - onProgressChanged : SeekBar의 값이 변할 때 이벤트 발생



1
2
3
4
5
6
7
8
9
10
    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 
    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progress="50" />
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        final TextView textView = (TextView) findViewById(R.id.textview);
        SeekBar seekBar = (SeekBar) findViewById(R.id.seekbar);
        textView.setText(String.valueOf(seekBar.getProgress()));
 
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                textView.setText(String.valueOf(progress));
            }
 
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                textView.setText("트래킹 시작");
            }
 
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                textView.setText("트래킹 종료");
            }
        });
    }
cs


SeekBar를 세로로 표시하려면 rotation 속성을 사용한다.


1
2
3
4
5
    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:rotation="270" />
cs


SeekBar 외형은 background 속성에 배경을 변경


progressDrawable 속성에 진행상태를 변경


thumb 속성에 손잡이를 변경



1
2
3
4
5
6
7
8
    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_seekbar"
        android:padding="10dp"
        android:progressDrawable="@drawable/pd_seekbar"
        android:thumb="@drawable/selector_seekbar_thumb" />
cs


bg_seekbar.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:centerColor="#666666"
        android:centerY="0.5"
        android:endColor="#999999"
        android:startColor="#FFFFFF" />
 
    <corners android:radius="5dp" />
 
    <stroke
        android:width="1dp"
        android:color="#999999" />
 
</shape>
cs


pd_seekbar.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="10dp" />
 
            <gradient
                android:angle="-90"
                android:centerColor="#00CC00"
                android:endColor="#FA8072"
                android:startColor="#FA8072" />
 
            <stroke
                android:width="10dp"
                android:color="#999999" />
        </shape>
    </item>
 
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="10dp" />
 
                <gradient
                    android:angle="-90"
                    android:centerColor="#666666"
                    android:centerY="0.5"
                    android:endColor="#F4A460"
                    android:startColor="#F0F8FF" />
 
                <stroke
                    android:width="1dp"
                    android:color="#999999" />
            </shape>
        </clip>
    </item>
</layer-list>
cs


selector_seekbar_thumb.xml

1
2
3
4
5
6
7
8
9
10
11
12
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/bg_seekbar_thumb_pressed"
        android:state_pressed="true" android:state_window_focused="true" />
 
    <item android:drawable="@drawable/bg_seekbar_thumb_pressed"
        android:state_focused="true" android:state_window_focused="true" />
 
    <item android:drawable="@drawable/bg_seekbar_thumb_pressed"
        android:state_selected="true" android:state_window_focused="true" />
 
    <item android:drawable="@drawable/bg_seekbar_thumb_normal" />
</selector>
cs


bg_seekbar_thumb_pressed.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="14dp"
            android:useLevel="false">
            <size
                android:width="32px"
                android:height="32px" />
            <gradient
                android:centerColor="#99cc99"
                android:endColor="#cccccc"
                android:startColor="#cccccc"
                android:type="sweep"
                android:useLevel="false" />
 
            <stroke
                android:width="2dp"
                android:color="#33666666" />
 
        </shape>
    </item>
 
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="10dp"
            android:useLevel="false">
            <size
                android:height="32px"
                android:width="32px" />
            <gradient
                android:centerColor="#ffffff"
                android:centerY="1"
                android:endColor="#666666"
                android:gradientRadius="20"
                android:startColor="#999999"
                android:type="radial"
                android:useLevel="false"/>
            <stroke
                android:width="1dp"
                android:color="#ffffff" />
        </shape>
    </item>
</layer-list>
cs


bg_seekbar_thumb_normal.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="14dp"
            android:useLevel="false">
            <size
                android:height="32px"
                android:width="32px" />
            <gradient
                android:centerColor="#999999"
                android:endColor="#00CED1"
                android:startColor="#8A2BE2"
                android:type="sweep"
                android:useLevel="false" />
 
            <stroke
                android:width="2dp"
                android:color="#33666666" />
        </shape>
    </item>
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="10dp"
            android:useLevel="false">
            <size
                android:height="32px"
                android:width="32px" />
            <gradient
                android:centerColor="#ffffff"
                android:centerY="1"
                android:endColor="#00CED1"
                android:gradientRadius="20"
                android:startColor="#8A3BE2"
                android:type="radial"
                android:useLevel="false" />
            <stroke
                android:width="1dp"
                android:color="#ffffff" />
        </shape>
    </item>
</layer-list>
cs


'Android' 카테고리의 다른 글

[Android] AutoCompleteTextView 사용하기  (0) 2019.03.14
[Android] EditText 사용하기  (0) 2019.03.13
[Android] 라디오 버튼(RadioButton) 사용  (0) 2019.03.11
[Android] CheckBox 사용  (0) 2019.03.08
[Android] ToggleButton/Switch 사용  (0) 2019.03.07

+ Recent posts