forked from guolindev/booksource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony
committed
Oct 4, 2016
1 parent
41eb65f
commit 73695ca
Showing
57 changed files
with
993 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.example.materialtest" | ||
minSdkVersion 15 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:design:24.2.1' | ||
compile 'de.hdodenhof:circleimageview:2.1.0' | ||
compile 'com.android.support:recyclerview-v7:24.2.1' | ||
compile 'com.android.support:cardview-v7:24.2.1' | ||
compile 'com.github.bumptech.glide:glide:3.7.0' | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
...ter12/MaterialTest/app/src/androidTest/java/com/example/materialtest/ApplicationTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.materialtest; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.materialtest"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="Fruits"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".FruitActivity" | ||
android:theme="@style/FruitActivityTheme"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
22 changes: 22 additions & 0 deletions
22
chapter12/MaterialTest/app/src/main/java/com/example/materialtest/Fruit.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.materialtest; | ||
|
||
public class Fruit { | ||
|
||
private String name; | ||
|
||
private int imageId; | ||
|
||
public Fruit(String name, int imageId) { | ||
this.name = name; | ||
this.imageId = imageId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getImageId() { | ||
return imageId; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
chapter12/MaterialTest/app/src/main/java/com/example/materialtest/FruitActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.example.materialtest; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.support.design.widget.CollapsingToolbarLayout; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.MenuItem; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
public class FruitActivity extends AppCompatActivity { | ||
|
||
public static final String FRUIT_NAME = "fruit_name"; | ||
|
||
public static final String FRUIT_IMAGE_ID = "fruit_image_id"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fruit); | ||
Intent intent = getIntent(); | ||
String fruitName = intent.getStringExtra(FRUIT_NAME); | ||
int fruitImageId = intent.getIntExtra(FRUIT_IMAGE_ID, 0); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); | ||
ImageView fruitImageView = (ImageView) findViewById(R.id.fruit_image_view); | ||
TextView fruitContentText = (TextView) findViewById(R.id.fruit_content_text); | ||
setSupportActionBar(toolbar); | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
} | ||
collapsingToolbar.setTitle(fruitName); | ||
Glide.with(this).load(fruitImageId).into(fruitImageView); | ||
String fruitContent = generateFruitContent(fruitName); | ||
fruitContentText.setText(fruitContent); | ||
} | ||
|
||
private String generateFruitContent(String fruitName) { | ||
StringBuilder fruitContent = new StringBuilder(); | ||
for (int i = 0; i < 500; i++) { | ||
fruitContent.append(fruitName); | ||
} | ||
return fruitContent.toString(); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
finish(); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
chapter12/MaterialTest/app/src/main/java/com/example/materialtest/FruitAdapter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.materialtest; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v7.widget.CardView; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.util.List; | ||
|
||
public class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{ | ||
|
||
private static final String TAG = "FruitAdapter"; | ||
|
||
private Context mContext; | ||
|
||
private List<Fruit> mFruitList; | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
CardView cardView; | ||
ImageView fruitImage; | ||
TextView fruitName; | ||
|
||
public ViewHolder(View view) { | ||
super(view); | ||
cardView = (CardView) view; | ||
fruitImage = (ImageView) view.findViewById(R.id.fruit_image); | ||
fruitName = (TextView) view.findViewById(R.id.fruit_name); | ||
} | ||
} | ||
|
||
public FruitAdapter(List<Fruit> fruitList) { | ||
mFruitList = fruitList; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
if (mContext == null) { | ||
mContext = parent.getContext(); | ||
} | ||
View view = LayoutInflater.from(mContext).inflate(R.layout.fruit_item, parent, false); | ||
final ViewHolder holder = new ViewHolder(view); | ||
holder.cardView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
int position = holder.getAdapterPosition(); | ||
Fruit fruit = mFruitList.get(position); | ||
Intent intent = new Intent(mContext, FruitActivity.class); | ||
intent.putExtra(FruitActivity.FRUIT_NAME, fruit.getName()); | ||
intent.putExtra(FruitActivity.FRUIT_IMAGE_ID, fruit.getImageId()); | ||
mContext.startActivity(intent); | ||
} | ||
}); | ||
return holder; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
Fruit fruit = mFruitList.get(position); | ||
holder.fruitName.setText(fruit.getName()); | ||
Glide.with(mContext).load(fruit.getImageId()).into(holder.fruitImage); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mFruitList.size(); | ||
} | ||
|
||
} |
Oops, something went wrong.