样式化 OsLicensesMenuActivity

Styling OssLicensesMenuActivity

我在我的应用程序上使用了一个名为 play-services-plugins to include Open Source Notices 的 Google 库。

我可以毫无问题地实现它,但我不知道如何设置显示许可证的 activity 样式。

在我的代码中,我通过调用 startActivity(Intent(this, OssLicensesMenuActivity::class.java))

来启动 activity

因为 OssLicensesMenuActivity 是 Activity class,我设法设计成这样:


styles.xml:

<style name="LicensesTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimaryDark</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


AndroidManifest.xml:

<activity
    android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
    android:theme="@style/LicensesTheme" />


这就像一个魅力,但这个 activity 只显示我正在使用的所有库。 还有第二个 activity 显示许可证,这是我不知道如何设置样式的那个。我面临的问题是来自 OssLicensesMenuActivity 的代码被混淆了,我找不到我想要设置样式的 activity class 的名称和包。

有人知道我怎么解决这个问题吗?

为了便于检查,来自OssLicensesMenuActivity的混淆代码如下:

package com.google.android.gms.oss.licenses;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;
import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.Loader;
import com.google.android.gms.common.annotation.KeepForSdk;
import com.google.android.gms.internal.oss_licenses.zzc;
import com.google.android.gms.oss.licenses.R.id;
import com.google.android.gms.oss.licenses.R.layout;
import com.google.android.gms.tasks.Task;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public final class OssLicensesMenuActivity extends AppCompatActivity implements LoaderCallbacks<List<zzc>> {
    private static String zzx;
    private ListView zzy;
    private ArrayAdapter<zzc> zzz;
    private boolean zzaa;
    private zze zzp;
    private Task<String> zzab;
    private com.google.android.gms.oss.licenses.zzc zzo;

    public OssLicensesMenuActivity() {
    }

    @KeepForSdk
    protected final void onCreate(@Nullable Bundle var1) {
        super.onCreate(var1);
        this.zzo = com.google.android.gms.oss.licenses.zzc.zza(this);
        this.zzaa = fileExistsAndNotEmpty(this, "third_party_licenses") && fileExistsAndNotEmpty(this, "third_party_license_metadata");
        Intent var3;
        if (zzx == null && (var3 = this.getIntent()).hasExtra("title")) {
            zzx = var3.getStringExtra("title");
            Log.w("OssLicensesMenuActivity", "The intent based title is deprecated. Use OssLicensesMenuActivity.setActivityTitle(title) instead.");
        }

        if (zzx != null) {
            this.setTitle(zzx);
        }

        if (this.getSupportActionBar() != null) {
            this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        if (this.zzaa) {
            zzh var10001 = com.google.android.gms.oss.licenses.zzc.zza(this).zzb();
            String var4 = this.getPackageName();
            zzh var2 = var10001;
            this.zzab = var10001.doRead(new zzk(var2, var4));
            this.getSupportLoaderManager().initLoader(54321, (Bundle)null, this);
            this.zzab.addOnCompleteListener(new zzp(this));
        } else {
            this.setContentView(layout.license_menu_activity_no_licenses);
        }
    }

    public static void setActivityTitle(@NonNull String var0) {
        zzx = var0;
    }

    @VisibleForTesting(
        otherwise = 2
    )
    @KeepForSdk
    static boolean fileExistsAndNotEmpty(@NonNull Context var0, @NonNull String var1) {
        InputStream var2 = null;

        try {
            Resources var3;
            String var4 = (var3 = var0.getResources()).getResourcePackageName(id.license_list);
            boolean var5 = (var2 = var3.openRawResource(var3.getIdentifier(var1, "raw", var4))).available() > 0;
            return var5;
        } catch (IOException | NotFoundException var13) {
        } finally {
            if (var2 != null) {
                try {
                    var2.close();
                } catch (IOException var12) {
                }
            }

        }

        return false;
    }

    @KeepForSdk
    public final boolean onOptionsItemSelected(MenuItem var1) {
        if (var1.getItemId() == 16908332) {
            this.finish();
            return true;
        } else {
            return super.onOptionsItemSelected(var1);
        }
    }

    @KeepForSdk
    public final void onDestroy() {
        this.getSupportLoaderManager().destroyLoader(54321);
        super.onDestroy();
    }

    @KeepForSdk
    public final Loader<List<zzc>> onCreateLoader(int var1, Bundle var2) {
        return this.zzaa ? new zzo(this, com.google.android.gms.oss.licenses.zzc.zza(this)) : null;
    }

    @KeepForSdk
    public final void onLoadFinished(Loader<List<zzc>> var1, List<zzc> var2) {
        this.zzz.clear();
        this.zzz.addAll(var2);
        this.zzz.notifyDataSetChanged();
    }

    @KeepForSdk
    public final void onLoaderReset(Loader<List<zzc>> var1) {
        this.zzz.clear();
        this.zzz.notifyDataSetChanged();
    }

    private class zza extends ArrayAdapter<zzc> {
        zza(Context var2) {
            OssLicensesMenuActivity.this.zzo;
            int var10002 = com.google.android.gms.oss.licenses.zzc.zza(OssLicensesMenuActivity.this.zzp);
            OssLicensesMenuActivity.this.zzo;
            super(var2, var10002, com.google.android.gms.oss.licenses.zzc.zzb(OssLicensesMenuActivity.this.zzp), new ArrayList());
        }

        public final View getView(int var1, View var2, ViewGroup var3) {
            if (var2 == null) {
                OssLicensesMenuActivity.this.zzo;
                LayoutInflater var10000 = OssLicensesMenuActivity.this.getLayoutInflater();
                zze var6 = OssLicensesMenuActivity.this.zzp;
                LayoutInflater var4 = var10000;
                XmlResourceParser var7 = var6.zzg.getXml(com.google.android.gms.oss.licenses.zzc.zza(var6));
                var2 = var4.inflate(var7, var3, false);
            }

            OssLicensesMenuActivity.this.zzo;
            ((TextView)var2.findViewById(com.google.android.gms.oss.licenses.zzc.zzb(OssLicensesMenuActivity.this.zzp))).setText(((zzc)this.getItem(var1)).toString());
            return var2;
        }
    }
}

只需对 "OssLicensesActivity" 执行与清单中对 "OssLicensesMenuActivity" 相同的操作:

    <activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
            android:theme="@style/LicensesTheme" />

这应该是 "second activity that displays the licence" 的样式。