Last active
November 8, 2017 15:33
-
-
Save brunoazevedomendonca/eccd86ccc283092180396085589b925e to your computer and use it in GitHub Desktop.
Localizator Android Studio 2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 26 | |
buildToolsVersion "26.0.1" | |
defaultConfig { | |
applicationId "br.com.example.testfinder" | |
minSdkVersion 15 | |
targetSdkVersion 26 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
compile fileTree(include: ['*.jar'], dir: 'libs') | |
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | |
exclude group: 'com.android.support', module: 'support-annotations' | |
}) | |
compile 'com.android.support:appcompat-v7:26.0.0-alpha1' | |
testCompile 'junit:junit:4.12' | |
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="br.com.example.testfinder"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".main.MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name=".add_address.AddAddressActivity" /> | |
<activity android:name=".show_addresses.ShowAddressesActivity"></activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.example.testfinder.add_address; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import br.com.example.testfinder.R; | |
public class AddAddressActivity extends AppCompatActivity { | |
TextView edtAddress; | |
Button btnAdd; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_add_address); | |
edtAddress = (TextView) findViewById(R.id.edt_address); | |
btnAdd = (Button) findViewById(R.id.btn_add); | |
btnAdd.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//verifica se há um endereço digitado | |
if (edtAddress.getText().toString().isEmpty()){ | |
Toast.makeText(AddAddressActivity.this, "Digite o endereço que deseja adicionar", Toast.LENGTH_SHORT).show(); | |
}else { | |
//retorna o endereço para a MainActivity | |
Intent resultIntent = new Intent(); | |
resultIntent.putExtra("movie_name", edtAddress.getText().toString()); | |
setResult(Activity.RESULT_OK, resultIntent); | |
finish(); | |
} | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.example.testfinder.main; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import br.com.example.testfinder.R; | |
import br.com.example.testfinder.add_address.AddAddressActivity; | |
import br.com.example.testfinder.show_addresses.ShowAddressesActivity; | |
import java.util.ArrayList; | |
public class MainActivity extends AppCompatActivity { | |
Button btnAddAddress; | |
Button btnShowAddresses; | |
//código utilizado para adicionar novos endereços | |
private final int RC_ADD_ADDRESS = 123; | |
//lista de endereços | |
private ArrayList<String> lstAddresses = new ArrayList<>(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
btnAddAddress = (Button) findViewById(R.id.btn_add_address); | |
btnShowAddresses = (Button) findViewById(R.id.btn_show_addresses); | |
//abre a activity para adicionar endereços | |
btnAddAddress.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent openAddAddressActivity = new Intent(MainActivity.this, AddAddressActivity.class); | |
startActivityForResult(openAddAddressActivity, RC_ADD_ADDRESS); | |
} | |
}); | |
//abre a activity para exibir os endereços cadastrados | |
btnShowAddresses.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//verifica se há endereços cadastrados antes executar a activity | |
if(lstAddresses.size() <= 0){ | |
Toast.makeText(MainActivity.this, "Não há endereços cadastrados", Toast.LENGTH_SHORT).show(); | |
}else{ | |
//abre a ShowAddressActivity enviando a lista de endereços | |
Intent openShowAddressActivity = new Intent(MainActivity.this, ShowAddressesActivity.class); | |
openShowAddressActivity.putStringArrayListExtra("addresses_list", lstAddresses); | |
startActivity(openShowAddressActivity); | |
} | |
} | |
}); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
//captura o resultado da tela de cadastro de endereços e adiciona na lista | |
if(requestCode == RC_ADD_ADDRESS && resultCode == Activity.RESULT_OK) { | |
lstAddresses.add(data.getStringExtra("movie_name")); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.example.testfinder.show_addresses; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import br.com.example.testfinder.R; | |
import java.util.List; | |
public class AddressesAdapter extends RecyclerView.Adapter<AddressesAdapter.ViewHolder>{ | |
private List<String> addressesList; | |
//Construtor para receber a lista | |
AddressesAdapter(List<String> addressesList){ | |
this.addressesList = addressesList; | |
} | |
//Infla o layout XML | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.address_list_item, parent, false); | |
return new ViewHolder(v); | |
} | |
//Seta os dados na lista | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
holder.tvAddress.setText(addressesList.get(position)); | |
} | |
//Retorna o tamanho da lista | |
@Override | |
public int getItemCount() { | |
return addressesList.size(); | |
} | |
//Mapeamento dos componentes da View | |
public class ViewHolder extends RecyclerView.ViewHolder{ | |
TextView tvAddress; | |
public ViewHolder(View itemView) { | |
super(itemView); | |
tvAddress = itemView.findViewById(R.id.tv_address); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.example.testfinder.show_addresses; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import br.com.example.testfinder.R; | |
import java.util.ArrayList; | |
public class ShowAddressesActivity extends AppCompatActivity { | |
RecyclerView rvAddresses; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_show_addresses); | |
rvAddresses = (RecyclerView) findViewById(R.id.rv_addresses); | |
//captura a lista enviada pela MainActivity | |
ArrayList<String> lstAddresses = getIntent().getStringArrayListExtra("addresses_list"); | |
//instancia um AddressesAdapter passando a lista de endereços | |
AddressesAdapter addressesAdapter = new AddressesAdapter(lstAddresses); | |
//seta o adapter no Recycler View | |
rvAddresses.setAdapter(addressesAdapter); | |
//cria o gerenciador de layouts | |
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | |
//seta o gerenciador de layouts no Recycler View | |
rvAddresses.setLayoutManager(layoutManager); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ScrollView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="br.com.example.testfinder.add_address.AddAddressActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:layout_margin="16dp"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/address" | |
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"/> | |
<EditText | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:inputType="textPostalAddress" | |
android:id="@+id/edt_address"/> | |
<Button | |
android:layout_width="250dp" | |
android:layout_height="wrap_content" | |
android:text="@string/add" | |
android:layout_marginTop="32dp" | |
android:layout_gravity="center" | |
android:id="@+id/btn_add"/> | |
</LinearLayout> | |
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ScrollView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="br.com.example.testfinder.main.MainActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<Button | |
android:layout_width="250dp" | |
android:layout_height="wrap_content" | |
android:text="@string/add_address" | |
android:id="@+id/btn_add_address"/> | |
<Button | |
android:layout_width="250dp" | |
android:layout_height="wrap_content" | |
android:text="@string/show_addresses" | |
android:id="@+id/btn_show_addresses"/> | |
</LinearLayout> | |
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="br.com.example.testfinder.show_addresses.ShowAddressesActivity"> | |
<android.support.v7.widget.RecyclerView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:scrollbars="vertical" | |
android:id="@+id/rv_addresses"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:id="@+id/address_item"> | |
<TextView | |
android:layout_marginLeft="16dp" | |
android:layout_marginRight="16dp" | |
android:paddingTop="8dp" | |
android:paddingBottom="8dp" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Rua Teste, 01, Cidade Teste - ET" | |
android:id="@+id/tv_address"/> | |
<View | |
android:layout_width="match_parent" | |
android:layout_marginRight="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_height="1dp" | |
android:background="@color/colorPrimary"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name">Localizator</string> | |
<string name="add_address">Adicionar Endereço</string> | |
<string name="show_addresses">Mostrar Endereços</string> | |
<string name="address">Endereço</string> | |
<string name="add">Adicionar</string> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
</style> | |
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment