If you think the Android project mobilepower-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2013 Dario Scoppelletti, <http://www.scoppelletti.it/>.
* //fromwww.java2s.com
* 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 it.scoppelletti.mobilepower.app;
import java.lang.reflect.*;
import android.os.*;
import org.slf4j.*;
import it.scoppelletti.mobilepower.os.*;
import it.scoppelletti.mobilepower.reflect.*;
/**
* Barra delle azioni.
*/finalclass ActionBarCompat implements ActionBarSupport, MemberCache.Resolver {
privatefinalstaticint METHOD_SETHOMEBUTTONENABLED = 1;
privatestaticfinal Logger myLogger = LoggerFactory.getLogger(
"ActionBarCompat");
privatefinal Object myTarget;
/**
* Costruttore.
*
* @param target Implementazione della barra delle azioni.
*/
ActionBarCompat(Object target) {
if (target == null) {
thrownew NullPointerException("Argument target is null.");
}
myTarget = target;
}
publicvoid setHomeButtonEnabled(boolean enabled) {
Method method;
if (Build.VERSION.SDK_INT <
BuildCompat.VERSION_CODES.ICE_CREAM_SANDWICH) {
return;
}
try {
method = (Method) MemberCache.getInstance().getMember(
myTarget.getClass(),
ActionBarCompat.METHOD_SETHOMEBUTTONENABLED, this);
method.invoke(myTarget, enabled);
} catch (Exception ex) {
myLogger.error("Method setHomeButtonEnabled failed.", ex);
}
}
public Member resolveMember(Class<?> clazz, int memberCode) {
Member member;
try {
switch (memberCode) {
case ActionBarCompat.METHOD_SETHOMEBUTTONENABLED:
member = clazz.getMethod("setHomeButtonEnabled", Boolean.TYPE);
break;
default:
thrownew NoSuchMethodException(
String.format("Unexpected memberCode %1$d.", memberCode));
}
} catch (Exception ex) {
thrownew UnsupportedOperationException(ex.getMessage(), ex);
}
return member;
}
}