Skip to content

Commit

Permalink
adds toolbar styling attr
Browse files Browse the repository at this point in the history
adds playstore default btn
updates version to 0.4.2
  • Loading branch information
patrickfav committed Jan 29, 2017
1 parent 8eceed6 commit 3015233
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Releases

## v0.4.2

* adds feature to be able to theme toolbar text & icons
* adds playstore link default

## v0.4.1 (2017-01-27)

* fixes bug in demo activity were application context was used in shake detector to start activity
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Add the following to your dependencies ([add jcenter to your repositories](https

```gradle
dependencies {
compile 'at.favre.lib.hood:hood-extended:0.4.1'
compile 'at.favre.lib.hood:hood-extended:0.4.2'
}
```

Expand Down Expand Up @@ -400,6 +400,7 @@ and overlays for standalone views:
You can also define your own theme (extending `Theme.AppCompat` or `ThemeOverlay.AppCompat`)
but you must define the following attributes in it:

* `hoodToolbarTextColor`: toolbar text and icon color
* `hoodZebraColor`: highlighting color for odd rows
* `hoodTextSizeNormal`: default text size
* `hoodTextSizeHeader`: header text size
Expand All @@ -410,6 +411,7 @@ Here is an example with useful defaults:
```xml
<style name="HoodThemeDark" parent="Theme.AppCompat.NoActionBar">
...
<item name="hoodToolbarTextColor">@android:color/primary_text_dark</item>
<item name="hoodZebraColor">@color/hoodlib_zebra_color_dark</item>
<item name="hoodTextSizeNormal">@dimen/hoodlib_standard_text_size</item>
<item name="hoodTextSizeHeader">@dimen/hoodlib_header_text_size</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void run() {
PageUtil.addAction(secondPage, DefaultButtonDefinitions.getBatterySaverSettingsAction(), DefaultButtonDefinitions.getDisplaySettingsAction());
PageUtil.addAction(secondPage, DefaultButtonDefinitions.getInputModeSettingsAction(), DefaultButtonDefinitions.getStorageSettingsAction());
PageUtil.addAction(secondPage, DefaultButtonDefinitions.getSecuritySettingsAction(), DefaultButtonDefinitions.getInstalledAppSettings());
PageUtil.addAction(secondPage, DefaultButtonDefinitions.getPlayStoreLink(BuildConfig.APPLICATION_ID));

secondPage.add(new PackageInfoAssembler(PackageInfoAssembler.Type.APK_VERSION_INFO, PackageInfoAssembler.Type.APK_INSTALL_INFO).createSection(this, true));

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<item name="colorPrimaryDark">#FF8F00</item>
<item name="colorAccent">#6900FF</item>

<item name="hoodToolbarTextColor">@android:color/primary_text_dark</item>
<item name="hoodZebraColor">#fffaec</item>
<item name="hoodTextSizeNormal">18sp</item>
<item name="hoodTextSizeHeader">28sp</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task clean(type: Delete) {
}

ext {
versionNameApp = "0.4.1"
versionNameApp = "0.4.2"
versionNameLib = "$versionNameApp"
versionCode = getCiBuildNumber()
versionNameDep = "0.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -182,4 +183,23 @@ public void onClick(View v, Map.Entry<CharSequence, String> value) {
return null;
}
}

/**
* Opens the app with given package name either in play store app or as a normal link
*
* @param packageName ie. the applicationId
* @return the button def
*/
public static ButtonDefinition getPlayStoreLink(final String packageName) {
return new ButtonDefinition("Open in Playstore", new OnClickAction() {
@Override
public void onClick(View v, Map.Entry<CharSequence, String> value) {
try {
v.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
} catch (android.content.ActivityNotFoundException anfe) {
v.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -40,8 +49,8 @@ public static void start(Context context, Class<?> activityClass) {
/**
* Creates the intent for starting this
*
* @param context non-null
* @param activityClass the actual implementation class (cannot be figured out in static context)
* @param context non-null
* @param activityClass the actual implementation class (cannot be figured out in static context)
* @return the intent ready to start
*/
public static Intent createIntent(@NonNull Context context, Class<?> activityClass) {
Expand Down Expand Up @@ -109,9 +118,29 @@ protected void onPause() {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.hoodlib_menu_pophood, menu);

tintMenuItem(menu, R.id.action_refresh);
tintMenuItem(menu, R.id.action_app_info);
return true;
}

private void tintMenuItem(Menu menu, @IdRes int iconId) {
MenuItem favoriteItem = menu.findItem(iconId);
Drawable favoriteIcon = DrawableCompat.wrap(favoriteItem.getIcon());

TypedValue typedValue = new TypedValue();
Resources.Theme theme = getTheme();
theme.resolveAttribute(R.attr.hoodToolbarTextColor, typedValue, true);

TypedArray ta = obtainStyledAttributes(new int[]{R.attr.hoodToolbarTextColor});
@ColorRes int color = ta.getResourceId(0, android.R.color.white);
ta.recycle();

ColorStateList colorSelector = ResourcesCompat.getColorStateList(getResources(), color, getTheme());
DrawableCompat.setTintList(favoriteIcon, colorSelector);
favoriteItem.setIcon(favoriteIcon);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:theme="@style/HoodThemeToolbarStyle"
app:layout_scrollFlags="scroll|enterAlways"
tools:targetApi="lollipop"/>
</android.support.design.widget.AppBarLayout>
Expand Down
4 changes: 4 additions & 0 deletions hood-extended/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="hoodToolbarTextColor" format="reference|color"/>
</resources>
6 changes: 6 additions & 0 deletions hood-extended/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<item name="colorPrimary">@color/hoodLibDefaultColorPrimary</item>
<item name="colorPrimaryDark">@color/hoodLibDefaultColorPrimaryDark</item>
<item name="colorAccent">@color/hoodLibDefaultColorAccent</item>
<item name="hoodToolbarTextColor">@android:color/white</item>
<item name="hoodZebraColor">@color/hoodlib_zebra_color</item>
<item name="hoodTextSizeNormal">@dimen/hoodlib_standard_text_size</item>
<item name="hoodTextSizeHeader">@dimen/hoodlib_header_text_size</item>
Expand All @@ -44,10 +45,15 @@
<item name="colorPrimary">@color/hoodLibDefaultColorPrimary</item>
<item name="colorPrimaryDark">@color/hoodLibDefaultColorPrimaryDark</item>
<item name="colorAccent">@color/hoodLibDefaultColorAccent</item>
<item name="hoodToolbarTextColor">@android:color/white</item>
<item name="hoodZebraColor">@color/hoodlib_zebra_color_dark</item>
<item name="hoodTextSizeNormal">@dimen/hoodlib_standard_text_size</item>
<item name="hoodTextSizeHeader">@dimen/hoodlib_header_text_size</item>
<item name="hoodViewpagerTabTextColor">@android:color/primary_text_dark</item>
<item name="hoodViewpagerTabBackgroundColor">?attr/colorPrimary</item>
</style>

<style name="HoodThemeToolbarStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">?hoodToolbarTextColor</item>
</style>
</resources>

0 comments on commit 3015233

Please sign in to comment.