下面列出了怎么用android.support.annotation.Keep的API类实例代码及写法,或者点击链接到github查看源代码。
@Keep
public void setDrawerPosition(float value)
{
drawerPosition = value;
if (drawerPosition > drawerLayout.getMeasuredWidth())
{
drawerPosition = drawerLayout.getMeasuredWidth();
}
else if (drawerPosition < 0)
{
drawerPosition = 0;
}
drawerLayout.setTranslationX(drawerPosition);
final int newVisibility = drawerPosition > 0 ? VISIBLE : GONE;
if (drawerLayout.getVisibility() != newVisibility)
{
drawerLayout.setVisibility(newVisibility);
}
setScrimOpacity(drawerPosition / (float) drawerLayout.getMeasuredWidth());
}
@Keep
public void setTopPadding(float value)
{
topPadding = value;
if (fragment != null)
{
View view = fragment.getFragmentView();
int additionalPadding = 0;
if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE)
{
additionalPadding = AndroidUtilities.dp(36);
}
if (view != null)
{
view.setPadding(0, (int) topPadding + additionalPadding, 0, 0);
}
if (isLocation && additionalContextView != null)
{
((LayoutParams) additionalContextView.getLayoutParams()).topMargin = -AndroidUtilities.dp(36) - (int) topPadding;
}
}
}
@Keep
public void setFullAnimationProgress(float value) {
fullAnimationProgress = value;
placeholderImageView.setRoundRadius(AndroidUtilities.dp(20 * (1.0f - fullAnimationProgress)));
float scale = 1.0f + thumbMaxScale * fullAnimationProgress;
placeholderImageView.setScaleX(scale);
placeholderImageView.setScaleY(scale);
float translationY = placeholderImageView.getTranslationY();
placeholderImageView.setTranslationX(thumbMaxX * fullAnimationProgress);
placeholderImageView.setTranslationY(startTranslation + (endTranslation - startTranslation) * fullAnimationProgress);
playerLayout.setTranslationY(panelStartTranslation + (panelEndTranslation - panelStartTranslation) * fullAnimationProgress);
shadow2.setTranslationY(panelStartTranslation + (panelEndTranslation - panelStartTranslation) * fullAnimationProgress + playerLayout.getMeasuredHeight());
menuItem.setAlpha(fullAnimationProgress);
searchItem.setAlpha(1.0f - fullAnimationProgress);
avatarContainer.setAlpha(1.0f - fullAnimationProgress);
actionBar.getTitleTextView().setAlpha(fullAnimationProgress);
actionBar.getSubtitleTextView().setAlpha(fullAnimationProgress);
}
@Keep
@SuppressLint("NewApi")
protected void setRevealRadius(float radius) {
revealRadius = radius;
if (Build.VERSION.SDK_INT <= 19) {
listView.invalidate();
}
if (!isDismissed()) {
for (int a = 0; a < innerAnimators.size(); a++) {
InnerAnimator innerAnimator = innerAnimators.get(a);
if (innerAnimator.startRadius > radius) {
continue;
}
innerAnimator.animatorSet.start();
innerAnimators.remove(a);
a--;
}
}
}
@Keep
public void setTopPadding(float value)
{
topPadding = value;
if (fragment != null)
{
View view = fragment.getFragmentView();
int additionalPadding = 0;
if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE)
{
additionalPadding = AndroidUtilities.dp(36);
}
if (view != null)
{
view.setPadding(0, (int) topPadding + additionalPadding, 0, 0);
}
if (isLocation && additionalContextView != null)
{
((LayoutParams) additionalContextView.getLayoutParams()).topMargin = -AndroidUtilities.dp(36) - (int) topPadding;
}
}
}
/**
* Track 事件
*
* @param eventName String 事件名称
* @param properties JSONObject 事件属性
*/
@Keep
public void track(@NonNull final String eventName, @Nullable JSONObject properties) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", eventName);
jsonObject.put("device_id", mDeviceId);
JSONObject sendProperties = new JSONObject(mDeviceInfo);
if (properties != null) {
SensorsDataPrivate.mergeJSONObject(properties, sendProperties);
}
jsonObject.put("properties", sendProperties);
jsonObject.put("time", System.currentTimeMillis());
Log.i(TAG, SensorsDataPrivate.formatJson(jsonObject.toString()));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* View 被点击,自动埋点
*
* @param view View
*/
@Keep
public static void trackViewOnClick(View view) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("$element_type", SensorsDataPrivate.getElementType(view));
jsonObject.put("$element_id", SensorsDataPrivate.getViewId(view));
jsonObject.put("$element_content", SensorsDataPrivate.getElementContent(view));
Activity activity = SensorsDataPrivate.getActivityFromView(view);
if (activity != null) {
jsonObject.put("$activity", activity.getClass().getCanonicalName());
}
SensorsDataAPI.getInstance().track("$AppClick", jsonObject);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Track 页面浏览事件
*
* @param activity Activity
*/
@Keep
private static void trackAppViewScreen(Activity activity) {
try {
if (activity == null) {
return;
}
if (mIgnoredActivities.contains(activity.getClass().getCanonicalName())) {
return;
}
JSONObject properties = new JSONObject();
properties.put("$activity", activity.getClass().getCanonicalName());
properties.put("$title", getActivityTitle(activity));
SensorsDataAPI.getInstance().track("$AppViewScreen", properties);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 插件中有时可能希望得到宿主的占位Activity,传递给其他组件使用,而其他组件希望使用这个Activity实例来访问宿主的资源。
* 例如:在插件中弹出通知,通知的图标希望使用宿主的图标,这时就需要访问宿主资源。
*
* @return 占位Activity实例
*/
@Keep
public Activity getShadow() {
try {
ActivityHostProxy shadow = (ActivityHostProxy) this.clone();
shadow.useHostTheme();
return shadow;
} catch (CloneNotSupportedException e) {
VLog.w(e, "clone ActivityHostProxy exception");
String msg = String.format("proxy %s for plugin activity %s cannot clone",
this.getClass().getSimpleName(), mPluginComponentName);
HashMap<String, Object> params = new HashMap<>(1);
params.put(LogReporter.Key.MESSAGE, msg);
LogReporter.reportState(LogReporter.EventId.PROXY_ACTIVITY_CANNOT_CLONE, false, params);
}
return null;
}
@Keep
public void setDrawerPosition(float value)
{
drawerPosition = value;
if (drawerPosition > drawerLayout.getMeasuredWidth())
{
drawerPosition = drawerLayout.getMeasuredWidth();
}
else if (drawerPosition < 0)
{
drawerPosition = 0;
}
drawerLayout.setTranslationX(drawerPosition);
final int newVisibility = drawerPosition > 0 ? VISIBLE : GONE;
if (drawerLayout.getVisibility() != newVisibility)
{
drawerLayout.setVisibility(newVisibility);
}
setScrimOpacity(drawerPosition / (float) drawerLayout.getMeasuredWidth());
}
@Keep
public void setContainerHeight(int value) {
containerHeight = value;
if (spansContainer != null) {
spansContainer.requestLayout();
}
}
@Keep
@Override
public void setAlpha(float alpha) {
ColorDrawable colorDrawable = (ColorDrawable) getBackground();
colorDrawable.setAlpha((int) (0xc0 * alpha));
invalidate();
}
@Keep
@Override
public void setAlpha(int alpha) {
if (parentActivity instanceof LaunchActivity) {
((LaunchActivity) parentActivity).drawerLayoutContainer.setAllowDrawContent(!isPhotoVisible || alpha != 255);
}
super.setAlpha(alpha);
}
@Keep
public void setAnimationIdicatorProgress(float value) {
animationIdicatorProgress = value;
TextView newTab = (TextView) tabsContainer.getChildAt(currentPosition);
TextView prevTab = (TextView) tabsContainer.getChildAt(previousPosition);
setAnimationProgressInernal(newTab, prevTab, value);
if (delegate != null) {
delegate.onPageScrolled(value);
}
}
@Keep
public void setContainerHeight(int value) {
containerHeight = value;
if (spansContainer != null) {
spansContainer.requestLayout();
}
}
@Keep
public void setY(int value) {
windowLayoutParams.y = value;
try {
windowManager.updateViewLayout(windowView, windowLayoutParams);
} catch (Exception ignore) {
}
}
@Keep
public void updateProgress(int progress) {
if (progress > 100)
progress = 100;
this.progress = progress;
invalidate();
}
@Keep
public void setProgress(float value)
{
if (progress == value)
{
return;
}
progress = value;
invalidate();
}
@Keep
public void setProgress(float value) {
if (progress == value) {
return;
}
progress = value;
invalidate();
}
@Keep
@Override
public void setAlpha(float alpha) {
ColorDrawable colorDrawable = (ColorDrawable) getBackground();
colorDrawable.setAlpha((int) (0xc0 * alpha));
invalidate();
}
@Keep
public void setAnimationIdicatorProgress(float value) {
animationIdicatorProgress = value;
TextView newTab = (TextView) tabsContainer.getChildAt(currentPosition);
TextView prevTab = (TextView) tabsContainer.getChildAt(previousPosition);
setAnimationProgressInernal(newTab, prevTab, value);
if (delegate != null) {
delegate.onPageScrolled(value);
}
}
@Keep
public void setProgress(float value) {
if (progress == value) {
return;
}
progress = value;
invalidate();
}
@Keep
public void setAnimationProgress(float progress) {
animProgress = progress;
animateToProgress = progress;
updatePath();
invalidateSelf();
}
@Keep
public void setX(int value) {
windowLayoutParams.x = value;
try {
windowManager.updateViewLayout(windowView, windowLayoutParams);
} catch (Exception ignore) {
}
}
@Keep
public void setY(int value) {
windowLayoutParams.y = value;
try {
windowManager.updateViewLayout(windowView, windowLayoutParams);
} catch (Exception ignore) {
}
}
@Keep
public void setX(int value) {
windowLayoutParams.x = value;
try {
windowManager.updateViewLayout(windowView, windowLayoutParams);
} catch (Exception ignore) {
}
}
@Keep
@SuppressWarnings("UnusedReturnValue")
public static SensorsDataAPI init(Application application) {
synchronized (mLock) {
if (null == INSTANCE) {
INSTANCE = new SensorsDataAPI(application);
}
return INSTANCE;
}
}
@Keep
public static void trackTabHost(String tabName) {
try {
JSONObject properties = new JSONObject();
properties.put("$element_type", "TabHost");
properties.put("$element_content", tabName);
SensorsDataAPI.getInstance().track("$AppClick", properties);
} catch (Exception e) {
e.printStackTrace();
}
}
@Keep
public void setThemeAnimationValue(float value)
{
themeAnimationValue = value;
for (int j = 0; j < 2; j++)
{
if (themeAnimatorDescriptions[j] != null)
{
int rE, gE, bE, aE, rS, gS, bS, aS, a, r, g, b;
for (int i = 0; i < themeAnimatorDescriptions[j].length; i++)
{
rE = Color.red(animateEndColors[j][i]);
gE = Color.green(animateEndColors[j][i]);
bE = Color.blue(animateEndColors[j][i]);
aE = Color.alpha(animateEndColors[j][i]);
rS = Color.red(animateStartColors[j][i]);
gS = Color.green(animateStartColors[j][i]);
bS = Color.blue(animateStartColors[j][i]);
aS = Color.alpha(animateStartColors[j][i]);
a = Math.min(255, (int) (aS + (aE - aS) * value));
r = Math.min(255, (int) (rS + (rE - rS) * value));
g = Math.min(255, (int) (gS + (gE - gS) * value));
b = Math.min(255, (int) (bS + (bE - bS) * value));
themeAnimatorDescriptions[j][i].setColor(Color.argb(a, r, g, b), false, false);
}
if (themeAnimatorDelegate[j] != null)
{
themeAnimatorDelegate[j].didSetColor();
}
}
}
}
@Keep
public void handleLoadPackage(Context context, XC_LoadPackage.LoadPackageParam lpparam) {
mSdcard = Environment.getExternalStorageDirectory().getPath();
if (!isXposedModule(context, lpparam.appInfo)) {
next(lpparam);
}
}