From 527a4f30a69aaa54fc9654539f0b6d839e37af3c Mon Sep 17 00:00:00 2001
From: Trevor Johns
The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.
++ + This sample shows you how to use ActionBarCompat to create a basic Activity which + displays action items. It covers inflating items from a menu resource, as well as adding + an item in code. Items that are not shown as action items on the Action Bar are + displayed in the action bar overflow. + +
diff --git a/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.
++ + This sample shows you how to use {@link android.support.v7.widget.PopupMenu PopupMenu} + from ActionBarCompat to create a list, with each item having a dropdown menu. + +
diff --git a/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.
++ + This sample shows you how a provide a context-sensitive ShareActionProvider with + ActionBarCompat, backwards compatible to API v7. + +
diff --git a/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +To learn more about using Android's custom testing framework, see -Testing Your -Android Activity.
++ + This sample provides a basic example of using an InstrumentationTest to probe the + internal state of an Activity. + +
diff --git a/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml b/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +-Android 4.4 introduces a way for you to provide a more immersive screen -experience in your app by letting users show or hide the status bar and -the navigation bar with a swipe. -
- --This sample demonstrates how this feature interacts with some of the other -UI flags related to full-screen apps. The sample also shows how to implement a -"sticky" mode, which re-hides the bars a few seconds after the user swipes -them back in. -
\ No newline at end of file + + \n\n\n\"Immersive Mode\", added in Android 4.4, improves the \"hide full screen\" and + \"hide nav bar\" modes, by letting users swipe the bars in and out. This sample + lets the user experiment with immersive mode by seeing how it interacts + with some of the other UI flags related to full-screen apps. + + diff --git a/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/CalendarQueryService.java b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/CalendarQueryService.java new file mode 100644 index 000000000..c39a5ed1b --- /dev/null +++ b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/CalendarQueryService.java @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.agendadata; + + +import static com.example.android.wearable.agendadata.Constants.TAG; +import static com.example.android.wearable.agendadata.Constants.CONNECTION_TIME_OUT_MS; +import static com.example.android.wearable.agendadata.Constants.CAL_DATA_ITEM_PATH_PREFIX; +import static com.example.android.wearable.agendadata.Constants.ALL_DAY; +import static com.example.android.wearable.agendadata.Constants.BEGIN; +import static com.example.android.wearable.agendadata.Constants.DATA_ITEM_URI; +import static com.example.android.wearable.agendadata.Constants.DESCRIPTION; +import static com.example.android.wearable.agendadata.Constants.END; +import static com.example.android.wearable.agendadata.Constants.EVENT_ID; +import static com.example.android.wearable.agendadata.Constants.ID; +import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC; +import static com.example.android.wearable.agendadata.Constants.TITLE; + +import android.app.IntentService; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.content.Intent; +import android.content.res.Resources; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.provider.CalendarContract; +import android.provider.ContactsContract.CommonDataKinds.Email; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; +import android.text.format.Time; +import android.util.Log; + +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; +import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; +import com.google.android.gms.wearable.Asset; +import com.google.android.gms.wearable.DataMap; +import com.google.android.gms.wearable.PutDataMapRequest; +import com.google.android.gms.wearable.Wearable; + +import java.io.ByteArrayOutputStream; +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * Queries calendar events using Android Calendar Provider API and creates a data item for each + * event. + */ +public class CalendarQueryService extends IntentService + implements ConnectionCallbacks, OnConnectionFailedListener { + + private static final String[] INSTANCE_PROJECTION = { + CalendarContract.Instances._ID, + CalendarContract.Instances.EVENT_ID, + CalendarContract.Instances.TITLE, + CalendarContract.Instances.BEGIN, + CalendarContract.Instances.END, + CalendarContract.Instances.ALL_DAY, + CalendarContract.Instances.DESCRIPTION, + CalendarContract.Instances.ORGANIZER + }; + + private static final String[] CONTACT_PROJECTION = new String[] { Data._ID, Data.CONTACT_ID }; + private static final String CONTACT_SELECTION = Email.ADDRESS + " = ?"; + + private GoogleApiClient mGoogleApiClient; + + public CalendarQueryService() { + super(CalendarQueryService.class.getSimpleName()); + } + + @Override + public void onCreate() { + super.onCreate(); + mGoogleApiClient = new GoogleApiClient.Builder(this) + .addApi(Wearable.API) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .build(); + } + + @Override + protected void onHandleIntent(Intent intent) { + mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); + // Query calendar events in the next 24 hours. + Time time = new Time(); + time.setToNow(); + long beginTime = time.toMillis(true); + time.monthDay++; + time.normalize(true); + long endTime = time.normalize(true); + + ListTo learn how to make the most of the accessibility features built into -the Android framework, see -Implementing Accessibility.
++ + This sample demonstrates how to create an accessible application, using a mix of different widgets demonstrating different ways of adding accessibility markup to a UI. + +
diff --git a/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml b/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +To see this in action, run the sample application and click:
-+ + Welcome to the Basic Android Key Store sample!\n\n + This sample demonstrates how to use the Android Key Store to safely create and store + encryption keys that only your application can access. You can also sign data + using those keys.\n\n + To create a new KeyPair, click \"Create\".\n\n + To sign some data using a KeyPair, click \"Sign\".\n\n + To verify the data using the signature provided, click \"Verify\".\n\n +
diff --git a/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml b/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +The sample sends consolidated query strings to the -{@link android.provider.ContactsContract.Data} table to match both contact -names and phone numbers. This approach helps to reduce the number of -queries needed when searching the contacts database.
++ + This sample demonstrates how to use the Contactables table to search for contacts. + \n\nQuery strings sent to the Contactables table will match both contact names and phone numbers, + reducing the number of queries your application needs to use when searching the contacts database! + +
diff --git a/samples/browseable/BasicContactables/res/values-v21/template-styles.xml b/samples/browseable/BasicContactables/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicContactables/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +To learn more about detecting basic touch gestures such as scrolling, -flinging, and double-tapping, see -Detecting Common Gestures.
++ + Welcome to Basic Gesture Detect! + In order to try this sample out, try dragging or tapping this text to see what happens! + +
diff --git a/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml b/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +This sample demonstrates how to enable and disable this feature -programmatically.
++ + \"Immersive Mode\" is a new UI mode which improves \"hide full screen\" and + \"hide nav bar\" modes, by letting users swipe the bars in and out. This sample + demonstrates how to enable and disable immersive mode programmatically. + +
diff --git a/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This activity uses a TextureView to render the frames of a video decoded using the + MediaCodec API. + +
diff --git a/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml b/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +To see this in action, run the sample and use the -Media Route Action Item in the action bar to select an -output device. If your device supports Miracast wireless displays, you may -need to enable Wireless Display functionality in the -system settings.
-You can also enable secondary screen simulation from the -Developer options in the system Settings. Once -connected, use the Change Color button to change the -background color of the secondary screen.
++ + This sample demonstrates the use of the MediaRouter API to display + content on a secondary display.\n\nUse the "Media Route Action Item" in the ActionBar + to select an output device. If your device supports Miracast wireless displays, + you may need to enable "Wireless Display" functionality in the system settings. + Secondary screen simulation can also be enabled from the "Developer Options".\n\n +Once connected, use the "Change Color" button to change the background color of the secondary screen. + +
diff --git a/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml b/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +To see this in action, run the sample and touch the screen with multiple -fingers to show that the pointer id (also represented by a colour) does not -change as new touch events are received.
++ +This samples demonstrates the use of MotionEvent properties to keep track of individual touches +across multiple touch events. +\n\nTouch the screen with multiple fingers to show that the pointer id +(also represented by a colour) does not change as new touch events are received.
This sample demonstrates how to use the -{@link android.net.ConnectivityManager} to determine if the device has an -active network connection, and if so, retrieve the connection type.
++ + This sample demonstrates how to use the ConnectivityManager to determine if you have + a network connection, and if so, what type of connection it is. + \n\nA "NetworkInfo" object is retrieved from the ConnectivityManager, which contains information + on the active connection, and then the connection type is printed to an on-screen console. + +
diff --git a/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml b/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This sample demonstrates how to display events in the system\'s notification bar. The + NotificationCompat API is used for compatibility with older devices, running Android + 2.2 (Froyo) or newer. + +
diff --git a/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml b/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +This sample demonstrates how to implement a sync adapter to fetch background -data for an app that doesn't require a user-visible account type or two-way -synchronization.
-The sample periodically downloads the feed from the Android Developers Blog and caches the data in a content provider. At runtime, the cached feed data is -displayed inside a {@link android.widget.ListView}.
-To learn more about creating and using sync adapters, see -Transferring Data Using Sync Adapters.
++ + This sample demonstrates using SyncAdapter to fetch background data for an app that + doesn\'t require a user-visible account type or 2-way synchronization. + + \n\nThis sample periodically downloads the feed from the Android Developer Blog and + caches the data in a content provider. At runtime, the cached feed data is displayed + inside a ListView. + +
diff --git a/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml b/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This application allows two Android devices to carry out two-way text chat over + Bluetooth. It demonstrates all the fundamental Bluetooth API capabilites, such as: + (1) Scanning for other Bluetooth devices + (2) Querying the local Bluetooth adapter for paired Bluetooth devices + (3) Establishing RFCOMM channels/sockets + (4) Connecting to a remote device + (5) Transfering data over Bluetooth + +
diff --git a/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png new file mode 100755 index 000000000..fc0491e63 Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..092887b72 Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-hdpi/tile.9.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/tile.9.png new file mode 100644 index 000000000..135862883 Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-hdpi/tile.9.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png new file mode 100755 index 000000000..d65de0251 Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..1c51ccd7c Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png new file mode 100755 index 000000000..c4b236eea Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..3fa260b7c Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png new file mode 100755 index 000000000..de264301c Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png differ diff --git a/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..6beccf392 Binary files /dev/null and b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml b/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml new file mode 100755 index 000000000..c9a52f621 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml @@ -0,0 +1,73 @@ + ++ * For devices with displays with a width of 720dp or greater, the sample log is always visible, + * on other devices it's visibility is controlled by an item on the Action Bar. + */ +public class MainActivity extends SampleActivityBase { + + public static final String TAG = "MainActivity"; + + // Whether the Log Fragment is currently shown + private boolean mLogShown; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + BluetoothChatFragment fragment = new BluetoothChatFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem logToggle = menu.findItem(R.id.menu_toggle_log); + logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator); + logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log); + + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch(item.getItemId()) { + case R.id.menu_toggle_log: + mLogShown = !mLogShown; + ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output); + if (mLogShown) { + output.setDisplayedChild(1); + } else { + output.setDisplayedChild(0); + } + supportInvalidateOptionsMenu(); + return true; + } + return super.onOptionsItemSelected(item); + } + + /** Create a chain of targets that will receive log data */ + @Override + public void initializeLogging() { + // Wraps Android's native log framework. + LogWrapper logWrapper = new LogWrapper(); + // Using Log, front-end to the logging chain, emulates android.util.log method signatures. + Log.setLogNode(logWrapper); + + // Filter strips out everything except the message text. + MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter(); + logWrapper.setNext(msgFilter); + + // On screen logging via a fragment with a TextView. + LogFragment logFragment = (LogFragment) getSupportFragmentManager() + .findFragmentById(R.id.log_fragment); + msgFilter.setNext(logFragment.getLogView()); + + Log.i(TAG, "Ready"); + } +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/BluetoothChat/src/com.example.android.common/activities/SampleActivityBase.java new file mode 100644 index 000000000..3228927b7 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/activities/SampleActivityBase.java @@ -0,0 +1,52 @@ +/* +* Copyright 2013 The Android Open Source 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. +*/ + +package com.example.android.common.activities; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +import com.example.android.common.logger.Log; +import com.example.android.common.logger.LogWrapper; + +/** + * Base launcher activity, to handle most of the common plumbing for samples. + */ +public class SampleActivityBase extends FragmentActivity { + + public static final String TAG = "SampleActivityBase"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onStart() { + super.onStart(); + initializeLogging(); + } + + /** Set up targets to receive log data */ + public void initializeLogging() { + // Using Log, front-end to the logging chain, emulates android.util.log method signatures. + // Wraps Android's native log framework + LogWrapper logWrapper = new LogWrapper(); + Log.setLogNode(logWrapper); + + Log.i(TAG, "Ready"); + } +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/Log.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/Log.java new file mode 100644 index 000000000..17503c568 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/Log.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2013 The Android Open Source 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. + */ +package com.example.android.common.logger; + +/** + * Helper class for a list (or tree) of LoggerNodes. + * + *
When this is set as the head of the list, + * an instance of it can function as a drop-in replacement for {@link android.util.Log}. + * Most of the methods in this class server only to map a method call in Log to its equivalent + * in LogNode.
+ */ +public class Log { + // Grabbing the native values from Android's native logging facilities, + // to make for easy migration and interop. + public static final int NONE = -1; + public static final int VERBOSE = android.util.Log.VERBOSE; + public static final int DEBUG = android.util.Log.DEBUG; + public static final int INFO = android.util.Log.INFO; + public static final int WARN = android.util.Log.WARN; + public static final int ERROR = android.util.Log.ERROR; + public static final int ASSERT = android.util.Log.ASSERT; + + // Stores the beginning of the LogNode topology. + private static LogNode mLogNode; + + /** + * Returns the next LogNode in the linked list. + */ + public static LogNode getLogNode() { + return mLogNode; + } + + /** + * Sets the LogNode data will be sent to. + */ + public static void setLogNode(LogNode node) { + mLogNode = node; + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void println(int priority, String tag, String msg, Throwable tr) { + if (mLogNode != null) { + mLogNode.println(priority, tag, msg, tr); + } + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + */ + public static void println(int priority, String tag, String msg) { + println(priority, tag, msg, null); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void v(String tag, String msg, Throwable tr) { + println(VERBOSE, tag, msg, tr); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void v(String tag, String msg) { + v(tag, msg, null); + } + + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void d(String tag, String msg, Throwable tr) { + println(DEBUG, tag, msg, tr); + } + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void d(String tag, String msg) { + d(tag, msg, null); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void i(String tag, String msg, Throwable tr) { + println(INFO, tag, msg, tr); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void i(String tag, String msg) { + i(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, String msg, Throwable tr) { + println(WARN, tag, msg, tr); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void w(String tag, String msg) { + w(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, Throwable tr) { + w(tag, null, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void e(String tag, String msg, Throwable tr) { + println(ERROR, tag, msg, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void e(String tag, String msg) { + e(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, String msg, Throwable tr) { + println(ASSERT, tag, msg, tr); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void wtf(String tag, String msg) { + wtf(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, Throwable tr) { + wtf(tag, null, tr); + } +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogFragment.java new file mode 100644 index 000000000..b302acd4b --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogFragment.java @@ -0,0 +1,109 @@ +/* +* Copyright 2013 The Android Open Source 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. +*/ +/* + * Copyright 2013 The Android Open Source 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. + */ + +package com.example.android.common.logger; + +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ScrollView; + +/** + * Simple fraggment which contains a LogView and uses is to output log data it receives + * through the LogNode interface. + */ +public class LogFragment extends Fragment { + + private LogView mLogView; + private ScrollView mScrollView; + + public LogFragment() {} + + public View inflateViews() { + mScrollView = new ScrollView(getActivity()); + ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + mScrollView.setLayoutParams(scrollParams); + + mLogView = new LogView(getActivity()); + ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); + logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; + mLogView.setLayoutParams(logParams); + mLogView.setClickable(true); + mLogView.setFocusable(true); + mLogView.setTypeface(Typeface.MONOSPACE); + + // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! + int paddingDips = 16; + double scale = getResources().getDisplayMetrics().density; + int paddingPixels = (int) ((paddingDips * (scale)) + .5); + mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); + mLogView.setCompoundDrawablePadding(paddingPixels); + + mLogView.setGravity(Gravity.BOTTOM); + mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); + + mScrollView.addView(mLogView); + return mScrollView; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View result = inflateViews(); + + mLogView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + @Override + public void afterTextChanged(Editable s) { + mScrollView.fullScroll(ScrollView.FOCUS_DOWN); + } + }); + return result; + } + + public LogView getLogView() { + return mLogView; + } +} \ No newline at end of file diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogNode.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogNode.java new file mode 100644 index 000000000..bc37cabc0 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogNode.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source 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. + */ +package com.example.android.common.logger; + +/** + * Basic interface for a logging system that can output to one or more targets. + * Note that in addition to classes that will output these logs in some format, + * one can also implement this interface over a filter and insert that in the chain, + * such that no targets further down see certain data, or see manipulated forms of the data. + * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data + * it received to HTML and sent it along to the next node in the chain, without printing it + * anywhere. + */ +public interface LogNode { + + /** + * Instructs first LogNode in the list to print the log data provided. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public void println(int priority, String tag, String msg, Throwable tr); + +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogView.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogView.java new file mode 100644 index 000000000..c01542b91 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogView.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 The Android Open Source 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. + */ +package com.example.android.common.logger; + +import android.app.Activity; +import android.content.Context; +import android.util.*; +import android.widget.TextView; + +/** Simple TextView which is used to output log data received through the LogNode interface. +*/ +public class LogView extends TextView implements LogNode { + + public LogView(Context context) { + super(context); + } + + public LogView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LogView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Formats the log data and prints it out to the LogView. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + + + String priorityStr = null; + + // For the purposes of this View, we want to print the priority as readable text. + switch(priority) { + case android.util.Log.VERBOSE: + priorityStr = "VERBOSE"; + break; + case android.util.Log.DEBUG: + priorityStr = "DEBUG"; + break; + case android.util.Log.INFO: + priorityStr = "INFO"; + break; + case android.util.Log.WARN: + priorityStr = "WARN"; + break; + case android.util.Log.ERROR: + priorityStr = "ERROR"; + break; + case android.util.Log.ASSERT: + priorityStr = "ASSERT"; + break; + default: + break; + } + + // Handily, the Log class has a facility for converting a stack trace into a usable string. + String exceptionStr = null; + if (tr != null) { + exceptionStr = android.util.Log.getStackTraceString(tr); + } + + // Take the priority, tag, message, and exception, and concatenate as necessary + // into one usable line of text. + final StringBuilder outputBuilder = new StringBuilder(); + + String delimiter = "\t"; + appendIfNotNull(outputBuilder, priorityStr, delimiter); + appendIfNotNull(outputBuilder, tag, delimiter); + appendIfNotNull(outputBuilder, msg, delimiter); + appendIfNotNull(outputBuilder, exceptionStr, delimiter); + + // In case this was originally called from an AsyncTask or some other off-UI thread, + // make sure the update occurs within the UI thread. + ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { + @Override + public void run() { + // Display the text we just generated within the LogView. + appendToLog(outputBuilder.toString()); + } + }))); + + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } + + public LogNode getNext() { + return mNext; + } + + public void setNext(LogNode node) { + mNext = node; + } + + /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since + * the logger takes so many arguments that might be null, this method helps cut out some of the + * agonizing tedium of writing the same 3 lines over and over. + * @param source StringBuilder containing the text to append to. + * @param addStr The String to append + * @param delimiter The String to separate the source and appended strings. A tab or comma, + * for instance. + * @return The fully concatenated String as a StringBuilder + */ + private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { + if (addStr != null) { + if (addStr.length() == 0) { + delimiter = ""; + } + + return source.append(addStr).append(delimiter); + } + return source; + } + + // The next LogNode in the chain. + LogNode mNext; + + /** Outputs the string as a new line of log data in the LogView. */ + public void appendToLog(String s) { + append("\n" + s); + } + + +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogWrapper.java new file mode 100644 index 000000000..16a9e7ba2 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogWrapper.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 The Android Open Source 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. + */ +package com.example.android.common.logger; + +import android.util.Log; + +/** + * Helper class which wraps Android's native Log utility in the Logger interface. This way + * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. + */ +public class LogWrapper implements LogNode { + + // For piping: The next node to receive Log data after this one has done its work. + private LogNode mNext; + + /** + * Returns the next LogNode in the linked list. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + + /** + * Prints data out to the console using Android's native log mechanism. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + // There actually are log methods that don't take a msg parameter. For now, + // if that's the case, just convert null to the empty string and move on. + String useMsg = msg; + if (useMsg == null) { + useMsg = ""; + } + + // If an exeption was provided, convert that exception to a usable string and attach + // it to the end of the msg method. + if (tr != null) { + msg += "\n" + Log.getStackTraceString(tr); + } + + // This is functionally identical to Log.x(tag, useMsg); + // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) + Log.println(priority, tag, useMsg); + + // If this isn't the last node in the chain, move things along. + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/MessageOnlyLogFilter.java new file mode 100644 index 000000000..19967dcd4 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/MessageOnlyLogFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source 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. + */ +package com.example.android.common.logger; + +/** + * Simple {@link LogNode} filter, removes everything except the message. + * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, + * just easy-to-read message updates as they're happening. + */ +public class MessageOnlyLogFilter implements LogNode { + + LogNode mNext; + + /** + * Takes the "next" LogNode as a parameter, to simplify chaining. + * + * @param next The next LogNode in the pipeline. + */ + public MessageOnlyLogFilter(LogNode next) { + mNext = next; + } + + public MessageOnlyLogFilter() { + } + + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + if (mNext != null) { + getNext().println(Log.NONE, null, msg, null); + } + } + + /** + * Returns the next LogNode in the chain. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + +} diff --git a/samples/browseable/BluetoothLeGatt/AndroidManifest.xml b/samples/browseable/BluetoothLeGatt/AndroidManifest.xml index babd6df2d..d3cf25757 100644 --- a/samples/browseable/BluetoothLeGatt/AndroidManifest.xml +++ b/samples/browseable/BluetoothLeGatt/AndroidManifest.xml @@ -22,8 +22,8 @@ android:versionCode="1" android:versionName="1.0"> -+ + This sample demonstrates the use of borderless buttons, bottom button bars + (OK and Cancel) and dividers to establish visual structure. + +
diff --git a/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml b/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +- This sample demonstrates how to emulate an NFC card, using the Host Card Emulation - feature added in Android 4.4. This sample makes the device appear as a - loyalty card whenever the screen is on and the user taps their device on an - appropriately configured NFC reader. -
- -- The CardReader sample - can be used to read the loyalty card implemented in this sample. -
+ + This sample demonstrates how to emulate an NFC card, using the "host card emulation" + feature added in Android 4.4. This sample makes the device appear as a loyalty card + whenever the screen is on and the user taps their device on an appropriately configured + NFC reader. + + The "CardReader" sample can be used to read the loyalty card implemented in this sample. + + diff --git a/samples/browseable/CardEmulation/res/values-v21/template-styles.xml b/samples/browseable/CardEmulation/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CardEmulation/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +- This sample demonstrates how to implement a low-level NFC card reader, for - reading cards that do not contain NDEF or Android Beam data. This sample is - designed to read the virtual loyalty card implemented in the CardEmulation sample. -
- -- In particular, this sample demonstrates how to disable Android Beam, select - which AIDs the reader is interested in, and establish communication with the - card. See Host-based - Card Emulation for more information on the HCE APIs. -
+ + This sample demonstrates how to implement a low-level NFC card reader, for reading cards + that do not contain NDEF or Android Beam data. This sample is designed to read the virtual + loyalty card implemented in the "CardEmulation" sample.\n\n + + In particular, this sample demonstrates how to disable Android Beam, select which AIDs the + reader is interested, and establish communication with the card + + diff --git a/samples/browseable/CardReader/res/values-v21/template-styles.xml b/samples/browseable/CardReader/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CardReader/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This sample demonstrates how to create custom checkable layouts, for use with ListView\'s choiceMode + attribute. + +
diff --git a/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml b/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This sample demonstrates notifications with custom content views. + +
diff --git a/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml b/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ + This sample demonstrates how to create and use a custom Transition. + +
diff --git a/samples/browseable/CustomTransition/res/values-v21/template-styles.xml b/samples/browseable/CustomTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java b/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java deleted file mode 100644 index d94261dd9..000000000 --- a/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.datalayer; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.IntentSender; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.provider.MediaStore; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; -import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; -import com.google.android.gms.common.data.FreezableUtils; -import com.google.android.gms.wearable.Asset; -import com.google.android.gms.wearable.DataApi.DataItemResult; -import com.google.android.gms.wearable.DataEvent; -import com.google.android.gms.wearable.DataEventBuffer; -import com.google.android.gms.wearable.MessageApi.SendMessageResult; -import com.google.android.gms.wearable.DataApi; -import com.google.android.gms.wearable.MessageApi; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Receives its own events using a listener API designed for foreground activities. Updates a data - * item every second while it is open. Also allows user to take a photo and send that as an asset to - * the paired wearable. - */ -public class MainActivity extends Activity implements DataApi.DataListener, - MessageApi.MessageListener, NodeApi.NodeListener, ConnectionCallbacks, - OnConnectionFailedListener { - - private static final String TAG = "MainActivity"; - - /** Request code for launching the Intent to resolve Google Play services errors. */ - private static final int REQUEST_RESOLVE_ERROR = 1000; - - private static final String START_ACTIVITY_PATH = "/start-activity"; - private static final String COUNT_PATH = "/count"; - private static final String IMAGE_PATH = "/image"; - private static final String IMAGE_KEY = "photo"; - private static final String COUNT_KEY = "count"; - - private GoogleApiClient mGoogleApiClient; - private boolean mResolvingError = false; - private boolean mCameraSupported = false; - - private ListView mDataItemList; - private Button mTakePhotoBtn; - private Button mSendPhotoBtn; - private ImageView mThumbView; - private Bitmap mImageBitmap; - private View mStartActivityBtn; - - private DataItemAdapter mDataItemListAdapter; - private Handler mHandler; - - // Send DataItems. - private ScheduledExecutorService mGeneratorExecutor; - private ScheduledFuture> mDataItemGeneratorFuture; - - static final int REQUEST_IMAGE_CAPTURE = 1; - - @Override - public void onCreate(Bundle b) { - super.onCreate(b); - mHandler = new Handler(); - LOGD(TAG, "onCreate"); - mCameraSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); - setContentView(R.layout.main_activity); - setupViews(); - - // Stores DataItems received by the local broadcaster or from the paired watch. - mDataItemListAdapter = new DataItemAdapter(this, android.R.layout.simple_list_item_1); - mDataItemList.setAdapter(mDataItemListAdapter); - - mGeneratorExecutor = new ScheduledThreadPoolExecutor(1); - - mGoogleApiClient = new GoogleApiClient.Builder(this) - .addApi(Wearable.API) - .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) - .build(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { - Bundle extras = data.getExtras(); - mImageBitmap = (Bitmap) extras.get("data"); - mThumbView.setImageBitmap(mImageBitmap); - } - } - - @Override - protected void onStart() { - super.onStart(); - if (!mResolvingError) { - mGoogleApiClient.connect(); - } - } - - @Override - public void onResume() { - super.onResume(); - mDataItemGeneratorFuture = mGeneratorExecutor.scheduleWithFixedDelay( - new DataItemGenerator(), 1, 5, TimeUnit.SECONDS); - } - - @Override - public void onPause() { - super.onPause(); - mDataItemGeneratorFuture.cancel(true /* mayInterruptIfRunning */); - } - - @Override - protected void onStop() { - if (!mResolvingError) { - Wearable.DataApi.removeListener(mGoogleApiClient, this); - Wearable.MessageApi.removeListener(mGoogleApiClient, this); - Wearable.NodeApi.removeListener(mGoogleApiClient, this); - mGoogleApiClient.disconnect(); - } - super.onStop(); - } - - @Override //ConnectionCallbacks - public void onConnected(Bundle connectionHint) { - LOGD(TAG, "Google API Client was connected"); - mResolvingError = false; - mStartActivityBtn.setEnabled(true); - mSendPhotoBtn.setEnabled(mCameraSupported); - Wearable.DataApi.addListener(mGoogleApiClient, this); - Wearable.MessageApi.addListener(mGoogleApiClient, this); - Wearable.NodeApi.addListener(mGoogleApiClient, this); - } - - @Override //ConnectionCallbacks - public void onConnectionSuspended(int cause) { - LOGD(TAG, "Connection to Google API client was suspended"); - mStartActivityBtn.setEnabled(false); - mSendPhotoBtn.setEnabled(false); - } - - @Override //OnConnectionFailedListener - public void onConnectionFailed(ConnectionResult result) { - if (mResolvingError) { - // Already attempting to resolve an error. - return; - } else if (result.hasResolution()) { - try { - mResolvingError = true; - result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR); - } catch (IntentSender.SendIntentException e) { - // There was an error with the resolution intent. Try again. - mGoogleApiClient.connect(); - } - } else { - Log.e(TAG, "Connection to Google API client has failed"); - mResolvingError = false; - mStartActivityBtn.setEnabled(false); - mSendPhotoBtn.setEnabled(false); - Wearable.DataApi.removeListener(mGoogleApiClient, this); - Wearable.MessageApi.removeListener(mGoogleApiClient, this); - Wearable.NodeApi.removeListener(mGoogleApiClient, this); - } - } - - @Override //DataListener - public void onDataChanged(DataEventBuffer dataEvents) { - LOGD(TAG, "onDataChanged: " + dataEvents); - final ListWhen this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java deleted file mode 100644 index 6fe681f62..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.delayedconfirmation; - -import android.app.Activity; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.Toast; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.wearable.MessageApi; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; -import com.google.android.gms.wearable.Wearable; - -/** - * Has a single button, used to start the Wearable MainActivity. - */ -public class MainActivity extends Activity implements MessageApi.MessageListener, - GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { - - private static final String TAG = "DelayedConfirmation"; - private static final String START_ACTIVITY_PATH = "/start-activity"; - private static final String TIMER_SELECTED_PATH = "/timer_selected"; - private static final String TIMER_FINISHED_PATH = "/timer_finished"; - private GoogleApiClient mGoogleApiClient; - - @Override - public void onCreate(Bundle b) { - super.onCreate(b); - setContentView(R.layout.main_activity); - mGoogleApiClient = new GoogleApiClient.Builder(this) - .addApi(Wearable.API) - .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) - .build(); - } - - @Override - protected void onResume() { - super.onResume(); - if (!mGoogleApiClient.isConnected()) { - mGoogleApiClient.connect(); - } - } - - @Override - protected void onDestroy() { - if (mGoogleApiClient.isConnected()) { - mGoogleApiClient.disconnect(); - } - super.onDestroy(); - } - - @Override - public void onConnected(Bundle bundle) { - Wearable.MessageApi.addListener(mGoogleApiClient, this); - } - - @Override - public void onConnectionSuspended(int i) { - Wearable.MessageApi.removeListener(mGoogleApiClient, this); - } - - @Override - public void onMessageReceived(final MessageEvent messageEvent) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (messageEvent.getPath().equals(TIMER_SELECTED_PATH)) { - Toast.makeText(getApplicationContext(), R.string.toast_timer_selected, - Toast.LENGTH_SHORT).show(); - } else if (messageEvent.getPath().equals(TIMER_FINISHED_PATH)) { - Toast.makeText(getApplicationContext(), R.string.toast_timer_finished, - Toast.LENGTH_SHORT).show(); - } - } - }); - - } - - @Override - public void onConnectionFailed(ConnectionResult connectionResult) { - Log.e(TAG, "Failed to connect to Google Api Client with error code " - + connectionResult.getErrorCode()); - } - - /** - * Sends a message to Wearable MainActivity when button is pressed. - */ - public void onStartWearableActivityClick(View view) { - Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback( - new ResultCallbackThis is a sample application for the -Displaying -Bitmaps Efficiently Android Training class.
--The sample demonstrates: -
-+ + This sample demonstrates two alternative presentations of the + action bar that are well-suited for simple data entry scenarios. + + In this presentation, a done bar replaces the action + bar entirely, providing two direct actions to persist or dismiss changes. This is + suitable for cases where no additional view details or actions are needed in the + action bar. + +
diff --git a/samples/browseable/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png b/samples/browseable/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png deleted file mode 100644 index 135862883..000000000 Binary files a/samples/browseable/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png and /dev/null differ diff --git a/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml b/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml index 38987ee20..516d28989 100644 --- a/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml +++ b/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml @@ -14,19 +14,37 @@ limitations under the License. --> -When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java deleted file mode 100644 index e87f6debd..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.elizachat; - -import android.text.TextUtils; - -/** - * A basic chat bot based on ELIZA, one of the earliest programs to employ primitive natural - * language processing. Like ELIZA, this bot can simulate a Rogerian psychotherapist using a - * collection of vague and generic responses. - */ -public class ElizaResponder { - - private static final String[] CONVERSATION_KEYWORDS = { - "CAN YOU", "CAN I", "YOU ARE", "YOURE", "I DONT", "I FEEL", "WHY DONT YOU", "WHY CANT I", - "ARE YOU", "I CANT", "I AM", " IM ", "YOU", "I WANT", "WHAT", "HOW", "WHO", "WHERE", - "WHEN", "WHY", "NAME", "CAUSE", "SORRY", "DREAM", "HELLO", "HI", "MAYBE", "NO", "YOUR", - "ALWAYS", "THINK", "ALIKE", "YES", "FRIEND", "COMPUTER", "NOKEYFOUND" }; - - private static String[] WORDS_TO_REPLACE = {"ARE","AM","WERE","WAS","YOU","I","YOUR","MY", - "IVE","YOUVE","IM","YOURE", "YOU", "ME"}; - - private static String[] QUESTIONS = { - "DON'T YOU BELIEVE THAT I CAN.", "PERHAPS YOU WOULD LIKE TO BE ABLE TO.", - "YOU WANT ME TO BE ABLE TO*", "PERHAPS YOU DON'T WANT TO*", - "DO YOU WANT TO BE ABLE TO*", "WHAT MAKES YOU THINK I AM*", - "DOES IT PLEASE YOU TO BELIEVE I AM*", "PERHAPS YOU WOULD LIKE TO BE*", - "DO YOU SOMETIMES WISH YOU WERE*", "DON'T YOU REALLY*", "WHY DON'T YOU*", - "DO YOU WISH TO BE ABLE TO*", "DOES THAT TROUBLE YOU?", - "TELL ME MORE ABOUT SUCH FEELINGS*", "DO YOU OFTEN FEEL*", - "DO YOU ENJOY FEELING*", "DO YOU REALLY BELIEVE I DON'T*", - "PERHAPS IN TIME I WILL*", "DO YOU WANT ME TO*", - "DO YOU THINK YOU SHOULD BE ABLE TO*", "WHY CAN'T YOU*", - "WHAT MAKES YOU WONDER WHETHER OR NOT I AM*", - "WOULD YOU PREFER IF I WERE NOT*", "PERHAPS IN YOUR FANTASIES I AM*", - "HOW DO YOU KNOW YOU CAN'T*", "HAVE YOU TRIED?", "PERHAPS YOU CAN NOW*", - "DID YOU COME TO ME BECAUSE YOU ARE*", "HOW LONG HAVE YOU BEEN*", - "DO YOU BELIEVE IT IS NORMAL TO BE*", "DO YOU ENJOY BEING*", - "I AM MORE INTERESTED IN TALKING ABOUT YOU.", "OH, I*", - "ARE YOU REALLY SO INTERESTED IN SOMEONE LIKE ME?", - "WHAT WOULD IT MEAN TO YOU IF YOU GOT*", "WHY DO YOU WANT*", - "SUPPOSE YOU SOON GOT*", "WHAT IF YOU NEVER GOT*", "I SOMETIMES ALSO WANT*", - "WHY DO YOU ASK?", "DOES THAT QUESTION INTEREST YOU?", - "WHAT ANSWER WOULD PLEASE YOU THE MOST?", "WHAT DO YOU THINK?", - "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?", - "WHAT IS IT THAT YOU REALLY WANT TO KNOW?", "HAVE YOU ASKED ANYONE ELSE?", - "HAVE YOU ASKED SUCH QUESTIONS BEFORE?", - "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?", "WE CAN KEEP THIS ANONYMOUS.", - "NO NEED TO SPECIFY ANY NAMES-- PLEASE GO ON.", "IS THAT THE REAL REASON?", - "DON'T ANY OTHER REASONS COME TO MIND?", - "DOES THAT REASON EXPLAIN ANYTHING ELSE?", "WHAT OTHER REASONS MIGHT THERE BE?", - "PLEASE DON'T APOLOGIZE.", "APOLOGIES ARE NOT NECESSARY.", - "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?", "NO NEED TO BE DEFENSIVE!", - "WHAT DOES THAT DREAM SUGGEST TO YOU?", "DO YOU DREAM OFTEN?", - "WHAT PERSONS APPEAR IN YOUR DREAMS?", "DO YOU HAVE PLEASANT DREAMS?", - "HOW DO YOU DO ... PLEASE STATE YOUR PROBLEM.", "YOU DON'T SEEM QUITE CERTAIN.", - "WHY THE UNCERTAIN TONE?", "LET'S TRY TO KEEP THIS POSITIVE.", "YOU AREN'T SURE?", - "DON'T YOU KNOW?", "IS THAT A DEFINITE NO OR MIGHT YOU CHANGE YOUR MIND?", - "I AM SENSING SOME NEGATIVITY.", "WHY NOT?", "ARE YOU SURE?", "WHY NO?", - "WHY ARE YOU CONCERNED ABOUT MY*", "WHAT ABOUT YOUR OWN*", - "CAN'T YOU THINK OF A SPECIFIC EXAMPLE?", "WHEN?", "WHAT ARE YOU THINKING OF?", - "REALLY. ALWAYS?", "DO YOU REALLY THINK SO?", "BUT YOU ARE NOT SURE YOU.", - "BELIEVE IN YOURSELF.", "IN WHAT WAY?", "WHAT RESEMBLANCE DO YOU SEE?", - "WHAT DOES THE SIMILARITY SUGGEST TO YOU?", - "WHAT OTHER CONNECTIONS DO YOU SEE?", "COULD THERE REALLY BE SOME CONNECTION?", - "HOW?", "YOU SEEM QUITE POSITIVE.", "ARE YOU SURE?", "I SEE.", "I UNDERSTAND.", - "TELL ME ABOUT YOUR FRIENDS.", "ARE YOU WORRIED ABOUT YOUR FRIENDS?", - "DO YOUR FRIENDS EVER GIVE YOU A HARD TIME?", "WHAT DO YOU LIKE ABOUT YOUR FRIENDS?", - "DO YOU LOVE YOUR FRIENDS?", "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU.", - "DO COMPUTERS EXCITE YOU?", "ARE YOU TALKING ABOUT ME IN PARTICULAR?", - "HOW DO YOU LIKE YOUR WATCH?", "WHY DO YOU MENTION COMPUTERS?", - "DO YOU FIND MACHINES AS FASCINATING AS I DO?", - "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?", - "WHAT ABOUT MACHINES EXCITES YOU THE MOST?", - "HEY THERE, HOW CAN I HELP YOU?", - "WHAT DOES THAT SUGGEST TO YOU?", "I SEE.", - "I'M NOT SURE I UNDERSTAND YOU FULLY.", "COME COME ELUCIDATE YOUR THOUGHTS.", - "CAN YOU ELABORATE ON THAT?", "THAT IS QUITE INTERESTING."}; - - private static char[] CONVERSATION_TO_RESPONSES_MAP = { - 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3, - 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9, - 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4, - 80,3,83,7,90,3,93,6,99,7,106,6}; - - private int[] responseStarts = new int[36]; - private int[] responseCurrentIndices = new int[36]; - private int[] responseEnds = new int[36]; - private String previousInput = null; - - public ElizaResponder() { - for (int i = 0; i < CONVERSATION_TO_RESPONSES_MAP.length / 2; i++) { - responseStarts[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i]; - responseCurrentIndices[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i]; - responseEnds[i] = responseStarts[i] + CONVERSATION_TO_RESPONSES_MAP[2 * i + 1]; - } - } - - public String elzTalk(String input) { - if (null == input) { - input = ""; - } - String result = ""; - - input = " " + input.toUpperCase().replace("\'", "") + " "; - - if (previousInput != null && input.equals(previousInput)) { - return "DIDN'T YOU JUST SAY THAT?\n"; - } - previousInput = input; - - int keywordIndex = 0; - for (; keywordIndex < CONVERSATION_KEYWORDS.length; ++keywordIndex) { - int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]); - if (index != -1) { - break; - } - } - - String afterKeyword = ""; - if (keywordIndex == CONVERSATION_KEYWORDS.length) { - keywordIndex = 35; - } else { - int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]); - afterKeyword = input.substring(index + CONVERSATION_KEYWORDS[keywordIndex].length()); - String[] parts = afterKeyword.split("\\s+"); - for (int i = 0; i < WORDS_TO_REPLACE.length / 2; i++) { - String first = WORDS_TO_REPLACE[i * 2]; - String second = WORDS_TO_REPLACE[i * 2 + 1]; - for (int j = 0; j < parts.length; ++j) { - if (parts[j].equals(first)) { - parts[j] = second; - } else if (parts[j].equals(second)) { - parts[j] = first; - } - } - } - afterKeyword = TextUtils.join(" ", parts); - } - - String question = QUESTIONS[responseCurrentIndices[keywordIndex] - 1]; - responseCurrentIndices[keywordIndex] = responseCurrentIndices[keywordIndex] + 1; - if (responseCurrentIndices[keywordIndex] > responseEnds[keywordIndex]) { - responseCurrentIndices[keywordIndex] = responseStarts[keywordIndex]; - } - result += question; - if (result.endsWith("*")) { - result = result.substring(0, result.length() - 1); - result += " " + afterKeyword; - } - - return result; - } -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java deleted file mode 100644 index 421dcb85a..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.elizachat; - -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Bundle; -import android.support.v4.content.LocalBroadcastManager; -import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.TextView; - -public class MainActivity extends Activity { - - @SuppressWarnings("unused") - private static final String TAG = "MainActivity"; - - public static final String EXTRA_MESSAGE = "message"; - - public static final String ACTION_NOTIFY = "com.example.android.elizachat.NOTIFY"; - - public static final String ACTION_GET_CONVERSATION - = "com.example.android.elizachat.CONVERSATION"; - - private BroadcastReceiver mReceiver; - - private TextView mHistoryView; - - @Override - protected void onCreate(Bundle saved) { - super.onCreate(saved); - setContentView(R.layout.main); - mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - processMessage(intent); - } - }; - mHistoryView = (TextView) findViewById(R.id.history); - startResponderService(); - } - - private void startResponderService() { - Intent serviceIntent = new Intent(ResponderService.ACTION_INCOMING); - startService(serviceIntent); - } - - @Override - protected void onResume() { - super.onResume(); - LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, - new IntentFilter(ACTION_NOTIFY)); - mHistoryView.setText(""); - Intent serviceIntent = new Intent(ACTION_GET_CONVERSATION); - startService(serviceIntent); - - } - - @Override - protected void onPause() { - LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); - super.onPause(); - } - - private void processMessage(Intent intent) { - String text = intent.getStringExtra(EXTRA_MESSAGE); - if (!TextUtils.isEmpty(text)) { - mHistoryView.append("\n" + text); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_stop_service: - stopService(new Intent(this, ResponderService.class)); - finish(); - break; - } - return true; - } -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java deleted file mode 100644 index 6d6cd9ab6..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.elizachat; - -import android.app.Notification; -import android.app.PendingIntent; -import android.app.Service; -import android.content.Intent; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.os.IBinder; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.RemoteInput; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v4.app.NotificationManagerCompat; -import android.text.TextUtils; -import android.util.Log; - -/** - * A service that runs in the background and provides responses to the incoming messages from the - * wearable. It also keeps a record of the chat session history, which it can provide upon request. - */ -public class ResponderService extends Service { - - public static final String ACTION_INCOMING = "com.example.android.elizachat.INCOMING"; - - public static final String ACTION_RESPONSE = "com.example.android.elizachat.REPLY"; - - public static final String EXTRA_REPLY = "reply"; - - private static final String TAG = "ResponderService"; - - private ElizaResponder mResponder; - - private String mLastResponse = null; - - private StringBuffer mCompleteConversation = new StringBuffer(); - - private LocalBroadcastManager mBroadcastManager; - - @Override - public void onCreate() { - super.onCreate(); - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Chat Service started"); - } - mResponder = new ElizaResponder(); - mBroadcastManager = LocalBroadcastManager.getInstance(this); - processIncoming(null); - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (null == intent || null == intent.getAction()) { - return Service.START_STICKY; - } - String action = intent.getAction(); - if (action.equals(ACTION_RESPONSE)) { - Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent); - CharSequence replyMessage = ""; - if (remoteInputResults != null) { - replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY); - } - processIncoming(replyMessage.toString()); - } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) { - broadcastMessage(mCompleteConversation.toString()); - } - return Service.START_STICKY; - } - - private void showNotification() { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Sent: " + mLastResponse); - } - NotificationCompat.Builder builder = new NotificationCompat.Builder(this) - .setContentTitle(getString(R.string.eliza)) - .setContentText(mLastResponse) - .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza)) - .setSmallIcon(R.drawable.bg_eliza) - .setPriority(NotificationCompat.PRIORITY_MIN); - - Intent intent = new Intent(ACTION_RESPONSE); - PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, - PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); - Notification notification = builder - .extend(new NotificationCompat.WearableExtender() - .addAction(new NotificationCompat.Action.Builder( - R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent) - .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY) - .setLabel(getString(R.string.reply)) - .build()) - .build())) - .build(); - NotificationManagerCompat.from(this).notify(0, notification); - } - - private void processIncoming(String text) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Received: " + text); - } - mLastResponse = mResponder.elzTalk(text); - String line = TextUtils.isEmpty(text) ? mLastResponse : text + "\n" + mLastResponse; - - // Send a new line of conversation to update the Activity, unless the incoming text was - // empty. - if (!TextUtils.isEmpty(text)) { - broadcastMessage(line); - } - NotificationManagerCompat.from(this).cancelAll(); - showNotification(); - mCompleteConversation.append("\n" + line); - } - - private void broadcastMessage(String message) { - Intent intent = new Intent(MainActivity.ACTION_NOTIFY); - intent.putExtra(MainActivity.EXTRA_MESSAGE, message); - mBroadcastManager.sendBroadcast(intent); - } - - @Override - public void onDestroy() { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Chat Service stopped"); - } - NotificationManagerCompat.from(this).cancel(0); - mBroadcastManager = null; - super.onDestroy(); - } -} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ElizaResponder.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ElizaResponder.java new file mode 100644 index 000000000..e6c054251 --- /dev/null +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ElizaResponder.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.elizachat; + +import android.text.TextUtils; + +/** + * A basic chat bot based on ELIZA, one of the earliest programs to employ primitive natural + * language processing. Like ELIZA, this bot can simulate a Rogerian psychotherapist using a + * collection of vague and generic responses. + */ +public class ElizaResponder { + + private static final String[] CONVERSATION_KEYWORDS = { + "CAN YOU", "CAN I", "YOU ARE", "YOURE", "I DONT", "I FEEL", "WHY DONT YOU", "WHY CANT I", + "ARE YOU", "I CANT", "I AM", " IM ", "YOU", "I WANT", "WHAT", "HOW", "WHO", "WHERE", + "WHEN", "WHY", "NAME", "CAUSE", "SORRY", "DREAM", "HELLO", "HI", "MAYBE", "NO", "YOUR", + "ALWAYS", "THINK", "ALIKE", "YES", "FRIEND", "COMPUTER", "NOKEYFOUND" }; + + private static String[] WORDS_TO_REPLACE = {"ARE","AM","WERE","WAS","YOU","I","YOUR","MY", + "IVE","YOUVE","IM","YOURE", "YOU", "ME"}; + + private static String[] QUESTIONS = { + "DON'T YOU BELIEVE THAT I CAN.", "PERHAPS YOU WOULD LIKE TO BE ABLE TO.", + "YOU WANT ME TO BE ABLE TO*", "PERHAPS YOU DON'T WANT TO*", + "DO YOU WANT TO BE ABLE TO*", "WHAT MAKES YOU THINK I AM*", + "DOES IT PLEASE YOU TO BELIEVE I AM*", "PERHAPS YOU WOULD LIKE TO BE*", + "DO YOU SOMETIMES WISH YOU WERE*", "DON'T YOU REALLY*", "WHY DON'T YOU*", + "DO YOU WISH TO BE ABLE TO*", "DOES THAT TROUBLE YOU?", + "TELL ME MORE ABOUT SUCH FEELINGS*", "DO YOU OFTEN FEEL*", + "DO YOU ENJOY FEELING*", "DO YOU REALLY BELIEVE I DON'T*", + "PERHAPS IN TIME I WILL*", "DO YOU WANT ME TO*", + "DO YOU THINK YOU SHOULD BE ABLE TO*", "WHY CAN'T YOU*", + "WHAT MAKES YOU WONDER WHETHER OR NOT I AM*", + "WOULD YOU PREFER IF I WERE NOT*", "PERHAPS IN YOUR FANTASIES I AM*", + "HOW DO YOU KNOW YOU CAN'T*", "HAVE YOU TRIED?", "PERHAPS YOU CAN NOW*", + "DID YOU COME TO ME BECAUSE YOU ARE*", "HOW LONG HAVE YOU BEEN*", + "DO YOU BELIEVE IT IS NORMAL TO BE*", "DO YOU ENJOY BEING*", + "I AM MORE INTERESTED IN TALKING ABOUT YOU.", "OH, I*", + "ARE YOU REALLY SO INTERESTED IN SOMEONE LIKE ME?", + "WHAT WOULD IT MEAN TO YOU IF YOU GOT*", "WHY DO YOU WANT*", + "SUPPOSE YOU SOON GOT*", "WHAT IF YOU NEVER GOT*", "I SOMETIMES ALSO WANT*", + "WHY DO YOU ASK?", "DOES THAT QUESTION INTEREST YOU?", + "WHAT ANSWER WOULD PLEASE YOU THE MOST?", "WHAT DO YOU THINK?", + "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?", + "WHAT IS IT THAT YOU REALLY WANT TO KNOW?", "HAVE YOU ASKED ANYONE ELSE?", + "HAVE YOU ASKED SUCH QUESTIONS BEFORE?", + "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?", "WE CAN KEEP THIS ANONYMOUS.", + "NO NEED TO SPECIFY ANY NAMES-- PLEASE GO ON.", "IS THAT THE REAL REASON?", + "DON'T ANY OTHER REASONS COME TO MIND?", + "DOES THAT REASON EXPLAIN ANYTHING ELSE?", "WHAT OTHER REASONS MIGHT THERE BE?", + "PLEASE DON'T APOLOGIZE.", "APOLOGIES ARE NOT NECESSARY.", + "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?", "NO NEED TO BE DEFENSIVE!", + "WHAT DOES THAT DREAM SUGGEST TO YOU?", "DO YOU DREAM OFTEN?", + "WHAT PERSONS APPEAR IN YOUR DREAMS?", "DO YOU HAVE PLEASANT DREAMS?", + "HOW DO YOU DO ... PLEASE STATE YOUR PROBLEM.", "YOU DON'T SEEM QUITE CERTAIN.", + "WHY THE UNCERTAIN TONE?", "LET'S TRY TO KEEP THIS POSITIVE.", "YOU AREN'T SURE?", + "DON'T YOU KNOW?", "IS THAT A DEFINITE NO OR MIGHT YOU CHANGE YOUR MIND?", + "I AM SENSING SOME NEGATIVITY.", "WHY NOT?", "ARE YOU SURE?", "WHY NO?", + "WHY ARE YOU CONCERNED ABOUT MY*", "WHAT ABOUT YOUR OWN*", + "CAN'T YOU THINK OF A SPECIFIC EXAMPLE?", "WHEN?", "WHAT ARE YOU THINKING OF?", + "REALLY. ALWAYS?", "DO YOU REALLY THINK SO?", "BUT YOU ARE NOT SURE YOU.", + "BELIEVE IN YOURSELF.", "IN WHAT WAY?", "WHAT RESEMBLANCE DO YOU SEE?", + "WHAT DOES THE SIMILARITY SUGGEST TO YOU?", + "WHAT OTHER CONNECTIONS DO YOU SEE?", "COULD THERE REALLY BE SOME CONNECTION?", + "HOW?", "YOU SEEM QUITE POSITIVE.", "ARE YOU SURE?", "I SEE.", "I UNDERSTAND.", + "TELL ME ABOUT YOUR FRIENDS.", "ARE YOU WORRIED ABOUT YOUR FRIENDS?", + "DO YOUR FRIENDS EVER GIVE YOU A HARD TIME?", "WHAT DO YOU LIKE ABOUT YOUR FRIENDS?", + "DO YOU LOVE YOUR FRIENDS?", "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU.", + "DO COMPUTERS EXCITE YOU?", "ARE YOU TALKING ABOUT ME IN PARTICULAR?", + "HOW DO YOU LIKE YOUR WATCH?", "WHY DO YOU MENTION COMPUTERS?", + "DO YOU FIND MACHINES AS FASCINATING AS I DO?", + "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?", + "WHAT ABOUT MACHINES EXCITES YOU THE MOST?", + "HEY THERE, HOW CAN I HELP YOU?", + "WHAT DOES THAT SUGGEST TO YOU?", "I SEE.", + "I'M NOT SURE I UNDERSTAND YOU FULLY.", "COME COME ELUCIDATE YOUR THOUGHTS.", + "CAN YOU ELABORATE ON THAT?", "THAT IS QUITE INTERESTING."}; + + private static char[] CONVERSATION_TO_RESPONSES_MAP = { + 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3, + 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9, + 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4, + 80,3,83,7,90,3,93,6,99,7,106,6}; + + private int[] responseStarts = new int[36]; + private int[] responseCurrentIndices = new int[36]; + private int[] responseEnds = new int[36]; + private String previousInput = null; + + public ElizaResponder() { + for (int i = 0; i < CONVERSATION_TO_RESPONSES_MAP.length / 2; i++) { + responseStarts[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i]; + responseCurrentIndices[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i]; + responseEnds[i] = responseStarts[i] + CONVERSATION_TO_RESPONSES_MAP[2 * i + 1]; + } + } + + public String elzTalk(String input) { + if (null == input) { + input = ""; + } + String result = ""; + + input = " " + input.toUpperCase().replace("\'", "") + " "; + + if (previousInput != null && input.equals(previousInput)) { + return "DIDN'T YOU JUST SAY THAT?\n"; + } + previousInput = input; + + int keywordIndex = 0; + for (; keywordIndex < CONVERSATION_KEYWORDS.length; ++keywordIndex) { + int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]); + if (index != -1) { + break; + } + } + + String afterKeyword = ""; + if (keywordIndex == CONVERSATION_KEYWORDS.length) { + keywordIndex = 35; + } else { + int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]); + afterKeyword = input.substring(index + CONVERSATION_KEYWORDS[keywordIndex].length()); + String[] parts = afterKeyword.split("\\s+"); + for (int i = 0; i < WORDS_TO_REPLACE.length / 2; i++) { + String first = WORDS_TO_REPLACE[i * 2]; + String second = WORDS_TO_REPLACE[i * 2 + 1]; + for (int j = 0; j < parts.length; ++j) { + if (parts[j].equals(first)) { + parts[j] = second; + } else if (parts[j].equals(second)) { + parts[j] = first; + } + } + } + afterKeyword = TextUtils.join(" ", parts); + } + + String question = QUESTIONS[responseCurrentIndices[keywordIndex] - 1]; + responseCurrentIndices[keywordIndex] = responseCurrentIndices[keywordIndex] + 1; + if (responseCurrentIndices[keywordIndex] > responseEnds[keywordIndex]) { + responseCurrentIndices[keywordIndex] = responseStarts[keywordIndex]; + } + result += question; + if (result.endsWith("*")) { + result = result.substring(0, result.length() - 1); + result += " " + afterKeyword; + } + + return result; + } +} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/MainActivity.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/MainActivity.java new file mode 100644 index 000000000..982e3def5 --- /dev/null +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/MainActivity.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.elizachat; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; + +public class MainActivity extends Activity { + + @SuppressWarnings("unused") + private static final String TAG = "MainActivity"; + + public static final String EXTRA_MESSAGE = "message"; + + public static final String ACTION_NOTIFY = "com.example.android.wearable.elizachat.NOTIFY"; + + public static final String ACTION_GET_CONVERSATION + = "com.example.android.wearable.elizachat.CONVERSATION"; + + private BroadcastReceiver mReceiver; + + private TextView mHistoryView; + + @Override + protected void onCreate(Bundle saved) { + super.onCreate(saved); + setContentView(R.layout.main); + mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + processMessage(intent); + } + }; + mHistoryView = (TextView) findViewById(R.id.history); + startResponderService(); + } + + private void startResponderService() { + Intent serviceIntent = new Intent(ResponderService.ACTION_INCOMING); + startService(serviceIntent); + } + + @Override + protected void onResume() { + super.onResume(); + LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, + new IntentFilter(ACTION_NOTIFY)); + mHistoryView.setText(""); + Intent serviceIntent = new Intent(ACTION_GET_CONVERSATION); + startService(serviceIntent); + + } + + @Override + protected void onPause() { + LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); + super.onPause(); + } + + private void processMessage(Intent intent) { + String text = intent.getStringExtra(EXTRA_MESSAGE); + if (!TextUtils.isEmpty(text)) { + mHistoryView.append("\n" + text); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_stop_service: + stopService(new Intent(this, ResponderService.class)); + finish(); + break; + } + return true; + } +} diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ResponderService.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ResponderService.java new file mode 100644 index 000000000..3bef19c6b --- /dev/null +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ResponderService.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.elizachat; + +import android.app.Notification; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Intent; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.IBinder; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.RemoteInput; +import android.support.v4.content.LocalBroadcastManager; +import android.support.v4.app.NotificationManagerCompat; +import android.text.TextUtils; +import android.util.Log; + +/** + * A service that runs in the background and provides responses to the incoming messages from the + * wearable. It also keeps a record of the chat session history, which it can provide upon request. + */ +public class ResponderService extends Service { + + public static final String ACTION_INCOMING = "com.example.android.wearable.elizachat.INCOMING"; + + public static final String ACTION_RESPONSE = "com.example.android.wearable.elizachat.REPLY"; + + public static final String EXTRA_REPLY = "reply"; + + private static final String TAG = "ResponderService"; + + private ElizaResponder mResponder; + + private String mLastResponse = null; + + private StringBuffer mCompleteConversation = new StringBuffer(); + + private LocalBroadcastManager mBroadcastManager; + + @Override + public void onCreate() { + super.onCreate(); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Chat Service started"); + } + mResponder = new ElizaResponder(); + mBroadcastManager = LocalBroadcastManager.getInstance(this); + processIncoming(null); + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + if (null == intent || null == intent.getAction()) { + return Service.START_STICKY; + } + String action = intent.getAction(); + if (action.equals(ACTION_RESPONSE)) { + Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent); + CharSequence replyMessage = ""; + if (remoteInputResults != null) { + replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY); + } + processIncoming(replyMessage.toString()); + } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) { + broadcastMessage(mCompleteConversation.toString()); + } + return Service.START_STICKY; + } + + private void showNotification() { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Sent: " + mLastResponse); + } + NotificationCompat.Builder builder = new NotificationCompat.Builder(this) + .setContentTitle(getString(R.string.eliza)) + .setContentText(mLastResponse) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza)) + .setSmallIcon(R.drawable.bg_eliza) + .setPriority(NotificationCompat.PRIORITY_MIN); + + Intent intent = new Intent(ACTION_RESPONSE); + PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); + Notification notification = builder + .extend(new NotificationCompat.WearableExtender() + .addAction(new NotificationCompat.Action.Builder( + R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent) + .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY) + .setLabel(getString(R.string.reply)) + .build()) + .build())) + .build(); + NotificationManagerCompat.from(this).notify(0, notification); + } + + private void processIncoming(String text) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Received: " + text); + } + mLastResponse = mResponder.elzTalk(text); + String line = TextUtils.isEmpty(text) ? mLastResponse : text + "\n" + mLastResponse; + + // Send a new line of conversation to update the Activity, unless the incoming text was + // empty. + if (!TextUtils.isEmpty(text)) { + broadcastMessage(line); + } + NotificationManagerCompat.from(this).cancelAll(); + showNotification(); + mCompleteConversation.append("\n" + line); + } + + private void broadcastMessage(String message) { + Intent intent = new Intent(MainActivity.ACTION_NOTIFY); + intent.putExtra(MainActivity.EXTRA_MESSAGE, message); + mBroadcastManager.sendBroadcast(intent); + } + + @Override + public void onDestroy() { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Chat Service stopped"); + } + NotificationManagerCompat.from(this).cancel(0); + mBroadcastManager = null; + super.onDestroy(); + } +} diff --git a/samples/browseable/ElizaChat/Shared/AndroidManifest.xml b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml index 9c02d59fc..dfbb0927d 100644 --- a/samples/browseable/ElizaChat/Shared/AndroidManifest.xml +++ b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml @@ -16,7 +16,7 @@ -->When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java deleted file mode 100644 index de95938ce..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.embeddedapp; - -import android.app.Activity; -import android.os.Bundle; - -public class PhoneActivity extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_phone); - } -} diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.wearable.embeddedapp/PhoneActivity.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.wearable.embeddedapp/PhoneActivity.java new file mode 100644 index 000000000..5a2f5ca3a --- /dev/null +++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.wearable.embeddedapp/PhoneActivity.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.embeddedapp; + +import android.app.Activity; +import android.os.Bundle; + +public class PhoneActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_phone); + } +} diff --git a/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml deleted file mode 100644 index f026bc505..000000000 --- a/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - -When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java deleted file mode 100644 index 106a47a22..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.findphone; - -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.media.RingtoneManager; -import android.net.Uri; -import android.util.Log; - -import com.google.android.gms.wearable.DataEvent; -import com.google.android.gms.wearable.DataEventBuffer; -import com.google.android.gms.wearable.DataMap; -import com.google.android.gms.wearable.WearableListenerService; - -import java.io.IOException; - -/** - * Listens for disconnection from home device. - */ -public class SoundAlarmListenerService extends WearableListenerService { - - private static final String TAG = "ExampleFindPhoneApp"; - - private static final String FIELD_ALARM_ON = "alarm_on"; - - private AudioManager mAudioManager; - private static int mOrigVolume; - private int mMaxVolume; - private Uri mAlarmSound; - private MediaPlayer mMediaPlayer; - - @Override - public void onCreate() { - super.onCreate(); - mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); - mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); - mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM); - mAlarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); - mMediaPlayer = new MediaPlayer(); - } - - @Override - public void onDestroy() { - // Reset the alarm volume to the user's original setting. - mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0); - mMediaPlayer.release(); - super.onDestroy(); - } - - @Override - public void onDataChanged(DataEventBuffer dataEvents) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName()); - } - for (DataEvent event : dataEvents) { - if (event.getType() == DataEvent.TYPE_DELETED) { - Log.i(TAG, event + " deleted"); - } else if (event.getType() == DataEvent.TYPE_CHANGED) { - Boolean alarmOn = - DataMap.fromByteArray(event.getDataItem().getData()).get(FIELD_ALARM_ON); - if (alarmOn) { - mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); - mMediaPlayer.reset(); - // Sound alarm at max volume. - mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mMaxVolume, 0); - mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); - try { - mMediaPlayer.setDataSource(getApplicationContext(), mAlarmSound); - mMediaPlayer.prepare(); - } catch (IOException e) { - Log.e(TAG, "Failed to prepare media player to play alarm.", e); - } - mMediaPlayer.start(); - } else { - // Reset the alarm volume to the user's original setting. - mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0); - if (mMediaPlayer.isPlaying()) { - mMediaPlayer.stop(); - } - } - } - } - dataEvents.close(); - } - -} diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.wearable.findphone/SoundAlarmListenerService.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.wearable.findphone/SoundAlarmListenerService.java new file mode 100644 index 000000000..c89db9d3c --- /dev/null +++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.wearable.findphone/SoundAlarmListenerService.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.wearable.findphone; + +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.media.RingtoneManager; +import android.net.Uri; +import android.util.Log; + +import com.google.android.gms.wearable.DataEvent; +import com.google.android.gms.wearable.DataEventBuffer; +import com.google.android.gms.wearable.DataMap; +import com.google.android.gms.wearable.WearableListenerService; + +import java.io.IOException; + +/** + * Listens for disconnection from home device. + */ +public class SoundAlarmListenerService extends WearableListenerService { + + private static final String TAG = "ExampleFindPhoneApp"; + + private static final String FIELD_ALARM_ON = "alarm_on"; + + private AudioManager mAudioManager; + private static int mOrigVolume; + private int mMaxVolume; + private Uri mAlarmSound; + private MediaPlayer mMediaPlayer; + + @Override + public void onCreate() { + super.onCreate(); + mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); + mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); + mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM); + mAlarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); + mMediaPlayer = new MediaPlayer(); + } + + @Override + public void onDestroy() { + // Reset the alarm volume to the user's original setting. + mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0); + mMediaPlayer.release(); + super.onDestroy(); + } + + @Override + public void onDataChanged(DataEventBuffer dataEvents) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName()); + } + for (DataEvent event : dataEvents) { + if (event.getType() == DataEvent.TYPE_DELETED) { + Log.i(TAG, event + " deleted"); + } else if (event.getType() == DataEvent.TYPE_CHANGED) { + Boolean alarmOn = + DataMap.fromByteArray(event.getDataItem().getData()).get(FIELD_ALARM_ON); + if (alarmOn) { + mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); + mMediaPlayer.reset(); + // Sound alarm at max volume. + mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mMaxVolume, 0); + mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); + try { + mMediaPlayer.setDataSource(getApplicationContext(), mAlarmSound); + mMediaPlayer.prepare(); + } catch (IOException e) { + Log.e(TAG, "Failed to prepare media player to play alarm.", e); + } + mMediaPlayer.start(); + } else { + // Reset the alarm volume to the user's original setting. + mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0); + if (mMediaPlayer.isPlaying()) { + mMediaPlayer.stop(); + } + } + } + } + dataEvents.close(); + } + +} diff --git a/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml b/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml deleted file mode 100644 index 80efe2e2d..000000000 --- a/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - -+ + This sample demonstrates how to start a transition right after a fragment transaction. + +
diff --git a/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml b/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java deleted file mode 100644 index b90aa3b11..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.geofencing; - -import android.net.Uri; - -import com.google.android.gms.location.Geofence; - -/** Constants used in companion app. */ -public final class Constants { - - private Constants() { - } - - public static final String TAG = "ExampleGeofencingApp"; - - // Request code to attempt to resolve Google Play services connection failures. - public final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000; - // Timeout for making a connection to GoogleApiClient (in milliseconds). - public static final long CONNECTION_TIME_OUT_MS = 100; - - // For the purposes of this demo, the geofences are hard-coded and should not expire. - // An app with dynamically-created geofences would want to include a reasonable expiration time. - public static final long GEOFENCE_EXPIRATION_TIME = Geofence.NEVER_EXPIRE; - - // Geofence parameters for the Android building on Google's main campus in Mountain View. - public static final String ANDROID_BUILDING_ID = "1"; - public static final double ANDROID_BUILDING_LATITUDE = 37.420092; - public static final double ANDROID_BUILDING_LONGITUDE = -122.083648; - public static final float ANDROID_BUILDING_RADIUS_METERS = 60.0f; - - // Geofence parameters for the Yerba Buena Gardens near the Moscone Center in San Francisco. - public static final String YERBA_BUENA_ID = "2"; - public static final double YERBA_BUENA_LATITUDE = 37.784886; - public static final double YERBA_BUENA_LONGITUDE = -122.402671; - public static final float YERBA_BUENA_RADIUS_METERS = 72.0f; - - - // The constants below are less interesting than those above. - - // Path for the DataItem containing the last geofence id entered. - public static final String GEOFENCE_DATA_ITEM_PATH = "/geofenceid"; - public static final Uri GEOFENCE_DATA_ITEM_URI = - new Uri.Builder().scheme("wear").path(GEOFENCE_DATA_ITEM_PATH).build(); - public static final String KEY_GEOFENCE_ID = "geofence_id"; - - // Keys for flattened geofences stored in SharedPreferences. - public static final String KEY_LATITUDE = "com.example.wearable.geofencing.KEY_LATITUDE"; - public static final String KEY_LONGITUDE = "com.example.wearable.geofencing.KEY_LONGITUDE"; - public static final String KEY_RADIUS = "com.example.wearable.geofencing.KEY_RADIUS"; - public static final String KEY_EXPIRATION_DURATION = - "com.example.wearable.geofencing.KEY_EXPIRATION_DURATION"; - public static final String KEY_TRANSITION_TYPE = - "com.example.wearable.geofencing.KEY_TRANSITION_TYPE"; - // The prefix for flattened geofence keys. - public static final String KEY_PREFIX = "com.example.wearable.geofencing.KEY"; - - // Invalid values, used to test geofence storage when retrieving geofences. - public static final long INVALID_LONG_VALUE = -999l; - public static final float INVALID_FLOAT_VALUE = -999.0f; - public static final int INVALID_INT_VALUE = -999; - -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java deleted file mode 100644 index 1af7bc68f..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.geofencing; - -import static com.example.android.geofencing.Constants.CONNECTION_TIME_OUT_MS; -import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_PATH; -import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_URI; -import static com.example.android.geofencing.Constants.KEY_GEOFENCE_ID; -import static com.example.android.geofencing.Constants.TAG; - -import android.app.IntentService; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.location.Geofence; -import com.google.android.gms.location.LocationClient; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.Wearable; - -import java.util.concurrent.TimeUnit; - -/** - * Listens for geofence transition changes. - */ -public class GeofenceTransitionsIntentService extends IntentService - implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { - - private GoogleApiClient mGoogleApiClient; - - public GeofenceTransitionsIntentService() { - super(GeofenceTransitionsIntentService.class.getSimpleName()); - } - - @Override - public void onCreate() { - super.onCreate(); - mGoogleApiClient = new GoogleApiClient.Builder(this) - .addApi(Wearable.API) - .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) - .build(); - } - - /** - * Handles incoming intents. - * @param intent The Intent sent by Location Services. This Intent is provided to Location - * Services (inside a PendingIntent) when addGeofences() is called. - */ - @Override - protected void onHandleIntent(Intent intent) { - // First check for errors. - if (LocationClient.hasError(intent)) { - int errorCode = LocationClient.getErrorCode(intent); - Log.e(TAG, "Location Services error: " + errorCode); - } else { - // Get the type of geofence transition (i.e. enter or exit in this sample). - int transitionType = LocationClient.getGeofenceTransition(intent); - // Create a DataItem when a user enters one of the geofences. The wearable app will - // receive this and create a notification to prompt him/her to check in. - if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) { - // Connect to the Google Api service in preparation for sending a DataItem. - mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); - // Get the geofence id triggered. Note that only one geofence can be triggered at a - // time in this example, but in some cases you might want to consider the full list - // of geofences triggered. - String triggeredGeofenceId = LocationClient.getTriggeringGeofences(intent).get(0) - .getRequestId(); - // Create a DataItem with this geofence's id. The wearable can use this to create - // a notification. - final PutDataMapRequest putDataMapRequest = - PutDataMapRequest.create(GEOFENCE_DATA_ITEM_PATH); - putDataMapRequest.getDataMap().putString(KEY_GEOFENCE_ID, triggeredGeofenceId); - if (mGoogleApiClient.isConnected()) { - Wearable.DataApi.putDataItem( - mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await(); - } else { - Log.e(TAG, "Failed to send data item: " + putDataMapRequest - + " - Client disconnected from Google Play Services"); - } - mGoogleApiClient.disconnect(); - } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) { - // Delete the data item when leaving a geofence region. - mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); - Wearable.DataApi.deleteDataItems(mGoogleApiClient, GEOFENCE_DATA_ITEM_URI).await(); - mGoogleApiClient.disconnect(); - } - } - } - - @Override - public void onConnected(Bundle connectionHint) { - } - - @Override - public void onConnectionSuspended(int cause) { - } - - @Override - public void onConnectionFailed(ConnectionResult result) { - } - -} diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java deleted file mode 100644 index 67dcd077d..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.geofencing; - -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_ID; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LATITUDE; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LONGITUDE; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_RADIUS_METERS; -import static com.example.android.geofencing.Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST; -import static com.example.android.geofencing.Constants.GEOFENCE_EXPIRATION_TIME; -import static com.example.android.geofencing.Constants.TAG; -import static com.example.android.geofencing.Constants.YERBA_BUENA_ID; -import static com.example.android.geofencing.Constants.YERBA_BUENA_LATITUDE; -import static com.example.android.geofencing.Constants.YERBA_BUENA_LONGITUDE; -import static com.example.android.geofencing.Constants.YERBA_BUENA_RADIUS_METERS; - -import android.app.Activity; -import android.app.PendingIntent; -import android.content.Intent; -import android.content.IntentSender; -import android.os.Bundle; -import android.util.Log; -import android.widget.Toast; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; -import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; -import com.google.android.gms.location.Geofence; -import com.google.android.gms.location.LocationClient; -import com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener; -import com.google.android.gms.location.LocationStatusCodes; - -import java.util.ArrayList; -import java.util.List; - -public class MainActivity extends Activity implements ConnectionCallbacks, - OnConnectionFailedListener, OnAddGeofencesResultListener { - - // Internal List of Geofence objects. In a real app, these might be provided by an API based on - // locations within the user's proximity. - ListWhen this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/GridViewPager/Shared/AndroidManifest.xml b/samples/browseable/GridViewPager/Shared/AndroidManifest.xml deleted file mode 100644 index 1be08aaeb..000000000 --- a/samples/browseable/GridViewPager/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - -+ + This sample demonstrates how to implement horizontal paging between fragments in + applications that use ActionBar, using a ViewPager widget. + +
diff --git a/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml b/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +This sample demonstrates how to enable toggling of this feature in a -{@link android.support.v4.app.Fragment}.
++ + One of the features introduced in KitKat is "immersive mode". Immersive mode gives the + user the ability to show/hide the status bar and navigation bar with a swipe. To try, + click the "Toggle immersive mode" button, then try swiping the bar in and out! + +
diff --git a/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +DEFAULT_VIBRATION_DURATION_MS.
- */
- public final static void vibrate(Context context, int duration) {
- if (duration == 0) {
- duration = DEFAULT_VIBRATION_DURATION_MS;
- }
- Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- v.vibrate(duration);
- }
-
- /**
- * Saves the counter value in the preference storage. If value
- * is negative, then the value will be removed from the preferences.
- */
- public static void saveCounterToPreference(Context context, int value) {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
- if (value < 0) {
- // we want to remove
- pref.edit().remove(PREF_KEY_COUNTER).apply();
- } else {
- pref.edit().putInt(PREF_KEY_COUNTER, value).apply();
- }
- }
-
- /**
- * Retrieves the value of counter from preference manager. If no value exists, it will return
- * 0.
- */
- public static int getCounterFromPreference(Context context) {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
- return pref.getInt(PREF_KEY_COUNTER, 0);
- }
-
-}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java
deleted file mode 100644
index aa6fa5323..000000000
--- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2014 Google Inc. All Rights Reserved.
- *
- * 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.example.android.jumpingjack.fragments;
-
-import com.example.android.jumpingjack.R;
-import com.example.android.jumpingjack.Utils;
-
-import android.app.Fragment;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.Handler;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * A simple fragment for showing the count
- */
-public class CounterFragment extends Fragment {
-
- private static final long ANIMATION_INTERVAL_MS = 500; // in milliseconds
- private TextView mCounterText;
- private Timer mAnimationTimer;
- private Handler mHandler;
- private TimerTask mAnimationTask;
- private boolean up = false;
- private Drawable mDownDrawable;
- private Drawable mUpDrawable;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.counter_layout, container, false);
- mDownDrawable = getResources().getDrawable(R.drawable.jump_down_50);
- mUpDrawable = getResources().getDrawable(R.drawable.jump_up_50);
- mCounterText = (TextView) view.findViewById(R.id.counter);
- mCounterText.setCompoundDrawablesWithIntrinsicBounds(mUpDrawable, null, null, null);
- setCounter(Utils.getCounterFromPreference(getActivity()));
- mHandler = new Handler();
- startAnimation();
- return view;
- }
-
- private void startAnimation() {
- mAnimationTask = new TimerTask() {
- @Override
- public void run() {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- mCounterText.setCompoundDrawablesWithIntrinsicBounds(
- up ? mUpDrawable : mDownDrawable, null, null, null);
- up = !up;
- }
- });
- }
- };
- mAnimationTimer = new Timer();
- mAnimationTimer.scheduleAtFixedRate(mAnimationTask, ANIMATION_INTERVAL_MS,
- ANIMATION_INTERVAL_MS);
- }
-
- public void setCounter(String text) {
- mCounterText.setText(text);
- }
-
- public void setCounter(int i) {
- setCounter(i < 0 ? "0" : String.valueOf(i));
- }
-
- @Override
- public void onDetach() {
- mAnimationTimer.cancel();
- super.onDetach();
- }
-}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java
deleted file mode 100644
index 0ef7a43f2..000000000
--- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 Google Inc. All Rights Reserved.
- *
- * 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.example.android.jumpingjack.fragments;
-
-import com.example.android.jumpingjack.MainActivity;
-import com.example.android.jumpingjack.R;
-
-import android.app.Fragment;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-
-/**
- * A simple fragment that shows a button to reset the counter
- */
-public class SettingsFragment extends Fragment {
-
- private Button mButton;
- private MainActivity mMainActivity;
-
- public SettingsFragment(MainActivity mainActivity) {
- mMainActivity = mainActivity;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.setting_layout, container, false);
- mButton = (Button) view.findViewById(R.id.btn);
- mButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mMainActivity.resetCounter();
- }
- });
- return view;
- }
-
-}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/MainActivity.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/MainActivity.java
new file mode 100644
index 000000000..cdaaf6ec7
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/MainActivity.java
@@ -0,0 +1,257 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.jumpingjack;
+
+import com.example.android.wearable.jumpingjack.fragments.CounterFragment;
+import com.example.android.wearable.jumpingjack.fragments.SettingsFragment;
+
+import android.app.Activity;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.v4.view.ViewPager;
+import android.util.Log;
+import android.view.WindowManager;
+import android.widget.ImageView;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * The main activity for the Jumping Jack application. This activity registers itself to receive
+ * sensor values. Since on wearable devices a full screen activity is very short-lived, we set the
+ * FLAG_KEEP_SCREEN_ON to give user adequate time for taking actions but since we don't want to
+ * keep screen on for an extended period of time, there is a SCREEN_ON_TIMEOUT_MS that is enforced
+ * if no interaction is discovered.
+ *
+ * This activity includes a {@link android.support.v4.view.ViewPager} with two pages, one that
+ * shows the current count and one that allows user to reset the counter. the current value of the
+ * counter is persisted so that upon re-launch, the counter picks up from the last value. At any
+ * stage, user can set this counter to 0.
+ */
+public class MainActivity extends Activity
+ implements SensorEventListener {
+
+ private static final String TAG = "JJMainActivity";
+
+ /** How long to keep the screen on when no activity is happening **/
+ private static final long SCREEN_ON_TIMEOUT_MS = 20000; // in milliseconds
+
+ /** an up-down movement that takes more than this will not be registered as such **/
+ private static final long TIME_THRESHOLD_NS = 2000000000; // in nanoseconds (= 2sec)
+
+ /**
+ * Earth gravity is around 9.8 m/s^2 but user may not completely direct his/her hand vertical
+ * during the exercise so we leave some room. Basically if the x-component of gravity, as
+ * measured by the Gravity sensor, changes with a variation (delta) > GRAVITY_THRESHOLD,
+ * we consider that a successful count.
+ */
+ private static final float GRAVITY_THRESHOLD = 7.0f;
+
+ private SensorManager mSensorManager;
+ private Sensor mSensor;
+ private long mLastTime = 0;
+ private boolean mUp = false;
+ private int mJumpCounter = 0;
+ private ViewPager mPager;
+ private CounterFragment mCounterPage;
+ private SettingsFragment mSettingPage;
+ private ImageView mSecondIndicator;
+ private ImageView mFirstIndicator;
+ private Timer mTimer;
+ private TimerTask mTimerTask;
+ private Handler mHandler;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.jj_layout);
+ setupViews();
+ mHandler = new Handler();
+ mJumpCounter = Utils.getCounterFromPreference(this);
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ renewTimer();
+ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
+ }
+
+ private void setupViews() {
+ mPager = (ViewPager) findViewById(R.id.pager);
+ mFirstIndicator = (ImageView) findViewById(R.id.indicator_0);
+ mSecondIndicator = (ImageView) findViewById(R.id.indicator_1);
+ final PagerAdapter adapter = new PagerAdapter(getFragmentManager());
+ mCounterPage = new CounterFragment();
+ mSettingPage = new SettingsFragment(this);
+ adapter.addFragment(mCounterPage);
+ adapter.addFragment(mSettingPage);
+ setIndicator(0);
+ mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int i, float v, int i2) {
+ }
+
+ @Override
+ public void onPageSelected(int i) {
+ setIndicator(i);
+ renewTimer();
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int i) {
+ }
+ });
+
+ mPager.setAdapter(adapter);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (mSensorManager.registerListener(this, mSensor,
+ SensorManager.SENSOR_DELAY_NORMAL)) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Successfully registered for the sensor updates");
+ }
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mSensorManager.unregisterListener(this);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Unregistered for sensor events");
+ }
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ detectJump(event.values[0], event.timestamp);
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ }
+
+ /**
+ * A simple algorithm to detect a successful up-down movement of hand(s). The algorithm is
+ * based on the assumption that when a person is wearing the watch, the x-component of gravity
+ * as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand
+ * is upward (signs are reversed if the watch is worn on the right hand). Since the upward or
+ * downward may not be completely accurate, we leave some room and instead of 9.8, we use
+ * GRAVITY_THRESHOLD. We also consider the up <-> down movement successful if it takes less than
+ * TIME_THRESHOLD_NS.
+ */
+ private void detectJump(float xValue, long timestamp) {
+ if ((Math.abs(xValue) > GRAVITY_THRESHOLD)) {
+ if(timestamp - mLastTime < TIME_THRESHOLD_NS && mUp != (xValue > 0)) {
+ onJumpDetected(!mUp);
+ }
+ mUp = xValue > 0;
+ mLastTime = timestamp;
+ }
+ }
+
+ /**
+ * Called on detection of a successful down -> up or up -> down movement of hand.
+ */
+ private void onJumpDetected(boolean up) {
+ // we only count a pair of up and down as one successful movement
+ if (up) {
+ return;
+ }
+ mJumpCounter++;
+ setCounter(mJumpCounter);
+ renewTimer();
+ }
+
+ /**
+ * Updates the counter on UI, saves it to preferences and vibrates the watch when counter
+ * reaches a multiple of 10.
+ */
+ private void setCounter(int i) {
+ mCounterPage.setCounter(i);
+ Utils.saveCounterToPreference(this, i);
+ if (i > 0 && i % 10 == 0) {
+ Utils.vibrate(this, 0);
+ }
+ }
+
+ public void resetCounter() {
+ setCounter(0);
+ renewTimer();
+ }
+
+ /**
+ * Starts a timer to clear the flag FLAG_KEEP_SCREEN_ON.
+ */
+ private void renewTimer() {
+ if (null != mTimer) {
+ mTimer.cancel();
+ }
+ mTimerTask = new TimerTask() {
+ @Override
+ public void run() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG,
+ "Removing the FLAG_KEEP_SCREEN_ON flag to allow going to background");
+ }
+ resetFlag();
+ }
+ };
+ mTimer = new Timer();
+ mTimer.schedule(mTimerTask, SCREEN_ON_TIMEOUT_MS);
+ }
+
+ /**
+ * Resets the FLAG_KEEP_SCREEN_ON flag so activity can go into background.
+ */
+ private void resetFlag() {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Resetting FLAG_KEEP_SCREEN_ON flag to allow going to background");
+ }
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ finish();
+ }
+ });
+ }
+
+ /**
+ * Sets the page indicator for the ViewPager.
+ */
+ private void setIndicator(int i) {
+ switch (i) {
+ case 0:
+ mFirstIndicator.setImageResource(R.drawable.full_10);
+ mSecondIndicator.setImageResource(R.drawable.empty_10);
+ break;
+ case 1:
+ mFirstIndicator.setImageResource(R.drawable.empty_10);
+ mSecondIndicator.setImageResource(R.drawable.full_10);
+ break;
+ }
+ }
+
+
+}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/PagerAdapter.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/PagerAdapter.java
new file mode 100644
index 000000000..f7ac2b010
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/PagerAdapter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.jumpingjack;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.support.v13.app.FragmentPagerAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A simple adapter for the {@link android.support.v4.view.ViewPager}
+ */
+public class PagerAdapter extends FragmentPagerAdapter {
+
+ ListDEFAULT_VIBRATION_DURATION_MS.
+ */
+ public final static void vibrate(Context context, int duration) {
+ if (duration == 0) {
+ duration = DEFAULT_VIBRATION_DURATION_MS;
+ }
+ Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ v.vibrate(duration);
+ }
+
+ /**
+ * Saves the counter value in the preference storage. If value
+ * is negative, then the value will be removed from the preferences.
+ */
+ public static void saveCounterToPreference(Context context, int value) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ if (value < 0) {
+ // we want to remove
+ pref.edit().remove(PREF_KEY_COUNTER).apply();
+ } else {
+ pref.edit().putInt(PREF_KEY_COUNTER, value).apply();
+ }
+ }
+
+ /**
+ * Retrieves the value of counter from preference manager. If no value exists, it will return
+ * 0.
+ */
+ public static int getCounterFromPreference(Context context) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ return pref.getInt(PREF_KEY_COUNTER, 0);
+ }
+
+}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/CounterFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/CounterFragment.java
new file mode 100644
index 000000000..c55eb9b04
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/CounterFragment.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.jumpingjack.fragments;
+
+import com.example.android.wearable.jumpingjack.R;
+import com.example.android.wearable.jumpingjack.Utils;
+
+import android.app.Fragment;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * A simple fragment for showing the count
+ */
+public class CounterFragment extends Fragment {
+
+ private static final long ANIMATION_INTERVAL_MS = 500; // in milliseconds
+ private TextView mCounterText;
+ private Timer mAnimationTimer;
+ private Handler mHandler;
+ private TimerTask mAnimationTask;
+ private boolean up = false;
+ private Drawable mDownDrawable;
+ private Drawable mUpDrawable;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.counter_layout, container, false);
+ mDownDrawable = getResources().getDrawable(R.drawable.jump_down_50);
+ mUpDrawable = getResources().getDrawable(R.drawable.jump_up_50);
+ mCounterText = (TextView) view.findViewById(R.id.counter);
+ mCounterText.setCompoundDrawablesWithIntrinsicBounds(mUpDrawable, null, null, null);
+ setCounter(Utils.getCounterFromPreference(getActivity()));
+ mHandler = new Handler();
+ startAnimation();
+ return view;
+ }
+
+ private void startAnimation() {
+ mAnimationTask = new TimerTask() {
+ @Override
+ public void run() {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mCounterText.setCompoundDrawablesWithIntrinsicBounds(
+ up ? mUpDrawable : mDownDrawable, null, null, null);
+ up = !up;
+ }
+ });
+ }
+ };
+ mAnimationTimer = new Timer();
+ mAnimationTimer.scheduleAtFixedRate(mAnimationTask, ANIMATION_INTERVAL_MS,
+ ANIMATION_INTERVAL_MS);
+ }
+
+ public void setCounter(String text) {
+ mCounterText.setText(text);
+ }
+
+ public void setCounter(int i) {
+ setCounter(i < 0 ? "0" : String.valueOf(i));
+ }
+
+ @Override
+ public void onDetach() {
+ mAnimationTimer.cancel();
+ super.onDetach();
+ }
+}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/SettingsFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/SettingsFragment.java
new file mode 100644
index 000000000..fffe8fb71
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/SettingsFragment.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.jumpingjack.fragments;
+
+import com.example.android.wearable.jumpingjack.MainActivity;
+import com.example.android.wearable.jumpingjack.R;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+/**
+ * A simple fragment that shows a button to reset the counter
+ */
+public class SettingsFragment extends Fragment {
+
+ private Button mButton;
+ private MainActivity mMainActivity;
+
+ public SettingsFragment(MainActivity mainActivity) {
+ mMainActivity = mainActivity;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.setting_layout, container, false);
+ mButton = (Button) view.findViewById(R.id.btn);
+ mButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mMainActivity.resetCounter();
+ }
+ });
+ return view;
+ }
+
+}
diff --git a/samples/browseable/LNotifications/_index.jd b/samples/browseable/LNotifications/_index.jd
index a993bb7c9..d156267db 100644
--- a/samples/browseable/LNotifications/_index.jd
+++ b/samples/browseable/LNotifications/_index.jd
@@ -1,5 +1,5 @@
page.tags="LNotifications Sample"
-sample.group=UI
+sample.group=Notification
@jd:body
diff --git a/samples/browseable/MediaBrowserService/AndroidManifest.xml b/samples/browseable/MediaBrowserService/AndroidManifest.xml
new file mode 100644
index 000000000..6d05c2791
--- /dev/null
+++ b/samples/browseable/MediaBrowserService/AndroidManifest.xml
@@ -0,0 +1,65 @@
+
+
+
+ + This sample shows how to implement an audio media app that provides + media library metadata and playback controls through a standard + service. + +
diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..47d6854e2 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png new file mode 100644 index 000000000..d8ea5a906 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png new file mode 100644 index 000000000..b4bdbb558 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png new file mode 100644 index 000000000..164385d04 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png new file mode 100644 index 000000000..3eeb0ef5b Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png new file mode 100644 index 000000000..4eaf7caab Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png new file mode 100644 index 000000000..e59dedb62 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..01b53fd50 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png new file mode 100644 index 000000000..e435d2a9f Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png new file mode 100644 index 000000000..0c75bb6da Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png new file mode 100644 index 000000000..dbba844df Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..af762f2be Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png new file mode 100644 index 000000000..14b6d17d4 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png new file mode 100644 index 000000000..a55d19922 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png new file mode 100644 index 000000000..8ce3a6008 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png new file mode 100644 index 000000000..f282b9245 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png new file mode 100644 index 000000000..2522877df Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png new file mode 100644 index 000000000..da3b4a74c Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png new file mode 100644 index 000000000..dfb9e670a Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png new file mode 100644 index 000000000..b82a8d98d Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..eef47aa34 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png new file mode 100644 index 000000000..72dfa9fa6 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png new file mode 100644 index 000000000..043acd808 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png new file mode 100644 index 000000000..718b6b5ce Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png new file mode 100644 index 000000000..4fe60888b Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png new file mode 100644 index 000000000..2c9310af9 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png new file mode 100644 index 000000000..836085b68 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png differ diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png new file mode 100644 index 000000000..7cd6cfc52 Binary files /dev/null and b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png differ diff --git a/samples/browseable/MediaBrowserService/res/layout/activity_player.xml b/samples/browseable/MediaBrowserService/res/layout/activity_player.xml new file mode 100644 index 000000000..21cdbbd9c --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/layout/activity_player.xml @@ -0,0 +1,22 @@ + ++ + This sample shows how to use the Media Effects APIs that were introduced in Android 4.0. + These APIs let you apply effects to image frames represented as OpenGL ES 2.0 textures. + Image frames can be images loaded from disk, frames from the device\'s camera, or other + video streams. + +
diff --git a/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..960dc8eb1 Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png b/samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png new file mode 100644 index 000000000..135862883 Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png differ diff --git a/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..9356f268e Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg b/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg new file mode 100644 index 000000000..ef79be200 Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg differ diff --git a/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..230d5584d Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..c825d4e4e Binary files /dev/null and b/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml b/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml new file mode 100755 index 000000000..c9a52f621 --- /dev/null +++ b/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml @@ -0,0 +1,73 @@ + +When this is set as the head of the list, + * an instance of it can function as a drop-in replacement for {@link android.util.Log}. + * Most of the methods in this class server only to map a method call in Log to its equivalent + * in LogNode.
+ */ +public class Log { + // Grabbing the native values from Android's native logging facilities, + // to make for easy migration and interop. + public static final int NONE = -1; + public static final int VERBOSE = android.util.Log.VERBOSE; + public static final int DEBUG = android.util.Log.DEBUG; + public static final int INFO = android.util.Log.INFO; + public static final int WARN = android.util.Log.WARN; + public static final int ERROR = android.util.Log.ERROR; + public static final int ASSERT = android.util.Log.ASSERT; + + // Stores the beginning of the LogNode topology. + private static LogNode mLogNode; + + /** + * Returns the next LogNode in the linked list. + */ + public static LogNode getLogNode() { + return mLogNode; + } + + /** + * Sets the LogNode data will be sent to. + */ + public static void setLogNode(LogNode node) { + mLogNode = node; + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void println(int priority, String tag, String msg, Throwable tr) { + if (mLogNode != null) { + mLogNode.println(priority, tag, msg, tr); + } + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + */ + public static void println(int priority, String tag, String msg) { + println(priority, tag, msg, null); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void v(String tag, String msg, Throwable tr) { + println(VERBOSE, tag, msg, tr); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void v(String tag, String msg) { + v(tag, msg, null); + } + + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void d(String tag, String msg, Throwable tr) { + println(DEBUG, tag, msg, tr); + } + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void d(String tag, String msg) { + d(tag, msg, null); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void i(String tag, String msg, Throwable tr) { + println(INFO, tag, msg, tr); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void i(String tag, String msg) { + i(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, String msg, Throwable tr) { + println(WARN, tag, msg, tr); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void w(String tag, String msg) { + w(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, Throwable tr) { + w(tag, null, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void e(String tag, String msg, Throwable tr) { + println(ERROR, tag, msg, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void e(String tag, String msg) { + e(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, String msg, Throwable tr) { + println(ASSERT, tag, msg, tr); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void wtf(String tag, String msg) { + wtf(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, Throwable tr) { + wtf(tag, null, tr); + } +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogFragment.java new file mode 100644 index 000000000..b302acd4b --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogFragment.java @@ -0,0 +1,109 @@ +/* +* Copyright 2013 The Android Open Source 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. +*/ +/* + * Copyright 2013 The Android Open Source 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. + */ + +package com.example.android.common.logger; + +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ScrollView; + +/** + * Simple fraggment which contains a LogView and uses is to output log data it receives + * through the LogNode interface. + */ +public class LogFragment extends Fragment { + + private LogView mLogView; + private ScrollView mScrollView; + + public LogFragment() {} + + public View inflateViews() { + mScrollView = new ScrollView(getActivity()); + ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + mScrollView.setLayoutParams(scrollParams); + + mLogView = new LogView(getActivity()); + ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); + logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; + mLogView.setLayoutParams(logParams); + mLogView.setClickable(true); + mLogView.setFocusable(true); + mLogView.setTypeface(Typeface.MONOSPACE); + + // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! + int paddingDips = 16; + double scale = getResources().getDisplayMetrics().density; + int paddingPixels = (int) ((paddingDips * (scale)) + .5); + mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); + mLogView.setCompoundDrawablePadding(paddingPixels); + + mLogView.setGravity(Gravity.BOTTOM); + mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); + + mScrollView.addView(mLogView); + return mScrollView; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View result = inflateViews(); + + mLogView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + @Override + public void afterTextChanged(Editable s) { + mScrollView.fullScroll(ScrollView.FOCUS_DOWN); + } + }); + return result; + } + + public LogView getLogView() { + return mLogView; + } +} \ No newline at end of file diff --git a/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogNode.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogNode.java new file mode 100644 index 000000000..bc37cabc0 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogNode.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source 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. + */ +package com.example.android.common.logger; + +/** + * Basic interface for a logging system that can output to one or more targets. + * Note that in addition to classes that will output these logs in some format, + * one can also implement this interface over a filter and insert that in the chain, + * such that no targets further down see certain data, or see manipulated forms of the data. + * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data + * it received to HTML and sent it along to the next node in the chain, without printing it + * anywhere. + */ +public interface LogNode { + + /** + * Instructs first LogNode in the list to print the log data provided. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public void println(int priority, String tag, String msg, Throwable tr); + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogView.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogView.java new file mode 100644 index 000000000..c01542b91 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogView.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 The Android Open Source 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. + */ +package com.example.android.common.logger; + +import android.app.Activity; +import android.content.Context; +import android.util.*; +import android.widget.TextView; + +/** Simple TextView which is used to output log data received through the LogNode interface. +*/ +public class LogView extends TextView implements LogNode { + + public LogView(Context context) { + super(context); + } + + public LogView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LogView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Formats the log data and prints it out to the LogView. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + + + String priorityStr = null; + + // For the purposes of this View, we want to print the priority as readable text. + switch(priority) { + case android.util.Log.VERBOSE: + priorityStr = "VERBOSE"; + break; + case android.util.Log.DEBUG: + priorityStr = "DEBUG"; + break; + case android.util.Log.INFO: + priorityStr = "INFO"; + break; + case android.util.Log.WARN: + priorityStr = "WARN"; + break; + case android.util.Log.ERROR: + priorityStr = "ERROR"; + break; + case android.util.Log.ASSERT: + priorityStr = "ASSERT"; + break; + default: + break; + } + + // Handily, the Log class has a facility for converting a stack trace into a usable string. + String exceptionStr = null; + if (tr != null) { + exceptionStr = android.util.Log.getStackTraceString(tr); + } + + // Take the priority, tag, message, and exception, and concatenate as necessary + // into one usable line of text. + final StringBuilder outputBuilder = new StringBuilder(); + + String delimiter = "\t"; + appendIfNotNull(outputBuilder, priorityStr, delimiter); + appendIfNotNull(outputBuilder, tag, delimiter); + appendIfNotNull(outputBuilder, msg, delimiter); + appendIfNotNull(outputBuilder, exceptionStr, delimiter); + + // In case this was originally called from an AsyncTask or some other off-UI thread, + // make sure the update occurs within the UI thread. + ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { + @Override + public void run() { + // Display the text we just generated within the LogView. + appendToLog(outputBuilder.toString()); + } + }))); + + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } + + public LogNode getNext() { + return mNext; + } + + public void setNext(LogNode node) { + mNext = node; + } + + /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since + * the logger takes so many arguments that might be null, this method helps cut out some of the + * agonizing tedium of writing the same 3 lines over and over. + * @param source StringBuilder containing the text to append to. + * @param addStr The String to append + * @param delimiter The String to separate the source and appended strings. A tab or comma, + * for instance. + * @return The fully concatenated String as a StringBuilder + */ + private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { + if (addStr != null) { + if (addStr.length() == 0) { + delimiter = ""; + } + + return source.append(addStr).append(delimiter); + } + return source; + } + + // The next LogNode in the chain. + LogNode mNext; + + /** Outputs the string as a new line of log data in the LogView. */ + public void appendToLog(String s) { + append("\n" + s); + } + + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogWrapper.java new file mode 100644 index 000000000..16a9e7ba2 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogWrapper.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 The Android Open Source 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. + */ +package com.example.android.common.logger; + +import android.util.Log; + +/** + * Helper class which wraps Android's native Log utility in the Logger interface. This way + * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. + */ +public class LogWrapper implements LogNode { + + // For piping: The next node to receive Log data after this one has done its work. + private LogNode mNext; + + /** + * Returns the next LogNode in the linked list. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + + /** + * Prints data out to the console using Android's native log mechanism. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + // There actually are log methods that don't take a msg parameter. For now, + // if that's the case, just convert null to the empty string and move on. + String useMsg = msg; + if (useMsg == null) { + useMsg = ""; + } + + // If an exeption was provided, convert that exception to a usable string and attach + // it to the end of the msg method. + if (tr != null) { + msg += "\n" + Log.getStackTraceString(tr); + } + + // This is functionally identical to Log.x(tag, useMsg); + // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) + Log.println(priority, tag, useMsg); + + // If this isn't the last node in the chain, move things along. + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/MessageOnlyLogFilter.java new file mode 100644 index 000000000..19967dcd4 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/MessageOnlyLogFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source 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. + */ +package com.example.android.common.logger; + +/** + * Simple {@link LogNode} filter, removes everything except the message. + * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, + * just easy-to-read message updates as they're happening. + */ +public class MessageOnlyLogFilter implements LogNode { + + LogNode mNext; + + /** + * Takes the "next" LogNode as a parameter, to simplify chaining. + * + * @param next The next LogNode in the pipeline. + */ + public MessageOnlyLogFilter(LogNode next) { + mNext = next; + } + + public MessageOnlyLogFilter() { + } + + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + if (mNext != null) { + getNext().println(Log.NONE, null, msg, null); + } + } + + /** + * Returns the next LogNode in the chain. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java new file mode 100644 index 000000000..02a8c590d --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 The Android Open Source 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. + */ + +package com.example.android.mediaeffects; + +import android.opengl.GLES20; + +public class GLToolbox { + + public static int loadShader(int shaderType, String source) { + int shader = GLES20.glCreateShader(shaderType); + if (shader != 0) { + GLES20.glShaderSource(shader, source); + GLES20.glCompileShader(shader); + int[] compiled = new int[1]; + GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); + if (compiled[0] == 0) { + String info = GLES20.glGetShaderInfoLog(shader); + GLES20.glDeleteShader(shader); + throw new RuntimeException("Could not compile shader " + shaderType + ":" + info); + } + } + return shader; + } + + public static int createProgram(String vertexSource, String fragmentSource) { + int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); + if (vertexShader == 0) { + return 0; + } + int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); + if (pixelShader == 0) { + return 0; + } + + int program = GLES20.glCreateProgram(); + if (program != 0) { + GLES20.glAttachShader(program, vertexShader); + checkGlError("glAttachShader"); + GLES20.glAttachShader(program, pixelShader); + checkGlError("glAttachShader"); + GLES20.glLinkProgram(program); + int[] linkStatus = new int[1]; + GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, + 0); + if (linkStatus[0] != GLES20.GL_TRUE) { + String info = GLES20.glGetProgramInfoLog(program); + GLES20.glDeleteProgram(program); + throw new RuntimeException("Could not link program: " + info); + } + } + return program; + } + + public static void checkGlError(String op) { + int error; + while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { + throw new RuntimeException(op + ": glError " + error); + } + } + + public static void initTexParams() { + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, + GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, + GLES20.GL_CLAMP_TO_EDGE); + } + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.java new file mode 100644 index 000000000..be6224310 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.java @@ -0,0 +1,109 @@ +/* +* Copyright 2013 The Android Open Source 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. +*/ + +package com.example.android.mediaeffects; + +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.ViewAnimator; + +import com.example.android.common.activities.SampleActivityBase; +import com.example.android.common.logger.Log; +import com.example.android.common.logger.LogFragment; +import com.example.android.common.logger.LogWrapper; +import com.example.android.common.logger.MessageOnlyLogFilter; + +/** + * A simple launcher activity containing a summary sample description, sample log and a custom + * {@link android.support.v4.app.Fragment} which can display a view. + *
+ * For devices with displays with a width of 720dp or greater, the sample log is always visible,
+ * on other devices it's visibility is controlled by an item on the Action Bar.
+ */
+public class MainActivity extends SampleActivityBase {
+
+ public static final String TAG = "MainActivity";
+
+ // Whether the Log Fragment is currently shown
+ private boolean mLogShown;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ if (savedInstanceState == null) {
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ MediaEffectsFragment fragment = new MediaEffectsFragment();
+ transaction.replace(R.id.sample_content_fragment, fragment);
+ transaction.commit();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
+ logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
+ logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);
+
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case R.id.menu_toggle_log:
+ mLogShown = !mLogShown;
+ ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output);
+ if (mLogShown) {
+ output.setDisplayedChild(1);
+ } else {
+ output.setDisplayedChild(0);
+ }
+ supportInvalidateOptionsMenu();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ /** Create a chain of targets that will receive log data */
+ @Override
+ public void initializeLogging() {
+ // Wraps Android's native log framework.
+ LogWrapper logWrapper = new LogWrapper();
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ Log.setLogNode(logWrapper);
+
+ // Filter strips out everything except the message text.
+ MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
+ logWrapper.setNext(msgFilter);
+
+ // On screen logging via a fragment with a TextView.
+ LogFragment logFragment = (LogFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.log_fragment);
+ msgFilter.setNext(logFragment.getLogView());
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java
new file mode 100644
index 000000000..5af16845f
--- /dev/null
+++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2014 The Android Open Source 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.
+ */
+
+package com.example.android.mediaeffects;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.media.effect.Effect;
+import android.media.effect.EffectContext;
+import android.media.effect.EffectFactory;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLUtils;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+public class MediaEffectsFragment extends Fragment implements GLSurfaceView.Renderer {
+
+ private static final String STATE_CURRENT_EFFECT = "current_effect";
+
+ private GLSurfaceView mEffectView;
+ private int[] mTextures = new int[2];
+ private EffectContext mEffectContext;
+ private Effect mEffect;
+ private TextureRenderer mTexRenderer = new TextureRenderer();
+ private int mImageWidth;
+ private int mImageHeight;
+ private boolean mInitialized = false;
+ private int mCurrentEffect;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_media_effects, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview);
+ mEffectView.setEGLContextClientVersion(2);
+ mEffectView.setRenderer(this);
+ mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
+ if (null != savedInstanceState && savedInstanceState.containsKey(STATE_CURRENT_EFFECT)) {
+ setCurrentEffect(savedInstanceState.getInt(STATE_CURRENT_EFFECT));
+ } else {
+ setCurrentEffect(R.id.none);
+ }
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.media_effects, menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ setCurrentEffect(item.getItemId());
+ mEffectView.requestRender();
+ return true;
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ outState.putInt(STATE_CURRENT_EFFECT, mCurrentEffect);
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
+ // Nothing to do here
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ if (mTexRenderer != null) {
+ mTexRenderer.updateViewSize(width, height);
+ }
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ if (!mInitialized) {
+ //Only need to do this once
+ mEffectContext = EffectContext.createWithCurrentGlContext();
+ mTexRenderer.init();
+ loadTextures();
+ mInitialized = true;
+ }
+ if (mCurrentEffect != R.id.none) {
+ //if an effect is chosen initialize it and apply it to the texture
+ initEffect();
+ applyEffect();
+ }
+ renderResult();
+ }
+
+ private void setCurrentEffect(int effect) {
+ mCurrentEffect = effect;
+ }
+
+ private void loadTextures() {
+ // Generate textures
+ GLES20.glGenTextures(2, mTextures, 0);
+
+ // Load input bitmap
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy);
+ mImageWidth = bitmap.getWidth();
+ mImageHeight = bitmap.getHeight();
+ mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);
+
+ // Upload to texture
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
+ GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ // Set texture parameters
+ GLToolbox.initTexParams();
+ }
+
+ private void initEffect() {
+ EffectFactory effectFactory = mEffectContext.getFactory();
+ if (mEffect != null) {
+ mEffect.release();
+ }
+ // Initialize the correct effect based on the selected menu/action item
+ switch (mCurrentEffect) {
+
+ case R.id.none:
+ break;
+
+ case R.id.autofix:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX);
+ mEffect.setParameter("scale", 0.5f);
+ break;
+
+ case R.id.bw:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE);
+ mEffect.setParameter("black", .1f);
+ mEffect.setParameter("white", .7f);
+ break;
+
+ case R.id.brightness:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BRIGHTNESS);
+ mEffect.setParameter("brightness", 2.0f);
+ break;
+
+ case R.id.contrast:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CONTRAST);
+ mEffect.setParameter("contrast", 1.4f);
+ break;
+
+ case R.id.crossprocess:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS);
+ break;
+
+ case R.id.documentary:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DOCUMENTARY);
+ break;
+
+ case R.id.duotone:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE);
+ mEffect.setParameter("first_color", Color.YELLOW);
+ mEffect.setParameter("second_color", Color.DKGRAY);
+ break;
+
+ case R.id.filllight:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FILLLIGHT);
+ mEffect.setParameter("strength", .8f);
+ break;
+
+ case R.id.fisheye:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE);
+ mEffect.setParameter("scale", .5f);
+ break;
+
+ case R.id.flipvert:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
+ mEffect.setParameter("vertical", true);
+ break;
+
+ case R.id.fliphor:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
+ mEffect.setParameter("horizontal", true);
+ break;
+
+ case R.id.grain:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN);
+ mEffect.setParameter("strength", 1.0f);
+ break;
+
+ case R.id.grayscale:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE);
+ break;
+
+ case R.id.lomoish:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH);
+ break;
+
+ case R.id.negative:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE);
+ break;
+
+ case R.id.posterize:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE);
+ break;
+
+ case R.id.rotate:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_ROTATE);
+ mEffect.setParameter("angle", 180);
+ break;
+
+ case R.id.saturate:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE);
+ mEffect.setParameter("scale", .5f);
+ break;
+
+ case R.id.sepia:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA);
+ break;
+
+ case R.id.sharpen:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SHARPEN);
+ break;
+
+ case R.id.temperature:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TEMPERATURE);
+ mEffect.setParameter("scale", .9f);
+ break;
+
+ case R.id.tint:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
+ mEffect.setParameter("tint", Color.MAGENTA);
+ break;
+
+ case R.id.vignette:
+ mEffect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE);
+ mEffect.setParameter("scale", .5f);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ private void applyEffect() {
+ mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
+ }
+
+ private void renderResult() {
+ if (mCurrentEffect != R.id.none) {
+ // if no effect is chosen, just render the original bitmap
+ mTexRenderer.renderTexture(mTextures[1]);
+ } else {
+ // render the result of applyEffect()
+ mTexRenderer.renderTexture(mTextures[0]);
+ }
+ }
+
+}
diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java
new file mode 100644
index 000000000..9c77927d2
--- /dev/null
+++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2014 The Android Open Source 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.
+ */
+
+package com.example.android.mediaeffects;
+
+import android.opengl.GLES20;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+public class TextureRenderer {
+
+ private int mProgram;
+ private int mTexSamplerHandle;
+ private int mTexCoordHandle;
+ private int mPosCoordHandle;
+
+ private FloatBuffer mTexVertices;
+ private FloatBuffer mPosVertices;
+
+ private int mViewWidth;
+ private int mViewHeight;
+
+ private int mTexWidth;
+ private int mTexHeight;
+
+ private static final String VERTEX_SHADER =
+ "attribute vec4 a_position;\n" +
+ "attribute vec2 a_texcoord;\n" +
+ "varying vec2 v_texcoord;\n" +
+ "void main() {\n" +
+ " gl_Position = a_position;\n" +
+ " v_texcoord = a_texcoord;\n" +
+ "}\n";
+
+ private static final String FRAGMENT_SHADER =
+ "precision mediump float;\n" +
+ "uniform sampler2D tex_sampler;\n" +
+ "varying vec2 v_texcoord;\n" +
+ "void main() {\n" +
+ " gl_FragColor = texture2D(tex_sampler, v_texcoord);\n" +
+ "}\n";
+
+ private static final float[] TEX_VERTICES = {
+ 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f
+ };
+
+ private static final float[] POS_VERTICES = {
+ -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f
+ };
+
+ private static final int FLOAT_SIZE_BYTES = 4;
+
+ public void init() {
+ // Create program
+ mProgram = GLToolbox.createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
+
+ // Bind attributes and uniforms
+ mTexSamplerHandle = GLES20.glGetUniformLocation(mProgram,
+ "tex_sampler");
+ mTexCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_texcoord");
+ mPosCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_position");
+
+ // Setup coordinate buffers
+ mTexVertices = ByteBuffer.allocateDirect(
+ TEX_VERTICES.length * FLOAT_SIZE_BYTES)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mTexVertices.put(TEX_VERTICES).position(0);
+ mPosVertices = ByteBuffer.allocateDirect(
+ POS_VERTICES.length * FLOAT_SIZE_BYTES)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mPosVertices.put(POS_VERTICES).position(0);
+ }
+
+ public void tearDown() {
+ GLES20.glDeleteProgram(mProgram);
+ }
+
+ public void updateTextureSize(int texWidth, int texHeight) {
+ mTexWidth = texWidth;
+ mTexHeight = texHeight;
+ computeOutputVertices();
+ }
+
+ public void updateViewSize(int viewWidth, int viewHeight) {
+ mViewWidth = viewWidth;
+ mViewHeight = viewHeight;
+ computeOutputVertices();
+ }
+
+ public void renderTexture(int texId) {
+ // Bind default FBO
+ GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
+
+ // Use our shader program
+ GLES20.glUseProgram(mProgram);
+ GLToolbox.checkGlError("glUseProgram");
+
+ // Set viewport
+ GLES20.glViewport(0, 0, mViewWidth, mViewHeight);
+ GLToolbox.checkGlError("glViewport");
+
+ // Disable blending
+ GLES20.glDisable(GLES20.GL_BLEND);
+
+ // Set the vertex attributes
+ GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false,
+ 0, mTexVertices);
+ GLES20.glEnableVertexAttribArray(mTexCoordHandle);
+ GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false,
+ 0, mPosVertices);
+ GLES20.glEnableVertexAttribArray(mPosCoordHandle);
+ GLToolbox.checkGlError("vertex attribute setup");
+
+ // Set the input texture
+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
+ GLToolbox.checkGlError("glActiveTexture");
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);
+ GLToolbox.checkGlError("glBindTexture");
+ GLES20.glUniform1i(mTexSamplerHandle, 0);
+
+ // Draw
+ GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
+ }
+
+ private void computeOutputVertices() {
+ if (mPosVertices != null) {
+ float imgAspectRatio = mTexWidth / (float)mTexHeight;
+ float viewAspectRatio = mViewWidth / (float)mViewHeight;
+ float relativeAspectRatio = viewAspectRatio / imgAspectRatio;
+ float x0, y0, x1, y1;
+ if (relativeAspectRatio > 1.0f) {
+ x0 = -1.0f / relativeAspectRatio;
+ y0 = -1.0f;
+ x1 = 1.0f / relativeAspectRatio;
+ y1 = 1.0f;
+ } else {
+ x0 = -1.0f;
+ y0 = -relativeAspectRatio;
+ x1 = 1.0f;
+ y1 = relativeAspectRatio;
+ }
+ float[] coords = new float[] { x0, y0, x1, y0, x0, y1, x1, y1 };
+ mPosVertices.put(coords).position(0);
+ }
+ }
+
+}
diff --git a/samples/browseable/MediaRecorder/AndroidManifest.xml b/samples/browseable/MediaRecorder/AndroidManifest.xml
index 32f88f64f..539dc2c3d 100644
--- a/samples/browseable/MediaRecorder/AndroidManifest.xml
+++ b/samples/browseable/MediaRecorder/AndroidManifest.xml
@@ -22,9 +22,7 @@
android:versionCode="1"
android:versionName="1.0">
-
This sample demonstrates how to use the {@link android.media.MediaRecorder} -API to record video from a camera or camcorder, and display a preview of the -recording.
++ + This sample uses the camera/camcorder as the A/V source for the MediaRecorder API. + A TextureView is used as the camera preview which limits the code to API 14+. This + can be easily replaced with a SurfaceView to run on older devices. + +
diff --git a/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml b/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + ++ +This sample shows a simple service that sends notifications using +NotificationCompat. In addition to sending a notification, it also extends +the notification with a CarExtender to make it compatible with Android Auto. +Each unread conversation from a user is sent as a distinct notification. + +
diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png new file mode 100644 index 000000000..00d0ec43a Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png differ diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..06d85f166 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png differ diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png new file mode 100644 index 000000000..9cdfca1e5 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png differ diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png new file mode 100644 index 000000000..771cb6bb8 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png differ diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..4e1cc86b4 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png differ diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png new file mode 100644 index 000000000..d6069ebc9 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png new file mode 100644 index 000000000..bdba57b6b Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..92f1e2ddd Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png new file mode 100644 index 000000000..786ed17b7 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png new file mode 100644 index 000000000..b36ec1730 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..2476cbddd Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png new file mode 100644 index 000000000..005207cc0 Binary files /dev/null and b/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png differ diff --git a/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml b/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml new file mode 100644 index 000000000..8f7b60a23 --- /dev/null +++ b/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml @@ -0,0 +1,67 @@ + +This sample demonstrates how to connect to the network and fetch raw HTML. -The sample uses {@link android.os.AsyncTask} to perform the fetch on a -background thread.
++ + This sample demonstrates how to connect to the network and fetch raw HTML using + HttpURLConnection. AsyncTask is used to perform the fetch on a background thread. + +
diff --git a/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml b/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ + + +When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java deleted file mode 100644 index 32be1a698..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.notifications; - -import android.content.Context; -import android.support.v4.app.NotificationCompat; - -/** - * Base class for notification actions presets. - */ -public abstract class ActionsPreset extends NamedPreset { - public ActionsPreset(int nameResId) { - super(nameResId); - } - - /** Apply the priority to a notification builder */ - public abstract void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions); -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java deleted file mode 100644 index 2481ac8d3..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.notifications; - -import android.content.Context; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.RemoteInput; - -/** - * Collection of notification actions presets. - */ -public class ActionsPresets { - public static final ActionsPreset NO_ACTIONS_PRESET = new NoActionsPreset(); - public static final ActionsPreset SINGLE_ACTION_PRESET = new SingleActionPreset(); - - public static final ActionsPreset[] PRESETS = new ActionsPreset[] { - NO_ACTIONS_PRESET, - SINGLE_ACTION_PRESET, - new ReplyActionPreset(), - new ReplyWithChoicesActionPreset(), - new DifferentActionsOnPhoneAndWearable(), - new LongTitleActionPreset() - }; - - private static class NoActionsPreset extends ActionsPreset { - public NoActionsPreset() { - super(R.string.no_actions); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - } - } - - private static class SingleActionPreset extends ActionsPreset { - public SingleActionPreset() { - super(R.string.single_action); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - builder.addAction(R.drawable.ic_full_action, - context.getString(R.string.example_action), - NotificationUtil.getExamplePendingIntent(context, - R.string.example_action_clicked)) - .build(); - } - } - - private static class LongTitleActionPreset extends ActionsPreset { - public LongTitleActionPreset() { - super(R.string.long_title_action); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - builder.addAction(R.drawable.ic_full_action, - context.getString(R.string.example_action_long_title), - NotificationUtil.getExamplePendingIntent(context, - R.string.example_action_clicked)) - .build(); - } - } - - private static class ReplyActionPreset extends ActionsPreset { - public ReplyActionPreset() { - super(R.string.reply_action); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY) - .setLabel(context.getString(R.string.example_reply_label)) - .build(); - NotificationCompat.Action action = new NotificationCompat.Action.Builder( - R.drawable.ic_full_reply, - context.getString(R.string.example_reply_action), - NotificationUtil.getExamplePendingIntent(context, - R.string.example_reply_action_clicked)) - .addRemoteInput(remoteInput) - .build(); - builder.addAction(action); - } - } - - private static class ReplyWithChoicesActionPreset extends ActionsPreset { - public ReplyWithChoicesActionPreset() { - super(R.string.reply_action_with_choices); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY) - .setLabel(context.getString(R.string.example_reply_answer_label)) - .setChoices(new String[] { context.getString(R.string.yes), - context.getString(R.string.no), context.getString(R.string.maybe) }) - .build(); - NotificationCompat.Action action = new NotificationCompat.Action.Builder( - R.drawable.ic_full_reply, - context.getString(R.string.example_reply_action), - NotificationUtil.getExamplePendingIntent(context, - R.string.example_reply_action_clicked)) - .addRemoteInput(remoteInput) - .build(); - wearableOptions.addAction(action); - } - } - - private static class DifferentActionsOnPhoneAndWearable extends ActionsPreset { - public DifferentActionsOnPhoneAndWearable() { - super(R.string.different_actions_on_phone_and_wearable); - } - - @Override - public void apply(Context context, NotificationCompat.Builder builder, - NotificationCompat.WearableExtender wearableOptions) { - NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder( - R.drawable.ic_full_action, - context.getString(R.string.phone_action), - NotificationUtil.getExamplePendingIntent(context, - R.string.phone_action_clicked)) - .build(); - builder.addAction(phoneAction); - - RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY) - .setLabel(context.getString(R.string.example_reply_label)) - .build(); - - NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder( - R.drawable.ic_full_reply, - context.getString(R.string.wearable_action), - NotificationUtil.getExamplePendingIntent(context, - R.string.wearable_action_clicked)) - .addRemoteInput(remoteInput) - .build(); - wearableOptions.addAction(wearableAction); - } - } -} diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java deleted file mode 100644 index 69263b25f..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.notifications; - -import android.content.Context; -import android.content.res.Resources; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.List; - -/** - * Manages the background image pickers. - */ -public class BackgroundPickers { - - public interface OnBackgroundPickersChangedListener { - public void onBackgroundPickersChanged(BackgroundPickers pickers); - } - - private final ViewGroup mContainer; - private final OnPickedListener mOnPickedListener; - private final List+ + This sample demonstrates how to use PdfRenderer to display PDF documents on the screen. + +
diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png new file mode 100644 index 000000000..32bd1aabc Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..0c9b69468 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png new file mode 100644 index 000000000..135862883 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png new file mode 100644 index 000000000..8efbbf8b3 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..1a6c3d0d8 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png new file mode 100644 index 000000000..ba143ea7a Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..2081f403b Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png new file mode 100644 index 000000000..394eb7e53 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png differ diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..b506de4d5 Binary files /dev/null and b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml b/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml new file mode 100755 index 000000000..be1aa49d9 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml @@ -0,0 +1,36 @@ + + +When this is set as the head of the list, - * an instance of it can function as a drop-in replacement for {@link android.util.Log}. - * Most of the methods in this class server only to map a method call in Log to its equivalent - * in LogNode.
- */ -public class Log { - // Grabbing the native values from Android's native logging facilities, - // to make for easy migration and interop. - public static final int NONE = -1; - public static final int VERBOSE = android.util.Log.VERBOSE; - public static final int DEBUG = android.util.Log.DEBUG; - public static final int INFO = android.util.Log.INFO; - public static final int WARN = android.util.Log.WARN; - public static final int ERROR = android.util.Log.ERROR; - public static final int ASSERT = android.util.Log.ASSERT; - - // Stores the beginning of the LogNode topology. - private static LogNode mLogNode; - - /** - * Returns the next LogNode in the linked list. - */ - public static LogNode getLogNode() { - return mLogNode; - } - - /** - * Sets the LogNode data will be sent to. - */ - public static void setLogNode(LogNode node) { - mLogNode = node; - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void println(int priority, String tag, String msg, Throwable tr) { - if (mLogNode != null) { - mLogNode.println(priority, tag, msg, tr); - } - } - - /** - * Instructs the LogNode to print the log data provided. Other LogNodes can - * be chained to the end of the LogNode as desired. - * - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - */ - public static void println(int priority, String tag, String msg) { - println(priority, tag, msg, null); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void v(String tag, String msg, Throwable tr) { - println(VERBOSE, tag, msg, tr); - } - - /** - * Prints a message at VERBOSE priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void v(String tag, String msg) { - v(tag, msg, null); - } - - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void d(String tag, String msg, Throwable tr) { - println(DEBUG, tag, msg, tr); - } - - /** - * Prints a message at DEBUG priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void d(String tag, String msg) { - d(tag, msg, null); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void i(String tag, String msg, Throwable tr) { - println(INFO, tag, msg, tr); - } - - /** - * Prints a message at INFO priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void i(String tag, String msg) { - i(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, String msg, Throwable tr) { - println(WARN, tag, msg, tr); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void w(String tag, String msg) { - w(tag, msg, null); - } - - /** - * Prints a message at WARN priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void w(String tag, Throwable tr) { - w(tag, null, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void e(String tag, String msg, Throwable tr) { - println(ERROR, tag, msg, tr); - } - - /** - * Prints a message at ERROR priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void e(String tag, String msg) { - e(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, String msg, Throwable tr) { - println(ASSERT, tag, msg, tr); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. - */ - public static void wtf(String tag, String msg) { - wtf(tag, msg, null); - } - - /** - * Prints a message at ASSERT priority. - * - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public static void wtf(String tag, Throwable tr) { - wtf(tag, null, tr); - } -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright 2013 The Android Open Source 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. -*/ -/* - * Copyright 2013 The Android Open Source 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. - */ - -package com.example.android.common.logger; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ScrollView; - -/** - * Simple fraggment which contains a LogView and uses is to output log data it receives - * through the LogNode interface. - */ -public class LogFragment extends Fragment { - - private LogView mLogView; - private ScrollView mScrollView; - - public LogFragment() {} - - public View inflateViews() { - mScrollView = new ScrollView(getActivity()); - ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - mScrollView.setLayoutParams(scrollParams); - - mLogView = new LogView(getActivity()); - ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); - logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - mLogView.setLayoutParams(logParams); - mLogView.setClickable(true); - mLogView.setFocusable(true); - mLogView.setTypeface(Typeface.MONOSPACE); - - // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! - int paddingDips = 16; - double scale = getResources().getDisplayMetrics().density; - int paddingPixels = (int) ((paddingDips * (scale)) + .5); - mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); - mLogView.setCompoundDrawablePadding(paddingPixels); - - mLogView.setGravity(Gravity.BOTTOM); - mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); - - mScrollView.addView(mLogView); - return mScrollView; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - View result = inflateViews(); - - mLogView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - mScrollView.fullScroll(ScrollView.FOCUS_DOWN); - } - }); - return result; - } - - public LogView getLogView() { - return mLogView; - } -} \ No newline at end of file diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Basic interface for a logging system that can output to one or more targets. - * Note that in addition to classes that will output these logs in some format, - * one can also implement this interface over a filter and insert that in the chain, - * such that no targets further down see certain data, or see manipulated forms of the data. - * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data - * it received to HTML and sent it along to the next node in the chain, without printing it - * anywhere. - */ -public interface LogNode { - - /** - * Instructs first LogNode in the list to print the log data provided. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - public void println(int priority, String tag, String msg, Throwable tr); - -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.app.Activity; -import android.content.Context; -import android.util.*; -import android.widget.TextView; - -/** Simple TextView which is used to output log data received through the LogNode interface. -*/ -public class LogView extends TextView implements LogNode { - - public LogView(Context context) { - super(context); - } - - public LogView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LogView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Formats the log data and prints it out to the LogView. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - - - String priorityStr = null; - - // For the purposes of this View, we want to print the priority as readable text. - switch(priority) { - case android.util.Log.VERBOSE: - priorityStr = "VERBOSE"; - break; - case android.util.Log.DEBUG: - priorityStr = "DEBUG"; - break; - case android.util.Log.INFO: - priorityStr = "INFO"; - break; - case android.util.Log.WARN: - priorityStr = "WARN"; - break; - case android.util.Log.ERROR: - priorityStr = "ERROR"; - break; - case android.util.Log.ASSERT: - priorityStr = "ASSERT"; - break; - default: - break; - } - - // Handily, the Log class has a facility for converting a stack trace into a usable string. - String exceptionStr = null; - if (tr != null) { - exceptionStr = android.util.Log.getStackTraceString(tr); - } - - // Take the priority, tag, message, and exception, and concatenate as necessary - // into one usable line of text. - final StringBuilder outputBuilder = new StringBuilder(); - - String delimiter = "\t"; - appendIfNotNull(outputBuilder, priorityStr, delimiter); - appendIfNotNull(outputBuilder, tag, delimiter); - appendIfNotNull(outputBuilder, msg, delimiter); - appendIfNotNull(outputBuilder, exceptionStr, delimiter); - - // In case this was originally called from an AsyncTask or some other off-UI thread, - // make sure the update occurs within the UI thread. - ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { - @Override - public void run() { - // Display the text we just generated within the LogView. - appendToLog(outputBuilder.toString()); - } - }))); - - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } - - public LogNode getNext() { - return mNext; - } - - public void setNext(LogNode node) { - mNext = node; - } - - /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since - * the logger takes so many arguments that might be null, this method helps cut out some of the - * agonizing tedium of writing the same 3 lines over and over. - * @param source StringBuilder containing the text to append to. - * @param addStr The String to append - * @param delimiter The String to separate the source and appended strings. A tab or comma, - * for instance. - * @return The fully concatenated String as a StringBuilder - */ - private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { - if (addStr != null) { - if (addStr.length() == 0) { - delimiter = ""; - } - - return source.append(addStr).append(delimiter); - } - return source; - } - - // The next LogNode in the chain. - LogNode mNext; - - /** Outputs the string as a new line of log data in the LogView. */ - public void appendToLog(String s) { - append("\n" + s); - } - - -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source 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. - */ -package com.example.android.common.logger; - -import android.util.Log; - -/** - * Helper class which wraps Android's native Log utility in the Logger interface. This way - * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. - */ -public class LogWrapper implements LogNode { - - // For piping: The next node to receive Log data after this one has done its work. - private LogNode mNext; - - /** - * Returns the next LogNode in the linked list. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - - /** - * Prints data out to the console using Android's native log mechanism. - * @param priority Log level of the data being logged. Verbose, Error, etc. - * @param tag Tag for for the log data. Can be used to organize log statements. - * @param msg The actual message to be logged. The actual message to be logged. - * @param tr If an exception was thrown, this can be sent along for the logging facilities - * to extract and print useful information. - */ - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - // There actually are log methods that don't take a msg parameter. For now, - // if that's the case, just convert null to the empty string and move on. - String useMsg = msg; - if (useMsg == null) { - useMsg = ""; - } - - // If an exeption was provided, convert that exception to a usable string and attach - // it to the end of the msg method. - if (tr != null) { - msg += "\n" + Log.getStackTraceString(tr); - } - - // This is functionally identical to Log.x(tag, useMsg); - // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) - Log.println(priority, tag, useMsg); - - // If this isn't the last node in the chain, move things along. - if (mNext != null) { - mNext.println(priority, tag, msg, tr); - } - } -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source 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. - */ -package com.example.android.common.logger; - -/** - * Simple {@link LogNode} filter, removes everything except the message. - * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, - * just easy-to-read message updates as they're happening. - */ -public class MessageOnlyLogFilter implements LogNode { - - LogNode mNext; - - /** - * Takes the "next" LogNode as a parameter, to simplify chaining. - * - * @param next The next LogNode in the pipeline. - */ - public MessageOnlyLogFilter(LogNode next) { - mNext = next; - } - - public MessageOnlyLogFilter() { - } - - @Override - public void println(int priority, String tag, String msg, Throwable tr) { - if (mNext != null) { - getNext().println(Log.NONE, null, msg, null); - } - } - - /** - * Returns the next LogNode in the chain. - */ - public LogNode getNext() { - return mNext; - } - - /** - * Sets the LogNode data will be sent to.. - */ - public void setNext(LogNode node) { - mNext = node; - } - -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java deleted file mode 100644 index ea5c56b5e..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.quiz; - -/** Constants used in the companion app. */ -public final class Constants { - private Constants() { - } - - public static final String ANSWERS = "answers"; - public static final String CHOSEN_ANSWER_CORRECT = "chosen_answer_correct"; - public static final String CORRECT_ANSWER_INDEX = "correct_answer_index"; - public static final String QUESTION = "question"; - public static final String QUESTION_INDEX = "question_index"; - public static final String QUESTION_WAS_ANSWERED = "question_was_answered"; - public static final String QUESTION_WAS_DELETED = "question_was_deleted"; - - public static final String NUM_CORRECT = "num_correct"; - public static final String NUM_INCORRECT = "num_incorrect"; - public static final String NUM_SKIPPED = "num_skipped"; - - public static final String QUIZ_ENDED_PATH = "/quiz_ended"; - public static final String QUIZ_EXITED_PATH = "/quiz_exited"; - public static final String RESET_QUIZ_PATH = "/reset_quiz"; -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java deleted file mode 100644 index a0f98c12b..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.quiz; - -import android.content.Context; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.io.InputStream; - -final class JsonUtils { - public static final String JSON_FIELD_QUESTIONS = "questions"; - public static final String JSON_FIELD_QUESTION = "question"; - public static final String JSON_FIELD_ANSWERS = "answers"; - public static final String JSON_FIELD_CORRECT_INDEX = "correctIndex"; - public static final int NUM_ANSWER_CHOICES = 4; - - private JsonUtils() { - } - - public static JSONObject loadJsonFile(Context context, String fileName) throws IOException, - JSONException { - InputStream is = context.getAssets().open(fileName); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - String jsonString = new String(buffer); - return new JSONObject(jsonString); - } -} diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java deleted file mode 100644 index ab8e3b45b..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java +++ /dev/null @@ -1,585 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source 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. - */ - -package com.example.android.quiz; - -import static com.example.android.quiz.Constants.ANSWERS; -import static com.example.android.quiz.Constants.CHOSEN_ANSWER_CORRECT; -import static com.example.android.quiz.Constants.CORRECT_ANSWER_INDEX; -import static com.example.android.quiz.Constants.NUM_CORRECT; -import static com.example.android.quiz.Constants.NUM_INCORRECT; -import static com.example.android.quiz.Constants.NUM_SKIPPED; -import static com.example.android.quiz.Constants.QUESTION; -import static com.example.android.quiz.Constants.QUESTION_INDEX; -import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED; -import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED; -import static com.example.android.quiz.Constants.QUIZ_ENDED_PATH; -import static com.example.android.quiz.Constants.QUIZ_EXITED_PATH; -import static com.example.android.quiz.Constants.RESET_QUIZ_PATH; - -import android.app.Activity; -import android.graphics.Color; -import android.net.Uri; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.RadioGroup; -import android.widget.TextView; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; -import com.google.android.gms.common.api.ResultCallback; -import com.google.android.gms.common.data.FreezableUtils; -import com.google.android.gms.wearable.DataApi; -import com.google.android.gms.wearable.DataEvent; -import com.google.android.gms.wearable.DataEventBuffer; -import com.google.android.gms.wearable.DataItem; -import com.google.android.gms.wearable.DataItemBuffer; -import com.google.android.gms.wearable.DataMap; -import com.google.android.gms.wearable.DataMapItem; -import com.google.android.gms.wearable.MessageApi; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.PriorityQueue; - -/** - * Allows the user to create questions, which will be put as notifications on the watch's stream. - * The status of questions will be updated on the phone when the user answers them. - */ -public class MainActivity extends Activity implements DataApi.DataListener, - MessageApi.MessageListener, ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener { - - private static final String TAG = "ExampleQuizApp"; - private static final String QUIZ_JSON_FILE = "Quiz.json"; - - // Various UI components. - private EditText questionEditText; - private EditText choiceAEditText; - private EditText choiceBEditText; - private EditText choiceCEditText; - private EditText choiceDEditText; - private RadioGroup choicesRadioGroup; - private TextView quizStatus; - private LinearLayout quizButtons; - private LinearLayout questionsContainer; - private Button readQuizFromFileButton; - private Button resetQuizButton; - - private GoogleApiClient mGoogleApiClient; - private PriorityQueue