List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.supremainc.biostar2.main.HomeActivity.java
protected void registerBroadcast() { if (mReceiver == null) { mReceiver = new BroadcastReceiver() { @Override// w w w . j a v a 2 s. c o m public void onReceive(Context context, Intent intent) { if (isFinishing()) { return; } final String action = intent.getAction(); if (action.equals(Setting.BROADCAST_ALARM_UPDATE)) { if (mLayout != null) { mLayout.setAlarmCount(); } } else if (action.equals(Setting.BROADCAST_USER_COUNT)) { if (mLayout != null) { int total = intent.getIntExtra(Setting.BROADCAST_USER_COUNT, -1); int oldTotal = mAppDataProvider.getUserCount(); if (total > -1 && total != oldTotal) { mAppDataProvider.setUserCount(total); mLayout.setUserCount(total); } else if (total == -1) { mUserDataProvider.getUsers(TAG, mUserCountListener, null, 0, 1, "1", null, null); } } } else if (action.equals(Setting.BROADCAST_DOOR_COUNT)) { if (mLayout != null) { int total = intent.getIntExtra(Setting.BROADCAST_DOOR_COUNT, -1); int oldTotal = mAppDataProvider.getDoorCount(); if (total > -1 && total != oldTotal) { mAppDataProvider.setDoorCount(total); mLayout.setDoorCount(total); } else if (total == -1) { mDoorDataProvider.getDoors(TAG, mDoorCountListener, null, 0, 1, "1", null, null); } } } else if (action.equals(Setting.BROADCAST_REROGIN)) { applyPermission(); } else if (action.equals(Setting.BROADCAST_PUSH_TOKEN_UPDATE)) { if (mGooglePush != null) { mGooglePush.checkNotification(); } } else if (action.equals(Setting.BROADCAST_GOTO_ALARMLIST)) { if (mContext == null) { return; } if (mPermissionDataProvider.getPermission(PERMISSION_MODULE.DOOR, true)) { mIsGoAlarmList = false; gotoScreen(ScreenType.ALARM_LIST, null, true); } } else if (action.equals(Setting.BROADCAST_UPDATE_MYINFO)) { mLayout.setUser(mUserDataProvider.getLoginUserInfo()); LocalBroadcastManager.getInstance(mContext) .sendBroadcast(new Intent(Setting.BROADCAST_REROGIN)); } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Setting.BROADCAST_ALARM_UPDATE); intentFilter.addAction(Setting.BROADCAST_USER_COUNT); intentFilter.addAction(Setting.BROADCAST_DOOR_COUNT); intentFilter.addAction(Setting.BROADCAST_REROGIN); intentFilter.addAction(Setting.BROADCAST_PUSH_TOKEN_UPDATE); intentFilter.addAction(Setting.BROADCAST_GOTO_ALARMLIST); intentFilter.addAction(Setting.BROADCAST_UPDATE_MYINFO); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, intentFilter); } }
From source file:com.supremainc.biostar2.user.UserModifyFragment.java
@Override protected void registerBroadcast() { if (mReceiver == null) { mReceiver = new BroadcastReceiver() { @Override/*from www . ja v a 2 s . c om*/ public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (mIsDestroy) { return; } if (action.equals(Setting.BROADCAST_UPDATE_FINGER)) { ArrayList<ListFingerprintTemplate> fingerTemplate = getExtraData( Setting.BROADCAST_UPDATE_FINGER, intent); if (fingerTemplate == null) { return; } if (mUserInfo != null) { mUserInfo.fingerprint_templates = fingerTemplate; mUserInfo.fingerprint_count = fingerTemplate.size(); } setFingerCount(); return; } if (action.equals(Setting.BROADCAST_UPDATE_CARD)) { ArrayList<ListCard> Cards = getExtraData(Setting.BROADCAST_UPDATE_CARD, intent); if (Cards == null) { return; } if (mUserInfo != null) { mUserInfo.cards = Cards; mUserInfo.card_count = Cards.size(); } setCardCount(); return; } if (action.equals(Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP)) { ArrayList<ListAccessGroup> accessGroups = getExtraData( Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP, intent); if (accessGroups == null) { return; } if (mUserInfo != null) { mUserInfo.access_groups = accessGroups; } setAccessGroupCount(); return; } if (action.equals(Setting.BROADCAST_PREFRENCE_REFRESH)) { if (mLayout == null || mContext == null) { return; } mLayout.setDateStart(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.start_datetime, TimeConvertProvider.DATE_TYPE.FORMAT_DATE)); mLayout.setDateEnd(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.expiry_datetime, TimeConvertProvider.DATE_TYPE.FORMAT_DATE)); return; } if (action.equals(Setting.BROADCAST_UPDATE_PERMISSION)) { ArrayList<CloudRole> permissions = getExtraData(Setting.BROADCAST_UPDATE_PERMISSION, intent); if (permissions == null) { return; } if (mUserInfo != null) { mUserInfo.roles = (ArrayList<CloudRole>) permissions.clone(); } setPermission(); return; } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Setting.BROADCAST_UPDATE_FINGER); intentFilter.addAction(Setting.BROADCAST_UPDATE_CARD); intentFilter.addAction(Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP); intentFilter.addAction(Setting.BROADCAST_PREFRENCE_REFRESH); intentFilter.addAction(Setting.BROADCAST_UPDATE_PERMISSION); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, intentFilter); } }
From source file:com.moez.QKSMS.mmssms.Transaction.java
private void sendMMSWiFi(final byte[] bytesToSend) { // enable mms connection to mobile data mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo.State state = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getState(); if ((0 == state.compareTo(NetworkInfo.State.CONNECTED) || 0 == state.compareTo(NetworkInfo.State.CONNECTING))) { sendData(bytesToSend);//from w ww . ja va 2s . c om } else { int resultInt = mConnMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "enableMMS"); if (resultInt == 0) { try { Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy()); sendData(bytesToSend); } catch (Exception e) { Log.e(TAG, "exception thrown", e); sendData(bytesToSend); } } else { // if mms feature is not already running (most likely isn't...) then register a receiver and wait for it to be active IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context1, Intent intent) { String action = intent.getAction(); if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { return; } NetworkInfo mNetworkInfo = mConnMgr.getActiveNetworkInfo(); if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE_MMS)) { return; } if (!mNetworkInfo.isConnected()) { return; } else { alreadySending = true; try { Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy()); sendData(bytesToSend); } catch (Exception e) { Log.e(TAG, "exception thrown", e); sendData(bytesToSend); } context.unregisterReceiver(this); } } }; context.registerReceiver(receiver, filter); try { Looper.prepare(); } catch (Exception e) { // Already on UI thread probably } // try sending after 3 seconds anyways if for some reason the receiver doesn't work new Handler().postDelayed(new Runnable() { @Override public void run() { if (!alreadySending) { try { context.unregisterReceiver(receiver); } catch (Exception e) { } try { Utils.ensureRouteToHost(context, settings.getMmsc(), settings.getProxy()); sendData(bytesToSend); } catch (Exception e) { Log.e(TAG, "exception thrown", e); sendData(bytesToSend); } } } }, 7000); } } }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The * intent will call closeExternalStorageFiles() if the external media is * going to be ejected, so applications can clean up any files they have * open.// w w w . j ava2 s .c o m */ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = MusicUtils.getCardId(ApolloService.this); reloadQueue(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme(DATA_SCHEME); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.easemob.chatuidemo.activity.ChatMainActivity.java
/** * ??//from w ww . j a v a 2s . co m */ private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { JudiApplication.getInstance().logout(new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { // ?? finish(); // startActivity(new Intent(MainActivity.this, LoginActivity.class)); } }); } @Override public void onProgress(int progress, String status) { } @Override public void onError(int code, String message) { } }); } }; IntentFilter filter = new IntentFilter(getPackageName() + ".em_internal_debug"); registerReceiver(internalDebugReceiver, filter); }
From source file:RhodesService.java
private File downloadPackage(String url) throws IOException { final Context ctx = RhodesActivity.getContext(); final Thread thisThread = Thread.currentThread(); final Runnable cancelAction = new Runnable() { public void run() { thisThread.interrupt();/*from ww w . jav a 2s . c om*/ } }; BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage("Cancel download?"); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { cancelAction.run(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Nothing } }); dialog.show(); } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) { cancelAction.run(); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD); filter.addAction(ACTION_CANCEL_DOWNLOAD); ctx.registerReceiver(downloadReceiver, filter); File tmpFile = null; InputStream is = null; OutputStream os = null; try { updateDownloadNotification(url, -1, 0); /* List<File> folders = new ArrayList<File>(); folders.add(Environment.getDownloadCacheDirectory()); folders.add(Environment.getDataDirectory()); folders.add(ctx.getCacheDir()); folders.add(ctx.getFilesDir()); try { folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir)); } catch (NameNotFoundException e1) { // Ignore } folders.add(Environment.getExternalStorageDirectory()); for (File folder : folders) { File tmpRootFolder = new File(folder, "rhodownload"); File tmpFolder = new File(tmpRootFolder, ctx.getPackageName()); if (tmpFolder.exists()) deleteFilesInFolder(tmpFolder.getAbsolutePath()); else tmpFolder.mkdirs(); File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk"); Logger.D(TAG, "Check path " + of.getAbsolutePath() + "..."); try { os = new FileOutputStream(of); } catch (FileNotFoundException e) { Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path"); continue; } Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app"); tmpFile = of; break; } */ tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk"); os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE); Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "..."); URL u = new URL(url); URLConnection conn = u.openConnection(); int totalBytes = -1; if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; totalBytes = httpConn.getContentLength(); } is = conn.getInputStream(); int downloaded = 0; updateDownloadNotification(url, totalBytes, downloaded); long prevProgress = 0; byte[] buf = new byte[65536]; for (;;) { if (thisThread.isInterrupted()) { tmpFile.delete(); Logger.D(TAG, "Download of " + url + " was canceled"); return null; } int nread = is.read(buf); if (nread == -1) break; //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes..."); os.write(buf, 0, nread); downloaded += nread; if (totalBytes > 0) { // Update progress view only if current progress is greater than // previous by more than 10%. Otherwise, if update it very frequently, // user will no have chance to click on notification view and cancel if need long progress = downloaded * 10 / totalBytes; if (progress > prevProgress) { updateDownloadNotification(url, totalBytes, downloaded); prevProgress = progress; } } } Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath()); return tmpFile; } catch (IOException e) { if (tmpFile != null) tmpFile.delete(); throw e; } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (os != null) os.close(); } catch (IOException e) { } mNM.cancel(DOWNLOAD_PACKAGE_ID); ctx.unregisterReceiver(downloadReceiver); } }
From source file:com.xinxin.facelinker.activity.MainActivity.java
/** * ??// w ww .j a v a 2 s . c o m */ private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { DemoApplication.getInstance().logout(new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { // ?? finish(); startActivity(new Intent(MainActivity.this, LoginActivity.class)); } }); } @Override public void onProgress(int progress, String status) { } @Override public void onError(int code, String message) { } }); } }; IntentFilter filter = new IntentFilter(getPackageName() + ".em_internal_debug"); registerReceiver(internalDebugReceiver, filter); }
From source file:com.tingtingapps.securesms.ConversationActivity.java
private void initializeReceivers() { securityUpdateReceiver = new BroadcastReceiver() { @Override/* www .j a v a 2 s.c o m*/ public void onReceive(Context context, Intent intent) { long eventThreadId = intent.getLongExtra("thread_id", -1); if (eventThreadId == threadId || eventThreadId == -2) { initializeSecurity(); calculateCharactersRemaining(); } } }; groupUpdateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.w("ConversationActivity", "Group update received..."); if (recipients != null) { long[] ids = recipients.getIds(); Log.w("ConversationActivity", "Looking up new recipients..."); recipients = RecipientFactory.getRecipientsForIds(context, ids, false); titleView.setTitle(recipients); } } }; registerReceiver(securityUpdateReceiver, new IntentFilter(SecurityEvent.SECURITY_UPDATE_EVENT), KeyCachingService.KEY_PERMISSION, null); registerReceiver(groupUpdateReceiver, new IntentFilter(GroupDatabase.DATABASE_UPDATE_ACTION)); }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
@SuppressLint("ResourceAsColor") @Override//w w w . j a v a 2s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_PROGRESS); if (!K9.isHideSpecialAccounts()) { createSpecialAccounts(); } Account[] accounts = Preferences.getPreferences(this).getAccounts(); Intent intent = getIntent(); // onNewIntent(intent); // see if we should show the welcome message if (ACTION_IMPORT_SETTINGS.equals(intent.getAction())) { mAccounts.onImport(); } else if (accounts.length < 1) { WelcomeMessage.showWelcomeMessage(this); finish(); return; } if (UpgradeDatabases.actionUpgradeDatabases(this, intent)) { finish(); return; } Log.d(TAG, "onCreate()"); String packageName = "com.bernard.beaconportal.activities"; counterss = "0"; int versionNumber = 0; try { PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA); versionNumber = pi.versionCode; String versionName = pi.versionName; Log.d(TAG, "K-9 is installed - " + versionNumber + " " + versionName); } catch (NameNotFoundException e) { Log.d(TAG, "K-9 not found"); } if (versionNumber <= 1) { // Register a listener for broadcasts (needed for the older versions // of k9) Log.d(TAG, "Initialising BroadcastReceiver for old K-9 version"); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "receiver.onReceive()"); doRefresh(); } }; filter = new IntentFilter(); filter.addAction("com.bernard.beaconportal.activities.intent.action.EMAIL_RECEIVED"); filter.addAction("com.bernard.beaconportal.activities.intent.action.EMAIL_DELETED"); filter.addDataScheme("email"); registerReceiver(receiver, filter); } else { // Register our own content observer, rather than using // addWatchContentUris() // since DashClock might not have permission to access the database Log.d(TAG, "Initialising ContentObserver for new K-9 version"); contentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { Log.d(TAG, "contentResolver.onChange()"); doRefresh(); } }; getContentResolver().registerContentObserver(Uri.parse(k9UnreadUri), true, contentObserver); } doRefresh(); if (UpgradeDatabases.actionUpgradeDatabases(this, getIntent())) { finish(); return; } if (useSplitView()) { setContentView(R.layout.split_drawer_main); } else { setContentView(R.layout.drawermain1); mViewSwitcher = (ViewSwitcher) findViewById(R.id.container); mViewSwitcher.setFirstInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_left)); mViewSwitcher.setFirstOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right)); mViewSwitcher.setSecondInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right)); mViewSwitcher.setSecondOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left)); mViewSwitcher.setOnSwitchCompleteListener(this); } mergeadapter = new MergeAdapter(); LayoutInflater inflater = getLayoutInflater(); accounts_view = inflater.inflate(R.layout.accounts_list, null); portals_view = inflater.inflate(R.layout.portal_list, null); folders_view = inflater.inflate(R.layout.folders_list, null); header_folders = inflater.inflate(R.layout.header_folders, null); header_drawer = inflater.inflate(R.layout.header_drawer, null); initializeActionBar(); mListView = (ListView) findViewById(android.R.id.list); // mListView.addHeaderView(header_folders, null, false); mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mListView.setLongClickable(true); mListView.setFastScrollEnabled(true); mListView.setScrollingCacheEnabled(false); // mListView.setOnItemClickListener(new OnItemClickListener() { // public void onItemClick(AdapterView<?> parent, View view, // int position, long id) { // // onOpenFolder(((FolderInfoHolder) mAdapter.getItem(position)).name); // // Log.d("Folder Click Listener", "clicked"); // // } // }); setResult(RESULT_CANCELED); // mDrawerList_Inbox = (ListView) findViewById(R.id.listview_inbox); // // View header_inbox = (View) inflater // .inflate(R.layout.header_inbox, null); // // mDrawerList_Inbox.setOnItemClickListener(this); // // mDrawerList_Inbox.setItemsCanFocus(false); // // mDrawerList_Inbox.setLongClickable(true); mListView.setSaveEnabled(true); mInflater = getLayoutInflater(); onNewIntent(getIntent()); context = this; SharedPreferences sharedpre = getSharedPreferences("show_view", Context.MODE_PRIVATE); Show_View = sharedpre.getString("show_view", ""); SharedPreferences Today_Homework = getApplicationContext().getSharedPreferences("due_today", Context.MODE_PRIVATE); SharedPreferences counts = getSharedPreferences("due_today", Context.MODE_PRIVATE); if (counts.contains("homeworkdue")) { counterss = counts.getString("homeworkdue", null); } else { counterss = null; } title_Inbox = new String[] { "Inbox" }; icon_Inbox = new int[] { R.drawable.ic_action_email }; count_Inbox = new String[] { K9counts }; if (Show_View.equals("Homework Due")) { title = new String[] { "Homework Due", "Schedule", "Resources", "Options", "Logout" }; icon = new int[] { R.drawable.ic_action_duehomework, R.drawable.ic_action_go_to_today, R.drawable.ic_action_resources, R.drawable.ic_action_settings, R.drawable.ic_action_logout }; if (counterss == null && counterss.isEmpty()) { count = new String[] { "", "", "", "", "" }; } else { count = new String[] { counterss, "", "", "", "" }; } } else { if (counterss == null && counterss.isEmpty()) { count = new String[] { "", "", "", "", "" }; } else { count = new String[] { "", counterss, "", "", "" }; } title = new String[] { "Schedule", "Homework Due", "Resources", "Options", "Logout" }; icon = new int[] { R.drawable.ic_action_go_to_today, R.drawable.ic_action_duehomework, R.drawable.ic_action_resources, R.drawable.ic_action_settings, R.drawable.ic_action_logout }; } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLinear = (LinearLayout) findViewById(R.id.left_drawer); // mDrawerList_Inbox = (ListView) findViewById(R.id.listview_inbox); // mDrawerList = (ListView) findViewById(R.id.listview_drawer); // mDrawer_Scroll = (ScrollView) // findViewById(R.id.left_drawer_scrollview); // mDrawerList.addHeaderView(header_drawer, null, false); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // mMenuAdapter_Inbox = new MenuListAdapter(MessageList.this, // title_Inbox, // icon_Inbox, count_Inbox); // mDrawerList_Inbox.setAdapter(mMenuAdapter_Inbox); // mDrawerList_Inbox // .setOnItemClickListener(new DrawerItemClickListener_Inbox()); mMenuAdapter = new MenuListAdapter(MessageList.this, title, icon, count); // mDrawerList.setAdapter(mMenuAdapter); // mergeadapter.addView(header_drawer); // // mergeadapter.addAdapter(mMenuAdapter); // // mergeadapter.addadapter(AccountsAdapter); // // mDrawerList.setAdapter(mergeadapter); getListView().setOnItemClickListener(new DrawerItemClickListener()); // mDrawerList_Inbox.setOnItemClickListener(new // DrawerItemClickListener()); // // if (savedInstanceState == null) { // selectItem_Inbox(1); // } SharedPreferences sharedpref = getSharedPreferences("actionbar_color", Context.MODE_PRIVATE); final int splitBarId = getResources().getIdentifier("split_action_bar", "id", "android"); final View splitActionBar = findViewById(splitBarId); if (!sharedpref.contains("actionbar_color")) { getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#4285f4"))); if (splitActionBar != null) { splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#4285f4"))); } } else { actionbar_colors = sharedpref.getString("actionbar_color", null); getActionBar().setBackgroundDrawable( new ColorDrawable(Color.parseColor(actionbar_colors))); if (splitActionBar != null) { splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(actionbar_colors))); } } android.app.ActionBar bar = getActionBar(); bar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); // Enable gesture detection for MessageLists // setupGestureDetector(this); if (!decodeExtras(getIntent())) { return; } findFragments(); initializeDisplayMode(savedInstanceState); initializeLayout(); initializeFragments(); displayViews(); // registerForContextMenu(mDrawerList_Inbox); registerForContextMenu(mListView); getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View view) { // TODO Auto-generated method stub super.onDrawerClosed(view); } @Override public void onDrawerOpened(View drawerView) { // TODO Auto-generated method stub super.onDrawerOpened(drawerView); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:com.eason.marker.emchat.chatuidemo.activity.EMChatMainActivity.java
/** * ??/* ww w.j ava2 s.c o m*/ */ private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { DemoHXSDKHelper.getInstance().logout(true, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { // ?? finish(); startActivity(new Intent(EMChatMainActivity.this, EMChatLoginActivity.class)); } }); } @Override public void onProgress(int progress, String status) { } @Override public void onError(int code, String message) { } }); } }; IntentFilter filter = new IntentFilter(getPackageName() + ".em_internal_debug"); registerReceiver(internalDebugReceiver, filter); }