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

add Toolbar support #39

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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
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 @@
#Wed May 07 11:40:46 MSK 2014
#Thu Oct 15 09:53:28 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
10 changes: 7 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 4
targetSdkVersion 21
targetSdkVersion 23
versionCode 5
versionName "1.2.0"
}
Expand All @@ -20,5 +20,9 @@ android {
}
}

dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
}

// Used to push in maven
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'

Choose a reason for hiding this comment

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

You should append an empty line at the end of a file.

33 changes: 33 additions & 0 deletions library/src/com/devspark/appmsg/AppMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.internal.app.ToolbarActionBar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
Expand Down Expand Up @@ -336,6 +340,8 @@ private static AppMsg makeText(Activity context, CharSequence text, Style style,
result.mDuration = style.duration;
result.mFloating = floating;

result.setLayoutParams(getLayoutParams(context));

return result;
}

Expand Down Expand Up @@ -369,6 +375,8 @@ private static AppMsg makeText(Activity context, CharSequence text, Style style,
result.mView = view;
result.mDuration = style.duration;
result.mFloating = floating;

result.setLayoutParams(getLayoutParams(context));

view.setOnClickListener(clickListener);

Expand Down Expand Up @@ -426,6 +434,31 @@ public static AppMsg makeText(Activity context, int resId, Style style, int layo
return makeText(context, context.getResources().getText(resId), style, layoutId);
}

private static FrameLayout.LayoutParams getLayoutParams(Activity context){
if (context instanceof AppCompatActivity) {
android.support.v7.app.ActionBar supportActionBar = ((AppCompatActivity) context).getSupportActionBar();
if (supportActionBar instanceof ToolbarActionBar) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, supportActionBar.getHeight(), 0, 0);
return layoutParams;
}
}
// for sdk >= android L
// kind of hacky
if (Build.VERSION.SDK_INT >= 21) {
android.app.ActionBar actionBar = context.getActionBar();
if (actionBar != null && actionBar.getClass().getName().equals("com.android.internal.app.ToolbarActionBar")) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, actionBar.getHeight(), 0, 0);
return layoutParams;
}
return null;

Choose a reason for hiding this comment

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

Remove this line will not change the logic of your code.

}
return null;
}

/**
* Show the view for the specified duration.
*/
Expand Down
3 changes: 2 additions & 1 deletion sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateUnchanged">
android:windowSoftInputMode="stateUnchanged"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 7
targetSdkVersion 21
minSdkVersion 21
targetSdkVersion 23
versionCode 5
versionName "1.2.0"
}
Expand All @@ -22,5 +22,5 @@ android {

dependencies {
compile project(':library')
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:appcompat-v7:23.0.1'
}
158 changes: 82 additions & 76 deletions sample/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,91 +1,97 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
android:orientation="vertical">

<LinearLayout
android:id="@+id/animated_root"
<include layout="@layout/app_bar_main"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:animateLayoutChanges="true"
android:padding="48dp">
android:fillViewport="true">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textAllCaps="true"
android:text="@string/style"
/>
<Spinner
android:id="@+id/style_spnr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
android:entries="@array/styles"
android:prompt="@string/style"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textAllCaps="true"
android:text="@string/priority"
/>
<Spinner
android:id="@+id/priority_spnr"
<LinearLayout
android:id="@+id/animated_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
android:entries="@array/priorities"
android:prompt="@string/priority"
/>
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:gravity="center"
android:orientation="vertical"
android:padding="48dp">

<CheckBox
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/style"
android:textAllCaps="true" />

<LinearLayout
android:id="@+id/alt_parent"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:orientation="vertical" />
<Spinner
android:id="@+id/style_spnr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/styles"
android:minHeight="48dp"
android:prompt="@string/style"
android:spinnerMode="dropdown" />

<CheckBox
android:id="@+id/parent_chk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/priority"
android:textAllCaps="true" />

<EditText
android:id="@+id/provided_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_message_here"
/>
<Spinner
android:id="@+id/priority_spnr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/priorities"
android:minHeight="48dp"
android:prompt="@string/priority"
android:spinnerMode="dropdown" />

<Button
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="@string/show_appmsg" />
<CheckBox
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bottom" />

<Button
android:id="@+id/cancel_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="@string/cancel_all" />
<LinearLayout
android:id="@+id/alt_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:orientation="vertical"
android:visibility="gone" />

<CheckBox
android:id="@+id/parent_chk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_parent" />

<EditText
android:id="@+id/provided_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_message_here" />

<Button
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="@string/show_appmsg" />

<Button
android:id="@+id/cancel_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="@string/cancel_all" />

</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
10 changes: 10 additions & 0 deletions sample/res/layout/app_bar_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

9 changes: 9 additions & 0 deletions sample/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="SelectableItem">
<item name="android:background">@android:drawable/list_selector_background</item>
</style>
Expand Down
8 changes: 6 additions & 2 deletions sample/src/com/devspark/appmsg/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import android.animation.LayoutTransition;
import android.annotation.TargetApi;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
Expand All @@ -44,7 +45,7 @@
*
* @author Evgeny Shishkin
*/
public class MainActivity extends ActionBarActivity {
public class MainActivity extends AppCompatActivity {
private static final int NORMAL_POSITION = 1;
private static final int INFO_POSITION = 2;

Expand All @@ -61,6 +62,9 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

mProvidedMsg = (EditText) findViewById(R.id.provided_txt);
mStyle = (Spinner) findViewById(R.id.style_spnr);
mStyle.setSelection(INFO_POSITION);
Expand Down