Skip to content

Commit

Permalink
Applicationクラスを継承して、データの共有をする。
Browse files Browse the repository at this point in the history
  • Loading branch information
ragecolor.5884 committed Dec 25, 2010
1 parent 2c2c9ce commit ba296f5
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ApplicationClassTest/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>
33 changes: 33 additions & 0 deletions ApplicationClassTest/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ApplicationClassTest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
21 changes: 21 additions & 0 deletions ApplicationClassTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kobashin.applicationclasstest" android:versionCode="1"
android:versionName="1.0">
<!-- application属性に「android:name」属性を追加 -->
<application android:name="com.kobashin.applicationclasstest.TestApplication"
android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".Main" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Sub" android:label="@string/app_name">
</activity>

</application>
<uses-sdk android:minSdkVersion="8" />

</manifest>
Binary file not shown.
Binary file added ApplicationClassTest/bin/classes.dex
Binary file not shown.
Binary file added ApplicationClassTest/bin/resources.ap_
Binary file not shown.
11 changes: 11 additions & 0 deletions ApplicationClassTest/default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-8
Binary file added ApplicationClassTest/res/drawable-hdpi/andy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ApplicationClassTest/res/drawable-hdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ApplicationClassTest/res/drawable-ldpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ApplicationClassTest/res/drawable-mdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ApplicationClassTest/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/Layout01">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />

<Button android:text="Call Sub Activity" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
2 changes: 2 additions & 0 deletions ApplicationClassTest/res/layout/sub.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"><ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
5 changes: 5 additions & 0 deletions ApplicationClassTest/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Main!</string>
<string name="app_name">ApplicationClassTest</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.kobashin.applicationclasstest;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Main extends Activity implements OnClickListener {
private Bitmap bmp_main;
private TestApplication ta;
private Button bt;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

/* getApplication()で自己アプリケーションクラスのインスタンスを拾う */
ta = (TestApplication) this.getApplication();

bt = (Button) findViewById(R.id.Button01);
bt.setOnClickListener(this);

}

@Override
public void onClick(View v) {
if (v == bt) {
bmp_main = BitmapFactory.decodeResource(getResources(),
R.drawable.andy);

ta.setObj(bmp_main);

Intent i = new Intent();
i.setClassName("com.kobashin.applicationclasstest",
"com.kobashin.applicationclasstest.Sub");
startActivity(i);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.kobashin.applicationclasstest;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Sub extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sub);

TextView tView = new TextView(this);

/* getApplication()で自己アプリケーションクラスのインスタンスを拾う */
TestApplication ta = (TestApplication)this.getApplication();

Bitmap bmp_sub = ta.getObj();

LinearLayout lLayout = (LinearLayout)findViewById(R.id.LinearLayout01);
ImageView iView = (ImageView)findViewById(R.id.ImageView01);

iView.setImageBitmap(bmp_sub);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kobashin.applicationclasstest;

import android.app.Application;
import android.graphics.Bitmap;
import android.util.Log;

public class TestApplication extends Application {
private final String TAG = "DEBUG-APPLICATION";
private Bitmap obj;

@Override
public void onCreate() {
/** Called when the Application-class is first created. */
Log.v(TAG,"--- onCreate() in ---");
}

@Override
public void onTerminate() {
/** This Method Called when this Application finished. */
Log.v(TAG,"--- onTerminate() in ---");
}

public void setObj(Bitmap bmp){
obj = bmp;
}

public Bitmap getObj(){
return obj;
}
}

0 comments on commit ba296f5

Please sign in to comment.