Tuesday, March 29, 2016

Issue with circular reveal and CircularRevealLibrary in Android

Leave a Comment

I was following this tutorial to the "T" but when I run the app I get the following message in the logcat. I'm not sure what is going wrong because the class should be there right?

Could not find method android.view.ViewAnimationUtils.createCircularReveal, referenced from method io.codetail.animation.ViewAnimationUtils.createCircularReveal

MainActivity:

    import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.app.ProgressDialog; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; import android.widget.AdapterView; import android.widget.Filter; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ListView;  import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonArrayRequest; import com.curtrostudios.testapp.network.AppConfig;  import org.json.JSONArray; import org.json.JSONException;  import java.util.ArrayList; import io.codetail.animation.SupportAnimator; import io.codetail.animation.ViewAnimationUtils;   /**  * Created by CurTro Studios on 2/22/2016.  */ public class MainActivity extends AppCompatActivity implements View.OnClickListener{     private ProgressDialog dialog=null ;     private String TAG="Main Activity";     private String tag_json_arry = "json_array_req";     private ProductsAdapter adapter;     private ListView list;     ArrayList<ProductRowData> rowdata;     private SearchView searchView;     private MenuItem myActionMenuItem;     LinearLayout mRevealView;     boolean hidden = true;     private ImageButton gallery_btn, photo_btn, video_btn, audio_btn, location_btn, contact_btn;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);         setSupportActionBar(toolbar);          mRevealView = (LinearLayout) findViewById(R.id.reveal_items);         mRevealView.setVisibility(View.GONE);          gallery_btn = (ImageButton) findViewById(R.id.login_img_btn);         photo_btn = (ImageButton) findViewById(R.id.info_img_btn);         video_btn = (ImageButton) findViewById(R.id.share_img_btn);         audio_btn = (ImageButton) findViewById(R.id.sortAtoZ);         location_btn = (ImageButton) findViewById(R.id.sortDate);         contact_btn = (ImageButton) findViewById(R.id.sortRegion);          gallery_btn.setOnClickListener(this);         photo_btn.setOnClickListener(this);         video_btn.setOnClickListener(this);         audio_btn.setOnClickListener(this);         location_btn.setOnClickListener(this);         contact_btn.setOnClickListener(this);          list=(ListView)findViewById(R.id.productList);         list.setTextFilterEnabled(true);         list.setOnItemClickListener(new AdapterView.OnItemClickListener() {             @Override             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                 //Get item at position                 ProductRowData item = (ProductRowData)parent.getItemAtPosition(position);                  //Pass the image title and url to DetailsActivity                 Intent intent = new Intent(MainActivity.this, ProductDetail.class);                 intent.putExtra("sid", item.getSID());                 intent.putExtra("name", item.getName());                 intent.putExtra("image", item.getImageURL());                 intent.putExtra("thumb", item.getThumbURL());                 intent.putExtra("description", item.getDescription());                 intent.putExtra("rating", item.getRating());                  //Start details activity                 startActivity(intent);             }         });         rowdata=new ArrayList<ProductRowData>();          dialog= new ProgressDialog(this);          dialog.setMessage("Loading...");         dialog.show();          JsonArrayRequest request = new JsonArrayRequest(AppConfig.URL_MAIN,                 new Response.Listener<JSONArray>() {                     @Override                     public void onResponse(JSONArray response) {                         Log.d(TAG, response.toString()); try {                             for(int i=0;i<response.length();i++){                                 String sid=response.getJSONObject(i).getString("sid");                                 String name=response.getJSONObject(i).getString("product_name");                                 String img;                                 String thumb = response.getJSONObject(i).getString("product_thumb");                                 String description = response.getJSONObject(i).getString("product_description");                                 String rating = response.getJSONObject(i).getString("product_rating");                                  img = response.getJSONObject(i).getString("product_pic");                                  rowdata.add(new ProductRowData(sid,name,img,thumb,description,rating));                             }                         } catch (JSONException e) {                             // TODO Auto-generated catch block                             e.printStackTrace();                         }                         adapter=new ProductsAdapter(MainActivity.this, rowdata);                         list.setAdapter(adapter);                         dialog.dismiss();                     }                 }, new Response.ErrorListener() {             @Override             public void onErrorResponse(VolleyError error) {                 Log.d(TAG, "Error: " + error.getMessage());                 dialog.dismiss();             }         });          VolleyController.getInstance().addToRequestQueue(request, tag_json_arry);         }      @Override     public void onClick(View v) {         hidden = true;         switch (v.getId()) {              case R.id.login_img_btn:                  break;             case R.id.info_img_btn:                  break;             case R.id.share_img_btn:                  break;             case R.id.sortAtoZ:                  break;             case R.id.sortDate:                  break;             case R.id.sortRegion:                  break;         }     }      public void Info(){         Intent info = new Intent(MainActivity.this,                 InfoActivity.class);         startActivity(info);     }      @Override     public boolean onCreateOptionsMenu(Menu menu) {         getMenuInflater().inflate(R.menu.menu_main, menu);          myActionMenuItem = menu.findItem(R.id.action_search);         searchView = (SearchView) myActionMenuItem.getActionView();         searchView.clearFocus();         searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {             @Override             public boolean onQueryTextSubmit(String query) {                 return false;             }               @Override             public boolean onQueryTextChange(String newText) {                 Filter filter = adapter.getFilter();                  if (TextUtils.isEmpty(newText)) {                     filter.filter("");                 } else {                     filter.filter(newText);                 }                 return true;             }         });         return true;     }      @Override     public boolean onOptionsItemSelected(MenuItem item) {         switch (item.getItemId()) {              case R.id.action_info:                  int cx = (mRevealView.getLeft() + mRevealView.getRight()); //                int cy = (mRevealView.getTop() + mRevealView.getBottom())/2;                 int cy = mRevealView.getTop();                  int radius = Math.max(mRevealView.getWidth(), mRevealView.getHeight());                  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {                       SupportAnimator animator =                             ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, 0, radius);                     animator.setInterpolator(new AccelerateDecelerateInterpolator());                     animator.setDuration(800);                      SupportAnimator animator_reverse = animator.reverse();                      if (hidden) {                         mRevealView.setVisibility(View.VISIBLE);                         animator.start();                         hidden = false;                     } else {                         animator_reverse.addListener(new SupportAnimator.AnimatorListener() {                             @Override                             public void onAnimationStart() {                              }                              @Override                             public void onAnimationEnd() {                                 mRevealView.setVisibility(View.INVISIBLE);                                 hidden = true;                              }                              @Override                             public void onAnimationCancel() {                              }                              @Override                             public void onAnimationRepeat() {                              }                         });                         animator_reverse.start();                      }                 } else {                     if (hidden) {                         Animator anim = android.view.ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, 0, radius);                         mRevealView.setVisibility(View.VISIBLE);                         anim.start();                         hidden = false;                      } else {                         Animator anim = android.view.ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, radius, 0);                         anim.addListener(new AnimatorListenerAdapter() {                             @Override                             public void onAnimationEnd(Animator animation) {                                 super.onAnimationEnd(animation);                                 mRevealView.setVisibility(View.INVISIBLE);                                 hidden = true;                             }                         });                         anim.start();                      }                 }                  return true;              case android.R.id.home:                 supportFinishAfterTransition();                 return true;             case R.id.action_search:                 return true;             case R.id.action_share:                 return true;         }         // Handle action bar item clicks here. The action bar will         // automatically handle clicks on the Home/Up button, so long         // as you specify a parent activity in AndroidManifest.xml.         //int id = item.getItemId();          //noinspection SimplifiableIfStatement         //if (id == R.id.action_search) {         //    return true;         //}         //if (id == R.id.action_info) {         //    return true;         //}         //if(id == R.id.action_share){         //    //Share();         //    return true;         //}          return super.onOptionsItemSelected(item);     }      @Override     protected void onResume() {         super.onResume();      }      @Override     protected void onPause() {         super.onPause();      }  } 

And my main layout:

    <android.support.design.widget.CoordinatorLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitsSystemWindows="true"     tools:context="com.curtrostudios.testapp.MainActivity">      <android.support.design.widget.AppBarLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/AppTheme.AppBarOverlay">          <android.support.v7.widget.Toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="?attr/colorPrimary"             app:popupTheme="@style/AppTheme.PopupOverlay" />      </android.support.design.widget.AppBarLayout>      <FrameLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_marginTop="?attr/actionBarSize">      <io.codetail.widget.RevealFrameLayout             android:layout_width="match_parent"             android:layout_height="wrap_content">          <LinearLayout             xmlns:android="http://schemas.android.com/apk/res/android"             android:id="@+id/reveal_items"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical">              <!--row 1 -->              <LinearLayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:background="#F0EFED"                 android:orientation="horizontal"                 android:padding="16dp">                  <!--Gallery Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/login_img_btn"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_login" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="Login" />                 </LinearLayout>                  <!--Photo Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/info_img_btn"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_info" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="Info" />                 </LinearLayout>                  <!--Video Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/share_img_btn"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_share" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="Share" />                 </LinearLayout>              </LinearLayout>              <LinearLayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:background="#F0EFED"                 android:orientation="horizontal"                 android:padding="16dp">                  <!--Gallery Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/sortAtoZ"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_a_z" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="A to Z" />                 </LinearLayout>                  <!--Photo Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/sortDate"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_sort_date" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="Date" />                 </LinearLayout>                  <!--Video Icon -->                 <LinearLayout                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:layout_weight="1"                     android:gravity="center"                     android:orientation="vertical">                      <ImageButton                         android:id="@+id/sortRegion"                         android:layout_width="70dp"                         android:layout_height="70dp"                         android:background="@mipmap/ic_region" />                      <TextView                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginTop="8dp"                         android:text="Region" />                 </LinearLayout>              </LinearLayout>          </LinearLayout>      </io.codetail.widget.RevealFrameLayout>     </FrameLayout>      <include layout="@layout/content_main" />  </android.support.design.widget.CoordinatorLayout> 

This is my build.gradle(app) file:

apply plugin: 'com.android.application'  android {     compileSdkVersion 23     buildToolsVersion "23.0.2"     defaultConfig {         applicationId "com.myapp.testapp"         minSdkVersion 16         targetSdkVersion 23         versionCode 1         versionName "1.0"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     }     productFlavors {     } }  dependencies {     compile fileTree(include: ['*.jar'], dir: 'libs')     testCompile 'junit:junit:4.12'     compile 'com.android.support:appcompat-v7:23.1.1'     compile 'com.android.support:design:23.1.1'     compile 'com.mcxiaoke.volley:library-aar:1.0.0'     compile 'com.github.traex.rippleeffect:library:1.3'     compile 'com.android.support:cardview-v7:23.1.1'     compile 'com.wrapp.floatlabelededittext:library:0.0.6'     compile('com.github.afollestad.material-dialogs:core:0.8.5.7@aar') {         transitive = true     }     compile ('com.github.ozodrukh:CircularReveal:1.3.1@aar') {         transitive = true;     } } 

EDIT

This is within my build.gradle(project) file:

allprojects {     repositories {         jcenter()         maven {             url "https://jitpack.io"         }     } } 

5 Answers

Answers 1

For anyone else that may see this with the same issue of the reveal animation/menu not showing, this is how I solved the problem. It wasn't that the RevealFrameLayout wasn't showing, it was just showing behind everything else. So, as you can see in my layout below, I just moved the FrameLayout below all other content and it works flawlessly now.

Main Layout

    <android.support.design.widget.CoordinatorLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitsSystemWindows="true"     tools:context="com.myapp.testapp.MainActivity">      <android.support.design.widget.AppBarLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/AppTheme.AppBarOverlay">          <android.support.v7.widget.Toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="?attr/colorPrimary"             app:popupTheme="@style/AppTheme.PopupOverlay" />      </android.support.design.widget.AppBarLayout>      <include layout="@layout/content_main" />      //Issue was solved by adding the FrameLayout here.     //below all other content. Works perfectly now.     <FrameLayout         android:layout_width="match_parent"         android:layout_height="wrap_content">          <include layout="@layout/reveal_layout" />      </FrameLayout>    </android.support.design.widget.CoordinatorLayout> 

Answers 2

Check your imported library.

in my case,

import io.codetail.animation.SupportAnimator; import io.codetail.animation.ViewAnimationUtils; 

It occurs no error.

Answers 3

As library has clearly mentioned that you should first add remote maven url:

repositories {         maven {             url "https://jitpack.io"         }     } 

and then a library dependency:

compile ('com.github.ozodrukh:CircularReveal:1.3.1@aar') {         transitive = true;     } 

now try building the project and sync the gradle! If this doesn't helps, change aar version to 1.1.1

compile ('com.github.ozodrukh:CircularReveal:1.1.1@aar') {         transitive = true;     } 

see if it helps.

also I suggest you to read this blog if the problem still persists!

Answers 4

Although, I was not able to figure out why you are getting the error because I haven't tried that library, but I think you can easily implement circular reveal without using the above library. Please have a look at Material-Animations, it has very neat working example for circular reveal which you can use easily.

Answers 5

Let me guess, you are testing the code (and getting that error) on a pre-Lollipop device/emulator.

The class ViewAnimationUtils has been introduced in Android at SDK 21 (Lollipop).

Your minSdkVersion is 16. Have a look at this other question suggesting a support library to take back the circular reveal animation to Android 2.3. The library is CircularReveal. You'll have to fork io.codetail.animation.ViewAnimationUtils to use it.

EDIT: question didn't mention it was already using CircularReveal library -- actually can be seen by the log

referenced from method io.codetail.animation.ViewAnimationUtils.createCircularReveal

EDIT 2: after seeing the updated response and knowing from OP that the logcat is not an error but just a warning

This is not a problem at all. It's a Dalvik feature, it checks for missing classes / methods and warn you if it doesn't find them. It will not crash unless you actually try to call them.

OkHttp library has similar warning and you can see they also say you can ignore them.

As a side note, the CircularReveal library appear to use the @TargetApi annotation where it should use @SuppressLint("NewApi"). @TargetApi means you are supposed to call that method from that Api level only. Anyway this is not the cause for the warning since this information is only available at compile time.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment