-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Chris Banes
committed
May 28, 2015
1 parent
6678cdb
commit 8573642
Showing
69 changed files
with
1,517 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
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 @@ | ||
Cheesesquare Sample | ||
=================================== | ||
|
||
Demos the new Android Design library. | ||
|
||
Pre-requisites | ||
-------------- | ||
|
||
- Android SDK v22 | ||
- Android Build Tools v22.0.1 | ||
- Android Support Repository v22.2 | ||
|
||
License | ||
------- | ||
|
||
Copyright 2014 The Android Open Source Project, Inc. | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
license agreements. See the NOTICE file distributed with this work for | ||
additional information regarding copyright ownership. The ASF licenses this | ||
file to you under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy of | ||
the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations under | ||
the License. |
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,34 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 22 | ||
buildToolsVersion "22.0.1" | ||
|
||
defaultConfig { | ||
applicationId "com.support.android.designlibdemo" | ||
minSdkVersion 9 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
compile 'com.android.support:design:22.2.0' | ||
compile 'com.android.support:appcompat-v7:22.2.0' | ||
compile 'com.android.support:cardview-v7:22.2.0' | ||
compile 'com.android.support:recyclerview-v7:22.2.0' | ||
|
||
compile 'com.github.bumptech.glide:glide:3.6.0' | ||
compile 'de.hdodenhof:circleimageview:1.3.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 /usr/local/google/home/chrisbanes/bin/current-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 *; | ||
#} |
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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2015 The Android Open Source Project | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.support.android.designlibdemo"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.DesignDemo"> | ||
|
||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".CheeseDetailActivity" /> | ||
|
||
</application> | ||
|
||
</manifest> |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/support/android/designlibdemo/CheeseDetailActivity.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 @@ | ||
/* | ||
* Copyright (C) 2015 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.support.android.designlibdemo; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.design.widget.CollapsingToolbarLayout; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.ImageView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.util.Random; | ||
|
||
public class CheeseDetailActivity extends AppCompatActivity { | ||
|
||
public static final String EXTRA_NAME = "cheese_name"; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_detail); | ||
|
||
Intent intent = getIntent(); | ||
final String cheeseName = intent.getStringExtra(EXTRA_NAME); | ||
|
||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
CollapsingToolbarLayout collapsingToolbar = | ||
(CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); | ||
collapsingToolbar.setTitle(cheeseName); | ||
|
||
loadBackdrop(); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
finish(); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
private void loadBackdrop() { | ||
final ImageView imageView = (ImageView) findViewById(R.id.backdrop); | ||
Glide.with(this).load(Cheeses.getRandomCheeseDrawable()).centerCrop().into(imageView); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.sample_actions, menu); | ||
return true; | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
app/src/main/java/com/support/android/designlibdemo/CheeseListFragment.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,138 @@ | ||
/* | ||
* Copyright (C) 2015 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.support.android.designlibdemo; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.widget.TextViewCompat; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.TypedValue; | ||
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.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class CheeseListFragment extends Fragment { | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
RecyclerView rv = (RecyclerView) inflater.inflate( | ||
R.layout.fragment_cheese_list, container, false); | ||
setupRecyclerView(rv); | ||
return rv; | ||
} | ||
|
||
private void setupRecyclerView(RecyclerView recyclerView) { | ||
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext())); | ||
recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(getActivity(), | ||
getRandomSublist(Cheeses.sCheeseStrings, 30))); | ||
} | ||
|
||
private List<String> getRandomSublist(String[] array, int amount) { | ||
ArrayList<String> list = new ArrayList<>(amount); | ||
Random random = new Random(); | ||
while (list.size() < amount) { | ||
list.add(array[random.nextInt(array.length)]); | ||
} | ||
return list; | ||
} | ||
|
||
public static class SimpleStringRecyclerViewAdapter | ||
extends RecyclerView.Adapter<SimpleStringRecyclerViewAdapter.ViewHolder> { | ||
|
||
private final TypedValue mTypedValue = new TypedValue(); | ||
private int mBackground; | ||
private List<String> mValues; | ||
|
||
public static class ViewHolder extends RecyclerView.ViewHolder { | ||
public String mBoundString; | ||
|
||
public final View mView; | ||
public final ImageView mImageView; | ||
public final TextView mTextView; | ||
|
||
public ViewHolder(View view) { | ||
super(view); | ||
mView = view; | ||
mImageView = (ImageView) view.findViewById(R.id.avatar); | ||
mTextView = (TextView) view.findViewById(android.R.id.text1); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString() + " '" + mTextView.getText(); | ||
} | ||
} | ||
|
||
public String getValueAt(int position) { | ||
return mValues.get(position); | ||
} | ||
|
||
public SimpleStringRecyclerViewAdapter(Context context, List<String> items) { | ||
context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); | ||
mBackground = mTypedValue.resourceId; | ||
mValues = items; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.list_item, parent, false); | ||
view.setBackgroundResource(mBackground); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final ViewHolder holder, int position) { | ||
holder.mBoundString = mValues.get(position); | ||
holder.mTextView.setText(mValues.get(position)); | ||
|
||
holder.mView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Context context = v.getContext(); | ||
Intent intent = new Intent(context, CheeseDetailActivity.class); | ||
intent.putExtra(CheeseDetailActivity.EXTRA_NAME, holder.mBoundString); | ||
|
||
context.startActivity(intent); | ||
} | ||
}); | ||
|
||
Glide.with(holder.mImageView.getContext()) | ||
.load(Cheeses.getRandomCheeseDrawable()) | ||
.fitCenter() | ||
.into(holder.mImageView); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mValues.size(); | ||
} | ||
} | ||
} |
Oops, something went wrong.