Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working till Android Studio 1 rc2 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ android {
buildToolsVersion "21.1.1"

defaultConfig {
minSdkVersion 17
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.*;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Space;
Expand All @@ -42,24 +50,25 @@ private static class State {
final List<Bitmap> bitmaps = new ArrayList<Bitmap>();

State(int background, int map, int[] photos) {

this.background = background;
this.map = map;
this.photos = photos;
}
}

private final State[] mStates = {
new State(R.color.az, R.raw.map_az, new int[] {
new State(R.color.az, R.raw.map_az, new int[]{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made a lot of style changes and added a lof of empty lines. I don't wish to change the style of this file (it would be inconsistent with the rest of the project too).

R.drawable.photo_01_antelope,
R.drawable.photo_09_horseshoe,
R.drawable.photo_10_sky
}),
new State(R.color.ut, R.raw.map_ut, new int[] {
new State(R.color.ut, R.raw.map_ut, new int[]{
R.drawable.photo_08_arches,
R.drawable.photo_03_bryce,
R.drawable.photo_04_powell,
}),
new State(R.color.ca, R.raw.map_ca, new int[] {
new State(R.color.ca, R.raw.map_ca, new int[]{
R.drawable.photo_07_san_francisco,
R.drawable.photo_02_tahoe,
R.drawable.photo_05_sierra,
Expand All @@ -77,6 +86,7 @@ private static class State {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Expand All @@ -92,20 +102,23 @@ protected void onCreate(Bundle savedInstanceState) {
mIntroView.setOnReadyListener(new IntroView.OnReadyListener() {
@Override
public void onReady() {

loadPhotos();
}
});

((TrackingScrollView) findViewById(R.id.scroller)).setOnScrollChangedListener(
new TrackingScrollView.OnScrollChangedListener() {
@Override
public void onScrollChanged(TrackingScrollView source, int l, int t, int ol, int ot) {
handleScroll(source, t);
}
});
@Override
public void onScrollChanged(TrackingScrollView source, int l, int t, int ol, int ot) {

handleScroll(source, t);
}
});
}

private void handleScroll(ViewGroup source, int top) {

final float actionBarHeight = getActionBar().getHeight();
final float firstItemHeight = findViewById(R.id.scroller).getHeight() - actionBarHeight;
final float alpha = Math.min(firstItemHeight, Math.max(0, top)) / firstItemHeight;
Expand All @@ -132,13 +145,14 @@ private void handleScroll(ViewGroup source, int top) {

@SuppressWarnings("PointlessBitwiseExpression")
private void changeBackgroundColor(View decorView, float alpha) {

float srcR = ((mAccentColor >> 16) & 0xff) / 255.0f;
float srcG = ((mAccentColor >> 8) & 0xff) / 255.0f;
float srcB = ((mAccentColor >> 0) & 0xff) / 255.0f;
float srcG = ((mAccentColor >> 8) & 0xff) / 255.0f;
float srcB = ((mAccentColor >> 0) & 0xff) / 255.0f;

float dstR = ((mAccentColor2 >> 16) & 0xff) / 255.0f;
float dstG = ((mAccentColor2 >> 8) & 0xff) / 255.0f;
float dstB = ((mAccentColor2 >> 0) & 0xff) / 255.0f;
float dstG = ((mAccentColor2 >> 8) & 0xff) / 255.0f;
float dstB = ((mAccentColor2 >> 0) & 0xff) / 255.0f;

int r = (int) ((srcR + ((dstR - srcR) * alpha)) * 255.0f);
int g = (int) ((srcG + ((dstG - srcG) * alpha)) * 255.0f);
Expand All @@ -151,6 +165,7 @@ private void changeBackgroundColor(View decorView, float alpha) {
}

private void removeOverdraw(View decorView, float alpha) {

if (alpha >= 1.0f) {
// Note: setting a large negative translation Y to move the View
// outside of the screen is an optimization. We could make the view
Expand All @@ -160,20 +175,31 @@ private void removeOverdraw(View decorView, float alpha) {
// when the view is made visible again.
mIntroView.setTranslationY(-mIntroView.getHeight() * 2.0f);
}
int sdk = android.os.Build.VERSION.SDK_INT;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this local variable.

if (alpha >= 1.0f && decorView.getBackground() != null) {
mWindowBackground = decorView.getBackground();
decorView.setBackground(null);
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
decorView.setBackgroundDrawable(null);
} else {
decorView.setBackground(null);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well call setBackgroundDrawable() on all versions, with an @SuppressWarning to remove the deprecated warnings.

}
} else if (alpha < 1.0f && decorView.getBackground() == null) {
decorView.setBackground(mWindowBackground);
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
decorView.setBackgroundDrawable(mWindowBackground);
} else {
decorView.setBackground(mWindowBackground);
}
mWindowBackground = null;
}
}

private void loadPhotos() {

final Resources resources = getResources();
new Thread(new Runnable() {
@Override
public void run() {

for (State s : mStates) {
for (int resId : s.photos) {
s.bitmaps.add(BitmapFactory.decodeResource(resources, resId));
Expand All @@ -183,6 +209,7 @@ public void run() {
mIntroView.post(new Runnable() {
@Override
public void run() {

finishLoadingPhotos();
}
});
Expand All @@ -191,6 +218,7 @@ public void run() {
}

private void finishLoadingPhotos() {

mIntroView.stopWaitAnimation();

LinearLayout container = (LinearLayout) findViewById(R.id.container);
Expand All @@ -207,6 +235,7 @@ private void finishLoadingPhotos() {
}

private void addState(LayoutInflater inflater, LinearLayout container, final State state) {

final int margin = getResources().getDimensionPixelSize(R.dimen.activity_peek_margin);

final View view = inflater.inflate(R.layout.item_state, container, false);
Expand Down Expand Up @@ -241,7 +270,8 @@ private void addState(LayoutInflater inflater, LinearLayout container, final Sta
s.setOnScrollChangedListener(new TrackingHorizontalScrollView.OnScrollChangedListener() {
@Override
public void onScrollChanged(TrackingHorizontalScrollView source,
int l, int t, int oldl, int oldt) {
int l, int t, int oldl, int oldt) {

final float width = source.getWidth() - margin;
final float alpha = Math.min(width, Math.max(0, l)) / width;

Expand All @@ -264,8 +294,14 @@ public void onScrollChanged(TrackingHorizontalScrollView source,
}

private void removeStateOverdraw(View stateView, State state, float alpha) {

if (alpha >= 1.0f && stateView.getBackground() != null) {
stateView.setBackground(null);
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
stateView.setBackgroundDrawable(null);
} else {
stateView.setBackground(null);
}
stateView.findViewById(R.id.state).setVisibility(View.INVISIBLE);
} else if (alpha < 1.0f && stateView.getBackground() == null) {
stateView.setBackgroundResource(state.background);
Expand All @@ -275,12 +311,14 @@ private void removeStateOverdraw(View stateView, State state, float alpha) {

@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();
if (id == R.id.action_about) {
Toast.makeText(this, R.string.text_about, Toast.LENGTH_LONG).show();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
classpath 'com.android.tools.build:gradle:0.14.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Nov 10 16:11:56 CET 2014
#Thu Nov 27 19:14:06 IST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip