List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR
Executor THREAD_POOL_EXECUTOR
To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.
Click Source Link
From source file:com.concentricsky.android.khanacademy.app.TopicListActivity.java
@Override protected void onStart() { super.onStart(); stopped = false;/*from w ww . j a v a 2 s . co m*/ mainMenuDelegate = new MainMenuDelegate(this); gridView = (GridView) findViewById(R.id.activity_topic_list_grid); gridView.setOnItemClickListener(clickListener); ActionBar ab = getActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle("Topics"); requestDataService(new ObjectCallback<KADataService>() { @Override public void call(final KADataService dataService) { TopicListActivity.this.dataService = dataService; try { thumbnailManager = dataService.getThumbnailManager(); dao = dataService.getHelper().getTopicDao(); if (topicId != null) { topic = dao.queryForId(topicId); } else { topic = dataService.getRootTopic(); topicId = topic.getId(); } // DEBUG if (topic == null) return; // header headerView = findViewById(R.id.header_topic_list); ((TextView) headerView.findViewById(R.id.header_video_list_title)).setText(topic.getTitle()); String desc = topic.getDescription(); TextView descView = (TextView) headerView.findViewById(R.id.header_video_list_description); if (desc != null && desc.length() > 0) { descView.setText(Html.fromHtml(desc)); descView.setVisibility(View.VISIBLE); } else { descView.setVisibility(View.GONE); } // Find child count for this parent topic. boolean videoChildren = Topic.CHILD_KIND_VIDEO.equals(topic.getChild_kind()); String[] idArg = { topic.getId() }; String sql = videoChildren ? "select count() from topicvideo where topic_id=?" : "select count() from topic where parentTopic_id=?"; int count = (int) dao.queryRawValue(sql, idArg); String countFormat = getString( videoChildren ? R.string.format_video_count : R.string.format_topic_count); // Set header count string. ((TextView) headerView.findViewById(R.id.header_video_list_count)) .setText(String.format(countFormat, count)); final ImageView thumb = (ImageView) headerView.findViewById(R.id.header_video_list_thumbnail); if (thumb != null) { new AsyncTask<Void, Void, Bitmap>() { @Override public Bitmap doInBackground(Void... arg) { Bitmap bmp = thumbnailManager.getThumbnail( TopicListActivity.this.topic.getThumb_id(), Thumbnail.QUALITY_SD); return bmp; } @Override public void onPostExecute(Bitmap bmp) { thumb.setImageBitmap(bmp); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } // list if (topicCursor != null) { topicCursor.close(); } topicCursor = buildCursor(topicId); ListAdapter adapter = new TopicGridAdapter(topicCursor); gridView.setAdapter(adapter); // Request the topic and its children be updated from the api. List<Topic> children = dao.queryForEq("parentTopic_id", topic.getId()); List<String> toUpdate = new ArrayList<String>(); for (Topic child : children) { toUpdate.add(child.getId()); } toUpdate.add(topic.getId()); } catch (SQLException e) { e.printStackTrace(); } } }); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_LIBRARY_UPDATE); filter.addAction(ACTION_BADGE_EARNED); filter.addAction(ACTION_TOAST); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter); }
From source file:com.google.maps.android.clustering.ClusterManager.java
/** * Force a re-cluster. You may want to call this after adding new item(s). *//* w ww.j a v a2 s . c om*/ public void cluster() { if (mMap == null) { return; } CameraPosition pos = mMap.getCameraPosition(); Projection projection = mMap.getProjection(); if (pos == null) { return; } final float zoom = pos.zoom; mClusterTaskLock.writeLock().lock(); try { // Attempt to cancel the in-flight request. if (mClustersTasks != null) { Iterator it = mClustersTasks.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); ((ClusterTask) pairs.getValue()).cancel(true); } mClustersTasks.clear(); } if (mClusterTask != null) { mClusterTask.cancel(true); } mClusterTask = new ClusterTask(null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { mClusterTask.execute(zoom, projection.getVisibleRegion().latLngBounds); } else { mClusterTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, zoom, projection.getVisibleRegion().latLngBounds); } } finally { mClusterTaskLock.writeLock().unlock(); } }
From source file:com.spydiko.rotationmanager.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myapp = (AppSpecificOrientation) getApplication(); setContentView(R.layout.activity_main); myapp.chechForUpdate(this); if (AppSpecificOrientation.appflood) { AppFlood.initialize(this, "4oxXbIyVm6xNiizl", "TbcZgeJj2facL52e003c9", AppFlood.AD_ALL); // AppFlood.showBanner(this,AppFlood.BANNER_POSITION_BOTTOM,AppFlood.BANNER_SMALL); AppFlood.preload(AppFlood.AD_ALL, new AFRequestDelegate() { @Override/* w w w .j a va 2 s . c om*/ public void onFinish(JSONObject arg0) { runOnUiThread(new Runnable() { public void run() { // Toast.makeText(MainActivity.this, "preload finish", Toast.LENGTH_SHORT).show(); AFBannerView afBannerView = (AFBannerView) findViewById(R.id.banner); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } afBannerView.setVisibility(View.VISIBLE); } }); } }); } // Initialize everything /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#00FEBB31")); actionBar.setBackgroundDrawable(colorDrawable); }*/ // AppFlood.initialize(this, "1lfdyfOzKDcLPRPu", "th4j61EB18bdL522870c8", AppFlood.AD_ALL); names = new ArrayList<String>(); // if (myapp.loadDonate("appflood2")) AppFlood.showFullScreen(this); myapp.configureAdColony(this); menu = new SlidingMenu(this); menu.setMode(SlidingMenu.LEFT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); menu.setShadowWidthRes(R.dimen.shadow_width); menu.setShadowDrawable(R.drawable.shadow); menu.setBehindOffsetRes(R.dimen.slidingmenu_offset); menu.setFadeDegree(0.35f); menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW); menu.setMenu(R.layout.slidingmenu); buttonClearAll = (Button) findViewById(R.id.button2); vibe = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); orientationButton = (ImageView) findViewById(R.id.orientationButton); globalOrientation = (LinearLayout) findViewById(R.id.globalOrientation); autoRotate = (TextView) findViewById(R.id.orientationText); activities = new ArrayList<Model>(); lv = (ListView) findViewById(R.id.appList); final ArrayList<Model> data = (ArrayList<Model>) getLastNonConfigurationInstance(); // Set Listeners orientationButton.setOnClickListener(this); buttonClearAll.setOnClickListener(this); if (AppSpecificOrientation.getCheck_button() == 0 || AppSpecificOrientation.getCheck_button() == 1) { if (Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1) { orientationButton.setImageDrawable(getResources().getDrawable(R.drawable.auto_rotate_on)); autoRotate.setTextColor(Color.GREEN); autoRotate.setText(getResources().getText(R.string.orientationOn)); AppSpecificOrientation.setCheck_button(0); } else { orientationButton.setImageDrawable(getResources().getDrawable(R.drawable.auto_rotate_off)); autoRotate.setTextColor(Color.RED); autoRotate.setText(getResources().getText(R.string.orientationOff)); AppSpecificOrientation.setCheck_button(1); } } else { if (AppSpecificOrientation.getCheck_button() == 2) { orientationButton.setImageDrawable(getResources().getDrawable(R.drawable.forced_portrait)); autoRotate.setTextColor(Color.CYAN); autoRotate.setText(getResources().getText(R.string.forced_portrait)); } else if (AppSpecificOrientation.getCheck_button() == 3) { orientationButton.setImageDrawable(getResources().getDrawable(R.drawable.forced_landscape)); autoRotate.setTextColor(Color.CYAN); autoRotate.setText(getResources().getText(R.string.forced_landscape)); } else if (AppSpecificOrientation.getCheck_button() == 4) { orientationButton.setImageDrawable(getResources().getDrawable(R.drawable.forced_auto)); autoRotate.setTextColor(Color.parseColor("#FFFFFF")); autoRotate.setText(getResources().getText(R.string.forced_auto)); } } // Register Content Observer getContentResolver().registerContentObserver( Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, rotationObserver); // Fill the list if (data == null) { // List not stored if (AppSpecificOrientation.LOG) Log.d(TAG, "null"); packageManager = getPackageManager(); this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication()); lv.setAdapter(adapter); UpdateData updateData = new UpdateData(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); else updateData.execute((Void[]) null); } else { // List stored if (AppSpecificOrientation.LOG) Log.d(TAG, "ok"); activities = data; buttonsLayout = (LinearLayout) findViewById(R.id.twoButtons); progBar = (LinearLayout) findViewById(R.id.channelsProgress); this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication()); lv.setAdapter(adapter); adapter.notifyDataSetChanged(); for (Model mdl : activities) { names.add(mdl.getPackageName()); } progBar.setVisibility(View.GONE); lv.setVisibility(View.VISIBLE); buttonsLayout.setVisibility(View.VISIBLE); globalOrientation.setVisibility(View.VISIBLE); } }
From source file:ru.freshartapp.automarka.utils.ImageDetailFragment.java
private void removeFromFavorites() { Log.d("removeFromFavorites", "start"); final FavotitesTask task = new FavotitesTask(this.FAVORITES_REMOVE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this.mModelId); } else {// www . j a v a 2 s .c o m task.execute(this.mModelId); } }
From source file:eu.power_switch.gui.fragment.settings.GatewaySettingsFragment.java
private void startAutoDiscovery() { if (!NetworkHandler.isWifiConnected()) { StatusMessageHandler.showInfoMessage(getRecyclerView(), R.string.missing_wifi_connection, Snackbar.LENGTH_LONG);// w ww . jav a2s.c om return; } searchGatewayFAB.startAnimation(AnimationHandler.getRotationClockwiseAnimation(getContext())); final RecyclerViewFragment recyclerViewFragment = this; new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { final List<Gateway> foundGateways = NetworkHandler.searchGateways(); // stop animation getActivity().runOnUiThread(new Runnable() { @Override public void run() { searchGatewayFAB.clearAnimation(); } }); if (foundGateways == null || foundGateways.isEmpty()) { StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.no_gateway_found, Snackbar.LENGTH_LONG); return null; } int unknownGatewaysCount = 0; int existingGatewaysCount = 0; int newGatewaysCount = 0; for (Gateway newGateway : foundGateways) { if (newGateway == null) { unknownGatewaysCount++; continue; } // save new Gateway if it doesn't exist already try { DatabaseHandler.addGateway(newGateway); newGatewaysCount++; } catch (GatewayAlreadyExistsException e) { existingGatewaysCount++; DatabaseHandler.enableGateway(e.getIdOfExistingGateway()); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } } StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), getString(R.string.autodiscover_response_message, newGatewaysCount, existingGatewaysCount, unknownGatewaysCount), Snackbar.LENGTH_LONG); sendGatewaysChangedBroadcast(recyclerViewFragment.getContext()); } catch (Exception e) { Log.e(e); } return null; } @Override protected void onProgressUpdate(Void... values) { } @Override protected void onPostExecute(Void aVoid) { } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.example.android.hawifi.MainActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*from w w w.j a va 2s . c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize text fragment that displays intro text. /*SimpleTextFragment introFragment = (SimpleTextFragment) getSupportFragmentManager().findFragmentById(R.id.intro_fragment); introFragment.setText(R.string.welcome_message); introFragment.getTextView().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0f);*/ // Initialize the logging framework. initializeLogging(); // Initialize the send buttons with a listener that for click events mTb = (ToggleButton) findViewById(R.id.tb_gl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gln"); } else { throwCmd("glf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_dl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("dln"); } else { throwCmd("dlf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_gu); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gun"); } else { throwCmd("guf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_gd); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gdn"); } else { throwCmd("gdf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_du); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("dun"); } else { throwCmd("duf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_dd); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("ddn"); } else { throwCmd("ddf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pc); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pcn"); } else { throwCmd("pcf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_tv); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("tvn"); } else { throwCmd("tvf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pln"); } else { throwCmd("plf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pk); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pkn"); } else { throwCmd("pkf"); } } }); // piotr findViewById(R.id.radioButton0).setEnabled(false); findViewById(R.id.radioButton1).setEnabled(false); findViewById(R.id.radioButton2).setEnabled(false); findViewById(R.id.radioButton3).setEnabled(false); findViewById(R.id.radioButton4).setEnabled(false); myUrls = new ardUrl[5]; long nonce = myTime(); String result = ""; for (int i = 0; i < 5; i++) { myUrls[i] = new ardUrl(); myUrls[i].stat = false; } myUrls[0].url = "http://piotrlech.ddns.net:60000/"; myUrls[1].url = "http://piotrlech.ddns.net:58052/"; myUrls[2].url = "http://192.168.1.25:84/"; myUrls[3].url = "http://192.168.1.42:83/"; myUrls[4].url = "http://192.168.2.42:83/"; chkArduino asyncTask0, asyncTask1, asyncTask2, asyncTask3, asyncTask4; WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String ap = wifiInfo.getSSID(); ap = ap.replace("\"", ""); if (ap.equals("FunBox-1EFF") || ap.equals("U4")) { //for (int i = 2; i < 4; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask2 = new chkArduino(); //asyncTask2.execute(myUrls[2].url + "stm" + "/" + nonce + "/" + result); asyncTask2.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[2].url + "stm" + "/" + nonce + "/" + result); asyncTask3 = new chkArduino(); //asyncTask3.execute(myUrls[3].url + "stm" + "/" + nonce + "/" + result); asyncTask3.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[3].url + "stm" + "/" + nonce + "/" + result); //StartAsyncTaskInParallel(asyncTask3); } if (ap.equals("PENTAGRAM")) { //for (int i = 4; i < 5; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask4 = new chkArduino(); asyncTask4.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[4].url + "stm" + "/" + nonce + "/" + result); } //for (int i = 0; i < 2; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask0 = new chkArduino(); asyncTask0.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[0].url + "stm" + "/" + nonce + "/" + result); asyncTask1 = new chkArduino(); asyncTask1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[1].url + "stm" + "/" + nonce + "/" + result); }
From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java
/** * Creates an instance of a TabPersistentStore. * @param modelSelector The {@link TabModelSelector} to restore to and save from. * @param tabCreatorManager The {@link TabCreatorManager} to use. * @param observer Notified when the TabPersistentStore has completed tasks. * @param mergeTabs Whether tabs from a second TabModelSelector should be merged into * into this instance. */// w ww . j a v a 2 s . c o m public TabPersistentStore(TabPersistencePolicy policy, TabModelSelector modelSelector, TabCreatorManager tabCreatorManager, TabPersistentStoreObserver observer, final boolean mergeTabs) { mPersistencePolicy = policy; mTabModelSelector = modelSelector; mTabCreatorManager = tabCreatorManager; mTabsToSave = new ArrayDeque<>(); mTabsToRestore = new ArrayDeque<>(); mTabIdsToRestore = new HashSet<>(); mObserver = observer; mPreferences = ContextUtils.getAppSharedPreferences(); assert isStateFile(policy.getStateFileName()) : "State file name is not valid"; boolean needsInitialization = mPersistencePolicy.performInitialization(AsyncTask.SERIAL_EXECUTOR); if (mPersistencePolicy.isMergeInProgress()) return; Executor executor = needsInitialization ? AsyncTask.SERIAL_EXECUTOR : AsyncTask.THREAD_POOL_EXECUTOR; mPrefetchTabListTask = startFetchTabListTask(executor, mPersistencePolicy.getStateFileName()); startPrefetchActiveTabTask(executor); if (mergeTabs) { assert mPersistencePolicy.getStateToBeMergedFileName() != null; mPrefetchTabListToMergeTask = startFetchTabListTask(executor, mPersistencePolicy.getStateToBeMergedFileName()); } }
From source file:ch.gianulli.flashcards.SessionFragment.java
private void fetchCards() { if (mCardsLoader != null) { mCardsLoader.cancel(true);//from w w w .j a v a2 s.c om mCardsLoader = null; } mCardsLoader = new AsyncTask<Void, Void, Boolean>() { @Override protected void onPreExecute() { super.onPreExecute(); setActivePage(Page.PROGRESS); } @Override protected Boolean doInBackground(Void... params) { try { mList = TrelloList.getList(mTrelloApi, null, mListId); if (mList != null) { // Select cards mCards = mList.getCards(); int mode = getArguments().getInt(KEY_MODE); int n = getArguments().getInt(KEY_NBR_OF_CARDS); if (mode == SessionActivity.MODE_AT_RANDOM) { mCards = new ArrayList<>(mCards); // cards in list stay untouched Collections.shuffle(mCards); mCards = new ArrayList<>(mCards.subList(0, Math.min(n, mCards.size()))); } else if (mode == SessionActivity.MODE_FROM_TOP) { mCards = new ArrayList<>(mCards.subList(0, Math.min(n, mCards.size()))); } else if (mode == SessionActivity.MODE_FROM_BOTTOM) { mCards = new ArrayList<>(mCards.subList(Math.max(0, mCards.size() - n), mCards.size())); Collections.reverse(mCards); } return true; } else { throw new TrelloNotAccessibleException("Result was null."); } } catch (TrelloNotAuthorizedException e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mTrelloApi.requestAuthorization(getActivity().getSupportFragmentManager()); } }); } catch (TrelloNotAccessibleException e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { setActivePage(Page.NO_CONNECTION); } }); Log.d("test", "Trello not accessible: " + e.getMessage()); } return false; } @Override protected void onPostExecute(Boolean success) { if (success) { mAdapter.setCards(mCards); setActivePage(Page.SESSION_VIEW); mViewPager.setCurrentItem(0); // Update page indicator mPageIndicator.setText(getResources().getString(R.string.page_indicator_text, mViewPager.getCurrentItem() + 1, mAdapter.getCount())); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.android.settings.users.RestrictedProfileSettings.java
@Override public Dialog onCreateDialog(int dialogId) { if (dialogId == DIALOG_ID_EDIT_USER_INFO) { if (mEditUserInfoDialog != null) { return mEditUserInfoDialog; }/*w w w . j a v a 2 s . com*/ LayoutInflater inflater = getActivity().getLayoutInflater(); View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null); UserInfo info = mUserManager.getUserInfo(mUser.getIdentifier()); final EditText userNameView = (EditText) content.findViewById(R.id.user_name); userNameView.setText(info.name); final ImageView userPhotoView = (ImageView) content.findViewById(R.id.user_photo); Drawable drawable = null; if (mSavedPhoto != null) { drawable = CircleFramedDrawable.getInstance(getActivity(), mSavedPhoto); } else { drawable = mUserIconView.getDrawable(); if (drawable == null) { drawable = getCircularUserIcon(); } } userPhotoView.setImageDrawable(drawable); mEditUserPhotoController = new EditUserPhotoController(this, userPhotoView, mSavedPhoto, drawable, mWaitingForActivityResult); mEditUserInfoDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.profile_info_settings_title) .setIconAttribute(R.drawable.ic_settings_multiuser).setView(content).setCancelable(true) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { // Update the name if changed. CharSequence userName = userNameView.getText(); if (!TextUtils.isEmpty(userName)) { CharSequence oldUserName = mUserNameView.getText(); if (oldUserName == null || !userName.toString().equals(oldUserName.toString())) { ((TextView) mHeaderView.findViewById(android.R.id.title)) .setText(userName.toString()); mUserManager.setUserName(mUser.getIdentifier(), userName.toString()); } } // Update the photo if changed. Drawable drawable = mEditUserPhotoController.getNewUserPhotoDrawable(); Bitmap bitmap = mEditUserPhotoController.getNewUserPhotoBitmap(); if (drawable != null && bitmap != null && !drawable.equals(mUserIconView.getDrawable())) { mUserIconView.setImageDrawable(drawable); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mUserManager.setUserIcon(mUser.getIdentifier(), mEditUserPhotoController.getNewUserPhotoBitmap()); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); } removeDialog(DIALOG_ID_EDIT_USER_INFO); } clearEditUserInfoDialog(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clearEditUserInfoDialog(); } }).create(); // Make sure the IME is up. mEditUserInfoDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); return mEditUserInfoDialog; } return null; }
From source file:uk.co.alt236.floatinginfo.provider.generalinfo.GeneralInfoProvider.java
private void startProcessMonitor() { mProcessMonitorTask = new ProcessMonitorAsyncTask(getContext()) { @Override/*from ww w . j a v a2 s . c om*/ protected void onProgressUpdate(ForegroundProcessInfo... values) { if (!mIsLogPaused.get()) { final boolean change; // = false; if (values[0].getPid() != mForegroundAppPid.get()) { change = true; mForegroundAppPid.set(values[0].getPid()); mUiManager.clearPeakUsage(); } else { change = false; } mMemoryInfoReader.update(mForegroundAppPid.get()); mCpuUtilisationReader.update(); mInfoStore.set(values[0]); mInfoStore.set(mCpuUtilisationReader.getCpuInfo()); mInfoStore.set(mMemoryInfoReader.getInfo()); updateDisplay(false); if (change) { showNotification(); } } } }; mProcessMonitorTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); Log.i(TAG, "process monitor task started"); }