Android Open Source - GlassCounter Results Activity






From Project

Back to project page GlassCounter.

License

The source code is released under:

Apache License

If you think the Android project GlassCounter 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.github.barcodeeye.scan;
//from  w w  w. j av  a 2s. com
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.github.barcodeeye.scan.api.CardPresenter;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;

public class ResultsActivity extends Activity {

    private static final String TAG = ResultsActivity.class.getSimpleName();
    private static final String EXTRA_CARDS = "EXTRA_CARDS";
    

    private final List<CardPresenter> mCardPresenters = new ArrayList<CardPresenter>();
    private CardScrollView mCardScrollView;

    public static Intent newIntent(Context context,
            List<CardPresenter> cardResults) {

        Intent intent = new Intent(context, ResultsActivity.class);
        if (cardResults != null) {
            intent.putExtra(EXTRA_CARDS,
                    cardResults.toArray(new CardPresenter[cardResults.size()]));
        }

        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        if (savedInstanceState != null) {
            readExtras(intent.getExtras());
        } else if (intent != null && intent.getExtras() != null) {
            readExtras(intent.getExtras());
        } else {
            Log.e(TAG, "No extras were present");
            finish();
            return;
        }

        if (mCardPresenters.size() == 0) {
            Log.w(TAG, "There were no cards to display");
            finish();
            return;
        }

        mCardScrollView = new CardScrollView(this);
        mCardScrollView.setAdapter(new CardScrollViewAdapter(this,
                mCardPresenters));
        mCardScrollView.activate();
        mCardScrollView.setOnItemClickListener(mOnItemClickListener);

        setContentView(mCardScrollView);
    }

    private void readExtras(Bundle extras) {
        Parcelable[] parcelCardsArray = extras.getParcelableArray(EXTRA_CARDS);
        for (int i = 0; i < parcelCardsArray.length; i++) {
            mCardPresenters.add((CardPresenter) parcelCardsArray[i]);
        }
    }

    public static class CardScrollViewAdapter extends CardScrollAdapter {

        private final Context mContext;
        private final List<CardPresenter> mCardPresenters;

        public CardScrollViewAdapter(Context context,
                List<CardPresenter> cardPresenter) {
            mContext = context;
            mCardPresenters = cardPresenter;
        }

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

        @Override
        public Object getItem(int position) {
            return mCardPresenters.get(position);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            CardPresenter cardPresenter = mCardPresenters.get(position);
            return cardPresenter.getCardView(mContext);
        }

        @Override
        public int getPosition(Object item) {
            return mCardPresenters.indexOf(item);
        }
    }

    private final OnItemClickListener mOnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            CardPresenter cardPresenter = mCardPresenters.get(position);
            PendingIntent pendingIntent = cardPresenter.getPendingIntent();
            if (pendingIntent != null) {
                try {
                    pendingIntent.send();
                } catch (CanceledException e) {
                    Log.w(TAG, e.getMessage());
                }
            } else {
                Log.w(TAG, "No PendingIntent attached to card!");
            }
        }
    };
}




Java Source Code List

com.github.barcodeeye.BaseGlassActivity.java
com.github.barcodeeye.LaunchActivity.java
com.github.barcodeeye.image.ImageManager.java
com.github.barcodeeye.migrated.AmbientLightManager.java
com.github.barcodeeye.migrated.BeepManager.java
com.github.barcodeeye.migrated.DecodeFormatManager.java
com.github.barcodeeye.migrated.DecodeHintManager.java
com.github.barcodeeye.migrated.FinishListener.java
com.github.barcodeeye.migrated.HttpHelper.java
com.github.barcodeeye.migrated.InactivityTimer.java
com.github.barcodeeye.migrated.Intents.java
com.github.barcodeeye.migrated.LocaleManager.java
com.github.barcodeeye.scan.CaptureActivityHandler.java
com.github.barcodeeye.scan.CaptureActivity.java
com.github.barcodeeye.scan.DecodeHandler.java
com.github.barcodeeye.scan.DecodeThread.java
com.github.barcodeeye.scan.FinalActivity.java
com.github.barcodeeye.scan.FourthActivity.java
com.github.barcodeeye.scan.ResultsActivity.java
com.github.barcodeeye.scan.api.CardPresenter.java
com.github.barcodeeye.scan.result.ResultProcessorFactory.java
com.github.barcodeeye.scan.result.ResultProcessor.java
com.github.barcodeeye.scan.result.internal.IsbnResultProcessor.java
com.github.barcodeeye.scan.result.internal.ProductResultProcessor.java
com.github.barcodeeye.scan.result.internal.TextResultProcessor.java
com.github.barcodeeye.scan.result.internal.UriResultProcessor.java
com.github.barcodeeye.scan.result.supplement.AmazonInfoRetriever.java
com.github.barcodeeye.scan.result.supplement.BookResultInfoRetriever.java
com.github.barcodeeye.scan.result.supplement.ProductResultInfoRetriever.java
com.github.barcodeeye.scan.result.supplement.SupplementalInfoRetriever.java
com.github.barcodeeye.scan.result.supplement.TitleRetriever.java
com.github.barcodeeye.scan.result.supplement.URIResultInfoRetriever.java
com.github.barcodeeye.scan.ui.ViewfinderView.java
com.google.zxing.client.android.camera.AutoFocusManager.java
com.google.zxing.client.android.camera.CameraConfigurationManager.java
com.google.zxing.client.android.camera.CameraManager.java
com.google.zxing.client.android.camera.PreviewCallback.java
com.google.zxing.client.android.camera.open.OpenCameraInterface.java
com.google.zxing.client.android.clipboard.ClipboardInterface.java
com.google.zxing.client.android.encode.ContactEncoder.java
com.google.zxing.client.android.encode.Formatter.java
com.google.zxing.client.android.encode.MECARDContactEncoder.java
com.google.zxing.client.android.encode.VCardContactEncoder.java
com.google.zxing.client.android.history.DBHelper.java
com.google.zxing.client.android.history.HistoryItemAdapter.java
com.google.zxing.client.android.history.HistoryItem.java
com.google.zxing.client.android.share.AppInfo.java
com.google.zxing.client.android.share.AppPickerActivity.java
com.google.zxing.client.android.share.BookmarkAdapter.java
com.google.zxing.client.android.share.BookmarkPickerActivity.java
com.google.zxing.client.android.share.LoadPackagesAsyncTask.java
com.google.zxing.client.android.wifi.NetworkType.java
com.google.zxing.client.android.wifi.WifiConfigManager.java