Pages

Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Thursday, May 5, 2016

Android example to create grouped sub OptionsMenu


Create menu/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu
>
<item
android_id="@+id/option1"
android_orderInCategory="100"
app_showAsAction="ifRoom"
android_title="Option 1"/>
<item
android_id="@+id/option2"
android_orderInCategory="100"
app_showAsAction="never"
android_title="Option 2"/>
<item
android_id="@+id/option3"
android_orderInCategory="100"
app_showAsAction="never"
android_title="Option 3...">
<menu >
<group android_id="@+id/group3"
android_checkableBehavior="single">
<item android_id="@+id/submenu3a"
android_title="SubMenu 3A" />
<item android_id="@+id/submenu3b"
android_title="SubMenu 3B" />
</group>
</menu>

</item>
</menu>

MainActivity.java
package com.blogspot.android_er.androidoptionsmenu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.option1:
Toast.makeText(MainActivity.this, "Option 1", Toast.LENGTH_LONG).show();
return true;
case R.id.option2:
Toast.makeText(MainActivity.this, "Option 2", Toast.LENGTH_LONG).show();
return true;
case R.id.submenu3a:
Toast.makeText(MainActivity.this, "Option 3 A", Toast.LENGTH_LONG).show();
return true;
case R.id.submenu3b:
Toast.makeText(MainActivity.this, "Option 3 B", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}



Read More..

Saturday, April 30, 2016

Animated GIF Androidify for 3D Hologram viewer


Last post I tried to generate interactive animation using ObjectAnimator, to simulate 3D Hologram effect. This post I create Custom View to display animated GIF of Androidify, to simulate the effect.


The animated GIFs of Androidify are create using Googles Androidify App.  Then I have to edit the animated GIFs to resize it to 200x200, and change the background to black using GIMP. Then copy the files to drawable folder in Android Studio project.

Create a custom view, GifView, to handle the animated GIF. If you are looking for display animated GIF, refer "Play animated GIF using android.graphics.Movie, with Movie.decodeStream(InputStream)". In this version, I have to handle src attribute from xml, such that I can display four GifView of different source.

GifView .java
package com.blogspot.android_er.androidmirror;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.view.View;

import java.io.InputStream;

public class GifView extends View {

private InputStream gifInputStream;
private Movie gifMovie;
private int movieWidth, movieHeight;
private long movieDuration;
private long mMovieStart;

public GifView(Context context) {
super(context);
init(context, null);
}

public GifView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}

public GifView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}

private void init(Context context, AttributeSet attrs){
setFocusable(true);

//Handle src attribute from xml
if(attrs == null){
gifInputStream = context.getResources().openRawResource(R.drawable.androidify1b);
}else{
int src_id = attrs.getAttributeResourceValue(
"http://schemas.android.com/apk/res/android",
"src",
R.drawable.androidify1b);
gifInputStream = context.getResources().openRawResource(src_id);
}

gifMovie = Movie.decodeStream(gifInputStream);
movieWidth = gifMovie.width();
movieHeight = gifMovie.height();
movieDuration = gifMovie.duration();
}

@Override
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
setMeasuredDimension(movieWidth, movieHeight);
}

public int getMovieWidth(){
return movieWidth;
}

public int getMovieHeight(){
return movieHeight;
}

public long getMovieDuration(){
return movieDuration;
}

@Override
protected void onDraw(Canvas canvas) {

long now = android.os.SystemClock.uptimeMillis();
if (mMovieStart == 0) { // first time
mMovieStart = now;
}

if (gifMovie != null) {

int dur = gifMovie.duration();
if (dur == 0) {
dur = 1000;
}

int relTime = (int)((now - mMovieStart) % dur);

gifMovie.setTime(relTime);

gifMovie.draw(canvas, 0, 0);
invalidate();

}

}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout


android_layout_width="match_parent"
android_layout_height="match_parent"
android_padding="16dp"
android_background="@android:color/black"
tools_context=".MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold"
android_layout_alignParentTop="true"/>

<GridLayout
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_columnCount="3"
android_layout_centerInParent="true">
<ImageView
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>
<com.blogspot.android_er.androidmirror.GifView
android_id="@+id/image2"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_src="@drawable/androidify1b"
android_layout_gravity="center"/>
<ImageView
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>
<com.blogspot.android_er.androidmirror.GifView
android_id="@+id/image4"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_src="@drawable/androidify2b"
android_layout_gravity="center"
android_rotation="270"/>
<ImageView
android_layout_width="20mm"
android_layout_height="20mm"/>
<com.blogspot.android_er.androidmirror.GifView
android_id="@+id/image6"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_src="@drawable/androidify3b"
android_layout_gravity="center"
android_rotation="90"/>
<ImageView
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>
<com.blogspot.android_er.androidmirror.GifView
android_id="@+id/image8"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_src="@drawable/androidify4b"
android_layout_gravity="center"
android_rotation="180"/>
<ImageView
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>

</GridLayout>
</RelativeLayout>


Edit AndroidManifest.xml to disable hardwareAccelerated by setting it false.
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.blogspot.android_er.androidmirror" >

<application
android_allowBackup="true"
android_icon="@mipmap/ic_launcher"
android_label="@string/app_name"
android_supportsRtl="true"
android_theme="@style/AppTheme" >
<activity android_name=".MainActivity"
android_hardwareAccelerated="false">
<intent-filter>
<action android_name="android.intent.action.MAIN" />

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

</manifest>


Nothing do on MainActivity.java
package com.blogspot.android_er.androidmirror;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

}



download filesDownload the files (Android Studio Format) .

download filesDownload APK .


If you have a DIY 3D Hologram Projector, you can view the test view at YouTube.

Read More..

Wednesday, April 20, 2016

Android 6 Essentials

Design, build, and create your own applications using the full range of features available in Android 6

Android 6 Essentials

About This Book
  • Learn how to utilize the robust features of Android 6 to design, develop, and publish better Android applications
  • Get useful guidance on creating new apps or migrating existing apps to support features such as app permissions, app links, fingerprint authentication, etc
  • A fast paced guide, packed with hands-on examples that ties all the features such as API, audio, video, camera, tab customization together under a single cover
Who This Book Is For
This book is for Android developers who are looking to move their applications into the next Android version with ease.

What You Will Learn
  • Familiarize yourself with the features of Android 6
  • Code with the new Android permissions model
  • Use apps auto backup and restore lost data automatically
  • Increase user engagement with apps through an assistant using triggers and providing contextual assistance
  • Assess and handle proper usage of the API
  • Work with Audio, Video,Camera in Android 6
  • Utilize the new features in Android for professional purposes
  • Understand and code Chromes custom tabs
In Detail
Android 6 is the latest and greatest version of the Android operating system, and comes packed with cutting edge new features for you to harness for the benefit of building better applications.

This step-by-step guide will take you through the basics of the Android Marshmallow permissions model and beyond into other crucial areas such as the Audio,Video,Camera API and Androids at work features. Learn how to create, deploy, and manage Android applications with Marshmallows API and the latest functionalities.

The combination of instructions and real-world examples will make your application deployment and testing a breeze.

Style and approach
This easy-to-follow, step-by-step tutorial provides explanations and examples to add the new Android 6 features to your skill set. Each chapter provides sequential steps and detailed information about the API, as well as best practices and testing options.

Read More..

Sunday, April 17, 2016

Create AVD using new Android Emulator in Android Studio 2 0 Preview


New Android Emulator Preview is available now, you can create AVD using new Emulator in Android Studio 2.0 Preview.

When I try it, dialog pop up with error message:
emulator: ERROR: Couldnt find crash service executable
C:UsersuserAppDataLocalAndroidsdk oolsemulator64-crash-service.exe
...
I check my system, I have emulator-crash-service.exe, not emulator64-crash-service.exe! I dont know is it a bug, or anything wrong in my setting.

updated@2015-12-13:
Seem its a bug of the new emulator in Windows. Somebody reported this issue: https://code.google.com/p/android/issues/detail?id=196629


Anyway, the emulator still can run and deploy my Hello World. This video show steps to create AVD using new Android Emulator in Android Studio 2.0 Preview; run on Windows 10 with CPU of Intel i5.


Reference:
- Android Developers Blog: Android Studio 2.0 Preview: Android Emulator
- Android Tools Project Site: Android Emulator Preview (with system requirement and update SDK)


Read More..