summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2014-10-14 12:23:55 -0700
committerlinus_lee <llee@cyngn.com>2014-11-20 12:51:32 -0800
commit2e720d9e87b41248bab1a3baa4552103038b0541 (patch)
treea073950045f5fe52eef5377a8694762a186707c6 /src
parent137f81b82727a42879e488fa2925a118940f11b7 (diff)
downloadandroid_packages_apps_Eleven-2e720d9e87b41248bab1a3baa4552103038b0541.tar.gz
android_packages_apps_Eleven-2e720d9e87b41248bab1a3baa4552103038b0541.tar.bz2
android_packages_apps_Eleven-2e720d9e87b41248bab1a3baa4552103038b0541.zip
Eleven : switch to toasts positioned towards the bottom of the screen to convey messages to user
https://cyanogen.atlassian.net/browse/MUSIC-88 Change-Id: I8a98038a5d7e2819b5f6aa51a505cb9c8b21de81
Diffstat (limited to 'src')
-rw-r--r--src/com/cyngn/eleven/utils/ApolloUtils.java1
-rw-r--r--src/com/cyngn/eleven/utils/CustomToast.java62
-rw-r--r--src/com/cyngn/eleven/utils/MusicUtils.java11
-rw-r--r--src/com/cyngn/eleven/utils/NavUtils.java4
-rw-r--r--src/com/devspark/appmsg/AppMsg.java313
-rw-r--r--src/com/devspark/appmsg/MsgManager.java196
6 files changed, 68 insertions, 519 deletions
diff --git a/src/com/cyngn/eleven/utils/ApolloUtils.java b/src/com/cyngn/eleven/utils/ApolloUtils.java
index c5c3040..851a3c4 100644
--- a/src/com/cyngn/eleven/utils/ApolloUtils.java
+++ b/src/com/cyngn/eleven/utils/ApolloUtils.java
@@ -48,7 +48,6 @@ import com.cyngn.eleven.cache.ImageFetcher;
import com.cyngn.eleven.ui.activities.ShortcutActivity;
import com.cyngn.eleven.widgets.ColorPickerView;
import com.cyngn.eleven.widgets.ColorSchemeDialog;
-import com.devspark.appmsg.AppMsg;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
diff --git a/src/com/cyngn/eleven/utils/CustomToast.java b/src/com/cyngn/eleven/utils/CustomToast.java
new file mode 100644
index 0000000..5c93076
--- /dev/null
+++ b/src/com/cyngn/eleven/utils/CustomToast.java
@@ -0,0 +1,62 @@
+package com.cyngn.eleven.utils;
+
+import android.app.Activity;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+import com.cyngn.eleven.R;
+
+/**
+ * Ancillary utilities class to customize the appearance of Toast messages
+ */
+public class CustomToast {
+
+ public static final int LENGTH_LONG = Toast.LENGTH_LONG;
+ public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
+
+ private Toast mToast;
+ private TextView mTextView;
+
+ public CustomToast(Activity activity, String message) {
+ mToast = new Toast( activity.getApplicationContext() );
+ LayoutInflater layoutInflater = activity.getLayoutInflater();
+ View toastView = layoutInflater.inflate(R.layout.custom_toast, null);
+ mToast.setView(toastView);
+
+ mTextView = (TextView) toastView.findViewById(R.id.toast_text_view);
+ if (message != null) {
+ mTextView.setText(message);
+ }
+
+ // set toast location
+ // centered with an offset in y expressed as % of display height
+ int displayHeight = activity.getWindow().getDecorView().getHeight();
+ int heightOffset = (int)(0.30 * displayHeight);
+ mToast.setGravity(Gravity.CENTER_HORIZONTAL, 0, heightOffset);
+
+ }
+
+ public static CustomToast makeText(Activity context, String text, int duration) {
+ CustomToast customToast = new CustomToast(context, text);
+ if (duration == CustomToast.LENGTH_LONG)
+ customToast.setDuration(duration);
+ else
+ customToast.setDuration(CustomToast.LENGTH_SHORT);
+
+ return customToast;
+ }
+
+ public void setDuration(int duration) {
+ mToast.setDuration(duration);
+ }
+
+ public void setMessage(String message) {
+ mTextView.setText(message);
+ }
+
+ public void show() {
+ mToast.show();
+ }
+}
diff --git a/src/com/cyngn/eleven/utils/MusicUtils.java b/src/com/cyngn/eleven/utils/MusicUtils.java
index 51e7ac7..57a33e0 100644
--- a/src/com/cyngn/eleven/utils/MusicUtils.java
+++ b/src/com/cyngn/eleven/utils/MusicUtils.java
@@ -51,7 +51,6 @@ import com.cyngn.eleven.model.AlbumArtistDetails;
import com.cyngn.eleven.provider.RecentStore;
import com.cyngn.eleven.provider.SongPlayCount;
import com.cyngn.eleven.service.MusicPlaybackTrack;
-import com.devspark.appmsg.AppMsg;
import java.io.File;
import java.util.Arrays;
@@ -1031,7 +1030,7 @@ public final class MusicUtils {
}
final String message = context.getResources().getQuantityString(
R.plurals.NNNtrackstoplaylist, numinserted, numinserted);
- AppMsg.makeText((Activity)context, message, AppMsg.STYLE_CONFIRM).show();
+ CustomToast.makeText((Activity)context, message, CustomToast.LENGTH_SHORT).show();
playlistChanged();
}
@@ -1050,7 +1049,7 @@ public final class MusicUtils {
});
final String message = context.getResources().getQuantityString(
R.plurals.NNNtracksfromplaylist, 1, 1);
- AppMsg.makeText((Activity)context, message, AppMsg.STYLE_CONFIRM).show();
+ CustomToast.makeText((Activity)context, message, CustomToast.LENGTH_SHORT).show();
playlistChanged();
}
@@ -1066,7 +1065,7 @@ public final class MusicUtils {
try {
mService.enqueue(list, MusicPlaybackService.LAST, sourceId, sourceType.mId);
final String message = makeLabel(context, R.plurals.NNNtrackstoqueue, list.length);
- AppMsg.makeText((Activity)context, message, AppMsg.STYLE_CONFIRM).show();
+ CustomToast.makeText((Activity)context, message,CustomToast.LENGTH_SHORT).show();
} catch (final RemoteException ignored) {
}
}
@@ -1100,7 +1099,7 @@ public final class MusicUtils {
Settings.System.putString(resolver, Settings.System.RINGTONE, uri.toString());
final String message = context.getString(R.string.set_as_ringtone,
cursor.getString(2));
- AppMsg.makeText((Activity)context, message, AppMsg.STYLE_CONFIRM).show();
+ CustomToast.makeText((Activity)context, message, CustomToast.LENGTH_SHORT).show();
}
} finally {
if (cursor != null) {
@@ -1529,7 +1528,7 @@ public final class MusicUtils {
final String message = makeLabel(context, R.plurals.NNNtracksdeleted, list.length);
- AppMsg.makeText((Activity)context, message, AppMsg.STYLE_CONFIRM).show();
+ CustomToast.makeText((Activity)context, message, CustomToast.LENGTH_SHORT).show();
// We deleted a number of tracks, which could affect any number of
// things
// in the media content domain, so update everything.
diff --git a/src/com/cyngn/eleven/utils/NavUtils.java b/src/com/cyngn/eleven/utils/NavUtils.java
index 1f8fdfd..8dad960 100644
--- a/src/com/cyngn/eleven/utils/NavUtils.java
+++ b/src/com/cyngn/eleven/utils/NavUtils.java
@@ -24,7 +24,6 @@ import com.cyngn.eleven.R;
import com.cyngn.eleven.ui.activities.HomeActivity;
import com.cyngn.eleven.ui.activities.SearchActivity;
import com.cyngn.eleven.ui.activities.SettingsActivity;
-import com.devspark.appmsg.AppMsg;
/**
* Various navigation helpers.
@@ -120,8 +119,7 @@ public final class NavUtils {
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, MusicUtils.getAudioSessionId());
context.startActivity(effects);
} catch (final ActivityNotFoundException notFound) {
- AppMsg.makeText(context, context.getString(R.string.no_effects_for_you),
- AppMsg.STYLE_ALERT);
+ CustomToast.makeText(context, context.getString(R.string.no_effects_for_you), CustomToast.LENGTH_SHORT).show();
}
}
diff --git a/src/com/devspark/appmsg/AppMsg.java b/src/com/devspark/appmsg/AppMsg.java
deleted file mode 100644
index 030c43c..0000000
--- a/src/com/devspark/appmsg/AppMsg.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright 2012 Evgeny Shishkin
- *
- * 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.
- */
-
-package com.devspark.appmsg;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.res.Resources;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup.LayoutParams;
-import android.widget.FrameLayout;
-import android.widget.TextView;
-
-import com.cyngn.eleven.R;
-
-/**
- * In-layout notifications. Based on {@link android.widget.Toast} notifications
- * and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
- *
- * @author e.shishkin
- *
- */
-public class AppMsg {
-
- /**
- * Show the view or text notification for a short period of time. This time
- * could be user-definable. This is the default.
- * @see #setDuration
- */
- public static final int LENGTH_SHORT = 3000;
-
- /**
- * Show the view or text notification for a long period of time. This time
- * could be user-definable.
- * @see #setDuration
- */
- public static final int LENGTH_LONG = 5000;
-
- /**
- * Show the text notification for a long period of time with a negative style.
- */
- public static final Style STYLE_ALERT = new Style(LENGTH_LONG, R.color.alert);
-
- /**
- * Show the text notification for a short period of time with a positive style.
- */
- public static final Style STYLE_CONFIRM = new Style(LENGTH_SHORT, R.color.confirm);
-
- /**
- * Show the text notification for a short period of time with a neutral style.
- */
- public static final Style STYLE_INFO = new Style(LENGTH_SHORT, R.color.info);
-
- private final Activity mContext;
- private int mDuration = LENGTH_SHORT;
- private View mView;
- private LayoutParams mLayoutParams;
-
- /**
- * Construct an empty AppMsg object. You must call {@link #setView} before
- * you can call {@link #show}.
- *
- * @param context
- * The context to use. Usually your
- * {@link android.app.Activity} object.
- */
- public AppMsg(Activity context) {
- mContext = context;
- }
-
- /**
- * Make a {@link AppMsg} that just contains a text view.
- *
- * @param context
- * The context to use. Usually your
- * {@link android.app.Activity} object.
- * @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 AppMsg makeText(Activity context, CharSequence text, Style style) {
- AppMsg result = new AppMsg(context);
-
- LayoutInflater inflate = (LayoutInflater)
- context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View v = inflate.inflate(R.layout.app_msg, null);
- v.setBackgroundResource(style.background);
-
- TextView tv = (TextView) v.findViewById(android.R.id.message);
- tv.setText(text);
-
- result.mView = v;
- result.mDuration = style.duration;
-
- return result;
- }
-
- /**
- * Make a {@link AppMsg} that just contains a text view with the text from a
- * resource.
- *
- * @param context
- * The context to use. Usually your
- * {@link android.app.Activity} object.
- * @param resId
- * The resource id of the string resource to use. Can be
- * formatted text.
- * @param duration
- * How long to display the message. Either {@link #LENGTH_SHORT}
- * or {@link #LENGTH_LONG}
- *
- * @throws Resources.NotFoundException
- * if the resource can't be found.
- */
- public static AppMsg makeText(Activity context, int resId, Style style)
- throws Resources.NotFoundException {
- return makeText(context, context.getResources().getText(resId), style);
- }
-
- /**
- * Show the view for the specified duration.
- */
- public void show() {
- MsgManager manager = MsgManager.getInstance();
- manager.add(this);
- }
-
- /**
- * @return <code>true</code> if the {@link AppMsg} is being displayed, else <code>false</code>.
- */
- boolean isShowing() {
- return mView != null && mView.getParent() != null;
- }
-
- /**
- * Close the view if it's showing, or don't show it if it isn't showing yet.
- * You do not normally have to call this. Normally view will disappear on its own
- * after the appropriate duration.
- */
- public void cancel() {
- MsgManager.getInstance().clearMsg(this);
- }
-
- /**
- * Cancels all queued {@link AppMsg}s. If there is a {@link AppMsg}
- * displayed currently, it will be the last one displayed.
- */
- public static void cancelAll() {
- MsgManager.getInstance().clearAllMsg();
- }
-
- /**
- * Return the activity.
- */
- public Activity getActivity() {
- return mContext;
- }
-
- /**
- * Set the view to show.
- * @see #getView
- */
- public void setView(View view) {
- mView = view;
- }
-
- /**
- * Return the view.
- * @see #setView
- */
- public View getView() {
- return mView;
- }
-
- /**
- * Set how long to show the view for.
- * @see #LENGTH_SHORT
- * @see #LENGTH_LONG
- */
- public void setDuration(int duration) {
- mDuration = duration;
- }
-
- /**
- * Return the duration.
- * @see #setDuration
- */
- public int getDuration() {
- return mDuration;
- }
-
- /**
- * Update the text in a AppMsg that was previously created using one of the makeText() methods.
- * @param resId The new text for the AppMsg.
- */
- public void setText(int resId) {
- setText(mContext.getText(resId));
- }
-
- /**
- * Update the text in a AppMsg that was previously created using one of the makeText() methods.
- * @param s The new text for the AppMsg.
- */
- public void setText(CharSequence s) {
- if (mView == null) {
- throw new RuntimeException("This AppMsg was not created with AppMsg.makeText()");
- }
- TextView tv = (TextView) mView.findViewById(android.R.id.message);
- if (tv == null) {
- throw new RuntimeException("This AppMsg was not created with AppMsg.makeText()");
- }
- tv.setText(s);
- }
-
- /**
- * Gets the crouton's layout parameters, constructing a default if necessary.
- * @return the layout parameters
- */
- public LayoutParams getLayoutParams() {
- if (mLayoutParams == null) {
- mLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- }
- return mLayoutParams;
- }
-
- /**
- * Sets the layout parameters which will be used to display the crouton.
- * @param layoutParams The layout parameters to use.
- * @return <code>this</code>, for chaining.
- */
- public AppMsg setLayoutParams(LayoutParams layoutParams) {
- mLayoutParams = layoutParams;
- return this;
- }
-
- /**
- * Constructs and sets the layout parameters to have some gravity.
- * @param gravity the gravity of the Crouton
- * @return <code>this</code>, for chaining.
- * @see android.view.Gravity
- */
- public AppMsg setLayoutGravity(int gravity) {
- mLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, gravity);
- return this;
- }
-
- /**
- * The style for a {@link AppMsg}.
- * @author e.shishkin
- */
- public static class Style {
-
- private final int duration;
- private final int background;
-
- /**
- * Construct an {@link AppMsg.Style} object.
- *
- * @param duration
- * How long to display the message. Either
- * {@link #LENGTH_SHORT} or {@link #LENGTH_LONG}
- * @param resId
- * resource for AppMsg background
- */
- public Style(int duration, int resId) {
- this.duration = duration;
- this.background = resId;
- }
-
- /**
- * Return the duration in milliseconds.
- */
- public int getDuration() {
- return duration;
- }
-
- /**
- * Return the resource id of background.
- */
- public int getBackground() {
- return background;
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof AppMsg.Style)) {
- return false;
- }
- Style style = (Style) o;
- return style.duration == duration
- && style.background == background;
- }
-
- }
-
-}
diff --git a/src/com/devspark/appmsg/MsgManager.java b/src/com/devspark/appmsg/MsgManager.java
deleted file mode 100644
index 08a5ef2..0000000
--- a/src/com/devspark/appmsg/MsgManager.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright 2012 Evgeny Shishkin
- *
- * 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.
- */
-
-package com.devspark.appmsg;
-
-import java.util.LinkedList;
-import java.util.Queue;
-
-import android.app.ActionBar;
-import android.app.Activity;
-import android.os.Handler;
-import android.os.Message;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-
-/**
- *
- * @author Evgeny Shishkin
- *
- */
-class MsgManager extends Handler {
-
- private static final int MESSAGE_DISPLAY = 0xc2007;
- private static final int MESSAGE_ADD_VIEW = 0xc20074dd;
- private static final int MESSAGE_REMOVE = 0xc2007de1;
-
- private static MsgManager mInstance;
-
- private Queue<AppMsg> msgQueue;
- private Animation inAnimation, outAnimation;
-
- private MsgManager() {
- msgQueue = new LinkedList<AppMsg>();
- }
-
- /**
- * @return The currently used instance of the {@link MsgManager}.
- */
- static synchronized MsgManager getInstance() {
- if (mInstance == null) {
- mInstance = new MsgManager();
- }
- return mInstance;
- }
-
- /**
- * Inserts a {@link AppMsg} to be displayed.
- *
- * @param AppMsg
- */
- void add(AppMsg appMsg) {
- msgQueue.add(appMsg);
- if (inAnimation == null) {
- inAnimation = AnimationUtils.loadAnimation(appMsg.getActivity(),
- android.R.anim.fade_in);
- }
- if (outAnimation == null) {
- outAnimation = AnimationUtils.loadAnimation(appMsg.getActivity(),
- android.R.anim.fade_out);
- }
- displayMsg();
- }
-
- /**
- * Removes all {@link AppMsg} from the queue.
- */
- void clearMsg(AppMsg appMsg) {
- msgQueue.remove(appMsg);
- }
-
- /**
- * Removes all {@link AppMsg} from the queue.
- */
- void clearAllMsg() {
- if (msgQueue != null) {
- msgQueue.clear();
- }
- removeMessages(MESSAGE_DISPLAY);
- removeMessages(MESSAGE_ADD_VIEW);
- removeMessages(MESSAGE_REMOVE);
- }
-
- /**
- * Displays the next {@link AppMsg} within the queue.
- */
- private void displayMsg() {
- if (msgQueue.isEmpty()) {
- return;
- }
- // First peek whether the AppMsg is being displayed.
- final AppMsg appMsg = msgQueue.peek();
- // If the activity is null we throw away the AppMsg.
- if (appMsg.getActivity() == null) {
- msgQueue.poll();
- }
- final Message msg;
- if (!appMsg.isShowing()) {
- // Display the AppMsg
- msg = obtainMessage(MESSAGE_ADD_VIEW);
- msg.obj = appMsg;
- sendMessage(msg);
- } else {
- msg = obtainMessage(MESSAGE_DISPLAY);
- sendMessageDelayed(msg, appMsg.getDuration()
- + inAnimation.getDuration() + outAnimation.getDuration());
- }
- }
-
- /**
- * Removes the {@link AppMsg}'s view after it's display duration.
- *
- * @param appMsg The {@link AppMsg} added to a {@link ViewGroup} and should be removed.s
- */
- private void removeMsg(final AppMsg appMsg) {
- ViewGroup parent = ((ViewGroup) appMsg.getView().getParent());
- if (parent != null) {
- appMsg.getView().startAnimation(outAnimation);
- // Remove the AppMsg from the queue.
- msgQueue.poll();
- // Remove the AppMsg from the view's parent.
- parent.removeView(appMsg.getView());
- Message msg = obtainMessage(MESSAGE_DISPLAY);
- sendMessage(msg);
- }
- }
-
- private void addMsgToView(AppMsg appMsg) {
- if (appMsg.getView().getParent() == null) {
- final Activity appActivity = appMsg.getActivity();
- final ActionBar actionBar = appActivity.getActionBar();
-
- // if the action bar is showing and we are overlaying the action bar then adjust
- // the view to account for the height of the action bar in case the action bar is
- // opaque
- if (actionBar.isShowing()
- && appActivity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
- final View v = appMsg.getView();
-
- // for some reason calling setTranslateY causes an animation glitch but setPadding
- // doesn't
- v.setPadding(
- v.getPaddingLeft(),
- v.getPaddingTop() + actionBar.getHeight(),
- v.getPaddingRight(),
- v.getPaddingBottom()
- );
- }
-
-
- appMsg.getActivity().addContentView(
- appMsg.getView(),
- appMsg.getLayoutParams());
- }
- appMsg.getView().startAnimation(inAnimation);
- final Message msg = obtainMessage(MESSAGE_REMOVE);
- msg.obj = appMsg;
- sendMessageDelayed(msg, appMsg.getDuration());
- }
-
- @Override
- public void handleMessage(Message msg) {
- final AppMsg appMsg;
- switch (msg.what) {
- case MESSAGE_DISPLAY:
- displayMsg();
- break;
- case MESSAGE_ADD_VIEW:
- appMsg = (AppMsg) msg.obj;
- addMsgToView(appMsg);
- break;
- case MESSAGE_REMOVE:
- appMsg = (AppMsg) msg.obj;
- removeMsg(appMsg);
- break;
- default:
- super.handleMessage(msg);
- break;
- }
- }
-} \ No newline at end of file