Skip to content

Commit

Permalink
Livefolders cleanup and properly detect options based on
Browse files Browse the repository at this point in the history
location
  • Loading branch information
John Van Etten committed Mar 31, 2011
1 parent 7aa7a46 commit 26594a3
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 128 deletions.
11 changes: 0 additions & 11 deletions src/org/adw/launcher2/FolderInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.adw.launcher2;

import java.util.List;

import android.graphics.Bitmap;
import android.view.View;

Expand Down Expand Up @@ -52,13 +50,4 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
super.executeAction(action, view, launcher);
}
}

@Override
public List<EditAction> getAvailableActions(View view) {
List<EditAction> result = super.getAvailableActions(view);
result.add(new EditAction(ACTION_DELETE,
android.R.drawable.ic_menu_delete,
R.string.menu_delete));
return result;
}
}
13 changes: 8 additions & 5 deletions src/org/adw/launcher2/IconItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
}

@Override
public List<EditAction> getAvailableActions(View view) {
List<EditAction> result = super.getAvailableActions(view);
result.add(new EditAction(ACTION_EDIT,
android.R.drawable.ic_menu_edit,
R.string.menu_edit));
public List<EditAction> getAvailableActions(View view, Launcher launcher) {
List<EditAction> result = super.getAvailableActions(view, launcher);
if ( container != ItemInfo.NO_ID )
{
result.add(new EditAction(ACTION_EDIT,
android.R.drawable.ic_menu_edit,
R.string.menu_edit));
}
return result;
}
}
25 changes: 16 additions & 9 deletions src/org/adw/launcher2/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,26 @@ public int getId()

interface ItemPackage
{
public String getPackageName();
public String getPackageName(Launcher launcher);
}

public List<EditAction> getAvailableActions(View view) {
return new ArrayList<EditAction>();
public List<EditAction> getAvailableActions(View view, Launcher launcher) {
ArrayList<EditAction> result = new ArrayList<EditAction>();
if ( container != ItemInfo.NO_ID )
{
result.add(new EditAction(ACTION_DELETE,
android.R.drawable.ic_menu_delete,
R.string.menu_delete));
}
return result;
}

public void executeAction(EditAction action, View view, Launcher launcher) {
switch(action.getId()) {
case ACTION_APPINFO: {
try
{
String appPackage = ((ItemPackage) this).getPackageName();
String appPackage = ((ItemPackage) this).getPackageName(launcher);
if ( appPackage != null )
{
Intent intent = new Intent();
Expand Down Expand Up @@ -267,7 +274,7 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
{
try
{
String appPackage = ((ItemPackage) this).getPackageName();
String appPackage = ((ItemPackage) this).getPackageName(null);
if ( appPackage != null )
{
Intent intent = new Intent(Intent.ACTION_VIEW);
Expand All @@ -288,7 +295,7 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
}
}

protected void addAppInfoAction(View view, List<EditAction> result)
protected void addAppInfoAction(View view, List<EditAction> result, Launcher launcher)
{
// get the application info label and if found show the option
if (mAppInfoLabel == null)
Expand All @@ -309,15 +316,15 @@ protected void addAppInfoAction(View view, List<EditAction> result)
}
if (mAppInfoLabel != null && this instanceof ItemPackage)
{
if ( ((ItemPackage) this).getPackageName() != null )
if ( ((ItemPackage) this).getPackageName(launcher) != null )
{
result.add(new EditAction(ACTION_APPINFO,
android.R.drawable.ic_menu_info_details,
mAppInfoLabel));
}
}
}
protected void addMarketAction(View view, List<EditAction> result)
protected void addMarketAction(View view, List<EditAction> result, Launcher launcher)
{
// get the market icon and label
if (mMarketIcon == null && mMarketLabel == null)
Expand All @@ -344,7 +351,7 @@ protected void addMarketAction(View view, List<EditAction> result)
// if market, show it as an option
if (mMarketIcon != null && mMarketLabel != null && this instanceof ItemPackage)
{
if ( ((ItemPackage) this).getPackageName() != null )
if ( ((ItemPackage) this).getPackageName(launcher) != null )
{
result.add(new EditAction(ACTION_MARKET, mMarketIcon,mMarketLabel));
}
Expand Down
16 changes: 15 additions & 1 deletion src/org/adw/launcher2/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import android.content.IntentFilter;
import android.content.Intent.ShortcutIconResource;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
Expand Down Expand Up @@ -980,6 +981,19 @@ public String getPackageNameFromIntent(Intent intent) {
if (res != null)
pName = res.activityInfo.packageName;
}

if (pName == null) {
Uri data = intent.getData();
if ( data != null )
{
String host = data.getHost();
PackageManager mgr = getPackageManager();
ProviderInfo packageInfo = mgr.resolveContentProvider(host, 0);
if (packageInfo != null)
pName = packageInfo.packageName;
}
}

return pName;
}

Expand Down Expand Up @@ -2437,7 +2451,7 @@ public void showActions(ItemInfo info, View view, PopupWindow.OnDismissListener
if (info == null || view == null)
return;

List<EditAction> actions = info.getAvailableActions(view);
List<EditAction> actions = info.getAvailableActions(view, this);
if (actions.size() <= 0)
return;
final View finalview = view;
Expand Down
13 changes: 5 additions & 8 deletions src/org/adw/launcher2/LauncherAppWidgetInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,19 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
}

@Override
public List<EditAction> getAvailableActions(View view) {
List<EditAction> result = super.getAvailableActions(view);
result.add(new EditAction(ACTION_DELETE,
android.R.drawable.ic_menu_delete,
R.string.menu_delete));
public List<EditAction> getAvailableActions(View view, Launcher launcher) {
List<EditAction> result = super.getAvailableActions(view, launcher);

result.add(new EditAction(ACTION_RESIZE,
android.R.drawable.ic_menu_crop,
R.string.menu_resize));
addAppInfoAction(view, result);
addMarketAction(view, result);
addAppInfoAction(view, result, launcher);
addMarketAction(view, result, launcher);
return result;
}

@Override
public String getPackageName()
public String getPackageName(Launcher launcher)
{
final AppWidgetProviderInfo appWidgetInfo = hostView.getAppWidgetInfo();
if (appWidgetInfo != null && appWidgetInfo.provider != null)
Expand Down
152 changes: 72 additions & 80 deletions src/org/adw/launcher2/LiveFolderInfo.java
Original file line number Diff line number Diff line change
@@ -1,80 +1,72 @@
/*
* 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.
*/

package org.adw.launcher2;

import java.util.List;

import org.adw.launcher2.settings.LauncherSettings;

import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

class LiveFolderInfo extends FolderInfo {

/**
* The base intent, if it exists.
*/
Intent baseIntent;

/**
* The live folder's content uri.
*/
Uri uri;

/**
* The live folder's display type.
*/
int displayMode;

LiveFolderInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER;
}

@Override
void onAddToDatabase(ContentValues values) {
super.onAddToDatabase(values);
values.put(LauncherSettings.Favorites.URI, uri.toString());
if (baseIntent != null) {
values.put(LauncherSettings.Favorites.INTENT, baseIntent.toUri(0));
}
values.put(LauncherSettings.Favorites.DISPLAY_MODE, displayMode);
}

private static final int ACTION_UNINSTALL = 2;

@Override
public void executeAction(EditAction action, View view, Launcher launcher) {
switch(action.getId()) {
case ACTION_UNINSTALL: {
launcher.UninstallPackage(launcher.getPackageNameFromIntent(baseIntent));
} break;
default:
super.executeAction(action, view, launcher);
}
}

@Override
public List<EditAction> getAvailableActions(View view) {
List<EditAction> result = super.getAvailableActions(view);
result.add(new EditAction(ACTION_UNINSTALL,
android.R.drawable.ic_menu_manage,
R.string.menu_uninstall));
return result;
}
}
/*
* 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.
*/

package org.adw.launcher2;

import java.util.List;

import org.adw.launcher2.settings.LauncherSettings;

import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

class LiveFolderInfo extends FolderInfo implements ItemInfo.ItemPackage {

/**
* The base intent, if it exists.
*/
Intent baseIntent;

/**
* The live folder's content uri.
*/
Uri uri;

/**
* The live folder's display type.
*/
int displayMode;

LiveFolderInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER;
}

@Override
void onAddToDatabase(ContentValues values) {
super.onAddToDatabase(values);
values.put(LauncherSettings.Favorites.URI, uri.toString());
if (baseIntent != null) {
values.put(LauncherSettings.Favorites.INTENT, baseIntent.toUri(0));
}
values.put(LauncherSettings.Favorites.DISPLAY_MODE, displayMode);
}

@Override
public List<EditAction> getAvailableActions(View view, Launcher launcher) {
List<EditAction> result = super.getAvailableActions(view, launcher);
addAppInfoAction(view, result, launcher);
addMarketAction(view, result, launcher);
return result;
}

@Override
public String getPackageName(Launcher launcher)
{
return launcher.getPackageNameFromIntent(baseIntent);
}
}
20 changes: 6 additions & 14 deletions src/org/adw/launcher2/ShortcutInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,17 @@ public void executeAction(EditAction action, View view, Launcher launcher) {
}

@Override
public List<EditAction> getAvailableActions(View view) {
List<EditAction> result = super.getAvailableActions(view);
result.add(new EditAction(ACTION_DELETE,
android.R.drawable.ic_menu_delete,
R.string.menu_delete
));
addAppInfoAction(view, result);
addMarketAction(view, result);
public List<EditAction> getAvailableActions(View view, Launcher launcher) {
List<EditAction> result = super.getAvailableActions(view, launcher);
addAppInfoAction(view, result, launcher);
addMarketAction(view, result, launcher);
return result;
}

@Override
public String getPackageName()
public String getPackageName(Launcher launcher)
{
if ( intent != null && intent.getComponent() != null )
{
return intent.getComponent().getPackageName();
}
return null;
return launcher.getPackageNameFromIntent(intent);
}
}

0 comments on commit 26594a3

Please sign in to comment.