upload android base code part1

This commit is contained in:
August 2018-08-08 15:50:00 +08:00
parent e02f198e2d
commit 0a1de6c4b3
48159 changed files with 9071466 additions and 0 deletions

View file

@ -0,0 +1,16 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_AAPT_FLAGS := --shared-lib
LOCAL_PACKAGE_NAME := SharedLibrary
LOCAL_EXPORT_PACKAGE_RESOURCES := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_FLAG_FILES := proguard.proguard
include $(BUILD_PACKAGE)

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.test.shared_library"
android:versionCode="2">
<application android:label="SharedLibrary">
<library android:name="com.google.android.test.shared_library" />
<activity android:name="ActivityMain"
android:icon="@drawable/size_48x48">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,7 @@
-keepparameternames
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * {
public protected *;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/cityStateZip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</merge>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AddressView">
<attr name="name" format="string" />
<attr name="streetNumber" format="integer" />
<attr name="streetName" format="string" />
<attr name="city" format="string" />
<attr name="state" format="string" />
<attr name="zip" format="string" />
<attr name="country" format="string" />
</declare-styleable>
</resources>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<public type="string" name="shared_string" id="0x00020003" />
<public type="style" name="CodeFont" id="0x00040000" />
<public type="style" name="Theme" id="0x00040001" />
<public type="attr" name="name" id="0x00010000" />
<public type="attr" name="streetNumber" id="0x00010001" />
<public type="attr" name="streetName" id="0x00010002" />
<public type="attr" name="city" id="0x00010003" />
<public type="attr" name="state" id="0x00010004" />
<public type="attr" name="zip" id="0x00010005" />
<public type="attr" name="country" id="0x00010006" />
<public type="drawable" name="size_48x48" id="0x00030000" />
<public type="array" name="animals" id="0x00050000" />
</resources>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="upgrade_title">Upgrade required</string>
<string name="upgrade_body"><xliff:g id="app">%1$s</xliff:g> requires a newer version
of <xliff:g id="lib">%2$s</xliff:g> to run.</string>
<string name="upgrade_button">Upgrade</string>
<string name="shared_string">Shared string!</string>
<string-array name="animals">
<item>@string/racoon</item>
<item>Rhino</item>
<item>Elephant</item>
</string-array>
<string name="racoon">Racoon</string>
</resources>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
<style name="Theme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/orange</item>
</style>
<color name="orange">#f0ad4e</color>
</resources>

View file

@ -0,0 +1,32 @@
/*
* Copyright (C) 2013 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.google.android.test.shared_library;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ActivityMain extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView content = new TextView(this);
content.setText("Dummy main entry for this apk; not really needed...");
setContentView(content);
}
}

View file

@ -0,0 +1,44 @@
package com.google.android.test.shared_library;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AddressView extends LinearLayout {
private TextView mNameView;
private TextView mStreetView;
private TextView mCityStateZipView;
private TextView mCountryView;
public AddressView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
View view = LayoutInflater.from(context).inflate(R.layout.address, this);
mNameView = (TextView) view.findViewById(R.id.name);
mStreetView = (TextView) view.findViewById(R.id.street);
mCityStateZipView = (TextView) view.findViewById(R.id.cityStateZip);
mCountryView = (TextView) view.findViewById(R.id.country);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.AddressView,
0, 0);
try {
mNameView.setText(a.getString(R.styleable.AddressView_name));
int streetNumber = a.getInteger(R.styleable.AddressView_streetNumber, -1);
mStreetView.setText((streetNumber <= 0 ? "" : Integer.toString(streetNumber)) +
" " + a.getString(R.styleable.AddressView_streetName));
mCityStateZipView.setText(a.getString(R.styleable.AddressView_city) + ", " +
a.getString(R.styleable.AddressView_state) + " " +
a.getString(R.styleable.AddressView_zip));
mCountryView.setText(a.getString(R.styleable.AddressView_country));
} finally {
a.recycle();
}
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (C) 2013 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.google.android.test.shared_library;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
public class SharedLibraryMain {
static String LIBRARY_PACKAGE = "com.google.android.test.shared_library";
/**
* Base version of the library.
*/
public static int VERSION_BASE = 1;
/**
* The second version of the library.
*/
public static int VERSION_SECOND = 2;
/**
* Return the version number of the currently installed library.
*/
public static int getVersion(Context context) {
PackageInfo pi = null;
try {
pi = context.getPackageManager().getPackageInfo(LIBRARY_PACKAGE, 0);
return pi.versionCode;
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException("Can't find my package!", e);
}
}
/**
* Check that the library's version is at least the given minimum version,
* displaying a dialog to have the user install an update if that is not true.
* The dialog is displayed as a DialogFragment in your activity if a newer
* version is needed. If a newer version is needed, false is returned.
*/
public static boolean ensureVersion(final Activity activity, int minVersion) {
final FragmentManager fm = activity.getFragmentManager();
final String dialogTag = LIBRARY_PACKAGE + ":version";
Fragment curDialog = fm.findFragmentByTag(dialogTag);
if (getVersion(activity) >= minVersion) {
// Library version is sufficient. Make sure any version dialog
// we had shown is removed before returning.
if (curDialog != null) {
fm.beginTransaction().remove(curDialog).commitAllowingStateLoss();
}
return true;
}
// The current version of the library does not meet the required version.
// If we don't already have a version dialog displayed, display it now.
if (curDialog == null) {
curDialog = new VersionDialog();
fm.beginTransaction().add(curDialog, dialogTag).commitAllowingStateLoss();
}
// Tell the caller that the current version is not sufficient.
return false;
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (C) 2013 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.google.android.test.shared_library;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
/**
* This is the dialog we show when the library's version is older than
* the version the app needs.
*/
public class VersionDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity activity = getActivity();
// Need to use our library's resources for showing the dialog.
final Context context;
try {
context = activity.createPackageContext(SharedLibraryMain.LIBRARY_PACKAGE, 0);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException("Can't find my package!", e);
}
final Resources res = context.getResources();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(res.getText(R.string.upgrade_title));
builder.setMessage(res.getString(R.string.upgrade_body,
activity.getApplicationInfo().loadLabel(activity.getPackageManager()),
context.getApplicationInfo().loadLabel(context.getPackageManager())));
builder.setPositiveButton(res.getText(R.string.upgrade_button),
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Launch play store into the details of our app.
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id="
+ SharedLibraryMain.LIBRARY_PACKAGE)));
} catch (android.content.ActivityNotFoundException anfe) {
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id="
+ SharedLibraryMain.LIBRARY_PACKAGE)));
}
}
});
return builder.create();
}
}