Anekdot ANDROID CLUB 2015. Сегодня  Navigation Drawer  CardView  Calligraphy  TextToSpeech.

Slides:



Advertisements
Similar presentations
1 Android Introduction Hello Threads. 2 Goal Create an application that uses a background thread as a UDP server to receive messages from the UDP client.
Advertisements

M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 2 Android Application Step by Step Eleonora Todorova Boyan Iliev.
Android Selection Widgets Yuliana Setiowati Rizky Yuniar Hakkun 1Politeknik Elektronika Negeri Surabaya.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
ListView Examples. Basic Steps for Creating a Listview 1.Create a layout (e.g., a LinearLayout), with elements for –the ListView (
ООП Классы. Данные отдельно, методы отдельно struct Node { Node* next; void* data; }; struct List { Node* first; int size; }; void* allocate() { … } void.
Cosc 5/4730 Material Design Spec’s and Toolbar.. Material Design First and for most, Material Design is a spec used by android to have app look similar.
Язык JavaScript Скриптовый язык для выполнения на html-страницах.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Android Accessing GPS Ken Nguyen Clayton State University 2012.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Mobile Computing Lecture#11 Adapters and Dialogs.
ListView.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Import import android.graphics.Bitmap; import android.widget.ImageView;
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
Application Specific Module Tutorial Akos Balasko 02/07/
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
User Interface Android Club Agenda Button OnClickListener OnLongClickListener ToggleButton Checkbox RatingBar AutoCompleteTextView.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
HTTP ANDROID CLUB 2015.
Service ANDROID CLUB Сегодня  Service Service - служба  Работает в фоновом режиме  Не имеет пользовательского интерфейса.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.
ListView and ExpandableListView
Android Application Lifecycle and Menus
Activity ANDROID CLUB Сегодня  Основные компоненты Android  Activity  Layout для Activity  Создание Activity  Launcher Activity  Activity.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Cosc 4735 Activities, fragments, callbacks/listeners/interfaces.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
Developing for Chromecast Cast Companion Library & Custom Receiver Application.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Cosc 5/4730 Support design library. Support Design library Adds (API 9+) back support to a number of 5.0 lollipop widgets and material design pieces –
Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Cosc 5/4730 RecyclerView And more..
Lab7 – Appendix.
Introduction to android
Android Programming - Features
CS499 – Mobile Application Development
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
Further android gui programming
ListView: Part 2.
Tashkent Weather ANDROID CLUB 2015.
תכנות ב android אליהו חלסצ'י.
Android Programming Lecture 6
CIS 470 Mobile App Development
null, true, and false are also reserved.
Android Lists and Fragments
Android Topics Custom ArrayAdapters
Android Topics Custom ArrayAdapters Creating an Event Listener
Android Developer Fundamentals V2
Android Developer Fundamentals V2 Lesson 4
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
ListView ? BaseAdapter ?.
Reactive Android Development
// Please Setting App_name to Send Successful
Lasalle-App Tecnología Móvil.
CA16R405 - Mobile Application Development (Theory)
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Anekdot ANDROID CLUB 2015

Сегодня  Navigation Drawer  CardView  Calligraphy  TextToSpeech

Шаг 1: Создать проект  Создавайте новый проект  Activity – Navigation Drawer Activity

Шаг 2: Navigation Drawer  Найдите res/menu/activity_main_drawer.xml  Добавьте три элемента: 1. Aнекдоты 2. Афоризмы 3. Цитаты

Решение 2: Navigation Drawer

Шаг 3: updateContent()  В MainActivity создавайте новый метод – updateContent  Ничего не возвращает  Принимает int type  Показывайте type в тосте  Вызывайте метод при запуске программы  Вызывайте метод при выбора элемента в navigation drawer – Анекдоты (1), Афоризмы (4), Цитаты(5)

Решение 3: "StatementWithEmptyBody" public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id. nav_joke ) { updateContent(1); } else if (id == R.id. nav_aphorism ) { updateContent(4); } else if (id == R.id. nav_citation ) { updateContent(5); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id. drawer_layout ); drawer.closeDrawer(GravityCompat. START ); return true ; }

Шаг 4: Получить данные  Добавьте разрешение: android.permission.INTERNET  Добавьте библиотеку: compile 'com.loopj.android:android-async-  В методе updateContent() получите данные c:  [type]  Кодировка данных - windows-1251

Решение 4: Получит данные public void updateContent( int type) { AsyncHttpClient client = new AsyncHttpClient(); String url = " + type; client.get(url, new AsyncHttpResponseHandler() public void onSuccess( int statusCode, Header[] headers, byte [] responseBody) { String json = null ; try { json = new String(responseBody, "windows-1251" ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } public void onFailure( int statusCode, Header[] headers, byte [] responseBody, Throwable error) { } }); }

Шаг 5: Лист  Создавайте лист строк – contents  Используя оператор цикла получите данные 10 раз  Каждый раз добавьте содержание content в contents

Решение 5: Лист final ArrayList contents = new ArrayList<>(); for ( int i = 0; i < 10; i++) { client.get(url, new AsyncHttpResponseHandler() public void onSuccess( int statusCode, Header[] headers, byte [] responseBody) { String json = null ; try { json = new String(responseBody, "windows-1251" ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String[] parts = json.split( "\"" ); String content = parts[3]; contents.add(content); public void onFailure( int statusCode, Header[] headers, byte [] responseBody, Throwable error) { } }); }

Шаг 6: Layout  Добавьте библиотеку: compile 'com.android.support:cardview-v7:23.1.0’  Создавайте layout: listitem_content  Добавьте в listitem - android.support.v7.widget.CardView  В CardView добавьте TextView - tvMyContent

Решение 6: Layout

Шаг 7: Adapter  Создавайте новый класс – ContentsAdapter  Наследник класса BaseAdapter  Конструктор принимает Context context, ArrayList contents - и инициализирует context, contents  В методе getView – установите значение в tvMyContent

Шаг 7: Adapter public class ContentsAdapter extends BaseAdapter { Context context ; ArrayList contents ; public ContentsAdapter(Context context, ArrayList contents) { this. context = context; this. contents = contents; public int getCount() { return contents.size(); public Object getItem( int position) { return contents.get(position); public long getItemId( int position) { return position; public View getView( int position, View convertView, ViewGroup parent) { View view = parent.inflate( context, R.layout. listitem_content, null ); TextView tvMyContent = (TextView) view.findViewById(R.id. tvMyContent ); String content = (String) getItem(position); tvMyContent.setText(content); return view; } }

Шаг 8: Показывать контент  Добавьте ListView – lvContents в сontent_main  Если после добавление контента в список, количество контента – 10 показывайте контент в lvContents

Решение 8: Показывать контент if (contents.size() == 10) { ListView lvContents = (ListView) findViewById(R.id. lvContents ); final ContentsAdapter adapter = new ContentsAdapter(MainActivity. this, contents); lvContents.setAdapter(adapter); }

Шаг 9: TextToSpeech  MainActivity имплементирует TextToSpeech.OnInitListener  Создавайте объект класса TextToSpeech - tts  Имплементируйте метод onInit()  В методе onInit проверьте status  Если статус – TextToSpeech.SUCCESS то установите язык по умолчанию русским, если нет показывайте в тосте что ошибка  Получите результат установки языка и проверьте  Если резултать равно result LANG_MISSING_DATA или TextToSpeech. LANG_NOT_SUPPORTED, показывайте тост что язык не поддерживается  При нажатии один из анекдотов, анекдот должен читаться

Решение 9: TextToSpeech public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, TextToSpeech.OnInitListener { private TextToSpeech mTTS public void onInit( int status) { // TODO Auto-generated method stub if (status == TextToSpeech. SUCCESS ) { Locale locale = new Locale( "ru" ); int result = mTTS.setLanguage(locale); //int result = mTTS.setLanguage(Locale.getDefault()); if (result == TextToSpeech. LANG_MISSING_DATA || result == TextToSpeech. LANG_NOT_SUPPORTED ) { Log.e( "TTS", "Извините, этот язык не поддерживается" ); } } else { Log.e( "TTS", "Ошибка!" ); } }

Шаг 10: Каллиграфия  Добавьте библиотеку: compile 'uk.co.chrisjenx:calligraphy:2.1.0’  Перейдите в вкладку Project app/src/main -> New- >Folder->Assets Folder  В папку assets добавьте папку fonts  В папку fonts добавьте шрифт – RobotoLight.ttf  В tvContent добавьте: fontPath="fonts/RobotoLight.ttf" tools:ignore="MissingPrefix"

Решение 10: Каллиграфия