Skip to content

Commit

Permalink
Merge pull request #9 from mitchhentges/title-feedback
Browse files Browse the repository at this point in the history
Title feedback animation
  • Loading branch information
Mitchell Hentges committed Dec 2, 2015
2 parents 58736ce + c1c2d36 commit 1f9bba9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Built using Gradle, because it's the default Android build tool supported by And
* Google Repository
* Android Support Repository
3. Get a [Google Maps API Key](https://developers.google.com/maps/documentation/android/signup)
4. In `~/gradle.properties`, enter `positionMockApiKey=YOUR_KEY_HERE`
4. In `~/gradle.properties`, enter `positionMockApiKey=YOUR_KEY_HERE` (or just set the environment variable `API_KEY`)
3. Run `gradle build`

## Purpose
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {

defaultConfig {
applicationId "ca.mitchhentges.positionmock"
minSdkVersion 11
minSdkVersion 12
//We're forced to use appcompat 21.0.3 due to Travis, and the target sdk should match
//noinspection OldTargetApi
targetSdkVersion 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
Expand All @@ -12,13 +11,9 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;

import java.io.IOException;

/**
* Created by Mitch
Expand All @@ -28,11 +23,13 @@ public class PositionMockActivity extends ActionBarActivity implements OnMapRead

private CurrentLocation currentLocation;
private Map map;
private TitleBarAnimator titleBarAnimator;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
titleBarAnimator = new TitleBarAnimator(this);

try {
map = new Map();
Expand Down Expand Up @@ -94,6 +91,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.apply:
titleBarAnimator.animateTitleBar();
map.applyTarget(currentLocation);
return true;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ca.mitchhentges.positionmock;

import android.animation.ValueAnimator;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

/**
* @author cacti
* @since 12/1/2015
*/
public class TitleBarAnimator {

private final ActionBarActivity activity;

public TitleBarAnimator(ActionBarActivity activity) {
this.activity = activity;
}

public void animateTitleBar() {
// Initial colors of each system bar.
final int toolbarColor = activity.getResources().getColor(R.color.toolbar_color);
final int toolbarToColor = activity.getResources().getColor(R.color.toolbar_to_color);

ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float position = animation.getAnimatedFraction();

if (position > 0.5) {
position = Math.abs(position - 1);
}

int blended = blendColors(toolbarColor, toolbarToColor, position * 2);
ColorDrawable background = new ColorDrawable(blended);
activity.getSupportActionBar().setBackgroundDrawable(background);
}
});
anim.setDuration(500).start();
}

private int blendColors(int from, int to, float ratio) {
final float inverseRatio = 1f - ratio;

final float r = Color.red(to) * ratio + Color.red(from) * inverseRatio;
final float g = Color.green(to) * ratio + Color.green(from) * inverseRatio;
final float b = Color.blue(to) * ratio + Color.blue(from) * inverseRatio;

return Color.rgb((int) r, (int) g, (int) b);
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="toolbar_color">#212121</color>
<color name="toolbar_to_color">#45B223</color>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ allprojects {
}

task wrapper(type: Wrapper) {
gradleVersion = '2.5'
gradleVersion = '2.9'
}
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 @@
#Fri Aug 07 20:19:40 PDT 2015
#Tue Dec 01 21:54:51 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip

0 comments on commit 1f9bba9

Please sign in to comment.