List of usage examples for android.os Handler Handler
public Handler()
From source file:com.wishlist.Wishlist.java
/** Called when the activity is first created. */ @Override//from ww w.j a v a 2 s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see FbAPIs.java"); return; } setContentView(R.layout.wishlist); mHandler = new Handler(); mText = (TextView) Wishlist.this.findViewById(R.id.txt); mUserPic = (ImageView) Wishlist.this.findViewById(R.id.user_pic); mProduceName = (EditText) Wishlist.this.findViewById(R.id.product_name); mWishlistSpinner = (Spinner) Wishlist.this.findViewById(R.id.wishlist_spinner); mPlacesListSpinner = (Spinner) Wishlist.this.findViewById(R.id.location); image = (ImageView) Wishlist.this.findViewById(R.id.itemPhoto); image.setImageResource(R.drawable.camera); image.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_PICK, (MediaStore.Images.Media.EXTERNAL_CONTENT_URI)); startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE); } }); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.wishlist_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWishlistSpinner.setAdapter(adapter); mPlacesListSpinner.setClickable(false); mAddtoTimeline = (Button) Wishlist.this.findViewById(R.id.timeline); mAddtoTimeline.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!Utility.mFacebook.isSessionValid()) { showToast(getString(R.string.must_login)); return; } mProductName = mProduceName.getText().toString(); if (mProductName == null || TextUtils.isEmpty(mProductName)) { showToast(getString(R.string.enter_product_name)); return; } if (imageBytes == null) { showToast(getString(R.string.take_product_photo)); return; } /* * Upload photo first and then publish to the timeline after successful photo upload. */ uploadPhoto(); } }); /* * Initalize Facebook Object, retrieve access token and layout the Login button */ initFacebook(); }
From source file:de.mangelow.throughput.NotificationService.java
@Override public void onCreate() { super.onCreate(); if (D)/*from ww w .j av a 2 s . com*/ Log.d(TAG, "Service started"); context = getApplicationContext(); res = context.getResources(); if (tmanager == null) { tmanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tmanager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mBroadcastReceiver, filter); int[] refresh_values = res.getIntArray(R.array.refresh_values); long refresh = (long) refresh_values[MainActivity.loadIntPref(context, MainActivity.REFRESH, MainActivity.REFRESH_DEFAULT)]; modifyNotification(R.drawable.ic_stat_zero, null, "", "", new Intent()); if (handler == null) { handler = new Handler(); handler.postDelayed(mRunnable, refresh); } }
From source file:bbw.com.crashr.HeatmapsDemoActivity.java
@Override protected void startDemo() { locationHandler_ = new Handler(); locationHandler_.postDelayed(updateLocationThread, 0); getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(HAMILTON_LAT, HAMILTON_LNG), 4)); getMap().setMyLocationEnabled(true); //updateMap(); }
From source file:com.ubuntuone.android.files.activity.StoreActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarContentView(R.layout.activity_store); webView = (WebView) findViewById(R.id.webview); webView.setWebViewClient(new ContainedWebViewClient()); webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); final WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); mHandler = new Handler(); mReceiver = new DetachableResultReceiver(mHandler); setUpActionBar();//from w w w . j a v a 2 s . co m if (!NetworkUtil.isConnected(this)) { showDialog(DIALOG_NO_NETWORK_ID); return; } mLoginTask = new LoginTask(); mLoginTask.execute(); mTracker = GoogleAnalyticsTracker.getInstance(); mTracker.start(Analytics.U1F_ACCOUNT, this); mTracker.trackPageView(TAG); }
From source file:net.evecom.android.PublicOpinionlistActivity.java
/** * /*from w w w . ja v a 2s . c om*/ */ private void getXmlAndSetList() { Runnable runnable = new Runnable() { public void run() { String strUrl = HttpUtil.BASE_URL + "teventAndroid/lookSocialAndroid?" + "areaId=" + ShareUtil.getString(getApplicationContext(), "SESSION", "AREAID", "0") + "&personid=" + ShareUtil.getString(getApplicationContext(), "SESSION", "EMPID", "1") + "&start=" + 1 + "&end=" + pageSize; try { sss = connServerForResult(strUrl); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String listopinionPerson = sss; try { opinionPerson = getPersons(listopinionPerson); } catch (JSONException e) { e.printStackTrace(); } handler.sendMessage(handler.obtainMessage(0, opinionPerson)); } }; try { // new Thread(runnable).start(); // handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0) { BinderListData(opinionPerson); } } }; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.c4mprod.utils.ImageManager.java
private ImageManager(final Context ctx) { instance = this; mDowloadLooper = new LooperThread(); mDowloadLooper.start();/* w w w . j a va2 s. c om*/ mUiHandler = new Handler() { @Override public void handleMessage(Message msg) { if (mStopped) { return; } ImageDownloadMessageData messageData = (ImageDownloadMessageData) msg.obj; View v = messageData.viewRef.get(); if (v != null && messageData.bitmap != null && messageData == getImageDownloadData(v, messageData.flags)) { if (messageData.listerner != null) { messageData.listerner.onImageDownloaded(v, messageData.bitmap); } else { if (v instanceof ImageView) { if ((messageData.flags & FLAG_IN_BACKGROUND) != 0) { BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } else { ((ImageView) v).setImageBitmap(messageData.bitmap); } } else if (v instanceof ImageButton) { if ((messageData.flags & FLAG_IN_BACKGROUND) != 0) { BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } else { ((ImageButton) v).setImageBitmap(messageData.bitmap); } } else { // no src BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } } } }; }; // create cache dir if needed new File(ctx.getExternalCacheDir() + THUMB_FOLDER).mkdirs(); }
From source file:com.facebook.android.friendsmash.HomeFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/* www .j av a2 s . co m*/ // Instantiate the timerHandler timerHandler = new Handler(); application = (FriendSmashApplication) getActivity().getApplication(); }
From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java
/** * Unfortunately font-style must be set programmatically // * http://stackoverflow/* w w w . ja va2 s .c o m*/ * .com/questions/10521416/option-menu-default-gray-border-removal <item * name="android:panelFullBackground">@color/barbackground</item> * */ public boolean onCreateOptionsMenu(android.view.Menu menu) { if (this instanceof AboutActivity) { return false; } MenuInflater inflater = getMenuInflater(); if (this instanceof SignInActivity || this instanceof SignUpActivity || this instanceof ResetPasswordActivity) { inflater.inflate(R.menu.menusimple, menu); } else { inflater.inflate(R.menu.menu, menu); } getLayoutInflater().setFactory(new Factory() { public View onCreateView(String name, Context context, AttributeSet attrs) { if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) { try { LayoutInflater layoutInflater = LayoutInflater.from(context); final View view = layoutInflater.createView(name, null, attrs); new Handler().post(new Runnable() { public void run() { ((TextView) view).setTextColor(Color.WHITE); view.setBackgroundResource(R.drawable.menu_selector); } }); return view; } catch (Exception e) { Log.w("onCreateOptionsMenu", e.getMessage(), e); } } return null; } }); return super.onCreateOptionsMenu(menu); }
From source file:com.meiste.greg.ptw.GAE.java
private GAE(final Context context) { mContext = context; mHandler = new Handler(); }
From source file:com.cranberrygame.phonegap.plugin.NavigationBar.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void _setUp(boolean autoHideNavigationBar) { if (autoHideNavigationBar) { Activity activity = cordova.getActivity(); //http://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore //http://www.youtube.com/watch?v=Xw9TIS_JsPM //https://developer.android.com/training/system-ui/status.html activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); final CordovaInterface cordova_final = cordova; //http://stackoverflow.com/questions/11762306/listen-for-first-touchevent-when-using-system-ui-flag-hide-navigation //http://stackoverflow.com/questions/15103339/android-full-screen-modeics-first-touch-shows-the-navigation-bar //http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html webView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override/*from w w w . j a v a2 s.c om*/ public void onSystemUiVisibilityChange(int vis) { if (vis == 0) { //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Activity activity = cordova_final.getActivity(); activity.getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }, 3000);//after ms } } }); } }