Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates

  • Loading branch information...
commit 7d4f2bf999a9b93cbc29ba33565bfd7b63f6ea49 1 parent 648b5e5
@vogella vogella authored
Showing with 427 additions and 164 deletions.
  1. +8 −0 aaa.test/.classpath
  2. +33 −0 aaa.test/.project
  3. +23 −0 aaa.test/AndroidManifest.xml
  4. +20 −0 aaa.test/proguard-project.txt
  5. +14 −0 aaa.test/project.properties
  6. BIN  aaa.test/res/drawable-hdpi/ic_launcher.png
  7. BIN  aaa.test/res/drawable-ldpi/ic_launcher.png
  8. BIN  aaa.test/res/drawable-mdpi/ic_launcher.png
  9. BIN  aaa.test/res/drawable-xhdpi/ic_launcher.png
  10. +12 −0 aaa.test/res/layout/main.xml
  11. +7 −0 aaa.test/res/values/strings.xml
  12. +13 −0 aaa.test/src/aaa/test/RSSFeedProvider.java
  13. +12 −0 aaa.test/src/aaa/test/RssFeedActivity.java
  14. +45 −0 aaa.test/src/aaa/test/RssItem.java
  15. +2 −2 com.example.android.rssfeed/proguard.cfg
  16. +12 −3 com.example.android.rssfeed/src/com/example/android/rssfeed/RssItem.java
  17. +20 −8 de.vogella.android.imagepick/res/layout/main.xml
  18. +10 −5 de.vogella.android.imagepick/src/de/vogella/android/imagepick/ImagePickActivity.java
  19. +39 −0 de.vogella.android.socialapp/res/layout/main_full.xml
  20. +7 −1 de.vogella.android.socialapp/res/menu/mainmenu.xml
  21. +11 −135 de.vogella.android.socialapp/src/de/vogella/android/socialapp/OverviewActivity.java
  22. +1 −1  de.vogella.android.touch/project.properties
  23. +6 −0 de.vogella.android.touch/res/menu/mymenu.xml
  24. +4 −1 de.vogella.android.touch/src/de/vogella/android/touch/TouchEventView.java
  25. +64 −0 de.vogella.android.touch/src/de/vogella/android/touch/TouchEventViewWithImage.java
  26. +64 −8 de.vogella.android.touch/src/de/vogella/android/touch/WriteOnScreenActivity.java
View
8 aaa.test/.classpath
@@ -0,0 +1,8 @@
+<?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="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 aaa.test/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>aaa.test</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>
View
23 aaa.test/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="aaa.test"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="15" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".RssFeedActivity"
+ 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>
View
20 aaa.test/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/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 *;
+#}
View
14 aaa.test/project.properties
@@ -0,0 +1,14 @@
+# 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 edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=Google Inc.:Google APIs:15
View
BIN  aaa.test/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  aaa.test/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  aaa.test/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  aaa.test/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 aaa.test/res/layout/main.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+
+</LinearLayout>
View
7 aaa.test/res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, MainActivity!</string>
+ <string name="app_name">Aaa.test</string>
+
+</resources>
View
13 aaa.test/src/aaa/test/RSSFeedProvider.java
@@ -0,0 +1,13 @@
+package aaa.test;
+
+import java.util.List;
+
+public class RSSFeedProvider {
+ public static List<RssItem> parse(String rssFeed) {
+ // TODO1 Create a list instance, e.g. ArrayList
+ // TODO2 Create RssItem instances, fill them with data
+ // and add them to the list
+ // TODO3 return your list instead of null
+ return null;
+ }
+}
View
12 aaa.test/src/aaa/test/RssFeedActivity.java
@@ -0,0 +1,12 @@
+package aaa.test;
+
+import android.app.ListActivity;
+import android.os.Bundle;
+
+public class RssFeedActivity extends ListActivity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+}
View
45 aaa.test/src/aaa/test/RssItem.java
@@ -0,0 +1,45 @@
+package aaa.test;
+
+public class RssItem {
+ private String pubDate;
+ private String description;
+ private String link;
+ private String title;
+
+ public String getPubDate() {
+ return pubDate;
+ }
+
+ public void setPubDate(String pubDate) {
+ this.pubDate = pubDate;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public void setLink(String link) {
+ this.link = link;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String toString() {
+ return "RssItem [title=" + title + "]";
+ }
+}
View
4 com.example.android.rssfeed/proguard.cfg
@@ -18,11 +18,11 @@
native <methods>;
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
View
15 com.example.android.rssfeed/src/com/example/android/rssfeed/RssItem.java
@@ -2,36 +2,45 @@
public class RssItem {
private String pubDate;
- private String description;
+ private String description;
private String link;
private String title;
+
public String getPubDate() {
return pubDate;
}
+
public void setPubDate(String pubDate) {
this.pubDate = pubDate;
}
+
public String getDescription() {
return description;
}
+
public void setDescription(String description) {
this.description = description;
}
+
public String getLink() {
return link;
}
+
public void setLink(String link) {
this.link = link;
}
+
public String getTitle() {
return title;
}
+
public void setTitle(String title) {
this.title = title;
}
-
+
@Override
public String toString() {
- return title;
+ return "RssItem [title=" + title + "]";
}
+
}
View
28 de.vogella.android.imagepick/res/layout/main.xml
@@ -1,10 +1,22 @@
<?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">
- <Button android:text="Button" android:id="@+id/button1"
- android:onClick="pickImage" android:layout_width="wrap_content"
- android:layout_height="wrap_content"></Button>
- <ImageView android:id="@+id/result" android:src="@drawable/icon"
- android:layout_width="match_parent" android:layout_height="match_parent"></ImageView>
-</LinearLayout>
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/button1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="pickImage"
+ android:text="Button" >
+ </Button>
+
+ <ImageView
+ android:id="@+id/result"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:src="@drawable/icon" >
+ </ImageView>
+
+</LinearLayout>
View
15 de.vogella.android.imagepick/src/de/vogella/android/imagepick/ImagePickActivity.java
@@ -35,21 +35,26 @@ public void pickImage(View View) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ InputStream stream = null;
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
try {
// We need to recyle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
- InputStream stream = getContentResolver().openInputStream(
- data.getData());
+ stream = getContentResolver().openInputStream(data.getData());
bitmap = BitmapFactory.decodeStream(stream);
- stream.close();
+
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ } finally {
+ if (stream != null)
+ try {
+ stream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
super.onActivityResult(requestCode, resultCode, data);
}
View
39 de.vogella.android.socialapp/res/layout/main_full.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ style="?android:attr/buttonBarStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/Button01"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Show" />
+
+ <Button
+ android:id="@+id/Button02"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Change" />
+ </LinearLayout>
+
+ <EditText
+ android:id="@+id/myView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10" >
+
+ <requestFocus />
+ </EditText>
+
+</LinearLayout>
View
8 de.vogella.android.socialapp/res/menu/mainmenu.xml
@@ -2,8 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
- android:id="@+id/preferences"
+ android:id="@+id/menuitem1"
+ android:showAsAction="ifRoom"
android:title="Prefs">
</item>
+ <item
+ android:id="@+id/menuitem2"
+ android:showAsAction="ifRoom"
+ android:title="Test">
+ </item>
</menu>
View
146 de.vogella.android.socialapp/src/de/vogella/android/socialapp/OverviewActivity.java
@@ -1,166 +1,42 @@
package de.vogella.android.socialapp;
import android.app.Activity;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.util.Log;
-import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.Toast;
public class OverviewActivity extends Activity {
- private static final String TAG = "de.vogella.android.socialapp";
- SharedPreferences preferences;
- protected Object mActionMode;
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getActionBar().setHomeButtonEnabled(true);
setContentView(R.layout.main);
- Button button = (Button) findViewById(R.id.Button01);
- // Initialize preferences
- preferences = PreferenceManager.getDefaultSharedPreferences(this);
-
- button.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- String username = preferences.getString("username", "n/a");
- String password = preferences.getString("password", "n/a");
- showPrefs(username, password);
- }
- });
-
- Button buttonChangePreferences = (Button) findViewById(R.id.Button02);
- buttonChangePreferences.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
-
- updatePreferenceValue();
- }
- });
- // Define the contextual action mode
- View view = findViewById(R.id.myView);
- view.setOnLongClickListener(new View.OnLongClickListener() {
- // Called when the user long-clicks on someView
- public boolean onLongClick(View view) {
- if (mActionMode != null) {
- return false;
- }
-
- // Start the CAB using the ActionMode.Callback defined above
- mActionMode = OverviewActivity.this
- .startActionMode(mActionModeCallback);
- view.setSelected(true);
- return true;
- }
- });
-
- }
-
- private void showPrefs(String username, String password) {
- Toast.makeText(OverviewActivity.this,
- "Input: " + username + " and password: " + password,
- Toast.LENGTH_LONG).show();
-
- }
-
- private void updatePreferenceValue() {
- Editor edit = preferences.edit();
- String username = preferences.getString("username", "n/a");
- // We will just revert the current user name and save again
- StringBuffer buffer = new StringBuffer();
- for (int i = username.length() - 1; i >= 0; i--) {
- buffer.append(username.charAt(i));
- }
- edit.putString("username", buffer.toString());
- edit.commit();
- // A toast is a view containing a quick little message for the
- // user. We give a little feedback
- Toast.makeText(OverviewActivity.this,
- "Reverted string sequence of user name.", Toast.LENGTH_LONG)
- .show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
- // MenuItem item = menu.findItem(R.id.menu_share);
- // ShareActionProvider provider = (ShareActionProvider) item
- // .getActionProvider();
- // Intent intent = new Intent(Intent.ACTION_SEND);
- // intent.setType("plain/text");
- // intent.putExtra(Intent.EXTRA_TEXT, "Hello");
- // provider.setShareIntent(intent);
return true;
}
- // This method is called once the menu is selected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- Log.i(TAG, "OptionsMenu called");
switch (item.getItemId()) {
- case R.id.preferences:
- // Launch Preference activity
- Intent i = new Intent(OverviewActivity.this,
- MyPreferencesActivity.class);
- startActivity(i);
- // Some feedback to the user
- Toast.makeText(OverviewActivity.this,
- "Enter your user credentials.", Toast.LENGTH_LONG).show();
+ case R.id.menuitem1:
+ Toast.makeText(this, "Menu Item 1 selected", Toast.LENGTH_SHORT)
+ .show();
break;
- // If home icon is clicked return to main Activity
- case android.R.id.home:
- Intent intent = new Intent(this, OverviewActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
+ case R.id.menuitem2:
+ Toast.makeText(this, "Menu item 2 selected", Toast.LENGTH_SHORT)
+ .show();
break;
- }
- return true;
- }
-
- private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
-
- // Called when the action mode is created; startActionMode() was called
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- // Inflate a menu resource providing context menu items
- MenuInflater inflater = mode.getMenuInflater();
- // Assumes that you have "contexual.xml" menu resources
- inflater.inflate(R.menu.contextual, menu);
- return true;
- }
-
- // Called each time the action mode is shown. Always called after
- // onCreateActionMode, but
- // may be called multiple times if the mode is invalidated.
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false; // Return false if nothing is done
- }
-
- // Called when the user selects a contextual menu item
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- switch (item.getItemId()) {
- case R.id.toast:
- Toast.makeText(OverviewActivity.this, "Selected menu",
- Toast.LENGTH_LONG).show();
- mode.finish(); // Action picked, so close the
- return true;
- default:
- return false;
- }
- }
- // Called when the user exits the action mode
- public void onDestroyActionMode(ActionMode mode) {
- mActionMode = null;
+ default:
+ break;
}
- };
-}
+ return true;
+ }
+}
View
2  de.vogella.android.touch/project.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-14
+target=android-15
View
6 de.vogella.android.touch/res/menu/mymenu.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:id="@+id/pickimage" android:showAsAction="ifRoom" android:title="Pick"></item>
+
+
+</menu>
View
5 de.vogella.android.touch/src/de/vogella/android/touch/TouchEventView.java
@@ -5,6 +5,7 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -12,6 +13,7 @@
public class TouchEventView extends View {
private Paint paint = new Paint();
private Path path = new Path();
+ private Point point = new Point();
public TouchEventView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -26,6 +28,7 @@ public TouchEventView(Context context, AttributeSet attrs) {
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
+ canvas.drawCircle((float) point.x, (float) point.y, 100, paint);
}
@Override
@@ -35,6 +38,7 @@ public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(x, y);
+ point.set((int) x, (int) y);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(x, y);
@@ -45,5 +49,4 @@ public boolean onTouchEvent(MotionEvent event) {
invalidate();
return true;
}
-
}
View
64 de.vogella.android.touch/src/de/vogella/android/touch/TouchEventViewWithImage.java
@@ -0,0 +1,64 @@
+package de.vogella.android.touch;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.Point;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class TouchEventViewWithImage extends View {
+ private Paint paint = new Paint();
+ private Path path = new Path();
+ private Point point = new Point();
+ private Bitmap bitmap;
+
+ public TouchEventViewWithImage(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ paint.setAntiAlias(true);
+ paint.setColor(Color.WHITE);
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setStrokeJoin(Paint.Join.ROUND);
+ paint.setStrokeWidth(5f);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (bitmap != null) {
+ canvas.drawBitmap(bitmap, new Matrix(), null);
+ }
+ canvas.drawPath(path, paint);
+ canvas.drawCircle((float) point.x, (float) point.y, 100, paint);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ float x = event.getX();
+ float y = event.getY();
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ path.moveTo(x, y);
+ point.set((int) x, (int) y);
+ return true;
+ case MotionEvent.ACTION_MOVE:
+ path.lineTo(x, y);
+ break;
+ default:
+ return false;
+ }
+ invalidate();
+ return true;
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ this.bitmap = bitmap;
+ invalidate();
+ }
+
+}
View
72 de.vogella.android.touch/src/de/vogella/android/touch/WriteOnScreenActivity.java
@@ -1,22 +1,78 @@
package de.vogella.android.touch;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
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.view.Window;
-import android.view.WindowManager;
+import android.view.Menu;
public class WriteOnScreenActivity extends Activity {
- /** Called when the activity is first created. */
+ Bitmap bitmap;
+ private TouchEventViewWithImage view;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- setContentView(new TouchEventView(this, null));
+ view = new TouchEventViewWithImage(this, null);
+ setContentView(view);
System.out.println("This is a log message");
Log.e("Mein Tag", "Hello");
}
+
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.mymenu, menu);
+ return true;
+ };
+
+ public boolean onOptionsItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.pickimage:
+ Intent intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ startActivityForResult(intent, 10);
+ break;
+
+ default:
+ break;
+ }
+ return false;
+ };
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ InputStream stream = null;
+ if (resultCode == RESULT_OK && requestCode == 10) {
+ if (bitmap != null) {
+ view.setBitmap(null);
+ bitmap.recycle();
+ }
+
+ try {
+ stream = getContentResolver().openInputStream(data.getData());
+ bitmap = BitmapFactory.decodeStream(stream);
+ view.setBitmap(bitmap);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ }
+ };
}
Please sign in to comment.
Something went wrong with that request. Please try again.