upload android base code part7

This commit is contained in:
August 2018-08-08 18:09:17 +08:00
parent 4e516ec6ed
commit 841ae54672
25229 changed files with 1709508 additions and 0 deletions

View file

@ -0,0 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := samples
# Only compile source java files in this apk.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := ObbApp
LOCAL_SDK_VERSION := current
LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 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.example.android.obbapp">
<!-- OBBs were introduced in SDK version 9 -->
<!-- <uses-sdk android:minSdkVersion="9"/> -->
<application android:label="@string/obb_app">
<activity android:name="ObbMountActivity">
<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,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 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.
-->
<!-- This file describes the layout of the main SkeletonApp activity
user interface.
-->
<!-- The top view is a layout manager that places its child views into
a row, here set to be vertical (so the first is at the top) -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:id="@+id/mount"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/mount" />
<Button android:id="@+id/unmount"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/mount"
android:text="@string/unmount" />
<TextView android:id="@+id/status_label" android:layout_below="@+id/mount"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/status_label" />
<TextView android:id="@+id/status" android:layout_below="@+id/mount"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/status_label" />
<TextView android:id="@+id/path_label" android:layout_below="@+id/status_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/path_label" />
<TextView android:id="@+id/path" android:layout_below="@+id/status_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/path_label" />
</RelativeLayout>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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.
-->
<!-- This file contains resource definitions for displayed strings, allowing
them to be changed based on the locale and options. -->
<resources>
<string name="obb_app">Obb App</string>
<string name="mount">Mount</string>
<string name="unmount">Unmount</string>
<string name="path_label">Path:</string>
<string name="status_label">Status:</string>
<string name="obb_already_mounted">OBB already mounted!</string>
<string name="obb_not_mounted">OBB is not mounted!</string>
<string name="failed_to_start_mount">Failed to start mount process...</string>
<string name="failed_to_start_unmount">Failed to start unmount process...</string>
<string name="attempting_mount">Attempting to mount...</string>
<string name="attempting_unmount">Attempting to unmount...</string>
</resources>

View file

@ -0,0 +1,148 @@
/*
* Copyright (C) 2010 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.example.android.obbapp;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.os.storage.OnObbStateChangeListener;
import android.os.storage.StorageManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import java.io.File;
/**
* This class provides a basic demonstration of how to manage an OBB file. It
* provides two buttons: one to mount an OBB and another to unmount an OBB. The
* main feature is that it implements an OnObbStateChangeListener which updates
* some text fields with relevant information.
*/
public class ObbMountActivity extends Activity {
private static final String TAG = "ObbMount";
private static String mObbPath;
private TextView mStatus;
private TextView mPath;
private StorageManager mSM;
/** Called with the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate our UI from its XML layout description.
setContentView(R.layout.obb_mount_activity);
// Hook up button presses to the appropriate event handler.
((Button) findViewById(R.id.mount)).setOnClickListener(mMountListener);
((Button) findViewById(R.id.unmount)).setOnClickListener(mUnmountListener);
// Text indications of current status
mStatus = (TextView) findViewById(R.id.status);
mPath = (TextView) findViewById(R.id.path);
ObbState state = (ObbState) getLastNonConfigurationInstance();
if (state != null) {
mSM = state.storageManager;
mStatus.setText(state.status);
mPath.setText(state.path);
} else {
// Get an instance of the StorageManager
mSM = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);
}
mObbPath = new File(Environment.getExternalStorageDirectory(), "test1.obb").getPath();
}
OnObbStateChangeListener mEventListener = new OnObbStateChangeListener() {
@Override
public void onObbStateChange(String path, int state) {
Log.d(TAG, "path=" + path + "; state=" + state);
mStatus.setText(String.valueOf(state));
if (state == OnObbStateChangeListener.MOUNTED) {
mPath.setText(mSM.getMountedObbPath(mObbPath));
} else {
mPath.setText("");
}
}
};
/**
* A call-back for when the user presses the back button.
*/
OnClickListener mMountListener = new OnClickListener() {
public void onClick(View v) {
try {
// We don't need to synchronize here to avoid clobbering the
// content of mStatus because the callback comes to our main
// looper.
if (mSM.mountObb(mObbPath, null, mEventListener)) {
mStatus.setText(R.string.attempting_mount);
} else {
mStatus.setText(R.string.failed_to_start_mount);
}
} catch (IllegalArgumentException e) {
mStatus.setText(R.string.obb_already_mounted);
Log.d(TAG, "OBB already mounted");
}
}
};
/**
* A call-back for when the user presses the clear button.
*/
OnClickListener mUnmountListener = new OnClickListener() {
public void onClick(View v) {
try {
if (mSM.unmountObb(mObbPath, false, mEventListener)) {
mStatus.setText(R.string.attempting_unmount);
} else {
mStatus.setText(R.string.failed_to_start_unmount);
}
} catch (IllegalArgumentException e) {
mStatus.setText(R.string.obb_not_mounted);
Log.d(TAG, "OBB not mounted");
}
}
};
@Override
public Object onRetainNonConfigurationInstance() {
// Since our OBB mount is tied to the StorageManager, retain it
ObbState state = new ObbState(mSM, mStatus.getText(), mPath.getText());
return state;
}
private static class ObbState {
public StorageManager storageManager;
public CharSequence status;
public CharSequence path;
ObbState(StorageManager storageManager, CharSequence status, CharSequence path) {
this.storageManager = storageManager;
this.status = status;
this.path = path;
}
}
}