31 Ocak 2017 Salı

Importing a Project

Android stüdyo ana sayfasında ımport diyerek daha önce hazırlanmış bir projeyi yükleyebiliyoruz.

Biraz uzun sürüyor.

Ensure that you have the latest extras (Android Studio library, Google Repository, etc) from the Android SDK Manager installed.
Ensure that you have all the required SDKs installed from the Android SDK Manager. For this course you will need SDK 15 through SDK 23.

Storage Options

https://developer.android.com/guide/topics/data/data-storage.html?utm_source=udacity&utm_medium=course&utm_campaign=android_basics

30 Ocak 2017 Pazartesi

Google Play Services

https://www.youtube.com/watch?v=M3Udfu6qidk

Volley

https://developer.android.com/training/volley/index.html?utm_source=udacity&utm_medium=course&utm_campaign=android_basics

Bu sayfada konuyu anlatan bi de ders var.

Creating Lists and Cards

https://developer.android.com/training/material/lists-cards.html?utm_source=udacity&utm_medium=course&utm_campaign=android_basics#RecyclerView

Supporting Tablets and Handsets

https://developer.android.com/guide/practices/tablets-and-handsets.html?utm_source=udacity&utm_medium=course&utm_campaign=android_basics#Fragments

Themes

https://developer.android.com/training/material/theme.html


xliff (Localization)

Mark message parts that should not be translated

Often strings contain text that shouldn’t be translated to other languages. Common examples might be a piece of code, a placeholder for a value, a special symbol, or a name. As you prepare your strings for translation, look for and mark text that should remain as-is, without translation, so that translators don’t change it.
To mark text that should not be translated, use an <xliff:g> placeholder tag. Here's an example tag that ensures the text "%1$s" will not be changed during translation (otherwise it could break the message):
<string name="countdown">
    <xliff:g id="time" example="5 days>%1$s</xliff:g>until holiday</string>
When you declare a placeholder tag, always add an id attribute that explains what the placeholder is for. If your apps will later replace the placeholder value, be sure to provide an example attribute to clarify the expected use.
Here are some more examples of placeholder tags:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Example placeholder for a special unicode symbol -->
<string name="star_rating">Check out our 5

    <xliff:g id="star">\u2605</xliff:g>
</string>
<!-- Example placeholder for a for a URL -->
<string name="app_homeurl">

    Visit us at <xliff:g id="application_homepage">http://my/app/home.html</xliff:g>
</string>
<!-- Example placeholder for a name -->
<string name="prod_name">

    Learn more at <xliff:g id="prod_gamegroup">Game Group</xliff:g>
</string>
<!-- Example placeholder for a literal -->
<string name="promo_message">

    Please use the "<xliff:g id="promotion_code">ABCDEFG</xliff:g>” to get a discount.
</string>

...
</resources>

Localization

Önce telefonun dil ayarlarından hangi dile uygun yapmak istiyorsak o dili seçiyoruz.

app / src / main / res / values / strings.xml
app / src / main / res / values-es / strings.xml
app / src / main / res / values-fr / strings.xml

ISO 639-1
EXAMPLE:
XML file saved at res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello!</string>
</resources>
This layout XML applies a string to a View:
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
This application code retrieves a string:
String string = getString(R.string.hello);

Common Intents

https://developer.android.com/guide/components/intents-common.html

Üstteki link,  sık kullanılan intent'leri içeriyor.

Aşağıdaki örnek Google Maps'te verilen koordinatı açıyor.

if kısmı, bu komutu çalıştıracak aplikasyon olup olmadığına bakıyor. Eğer uygun aplikasyon yoksa ve biz start komutunu verirsek uygulama patlıyor.

Intent intent = new Intent (Intent.ACTION_VIEW);intent.setData(Uri.parse("geo:47.6, -122.3"));if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity (intent);}

29 Ocak 2017 Pazar

Equality, Relational, and Conditional Operators

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html

Bilindik opeatörlerin dışında bir Objenin, hangi objeden türediğini sorgulamak için instanceOf kelimesi de bir operatördür.

If - then - else



https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html

28 Ocak 2017 Cumartesi

27 Ocak 2017 Cuma

Primitive Data Types

Java programlama dilinde değişkenler kullanılmadan önce tanımlanmalıdır. 

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

26 Ocak 2017 Perşembe

Logs

Another skill you will need for this exercise is the ability write to the Android Logs. More information can be found here, but essentially you write a Java statement like this in your code:

We’ve used Log.i() here which stands for an "information" level log. You have these other options as well:

TextView içindeki değeri alıp, Log'a yazıyoruz.

<TextView    android:id="@+id/menu_item_1"


public void printToLogs(View view) {
    // Find first menu item TextView and print the text to the logs    TextView menuItem1 = (TextView) findViewById(R.id.menu_item_1);    String input1 = menuItem1.getText().toString();    Log.i("EnterpriseActivity.java", input1);


25 Ocak 2017 Çarşamba

Getter and Setter Methods Review

Getter and Setter Methods Review

You’ve been using methods such as setText and setImageResource. These are called setter methods because they are meant to modify or manipulate one value of a view (such as the text or image that it stores). Conventionally they start with the word "set".
There’s also a category of methods called getter methods, whose sole purpose is to "get" one value of a view, such as getting the current text of a view. Conventionally they start with the word "get". We’ll be using some getter methods in this next exercise.

21 Ocak 2017 Cumartesi

Resources

Android Strudio içinde, soldan

Project / app / src / res

içinde bulunur.


Bir android uygulaması Resources ve Java Code'lardan oluşur.

Örneğin MainActivity.java dosyası Java dosyalarına bir örnektir.


Resources ise üstte göründüğü gibi imaj, xml, text, renk kodları gibi elemanlardan oluşur.



Returning Value from a Method

https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

Bir fonksiyonda iki return olamaz.

Metod signature'daki return type ile döndürdüğümüz return type birbirini tutmalı.

Return type yoksa void kullanmalıyız.

return; deyip bırakırsak fonksiyonu sonlandırdığımız anlamına gelir.

19 Ocak 2017 Perşembe

@param


Metod tanımlarken, metodun üzerinde input parametrelerinin açıklamasını yazmak iyi olur.

 /**     *     * @param message is the message to be shown when we press the order button.     */    private void displayMessage(String message) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);        priceTextView.setText(message);    }
}

Access Modifier

Bunların en popüler olanları Public ve Private.

Method Signature



Tipik bir metod tanımlama:

public double calculateAnswer(double wingSpan, int numberOfEngines,
                              double length, double grossTons) {
    //do the calculation here
}

Metod tanımlama için gerekli olanlar, metodun dönüş tipi, adı, bir çift parantez ve süslü parantezler arasında body.

Daha genel olarak metod tanımlamaları sırasıyla 6 komponente sahiptir.

1- Modifier: public, private.
2- Return Type: metod tarafından geri döndürülen değer tipi ya da void diyerek metodtan bir değer geri dönmediğini bildiriyoruz.
3- Metodun adı.
4- Parantez içinde parametre listesi, virgülle ayrılır ve önünde kendi data tipi bulunur. Eğer parametre yoksa boş parantez olur.
5- İstisna listesi.
6- Süslü parantezler içinde metod gövdesi. Lokal değişkenler burada tanımlanır.

Modifiers, return types ve parametreler daha sonra anlatılacak. İstisnalar daha sonraki derste anlatılacak.

Overloading Methods

Bu konuyu ben de ilk defa görüyorum. Aynı isimle birden fazla metod tanımlayabiliriz fakat her birinin kabul ettiği değişken ve tipi farklı olmalı. Fakat aynı parametre ismi ve data tipine sahip ikinci
bir metod tanımlayamayız.

public class DataArtist {
    ...
    public void draw(String s) {
        ...
    }
    public void draw(int i) {
        ...
    }
    public void draw(double f) {
        ...
    }
    public void draw(int i, double f) {
        ...
    }
}

17 Ocak 2017 Salı

Lesson 3A Kahve Sipariş Uygulaması


 XML 
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.ersanaskin.notopening.MainActivity"    android:orientation="vertical">
    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="TOPPINGS" />    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="15dp">        <CheckBox            android:text="CheckBox"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:id="@+id/checkBox"            android:layout_weight="1"            android:layout_marginRight="30dp"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="Whipped Cream" />    </LinearLayout>    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="QUANTITY"        android:layout_marginTop="20dp"/>    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="15dp">        <Button            android:layout_width="50dp"            android:layout_height="wrap_content"            android:text="-"            android:onClick="decreaseQuantity"/>        <TextView            android:id="@+id/quantity_text_view"            android:layout_width="50dp"            android:layout_height="wrap_content"            android:text="0"            android:textAlignment="center"/>        <Button            android:layout_width="50dp"            android:layout_height="wrap_content"            android:text="+"            android:onClick="increaseQuantity"/>    </LinearLayout>    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="ORDER SUMMARY"        android:layout_marginTop="15dp"/>    <TextView        android:id="@+id/order_summary_text_view"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="15dp"/>    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="ORDER"        android:onClick="displayMessage"/></LinearLayout>

JAVA
package com.example.ersanaskin.notopening;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.TextView;
public class MainActivity extends AppCompatActivity {

    int quantity = 0;    int coffeePrice = 10;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }

    public void increaseQuantity(View view){
        quantity ++;        display(quantity);    }

    public void decreaseQuantity(View view){
        quantity --;        display(quantity);    }

    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);        quantityTextView.setText("" + number);    }

    public void displayMessage(View v) {
        String message = "Hello Ersan. You bought " + quantity + " coffee. Please pay $" + quantity * coffeePrice + ".";        TextView orderSummaryTextView = (TextView) findViewById(R.id.order_summary_text_view);        orderSummaryTextView.setText(message);    }
}

16 Ocak 2017 Pazartesi


Ekrandaki uygulamayı çalıştıran Java kodu aşağıda. Oldukça basit, butona basınca submitOrder fonksiyonunu çağırıyor. submitOrder'da diğer 2 fonksiyonu tetikliyor.


package com.example.ersanaskin.justjava;
/** * Add your package below. Package name can be found in the project's AndroidManifest.xml file. 
* This is the package name our example uses: * * package com.example.android.justjava; */

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.text.NumberFormat;

/** * This app displays an order form to order coffee. */
public class MainActivity extends AppCompatActivity {

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

    /**     * This method is called when the order button is clicked.     */
        public void submitOrder(View view) {
        display(2 * 2);
        displayPrice(2 * 5);
        }

    /**     * This method displays the given quantity value on the screen.     */
    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
        quantityTextView.setText("" + number);
    }

    private void displayPrice(int number) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
    }

CourtCounter github


https://github.com/udacity/Court-Counter

15 Ocak 2017 Pazar

14 Ocak 2017 Cumartesi

Android Experts

https://developers.google.com/experts/all/technology/android?utm_source=udacity&utm_medium=course&utm_campaign=android_basics

12 Ocak 2017 Perşembe

Escape Characters

https://docs.oracle.com/javase/tutorial/java/data/characters.html

Escape Sequences
Escape SequenceDescription
\tInsert a tab in the text at this point.
\bInsert a backspace in the text at this point.
\nInsert a newline in the text at this point.
\rInsert a carriage return in the text at this point.
\fInsert a formfeed in the text at this point.
\'Insert a single quote character in the text at this point.
\"Insert a double quote character in the text at this point.
\\Insert a backslash character in the text at this point.

Android Studio'da Component Structure nerede?


Sol alt köşedeki kare ikona tıklıyoruz.


Yine sol tarafta Structure butonunu görebilirsiniz. Burdan XML yapısının görsel halini görebilirsin.

View Hierarchy Diagram


Debugging with Android Studio <-

10 Ocak 2017 Salı

Variables

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html


Instance Variables (Non-Static Fields) 
Her obje için değişen değer. Örneğin, currentSpeed

Class Variables (Static Fields)
Class kaç kez oluşturulursa oluşturulsun, bu değişkenden bir tane var. Örneğin, bir bisiklet tipi için static int numGears = 6; Bunun da üzerine final eklenirse, bu değişkenin hiç bir zaman değişmeyeceği belirtilir.

Local Variables 
Metodlar durumlarını local değişkenlerde tutar. Örnek, int count = 0;  Bunun dışında ekstra bi tanımlama yok. Bu değişkenin local olmasını tamamen bulunduğu yer belirliyor, yani bir metodun içinde olması. 

Parameters
public static void main(String[] args) Buradaki args parametredir ve her zaman değişken olarak adlandırılır (field değil).

Naming
Değişkenin ilk karakteri harf olmalı, sembol ya da rakam kullanılmaz. İkinci karakterde rakam ya da sembol kullanılabilir. Değişken isimleri anlaşılabilir olmalı. Eğer değişken ismi bir kelimeden oluşuyorsa hepsini küçük harf kullan. Birden çoksa kelimeden oluşuyorsa, ilk harfi büyük olsun ve her kelimenin başlangıcı büyük harfle başlasın. Eğer static bir sabitse böyle olabilir static final int NUM_GEARS = 6;


Rezerve edilmiş kelimeler: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

gist.github.com nedir?

Kod parçaları yayınlamak için bir servis.

Örnek:

https://gist.github.com/anonymous/fa134c55a4a43e8d6004

Java Operatörleri

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html

Bilmediklerim

Arithmetic Operators

%       Remainder operator

Unary Operators

!       Logical complement operator;
        inverts the value of a boolean

Conditional Operators

&&      Conditional-AND
||      Conditional-OR
?:      Ternary (shorthand for 
        if-then-else statement)

Type Comparison Operator

instanceof      Compares an object to 
                a specified type 

Bitwise and Bit Shift Operators

~       Unary bitwise complement
<<      Signed left shift
>>      Signed right shift
>>>     Unsigned right shift
&       Bitwise AND
^       Bitwise exclusive OR
|       Bitwise inclusive OR

Örnek Java Dosyası.

Butona basıldığında, ekrandaki TextView'in içeriğini 1 yapan Java kodu.

submitOrder fonksiyonu, XML içinde onClick özelliği ile tetikleniyor.

package com.example.ersanaskin.justjava;
/** * Add your package below. Package name can be found in the project's AndroidManifest.xml file. * This is the package name our example uses: * * package com.example.android.justjava; */
import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.TextView;
/** * This app displays an order form to order coffee. */public class MainActivity extends AppCompatActivity {

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

    /**     * This method is called when the order button is clicked.     */    public void submitOrder(View view) {
        display(1);    }

    /**     * This method displays the given quantity value on the screen.     */    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);        quantityTextView.setText("" + number);    }
}

Android Studio içinde MainActivity.java nerede?

Sol tarafta, dikey olarak yerleştirilmiş butonlardan, Project'e bastığımızda ağaç yapısını görüyoruz.
Res altında, drawable içinde imaj dosyaları var. Java altında ise MainActivity.java.


Linear Layout Örneği

Aşağıdaki ekran görüntüsü, daha aşağıdaki XML ile oluşturuldu.




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingLeft="16dp"    android:paddingRight="16dp"    android:orientation="vertical"    android:paddingTop="16dp">
    <TextView        android:id="@+id/quantity_text_view"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textAppearance="?android:textAppearanceLarge"        android:textColor="@android:color/black"        android:textStyle="bold"        android:text="quantity"        android:textAllCaps="true"/>
    <TextView        android:id="@+id/number_text_wiew"        android:layout_width="100dp"        android:layout_height="wrap_content"        android:textAppearance="?android:textAppearanceLarge"        android:textColor="@android:color/darker_gray"        android:textStyle="bold"        android:text="0"/>
    <Button        android:id="@+id/button"        android:layout_width="100dp"        android:layout_height="wrap_content"        android:text="button"        android:textAllCaps="true"/>
</LinearLayout>

Layout Planning

Hazırlamak istediğimiz layout'u önce planlamak işleri daha kolaylaştırabilir.

Önce hangi View Group'u kullanacağız. Aşağıdaki görüntü için LinearLayout uygun. 

Ve orientation için de;

android:orientation="vertical" .

QUANTITY= TextView.
0= TextView.
ORDER= Button






8 Ocak 2017 Pazar

RelativeLayout Örneği



<?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="match_parent">
    <ImageView        
android:id="@+id/imageRuya"
android:layout_width="100dp"        
android:layout_height="100dp"        
android:layout_margin="8dp"
android:scaleType="centerCrop"        
android:src="@drawable/ruya" />
    <TextView        
android:id="@+id/adi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rüya Aşkın"
android:textStyle="bold"
android:textAppearance="?android:textAppearanceMedium"
android:layout_alignTop="@+id/imageRuya"
android:layout_alignLeft="@+id/lakabi"
android:layout_alignStart="@+id/lakabi" />
<TextView
android:id="@+id/lakabi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lakabı: Prenses"
android:textAppearance="?android:textAppearanceSmall"
android:layout_below="@+id/adi"
android:layout_alignLeft="@+id/yasi"
android:layout_alignStart="@+id/yasi" />
    <TextView        android:id="@+id/yasi"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/lakabi"        android:layout_toRightOf="@id/imageRuya"        android:text="Yaş: 10"        android:textAppearance="?android:textAppearanceSmall" />
    <ImageView        android:id="@+id/imageOmer1"        android:layout_width="100dp"        android:layout_height="100dp"        android:layout_margin="8dp"        android:scaleType="centerCrop"        android:src="@drawable/omer"        android:layout_below="@id/imageRuya"/>
    <TextView        android:id="@+id/adi1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignTop="@id/imageOmer1"        android:layout_toRightOf="@id/imageOmer1"        android:text="Ömer Aşkın"        android:textStyle="bold"        android:textAppearance="?android:textAppearanceMedium" />    <TextView        android:id="@+id/lakabi1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/adi1"        android:layout_toRightOf="@id/imageOmer1"        android:text="Lakabı: Iron Man"        android:textAppearance="?android:textAppearanceSmall"        android:layout_marginTop="4dp"/>    <TextView        android:id="@+id/yasi1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/lakabi1"        android:layout_toRightOf="@id/imageOmer1"        android:text="Yaş: 6"        android:textAppearance="?android:textAppearanceSmall" /></RelativeLayout>