auto import from //branches/cupcake/...@131421

This commit is contained in:
The Android Open Source Project 2009-02-13 12:57:53 -08:00
parent 15a8880cb1
commit 98baae654d
28 changed files with 198 additions and 312 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 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.
-->
<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
android:dial="@drawable/clock_dial"
android:hand_hour="@drawable/clock_hour"
android:hand_minute="@drawable/clock_minute"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 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.
-->
<com.android.launcher.PhotoFrame xmlns:android="http://schemas.android.com/apk/res/android"
android:scaleType="center"
android:cropToPadding="true"
android:background="@drawable/picture_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

View File

@ -28,38 +28,32 @@
<string name="menu_item_add_item">"Legg til skrivebord"</string>
<string name="group_applications">"Applikasjon"</string>
<string name="group_shortcuts">"Snarvei"</string>
<!-- no translation found for group_search (5905328940867162196) -->
<skip />
<!-- no translation found for group_folder (236213814675135523) -->
<skip />
<string name="group_search">"Søk"</string>
<string name="group_folder">"Mappe"</string>
<string name="group_live_folders">"Aktiv mappe"</string>
<string name="group_widgets">"Skrivebordselement"</string>
<!-- no translation found for group_gadgets (7795333306847768497) -->
<skip />
<string name="group_gadgets">"Gadget"</string>
<string name="group_wallpapers">"Bakgrunnsbilde"</string>
<string name="add_folder">"Mappe"</string>
<string name="add_clock">"Klokke"</string>
<string name="add_photo_frame">"Bilderamme"</string>
<string name="add_search">"Søk"</string>
<string name="out_of_space">"Ikke nok plass på skrivebordet."</string>
<!-- no translation found for title_select_shortcut (2858897527672831763) -->
<skip />
<!-- no translation found for title_select_live_folder (441136484932944782) -->
<skip />
<string name="title_select_shortcut">"Velg snarvei"</string>
<string name="title_select_live_folder">"Velg aktiv mappe"</string>
<string name="menu_add">"Legg til"</string>
<string name="menu_wallpaper">"Bakgrunnsbilde"</string>
<string name="menu_search">"Søk"</string>
<string name="menu_notifications">"Varslinger"</string>
<string name="menu_settings">"Innstillinger"</string>
<string name="permlab_install_shortcut">"shortcuts"</string>
<string name="permdesc_install_shortcut">"Allows an application to add shortcuts without user intervention."</string>
<string name="permlab_uninstall_shortcut">"uninstall shortcuts"</string>
<string name="permdesc_uninstall_shortcut">"Allows an application to remove shortcuts without user intervention."</string>
<string name="permlab_read_settings">"read Home settings and shortcuts"</string>
<string name="permdesc_read_settings">"Allows an application to read the settings and shortcuts in Home."</string>
<string name="permlab_write_settings">"write Home settings and shortcuts"</string>
<string name="permdesc_write_settings">"Allows an application to change the settings and shortcuts in Home."</string>
<string name="permlab_install_shortcut">"installere snarveier"</string>
<string name="permdesc_install_shortcut">"Lar applikasjonen legge til snarveier uten å involvere brukeren."</string>
<string name="permlab_uninstall_shortcut">"avinstallere snarveier"</string>
<string name="permdesc_uninstall_shortcut">"Lar applikasjonen fjerne snarveier uten å involvere brukeren."</string>
<string name="permlab_read_settings">"lese skrivebordsinnstillinger og -snarveier"</string>
<string name="permdesc_read_settings">"Lar applikasjonen lese innstillinger og snarveier fra skrivebordet."</string>
<string name="permlab_write_settings">"skrive skrivebordsinnstillinger og -snarveier"</string>
<string name="permdesc_write_settings">"Lar applikasjonen endre innstillinger og snarveier på skrivebordet."</string>
<string name="search_hint">"Google-søk"</string>
<!-- no translation found for gadget_error_text (7654995305187314446) -->
<skip />
<string name="gadget_error_text">"Problem under lasting av gadget"</string>
</resources>

View File

@ -357,16 +357,10 @@ public class CellLayout extends ViewGroup {
}
cellInfo.valid = cellInfo.vacantCells.size() > 0;
if (cellInfo.valid) {
int[] xy = new int[2];
if (cellInfo.findCellForSpan(xy, 1, 1)) {
cellInfo.cellX = xy[0];
cellInfo.cellY = xy[1];
cellInfo.spanY = 1;
cellInfo.spanX = 1;
}
}
// Assume the caller will perform their own cell searching, otherwise we
// risk causing an unnecessary rebuild after findCellForSpan()
return cellInfo;
}
@ -665,9 +659,9 @@ public class CellLayout extends ViewGroup {
*
* @param width Width in pixels
* @param height Height in pixels
* @param cellInfo {@link CellInfo} to fill with calculated span parameters
* @param Horizontal and vertical spans required
*/
public void rectToCell(int width, int height, CellInfo cellInfo) {
public int[] rectToCell(int width, int height) {
// Always assume we're working with the smallest span to make sure we
// reserve enough space in both orientations.
int actualWidth = mCellWidth + mWidthGap;
@ -675,8 +669,9 @@ public class CellLayout extends ViewGroup {
int smallerSize = Math.min(actualWidth, actualHeight);
// Always round up to next largest cell
cellInfo.spanX = (width + smallerSize) / smallerSize;
cellInfo.spanY = (height + smallerSize) / smallerSize;
int spanX = (width + smallerSize) / smallerSize;
int spanY = (height + smallerSize) / smallerSize;
return new int[] { spanX, spanY };
}
/**

View File

@ -37,7 +37,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.gadget.GadgetInfo;
import android.gadget.GadgetProviderInfo;
import android.gadget.GadgetManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
@ -197,7 +197,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mInflater = getLayoutInflater();
mGadgetManager = GadgetManager.getInstance(this);
mGadgetHost = new LauncherGadgetHost(this, GADGET_HOST_ID);
mGadgetHost.startListening();
// TODO: figure out if this is first launch and correctly clear GadgetHost database
@ -234,18 +236,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
Selection.setSelection(mDefaultKeySsb, 0);
}
@Override
protected void onStart() {
super.onStart();
mGadgetHost.startListening();
}
@Override
protected void onStop() {
super.onStop();
mGadgetHost.stopListening();
}
private void checkForLocaleChange() {
final SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
final Configuration configuration = getResources().getConfiguration();
@ -315,7 +305,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
switch (requestCode) {
case REQUEST_PICK_APPLICATION:
completeAddApplication(this, data, mAddItemCellInfo);
completeAddApplication(this, data, mAddItemCellInfo, !mDesktopLocked);
break;
case REQUEST_PICK_SHORTCUT:
addShortcut(data);
@ -541,8 +531,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
* @param data The intent describing the application.
* @param cellInfo The position on screen where to create the shortcut.
*/
void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo,
boolean insertAtFirst) {
cellInfo.screen = mWorkspace.getCurrentScreen();
if (!findSingleSlot(cellInfo)) return;
// Find details for this application
ComponentName component = data.getComponent();
@ -567,7 +559,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
itemInfo.icon = activityInfo.loadIcon(packageManager);
itemInfo.container = ItemInfo.NO_ID;
mWorkspace.addApplicationShortcut(itemInfo, mAddItemCellInfo);
mWorkspace.addApplicationShortcut(itemInfo, cellInfo, insertAtFirst);
}
}
@ -580,8 +572,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On
*/
private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo,
boolean insertAtFirst) {
cellInfo.screen = mWorkspace.getCurrentScreen();
if (!findSingleSlot(cellInfo)) return;
final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
if (!mRestoring) {
@ -610,20 +603,20 @@ public final class Launcher extends Activity implements View.OnClickListener, On
Log.d(LOG_TAG, "dumping extras content="+extras.toString());
GadgetInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
GadgetProviderInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
// Calculate the grid spans needed to fit this gadget
CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
layout.rectToCell(gadgetInfo.minWidth, gadgetInfo.minHeight, cellInfo);
int[] spans = layout.rectToCell(gadgetInfo.minWidth, gadgetInfo.minHeight);
// Try finding open space on Launcher screen
final int[] xy = mCellCoordinates;
if (!findSlot(cellInfo, xy, cellInfo.spanX, cellInfo.spanY)) return;
if (!findSlot(cellInfo, xy, spans[0], spans[1])) return;
// Build Launcher-specific Gadget info and save to database
LauncherGadgetInfo launcherInfo = new LauncherGadgetInfo(gadgetId);
launcherInfo.spanX = cellInfo.spanX;
launcherInfo.spanY = cellInfo.spanY;
launcherInfo.spanX = spans[0];
launcherInfo.spanY = spans[1];
LauncherModel.addItemToDatabase(this, launcherInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP,
@ -643,19 +636,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} else if (sModel.isDesktopLoaded()) {
sModel.addDesktopItem(launcherInfo);
}
// Request fresh update if we needed to config this gadget to
// remove the stale UPDATE from the initial bind
if (!extras.containsKey(SKIP_CONFIG) || true) {
// TODO: move this down into GadgetManager to prevent abuse? (anyone
// could force a specific gadget into the ground through flooding)
Log.d(LOG_TAG, "requesting new gadget update because we had a config step");
Intent intent = new Intent(GadgetManager.GADGET_UPDATE_ACTION);
intent.putExtra(GadgetManager.EXTRA_GADGET_IDS, new int[] { gadgetId });
intent.setComponent(gadgetInfo.provider);
sendBroadcast(intent);
}
}
public LauncherGadgetHost getGadgetHost() {
@ -802,6 +782,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDestroyed = true;
super.onDestroy();
mGadgetHost.stopListening();
TextKeyListener.getInstance().release();
@ -901,24 +883,20 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
}
static final String SKIP_CONFIG = "skip_config";
void addGadget(Intent data) {
// TODO: catch bad gadget exception when sent
int gadgetId = data.getIntExtra(GadgetManager.EXTRA_GADGET_ID, -1);
GadgetInfo gadget = mGadgetManager.getGadgetInfo(gadgetId);
GadgetProviderInfo gadget = mGadgetManager.getGadgetInfo(gadgetId);
if (gadget.configure != null) {
// Launch over to configure gadget, if needed
Intent intent = new Intent(GadgetManager.GADGET_CONFIGURE_ACTION);
Intent intent = new Intent(GadgetManager.ACTION_GADGET_CONFIGURE);
intent.setComponent(gadget.configure);
intent.putExtra(GadgetManager.EXTRA_GADGET_ID, gadgetId);
startActivityForResult(intent, REQUEST_CREATE_GADGET);
} else {
// Otherwise just add it
Log.d(LOG_TAG, "dumping extras content="+data.getExtras().toString());
data.putExtra(SKIP_CONFIG, true);
Log.d(LOG_TAG, "dumping extras content="+data.getExtras().toString());
onActivityResult(REQUEST_CREATE_GADGET, Activity.RESULT_OK, data);
}
}
@ -951,28 +929,32 @@ public final class Launcher extends Activity implements View.OnClickListener, On
startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
}
void addFolder() {
void addFolder(boolean insertAtFirst) {
UserFolderInfo folderInfo = new UserFolderInfo();
folderInfo.title = getText(R.string.folder_name);
int cellX = mAddItemCellInfo.cellX;
int cellY = mAddItemCellInfo.cellY;
CellLayout.CellInfo cellInfo = mAddItemCellInfo;
cellInfo.screen = mWorkspace.getCurrentScreen();
if (!findSingleSlot(cellInfo)) return;
// Update the model
LauncherModel.addItemToDatabase(this, folderInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP,
mWorkspace.getCurrentScreen(), cellX, cellY, false);
mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
sModel.addDesktopItem(folderInfo);
sModel.addFolder(folderInfo);
// Create the view
FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
(ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
mWorkspace.addInCurrentScreen(newFolder, cellX, cellY, 1, 1);
mWorkspace.addInCurrentScreen(newFolder,
cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
}
private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo,
boolean insertAtFirst) {
cellInfo.screen = mWorkspace.getCurrentScreen();
if (!findSingleSlot(cellInfo)) return;
final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
if (!mRestoring) {
@ -1031,6 +1013,16 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return info;
}
private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
final int[] xy = new int[2];
if (findSlot(cellInfo, xy, 1, 1)) {
cellInfo.cellX = xy[0];
cellInfo.cellY = xy[1];
return true;
}
return false;
}
private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
boolean[] occupied = mSavedState != null ?
@ -1184,7 +1176,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
count = shortcuts.size();
final DesktopItemsBinder binder = new DesktopItemsBinder(this, shortcuts);
binder.obtainMessage(DesktopItemsBinder.MESSAGE_BIND_ITEMS, 0, count).sendToTarget();
}
@ -1226,26 +1218,16 @@ public final class Launcher extends Activity implements View.OnClickListener, On
final LauncherGadgetInfo launcherInfo = (LauncherGadgetInfo) item;
final int gadgetId = launcherInfo.gadgetId;
GadgetInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
GadgetProviderInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
launcherInfo.hostView = mGadgetHost.createView(this, gadgetId, gadgetInfo);
Log.d(LOG_TAG, "about to setGadget during desktop bind");
Log.d(LOG_TAG, "about to setGadget for id="+gadgetId+", info="+gadgetInfo);
launcherInfo.hostView.setGadget(gadgetId, gadgetInfo);
launcherInfo.hostView.setTag(launcherInfo);
workspace.addInScreen(launcherInfo.hostView, item.screen, item.cellX,
item.cellY, item.spanX, item.spanY, !desktopLocked);
// Now that we've bound the item, request an update for it
if (gadgetInfo != null) {
if (gadgetInfo.provider != null) {
Intent intent = new Intent(GadgetManager.GADGET_UPDATE_ACTION);
intent.putExtra(GadgetManager.EXTRA_GADGET_IDS, new int[] { gadgetId });
intent.setComponent(gadgetInfo.provider);
sendBroadcast(intent);
}
}
break;
case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
final int screen = workspace.getCurrentScreen();
@ -1657,8 +1639,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
case AddAdapter.ITEM_GADGET: {
int gadgetId = Launcher.this.mGadgetHost.allocateGadgetId();
Intent pickIntent = new Intent(GadgetManager.GADGET_PICK_ACTION);
pickIntent.putExtra(GadgetManager.EXTRA_HOST_ID, GADGET_HOST_ID);
Intent pickIntent = new Intent(GadgetManager.ACTION_GADGET_PICK);
pickIntent.putExtra(GadgetManager.EXTRA_GADGET_ID, gadgetId);
startActivityForResult(pickIntent, REQUEST_PICK_GADGET);
break;
@ -1676,7 +1657,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
case AddAdapter.ITEM_FOLDER: {
addFolder();
addFolder(!mDesktopLocked);
dismissDialog(DIALOG_CREATE_SHORTCUT);
break;
}

View File

@ -19,113 +19,20 @@ package com.android.launcher;
import android.content.Context;
import android.gadget.GadgetHost;
import android.gadget.GadgetHostView;
import android.gadget.GadgetInfo;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.TextView;
import android.gadget.GadgetProviderInfo;
/**
* Specific {@link GadgetHost} that creates our {@link LauncherGadgetHostView} which correctly
* captures all long-press events. This ensures that users can always pick up and move gadgets.
* Specific {@link GadgetHost} that creates our {@link LauncherGadgetHostView}
* which correctly captures all long-press events. This ensures that users can
* always pick up and move gadgets.
*/
public class LauncherGadgetHost extends GadgetHost {
public LauncherGadgetHost(Context context, int hostId) {
super(context, hostId);
}
protected GadgetHostView onCreateView(Context context, int gadgetId, GadgetInfo gadget) {
protected GadgetHostView onCreateView(Context context, int gadgetId,
GadgetProviderInfo gadget) {
return new LauncherGadgetHostView(context);
}
/**
* {@inheritDoc}
*/
public class LauncherGadgetHostView extends GadgetHostView {
static final String TAG = "LauncherGadgetHostView";
private boolean mHasPerformedLongPress;
private CheckForLongPress mPendingCheckForLongPress;
private LayoutInflater mInflater;
public LauncherGadgetHostView(Context context) {
super(context);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Prepare our default transition animations
setAnimateFirstView(true);
setInAnimation(context, android.R.anim.fade_in);
setOutAnimation(context, android.R.anim.fade_out);
}
@Override
protected View getErrorView() {
return mInflater.inflate(R.layout.gadget_error, this, false);
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Consume any touch events for ourselves after longpress is triggered
if (mHasPerformedLongPress) {
mHasPerformedLongPress = false;
return true;
}
// Watch for longpress events at this level to make sure
// users can always pick up this Gadget
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
postCheckForLongClick();
break;
}
case MotionEvent.ACTION_UP: {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
break;
}
}
// Otherwise continue letting touch events fall through to children
return false;
}
class CheckForLongPress implements Runnable {
private int mOriginalWindowAttachCount;
public void run() {
if ((mParent != null) && hasWindowFocus()
&& mOriginalWindowAttachCount == getWindowAttachCount()
&& !mHasPerformedLongPress) {
if (performLongClick()) {
mHasPerformedLongPress = true;
}
}
}
public void rememberWindowAttachCount() {
mOriginalWindowAttachCount = getWindowAttachCount();
}
}
private void postCheckForLongClick() {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress();
}
mPendingCheckForLongPress.rememberWindowAttachCount();
postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* Copyright (C) 2009 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.android.launcher;
import android.content.Context;
import android.gadget.GadgetHostView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
/**
* {@inheritDoc}
*/
public class LauncherGadgetHostView extends GadgetHostView {
private boolean mHasPerformedLongPress;
private CheckForLongPress mPendingCheckForLongPress;
private LayoutInflater mInflater;
public LauncherGadgetHostView(Context context) {
super(context);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
protected View getErrorView() {
return mInflater.inflate(R.layout.gadget_error, this, false);
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Consume any touch events for ourselves after longpress is triggered
if (mHasPerformedLongPress) {
mHasPerformedLongPress = false;
return true;
}
// Watch for longpress events at this level to make sure
// users can always pick up this Gadget
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
postCheckForLongClick();
break;
}
case MotionEvent.ACTION_UP: {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
break;
}
}
// Otherwise continue letting touch events fall through to children
return false;
}
class CheckForLongPress implements Runnable {
private int mOriginalWindowAttachCount;
public void run() {
if ((mParent != null) && hasWindowFocus()
&& mOriginalWindowAttachCount == getWindowAttachCount()
&& !mHasPerformedLongPress) {
if (performLongClick()) {
mHasPerformedLongPress = true;
}
}
}
public void rememberWindowAttachCount() {
mOriginalWindowAttachCount = getWindowAttachCount();
}
}
private void postCheckForLongClick() {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress();
}
mPendingCheckForLongPress.rememberWindowAttachCount();
postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
}
}

View File

@ -894,37 +894,6 @@ public class LauncherModel {
return null;
}
static Widget getPhotoFrameInfo(Context context, int screen, int cellX, int cellY) {
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
null, "screen=? and cellX=? and cellY=? and itemType=?",
new String[] { String.valueOf(screen), String.valueOf(cellX), String.valueOf(cellY),
String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME) }, null);
try {
if (c.moveToFirst()) {
final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ID);
final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
Widget widgetInfo = Widget.makePhotoFrame();
widgetInfo.id = c.getLong(idIndex);
widgetInfo.screen = c.getInt(screenIndex);
widgetInfo.container = c.getInt(containerIndex);
widgetInfo.cellX = c.getInt(cellXIndex);
widgetInfo.cellY = c.getInt(cellYIndex);
return widgetInfo;
}
} finally {
c.close();
}
return null;
}
/**
* Add an item to the database in a specified container. Sets the container, screen, cellX and
* cellY fields of the item. Also assigns an ID to the item.

View File

@ -178,10 +178,13 @@ class LiveFolderAdapter extends CursorAdapter {
}
mCustomIcons.clear();
try {
getCursor().close();
} finally {
mLauncher.stopManagingCursor(getCursor());
final Cursor cursor = getCursor();
if (cursor != null) {
try {
cursor.close();
} finally {
mLauncher.stopManagingCursor(cursor);
}
}
}

View File

@ -50,7 +50,6 @@ public class WallpaperChooser extends Activity implements AdapterView.OnItemSele
R.drawable.wallpaper_path_small,
R.drawable.wallpaper_sunrise_small,
R.drawable.wallpaper_mountain_small,
R.drawable.wallpaper_ripples_small,
R.drawable.wallpaper_road_small,
R.drawable.wallpaper_jellyfish_small,
R.drawable.wallpaper_zanzibar_small,
@ -68,7 +67,6 @@ public class WallpaperChooser extends Activity implements AdapterView.OnItemSele
R.drawable.wallpaper_path,
R.drawable.wallpaper_sunrise,
R.drawable.wallpaper_mountain,
R.drawable.wallpaper_ripples,
R.drawable.wallpaper_road,
R.drawable.wallpaper_jellyfish,
R.drawable.wallpaper_zanzibar,
@ -130,7 +128,7 @@ public class WallpaperChooser extends Activity implements AdapterView.OnItemSele
"drawable", packageName);
if (thumbRes != 0) {
mThumbs.add(res);
mThumbs.add(thumbRes);
mImages.add(res);
}
}

View File

@ -20,32 +20,11 @@ import android.content.ContentValues;
import android.graphics.Bitmap;
/**
* Represents one instance of a Launcher widget (clock, search, photo frame).
*
* Represents one instance of a Launcher widget, such as search.
*/
class Widget extends ItemInfo {
int layoutResource;
Bitmap photo;
static Widget makeClock() {
Widget w = new Widget();
w.itemType = LauncherSettings.Favorites.ITEM_TYPE_WIDGET_CLOCK;
w.spanX = 2;
w.spanY = 2;
w.layoutResource = R.layout.widget_clock;
return w;
}
static Widget makePhotoFrame() {
Widget w = new Widget();
w.itemType = LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME;
w.spanX = 2;
w.spanY = 2;
w.layoutResource = R.layout.widget_photo_frame;
return w;
}
static Widget makeSearch() {
Widget w = new Widget();
w.itemType = LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH;
@ -54,11 +33,4 @@ class Widget extends ItemInfo {
w.layoutResource = R.layout.widget_search;
return w;
}
@Override
void onAddToDatabase(ContentValues values) {
super.onAddToDatabase(values);
writeBitmap(values, photo);
}
}

View File

@ -839,11 +839,16 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
}
void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo) {
addApplicationShortcut(info, cellInfo, false);
}
void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo,
boolean insertAtFirst) {
final CellLayout layout = (CellLayout) getChildAt(cellInfo.screen);
final int[] result = new int[2];
layout.cellToPoint(cellInfo.cellX, cellInfo.cellY, result);
onDropExternal(result[0], result[1], info, layout);
onDropExternal(result[0], result[1], info, layout, insertAtFirst);
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
@ -882,6 +887,11 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
}
private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout) {
onDropExternal(x, y, dragInfo, cellLayout, false);
}
private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout,
boolean insertAtFirst) {
// Drag from somewhere else
ItemInfo info = (ItemInfo) dragInfo;
@ -905,7 +915,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
throw new IllegalStateException("Unknown item type: " + info.itemType);
}
cellLayout.addView(view);
cellLayout.addView(view, insertAtFirst ? 0 : -1);
view.setOnLongClickListener(mLongClickListener);
cellLayout.onDropChild(view, x, y);
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();