diff options
author | cretin45 <cretin45@gmail.com> | 2016-01-26 10:27:07 -0800 |
---|---|---|
committer | cretin45 <cretin45@gmail.com> | 2016-01-26 12:46:03 -0800 |
commit | 02164017d808640e32a2dfa668f70526854b5834 (patch) | |
tree | 1e394572f519c8ff64520d9043830926367c4121 | |
parent | 7d9ebd36aceddd6d1099d50e34de69f1413d5d0a (diff) | |
download | android_external_cyanogen_UICommon-02164017d808640e32a2dfa668f70526854b5834.tar.gz android_external_cyanogen_UICommon-02164017d808640e32a2dfa668f70526854b5834.tar.bz2 android_external_cyanogen_UICommon-02164017d808640e32a2dfa668f70526854b5834.zip |
Make into module
* Also added overload for overriding max lines in message
Change-Id: Ibcce8a53034990f37754f45fbfb0c9a566c19022
-rw-r--r-- | Android.mk | 32 | ||||
-rw-r--r-- | AndroidManifest.xml | 19 | ||||
-rw-r--r-- | src/com/cyngn/uicommon/view/Snackbar.java | 35 |
3 files changed, 82 insertions, 4 deletions
@@ -1 +1,31 @@ -# TODO: fill this in +# Copyright (C) 2016 CyanogenMod Project +# +# 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. + +LOCAL_PATH := $(call my-dir) + +# Here is the final static library that apps can link against. +# The R class is automatically excluded from the generated library. +# Applications that use this library must specify LOCAL_RESOURCE_DIR +# in their makefiles to include the resources in their package. +include $(CLEAR_VARS) +LOCAL_MODULE := uicommon +LOCAL_SRC_FILES := $(call all-java-files-under,src) +LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res +LOCAL_JAVA_LIBRARIES += android-support-v4 \ + android-support-v7-recyclerview + +LOCAL_AAPT_FLAGS := \ + --auto-add-overlay + +include $(BUILD_STATIC_JAVA_LIBRARY)
\ No newline at end of file diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..be59434 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 CyanogenMod Project + + 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. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.cyngn.uicommon"> + <application /> +</manifest> diff --git a/src/com/cyngn/uicommon/view/Snackbar.java b/src/com/cyngn/uicommon/view/Snackbar.java index d8779a5..f645577 100644 --- a/src/com/cyngn/uicommon/view/Snackbar.java +++ b/src/com/cyngn/uicommon/view/Snackbar.java @@ -167,12 +167,13 @@ public final class Snackbar { private int mDuration; private Callback mCallback; - private Snackbar(ViewGroup parent) { + private Snackbar(ViewGroup parent, int maxLines) { mParent = parent; mContext = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(mContext); mView = (SnackbarLayout) inflater.inflate(R.layout.layout_snackbar, mParent, false); + mView.setMaxLines(maxLines); } /** @@ -187,16 +188,36 @@ public final class Snackbar { * @param text The text to show. Can be formatted text. * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or {@link * #LENGTH_LONG} + * @param maxLines The maximum lines of the message text. */ public static Snackbar make(View view, CharSequence text, - @Duration int duration) { - Snackbar snackbar = new Snackbar(findSuitableParent(view)); + @Duration int duration, int maxLines) { + Snackbar snackbar = new Snackbar(findSuitableParent(view), maxLines); snackbar.setText(text); snackbar.setDuration(duration); return snackbar; } /** + * Make a Snackbar to display a message + * + * <p>Snackbar will try and find a parent view to hold Snackbar's view from the value given + * to {@code view}. Snackbar will walk up the view tree trying to find the window decor's + * content view. + * + * + * @param view The view to find a parent from. + * @param text The text to show. Can be formatted text. + * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or {@link + * #LENGTH_LONG} + */ + public static Snackbar make(View view, CharSequence text, + @Duration int duration) { + return make(view, text, duration, + view.getResources().getInteger(R.integer.config_snackbar_text_max_lines)); + } + + /** * Make a Snackbar to display a message. * * Make a Snackbar to display a message @@ -214,6 +235,10 @@ public final class Snackbar { return make(view, view.getResources().getText(resId), duration); } + public static Snackbar make(View view, int resId, @Duration int duration, int maxlines) { + return make(view, view.getResources().getText(resId), duration, maxlines); + } + private static ViewGroup findSuitableParent(View view) { ViewGroup fallback = null; do { @@ -525,6 +550,10 @@ public final class Snackbar { mActionView = (Button) findViewById(R.id.snackbar_action); } + void setMaxLines(int maxLines) { + mMessageView.setMaxLines(maxLines); + } + TextView getMessageView() { return mMessageView; } |