Android Open Source - android_Findex Widget Views






From Project

Back to project page android_Findex.

License

The source code is released under:

Apache License

If you think the Android project android_Findex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lithidsw.findex.widget;
// w w  w.  j a va2 s  .com
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

import com.lithidsw.findex.R;
import com.lithidsw.findex.FileInfoActivity;
import com.lithidsw.findex.db.DBUtils;
import com.lithidsw.findex.info.FileInfo;
import com.lithidsw.findex.loader.ImageLoader;
import com.lithidsw.findex.utils.C;
import com.lithidsw.findex.utils.FileUtils;

import java.util.ArrayList;

public class WidgetViews implements RemoteViewsService.RemoteViewsFactory {

    private Context mContext;
    private ArrayList<FileInfo> mFiles = new ArrayList<FileInfo>();

    private int mThemeStyle;
    private int mAppWidgetId;
    private WidgetInfo mWidgetInfo;

    private AppWidgetManager mAppManager;

    private ImageLoader imageLoader;

    public WidgetViews(Context context, int id) {
        Log.e("Fearch", "Got id: " + id);
        mContext = context;
        mAppWidgetId = id;
        mWidgetInfo = new DBUtils(context).getWidget(mAppWidgetId);
        Log.e("Fearch", "Added id: " + mWidgetInfo.id + " Pos: " + mWidgetInfo.position + " Value: " + mWidgetInfo.value);
        mThemeStyle = R.style.AppThemeDark;
        mAppManager = AppWidgetManager.getInstance(mContext);
        imageLoader = new ImageLoader(context, 100, R.drawable.loader);
        onDataSetChanged();
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDataSetChanged() {
        updateConvoList();
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public int getCount() {
        if (mFiles != null) {
            return mFiles.size();
        }
        return 0;
    }

    @Override
    public RemoteViews getViewAt(int position) {
        RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);

        final String filename = mFiles.get(position).name;
        final String tag = mFiles.get(position).type;
        final String path = mFiles.get(position).path;
        final long modified = mFiles.get(position).modified;
        final long size = mFiles.get(position).size;

        WidgetLoadStub widgetLoadStub = new WidgetLoadStub();
        widgetLoadStub.views = row;
        widgetLoadStub.id = mAppWidgetId;
        widgetLoadStub.manager = mAppManager;

        try {
            row.setTextViewText(R.id.file_name, filename);
            row.setTextViewText(R.id.file_size, FileUtils.humanReadableByteCount(size, false));
            if (path.endsWith(".apk")) {
                row.setImageViewResource(R.id.file_icon, resItem(R.attr.file_default));
                imageLoader.DisplayImage(path, null, widgetLoadStub);
            } else {
                if (tag.contains(C.TAG_PICTURES)) {
                    row.setImageViewResource(R.id.file_icon, resItem(R.attr.file_picture));
                    imageLoader.DisplayImage(path, null, widgetLoadStub);
                } else if (tag.contains(C.TAG_VIDEO)) {
                    row.setImageViewResource(R.id.file_icon, resItem(R.attr.file_video));
                    imageLoader.DisplayImage(path, null, widgetLoadStub);
                } else if (tag.contains(C.TAG_SOUNDS)) {
                    row.setImageViewResource(R.id.file_icon, resItem(R.attr.file_sound));
                    row.setImageViewResource(R.id.file_image, resItem(R.attr.file_sound));
                } else {
                    row.setImageViewResource(R.id.file_icon, resItem(R.attr.file_default));
                    row.setImageViewResource(R.id.file_image, resItem(R.attr.file_default));
                }
            }

            Intent in = new Intent(mContext, FileInfoActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("fileinfo", mFiles.get(position));
            in.putExtras(bundle);
            in.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            row.setOnClickFillInIntent(R.id.listview_click, in);

            return(row);
        } catch (IndexOutOfBoundsException e) {
            return null;
        }
    }

    @Override
    public RemoteViews getLoadingView() {
        return null;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

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

    @Override
    public boolean hasStableIds() {
        return true;
    }

    private void updateConvoList() {
        mFiles.clear();

        if (mWidgetInfo.value.equalsIgnoreCase("downloads")) {
            mFiles.addAll(new DBUtils(mContext).getDownloadFiles(""));
        } else if (mWidgetInfo.value.equalsIgnoreCase("all")) {
            mFiles.addAll(new DBUtils(mContext).getAllFiles(""));
        } else if (mWidgetInfo.value.equalsIgnoreCase("trash bin")) {
            mFiles.addAll(new DBUtils(mContext).getAllTrashFiles(""));
        } else {
            if (mWidgetInfo.position < C.NUM_MAIN_TITLES) {
                mFiles.addAll(new DBUtils(mContext).getMainTagFiles(mWidgetInfo.value, ""));
            } else {
                mFiles.addAll(new DBUtils(mContext).getCustomTagFiles(mWidgetInfo.value, ""));
            }
        }
    }

    private int resItem(int item) {
        Resources.Theme theme =  mContext.getTheme();
        if (theme != null) {
            TypedArray a = mContext.getTheme().obtainStyledAttributes(mThemeStyle, new int[] {item});
            if (a != null) {
                int attributeResourceId = a.getResourceId(0, 0);
                a.recycle();
                return attributeResourceId;
            }
        }

        return 0;
    }
}




Java Source Code List

com.lithidsw.findex.AddTagActivity.java
com.lithidsw.findex.FileInfoActivity.java
com.lithidsw.findex.IntroActivity.java
com.lithidsw.findex.IntroFragment.java
com.lithidsw.findex.MainActivity.java
com.lithidsw.findex.MainFragment.java
com.lithidsw.findex.SettingsActivity.java
com.lithidsw.findex.adapter.DrawerListAdapter.java
com.lithidsw.findex.adapter.FilePageAdapter.java
com.lithidsw.findex.adapter.InfoTagListAdapter.java
com.lithidsw.findex.adapter.StorageListAdapter.java
com.lithidsw.findex.adapter.WidgetListAdapter.java
com.lithidsw.findex.db.DBHelper.java
com.lithidsw.findex.db.DBUtils.java
com.lithidsw.findex.ef.DirectoryAdapter.java
com.lithidsw.findex.ef.DirectoryListActivity.java
com.lithidsw.findex.ef.DirectoryManager.java
com.lithidsw.findex.info.DirPickerInfo.java
com.lithidsw.findex.info.FileInfo.java
com.lithidsw.findex.loader.ImageLoader.java
com.lithidsw.findex.loader.MemoryCache.java
com.lithidsw.findex.receiver.ActionReceiver.java
com.lithidsw.findex.service.IndexService.java
com.lithidsw.findex.utils.C.java
com.lithidsw.findex.utils.DateBuilder.java
com.lithidsw.findex.utils.FileStartActivity.java
com.lithidsw.findex.utils.FileUtils.java
com.lithidsw.findex.utils.FileWalker.java
com.lithidsw.findex.utils.ItemCountLoader.java
com.lithidsw.findex.utils.MrToast.java
com.lithidsw.findex.utils.StorageOptions.java
com.lithidsw.findex.widget.WidgetConfigActivity.java
com.lithidsw.findex.widget.WidgetInfo.java
com.lithidsw.findex.widget.WidgetLoadStub.java
com.lithidsw.findex.widget.WidgetProvider.java
com.lithidsw.findex.widget.WidgetService.java
com.lithidsw.findex.widget.WidgetUtils.java
com.lithidsw.findex.widget.WidgetViews.java