Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

In this page you can find the example usage for android.os Bundle containsKey.

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:com.hybris.mobile.app.commerce.fragment.CatalogContentFragmentBase.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Breadcrum//from   ww w  .  j a  v  a  2s . c  o m
    mCategoryBreadcrumb = (TextView) getView().findViewById(R.id.catalog_content_header_breadcumb);
    mCategoryBreadcrumb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Open the drawer
            DrawerLayout mCatalogDrawer = ((DrawerLayout) getActivity().findViewById(R.id.catalog_menu_drawer));
            mCatalogDrawer.openDrawer(mCatalogDrawer.getChildAt(1));
        }
    });

    List<ViewTypeItem> viewTypeTextViewList = new ArrayList<>();
    viewTypeTextViewList.add(new ViewTypeItem(getString(R.string.catalog_content_header_list_view),
            R.drawable.ic_subnav_list_blue));
    viewTypeTextViewList.add(new ViewTypeItem(getString(R.string.catalog_content_header_grid_view),
            R.drawable.ic_subnav_grid_blue));
    mItemViewTypeSpinner = (Spinner) getView().findViewById(R.id.catalog_content_header_view_type_spinner);
    ViewTypeAdapter mViewTypeAdapter = new ViewTypeAdapter(getActivity(), viewTypeTextViewList);
    mItemViewTypeSpinner.setAdapter(mViewTypeAdapter);
    mItemViewTypeSpinner.setOnItemSelectedListener(new ItemViewTypeSpinnerListener());

    // Select the default view
    mItemViewTypeSpinner.setSelection(SessionHelper.getCatalogContentViewType());

    // List/Line view
    mProductListView = (ListView) getView().findViewById(R.id.catalog_content_product_list);

    // Footer loading
    mFooterLoadingListView = getActivity().getLayoutInflater().inflate(R.layout.loading_spinner,
            mProductListView, false);

    // Grid view
    mProductGridView = (GridView) getView().findViewById(R.id.catalog_content_product_grid);

    // Infinite scroll listener for the list view
    mInfiniteScrollListener = new InfiniteScrollListener() {

        @Override
        public void loadNextItems(int page) {
            Log.i(TAG, "Loading the items for page " + page);
            mCurrentPage = page;
            updateProductList();
        }

    };

    mProductListView.setOnScrollListener(mInfiniteScrollListener);
    mProductGridView.setOnScrollListener(mInfiniteScrollListener);

    // Default product adapter
    mProductItemsAdapter = new ProductListAdapter(getActivity(), null, 0,
            CommerceApplication.getContentServiceHelper());

    // No product found view
    mNoProductFoundView = getActivity().findViewById(R.id.catalog_content_product_list_no_product_found);
    mNoProductFoundTextView = (TextView) getActivity()
            .findViewById(R.id.catalog_content_product_list_no_product_found_text);
    mNoProductFoundViewImage = getActivity()
            .findViewById(R.id.catalog_content_product_list_no_product_found_image);
    mNoProductFoundDidYouMeanView = getActivity()
            .findViewById(R.id.catalog_content_product_list_no_product_found_did_you_mean_view);
    mNoProductFoundDidYouMeanTextView = (TextView) getActivity()
            .findViewById(R.id.catalog_content_product_list_no_product_found_did_you_mean);

    // On click on did you mean, we update the list with the suggested term
    mNoProductFoundDidYouMeanTextView.setOnClickListener(mDidYouMeanOnClickListener);

    // Search header
    mSearchHeader = getActivity().findViewById(R.id.catalog_content_product_list_header_search);
    mSearchHeaderSearched = (TextView) getActivity()
            .findViewById(R.id.catalog_content_product_list_header_search_searched);
    mSearchHeaderDidYouMean = (TextView) getActivity()
            .findViewById(R.id.catalog_content_product_list_header_search_did_you_mean);
    mSearchHeaderDidYouMeanView = getActivity()
            .findViewById(R.id.catalog_content_product_list_header_search_did_you_mean_view);
    mSearchHeaderNbResults = (TextView) getActivity()
            .findViewById(R.id.catalog_content_product_list_header_search_nb_results);

    // On click on did you mean, we update the list with the suggested term
    mSearchHeaderDidYouMean.setOnClickListener(mDidYouMeanOnClickListener);

    // Restore the current category or search query
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(SAVED_INSTANCE_CATEGORY)) {
            mCurrentCategory = savedInstanceState.getParcelable(SAVED_INSTANCE_CATEGORY);
        }

        if (savedInstanceState.containsKey(SAVED_INSTANCE_SEARCH_TEXT)) {
            mCurrentSearchText = savedInstanceState.getString(SAVED_INSTANCE_SEARCH_TEXT);
        }

    }

    // Product list loader
    mProductListLoader = new ProductListLoader(getActivity(), CommerceApplication.getContentServiceHelper(),
            mProductItemsAdapter, new QueryProducts(), new OnRequestListener() {

                @Override
                public void beforeRequest() {
                    showLoading(true);
                }

                @Override
                public void afterRequestBeforeResponse() {

                }

                @Override
                public void afterRequest(boolean isDataSynced) {
                    updateUI(false, null, mProductItemsAdapter.getCount());
                    mInitialCall = false;

                    // TODO - offline enabling this will cause the content provider provider to ba called infinitly
                    showLoading(false);
                }
            });

}

From source file:at.alladin.rmbt.android.main.RMBTMainMenuFragment.java

/**
 * /*w  ww . ja va 2  s .  c o  m*/
 * @param view
 * @param inflater
 * @param savedInstanceState
 * @return
 */
private View createView(View view, LayoutInflater inflater, Bundle savedInstanceState) {

    startButton = view.findViewById(R.id.title_page_start_button);
    startButtonText = (TextView) view.findViewById(R.id.title_page_start_button_text);

    if (startButton != null) {
        startButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ((RMBTMainActivity) getActivity()).checkPermissionsAndStartTest();
            }
        });
    }

    final View startButtonLayout = view.findViewById(R.id.title_page_start_button_layout);
    if (startButtonLayout != null) {
        final Animation delayedPulseAnimation = AnimationUtils.loadAnimation(getActivity(),
                R.anim.delayed_pulse);
        delayedPulseAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {

                startButtonLayout.startAnimation(animation);
            }
        });
        startButtonLayout.startAnimation(delayedPulseAnimation);
    }

    //infoLocation = (TextView) view.findViewById(R.id.info_gps_location);
    //infoLocation.setVisibility(View.GONE);
    infoNetwork = (TextView) view.findViewById(R.id.info_network_name);
    setViewVisibility(infoNetwork, View.GONE);

    infoNetworkLabel = (TextView) view.findViewById(R.id.info_network_name_label);
    setViewVisibility(infoNetworkLabel, View.GONE);

    infoNetworkType = (TextView) view.findViewById(R.id.info_network_type);
    setViewVisibility(infoNetworkType, View.GONE);

    infoSignalStrength = (TextView) view.findViewById(R.id.info_signal_strength);
    setViewVisibility(infoSignalStrength, View.GONE);

    infoSignalStrengthExtra = (TextView) view.findViewById(R.id.info_signal_strength_extra);
    setViewVisibility(infoSignalStrengthExtra, View.INVISIBLE);

    locationView = (ImageView) view.findViewById(R.id.location_image);
    setViewVisibility(locationView, View.INVISIBLE);

    locationButton = view.findViewById(R.id.title_page_location_button);
    if (locationButton != null) {
        locationButton.setOnClickListener(detailShowOnClickListener);
    }

    ipv4View = (ImageView) view.findViewById(R.id.ipv4_status);
    ipv4Button = view.findViewById(R.id.title_page_ipv4_button);
    if (ipv4Button != null) {
        ipv4Button.setOnClickListener(detailShowOnClickListener);
    }

    ipv6View = (ImageView) view.findViewById(R.id.ipv6_status);
    ipv6Button = view.findViewById(R.id.title_page_ipv6_button);
    if (ipv6Button != null) {
        ipv6Button.setOnClickListener(detailShowOnClickListener);
    }

    trafficButton = view.findViewById(R.id.title_page_traffic_button);
    if (trafficButton != null) {
        trafficButton.setOnClickListener(detailShowOnClickListener);
    }

    infoOverlayList = (ListView) view.findViewById(R.id.info_overlay_list);
    if (infoOverlayList != null) {
        infoValueListAdapterMap.put(OverlayType.TRAFFIC, new InfoArrayAdapter(getActivity(),
                OverlayType.TRAFFIC, InfoOverlayEnum.DL_TRAFFIC, InfoOverlayEnum.UL_TRAFFIC));

        infoValueListAdapterMap.put(OverlayType.IPV4, new InfoArrayAdapter(getActivity(), OverlayType.IPV4,
                InfoOverlayEnum.IPV4, InfoOverlayEnum.IPV4_PUB));

        infoValueListAdapterMap.put(OverlayType.IPV6, new InfoArrayAdapter(getActivity(), OverlayType.IPV6,
                InfoOverlayEnum.IPV6, InfoOverlayEnum.IPV6_PUB));

        infoValueListAdapterMap.put(OverlayType.LOCATION,
                new InfoArrayAdapter(getActivity(), OverlayType.LOCATION, InfoOverlayEnum.LOCATION));
    }

    infoOverlayTitle = (TextView) view.findViewById(R.id.info_overlay_title);

    infoOverlay = (RelativeLayout) view.findViewById(R.id.info_overlay);
    if (infoOverlay != null) {
        if (infoOverlay.getVisibility() == View.GONE) {
            infoOverlay.setOnClickListener(detailHideOnClickListener);
            infoOverlayList.setOnItemClickListener(detailHideOnItemClickListener);
        }
    }

    captivePortalWarning = (ImageView) view.findViewById(R.id.captive_portal_image);

    antennaView = (ImageView) view.findViewById(R.id.antenne_image);
    if (antennaView != null) {
        //antennaView.setOnClickListener(detailShowOnClickListener);

        if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_INFO_LAST_ANTENNA_IMAGE)) {
            int antennaImageId = savedInstanceState.getInt(BUNDLE_INFO_LAST_ANTENNA_IMAGE);
            antennaView.setImageResource(antennaImageId);
            antennaView.setTag(antennaImageId);
        }
    }
    ulSpeedView = (ImageView) view.findViewById(R.id.traffic_ul_image);
    dlSpeedView = (ImageView) view.findViewById(R.id.traffic_dl_image);

    developerCodeInfoView = (TextView) view.findViewById(R.id.developerCodeInfo);

    return view;
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/** Called when the activity is first created. */
@Override//from w w  w .j a  v a2  s.c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // must be at the beginning of any activity that can be called from an
    // external intent
    try {
        Collect.createODKDirs();
    } catch (RuntimeException e) {
        createErrorDialog(e.getMessage(), EXIT);
        return;
    }
    Log.i("Activity", "Created");
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences
            .registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
                @Override
                public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                    compressImage = mSharedPreferences
                            .getBoolean(PreferencesActivity.KEY_ENABLE_IMAGE_COMPRESSION, false);
                }
            });
    setContentView(R.layout.form_entry);
    /*      setTitle(getString(R.string.app_name) + " > "
    + getString(R.string.loading_form));*/
    setTitle(getString(R.string.app_name));

    Log.i("Entry", "Form");
    mErrorMessage = null;
    //progressBar = (ProgressBar) findViewById(R.id.progress);
    //progressBar.setVisibility(ProgressBar.VISIBLE);
    //progressBar.setProgress(0);

    mBeenSwiped = false;
    mAlertDialog = null;
    mCurrentView = null;
    mInAnimation = null;
    mOutAnimation = null;
    mGestureDetector = new GestureDetector(this, this);
    mQuestionHolder = (LinearLayout) findViewById(R.id.questionholder);

    // get admin preference settings
    mAdminPreferences = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0);

    mNextButton = (ImageButton) findViewById(R.id.form_forward_button);
    mNextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBeenSwiped = true;
            showNextView();
        }
    });

    mBackButton = (ImageButton) findViewById(R.id.form_back_button);
    mBackButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBeenSwiped = true;
            showPreviousView();
        }
    });

    needLocation = mSharedPreferences.getBoolean(PreferencesActivity.KEY_GPS_FIX, false);
    if (needLocation) {

        mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);
    }

    // Load JavaRosa modules. needed to restore forms.
    new XFormsModule().registerModule();

    // needed to override rms property manager
    org.javarosa.core.services.PropertyManager.setPropertyManager(new PropertyManager(getApplicationContext()));

    String startingXPath = null;
    String waitingXPath = null;
    String instancePath = null;
    Boolean newForm = true;
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(KEY_FORMPATH)) {
            mFormPath = savedInstanceState.getString(KEY_FORMPATH);
        }
        if (savedInstanceState.containsKey(KEY_INSTANCEPATH)) {
            instancePath = savedInstanceState.getString(KEY_INSTANCEPATH);
        }
        if (savedInstanceState.containsKey(KEY_XPATH)) {
            startingXPath = savedInstanceState.getString(KEY_XPATH);
            Log.i(t, "startingXPath is: " + startingXPath);
        }
        if (savedInstanceState.containsKey(KEY_XPATH_WAITING_FOR_DATA)) {
            waitingXPath = savedInstanceState.getString(KEY_XPATH_WAITING_FOR_DATA);
            Log.i(t, "waitingXPath is: " + waitingXPath);
        }
        if (savedInstanceState.containsKey(NEWFORM)) {
            newForm = savedInstanceState.getBoolean(NEWFORM, true);
        }
        if (savedInstanceState.containsKey(KEY_ERROR)) {
            mErrorMessage = savedInstanceState.getString(KEY_ERROR);
        }
    }

    // If a parse error message is showing then nothing else is loaded
    // Dialogs mid form just disappear on rotation.
    if (mErrorMessage != null) {
        createErrorDialog(mErrorMessage, EXIT);
        return;
    }

    // Check to see if this is a screen flip or a new form load.
    Object data = getLastNonConfigurationInstance();
    if (data instanceof FormLoaderTask) {
        mFormLoaderTask = (FormLoaderTask) data;
    } else if (data instanceof SaveToDiskTask) {
        mSaveToDiskTask = (SaveToDiskTask) data;
    } else if (data == null) {
        if (!newForm) {
            if (Collect.getInstance().getFormController() != null) {
                refreshCurrentView();
            } else {
                Log.w(t, "Reloading form and restoring state.");
                // we need to launch the form loader to load the form
                // controller...
                mFormLoaderTask = new FormLoaderTask(instancePath, startingXPath, waitingXPath);
                Collect.getInstance().getActivityLogger().logAction(this, "formReloaded", mFormPath);
                // TODO: this doesn' work (dialog does not get removed):
                // showDialog(PROGRESS_DIALOG);
                // show dialog before we execute...
                Log.i("Loader", "Executing");
                mFormLoaderTask.execute(mFormPath);
            }
            return;
        }

        // Not a restart from a screen orientation change (or other).
        Collect.getInstance().setFormController(null);
        CompatibilityUtils.invalidateOptionsMenu(this);

        Intent intent = getIntent();
        if (intent != null) {
            Uri uri = intent.getData();

            if (getContentResolver().getType(uri).equals(InstanceColumns.CONTENT_ITEM_TYPE)) {
                // get the formId and version for this instance...
                String jrFormId = null;
                String jrVersion = null;
                {
                    Cursor instanceCursor = null;
                    try {
                        instanceCursor = getContentResolver().query(uri, null, null, null, null);
                        if (instanceCursor.getCount() != 1) {
                            this.createErrorDialog("Bad URI: " + uri, EXIT);
                            return;
                        } else {
                            instanceCursor.moveToFirst();
                            instancePath = instanceCursor.getString(
                                    instanceCursor.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH));
                            Collect.getInstance().getActivityLogger().logAction(this, "instanceLoaded",
                                    instancePath);

                            jrFormId = instanceCursor
                                    .getString(instanceCursor.getColumnIndex(InstanceColumns.JR_FORM_ID));
                            int idxJrVersion = instanceCursor.getColumnIndex(InstanceColumns.JR_VERSION);

                            jrVersion = instanceCursor.isNull(idxJrVersion) ? null
                                    : instanceCursor.getString(idxJrVersion);
                        }
                    } finally {
                        if (instanceCursor != null) {
                            instanceCursor.close();
                        }
                    }
                }

                String[] selectionArgs;
                String selection;

                if (jrVersion == null) {
                    selectionArgs = new String[] { jrFormId };
                    selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + " IS NULL";
                } else {
                    selectionArgs = new String[] { jrFormId, jrVersion };
                    selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + "=?";
                }

                {
                    Cursor formCursor = null;
                    try {
                        formCursor = getContentResolver().query(FormsColumns.CONTENT_URI, null, selection,
                                selectionArgs, null);
                        if (formCursor.getCount() == 1) {
                            formCursor.moveToFirst();
                            mFormPath = formCursor
                                    .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                        } else if (formCursor.getCount() < 1) {
                            this.createErrorDialog(
                                    getString(R.string.parent_form_not_present, jrFormId)
                                            + ((jrVersion == null) ? ""
                                                    : "\n" + getString(R.string.version) + " " + jrVersion),
                                    EXIT);
                            return;
                        } else if (formCursor.getCount() > 1) {
                            // still take the first entry, but warn that
                            // there are multiple rows.
                            // user will need to hand-edit the SQLite
                            // database to fix it.
                            formCursor.moveToFirst();
                            mFormPath = formCursor
                                    .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                            this.createErrorDialog(getString(R.string.survey_multiple_forms_error), EXIT);
                            return;
                        }
                    } finally {
                        if (formCursor != null) {
                            formCursor.close();
                        }
                    }
                }
            } else if (getContentResolver().getType(uri).equals(FormsColumns.CONTENT_ITEM_TYPE)) {
                Cursor c = null;
                try {
                    c = getContentResolver().query(uri, null, null, null, null);
                    if (c.getCount() != 1) {
                        this.createErrorDialog("Bad URI: " + uri, EXIT);
                        return;
                    } else {
                        c.moveToFirst();
                        mFormPath = c.getString(c.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                        // This is the fill-blank-form code path.
                        // See if there is a savepoint for this form that
                        // has never been
                        // explicitly saved
                        // by the user. If there is, open this savepoint
                        // (resume this filled-in
                        // form).
                        // Savepoints for forms that were explicitly saved
                        // will be recovered
                        // when that
                        // explicitly saved instance is edited via
                        // edit-saved-form.
                        final String filePrefix = mFormPath.substring(mFormPath.lastIndexOf('/') + 1,
                                mFormPath.lastIndexOf('.')) + "_";
                        final String fileSuffix = ".xml.save";
                        File cacheDir = new File(Collect.CACHE_PATH);
                        File[] files = cacheDir.listFiles(new FileFilter() {
                            @Override
                            public boolean accept(File pathname) {
                                String name = pathname.getName();
                                return name.startsWith(filePrefix) && name.endsWith(fileSuffix);
                            }
                        });
                        // see if any of these savepoints are for a
                        // filled-in form that has never been
                        // explicitly saved by the user...
                        for (int i = 0; i < files.length; ++i) {
                            File candidate = files[i];
                            String instanceDirName = candidate.getName().substring(0,
                                    candidate.getName().length() - fileSuffix.length());
                            File instanceDir = new File(
                                    Collect.INSTANCES_PATH + File.separator + instanceDirName);
                            File instanceFile = new File(instanceDir, instanceDirName + ".xml");
                            if (instanceDir.exists() && instanceDir.isDirectory() && !instanceFile.exists()) {
                                // yes! -- use this savepoint file
                                instancePath = instanceFile.getAbsolutePath();
                                break;
                            }
                        }
                    }
                } finally {
                    if (c != null) {
                        c.close();
                    }
                }
            } else {
                Log.e(t, "unrecognized URI");
                this.createErrorDialog("Unrecognized URI: " + uri, EXIT);
                return;
            }

            mFormLoaderTask = new FormLoaderTask(instancePath, null, null);
            Collect.getInstance().getActivityLogger().logAction(this, "formLoaded", mFormPath);
            showDialog(PROGRESS_DIALOG);
            // show dialog before we execute...
            Log.i("Loader", "Executing");
            mFormLoaderTask.execute(mFormPath);
        }
    }

}

From source file:com.hybris.mobile.app.commerce.fragment.ProductDetailFragmentBase.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_product_detail, container, false);

    // Initialize View by linking and giving instance to xml element in the
    // layout//from w  w  w . j  ava2 s .co  m
    mCloseProductDetailButton = (ImageButton) view.findViewById(R.id.product_detail_exit);
    mProductDetaiNameText = (TextView) view.findViewById(R.id.product_detail_name);
    mOrderFormButton = (ImageButton) view.findViewById(R.id.product_detail_order_form);
    mViewPager = (ViewPager) view.findViewById(R.id.product_detail_view_pager);
    mImageAdapter = new ImagePagerAdapter(new ArrayList<Image>());
    mLayoutIndicator = (LinearLayout) view.findViewById(R.id.product_detail_view_pager_indicator_bar);
    mProductPrice = (TextView) view.findViewById(R.id.product_detail_volume_price);
    mVolumePricingExpandableButton = (Button) view.findViewById(R.id.product_detail_volume_pricing_button);
    mVolumePricingExpandableLayout = (TableLayout) view
            .findViewById(R.id.product_detail_volume_pricing_table_layout);
    mProductDetailDescriptionLayout = (LinearLayout) view.findViewById(R.id.product_detail_description_layout);
    mProductShortDescription = (TextView) view.findViewById(R.id.product_detail_short_description);
    mStocklevelText = (TextView) view.findViewById(R.id.product_detail_stocklevel_text);
    mTotalPriceText = (TextView) view.findViewById(R.id.product_detail_total_price_text);
    mQuantityEditText = (EditText) view.findViewById(R.id.product_detail_quantity_editText);
    mAddToCartButton = (LinearLayout) view.findViewById(R.id.product_detail_add_to_cart_layout_button);
    mProductDetailAddToCartText = (TextView) view.findViewById(R.id.product_detail_add_to_cart_text);
    mProductDetailExpandableButton = (Button) view.findViewById(R.id.product_detail_expandable_button);
    mProductDetailExpandableText = (TextView) view.findViewById(R.id.product_detail_expandable_text);
    mDeliveryExpandableButton = (Button) view.findViewById(R.id.product_detail_delivery_expandable_button);
    mDeliveryExpandableText = (TextView) view.findViewById(R.id.product_detail_delivery_expandable_text);
    mProductDetailVariantSpinner1 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_1);
    mProductDetailVariantSpinner2 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_2);
    mProductDetailVariantSpinner3 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_3);
    mStocklevelTextLoading = (ProgressBar) view.findViewById(R.id.product_detail_stocklevel_text_loading);
    mNoImage = view.findViewById(R.id.product_item_no_image);
    mRatingBar = (RatingBar) view.findViewById(R.id.product_detail_rating);
    mReviews = (TextView) view.findViewById(R.id.product_detail_reviews);

    mReviews.setOnClickListener(mReviewOnClickListener);

    // Zoom UI
    mProductDetailScrollView = (ScrollView) view.findViewById(R.id.product_detail_scrollView);
    mScrollViewLayout = (LinearLayout) view.findViewById(R.id.product_detail_scrollView_layout);
    mImageLayout = (LinearLayout) view.findViewById(R.id.product_detail_image_layout);
    mMiddleSection = (LinearLayout) view.findViewById(R.id.product_detail_middle_section);
    mBottomSection = (LinearLayout) view.findViewById(R.id.product_detail_bottom_section);
    mViewDivider = view.findViewById(R.id.product_detail_middle_divider);

    // Only show description when not blank
    mProductDetailDescriptionLayout.setVisibility(View.GONE);

    // Listener
    mCloseProductDetailButton.setOnClickListener(exitProductDetailButtonListener);
    mOrderFormButton.setOnClickListener(orderFormButtonListener);
    mViewPager.setOnTouchListener(imageViewPagerOnTouchListener);
    mViewPager.addOnPageChangeListener(imageViewPagerOnPageChangeListener);
    mVolumePricingExpandableButton.setOnClickListener(expandableLayoutListener);
    mProductDetailExpandableButton.setOnClickListener(
            new ExpandablePanelListener(mProductDetailExpandableButton, mProductDetailExpandableText));
    mDeliveryExpandableButton.setOnClickListener(
            new ExpandablePanelListener(mDeliveryExpandableButton, mDeliveryExpandableText));
    mQuantityEditText.setOnFocusChangeListener(quantityEditTextListener);
    mAddToCartButton.setOnClickListener(addToCartButtonListener);

    mProductDetailVariantSpinner1.setOnItemSelectedListener(getVariantSpinnerListener());
    mProductDetailVariantSpinner2.setOnItemSelectedListener(getVariantSpinnerListener());
    mProductDetailVariantSpinner3.setOnItemSelectedListener(getVariantSpinnerListener());

    mSpinnersVariants = new ArrayList<>();
    mSpinnersVariants.add(mProductDetailVariantSpinner1);
    mSpinnersVariants.add(mProductDetailVariantSpinner2);
    mSpinnersVariants.add(mProductDetailVariantSpinner3);

    mQuantityEditText.addTextChangedListener(quantityEditTextTextWatcher);
    mQuantityEditText.setOnEditorActionListener(new SubmitListener() {
        @Override
        public void onSubmitAction() {
            addToCart();
        }
    });

    // When clicking outside a EditText, hide keyboard, remove focus and
    // reset to the default value
    // Clicking on the main view
    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            UIUtils.hideKeyboard(getActivity());
            mQuantityEditText.clearFocus();
            v.performClick();
            return false;
        }
    });

    Intent intentCaller = getActivity().getIntent();

    // Query object to get the products details
    mQueryProduct = new QueryProduct();

    if (intentCaller.hasExtra(IntentConstants.PRODUCT_CODE)) {
        mQueryProduct.setCode(getActivity().getIntent().getStringExtra(IntentConstants.PRODUCT_CODE));
    } else if (StringUtils.equals(intentCaller.getAction(), Intent.ACTION_VIEW)) {
        mQueryProduct.setCode(RegexUtils.getProductCode(intentCaller.getDataString()));
    }

    // Restore the current spinner selection
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(SAVED_INSTANCE_PRODUCT_CODE)) {
            mQueryProduct.setCode(savedInstanceState.getString(SAVED_INSTANCE_PRODUCT_CODE, null));
        }
    }

    mProductLoader = getProductLoader(getActivity(), CommerceApplication.getContentServiceHelper(),
            mQueryProduct, new OnRequestListener() {

                @Override
                public void beforeRequest() {
                    afterBeforeRequest(true);
                }

                @Override
                public void afterRequestBeforeResponse() {

                }

                @Override
                public void afterRequest(boolean isDataSynced) {
                    afterBeforeRequest(false);
                }
            });

    return view;
}

From source file:com.irccloud.android.activity.MainActivity.java

@SuppressLint("NewApi")
@SuppressWarnings({ "deprecation", "unchecked" })
@Override/*from  w  w w .  j  av  a2 s  .  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    suggestionsTimer = new Timer("suggestions-timer");
    countdownTimer = new Timer("messsage-countdown-timer");

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenReceiver, filter);

    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        if (cloud != null) {
            setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                    cloud, 0xFFF2F7FC));
            cloud.recycle();
        }
    }
    setContentView(R.layout.activity_message);
    try {
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    } catch (Throwable t) {
    }

    suggestionsAdapter = new SuggestionsAdapter();
    progressBar = (ProgressBar) findViewById(R.id.progress);
    errorMsg = (TextView) findViewById(R.id.errorMsg);
    buffersListView = findViewById(R.id.BuffersList);
    messageContainer = (LinearLayout) findViewById(R.id.messageContainer);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);

    redColor = getResources().getColor(R.color.highlight_red);
    blueColor = getResources().getColor(R.color.dark_blue);

    messageTxt = (ActionEditText) findViewById(R.id.messageTxt);
    messageTxt.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && messageTxt.getText() != null && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            } else if (keyCode == KeyEvent.KEYCODE_TAB) {
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                    nextSuggestion();
                return true;
            }
            return false;
        }
    });
    messageTxt.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (drawerLayout != null && v == messageTxt && hasFocus) {
                drawerLayout.closeDrawers();
                update_suggestions(false);
            } else if (!hasFocus) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        suggestionsContainer.setVisibility(View.INVISIBLE);
                    }
                });
            }
        }
    });
    messageTxt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawerLayout != null) {
                drawerLayout.closeDrawers();
            }
        }
    });
    messageTxt.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null
                    && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            }
            return true;
        }
    });
    textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Object[] spans = s.getSpans(0, s.length(), Object.class);
            for (Object o : spans) {
                if (((s.getSpanFlags(o) & Spanned.SPAN_COMPOSING) != Spanned.SPAN_COMPOSING)
                        && (o.getClass() == StyleSpan.class || o.getClass() == ForegroundColorSpan.class
                                || o.getClass() == BackgroundColorSpan.class
                                || o.getClass() == UnderlineSpan.class || o.getClass() == URLSpan.class)) {
                    s.removeSpan(o);
                }
            }
            if (s.length() > 0
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED) {
                sendBtn.setEnabled(true);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(1);
            } else {
                sendBtn.setEnabled(false);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(0.5f);
            }
            String text = s.toString();
            if (text.endsWith("\t")) { //Workaround for Swype
                text = text.substring(0, text.length() - 1);
                messageTxt.setText(text);
                nextSuggestion();
            } else if (suggestionsContainer != null && suggestionsContainer.getVisibility() == View.VISIBLE) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        update_suggestions(false);
                    }
                });
            } else {
                if (suggestionsTimer != null) {
                    if (suggestionsTimerTask != null)
                        suggestionsTimerTask.cancel();
                    suggestionsTimerTask = new TimerTask() {
                        @Override
                        public void run() {
                            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                            update_suggestions(false);
                        }
                    };
                    suggestionsTimer.schedule(suggestionsTimerTask, 250);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    };
    messageTxt.addTextChangedListener(textWatcher);
    sendBtn = findViewById(R.id.sendBtn);
    sendBtn.setFocusable(false);
    sendBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED)
                new SendTask().execute((Void) null);
        }
    });

    photoBtn = findViewById(R.id.photoBtn);
    if (photoBtn != null) {
        photoBtn.setFocusable(false);
        photoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                insertPhoto();
            }
        });
    }
    userListView = findViewById(R.id.usersListFragment);

    View v = getLayoutInflater().inflate(R.layout.actionbar_messageview, null);
    v.findViewById(R.id.actionTitleArea).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            show_topic_popup();
        }
    });

    if (drawerLayout != null) {
        if (findViewById(R.id.usersListFragment2) == null) {
            upDrawable = new DrawerArrowDrawable(this);
            greyColor = upDrawable.getColor();
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationIcon(upDrawable);
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationContentDescription("Show navigation drawer");
            drawerLayout.setDrawerListener(mDrawerListener);
            if (refreshUpIndicatorTask != null)
                refreshUpIndicatorTask.cancel(true);
            refreshUpIndicatorTask = new RefreshUpIndicatorTask();
            refreshUpIndicatorTask.execute((Void) null);
        }
    }
    messageTxt.setDrawerLayout(drawerLayout);

    title = (TextView) v.findViewById(R.id.title);
    subtitle = (TextView) v.findViewById(R.id.subtitle);
    key = (ImageView) v.findViewById(R.id.key);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        server = ServersDataSource.getInstance().getServer(savedInstanceState.getInt("cid"));
        buffer = BuffersDataSource.getInstance().getBuffer(savedInstanceState.getInt("bid"));
        backStack = (ArrayList<Integer>) savedInstanceState.getSerializable("backStack");
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("imagecaptureuri"))
        imageCaptureURI = Uri.parse(savedInstanceState.getString("imagecaptureuri"));
    else
        imageCaptureURI = null;

    ConfigInstance config = (ConfigInstance) getLastCustomNonConfigurationInstance();
    if (config != null) {
        imgurTask = config.imgurUploadTask;
        fileUploadTask = config.fileUploadTask;
    }

    drawerLayout.setScrimColor(0);
    drawerLayout.closeDrawers();

    getSupportActionBar().setElevation(0);
}