Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:com.example.maciej.mytask.MainActivity.java

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

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);//from www .  j a va  2  s. c  o  m

    createNotification();

    mDateTimeTextView = (TextView) findViewById(R.id.dateTimeTextView);
    //      final Button addTaskBtn = (Button) findViewById(R.id.addTaskBtn);
    final ListView listview = (ListView) findViewById(R.id.taskListview);
    //      final CheckedTextView listitem = (CheckedTextView) findViewById(R.id.checkedTextView1);
    mNameList = new ArrayList<String>();
    mDescriptionList = new ArrayList<String>();
    mDateList = new ArrayList<String>();

    String savedNameList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_NAME_LIST, null);
    if (savedNameList != null) {
        String[] name_items = savedNameList.split(",");
        mNameList = new ArrayList<String>(Arrays.asList(name_items));
    }

    String savedDescriptionList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE)
            .getString(KEY_DESCRIPTION_LIST, null);
    if (savedDescriptionList != null) {
        String[] description_items = savedDescriptionList.split(",");
        mDescriptionList = new ArrayList<String>(Arrays.asList(description_items));
    }

    String savedDateList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_DATE_LIST, null);
    if (savedDateList != null) {
        String[] date_items = savedDateList.split(",");
        mDateList = new ArrayList<String>(Arrays.asList(date_items));
    }

    mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, mNameList);
    listview.setAdapter(mAdapter);
    listview.setItemsCanFocus(false);
    listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            CheckedTextView item = (CheckedTextView) view;
            if (item.isChecked()) {
                Toast.makeText(getApplicationContext(), getString(R.string.checked), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), getString(R.string.unchecked), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            descriptionClicked(view);
            return true;
        }
    });

    mTickReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
                mDateTimeTextView.setText(getCurrentTimeStamp());
            }
        }
    };

}

From source file:com.gigathinking.simpleapplock.AppListFragment.java

@Override
public void onStart() {
    super.onStart();

    if (!noAds) {
        final AdView adView = (AdView) getActivity().findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1")
                .addTestDevice("YOUR DEVICE 2").build();
        adView.loadAd(adRequest);/*from w  w  w .  j  a v  a2s  .  c o  m*/
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.id_ll_app_list);
                ll.findViewById(R.id.adView).setVisibility(View.VISIBLE);
            }
        });
    } else {
        (getActivity().findViewById(R.id.adView)).setVisibility(View.GONE);
    }

    interstitial = new InterstitialAd(getActivity());
    interstitial.setAdUnitId("YOUR AD UNIT ID");
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            super.onAdClosed();
            mPrefs.edit().putInt("ad_count", (mPrefs.getInt("ad_count", 0) + 1)).commit();
        }
    });

    // Create ad request.
    AdRequest adRequestInterestial = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1")
            .addTestDevice("YOUR DEVICE 2").build();

    // Begin loading your interstitial.
    if (!noAds) {
        interstitial.loadAd(adRequestInterestial);
    }

    if (!mList.isEmpty()) {
        showInitialStart(false);
    } else {
        showInitialStart(true);
    }
    AbsListView listView = (AbsListView) getActivity().findViewById(R.id.lv_app_list);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(this);
    mAdapter = new AppListAdapter(getActivity(), R.layout.layout_applist_item, mList);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(this);
    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (isAdded()) {
                startActivityForResult(new Intent(context, AppPicker.class), 22);
            }
        }
    };
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver,
            new IntentFilter(AppLockApplication.LAUNCH_PICKER));

    //Limit 5 interstitial ads per day.
    int today = Integer.parseInt(DateFormat.format("d", Calendar.getInstance()).toString());
    if (mPrefs.getInt("today", 0) != today) {
        mPrefs.edit().putInt("ad_count", 0).commit();
        mPrefs.edit().putInt("today", today).commit();
    }
}

From source file:com.linkedin.android.shaky.Shaky.java

/**
 * Receiver for start and end of feedback flow. When the user accepts the
 * dialog, starts the collect data background task.
 *//*www  .  j  av a2s .c o  m*/
@NonNull
private BroadcastReceiver createReceiver() {
    return new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (SendFeedbackDialog.ACTION_START_FEEDBACK_FLOW.equals(intent.getAction())) {
                if (activity != null) {
                    doStartFeedbackFlow();
                }
            } else if (FeedbackActivity.ACTION_END_FEEDBACK_FLOW.equals(intent.getAction())) {
                delegate.submit(activity, unpackResult(intent));
            }
        }
    };
}

From source file:eu.liveGov.gordexola.urbanplanning.activities.MainActivity.java

@SuppressLint("NewApi")
@Override//from www. j ava 2 s .  c om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Process process = Runtime.getRuntime().exec("logcat -c");
    } catch (IOException e) {
        Log.e("MainActivity", "I was unable to clear LogCat");
    }
    _savedInstanceState = savedInstanceState;
    configureLogbackDirectly();

    tracker = EasyTracker.getInstance(this);
    setContentView(R.layout.activity_main);
    initialiseTabHost();
    initialisePager();
    ctx = this;

    //------ Location Service Start --------------------
    Functions.startLocationService(ctx);

    //------------ Measure kb downloaded ----------------
    uid = this.getApplicationInfo().uid;
    mStartRX = TrafficStats.getUidRxBytes(uid);
    mStartTX = TrafficStats.getUidTxBytes(uid);

    //------------ Menu hard or soft key ------------------
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        boolean hasMenuKey = ViewConfiguration.get(ctx).hasPermanentMenuKey();

        ActionBar actionBar = getActionBar();
        if (!hasMenuKey) {
            actionBar.show();
        } else {
            actionBar.hide();

        }
    }

    //------------------ Temperature -----------------------------------
    mReceiver_Temperature = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
            if (temperature > 450) {
                String mes = getString(R.string.tempwarn);
                int fullstopIndex = mes.indexOf(".");

                mes = mes.replace("XXXXX", Float.toString((((float) temperature) / 10)) + "\u2103");
                String mesA = mes.substring(0, fullstopIndex);
                Toast.makeText(ctx, mesA, Toast.LENGTH_LONG).show();
                String mesB = mes.substring(fullstopIndex + 2);
                Toast.makeText(ctx, mesB, Toast.LENGTH_LONG).show();
            }
        }
    };

    //--------------- Remove Transparency and Enable -------------------------------
    intentFilter = new IntentFilter("android.intent.action.MAIN"); // DataCh
    mReceiverARFinished = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String ARFINISHED = intent.getStringExtra("ARFINISHED");
            Integer ARDATAPLUSVal = intent.getIntExtra("DataPlus", 0);

            if (ARFINISHED != null) {
                Log.e("AR Finished", "ok 2");

                if (pbarGeneral != null)
                    pbarGeneral.setProgress(90);

                Message msg = new Message();
                msg.arg1 = 2;
                handlerDialog.sendMessage(msg);

            } else if (ARDATAPLUSVal != 0) {
                if (pbarGeneral != null) {

                    if (ARDATAPLUSVal > 90)
                        ARDATAPLUSVal = 90;

                    pbarGeneral.setProgress(ARDATAPLUSVal);
                } else {
                    if (ARDATAPLUSVal < 15) {
                        Message msg = new Message();
                        msg.arg1 = 1;
                        handlerDialog.sendMessage(msg);
                    }
                }
            }
        }
    };
    registerReceiver(mReceiverARFinished, intentFilter);

    //----- Handler for Redrawing Markers from update thread ------------
    handlerDialog = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.arg1 == 1) {
                if (progressReceiving == null) {
                    progressReceiving = ProgressDialog.show(ctx, "", "", true);
                    progressReceiving.setContentView(R.layout.dialog_transparent_progress);
                    pbarGeneral = (ProgressBar) progressReceiving.findViewById(R.id.allprogress);
                }
            } else {
                if (progressReceiving != null && progressReceiving.isShowing())
                    progressReceiving.dismiss();

                progressReceiving = null;
            }
            super.handleMessage(msg);
        }
    };

    if (Functions.checkInternetConnection(this) && Functions.hasNetLocationProviderEnabled(this)
            && Functions.hasGPSLocationProviderEnabled(this)) {
        // Show progress transparency
        Message msg = new Message();
        msg.arg1 = 1;
        handlerDialog.sendMessage(msg);
    }
}

From source file:com.tourmaline.example.ExampleApplication.java

@Override
public void onCreate() {
    super.onCreate();

    // Want to attach the lifecycle broadcast listener to the application
    // context since that is the only context guaranteed to last for full
    // application lifetime
    final LocalBroadcastManager mgr = LocalBroadcastManager.getInstance(this);
    mgr.registerReceiver(new BroadcastReceiver() {
        @Override/* w  w  w. j av  a2  s .  co m*/
        public void onReceive(Context context, Intent i) {
            int state = i.getIntExtra("state", Engine.INIT_SUCCESS);
            switch (state) {
            case Engine.INIT_SUCCESS: {
                Log.i(LOG_AREA, "ENGINE INIT SUCCESS");
                registerActivityListener();
                registerLocationListener();
                registerTelematicsListener();
                break;
            }
            case Engine.INIT_REQUIRED: {
                Log.i(LOG_AREA, "ENGINE INIT REQUIRED: Engine " + "needs to restart in background...");
                final Monitoring.State monitoringState = Monitoring.getState(getApplicationContext());
                final CompletionListener listener = new CompletionListener() {
                    @Override
                    public void OnSuccess() {
                    }

                    @Override
                    public void OnFail(int i, String s) {
                    }
                };
                switch (monitoringState) {
                case AUTOMATIC:
                    initEngine(true, listener);
                    break;
                case MANUAL:
                    initEngine(false, listener);
                    break;
                default:
                    break;
                }
                break;
            }
            case Engine.INIT_FAILURE: {
                final String msg = i.getStringExtra("message");
                final int reason = i.getIntExtra("reason", 0);
                Log.e(LOG_AREA, "ENGINE INIT FAILURE" + reason + ": " + msg);
                break;
            }
            case Engine.GPS_ENABLED: {
                Log.i(LOG_AREA, "GPS_ENABLED");
                gpsEnable = true;
                Alerts.hide(getApplicationContext(), Alerts.Type.GPS);
                break;
            }
            case Engine.GPS_DISABLED: {
                Log.i(LOG_AREA, "GPS_DISABLED");
                gpsEnable = false;
                Alerts.show(getApplicationContext(), Alerts.Type.GPS);
                break;
            }
            case Engine.LOCATION_PERMISSION_GRANTED: {
                Log.i(LOG_AREA, "LOCATION_PERMISSION_GRANTED");
                //since there is no Android callback for this state, the SDK will be informed
                //only when it needs to get a new location, then it can take several
                //minutes for the notification to disappear
                locationPermissionGranted = true;
                Alerts.hide(getApplicationContext(), Alerts.Type.PERMISSION);
                break;
            }
            case Engine.LOCATION_PERMISSION_DENIED: {
                Log.i(LOG_AREA, "LOCATION_PERMISSION_DENIED");
                //In that case Android OS restart the app automatically
                locationPermissionGranted = false;
                Alerts.show(getApplicationContext(), Alerts.Type.PERMISSION);
                break;
            }
            case Engine.POWER_SAVE_MODE_DISABLED: {
                Log.i(LOG_AREA, "POWER_SAVE_MODE_DISABLED");
                powerSavingEnable = false;
                Alerts.hide(getApplicationContext(), Alerts.Type.POWER);
                break;
            }
            case Engine.POWER_SAVE_MODE_ENABLED: {
                Log.i(LOG_AREA, "POWER_SAVE_MODE_ENABLED");
                powerSavingEnable = true;
                Alerts.show(getApplicationContext(), Alerts.Type.POWER);
                break;
            }
            case Engine.SDK_UP_TO_DATE: {
                Log.i(LOG_AREA, "SDK_UP_TO_DATE");
                sdkUpToDate = true;
                break;
            }
            case Engine.SDK_UPDATE_MANDATORY: {
                Log.i(LOG_AREA, "SDK_UPDATE_MANDATORY");
                sdkUpToDate = false;
                break;
            }
            case Engine.SDK_UPDATE_AVAILABLE: {
                Log.i(LOG_AREA, "SDK_UPDATE_AVAILABLE");
                sdkUpToDate = false;
                break;
            }
            }
        }
    }, new IntentFilter(Engine.ACTION_LIFECYCLE));
}

From source file:eu.power_switch.gui.fragment.settings.GatewaySettingsFragment.java

@Override
public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_gateway_settings, container, false);

    setHasOptionsMenu(true);//from ww w.  j  a  v a  2s  .c o  m

    final RecyclerViewFragment recyclerViewFragment = this;
    final View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            switch (view.getId()) {
            case R.id.add_fab:
                ConfigureGatewayDialog configureGatewayDialog = new ConfigureGatewayDialog();
                configureGatewayDialog.setTargetFragment(recyclerViewFragment, 0);
                configureGatewayDialog.show(getFragmentManager(), null);
                break;
            case R.id.search_gateway_fab:
                startAutoDiscovery();
                break;
            default:
                break;
            }
        }
    };

    searchGatewayFAB = (FloatingActionButton) rootView.findViewById(R.id.search_gateway_fab);
    searchGatewayFAB.setImageDrawable(IconicsHelper.getRefreshIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    searchGatewayFAB.setOnClickListener(onClickListener);

    addGatewayFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    addGatewayFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    addGatewayFAB.setOnClickListener(onClickListener);

    recyclerViewGateways = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    gatewayRecyclerViewAdapter = new GatewayRecyclerViewAdapter(getActivity(), gateways);
    gatewayRecyclerViewAdapter
            .setOnItemLongClickListener(new GatewayRecyclerViewAdapter.OnItemLongClickListener() {
                @Override
                public void onItemLongClick(View itemView, int position) {
                    Gateway gateway = gateways.get(position);

                    ConfigureGatewayDialog configureGatewayDialog = ConfigureGatewayDialog
                            .newInstance(gateway.getId());
                    configureGatewayDialog.setTargetFragment(recyclerViewFragment, 0);
                    configureGatewayDialog.show(getFragmentManager(), null);
                }
            });
    recyclerViewGateways.setAdapter(gatewayRecyclerViewAdapter);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(),
            StaggeredGridLayoutManager.VERTICAL);
    recyclerViewGateways.setLayoutManager(layoutManager);

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateListContent();
        }
    };
}

From source file:com.taobao.weex.ui.component.WXText.java

private void registerTypefaceObserver(String desiredFontFamily) {
    if (WXEnvironment.getApplication() == null) {
        WXLogUtils.w("WXText", "ApplicationContent is null on register typeface observer");
        return;//w w w  .ja  va 2  s.c  o  m
    }
    mFontFamily = desiredFontFamily;
    if (mTypefaceObserver != null) {
        return;
    }

    mTypefaceObserver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String fontFamily = intent.getStringExtra("fontFamily");
            if (!mFontFamily.equals(fontFamily)) {
                return;
            }

            FontDO fontDO = TypefaceUtil.getFontDO(fontFamily);
            if (fontDO != null && fontDO.getTypeface() != null && getHostView() != null) {
                WXTextView hostView = getHostView();
                Layout layout = hostView.getTextLayout();
                if (layout != null) {
                    layout.getPaint().setTypeface(fontDO.getTypeface());
                    WXLogUtils.d("WXText", "Apply font family " + fontFamily + " to paint");
                } else {
                    WXLogUtils.w("WXText", "Layout not created");
                }
                hostView.invalidate();
            }
            WXLogUtils.d("WXText", "Font family " + fontFamily + " is available");
        }
    };

    LocalBroadcastManager.getInstance(WXEnvironment.getApplication()).registerReceiver(mTypefaceObserver,
            new IntentFilter(TypefaceUtil.ACTION_TYPE_FACE_AVAILABLE));
}

From source file:com.trimble.mcs.cordova.plugin.TrmbMcsRfid.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    // Create broadcast receiver to receive RFID scan intents
    mRfidTagReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            handleRfidTagIntent(context, intent);
        }//from w  ww.j a  v  a2s . c  om
    };

    mRfidTagFilter = new IntentFilter();
    mRfidTagFilter.addAction(RfidConstants.ACTION_RFID_TAG_SCANNED);

    // Create broadcast receiver to receive RFID scan status
    mRfidStatusReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            handleRfidStatusIntent(context, intent);
        }
    };

    mRfidStatusFilter = new IntentFilter();
    mRfidStatusFilter.addAction(RfidConstants.ACTION_RFID_START_SCAN_NOTIFICATION);
    mRfidStatusFilter.addAction(RfidConstants.ACTION_RFID_STOP_SCAN_NOTIFICATION);
}

From source file:com.wordpress.jftreading.FragmentMain.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.update_contact:
        startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI),
                PICK_CONTACT_REQUEST);//from   ww  w . j ava2  s . c  o  m
        break;
    case R.id.call_btn:
        // Dial mobile number
        if (contactUri != null) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + getMobileNumber(contactUri)));
            startActivity(callIntent);
        }
        break;
    case R.id.send_btn:
        String stextMessage = textMessage.getText().toString();
        if (stextMessage.matches("")) {

        } else if (contactUri != null) {

            dialog = ProgressDialog.show(getActivity(), "Sending", "Sending text message");
            Thread th = new Thread(new Runnable() {

                @Override
                public void run() {
                    // Send text message
                    try {
                        String SENT = "sent";
                        String DELIVERED = "delivered";

                        Intent sentIntent = new Intent(SENT);
                        //Create Pending Intents
                        PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(),
                                0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                        Intent deliveryIntent = new Intent(DELIVERED);

                        PendingIntent deliverPI = PendingIntent.getBroadcast(
                                getActivity().getApplicationContext(), 0, deliveryIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT);
                        //Register for SMS send action
                        getActivity().registerReceiver(new BroadcastReceiver() {
                            String result = "";

                            @Override
                            public void onReceive(Context context, Intent intent) {

                                switch (getResultCode()) {

                                case Activity.RESULT_OK:
                                    result = "Message sent";
                                    break;
                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                    result = "Sending failed";
                                    break;
                                case SmsManager.RESULT_ERROR_RADIO_OFF:
                                    result = "Radio off";
                                    break;
                                case SmsManager.RESULT_ERROR_NULL_PDU:
                                    result = "No PDU defined";
                                    break;
                                case SmsManager.RESULT_ERROR_NO_SERVICE:
                                    result = "No service";
                                    break;
                                }

                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (result != "") {
                                            Toast toast = Toast.makeText(getActivity().getApplicationContext(),
                                                    result, Toast.LENGTH_LONG);
                                            toast.setGravity(Gravity.CENTER, 0, 0);
                                            toast.show();
                                            result = "";
                                        }
                                        dialog.dismiss();
                                    }
                                });
                            }

                        }, new IntentFilter(SENT));
                        //Register for Delivery event
                        getActivity().registerReceiver(new BroadcastReceiver() {

                            @Override
                            public void onReceive(Context context, Intent intent) {
                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        Toast.makeText(getActivity().getApplicationContext(), "Delivered",
                                                Toast.LENGTH_LONG).show();
                                    }
                                });
                            }

                        }, new IntentFilter(DELIVERED));

                        //Send SMS
                        SmsManager smsManager = SmsManager.getDefault();
                        smsManager.sendTextMessage(getMobileNumber(contactUri), null,
                                textMessage.getText().toString(), sentPI, deliverPI);
                    } catch (Exception ex) {
                        final String exception = ex.getMessage().toString();
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getActivity().getApplicationContext(), exception,
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        ex.printStackTrace();
                        dialog.dismiss();
                    }

                }
            });
            th.start();
        }
        break;
    default:
        break;
    }
}

From source file:eu.power_switch.gui.fragment.main.RoomsFragment.java

@Override
public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_rooms, container, false);

    setHasOptionsMenu(true);/* w w  w.j  a  v a 2 s .com*/

    rooms = new ArrayList<>();
    recyclerViewRooms = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    roomsRecyclerViewAdapter = new RoomRecyclerViewAdapter(this, getActivity(), rooms);
    recyclerViewRooms.setAdapter(roomsRecyclerViewAdapter);
    layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL);
    recyclerViewRooms.setLayoutManager(layoutManager);

    addReceiverFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    addReceiverFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    final RecyclerViewFragment recyclerViewFragment = this;
    addReceiverFAB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (AnimationHandler.checkTargetApi()) {
                //                    Intent intent = new Intent();
                //
                //                    ActivityOptionsCompat options =
                //                            ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                //                                    addReceiverFAB,   // The view which starts the transition
                //                                    "configureReceiverTransition"    // The transitionName of the view were transitioning to
                //                            );
                //                    ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
            } else {

            }

            if (SettingsConstants.INVALID_APARTMENT_ID == SmartphonePreferencesHandler
                    .getCurrentApartmentId()) {
                new AlertDialog.Builder(getContext())
                        .setMessage(R.string.please_create_or_activate_apartment_first)
                        .setNeutralButton(android.R.string.ok, null).show();
                return;
            }

            ConfigureReceiverDialog configureReceiverDialog = new ConfigureReceiverDialog();
            configureReceiverDialog.setTargetFragment(recyclerViewFragment, 0);
            configureReceiverDialog.show(getFragmentManager(), null);
        }
    });

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("RoomsFragment", "received intent: " + intent.getAction());
            updateUI();
        }
    };
}