Skip to content
Permalink
Browse files

Make this build in Eclipse

Changing up custom extension mechanism to enable building in Eclipse.

Change-Id: I519c162a852abda0cc2b6d0b3f3bd4e8f53b6ad7
  • Loading branch information...
Sara Ting Michael Chan
Sara Ting authored and Michael Chan committed Dec 17, 2012
1 parent 6f67927 commit f84b1a90cf76e7eff76affa17834377194caba8c
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src_ex_common"/>
<classpathentry kind="src" path="src_opt_calendar"/>
<classpathentry kind="src" path="extensions_src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="../../../out/target/common/obj/JAVA_LIBRARIES/android-support-v4_intermediates/classes"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
# Include res dir from chips
chips_dir := ../../../frameworks/ex/chips/res
res_dirs := $(chips_dir) res
src_dirs := src extensions_src
src_dirs := src

LOCAL_EMMA_COVERAGE_FILTER := +com.android.calendar.*

@@ -12,5 +12,6 @@

# Project target.
target=android-17
android.library=false
android.library=true
android.library.reference.1=../../../frameworks/ex/chips
android.library.reference.2=../../../frameworks/opt/calendar
@@ -19,6 +19,6 @@
<header android:fragment="com.android.calendar.GeneralPreferences"
android:title="@string/menu_general_preferences" />

<header android:fragment="com.android.calendar.extensions.AboutPreferences"
<header android:fragment="com.android.calendar.AboutPreferences"
android:title="@string/menu_about_preferences" />
</preference-headers>
@@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.android.calendar.extensions;
package com.android.calendar;

import android.app.Activity;
import android.content.pm.PackageInfo;
@@ -74,7 +74,6 @@
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.agenda.AgendaFragment;
import com.android.calendar.extensions.AllInOneMenuExtensions;
import com.android.calendar.month.MonthByWeekFragment;
import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;

@@ -165,7 +164,8 @@
private LayoutParams mControlsParams;
private LinearLayout.LayoutParams mVerticalControlsParams;

private AllInOneMenuExtensions mExtensions = new AllInOneMenuExtensions();
private AllInOneMenuExtensionsInterface mExtensions = ExtensionsFactory
.getAllInOneMenuExtensions();

private final AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.calendar;

import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;

/*
* Interface for additional options in the AllInOne menu.
*/
public interface AllInOneMenuExtensionsInterface {
/**
* Returns additional options.
*/
Integer getExtensionMenuResource(Menu menu);

/**
* Handle selection of the additional options.
*/
boolean handleItemSelected(MenuItem item, Context context);
}
@@ -33,5 +33,8 @@ public void onCreate() {
// moved to that implementation.
Utils.setSharedPreference(this, GeneralPreferences.KEY_VERSION,
Utils.getVersionCode(this));

// Initialize the registry mapping some custom behavior.
ExtensionsFactory.init(getAssets());
}
}
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.calendar;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/*
* Skeleton for additional options in the AllInOne menu.
*/
public class ExtensionsFactory {
private static String TAG = "ExtensionsFactory";

// Config filename for mappings of various class names to their custom implementations.
private static String EXTENSIONS_PROPERTIES = "calendar_extensions.properties";

private static String ALL_IN_ONE_MENU_KEY = "AllInOneMenuExtensions";

private static Properties sProperties = new Properties();
private static AllInOneMenuExtensionsInterface sAllInOneMenuExtensions = null;

public static void init(AssetManager assetManager) {
try {
InputStream fileStream = assetManager.open(EXTENSIONS_PROPERTIES);
sProperties.load(fileStream);
fileStream.close();
} catch (IOException e) {
// No custom extensions. Ignore.
Log.d(TAG, "No custom extensions.", e);
}
}

private static <T> T createInstance(String className) {
try {
Class<?> c = Class.forName(className);
return (T) c.newInstance();
} catch (ClassNotFoundException e) {
Log.e(TAG, className + ": unable to create instance.", e);
} catch (IllegalAccessException e) {
Log.e(TAG, className + ": unable to create instance.", e);
} catch (InstantiationException e) {
Log.e(TAG, className + ": unable to create instance.", e);
}
return null;
}

public static AllInOneMenuExtensionsInterface getAllInOneMenuExtensions() {
if (sAllInOneMenuExtensions == null) {
String className = sProperties.getProperty(ALL_IN_ONE_MENU_KEY);
if (className != null) {
sAllInOneMenuExtensions = createInstance(className);
} else {
Log.d(TAG, ALL_IN_ONE_MENU_KEY + " not found in properties file.");
}

if (sAllInOneMenuExtensions == null) {
sAllInOneMenuExtensions = new AllInOneMenuExtensionsInterface() {
@Override
public Integer getExtensionMenuResource(Menu menu) {
return null;
}

@Override
public boolean handleItemSelected(MenuItem item, Context context) {
return false;
}
};
}
}

return sAllInOneMenuExtensions;
}
}

0 comments on commit f84b1a9

Please sign in to comment.
You can’t perform that action at this time.