Animated Gif (Androidify) For 3D Hologram Viewer

Posted on


Last postal service I tried to generate interactive animation using ObjectAnimator, to copy 3D Hologram effect. This postal service I job Custom View to display animated GIF of Androidify, to copy the effect.

The animated GIFs of Androidify are job using edit the animated GIFs to resize it to 200×200, as well as modify the background to dark using GIMP. Then re-create the files to drawable folder inward Android Studio project.

Create a custom view, GifView, to grip the animated GIF. If y’all are looking for display animated GIF, refer “Play animated GIF using android.graphics.Movie, amongst Movie.decodeStream(InputStream)”. In this version, I bring to handle src attribute from xml, such that I tin dismiss display 4 GifView of unlike 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;  world cast GifView extends View {      somebody InputStream gifInputStream;     somebody Movie gifMovie;     somebody int movieWidth, movieHeight;     somebody long movieDuration;     somebody long mMovieStart;      world GifView(Context context) {         super(context);         init(context, null);     }      world GifView(Context context, AttributeSet attrs) {         super(context, attrs);         init(context, attrs);     }      world GifView(Context context, AttributeSet attrs,                    int defStyleAttr) {         super(context, attrs, defStyleAttr);         init(context, attrs);     }      somebody 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);     }      world int getMovieWidth(){         provide movieWidth;     }      world int getMovieHeight(){         provide movieHeight;     }      world long getMovieDuration(){         provide movieDuration;     }      @Override     protected void onDraw(Canvas canvas) {          long right away = android.os.SystemClock.uptimeMillis();         if (mMovieStart == 0) {   // rootage fourth dimension             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     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: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="https://rootandroid.org//"         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 past times setting it false.

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     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 job on MainActivity.java

package com.blogspot.android_er.androidmirror;  import android.os.Bundle; import android.support.v7.app.AppCompatActivity;  world cast MainActivity extends AppCompatActivity {      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);     }  }  

 This postal service I job Custom View to display animated GIF of Androidify Animated GIF (Androidify) for 3D Hologram viewerDownload the files (Android Studio Format) .

 This postal service I job Custom View to display animated GIF of Androidify Animated GIF (Androidify) for 3D Hologram viewerDownload APK .


If y’all bring a DIY 3D Hologram Projector, y’all tin dismiss sentiment the test sentiment at YouTube.