This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Dimitry Ivanov
committed
Sep 3, 2016
0 parents
commit b894a68
Showing
96 changed files
with
1,827 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,51 @@ | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
|
||
/gradle | ||
gradlew | ||
gradlew.bat | ||
|
||
**/build | ||
|
||
*.iml | ||
|
||
# built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# files for the dex VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# generated files | ||
bin/ | ||
gen/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
gradle.properties | ||
|
||
# Project configuration file (target-sdk-version) | ||
.DS_Store | ||
project.properties | ||
out | ||
|
||
# Eclipse project files | ||
.classpath | ||
.project | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Intellij project files | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
.gradle/ |
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,25 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
|
||
compileSdkVersion SDK_VERSION | ||
buildToolsVersion BUILD_TOOLS_VERSION | ||
|
||
defaultConfig { | ||
applicationId "ru.noties.sbv.sample" | ||
minSdkVersion MIN_SDK_VERSION | ||
targetSdkVersion SDK_VERSION | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:24.2.0' | ||
compile project(':library') | ||
compile 'ru.noties:debug:2.0.2@jar' | ||
compile 'com.android.support:recyclerview-v7:24.2.0' | ||
compile 'ru.noties:ccf:1.0.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:\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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="ru.noties.sbv.sample" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<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"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".SampleActivity"/> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2016 Dimitry Ivanov ([email protected]) | ||
* | ||
* 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 ru.noties.sbv.sample; | ||
|
||
import android.graphics.drawable.Drawable; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.content.ContextCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import ru.noties.sbv.ScrollingBackgroundView; | ||
|
||
public abstract class BaseFragment extends Fragment { | ||
|
||
private ScrollingBackgroundView mScrollingBackgroundView; | ||
|
||
@Override | ||
public abstract View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle sis); | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle sis) { | ||
super.onViewCreated(view, sis); | ||
|
||
mScrollingBackgroundView = findView(view, R.id.scrolling_background_view); | ||
} | ||
|
||
public void setDrawable(Drawable drawable) { | ||
mScrollingBackgroundView.setDrawable(drawable); | ||
} | ||
|
||
public void setDrawable(int drawable) { | ||
setDrawable(ContextCompat.getDrawable(getContext(), drawable)); | ||
} | ||
|
||
protected ScrollingBackgroundView scrollingBackgroundView() { | ||
return mScrollingBackgroundView; | ||
} | ||
|
||
protected static <V extends View> V findView(View view, int id) { | ||
//noinspection unchecked | ||
return (V) view.findViewById(id); | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
app/src/main/java/ru/noties/sbv/sample/MainActivity.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,136 @@ | ||
/* | ||
* Copyright 2016 Dimitry Ivanov ([email protected]) | ||
* | ||
* 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 ru.noties.sbv.sample; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.Window; | ||
import android.widget.TextView; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import ru.noties.debug.Debug; | ||
import ru.noties.debug.out.AndroidLogDebugOutput; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
static { | ||
Debug.init(new AndroidLogDebugOutput(true)); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
final Adapter adapter = new Adapter(this, new Adapter.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(String fragmentName) { | ||
final Intent intent = SampleActivity.makeIntent(MainActivity.this, fragmentName); | ||
startActivity(intent); | ||
} | ||
}); | ||
adapter.setItems(items()); | ||
|
||
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
|
||
private static List<Item> items() { | ||
return Arrays.asList( | ||
new Item("Space Explorer", SpaceExplorerFragment.class.getName()), | ||
new Item("Parallax", ParallaxFragment.class.getName()), | ||
new Item("Recycler View", RecyclerFragment.class.getName()), | ||
new Item("View Pager", ViewPagerFragment.class.getName()) | ||
); | ||
} | ||
|
||
private static class Item { | ||
|
||
final String name; | ||
final String fragmentClassName; | ||
|
||
Item(String name, String fragmentClassName) { | ||
this.name = name; | ||
this.fragmentClassName = fragmentClassName; | ||
} | ||
} | ||
|
||
private static class Adapter extends RecyclerView.Adapter<Adapter.Holder> { | ||
|
||
interface OnItemClickListener { | ||
void onItemClick(String fragmentName); | ||
} | ||
|
||
private final LayoutInflater mInflater; | ||
private final OnItemClickListener mOnItemClickListener; | ||
|
||
private List<Item> mItems; | ||
|
||
Adapter(Context context, OnItemClickListener onItemClickListener) { | ||
this.mInflater = LayoutInflater.from(context); | ||
this.mOnItemClickListener = onItemClickListener; | ||
} | ||
|
||
public void setItems(List<Item> items) { | ||
this.mItems = items; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public Holder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new Holder(mInflater.inflate(R.layout.adapter_main_item, parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(Holder holder, int position) { | ||
final Item item = mItems.get(position); | ||
holder.text.setText(item.name); | ||
holder.text.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mOnItemClickListener.onItemClick(item.fragmentClassName); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mItems != null ? mItems.size() : 0; | ||
} | ||
|
||
static class Holder extends RecyclerView.ViewHolder { | ||
|
||
final TextView text; | ||
|
||
public Holder(View itemView) { | ||
super(itemView); | ||
|
||
text = (TextView) itemView.findViewById(R.id.adapter_main_text); | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/src/main/java/ru/noties/sbv/sample/ParallaxFragment.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,74 @@ | ||
/* | ||
* Copyright 2016 Dimitry Ivanov ([email protected]) | ||
* | ||
* 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 ru.noties.sbv.sample; | ||
|
||
import android.animation.FloatEvaluator; | ||
import android.animation.ValueAnimator; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import ru.noties.sbv.ScrollingBackgroundView; | ||
|
||
public class ParallaxFragment extends BaseFragment { | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle sis) { | ||
return inflater.inflate(R.layout.fragment_parallax, parent, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle sis) { | ||
super.onViewCreated(view, sis); | ||
|
||
final int step = getResources().getDimensionPixelSize(R.dimen.space_explorer_step); | ||
|
||
{ | ||
final ScrollingBackgroundView clouds = findView(view, R.id.fragment_parallax_clouds); | ||
setUp(clouds, step, 1.F); | ||
} | ||
|
||
{ | ||
final ScrollingBackgroundView birds = findView(view, R.id.fragment_parallax_bird); | ||
setUp(birds, step, 1.5F); | ||
} | ||
} | ||
|
||
private void setUp(final ScrollingBackgroundView view, final int step, final float speed) { | ||
view.postOnAnimation(new Runnable() { | ||
@Override | ||
public void run() { | ||
final ValueAnimator animator = ValueAnimator.ofFloat(.0F, 1.F); | ||
animator.setEvaluator(new FloatEvaluator()); | ||
animator.setDuration(400L); | ||
animator.setRepeatMode(ValueAnimator.RESTART); | ||
animator.setRepeatCount(ValueAnimator.INFINITE); | ||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
view.scrollBy( | ||
(int) (step * speed + .5F), | ||
0 | ||
); | ||
} | ||
}); | ||
animator.start(); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.