Активность Coverflow действительно открывается - принудительно остановлена - PullRequest
0 голосов
/ 28 мая 2018

сначала я использовал реализацию 'com.github.moondroid.coverflow: library: 1.0'

мое приложение, к сожалению, остановлено, говорит, что оно делится на ноль, и что мне делать

logcat

05-28 16: 48: 18.789 15741-15945 / com.blipclap.creativegraphy D / FA: Событие записи в журнал (FE): представление_экранов (_vs), Bundle [{firebase_event_origin (_o) = auto, firebase_previous_class (_pc) = HomeActivity, firebase_previous_id (_pi) = - 3941845028126870572, firebase_screen_class (_sc) = ViewDownload, firebase_screen_id_id (_si)} 4818: 284: 284: 0: 0: 0: 0: 0: 0.com.blipclap.creativegraphy D / FA: подключено к удаленному сервису 05-28 16: 48: 18.851 15741-15741 / com.blipclap.creativegraphy D / AndroidRuntime: завершение работы VM 05-28 16: 48: 18.855 15741-15741 / com.blipclap.creativegraphy E / AndroidRuntime: ОСНОВНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.blipclap.creativegraphy, PID: 15741 java.lang.ArithmeticException: делить на ноль в it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow.dispatchDraw (FeatureCoverFlow.java:471) в android.view.View.updateDisplayListIfDirty (View.java:15263) в android.view.View.draw (View.java:16048) в android.view.ViewGroup.drawChild (ViewGroup.java): 3610) на android.view.ViewGroup.dispatchDraw (ViewGroup.java:3400) на android.view.View.updateDisplayListIfDirty (View.java:15263) на android.view.View.draw (View.java:16048) на android.view.ViewGroup.drawChild (ViewGroup.java:3610) в android.view.ViewGroup.dispatchDraw (ViewGroup.java:3400) в android.view.View.updateDisplayListIfDirty (View.java:15263) в android.view.View.draw (View.java:16048) в android.view.ViewGroup.drawChild (ViewGroup.java:3610) в android.view.ViewGroup.dispatchDraw (ViewGroup.java:3400) в android.view.View.updateDisplayListIfDirty (View.java): 15263) на android.view.View.draw (View.java:16048) на android.view.ViewGroup.drawChild (ViewGroup.java:3610) на android.view.ViewGroup.dispatchDraw (ViewGroup.java:3400) на android.view.View.updateDisplayListIfDirty (View.java:15263) в android.view.View.draw (View.java:16048) в android.view.ViewGroup.drawChild (ViewGroup.java:3610) в android.view.ViewGroup.dispatchDraw (ViewGroup.java:3400) в android.view.View.updateDisplayListIfDirty (View.java:15263) в android.view.View.draw (View.java:16048) в android.view.ViewGroup.drawChild (ViewGroup.java:3610) в android.view.ViewGroup.dispatchDraw (ViewGroup.Java: 3400) на android.view.View.draw (View.java:16281) на com.android.internal.policy.PhoneWindow $ DecorView.draw (PhoneWindow.java:2695) на android.view.View.updateDisplayListIfDirty (Просмотреть.java: 15268) в android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:281) в android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:287) в android.rerererereRereReна android.view.ViewRootImpl.draw (ViewRootImpl.java:2615) на android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2434) на android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2067)iew.ViewRootImpl.doTraversal (ViewRootImpl.java:1107) в android.view.ViewRootImpl $ TraversalRunnable.run (ViewRootImpl.java:6013) в android.view.Choreographer $ CallbackRecord.run и в Хореоге:.Choreographer.doCallbacks (Choreographer.java:670) на android.view.Choreographer.doFrame (Choreographer.java:606) на android.view.Choreographer $ FrameDisplayEventReceiver.run (Choreographer.java:844) и на android.handleCallback (Handler.java:739) на android.os.Handler.dispatchMessage (Handler.java:95)на android.os.Looper.loop (Looper.java:157) на android.app.ActivityThread.main (ActivityThread.java:5429) на java.lang.reflect.Method.invoke (нативный метод) на com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:726) на com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

Мой код

домашняя активность

 @SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_view_downloads) {
        startActivity(new Intent(HomeActivity.this, ViewDownload.class));
    }

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

viewdownload

 package com.blipclap.creativegraphy;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import com.blipclap.creativegraphy.Adapter.DownloadAdapter;
import com.blipclap.creativegraphy.Model.Downloads;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow;

public class ViewDownload extends AppCompatActivity {

    private FeatureCoverFlow coverFlow;
    private DownloadAdapter downloadAdapter;
    private List<Downloads> downloadsList = new ArrayList<>();
    private TextSwitcher mTitle;
    private String file_path;

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

        initData();
        mTitle = (TextSwitcher) findViewById(R.id.title);
        mTitle.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                LayoutInflater inflater = 
LayoutInflater.from(ViewDownload.this);
                TextView txt = (TextView) 
inflater.inflate(R.layout.layout_download_title, null);
                return txt;
            }
        });
        Animation in = AnimationUtils.loadAnimation(this, 
R.anim.slide_in_top);
        Animation out = AnimationUtils.loadAnimation(this, 
R.anim.slide_out_bottom);
        mTitle.setInAnimation(in);
        mTitle.setOutAnimation(out);

        downloadAdapter = new DownloadAdapter(downloadsList, this);
        coverFlow = (FeatureCoverFlow) findViewById(R.id.coverFlow);
        coverFlow.setAdapter(downloadAdapter);

        coverFlow.setOnItemClickListener(new 
AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int 
position, long id) {
                //TODO CoverFlow item clicked
            }
        });

        coverFlow.setOnScrollPositionListener(new 
FeatureCoverFlow.OnScrollPositionListener() {
            @Override
            public void onScrolledToPosition(int position) {
                mTitle.setText(downloadsList.get(position).getName());
            }

            @Override
            public void onScrolling() {

            }
        });

    }

    private ArrayList<Downloads> initData() {
        ArrayList<Downloads> downloads = new ArrayList<>();

        //Target Folder
        file_path = 
Environment.getExternalStorageDirectory().getAbsolutePath() + 
"/CreativeGraphy";
        File dir = new File(file_path);

        Downloads d;

        if (dir.exists()) {
            //Get all files From target folder
            File[] files = dir.listFiles();
if (files.length!=0) {
    //Loop for getting name and uri
    for (int i = 0; i < files.length; i++) {
        File file = files[i];

        d = new Downloads();
        d.setName(file.getName());
        d.setUri(Uri.fromFile(file));

        downloads.add(d);
    }
}else if (files.length==0)
{
    d = new Downloads();
    d.setName("You have not Downloaded any Wallpaper");
    d.setUri(Uri.parse("R.drawable.ic_terrain_black_24dp"));

    downloads.add(d);
}
        }
        return downloads;
    }
}

Модель

 package com.blipclap.creativegraphy.Model;

import android.net.Uri;

public class Downloads {
    private String Name;
    private Uri uri;


    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public Uri getUri() {
        return uri;
    }

    public void setUri(Uri uri) {
        this.uri = uri;
    }
}

Адаптер

 package com.blipclap.creativegraphy.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.blipclap.creativegraphy.Model.Downloads;
import com.blipclap.creativegraphy.R;
import com.squareup.picasso.Picasso;

import java.util.List;

public class DownloadAdapter extends BaseAdapter {
private List<Downloads> downloadsList;
private Context mContext;

public DownloadAdapter(List<Downloads> downloadsList, Context mContext) {
    this.downloadsList = downloadsList;
    this.mContext = mContext;
}

@Override
public int getCount() {
    return downloadsList.size();
}

@Override
public Object getItem(int i) {
    return downloadsList.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View rowView = view;
if (rowView==null)
{
rowView = 
LayoutInflater.from(mContext).inflate(R.layout.layout_download_item,null);

TextView name =(TextView)rowView.findViewById(R.id.label);
ImageView image=(ImageView)rowView.findViewById(R.id.image);

final Downloads downloads =(Downloads) this.getItem(i);

//Set data
 Picasso.with(mContext).load(downloads.getUri())
 .placeholder(R.drawable.ic_terrain_black_24dp)
        .into(image);
name.setText(downloads.getName());
}
return rowView;
}
}

Макет основного макета

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".ViewDownload">

<it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow
    android:id="@+id/coverFlow"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:coverHeight="200dp"
    app:coverWidth="140dp"
    app:maxScaleFactor="1.5"
    app:reflectionGap="0px"
    app:rotationThreshold="0.5"
    app:scalingThreshold="0.5"
    app:spacing="0.6" />

<TextSwitcher
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerVertical="true"
    android:paddingBottom="16dp"></TextSwitcher>

</RelativeLayout>

макет элемента

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="160dp"
android:background="@drawable/selector_bg"
android:clickable="true">

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:scaleType="centerCrop" />

<TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/label_bg"
    android:gravity="center"
    android:padding="8dp"
    android:textAppearance="?android:attr/textAppearanceSmallInverse"
    android:visibility="gone" />

</RelativeLayout>

макет заголовка

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/label_bg"
android:gravity="center"
android:padding="8dp"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
android:visibility="gone" />

1 Ответ

0 голосов
/ 28 мая 2018

решение

       private List<Downloads> initData() {

        //Target Folder
        file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/CreativeGraphy";
        File dir = new File(file_path);

        Downloads d;

        if (dir.exists()) {
            //Get all files From target folder
            File[] files = dir.listFiles();
if (files.length!=0) {
    //Loop for getting name and uri
    for (int i = 0; i < files.length; i++) {
        File file = files[i];

        d = new Downloads();
        d.setName(file.getName());
        d.setUri(Uri.fromFile(file));

        downloadsList.add(d);
    }
}else if (files.length==0)
{
    d = new Downloads();
    d.setName("You have not Downloaded any Wallpaper");
    d.setUri(Uri.parse("R.drawable.ic_terrain_black_24dp"));

    downloadsList.add(d);
}
        }
        return downloadsList;
    }
}
...