List of usage examples for android.widget ImageView setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:info.guardianproject.pixelknot.PixelKnotActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dump = new File(DUMP); if (!dump.exists()) dump.mkdir();// w w w .ja v a 2 s . c om d = R.drawable.progress_off_selected; d_ = R.drawable.progress_on; setContentView(R.layout.pixel_knot_activity); ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); scale = Image.getScale(am.getMemoryClass()); if (Build.VERSION.SDK_INT <= 10) getSupportActionBar().hide(); else ((RelativeLayout) findViewById(R.id.pk_header)).setVisibility(View.GONE); imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); options_holder = (LinearLayout) findViewById(R.id.options_holder); action_display = (LinearLayout) findViewById(R.id.action_display); action_display_ = (LinearLayout) findViewById(R.id.action_display_); progress_holder = (LinearLayout) findViewById(R.id.progress_holder); List<Fragment> fragments = new Vector<Fragment>(); if (getIntent().getData() == null) { Fragment cover_image_fragment = Fragment.instantiate(this, CoverImageFragment.class.getName()); Fragment set_message_fragment = Fragment.instantiate(this, SetMessageFragment.class.getName()); Fragment share_fragment = Fragment.instantiate(this, ShareFragment.class.getName()); fragments.add(0, cover_image_fragment); fragments.add(1, set_message_fragment); fragments.add(2, share_fragment); } else { Fragment stego_image_fragment = Fragment.instantiate(this, StegoImageFragment.class.getName()); Bundle args = new Bundle(); args.putString(Keys.COVER_IMAGE_NAME, IO.pullPathFromUri(this, getIntent().getData())); stego_image_fragment.setArguments(args); Fragment decrypt_image_fragment = Fragment.instantiate(this, DecryptImageFragment.class.getName()); fragments.add(0, stego_image_fragment); fragments.add(1, decrypt_image_fragment); } pk_pager = new PKPager(getSupportFragmentManager(), fragments); view_pager = (ViewPager) findViewById(R.id.fragment_holder); view_pager.setAdapter(pk_pager); view_pager.setOnPageChangeListener(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.setMargins(5, 0, 5, 0); for (int p = 0; p < fragments.size(); p++) { ImageView progress_view = new ImageView(this); progress_view.setLayoutParams(lp); progress_view.setBackgroundResource(p == 0 ? d_ : d); progress_holder.addView(progress_view); } last_diff = 0; activity_root = findViewById(R.id.activity_root); activity_root.getViewTreeObserver().addOnGlobalLayoutListener(this); last_locale = PreferenceManager.getDefaultSharedPreferences(this).getString(Settings.LANGUAGE, "0"); }
From source file:com.android.mms.rcs.FavoriteDetailAdapter.java
private void initImageMsgView(LinearLayout linearLayout) { String thumbPath = mCursor/*from w w w .j a v a2 s . c o m*/ .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.THUMBNAIL)); String fileName = mCursor .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME)); thumbPath = RcsUtils.formatFilePathIfExisted(thumbPath); fileName = RcsUtils.formatFilePathIfExisted(fileName); ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view); Bitmap thumbPathBitmap = null; Bitmap filePathBitmap = null; if (!TextUtils.isEmpty(thumbPath)) { thumbPathBitmap = RcsUtils.decodeInSampleSizeBitmap(thumbPath); } else if (!TextUtils.isEmpty(fileName)) { filePathBitmap = RcsUtils.decodeInSampleSizeBitmap(fileName); } if (thumbPathBitmap != null) { imageView.setBackgroundDrawable(new BitmapDrawable(thumbPathBitmap)); } else if (filePathBitmap != null) { imageView.setBackgroundDrawable(new BitmapDrawable(filePathBitmap)); } else { imageView.setBackgroundResource(R.drawable.ic_attach_picture_holo_light); } }
From source file:com.mci.firstidol.activity.MainActivity.java
/** * tabitem/*from w ww. ja v a2s . c o m*/ * * @param drawable_res * ? * @param string_res * ? * @return */ public RelativeLayout initTabItem(int drawable_res, int string_res) { RelativeLayout layout = null; try { layout = (RelativeLayout) getLayoutInflater().inflate(R.layout.tab_item, null); ImageView index_icon = (ImageView) layout.findViewById(R.id.item_icon); TextView index_name = (TextView) layout.findViewById(R.id.item_name); index_name.setText(context.getResources().getString(string_res)); index_icon.setBackgroundResource(drawable_res); } catch (Exception e) { e.printStackTrace(); } return layout; }
From source file:com.dldzkj.app.renxing.SplashActivity.java
private void initView() { vp = (ViewPager) findViewById(R.id.viewPager); ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup); //?ID/*from w w w . j a v a2 s .co m*/ imgIdArray = new int[] { R.drawable.w1, R.drawable.w2, R.drawable.w3 }; tips = new ImageView[imgIdArray.length]; for (int i = 0; i < tips.length; i++) { ImageView imageView = new ImageView(this); imageView.setLayoutParams(new ViewGroup.LayoutParams(10, 10)); tips[i] = imageView; if (i == 0) { tips[i].setBackgroundResource(R.drawable.dot_focus); } else { tips[i].setBackgroundResource(R.drawable.dot_blur); } LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); layoutParams.leftMargin = 15; layoutParams.rightMargin = 15; layoutParams.bottomMargin = 20; group.addView(imageView, layoutParams); } // mImageViews = new ImageView[imgIdArray.length]; for (int i = 0; i < mImageViews.length; i++) { ImageView imageView = new ImageView(this); mImageViews[i] = imageView; imageView.setBackgroundResource(imgIdArray[i]); } mImageViews[mImageViews.length - 1].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(SplashActivity.this, EnterActivity.class)); finish(); } }); //Adapter vp.setAdapter(new MyAdapter()); //?? vp.setOnPageChangeListener(this); //ViewPager, 100?? vp.setCurrentItem(0); }
From source file:cn.com.incito.driver.fragments.infocenter.MyInfoFragment.java
/** * // w w w . ja va 2 s .c o m */ private void initWeather() { // String relativeUrl = "weather?"; RequestParams requestParams = new RequestParams(); requestParams.put("output", "json"); requestParams.put("ak", "1b0704b98c5aa65c3bf624d125a99d12"); requestParams.put("location", locationCity); BaiduTelematicsV3API.get(relativeUrl, requestParams, new JsonHttpResponseHandler() { @Override public void onSuccess(JSONObject response) { Log.d("BaiduTelematicsV3API onSuccess(JSONObject response)", response.toString()); Log.d("NET_LOG", "RESPONSE " + response.toString()); weathFormatData = parseWeatherParams(response); mWeahterInfo.removeAllViews(); if (weathFormatData != null && weathFormatData.size() != 0) { for (final BaiduTelematicsV3WeatherCity city : weathFormatData) { View weatherView = mInflater.inflate(R.layout.fragment_myinfo_weather_info, null); TextView cityName = (TextView) weatherView.findViewById(R.id.cityname); ImageView weatherPic = (ImageView) weatherView.findViewById(R.id.weather_pic); cityName.setText(city.getCurrentCity()); // String dayPictureUrl = city.getWeather_data() // .get(0).getDayPictureUrl(); // ImageLoader.getInstance().displayImage( // dayPictureUrl, weatherPic); weatherPic.setBackgroundResource( new WeatherIconUtil().transferImg(city.getWeather_data().get(0).getWeather())); TextView temperature = (TextView) weatherView.findViewById(R.id.temperature); temperature.setText(city.getWeather_data().get(0).getTemperature()); mWeahterInfo.addView(weatherView); break; } } /* * try { String status = response.getString("status"); * String date = response.getString("date"); String * error = response.getString("error"); // if * (status.equalsIgnoreCase("success") // && * error.equalsIgnoreCase("0")) { JSONArray results = * response .getJSONArray("results"); for (int i = 0; i * < results.length(); i++) { JSONObject jsonObject = * results .getJSONObject(i); String currentCity = * jsonObject .getString("currentCity"); * * View weatherView = mInflater.inflate( * R.layout.weather_info, null); TextView cityName = * (TextView) weatherView .findViewById(R.id.cityname); * ImageView weatherPic = (ImageView) weatherView * .findViewById(R.id.weather_pic); * cityName.setText(currentCity); JSONArray weatherArray * = jsonObject .getJSONArray("weather_data"); * JSONObject weatherObject = weatherArray * .getJSONObject(0); String dayPictureUrl = * weatherObject .getString("dayPictureUrl"); * ImageLoader.getInstance().displayImage( * dayPictureUrl, weatherPic); * * // for (int j = 0; j < // weatherArray.length(); j++) * { // JSONObject weatherObject = // * weatherArray.getJSONObject(j); // String // * date1=weatherObject.getString("date"); // String // * nightPictureUrl * =weatherObject.getString("nightPictureUrl"); // * String // * dayPictureUrl=weatherObject.getString("dayPictureUrl" * ); // String // * weather=weatherObject.getString("weather"); // String * // wind=weatherObject.getString("wind"); // String // * temperature=weatherObject.getString("temperature"); * // // } * * weatherView.setOnClickListener(new OnClickListener() * { * * @Override public void onClick(View arg0) { // TODO * Auto-generated method stub Intent intent = new * Intent(getActivity(), WeatherInfoActivity.class); * startActivity(intent); } }); * mWeahterInfo.addView(weatherView); * * } // } * * } catch (JSONException e) { // TODO Auto-generated * catch block e.printStackTrace(); } */ } @Override public void onFailure(Throwable e, JSONObject errorResponse) { Log.d("BaiduTelematicsV3API onFailure(Throwable e, JSONObject errorResponse)", e.getMessage()); } }); }
From source file:com.brandao.tictactoe.board.BoardFragment.java
public void animateOut(final ImageView image, final int index) { Animation zoomOutOut = AnimationUtils.loadAnimation(getActivity(), R.anim.zoom_out); zoomOutOut.setInterpolator(//from www. jav a2 s. c o m AnimationUtils.loadInterpolator(getActivity(), android.R.anim.anticipate_interpolator)); zoomOutOut.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { mAnimating = false; image.setBackgroundResource(R.drawable.transparent_image); if (index == 8) { initFirstTurn(); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { mAnimating = true; } }); image.startAnimation(zoomOutOut); }
From source file:com.android.mms.rcs.FavoriteDetailAdapter.java
private void initVcardMagView(LinearLayout linearLayout) { ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view); String fileName = mCursor//from w ww . j a v a 2s . co m .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME)); String vcardFileName = fileName; ArrayList<PropertyNode> propList = RcsMessageOpenUtils.openRcsVcardDetail(mContext, vcardFileName); Bitmap bitmap = null; for (PropertyNode propertyNode : propList) { if ("PHOTO".equals(propertyNode.propName)) { if (propertyNode.propValue_bytes != null) { byte[] bytes = propertyNode.propValue_bytes; bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); bitmap = RcsUtils.decodeInSampleSizeBitmap(bitmap); break; } } } if (bitmap != null) { imageView.setBackgroundDrawable(new BitmapDrawable(bitmap)); } else { imageView.setBackgroundResource(R.drawable.ic_attach_vcard); } }
From source file:lu.fisch.canze.activities.MainActivity.java
private void setBluetoothState(int btState) { if (bluetoothMenutItem != null) { final ImageView imageView = (ImageView) bluetoothMenutItem.getActionView() .findViewById(R.id.animated_menu_item_action); // stop the animation if there is one running AnimationDrawable frameAnimation; if (imageView.getBackground() instanceof AnimationDrawable) { frameAnimation = (AnimationDrawable) imageView.getBackground(); if (frameAnimation.isRunning()) frameAnimation.stop();/*from ww w . java 2s . co m*/ } switch (btState) { case BLUETOOTH_DISCONNECTED: imageView.setBackgroundResource(R.mipmap.bluetooth_none); break; case BLUETOOTH_CONNECTED: imageView.setBackgroundResource(R.mipmap.bluetooth_3); break; case BLUETOOTH_SEARCH: runOnUiThread(new Runnable() { @SuppressLint("NewApi") @Override public void run() { AnimationDrawable drawable = (AnimationDrawable) ContextCompat .getDrawable(getApplicationContext(), R.anim.animation_bluetooth); // Use setBackgroundDrawable() for API 14 and 15 and setBackground() for API 16+: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(drawable); } else { //noinspection deprecation imageView.setBackgroundDrawable(drawable); } AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.start(); } }); break; default: break; } } }
From source file:com.dsdar.thosearoundme.TeamViewActivity.java
@Override public void onMapLongClick(LatLng point) { if (TeamMapFragment.isStickyTeam.equals("true")) { // if (MyAppConstants.ISOWNER) { View marker1 = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.sticky_marker, null); ImageView sticky_marker_img = (ImageView) marker1.findViewById(R.id.stikcy_marker_img); // marker_img.getBackground().setColorFilter(-9175296, // Mode.SRC_IN); sticky_marker_img.setBackgroundResource(R.drawable.pin_red); if (MyAppConstants.myStickyMarker != null) { MyAppConstants.myStickyMarker.remove(); }/*w w w . j a va 2s . c om*/ MyAppConstants.myStickyMarker = itsGoogleMap.addMarker(new MarkerOptions() .position(new LatLng(point.latitude, point.longitude)) .icon(BitmapDescriptorFactory.fromBitmap(TeamMapFragment.createDrawableFromView(this, marker1))) .draggable(true)); insertStickyTeamMarkerInfo(point.latitude, point.longitude, null, null, null, null); } // } }
From source file:org.pouyadr.ui.LocationActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); if (AndroidUtilities.isTablet()) { actionBar.setOccupyStatusBar(false); }/* w w w. j a v a 2s . c om*/ actionBar.setAddToContainer(messageObject != null); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == map_list_menu_map) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); } } else if (id == map_list_menu_satellite) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); } } else if (id == map_list_menu_hybrid) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); } } else if (id == share) { try { double lat = messageObject.messageOwner.media.geo.lat; double lon = messageObject.messageOwner.media.geo._long; getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon))); } catch (Exception e) { FileLog.e("tmessages", e); } } } }); ActionBarMenu menu = actionBar.createMenu(); if (messageObject != null) { if (messageObject.messageOwner.media.title != null && messageObject.messageOwner.media.title.length() > 0) { actionBar.setTitle(messageObject.messageOwner.media.title); if (messageObject.messageOwner.media.address != null && messageObject.messageOwner.media.address.length() > 0) { actionBar.setSubtitle(messageObject.messageOwner.media.address); } } else { actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation)); } menu.addItem(share, R.drawable.share); } else { actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation)); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; listView.setVisibility(View.GONE); mapViewClip.setVisibility(View.GONE); searchListView.setVisibility(View.VISIBLE); searchListView.setEmptyView(emptyTextLayout); } @Override public void onSearchCollapse() { searching = false; searchWas = false; searchListView.setEmptyView(null); listView.setVisibility(View.VISIBLE); mapViewClip.setVisibility(View.VISIBLE); searchListView.setVisibility(View.GONE); emptyTextLayout.setVisibility(View.GONE); searchAdapter.searchDelayed(null, null); } @Override public void onTextChanged(EditText editText) { if (searchAdapter == null) { return; } String text = editText.getText().toString(); if (text.length() != 0) { searchWas = true; } searchAdapter.searchDelayed(text, userLocation); } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); } ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0); item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0); item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0); fragmentView = new FrameLayout(context) { private boolean first = true; @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { fixLayoutInternal(first); first = false; } } }; FrameLayout frameLayout = (FrameLayout) fragmentView; locationButton = new ImageView(context); locationButton.setBackgroundResource(R.drawable.floating_user_states); locationButton.setImageResource(R.drawable.myloc_on); locationButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); locationButton.setStateListAnimator(animator); locationButton.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } if (messageObject != null) { mapView = new MapView(context); frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable()); mapView.onCreate(null); try { MapsInitializer.initialize(context); // googleMap = mapView.getMap(); } catch (Exception e) { FileLog.e("tmessages", e); } FrameLayout bottomView = new FrameLayout(context); bottomView.setBackgroundResource(R.drawable.location_panel); frameLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM)); bottomView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (userLocation != null) { LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); if (googleMap != null) { CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4); googleMap.animateCamera(position); } } } }); avatarImageView = new BackupImageView(context); avatarImageView.setRoundRadius(AndroidUtilities.dp(20)); bottomView.addView(avatarImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0)); nameTextView = new TextView(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); nameTextView.setTextColor(0xff212121); nameTextView.setMaxLines(1); nameTextView.setTypeface(AndroidUtilities.getTypeface(org.pouyadr.finalsoft.Fonts.CurrentFont())); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setSingleLine(true); nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); bottomView.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0)); distanceTextView = new TextView(context); distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); distanceTextView.setTextColor(0xff2f8cc9); distanceTextView.setMaxLines(1); distanceTextView.setEllipsize(TextUtils.TruncateAt.END); distanceTextView.setSingleLine(true); distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); bottomView.addView(distanceTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0)); userLocation = new Location("network"); userLocation.setLatitude(messageObject.messageOwner.media.geo.lat); userLocation.setLongitude(messageObject.messageOwner.media.geo._long); if (googleMap != null) { LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); try { googleMap.addMarker(new MarkerOptions().position(latLng) .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin))); } catch (Exception e) { FileLog.e("tmessages", e); } CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4); googleMap.moveCamera(position); } ImageView routeButton = new ImageView(context); routeButton.setBackgroundResource(R.drawable.floating_states); routeButton.setImageResource(R.drawable.navigate); routeButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); routeButton.setStateListAnimator(animator); routeButton.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } frameLayout.addView(routeButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28)); routeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(true); return; } } } if (myLocation != null) { try { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", myLocation.getLatitude(), myLocation.getLongitude(), messageObject.messageOwner.media.geo.lat, messageObject.messageOwner.media.geo._long))); getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } } } }); frameLayout.addView(locationButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100)); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(true); return; } } } if (myLocation != null && googleMap != null) { googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), googleMap.getMaxZoomLevel() - 4)); } } }); } else { searchWas = false; searching = false; mapViewClip = new FrameLayout(context); mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable()); if (adapter != null) { adapter.destroy(); } if (searchAdapter != null) { searchAdapter.destroy(); } listView = new ListView(context); listView.setAdapter(adapter = new LocationActivityAdapter(context)); listView.setVerticalScrollBarEnabled(false); listView.setDividerHeight(0); listView.setDivider(null); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (totalItemCount == 0) { return; } updateClipView(firstVisibleItem); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { if (delegate != null && userLocation != null) { TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo(); location.geo = new TLRPC.TL_geoPoint(); location.geo.lat = userLocation.getLatitude(); location.geo._long = userLocation.getLongitude(); delegate.didSelectLocation(location); } finishFragment(); } else { TLRPC.TL_messageMediaVenue object = adapter.getItem(position); if (object != null && delegate != null) { delegate.didSelectLocation(object); } finishFragment(); } } }); adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() { @Override public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) { if (!wasResults && !places.isEmpty()) { wasResults = true; } } }); adapter.setOverScrollHeight(overScrollHeight); frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); mapView = new MapView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (animatorSet != null) { animatorSet.cancel(); } animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.playTogether( ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop + -AndroidUtilities.dp(10)), ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f)); animatorSet.start(); } else if (ev.getAction() == MotionEvent.ACTION_UP) { if (animatorSet != null) { animatorSet.cancel(); } animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.playTogether( ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop), ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f)); animatorSet.start(); } } if (ev.getAction() == MotionEvent.ACTION_MOVE) { if (!userLocationMoved) { if (Build.VERSION.SDK_INT >= 11) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f)); animatorSet.start(); } else { locationButton.setVisibility(VISIBLE); } userLocationMoved = true; } if (googleMap != null && userLocation != null) { userLocation.setLatitude(googleMap.getCameraPosition().target.latitude); userLocation.setLongitude(googleMap.getCameraPosition().target.longitude); } adapter.setCustomLocation(userLocation); } return super.onInterceptTouchEvent(ev); } }; try { mapView.onCreate(null); } catch (Exception e) { FileLog.e("tmessages", e); } try { MapsInitializer.initialize(context); // googleMap = mapView.getMap(); } catch (Exception e) { FileLog.e("tmessages", e); } View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); mapViewClip.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM)); markerImageView = new ImageView(context); markerImageView.setImageResource(R.drawable.map_pin); mapViewClip.addView(markerImageView, LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); if (Build.VERSION.SDK_INT >= 11) { markerXImageView = new ImageView(context); markerXImageView.setAlpha(0.0f); markerXImageView.setImageResource(R.drawable.place_x); mapViewClip.addView(markerXImageView, LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); } mapViewClip.addView(locationButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(false); return; } } } if (myLocation != null && googleMap != null) { if (Build.VERSION.SDK_INT >= 11) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f)); animatorSet.start(); } else { locationButton.setVisibility(View.INVISIBLE); } adapter.setCustomLocation(null); userLocationMoved = false; googleMap.animateCamera(CameraUpdateFactory .newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()))); } } }); if (Build.VERSION.SDK_INT >= 11) { locationButton.setAlpha(0.0f); } else { locationButton.setVisibility(View.INVISIBLE); } emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.GONE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 100, 0, 0)); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); emptyTextLayout.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); FrameLayout frameLayoutEmpty = new FrameLayout(context); emptyTextLayout.addView(frameLayoutEmpty, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); searchListView = new ListView(context); searchListView.setVisibility(View.GONE); searchListView.setDividerHeight(0); searchListView.setDivider(null); searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context)); frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); searchListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position); if (object != null && delegate != null) { delegate.didSelectLocation(object); } finishFragment(); } }); if (googleMap != null) { userLocation = new Location("network"); userLocation.setLatitude(20.659322); userLocation.setLongitude(-11.406250); } frameLayout.addView(actionBar); } if (googleMap != null) { try { googleMap.setMyLocationEnabled(true); } catch (Exception e) { FileLog.e("tmessages", e); } googleMap.getUiSettings().setMyLocationButtonEnabled(false); googleMap.getUiSettings().setZoomControlsEnabled(false); googleMap.getUiSettings().setCompassEnabled(false); googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location location) { positionMarker(location); } }); positionMarker(myLocation = getLastLocation()); } return fragmentView; }