Merge commit 'd297be2136209cab4edbcf8879520f65fb564103' into HEAD
@@ -83,25 +83,27 @@ external/clang/lib/Headers build-tools/${PLATFORM_NAME}/rende
|
||||
external/clang/LICENSE.TXT build-tools/${PLATFORM_NAME}/renderscript/clang-include/LICENSE.TXT
|
||||
|
||||
prebuilts/sdk/renderscript/lib/javalib.jar build-tools/${PLATFORM_NAME}/renderscript/lib/renderscript-v8.jar
|
||||
prebuilts/sdk/renderscript/lib/arm/libclcore.bc build-tools/${PLATFORM_NAME}/renderscript/lib/libclcore.bc
|
||||
|
||||
prebuilts/sdk/renderscript/lib/arm/libc.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/armeabi-v7a/libc.so
|
||||
prebuilts/sdk/renderscript/lib/arm/libm.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/armeabi-v7a/libm.so
|
||||
prebuilts/sdk/renderscript/lib/arm/libcompiler_rt.a build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/armeabi-v7a/libcompiler_rt.a
|
||||
prebuilts/sdk/renderscript/lib/arm/libRSSupport.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/armeabi-v7a/libRSSupport.so
|
||||
prebuilts/sdk/renderscript/lib/arm/librsjni.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/armeabi-v7a/librsjni.so
|
||||
prebuilts/sdk/renderscript/lib/arm/libclcore.bc build-tools/${PLATFORM_NAME}/renderscript/lib/bc/armeabi-v7a/libclcore.bc
|
||||
|
||||
prebuilts/sdk/renderscript/lib/mips/libc.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/mips/libc.so
|
||||
prebuilts/sdk/renderscript/lib/mips/libm.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/mips/libm.so
|
||||
prebuilts/sdk/renderscript/lib/mips/libcompiler_rt.a build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/mips/libcompiler_rt.a
|
||||
prebuilts/sdk/renderscript/lib/mips/libRSSupport.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/mips/libRSSupport.so
|
||||
prebuilts/sdk/renderscript/lib/mips/librsjni.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/mips/librsjni.so
|
||||
prebuilts/sdk/renderscript/lib/mips/libclcore.bc build-tools/${PLATFORM_NAME}/renderscript/lib/bc/mips/libclcore.bc
|
||||
|
||||
prebuilts/sdk/renderscript/lib/x86/libc.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/x86/libc.so
|
||||
prebuilts/sdk/renderscript/lib/x86/libm.so build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/x86/libm.so
|
||||
prebuilts/sdk/renderscript/lib/x86/libcompiler_rt.a build-tools/${PLATFORM_NAME}/renderscript/lib/intermediates/x86/libcompiler_rt.a
|
||||
prebuilts/sdk/renderscript/lib/x86/libRSSupport.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/x86/libRSSupport.so
|
||||
prebuilts/sdk/renderscript/lib/x86/librsjni.so build-tools/${PLATFORM_NAME}/renderscript/lib/packaged/x86/librsjni.so
|
||||
prebuilts/sdk/renderscript/lib/x86/libclcore.bc build-tools/${PLATFORM_NAME}/renderscript/lib/bc/x86/libclcore.bc
|
||||
|
||||
|
||||
|
||||
@@ -168,6 +170,7 @@ docs/features.txt platforms/${PLATFORM_NAME}/data/features.txt
|
||||
|
||||
# fonts for layoutlib.
|
||||
frameworks/base/data/fonts platforms/${PLATFORM_NAME}/data/fonts
|
||||
external/noto-fonts platforms/${PLATFORM_NAME}/data/fonts
|
||||
|
||||
# NOTICE files are copied by build/core/Makefile from sdk.git
|
||||
sdk/files/sdk_files_NOTICE.txt platforms/${PLATFORM_NAME}/templates/NOTICE.txt
|
||||
@@ -218,14 +221,51 @@ development/samples/samples_source.properties samples/${PLATFORM_NAME}/source.p
|
||||
# Note: Some samples reference a shared "common" directory. In the future
|
||||
# this will be copied in automatically via a templating system. For now,
|
||||
# we need to copy it in here as needed.
|
||||
developers/samples/android/connectivity samples/${PLATFORM_NAME}/connectivity
|
||||
developers/samples/android/common samples/${PLATFORM_NAME}/connectivity/sync/BasicSyncAdapter/BasicSyncAdapter/src/main/java/com/example/android/common
|
||||
developers/samples/android/content samples/${PLATFORM_NAME}/content
|
||||
developers/samples/android/input samples/${PLATFORM_NAME}/input
|
||||
developers/samples/android/media samples/${PLATFORM_NAME}/media
|
||||
developers/samples/android/security samples/${PLATFORM_NAME}/security
|
||||
developers/samples/android/testing samples/${PLATFORM_NAME}/testing
|
||||
developers/samples/android/ui samples/${PLATFORM_NAME}/ui
|
||||
developers/build/prebuilts/gradle/BasicAndroidKeyStore/ samples/${PLATFORM_NAME}/security/BasicAndroidKeyStore
|
||||
developers/build/prebuilts/gradle/BasicSyncAdapter/ samples/${PLATFORM_NAME}/connectivity/BasicSyncAdapter
|
||||
developers/build/prebuilts/gradle/NetworkConnect/ samples/${PLATFORM_NAME}/connectivity/NetworkConnect
|
||||
developers/build/prebuilts/gradle/BasicNetworking/ samples/${PLATFORM_NAME}/connectivity/BasicNetworking
|
||||
developers/build/prebuilts/gradle/BluetoothLeGatt/ samples/${PLATFORM_NAME}/connectivity/BluetoothLeGatt
|
||||
developers/build/prebuilts/gradle/AppRestrictions/ samples/${PLATFORM_NAME}/content/AppRestrictions
|
||||
developers/build/prebuilts/gradle/BasicContactables/ samples/${PLATFORM_NAME}/content/BasicContactables
|
||||
developers/build/prebuilts/gradle/StorageClient/ samples/${PLATFORM_NAME}/content/StorageClient
|
||||
developers/build/prebuilts/gradle/StorageProvider/ samples/${PLATFORM_NAME}/content/StorageProvider
|
||||
developers/build/prebuilts/gradle/BasicGestureDetect/ samples/${PLATFORM_NAME}/input/BasicGestureDetect
|
||||
developers/build/prebuilts/gradle/BasicMultitouch/ samples/${PLATFORM_NAME}/input/BasicMultitouch
|
||||
developers/build/prebuilts/gradle/ActivityInstrumentation/ samples/${PLATFORM_NAME}/testing/ActivityInstrumentation
|
||||
developers/build/prebuilts/gradle/MediaRecorder/ samples/${PLATFORM_NAME}/media/MediaRecorder
|
||||
developers/build/prebuilts/gradle/BasicMediaRouter/ samples/${PLATFORM_NAME}/media/BasicMediaRouter
|
||||
developers/build/prebuilts/gradle/BasicMediaDecoder/ samples/${PLATFORM_NAME}/media/BasicMediaDecoder
|
||||
developers/build/prebuilts/gradle/BorderlessButtons/ samples/${PLATFORM_NAME}/ui/BorderlessButtons
|
||||
developers/build/prebuilts/gradle/BasicAccessibility/ samples/${PLATFORM_NAME}/ui/BasicAccessibility
|
||||
developers/build/prebuilts/gradle/CustomChoiceList/ samples/${PLATFORM_NAME}/ui/CustomChoiceList
|
||||
developers/build/prebuilts/gradle/TextSwitcher/ samples/${PLATFORM_NAME}/ui/TextSwitcher
|
||||
developers/build/prebuilts/gradle/HorizontalPaging/ samples/${PLATFORM_NAME}/ui/HorizontalPaging
|
||||
developers/build/prebuilts/gradle/ActionBarCompat-Styled/ samples/${PLATFORM_NAME}/ui/ActionBarCompat-Styled
|
||||
developers/build/prebuilts/gradle/ActionBarCompat-ListPopupMenu/ samples/${PLATFORM_NAME}/ui/ActionBarCompat-ListPopupMenu
|
||||
developers/build/prebuilts/gradle/ActionBarCompat-ShareActionProvider/ samples/${PLATFORM_NAME}/ui/ActionBarCompat-ShareActionProvider
|
||||
developers/build/prebuilts/gradle/ActionBarCompat-Basic/ samples/${PLATFORM_NAME}/ui/ActionBarCompat-Basic
|
||||
developers/build/prebuilts/gradle/BasicNotifications/ samples/${PLATFORM_NAME}/ui/BasicNotifications
|
||||
developers/build/prebuilts/gradle/CustomNotifications/ samples/${PLATFORM_NAME}/ui/CustomNotifications
|
||||
developers/build/prebuilts/gradle/DoneBar/ samples/${PLATFORM_NAME}/ui/DoneBar
|
||||
developers/build/prebuilts/gradle/BasicImmersiveMode/ samples/${PLATFORM_NAME}/ui/BasicImmersiveMode
|
||||
developers/build/prebuilts/gradle/AdvancedImmersiveMode/ samples/${PLATFORM_NAME}/ui/AdvancedImmersiveMode
|
||||
developers/build/prebuilts/gradle/ImmersiveMode/ samples/${PLATFORM_NAME}/ui/ImmersiveMode
|
||||
developers/build/prebuilts/gradle/RepeatingAlarm/ samples/${PLATFORM_NAME}/background/RepeatingAlarm
|
||||
developers/build/prebuilts/gradle/TextLinkify/ samples/${PLATFORM_NAME}/ui/TextLinkify
|
||||
developers/build/prebuilts/gradle/BasicRenderScript samples/${PLATFORM_NAME}/renderscript/BasicRenderScript
|
||||
developers/build/prebuilts/gradle/RenderScriptIntrinsic samples/${PLATFORM_NAME}/renderscript/RenderScriptIntrinsic
|
||||
developers/build/prebuilts/gradle/SlidingTabsBasic samples/${PLATFORM_NAME}/ui/SlidingTabsBasic
|
||||
developers/build/prebuilts/gradle/SlidingTabsColors samples/${PLATFORM_NAME}/ui/SlidingTabsColors
|
||||
developers/build/prebuilts/gradle/CardEmulation samples/${PLATFORM_NAME}/connectivity/CardEmulation
|
||||
developers/build/prebuilts/gradle/CardReader samples/${PLATFORM_NAME}/connectivity/CardReader
|
||||
developers/build/prebuilts/gradle/BatchStepSensor samples/${PLATFORM_NAME}/sensors/BatchStepSensor
|
||||
developers/build/prebuilts/gradle/DisplayingBitmaps samples/${PLATFORM_NAME}/ui/DisplayingBitmaps
|
||||
developers/build/prebuilts/gradle/BasicTransition samples/${PLATFORM_NAME}/ui/BasicTransition
|
||||
developers/build/prebuilts/gradle/AdapterTransition samples/${PLATFORM_NAME}/ui/AdapterTransition
|
||||
developers/build/prebuilts/gradle/MediaRouter samples/${PLATFORM_NAME}/media/MediaRouter
|
||||
|
||||
|
||||
|
||||
# Old sample tree
|
||||
development/samples/AccelerometerPlay samples/${PLATFORM_NAME}/legacy/AccelerometerPlay
|
||||
|
||||
@@ -2469,6 +2469,16 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".view.GameActivity"
|
||||
android:label="Views/System UI Visibility/Game"
|
||||
android:theme="@android:style/Theme.Holo.NoActionBar"
|
||||
android:enabled="@bool/atLeastKitKat">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".view.Switches" android:label="Views/Switches">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
48
samples/ApiDemos/res/layout/game.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<!-- BEGIN_INCLUDE(complete) -->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
>
|
||||
<!-- This is the outer area of the entire game screen, extending out under
|
||||
system UI elements. -->
|
||||
<view class="com.example.android.apis.view.GameActivity$Content"
|
||||
android:id="@+id/content"
|
||||
android:src="@drawable/frantic"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="center"
|
||||
/>
|
||||
<!-- This is the inner area of the game, not covered by system UI elements.
|
||||
Any UI elements that need to be accessible when the game is paused or other
|
||||
states where the system UI is shown (such as in menus) should go here. -->
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:animateLayoutChanges="true"
|
||||
>
|
||||
<Button
|
||||
android:id="@+id/play"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|right"
|
||||
android:textSize="28dp"
|
||||
/>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
<!-- END_INCLUDE(complete) -->
|
||||
@@ -266,7 +266,7 @@ public class LoaderCustom extends Activity {
|
||||
onReleaseResources(apps);
|
||||
}
|
||||
}
|
||||
List<AppEntry> oldApps = apps;
|
||||
List<AppEntry> oldApps = mApps;
|
||||
mApps = apps;
|
||||
|
||||
if (isStarted()) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
@@ -87,9 +88,6 @@ public class TouchPaint extends GraphicsActivity {
|
||||
/** Is fading mode enabled? */
|
||||
boolean mFading;
|
||||
|
||||
/** The index of the current color to use. */
|
||||
int mColorIndex;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -104,10 +102,10 @@ public class TouchPaint extends GraphicsActivity {
|
||||
// the contents of the bitmap.
|
||||
if (savedInstanceState != null) {
|
||||
mFading = savedInstanceState.getBoolean("fading", true);
|
||||
mColorIndex = savedInstanceState.getInt("color", 0);
|
||||
mView.mColorIndex = savedInstanceState.getInt("color", 0);
|
||||
} else {
|
||||
mFading = true;
|
||||
mColorIndex = 0;
|
||||
mView.mColorIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ public class TouchPaint extends GraphicsActivity {
|
||||
// Save away the fading state to restore if needed later. Note that
|
||||
// we do not currently save the contents of the display.
|
||||
outState.putBoolean("fading", mFading);
|
||||
outState.putInt("color", mColorIndex);
|
||||
outState.putInt("color", mView.mColorIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,9 +223,9 @@ public class TouchPaint extends GraphicsActivity {
|
||||
*
|
||||
* It handles all of the input events and drawing functions.
|
||||
*/
|
||||
class PaintView extends View {
|
||||
public static class PaintView extends View {
|
||||
private static final int FADE_ALPHA = 0x06;
|
||||
private static final int MAX_FADE_STEPS = 256 / FADE_ALPHA + 4;
|
||||
private static final int MAX_FADE_STEPS = 256 / (FADE_ALPHA/2) + 4;
|
||||
private static final int TRACKBALL_SCALE = 10;
|
||||
|
||||
private static final int SPLAT_VECTORS = 40;
|
||||
@@ -235,21 +233,31 @@ public class TouchPaint extends GraphicsActivity {
|
||||
private final Random mRandom = new Random();
|
||||
private Bitmap mBitmap;
|
||||
private Canvas mCanvas;
|
||||
private final Paint mPaint;
|
||||
private final Paint mFadePaint;
|
||||
private final Paint mPaint = new Paint();
|
||||
private final Paint mFadePaint = new Paint();
|
||||
private float mCurX;
|
||||
private float mCurY;
|
||||
private int mOldButtonState;
|
||||
private int mFadeSteps = MAX_FADE_STEPS;
|
||||
|
||||
/** The index of the current color to use. */
|
||||
int mColorIndex;
|
||||
|
||||
public PaintView(Context c) {
|
||||
super(c);
|
||||
init();
|
||||
}
|
||||
|
||||
public PaintView(Context c, AttributeSet attrs) {
|
||||
super(c, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setFocusable(true);
|
||||
|
||||
mPaint = new Paint();
|
||||
mPaint.setAntiAlias(true);
|
||||
|
||||
mFadePaint = new Paint();
|
||||
mFadePaint.setColor(BACKGROUND_COLOR);
|
||||
mFadePaint.setAlpha(FADE_ALPHA);
|
||||
}
|
||||
@@ -273,6 +281,31 @@ public class TouchPaint extends GraphicsActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void text(String text) {
|
||||
if (mBitmap != null) {
|
||||
final int width = mBitmap.getWidth();
|
||||
final int height = mBitmap.getHeight();
|
||||
mPaint.setColor(COLORS[mColorIndex]);
|
||||
mPaint.setAlpha(255);
|
||||
int size = height;
|
||||
mPaint.setTextSize(size);
|
||||
Rect bounds = new Rect();
|
||||
mPaint.getTextBounds(text, 0, text.length(), bounds);
|
||||
int twidth = bounds.width();
|
||||
twidth += (twidth/4);
|
||||
if (twidth > width) {
|
||||
size = (size*width)/twidth;
|
||||
mPaint.setTextSize(size);
|
||||
mPaint.getTextBounds(text, 0, text.length(), bounds);
|
||||
}
|
||||
Paint.FontMetrics fm = mPaint.getFontMetrics();
|
||||
mCanvas.drawText(text, (width-bounds.width())/2,
|
||||
((height-size)/2) - fm.ascent, mPaint);
|
||||
mFadeSteps = 0;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
int curW = mBitmap != null ? mBitmap.getWidth() : 0;
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.apis.view;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.ActionBar.Tab;
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.ShareActionProvider;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.SearchView.OnQueryTextListener;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
import com.example.android.apis.graphics.TouchPaint;
|
||||
|
||||
/**
|
||||
* This activity demonstrates how to use the system UI flags to
|
||||
* implement an immersive game.
|
||||
*/
|
||||
public class GameActivity extends Activity {
|
||||
|
||||
/**
|
||||
* Implementation of a view for the game, filling the entire screen.
|
||||
*/
|
||||
//BEGIN_INCLUDE(content)
|
||||
public static class Content extends TouchPaint.PaintView implements
|
||||
View.OnSystemUiVisibilityChangeListener, View.OnClickListener {
|
||||
Activity mActivity;
|
||||
Button mPlayButton;
|
||||
boolean mPaused;
|
||||
int mLastSystemUiVis;
|
||||
boolean mUpdateSystemUi;
|
||||
|
||||
Runnable mFader = new Runnable() {
|
||||
@Override public void run() {
|
||||
fade();
|
||||
if (mUpdateSystemUi) {
|
||||
updateNavVisibility();
|
||||
}
|
||||
if (!mPaused) {
|
||||
getHandler().postDelayed(mFader, 1000/30);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Content(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOnSystemUiVisibilityChangeListener(this);
|
||||
}
|
||||
|
||||
public void init(Activity activity, Button playButton) {
|
||||
// This called by the containing activity to supply the surrounding
|
||||
// state of the game that it will interact with.
|
||||
mActivity = activity;
|
||||
mPlayButton = playButton;
|
||||
mPlayButton.setOnClickListener(this);
|
||||
setGamePaused(true);
|
||||
}
|
||||
|
||||
@Override public void onSystemUiVisibilityChange(int visibility) {
|
||||
// Detect when we go out of nav-hidden mode, to reset back to having
|
||||
// it hidden; our game wants those elements to stay hidden as long
|
||||
// as it is being played and stay shown when paused.
|
||||
int diff = mLastSystemUiVis ^ visibility;
|
||||
mLastSystemUiVis = visibility;
|
||||
if (!mPaused && (diff&SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
|
||||
&& (visibility&SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
|
||||
// We are running and the system UI navigation has become
|
||||
// shown... we want it to remain hidden, so update our system
|
||||
// UI state at the next game loop.
|
||||
mUpdateSystemUi = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onWindowVisibilityChanged(int visibility) {
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
|
||||
// When we become visible or invisible, play is paused.
|
||||
setGamePaused(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
|
||||
// When we become visible or invisible, play is paused.
|
||||
// Optional: pause game when window loses focus. This will cause it to
|
||||
// pause, for example, when the notification shade is pulled down.
|
||||
if (!hasWindowFocus) {
|
||||
//setGamePaused(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
if (v == mPlayButton) {
|
||||
// Clicking on the play/pause button toggles its state.
|
||||
setGamePaused(!mPaused);
|
||||
}
|
||||
}
|
||||
|
||||
void setGamePaused(boolean paused) {
|
||||
mPaused = paused;
|
||||
mPlayButton.setText(paused ? R.string.play : R.string.pause);
|
||||
setKeepScreenOn(!paused);
|
||||
updateNavVisibility();
|
||||
Handler h = getHandler();
|
||||
if (h != null) {
|
||||
getHandler().removeCallbacks(mFader);
|
||||
if (!paused) {
|
||||
mFader.run();
|
||||
text("Draw!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateNavVisibility() {
|
||||
int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
||||
if (!mPaused) {
|
||||
newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
}
|
||||
|
||||
// Set the new desired visibility.
|
||||
setSystemUiVisibility(newVis);
|
||||
mUpdateSystemUi = false;
|
||||
}
|
||||
}
|
||||
//END_INCLUDE(content)
|
||||
|
||||
Content mContent;
|
||||
|
||||
public GameActivity() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.game);
|
||||
mContent = (Content)findViewById(R.id.content);
|
||||
mContent.init(this, (Button)findViewById(R.id.play));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
// Pause game when its activity is paused.
|
||||
mContent.setGamePaused(true);
|
||||
}
|
||||
}
|
||||
29
samples/ControllerSample/AndroidManifest.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.controllersample"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
android:targetSdkVersion="18" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".GameViewActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
BIN
samples/ControllerSample/libs/android-support-v4.jar
Normal file
20
samples/ControllerSample/proguard-project.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
14
samples/ControllerSample/project.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-18
|
||||
BIN
samples/ControllerSample/res/drawable-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
samples/ControllerSample/res/drawable-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 746 B |
BIN
samples/ControllerSample/res/drawable-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
samples/ControllerSample/res/drawable-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
|
||||
<!-- Game controller input demo. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dip"
|
||||
android:text="@string/game_controller_input_description" />
|
||||
|
||||
<com.example.controllersample.GameView
|
||||
android:id="@+id/game"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_margin="15dip"
|
||||
android:layout_weight="1"
|
||||
android:background="#000000" />
|
||||
|
||||
</LinearLayout>
|
||||
11
samples/ControllerSample/res/values-v11/styles.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
12
samples/ControllerSample/res/values-v14/styles.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
11
samples/ControllerSample/res/values/strings.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Controller Sample</string>
|
||||
<string name="game_controller_input_description">
|
||||
This activity demonstrates how to process input events received from
|
||||
game controllers. Please connect your game controller now and try
|
||||
moving the joysticks or pressing buttons. If it helps, try to imagine
|
||||
that you are a lone space cowboy in hot pursuit of the aliens who kidnapped
|
||||
your favorite llama on their way back to Andromeda…
|
||||
</string>
|
||||
</resources>
|
||||
20
samples/ControllerSample/res/values/styles.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.controllersample;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class GameViewActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.game_controller_input);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.inputmanagercompat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public interface InputManagerCompat {
|
||||
/**
|
||||
* Gets information about the input device with the specified id.
|
||||
*
|
||||
* @param id The device id
|
||||
* @return The input device or null if not found
|
||||
*/
|
||||
public InputDevice getInputDevice(int id);
|
||||
|
||||
/**
|
||||
* Gets the ids of all input devices in the system.
|
||||
*
|
||||
* @return The input device ids.
|
||||
*/
|
||||
public int[] getInputDeviceIds();
|
||||
|
||||
/**
|
||||
* Registers an input device listener to receive notifications about when
|
||||
* input devices are added, removed or changed.
|
||||
*
|
||||
* @param listener The listener to register.
|
||||
* @param handler The handler on which the listener should be invoked, or
|
||||
* null if the listener should be invoked on the calling thread's
|
||||
* looper.
|
||||
*/
|
||||
public void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener,
|
||||
Handler handler);
|
||||
|
||||
/**
|
||||
* Unregisters an input device listener.
|
||||
*
|
||||
* @param listener The listener to unregister.
|
||||
*/
|
||||
public void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener);
|
||||
|
||||
/*
|
||||
* The following three calls are to simulate V16 behavior on pre-Jellybean
|
||||
* devices. If you don't call them, your callback will never be called
|
||||
* pre-API 16.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pass the motion events to the InputManagerCompat. This is used to
|
||||
* optimize for polling for controllers. If you do not pass these events in,
|
||||
* polling will cause regular object creation.
|
||||
*
|
||||
* @param event the motion event from the app
|
||||
*/
|
||||
public void onGenericMotionEvent(MotionEvent event);
|
||||
|
||||
/**
|
||||
* Tell the V9 input manager that it should stop polling for disconnected
|
||||
* devices. You can call this during onPause in your activity, although you
|
||||
* might want to call it whenever your game is not active (or whenever you
|
||||
* don't care about being notified of new input devices)
|
||||
*/
|
||||
public void onPause();
|
||||
|
||||
/**
|
||||
* Tell the V9 input manager that it should start polling for disconnected
|
||||
* devices. You can call this during onResume in your activity, although you
|
||||
* might want to call it less often (only when the gameplay is actually
|
||||
* active)
|
||||
*/
|
||||
public void onResume();
|
||||
|
||||
public interface InputDeviceListener {
|
||||
/**
|
||||
* Called whenever the input manager detects that a device has been
|
||||
* added. This will only be called in the V9 version when a motion event
|
||||
* is detected.
|
||||
*
|
||||
* @param deviceId The id of the input device that was added.
|
||||
*/
|
||||
void onInputDeviceAdded(int deviceId);
|
||||
|
||||
/**
|
||||
* Called whenever the properties of an input device have changed since
|
||||
* they were last queried. This will not be called for the V9 version of
|
||||
* the API.
|
||||
*
|
||||
* @param deviceId The id of the input device that changed.
|
||||
*/
|
||||
void onInputDeviceChanged(int deviceId);
|
||||
|
||||
/**
|
||||
* Called whenever the input manager detects that a device has been
|
||||
* removed. For the V9 version, this can take some time depending on the
|
||||
* poll rate.
|
||||
*
|
||||
* @param deviceId The id of the input device that was removed.
|
||||
*/
|
||||
void onInputDeviceRemoved(int deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to construct a compatible InputManager.
|
||||
*/
|
||||
public static class Factory {
|
||||
|
||||
/**
|
||||
* Constructs and returns a compatible InputManger
|
||||
*
|
||||
* @param context the Context that will be used to get the system
|
||||
* service from
|
||||
* @return a compatible implementation of InputManager
|
||||
*/
|
||||
public static InputManagerCompat getInputManager(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
return new InputManagerV16(context);
|
||||
} else {
|
||||
return new InputManagerV9();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.inputmanagercompat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class InputManagerV16 implements InputManagerCompat {
|
||||
|
||||
private final InputManager mInputManager;
|
||||
private final Map<InputManagerCompat.InputDeviceListener, V16InputDeviceListener> mListeners;
|
||||
|
||||
public InputManagerV16(Context context) {
|
||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||
mListeners = new HashMap<InputManagerCompat.InputDeviceListener, V16InputDeviceListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputDevice getInputDevice(int id) {
|
||||
return mInputManager.getInputDevice(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputDeviceIds() {
|
||||
return mInputManager.getInputDeviceIds();
|
||||
}
|
||||
|
||||
static class V16InputDeviceListener implements InputManager.InputDeviceListener {
|
||||
final InputManagerCompat.InputDeviceListener mIDL;
|
||||
|
||||
public V16InputDeviceListener(InputDeviceListener idl) {
|
||||
mIDL = idl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
mIDL.onInputDeviceAdded(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
mIDL.onInputDeviceChanged(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
mIDL.onInputDeviceRemoved(deviceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
|
||||
V16InputDeviceListener v16Listener = new V16InputDeviceListener(listener);
|
||||
mInputManager.registerInputDeviceListener(v16Listener, handler);
|
||||
mListeners.put(listener, v16Listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterInputDeviceListener(InputDeviceListener listener) {
|
||||
V16InputDeviceListener curListener = mListeners.remove(listener);
|
||||
if (null != curListener)
|
||||
{
|
||||
mInputManager.unregisterInputDeviceListener(curListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenericMotionEvent(MotionEvent event) {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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.inputmanagercompat;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public class InputManagerV9 implements InputManagerCompat {
|
||||
private static final String LOG_TAG = "InputManagerV9";
|
||||
private static final int MESSAGE_TEST_FOR_DISCONNECT = 101;
|
||||
private static final long CHECK_ELAPSED_TIME = 3000L;
|
||||
|
||||
private static final int ON_DEVICE_ADDED = 0;
|
||||
private static final int ON_DEVICE_CHANGED = 1;
|
||||
private static final int ON_DEVICE_REMOVED = 2;
|
||||
|
||||
private final SparseArray<long[]> mDevices;
|
||||
private final Map<InputDeviceListener, Handler> mListeners;
|
||||
private final Handler mDefaultHandler;
|
||||
|
||||
private static class PollingMessageHandler extends Handler {
|
||||
private final WeakReference<InputManagerV9> mInputManager;
|
||||
|
||||
PollingMessageHandler(InputManagerV9 im) {
|
||||
mInputManager = new WeakReference<InputManagerV9>(im);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case MESSAGE_TEST_FOR_DISCONNECT:
|
||||
InputManagerV9 imv = mInputManager.get();
|
||||
if (null != imv) {
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
int size = imv.mDevices.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
long[] lastContact = imv.mDevices.valueAt(i);
|
||||
if (null != lastContact) {
|
||||
if (time - lastContact[0] > CHECK_ELAPSED_TIME) {
|
||||
// check to see if the device has been
|
||||
// disconnected
|
||||
int id = imv.mDevices.keyAt(i);
|
||||
if (null == InputDevice.getDevice(id)) {
|
||||
// disconnected!
|
||||
imv.notifyListeners(ON_DEVICE_REMOVED, id);
|
||||
imv.mDevices.remove(id);
|
||||
} else {
|
||||
lastContact[0] = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sendEmptyMessageDelayed(MESSAGE_TEST_FOR_DISCONNECT,
|
||||
CHECK_ELAPSED_TIME);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public InputManagerV9() {
|
||||
mDevices = new SparseArray<long[]>();
|
||||
mListeners = new HashMap<InputDeviceListener, Handler>();
|
||||
mDefaultHandler = new PollingMessageHandler(this);
|
||||
// as a side-effect, populates our collection of watched
|
||||
// input devices
|
||||
getInputDeviceIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputDevice getInputDevice(int id) {
|
||||
return InputDevice.getDevice(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputDeviceIds() {
|
||||
// add any hitherto unknown devices to our
|
||||
// collection of watched input devices
|
||||
int[] activeDevices = InputDevice.getDeviceIds();
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
for ( int id : activeDevices ) {
|
||||
long[] lastContact = mDevices.get(id);
|
||||
if ( null == lastContact ) {
|
||||
// we have a new device
|
||||
mDevices.put(id, new long[] { time });
|
||||
}
|
||||
}
|
||||
return activeDevices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
|
||||
mListeners.remove(listener);
|
||||
if (handler == null) {
|
||||
handler = mDefaultHandler;
|
||||
}
|
||||
mListeners.put(listener, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterInputDeviceListener(InputDeviceListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyListeners(int why, int deviceId) {
|
||||
// the state of some device has changed
|
||||
if (!mListeners.isEmpty()) {
|
||||
// yes... this will cause an object to get created... hopefully
|
||||
// it won't happen very often
|
||||
for (InputDeviceListener listener : mListeners.keySet()) {
|
||||
Handler handler = mListeners.get(listener);
|
||||
DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
|
||||
handler.post(odc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeviceEvent implements Runnable {
|
||||
private int mMessageType;
|
||||
private int mId;
|
||||
private InputDeviceListener mListener;
|
||||
private static Queue<DeviceEvent> sEventQueue = new ArrayDeque<DeviceEvent>();
|
||||
|
||||
private DeviceEvent() {
|
||||
}
|
||||
|
||||
static DeviceEvent getDeviceEvent(int messageType, int id,
|
||||
InputDeviceListener listener) {
|
||||
DeviceEvent curChanged = sEventQueue.poll();
|
||||
if (null == curChanged) {
|
||||
curChanged = new DeviceEvent();
|
||||
}
|
||||
curChanged.mMessageType = messageType;
|
||||
curChanged.mId = id;
|
||||
curChanged.mListener = listener;
|
||||
return curChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (mMessageType) {
|
||||
case ON_DEVICE_ADDED:
|
||||
mListener.onInputDeviceAdded(mId);
|
||||
break;
|
||||
case ON_DEVICE_CHANGED:
|
||||
mListener.onInputDeviceChanged(mId);
|
||||
break;
|
||||
case ON_DEVICE_REMOVED:
|
||||
mListener.onInputDeviceRemoved(mId);
|
||||
break;
|
||||
default:
|
||||
Log.e(LOG_TAG, "Unknown Message Type");
|
||||
break;
|
||||
}
|
||||
// dump this runnable back in the queue
|
||||
sEventQueue.offer(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenericMotionEvent(MotionEvent event) {
|
||||
// detect new devices
|
||||
int id = event.getDeviceId();
|
||||
long[] timeArray = mDevices.get(id);
|
||||
if (null == timeArray) {
|
||||
notifyListeners(ON_DEVICE_ADDED, id);
|
||||
timeArray = new long[1];
|
||||
mDevices.put(id, timeArray);
|
||||
}
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
timeArray[0] = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mDefaultHandler.removeMessages(MESSAGE_TEST_FOR_DISCONNECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mDefaultHandler.sendEmptyMessage(MESSAGE_TEST_FOR_DISCONNECT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -305,6 +305,15 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".widget.SwipeRefreshLayoutActivity"
|
||||
android:label="@string/swipe"
|
||||
android:theme="@style/ThemeHoloLight">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".widget.ContentLoadingProgressBarActivity"
|
||||
android:label="@string/content_loading_progress_bar">
|
||||
<intent-filter>
|
||||
|
||||
BIN
samples/Support4Demos/res/drawable-hdpi/refresh.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
samples/Support4Demos/res/drawable-mdpi/refresh.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
samples/Support4Demos/res/drawable-xhdpi/refresh.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe_refresh_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!-- some full screen pullable view that will be the offsetable content -->
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/content"/>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
22
samples/Support4Demos/res/menu/swipe_refresh_menu.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/force_refresh"
|
||||
android:showAsAction="ifRoom"
|
||||
android:icon="@drawable/refresh"
|
||||
android:title="Refresh" />
|
||||
</menu>
|
||||
@@ -19,6 +19,10 @@
|
||||
<style name="ThemeHolo" parent="android:Theme.Holo">
|
||||
</style>
|
||||
|
||||
<!-- For API level 11 or later, the Holo theme is available and we prefer that. -->
|
||||
<style name="ThemeHoloLight" parent="android:Theme.Holo.Light">
|
||||
</style>
|
||||
|
||||
<!-- For API level 11 or later, we can use the magical DialogWhenLarge theme. -->
|
||||
<style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge">
|
||||
</style>
|
||||
|
||||
@@ -18,5 +18,9 @@
|
||||
<drawable name="red">#7f00</drawable>
|
||||
<drawable name="blue">#770000ff</drawable>
|
||||
<drawable name="green">#7700ff00</drawable>
|
||||
<drawable name="yellow">#77ffff00</drawable>
|
||||
<drawable name="yellow">#77ffff00</drawable>
|
||||
<color name="color1">#ff0f9d58</color>
|
||||
<color name="color2">#ffdb4437</color>
|
||||
<color name="color3">#ff4285f4</color>
|
||||
<color name="color4">#fff4b400</color>
|
||||
</resources>
|
||||
|
||||
@@ -160,7 +160,13 @@
|
||||
|
||||
<string name="drawer_layout_summary">This activity illustrates the use of sliding drawers. The drawer may be pulled out from the starting edge, which is left on left-to-right locales, with an edge swipe. If this demo is running on Ice Cream Sandwich or newer you may tap the icon at the starting side of the action bar to open the drawer as well.</string>
|
||||
|
||||
<!-- Title of the navigation drawer, used by accessibility to announce state changes. -->
|
||||
<string name="drawer_title">Navigation</string>
|
||||
|
||||
<!-- Description of the icon that opens the navigation drawer, used by accessibility. -->
|
||||
<string name="drawer_open">Open navigation drawer</string>
|
||||
|
||||
<!-- Description of the icon that closes the navigation drawer, used by accessibility. -->
|
||||
<string name="drawer_close">Close navigation drawer</string>
|
||||
|
||||
<string name="sliding_pane_layout_support">Widget/Sliding pane layout</string>
|
||||
@@ -176,4 +182,6 @@
|
||||
<!-- ContentLoadingProgressBar -->
|
||||
<string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string>
|
||||
|
||||
<!-- Swipe refresh -->
|
||||
<string name="swipe">Widget/SwipeRefreshLayout</string>
|
||||
</resources>
|
||||
|
||||
@@ -21,7 +21,14 @@
|
||||
selected when the holographic theme is available. -->
|
||||
<style name="ThemeHolo" parent="android:Theme">
|
||||
</style>
|
||||
|
||||
|
||||
<!-- This is a theme that will adjust itself depending on the API version.
|
||||
The default definition is the safe one, using a theme that has always
|
||||
been defined. Look at values-11/styles.xml for a variation that is
|
||||
selected when the holographic theme is available. -->
|
||||
<style name="ThemeHoloLight" parent="android:Theme.Light">
|
||||
</style>
|
||||
|
||||
<!-- Older platforms don't have Theme.Holo.DialogWhenLarge; we will define
|
||||
our own wrapper theme that uses it only when running on the appropriate
|
||||
platform version. On older platforms, we always use the generic
|
||||
|
||||
@@ -89,6 +89,11 @@ public class DrawerLayoutActivity extends Activity {
|
||||
mDrawerLayout.setDrawerListener(new DemoDrawerListener());
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
|
||||
|
||||
// The drawer title must be set in order to announce state changes when
|
||||
// accessibility is turned on. This is typically a simple description,
|
||||
// e.g. "Navigation".
|
||||
mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title));
|
||||
|
||||
mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
|
||||
Shakespeare.TITLES));
|
||||
mDrawer.setOnItemClickListener(new DrawerItemClickListener());
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.supportv4.widget;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.android.supportv4.R;
|
||||
import com.example.android.supportv4.Shakespeare;
|
||||
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
|
||||
/**
|
||||
* Example of using the SwipeRefreshLayout.
|
||||
*/
|
||||
public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshListener {
|
||||
public static final String[] TITLES =
|
||||
{
|
||||
"Henry IV (1)",
|
||||
"Henry V",
|
||||
"Henry VIII",
|
||||
"Richard II",
|
||||
"Richard III",
|
||||
"Merchant of Venice",
|
||||
"Othello",
|
||||
"King Lear",
|
||||
"Henry IV (1)",
|
||||
"Henry V",
|
||||
"Henry VIII",
|
||||
"Richard II",
|
||||
"Richard III",
|
||||
"Merchant of Venice",
|
||||
"Othello",
|
||||
"King Lear",
|
||||
"Henry IV (1)",
|
||||
"Henry V",
|
||||
"Henry VIII",
|
||||
"Richard II",
|
||||
"Richard III",
|
||||
"Merchant of Venice",
|
||||
"Othello",
|
||||
"King Lear",
|
||||
"Henry IV (1)",
|
||||
"Henry V",
|
||||
"Henry VIII",
|
||||
"Richard II",
|
||||
"Richard III",
|
||||
"Merchant of Venice",
|
||||
"Othello",
|
||||
"King Lear"
|
||||
};
|
||||
// Try a SUPER quick refresh to make sure we don't get extra refreshes
|
||||
// while the user's finger is still down.
|
||||
private static final boolean SUPER_QUICK_REFRESH = false;
|
||||
private View mContent;
|
||||
private SwipeRefreshLayout mSwipeRefreshWidget;
|
||||
private ListView mList;
|
||||
private Handler mHandler = new Handler();
|
||||
private final Runnable mRefreshDone = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshWidget.setRefreshing(false);
|
||||
}
|
||||
|
||||
};
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.swipe_refresh_widget_sample);
|
||||
mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
|
||||
mSwipeRefreshWidget.setColorScheme(R.color.color1, R.color.color2, R.color.color3,
|
||||
R.color.color4);
|
||||
mList = (ListView) findViewById(R.id.content);
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_1, android.R.id.text1, TITLES);
|
||||
mList.setAdapter(arrayAdapter);
|
||||
mSwipeRefreshWidget.setOnRefreshListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.swipe_refresh_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for the menu item to force a refresh.
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
final int id = item.getItemId();
|
||||
switch(id) {
|
||||
case R.id.force_refresh:
|
||||
mSwipeRefreshWidget.setRefreshing(true);
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
mHandler.removeCallbacks(mRefreshDone);
|
||||
mHandler.postDelayed(mRefreshDone, 1000);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
page.tags="Basic ActionBarCompat"
|
||||
page.tags="ActionBarCompat-Basic"
|
||||
sample.group=UI
|
||||
@jd:body
|
||||
|
||||
|
Before Width: | Height: | Size: 860 B After Width: | Height: | Size: 860 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 557 B After Width: | Height: | Size: 557 B |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |
|
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
|
Before Width: | Height: | Size: 750 B After Width: | Height: | Size: 750 B |
|
Before Width: | Height: | Size: 365 B After Width: | Height: | Size: 365 B |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 713 B After Width: | Height: | Size: 713 B |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
<resources>
|
||||
<string name="app_name">Basic</string>
|
||||
<string name="app_name">ActionBarCompat-Basic</string>
|
||||
<string name="intro_message">
|
||||
<![CDATA[
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
page.tags="ListPopupMenu"
|
||||
page.tags="ActionBarCompat-ListPopupMenu"
|
||||
sample.group=UI
|
||||
@jd:body
|
||||
|
||||
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 122 B After Width: | Height: | Size: 122 B |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
<resources>
|
||||
<string name="app_name">ListPopupMenu</string>
|
||||
<string name="app_name">ActionBarCompat-ListPopupMenu</string>
|
||||
<string name="intro_message">
|
||||
<![CDATA[
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
page.tags="ShareActionProvider"
|
||||
page.tags="ActionBarCompat-ShareActionProvider"
|
||||
sample.group=UI
|
||||
@jd:body
|
||||
|
||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |