Skip to content

Commit

Permalink
Init project, custom Inflater and ContextWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjenx committed Dec 20, 2013
0 parents commit 5b9dbd9
Show file tree
Hide file tree
Showing 36 changed files with 658 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .gitignore
@@ -0,0 +1,44 @@
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties
/local.properties

# Eclipse
.classpath
.project
.settings

# Android Studio (InteliJ)
.idea/
/.idea/workspace.xml
*.iml
*.iws
*.ipr
/*/out
/*/build
/*/*/production

#Gradle
.gradletasknamecache
.gradle/
build/
bin/

#Crashlytics
com_crashlytics_export_strings.xml

#OSx
.DS_Store
1 change: 1 addition & 0 deletions CalligraphySample/.gitignore
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions CalligraphySample/build.gradle
@@ -0,0 +1,35 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile project(':calligraphy')
}
17 changes: 17 additions & 0 deletions CalligraphySample/proguard-rules.txt
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Developer/android-sdk-osx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# 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 *;
#}
21 changes: 21 additions & 0 deletions CalligraphySample/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.chrisjenx.calligraphy.sample" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="uk.co.chrisjenx.calligraphy.sample.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added CalligraphySample/src/main/ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,48 @@
package uk.co.chrisjenx.calligraphy.sample;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(new CalligraphyContextWrapper(newBase));
}

/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}

}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions CalligraphySample/src/main/res/layout/activity_main.xml
@@ -0,0 +1,8 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="uk.co.chrisjenx.calligraphy.sample.MainActivity"
tools:ignore="MergeRootFrame"/>
16 changes: 16 additions & 0 deletions CalligraphySample/src/main/res/layout/fragment_main.xml
@@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="uk.co.chrisjenx.calligraphy.sample.MainActivity$PlaceholderFragment">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>
9 changes: 9 additions & 0 deletions CalligraphySample/src/main/res/menu/main.xml
@@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="uk.co.chrisjenx.calligraphy.sample.MainActivity" >

<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
6 changes: 6 additions & 0 deletions CalligraphySample/src/main/res/values-w820dp/dimens.xml
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions CalligraphySample/src/main/res/values/dimens.xml
@@ -0,0 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>
8 changes: 8 additions & 0 deletions CalligraphySample/src/main/res/values/strings.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">My Module</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
8 changes: 8 additions & 0 deletions CalligraphySample/src/main/res/values/styles.xml
@@ -0,0 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

</resources>
1 change: 1 addition & 0 deletions build.gradle
@@ -0,0 +1 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1 change: 1 addition & 0 deletions calligraphy/.gitignore
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions calligraphy/build.gradle
@@ -0,0 +1,38 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

dependencies {
compile 'com.android.support:appcompat-v7:+'
}
17 changes: 17 additions & 0 deletions calligraphy/proguard-rules.txt
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Developer/android-sdk-osx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# 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 *;
#}
10 changes: 10 additions & 0 deletions calligraphy/src/main/AndroidManifest.xml
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.chrisjenx.calligraphy">

<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">

</application>

</manifest>
@@ -0,0 +1,30 @@
package uk.co.chrisjenx.calligraphy;

import android.content.Context;
import android.content.ContextWrapper;
import android.view.LayoutInflater;

/**
* Created by chris on 19/12/2013
* Project: Calligraphy
*/
public class CalligraphyContextWrapper extends ContextWrapper {

private LayoutInflater mInflater;

public CalligraphyContextWrapper(Context base) {
super(base);
}

@Override
public Object getSystemService(String name) {
if (LAYOUT_INFLATER_SERVICE.equals(name)) {
if (mInflater == null) {
mInflater = new CalligraphyLayoutInflater(LayoutInflater.from(getBaseContext()), this);
}
return mInflater;
}
return super.getSystemService(name);
}

}
@@ -0,0 +1,52 @@
package uk.co.chrisjenx.calligraphy;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

/**
* Created by chris on 19/12/2013
* Project: Calligraphy
*/
public class CalligraphyLayoutInflater extends LayoutInflater {
private static final String[] sClassPrefixList = {
"android.widget.",
"android.webkit."
};

protected CalligraphyLayoutInflater(Context context) {
super(context);
}

protected CalligraphyLayoutInflater(LayoutInflater original, Context newContext) {
super(original, newContext);
}

/**
* Override onCreateView to instantiate names that correspond to the
* widgets known to the Widget factory. If we don't find a match,
* call through to our super class.
*/
@Override
protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException {
for (String prefix : sClassPrefixList) {
try {
View view = createView(name, prefix, attrs);
if (view != null) {
return view;
}
} catch (ClassNotFoundException e) {
// In this case we want to let the base class take a crack
// at it.
}
}

return super.onCreateView(name, attrs);
}

@Override
public LayoutInflater cloneInContext(Context newContext) {
return new CalligraphyLayoutInflater(this, newContext);
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5b9dbd9

Please sign in to comment.