Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
totemtec committed Apr 23, 2015
0 parents commit 2df0721
Show file tree
Hide file tree
Showing 985 changed files with 77,668 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.gradle
/local.properties
.DS_Store
/build
*.iml
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.example.android.apis"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\develop\ASAndroidSDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
3,151 changes: 3,151 additions & 0 deletions app/src/main/AndroidManifest.xml

Large diffs are not rendered by default.

Binary file added app/src/main/assets/HelloActivity.apk
Binary file not shown.
Binary file added app/src/main/assets/fonts/samplefont.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions app/src/main/assets/read_asset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This text is stored in a raw Asset.

It was read and placed into the TextView here.
150 changes: 150 additions & 0 deletions app/src/main/java/com/example/android/apis/ApiDemos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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.
*/

package com.example.android.apis;

import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ApiDemos extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();
String path = intent.getStringExtra("com.example.android.apis.Path");

if (path == null) {
path = "";
}

setListAdapter(new SimpleAdapter(this, getData(path),
android.R.layout.simple_list_item_1, new String[] { "title" },
new int[] { android.R.id.text1 }));
getListView().setTextFilterEnabled(true);
}

protected List<Map<String, Object>> getData(String prefix) {
List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_SAMPLE_CODE);

PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

if (null == list)
return myData;

String[] prefixPath;
String prefixWithSlash = prefix;

if (prefix.equals("")) {
prefixPath = null;
} else {
prefixPath = prefix.split("/");
prefixWithSlash = prefix + "/";
}

int len = list.size();

Map<String, Boolean> entries = new HashMap<String, Boolean>();

for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq != null
? labelSeq.toString()
: info.activityInfo.name;

if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {

String[] labelPath = label.split("/");

String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];

if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
addItem(myData, nextLabel, activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
} else {
if (entries.get(nextLabel) == null) {
addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}

Collections.sort(myData, sDisplayNameComparator);

return myData;
}

private final static Comparator<Map<String, Object>> sDisplayNameComparator =
new Comparator<Map<String, Object>>() {
private final Collator collator = Collator.getInstance();

public int compare(Map<String, Object> map1, Map<String, Object> map2) {
return collator.compare(map1.get("title"), map2.get("title"));
}
};

protected Intent activityIntent(String pkg, String componentName) {
Intent result = new Intent();
result.setClassName(pkg, componentName);
return result;
}

protected Intent browseIntent(String path) {
Intent result = new Intent();
result.setClass(this, ApiDemos.class);
result.putExtra("com.example.android.apis.Path", path);
return result;
}

protected void addItem(List<Map<String, Object>> data, String name, Intent intent) {
Map<String, Object> temp = new HashMap<String, Object>();
temp.put("title", name);
temp.put("intent", intent);
data.add(temp);
}

@Override
@SuppressWarnings("unchecked")
protected void onListItemClick(ListView l, View v, int position, long id) {
Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);

Intent intent = new Intent((Intent) map.get("intent"));
intent.addCategory(Intent.CATEGORY_SAMPLE_CODE);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/

package com.example.android.apis;

import android.app.Application;

/**
* This is an example of a {@link android.app.Application} class. This can
* be used as a central repository for per-process information about your app;
* however it is recommended to use singletons for that instead rather than merge
* all of these globals from across your application into one place here.
*
* In this case, we have not defined any specific work for this Application.
*
* See samples/ApiDemos/tests/src/com.example.android.apis/ApiDemosApplicationTests for an example
* of how to perform unit tests on an Application object.
*/
public class ApiDemosApplication extends Application {
@Override
public void onCreate() {
}
}
Loading

0 comments on commit 2df0721

Please sign in to comment.