List of usage examples for android.widget LinearLayout getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:com.yaniv.online.MainActivity.java
public void updateParticipantUI(String pid) { Log.d(TAG, "updateParticipantUI()"); int i;//from ww w . j ava2 s. co m int arr[]; Log.d(TAG, "updateParticipantUI() - mParticipantPlayerPosition - " + mParticipantPlayerPosition); Log.d(TAG, "updateParticipantUI() - pid - " + pid); if (mParticipantPlayerPosition.get("top").equals(pid)) { LinearLayout layout = (LinearLayout) findViewById(R.id.player_top); ViewGroup.LayoutParams params = layout.getLayoutParams(); params.width = mParticipantCards.get(pid).size() * topCardWidthParam; layout.setLayoutParams(params); arr = cardsTopID; } else if (mParticipantPlayerPosition.get("left").equals(pid)) { arr = cardsLeftID; } else { arr = cardsRightID; } ImageView myCard; Log.d(TAG, "updateParticipantUI() - mParticipantCards.get(pid) - " + mParticipantCards.get(pid)); for (i = 0; i < mParticipantCards.get(pid).size() && i < 5; i++) { int drawable; if (yaniv) { drawable = cardsDrawable.get("" + mParticipantCards.get(pid).get(i).getKey()); } else { drawable = R.drawable.pile_1; } myCard = (ImageView) findViewById(arr[i]); myCard.setImageResource(drawable); myCard.setVisibility(View.VISIBLE); } for (; i < 5; i++) { myCard = (ImageView) findViewById(arr[i]); myCard.setVisibility(View.GONE); } }
From source file:com.yaniv.online.MainActivity.java
public void updateParticipantsCardsOnGameOverUI() { (findViewById(R.id.myPlayIcon)).setVisibility(View.GONE); (findViewById(R.id.topPlayIcon)).setVisibility(View.GONE); (findViewById(R.id.rightPlayIcon)).setVisibility(View.GONE); (findViewById(R.id.leftPlayIcon)).setVisibility(View.GONE); (findViewById(R.id.yaniv_declare)).setVisibility(View.GONE); TextView lastPlayerPick = (TextView) (findViewById(R.id.lastPlayerPick)); lastPlayerPick.setText(""); Log.d(TAG, "updateParticipantsCardsOnGameOverUI()"); int i;/*from w w w . j a va 2s . c o m*/ ImageView myCard; for (Participant p : mParticipants) { String id = p.getParticipantId(); if (!id.equals(mMyId)) { for (i = 0; i < mParticipantCards.get(id).size(); i++) { int arr[]; if (mParticipantPlayerPosition.get("top").equals(id)) { LinearLayout layout = (LinearLayout) findViewById(R.id.player_top); ViewGroup.LayoutParams params = layout.getLayoutParams(); params.width = mParticipantCards.get(id).size() * topCardWidthParam; layout.setLayoutParams(params); arr = cardsTopID; } else if (mParticipantPlayerPosition.get("left").equals(id)) { arr = cardsLeftID; } else { arr = cardsRightID; } int drawable = cardsDrawable.get("" + mParticipantCards.get(id).get(i).getKey()); myCard = (ImageView) findViewById(arr[i]); myCard.setImageResource(drawable); } } } }
From source file:com.yaniv.online.MainActivity.java
private void updateLayoutParams() { // Save my layout size LinearLayout layout = (LinearLayout) findViewById(R.id.myCardsLayout); // Gets the layout params that will allow you to resize the layout ViewGroup.LayoutParams params = layout.getLayoutParams(); myCardWidthParam = params.width / 5; // Save top player layout size layout = (LinearLayout) findViewById(R.id.player_top); // Gets the layout params that will allow you to resize the layout params = layout.getLayoutParams();/*from w w w. j a va2s . co m*/ topCardWidthParam = params.width / 5; }
From source file:com.yaniv.online.MainActivity.java
public void drawMyCards() { if (myCards == null) { Log.d(TAG, "Call on null object - myCards"); return;/*from w w w. j a va2s .c om*/ } int i; ImageView myCard; // Gets linearlayout LinearLayout layout = (LinearLayout) findViewById(R.id.myCardsLayout); // Gets the layout params that will allow you to resize the layout ViewGroup.LayoutParams params = layout.getLayoutParams(); // Changes the height and width to the specified *pixels* params.width = myCards.size() * myCardWidthParam; layout.setLayoutParams(params); for (i = 0; i < myCards.size(); i++) { int drawable = cardsDrawable.get("" + myCards.get(i).getKey()); myCard = (ImageView) findViewById(cardsID[i]); myCard.setImageResource(drawable); myCard.setVisibility(View.VISIBLE); } for (; i < 5; i++) { myCard = (ImageView) findViewById(cardsID[i]); myCard.setVisibility(View.GONE); } }
From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java
@Override public void onClick(View v) { // Toast.makeText(this,"clicked ..."+v.getId(),3000).show(); ImageView button = null;//www.jav a 2 s . c om LinearLayout l = null; int grid = 0; int testid = 0; boolean buttonfound = false; int id = v.getId(); if (id == R.id.download_header || id == R.id.btn_download_toggle) { if (total_download_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test1_grid; testid = TestResult.DOWNLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.download_content); button = (ImageView) findViewById(R.id.btn_download_toggle); } if (id == R.id.upload_header || id == R.id.btn_upload_toggle) { if (total_upload_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test2_grid; testid = TestResult.UPLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.upload_content); button = (ImageView) findViewById(R.id.btn_upload_toggle); } if (id == R.id.latency_header || id == R.id.btn_latency_toggle) { if (total_latency_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test3_grid; testid = TestResult.LATENCY_TEST_ID; l = (LinearLayout) findViewById(R.id.latency_content); button = (ImageView) findViewById(R.id.btn_latency_toggle); } if (id == R.id.packetloss_header || id == R.id.btn_packetloss_toggle) { if (total_packetloss_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test4_grid; testid = TestResult.PACKETLOSS_TEST_ID; l = (LinearLayout) findViewById(R.id.packetloss_content); button = (ImageView) findViewById(R.id.btn_packetloss_toggle); } if (id == R.id.jitter_header || id == R.id.btn_jitter_toggle) { if (total_jitter_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test5_grid; testid = TestResult.JITTER_TEST_ID; l = (LinearLayout) findViewById(R.id.jitter_content); button = (ImageView) findViewById(R.id.btn_jitter_toggle); } // actions if (buttonfound) { if (l.getVisibility() == View.INVISIBLE) { button.setBackgroundResource(R.drawable.btn_up); button.setContentDescription(getString(R.string.close_panel)); // graphHandler1.update(); l.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); target_height = l.getMeasuredHeight(); clearGrid(grid); loadDownloadGrid(testid, grid, 0, 5); l.getLayoutParams().height = 0; l.setVisibility(View.VISIBLE); ResizeAnimation animation = null; animation = new ResizeAnimation(l, target_height, 0, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } }); l.startAnimation(animation); } else { ResizeAnimation animation = null; int required_height = l.getMeasuredHeight(); animation = new ResizeAnimation(l, 0, target_height, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); MyAnimationListener animationListener = new MyAnimationListener(); animationListener.setView(l); animation.setAnimationListener(animationListener); l.startAnimation(animation); button.setBackgroundResource(R.drawable.btn_down); button.setContentDescription(getString(R.string.open_panel)); } } }
From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java
public void updateViews() { this.setOrientation(VERTICAL); float scale = getResources().getDisplayMetrics().density; this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding), getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding)); LinearLayout timeStartEndLayout = new LinearLayout(getContext()); TextView timeStartEndText = new TextView(getContext()); timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip)); timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL); }//w w w .j a va2 s . c o m } // Check if we have Realtime for start and or end. boolean hasRealtime = false; Pair<Date, RealTimeState> transitTime = trip.departsAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } else { transitTime = trip.arrivesAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } } // if (hasRealtime) { // ImageView liveDrawable = new ImageView(getContext()); // liveDrawable.setImageResource(R.drawable.ic_live); // ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0); // timeStartEndLayout.addView(liveDrawable); // // AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f); // animation1.setDuration(600); // animation1.setRepeatMode(Animation.REVERSE); // animation1.setRepeatCount(Animation.INFINITE); // // liveDrawable.startAnimation(animation1); // } timeStartEndLayout.addView(timeStartEndText); LinearLayout startAndEndPointLayout = new LinearLayout(getContext()); TextView startAndEndPoint = new TextView(getContext()); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); startAndEndPoint.setText(String.format("%s %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()), bidiFormatter.unicodeWrap(trip.toStop().getName()))); startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL); } } ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale)); startAndEndPointLayout.addView(startAndEndPoint); RelativeLayout timeLayout = new RelativeLayout(getContext()); LinearLayout routeChanges = new LinearLayout(getContext()); routeChanges.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); changesLayoutParams.gravity = Gravity.CENTER_VERTICAL; if (trip.hasAlertsOrNotes()) { ImageView warning = new ImageView(getContext()); warning.setImageResource(R.drawable.ic_trip_deviation); ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0); routeChanges.addView(warning); } int currentTransportCount = 1; int transportCount = trip.getLegs().size(); for (Leg leg : trip.getLegs()) { if (!leg.isTransit() && transportCount > 3) { if (leg.getDistance() < 150) { continue; } } if (currentTransportCount > 1 && transportCount >= currentTransportCount) { ImageView separator = new ImageView(getContext()); separator.setImageResource(R.drawable.transport_separator); ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0); separator.setLayoutParams(changesLayoutParams); routeChanges.addView(separator); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(separator, -1f); } } ImageView changeImageView = new ImageView(getContext()); Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg); changeImageView.setImageDrawable(transportDrawable); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(changeImageView, -1f); } ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0); changeImageView.setLayoutParams(changesLayoutParams); routeChanges.addView(changeImageView); if (currentTransportCount <= 3) { String lineName = leg.getRouteShortName(); if (!TextUtils.isEmpty(lineName)) { TextView lineNumberView = new TextView(getContext()); lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan( LegUtil.getColor(getContext(), leg), Color.WHITE, ViewHelper.dipsToPix(getContext().getResources(), 4)); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(lineName); sb.append(' '); sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); lineNumberView.setText(sb); ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale), (int) (2 * scale), 0); lineNumberView.setLayoutParams(changesLayoutParams); routeChanges.addView(lineNumberView); } } currentTransportCount++; } TextView durationText = new TextView(getContext()); durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000)); durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); durationText.setTypeface(Typeface.DEFAULT_BOLD); timeLayout.addView(routeChanges); timeLayout.addView(durationText); RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText .getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END); } else { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } durationText.setLayoutParams(durationTextParams); View divider = new View(getContext()); ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); divider.setLayoutParams(dividerParams); this.addView(timeLayout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams(); params.height = LayoutParams.MATCH_PARENT; params.addRule(RelativeLayout.CENTER_VERTICAL); routeChanges.setLayoutParams(params); this.addView(startAndEndPointLayout); this.addView(timeStartEndLayout); if (mShowDivider) { this.addView(divider); } }
From source file:self.philbrown.droidQuery.Example.ExampleActivity.java
/** * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>. * <br>/*from ww w. j ava2 s.co m*/ * For this example, the public stream is retrieved using <em>ajax</em>, and for each message * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to * retrieve the thumbnail image for the user. As all these events occur on a background thread, the * main ScrollView is populated with cells and displayed to the user. * <br> * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will * trigger the global start and stop events (which show a progress indicator, using a droidQuery * extension). The image get requests are not global, so they will not trigger global events. */ public void refresh() { $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json") .type("GET").error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete request: " + reason); } }).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason JSONObject json = (JSONObject) params[0]; String reason = (String) params[1]; try { Map<String, ?> map = $.map(json); JSONArray datas = (JSONArray) map.get("data"); if (datas.length() != 0) { //clear old subviews in layout $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove(); //get each message infos and create a cell for (int i = 0; i < datas.length(); i++) { JSONObject jdata = (JSONObject) datas.get(i); Map<String, ?> data = $.map(jdata); String text = data.get("text").toString(); Map<String, ?> user = $.map((JSONObject) data.get("user")); String username = user.get("username").toString(); String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url"); //get Avatar image in a new task (but go ahead and create the cell for now) LinearLayout cell = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); cell_params.bottomMargin = 5; cell.setLayoutParams(cell_params); cell.setOrientation(LinearLayout.HORIZONTAL); cell.setWeightSum(8); cell.setPadding(5, 5, 5, 5); cell.setBackgroundColor(Color.parseColor("#333333")); final LinearLayout fcell = cell; //contains the image location ImageView image = new ImageView(ExampleActivity.this); image.setId(99); LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); ip_params.weight = 2; image.setLayoutParams(ip_params); image.setPadding(0, 0, 5, 0); $.with(image).attr("alpha", 0.0f); cell.addView(image); final ImageView fimage = image; //the text location in the cell LinearLayout body = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); body_params.weight = 5; body.setLayoutParams(body_params); body.setOrientation(LinearLayout.VERTICAL); body.setGravity(Gravity.CENTER_VERTICAL); cell.addView(body); //the username TextView name = new TextView(ExampleActivity.this); LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); name.setLayoutParams(name_params); name.setTextColor(Color.GRAY); name.setText(username); body.addView(name); //the message TextView message = new TextView(ExampleActivity.this); LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); message.setLayoutParams(msg_params); message.setTextColor(Color.WHITE); message.setTextSize(18); message.setText(text); body.addView(message); CheckBox checkbox = new CheckBox(ExampleActivity.this); LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); box_params.weight = 1; checkbox.setLayoutParams(box_params); cell.addView(checkbox); $.with(ExampleActivity.this, R.id.example_layout).add(cell); //$.with(fimage).image(avatarURL, 200, 200, $.noop()); $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200) .imageWidth(200).global(false).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason Bitmap src = (Bitmap) params[0]; String reason = (String) params[1]; $.with(fimage).val(src); try { $.with(fimage) .fadeIn(new AnimationOptions("{ duration: 400 }")); } catch (Throwable e) { e.printStackTrace(); } LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell .getLayoutParams(); try { lparams.height = Math.min(src.getWidth(), fimage.getWidth()); } catch (Throwable t) { //ignore NPE } fcell.setLayoutParams(lparams); } }).error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete image request: " + reason); } })); } } else { Log.w("app.net client", "could not update data"); } } catch (Throwable t) { t.printStackTrace(); } } })); }
From source file:org.quantumbadger.redreader.activities.ImageViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences); if (solidblack) getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); final Intent intent = getIntent(); mUrl = General.uriFromString(intent.getDataString()); final RedditPost src_post = intent.getParcelableExtra("post"); if (mUrl == null) { General.quickToast(this, "Invalid URL. Trying web browser."); revertToWeb();// w w w . java2 s . c om return; } Log.i("ImageViewActivity", "Loading URL " + mUrl.toString()); final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); final LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(progressBar); CacheManager.getInstance(this) .makeRequest(mRequest = new CacheRequest(mUrl, RedditAccountManager.getAnon(), null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, this) { private void setContentView(View v) { layout.removeAllViews(); layout.addView(v); v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context.getApplicationContext(), new RRError(null, null, t)); } @Override protected void onDownloadNecessary() { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(true); } }); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { // TODO handle properly mRequest = null; progressBar.setVisibility(View.GONE); layout.addView(new ErrorView(ImageViewActivity.this, error)); } }); } @Override protected void onProgress(final boolean authorizationInProgress, final long bytesRead, final long totalBytes) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(authorizationInProgress); progressBar.setProgress((int) ((100 * bytesRead) / totalBytes)); } }); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, final String mimetype) { if (mimetype == null || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) { revertToWeb(); return; } final InputStream cacheFileInputStream; try { cacheFileInputStream = cacheFile.getInputStream(); } catch (IOException e) { notifyFailure(RequestFailureType.PARSE, e, null, "Could not read existing cached image."); return; } if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } if (Constants.Mime.isVideo(mimetype)) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; try { final RelativeLayout layout = new RelativeLayout(context); layout.setGravity(Gravity.CENTER); final VideoView videoView = new VideoView(ImageViewActivity.this); videoView.setVideoURI(cacheFile.getUri()); layout.addView(videoView); setContentView(layout); layout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; layout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; videoView.setLayoutParams( new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(true); videoView.start(); } }); videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(final MediaPlayer mediaPlayer, final int i, final int i1) { revertToWeb(); return true; } }); videoView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { finish(); return true; } }); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } catch (Throwable e) { General.quickToast(context, R.string.imageview_invalid_video); revertToWeb(); } } }); } else if (Constants.Mime.isImageGif(mimetype)) { final PrefsUtility.GifViewMode gifViewMode = PrefsUtility .pref_behaviour_gifview_mode(context, sharedPreferences); if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) { revertToWeb(); return; } else if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { LinkHandler.openWebBrowser(ImageViewActivity.this, Uri.parse(mUrl.toString())); finish(); } }); return; } if (AndroidApi.isIceCreamSandwichOrLater() && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; try { final GIFView gifView = new GIFView(ImageViewActivity.this, cacheFileInputStream); setContentView(gifView); gifView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } catch (Throwable e) { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } } }); } else { gifThread = new GifDecoderThread(cacheFileInputStream, new GifDecoderThread.OnGifLoadedListener() { public void onGifLoaded() { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); setContentView(imageView); gifThread.setView(imageView); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } }); } public void onOutOfMemory() { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } public void onGifInvalid() { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } }); gifThread.start(); } } else { final ImageTileSource imageTileSource; try { final long bytes = cacheFile.getSize(); final byte[] buf = new byte[(int) bytes]; try { new DataInputStream(cacheFileInputStream).readFully(buf); } catch (IOException e) { throw new RuntimeException(e); } try { imageTileSource = new ImageTileSourceWholeBitmap(buf); } catch (Throwable t) { Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t); General.quickToast(context, R.string.imageview_decode_failed); revertToWeb(); return; } } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); return; } AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; mImageViewDisplayerManager = new ImageViewDisplayListManager(imageTileSource, ImageViewActivity.this); surfaceView = new RRGLSurfaceView(ImageViewActivity.this, mImageViewDisplayerManager); setContentView(surfaceView); surfaceView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); if (mIsPaused) { surfaceView.onPause(); } else { surfaceView.onResume(); } } }); } } }); final RedditPreparedPost post = src_post == null ? null : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false, false, RedditAccountManager.getInstance(this).getDefaultAccount(), false); final FrameLayout outerFrame = new FrameLayout(this); outerFrame.addView(layout); if (post != null) { final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this); final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this, new BezelSwipeOverlay.BezelSwipeListener() { public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) { toolbarOverlay.setContents( post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay)); toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT : SideToolbarOverlay.SideToolbarPosition.RIGHT); return true; } public boolean onTap() { if (toolbarOverlay.isShown()) { toolbarOverlay.hide(); return true; } return false; } }); outerFrame.addView(bezelOverlay); outerFrame.addView(toolbarOverlay); bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; } setContentView(outerFrame); }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
protected void updateMessageDetail(final boolean isUpdate) { T.UI();//from w w w.j av a2 s . c o m // Set sender avatar ImageView avatarImage = (ImageView) findViewById(R.id.avatar); String sender = mCurrentMessage.sender; setAvatar(avatarImage, sender); // Set sender name TextView senderView = (TextView) findViewById(R.id.sender); final String senderName = mFriendsPlugin.getName(sender); senderView.setText(senderName == null ? sender : senderName); // Set timestamp TextView timestampView = (TextView) findViewById(R.id.timestamp); timestampView.setText(TimeUtils.getDayTimeStr(this, mCurrentMessage.timestamp * 1000)); // Set clickable region on top to go to friends detail final RelativeLayout messageHeader = (RelativeLayout) findViewById(R.id.message_header); messageHeader.setOnClickListener(getFriendDetailOnClickListener(mCurrentMessage.sender)); messageHeader.setVisibility(View.VISIBLE); // Set message TextView messageView = (TextView) findViewById(R.id.message); WebView web = (WebView) findViewById(R.id.webview); FrameLayout flay = (FrameLayout) findViewById(R.id.message_details); Resources resources = getResources(); flay.setBackgroundColor(resources.getColor(R.color.mc_background)); boolean showBranded = false; int darkSchemeTextColor = resources.getColor(android.R.color.primary_text_dark); int lightSchemeTextColor = resources.getColor(android.R.color.primary_text_light); senderView.setTextColor(lightSchemeTextColor); timestampView.setTextColor(lightSchemeTextColor); BrandingResult br = null; if (!TextUtils.isEmptyOrWhitespace(mCurrentMessage.branding)) { boolean brandingAvailable = false; try { brandingAvailable = mMessagingPlugin.getBrandingMgr().isBrandingAvailable(mCurrentMessage.branding); } catch (BrandingFailureException e1) { L.d(e1); } try { if (brandingAvailable) { br = mMessagingPlugin.getBrandingMgr().prepareBranding(mCurrentMessage); WebSettings settings = web.getSettings(); settings.setJavaScriptEnabled(false); settings.setBlockNetworkImage(false); web.loadUrl("file://" + br.file.getAbsolutePath()); web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); if (br.color != null) { flay.setBackgroundColor(br.color); } if (!br.showHeader) { messageHeader.setVisibility(View.GONE); MarginLayoutParams mlp = (MarginLayoutParams) web.getLayoutParams(); mlp.setMargins(0, 0, 0, mlp.bottomMargin); } else if (br.scheme == ColorScheme.dark) { senderView.setTextColor(darkSchemeTextColor); timestampView.setTextColor(darkSchemeTextColor); } showBranded = true; } else { mMessagingPlugin.getBrandingMgr().queueGenericBranding(mCurrentMessage.branding); } } catch (BrandingFailureException e) { L.bug("Could not display message with branding: branding is available, but prepareBranding failed", e); } } if (showBranded) { web.setVisibility(View.VISIBLE); messageView.setVisibility(View.GONE); } else { web.setVisibility(View.GONE); messageView.setVisibility(View.VISIBLE); messageView.setText(mCurrentMessage.message); } // Add list of members who did not ack yet FlowLayout memberSummary = (FlowLayout) findViewById(R.id.member_summary); memberSummary.removeAllViews(); SortedSet<MemberStatusTO> memberSummarySet = new TreeSet<MemberStatusTO>(getMemberstatusComparator()); for (MemberStatusTO ms : mCurrentMessage.members) { if ((ms.status & MessagingPlugin.STATUS_ACKED) != MessagingPlugin.STATUS_ACKED && !ms.member.equals(mCurrentMessage.sender)) { memberSummarySet.add(ms); } } FlowLayout.LayoutParams flowLP = new FlowLayout.LayoutParams(2, 0); for (MemberStatusTO ms : memberSummarySet) { FrameLayout fl = new FrameLayout(this); fl.setLayoutParams(flowLP); memberSummary.addView(fl); fl.addView(createParticipantView(ms)); } memberSummary.setVisibility(memberSummarySet.size() < 2 ? View.GONE : View.VISIBLE); // Add members statuses final LinearLayout members = (LinearLayout) findViewById(R.id.members); members.removeAllViews(); final String myEmail = mService.getIdentityStore().getIdentity().getEmail(); boolean isMember = false; mSomebodyAnswered = false; for (MemberStatusTO ms : mCurrentMessage.members) { boolean showMember = true; View view = getLayoutInflater().inflate(R.layout.message_member_detail, null); // Set receiver avatar RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.avatar); rl.addView(createParticipantView(ms)); // Set receiver name TextView receiverView = (TextView) view.findViewById(R.id.receiver); final String memberName = mFriendsPlugin.getName(ms.member); receiverView.setText(memberName == null ? sender : memberName); // Set received timestamp TextView receivedView = (TextView) view.findViewById(R.id.received_timestamp); if ((ms.status & MessagingPlugin.STATUS_RECEIVED) == MessagingPlugin.STATUS_RECEIVED) { final String humanTime = TimeUtils.getDayTimeStr(this, ms.received_timestamp * 1000); if (ms.member.equals(mCurrentMessage.sender)) receivedView.setText(getString(R.string.sent_at, humanTime)); else receivedView.setText(getString(R.string.received_at, humanTime)); } else { receivedView.setText(R.string.not_yet_received); } // Set replied timestamp TextView repliedView = (TextView) view.findViewById(R.id.acked_timestamp); if ((ms.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED) { mSomebodyAnswered = true; String acked_timestamp = TimeUtils.getDayTimeStr(this, ms.acked_timestamp * 1000); if (ms.button_id != null) { ButtonTO button = null; for (ButtonTO b : mCurrentMessage.buttons) { if (b.id.equals(ms.button_id)) { button = b; break; } } if (button == null) { repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); } else { repliedView.setText(getString(R.string.replied_at, button.caption, acked_timestamp)); } } else { if (ms.custom_reply == null) { // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); } else repliedView.setText(getString(R.string.replied_at, ms.custom_reply, acked_timestamp)); } } else { repliedView.setText(R.string.not_yet_replied); showMember = !ms.member.equals(mCurrentMessage.sender); } if (br != null && br.scheme == ColorScheme.dark) { receiverView.setTextColor(darkSchemeTextColor); receivedView.setTextColor(darkSchemeTextColor); repliedView.setTextColor(darkSchemeTextColor); } else { receiverView.setTextColor(lightSchemeTextColor); receivedView.setTextColor(lightSchemeTextColor); repliedView.setTextColor(lightSchemeTextColor); } if (showMember) members.addView(view); isMember |= ms.member.equals(myEmail); } boolean isLocked = (mCurrentMessage.flags & MessagingPlugin.FLAG_LOCKED) == MessagingPlugin.FLAG_LOCKED; boolean canEdit = isMember && !isLocked; // Add attachments LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachment_layout); attachmentLayout.removeAllViews(); if (mCurrentMessage.attachments.length > 0) { attachmentLayout.setVisibility(View.VISIBLE); for (final AttachmentTO attachment : mCurrentMessage.attachments) { View v = getLayoutInflater().inflate(R.layout.attachment_item, null); ImageView attachment_image = (ImageView) v.findViewById(R.id.attachment_image); if (AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(attachment.content_type) || AttachmentViewerActivity.CONTENT_TYPE_PNG.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_img); } else if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_pdf); } else if (AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4 .equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_video); } else { attachment_image.setImageResource(R.drawable.attachment_unknown); L.d("attachment.content_type not known: " + attachment.content_type); } TextView attachment_text = (TextView) v.findViewById(R.id.attachment_text); attachment_text.setText(attachment.name); v.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String downloadUrlHash = mMessagingPlugin .attachmentDownloadUrlHash(attachment.download_url); File attachmentsDir; try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), null); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } boolean attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); if (!attachmentAvailable) { try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), mCurrentMessage.key); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); } if (!mService.getNetworkConnectivityManager().isConnected() && !attachmentAvailable) { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(R.string.no_internet_connection_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } if (IOUtils.shouldCheckExternalStorageAvailable()) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // Its all oke } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (!attachmentAvailable) { L.d("Unable to write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } else { L.d("Unable to read or write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } L.d("attachment.content_type: " + attachment.content_type); L.d("attachment.download_url: " + attachment.download_url); L.d("attachment.name: " + attachment.name); L.d("attachment.size: " + attachment.size); if (AttachmentViewerActivity.supportsContentType(attachment.content_type)) { Intent i = new Intent(ServiceMessageDetailActivity.this, AttachmentViewerActivity.class); i.putExtra("thread_key", mCurrentMessage.getThreadKey()); i.putExtra("message", mCurrentMessage.key); i.putExtra("content_type", attachment.content_type); i.putExtra("download_url", attachment.download_url); i.putExtra("name", attachment.name); i.putExtra("download_url_hash", downloadUrlHash); startActivity(i); } else { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(getString(R.string.attachment_can_not_be_displayed_in_your_version, getString(R.string.app_name))); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); attachmentLayout.addView(v); } } else { attachmentLayout.setVisibility(View.GONE); } LinearLayout widgetLayout = (LinearLayout) findViewById(R.id.widget_layout); if (mCurrentMessage.form == null) { widgetLayout.setVisibility(View.GONE); } else { widgetLayout.setVisibility(View.VISIBLE); widgetLayout.setEnabled(canEdit); displayWidget(widgetLayout, br); } // Add buttons TableLayout tableLayout = (TableLayout) findViewById(R.id.buttons); tableLayout.removeAllViews(); for (final ButtonTO button : mCurrentMessage.buttons) { addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.form == null && (mCurrentMessage.flags & MessagingPlugin.FLAG_ALLOW_DISMISS) == MessagingPlugin.FLAG_ALLOW_DISMISS) { ButtonTO button = new ButtonTO(); button.caption = "Roger that!"; addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.broadcast_type != null) { L.d("Show broadcast spam control"); final RelativeLayout broadcastSpamControl = (RelativeLayout) findViewById(R.id.broadcast_spam_control); View broadcastSpamControlBorder = findViewById(R.id.broadcast_spam_control_border); final View broadcastSpamControlDivider = findViewById(R.id.broadcast_spam_control_divider); final LinearLayout broadcastSpamControlTextContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_text_container); TextView broadcastSpamControlText = (TextView) findViewById(R.id.broadcast_spam_control_text); final LinearLayout broadcastSpamControlSettingsContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_settings_container); TextView broadcastSpamControlSettingsText = (TextView) findViewById( R.id.broadcast_spam_control_settings_text); TextView broadcastSpamControlIcon = (TextView) findViewById(R.id.broadcast_spam_control_icon); broadcastSpamControlIcon.setTypeface(mFontAwesomeTypeFace); broadcastSpamControlIcon.setText(R.string.fa_bell); final FriendBroadcastInfo fbi = mFriendsPlugin.getFriendBroadcastFlowForMfr(mCurrentMessage.sender); if (fbi == null) { L.bug("BroadcastData was null for: " + mCurrentMessage.sender); collapseDetails(DETAIL_SECTIONS); return; } broadcastSpamControl.setVisibility(View.VISIBLE); broadcastSpamControlSettingsContainer.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { L.d("goto broadcast settings"); PressMenuIconRequestTO request = new PressMenuIconRequestTO(); request.coords = fbi.coords; request.static_flow_hash = fbi.staticFlowHash; request.hashed_tag = fbi.hashedTag; request.generation = fbi.generation; request.service = mCurrentMessage.sender; mContext = "MENU_" + UUID.randomUUID().toString(); request.context = mContext; request.timestamp = System.currentTimeMillis() / 1000; showTransmitting(null); Map<String, Object> userInput = new HashMap<String, Object>(); userInput.put("request", request.toJSONMap()); userInput.put("func", "com.mobicage.api.services.pressMenuItem"); MessageFlowRun mfr = new MessageFlowRun(); mfr.staticFlowHash = fbi.staticFlowHash; try { JsMfr.executeMfr(mfr, userInput, mService, true); } catch (EmptyStaticFlowException ex) { completeTransmit(null); AlertDialog.Builder builder = new AlertDialog.Builder(ServiceMessageDetailActivity.this); builder.setMessage(ex.getMessage()); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } } }); UIUtils.showHint(this, mService, HINT_BROADCAST, R.string.hint_broadcast, mCurrentMessage.broadcast_type, mFriendsPlugin.getName(mCurrentMessage.sender)); broadcastSpamControlText .setText(getString(R.string.broadcast_subscribed_to, mCurrentMessage.broadcast_type)); broadcastSpamControlSettingsText.setText(fbi.label); int ligthAlpha = 180; int darkAlpha = 70; int alpha = ligthAlpha; if (br != null && br.scheme == ColorScheme.dark) { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.black)); broadcastSpamControlBorder.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(darkSchemeTextColor); activity.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlText.setTextColor(lightSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(lightSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(lightSchemeTextColor), Color.green(lightSchemeTextColor), Color.blue(lightSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); alpha = darkAlpha; } else { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.white)); broadcastSpamControlBorder.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(lightSchemeTextColor); activity.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlText.setTextColor(darkSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(darkSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(darkSchemeTextColor), Color.green(darkSchemeTextColor), Color.blue(darkSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); } if (br != null && br.color != null) { int alphaColor = Color.argb(alpha, Color.red(br.color), Color.green(br.color), Color.blue(br.color)); broadcastSpamControl.setBackgroundColor(alphaColor); } mService.postOnUIHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { int maxHeight = broadcastSpamControl.getHeight(); broadcastSpamControlDivider.getLayoutParams().height = maxHeight; broadcastSpamControlDivider.requestLayout(); broadcastSpamControlSettingsContainer.getLayoutParams().height = maxHeight; broadcastSpamControlSettingsContainer.requestLayout(); broadcastSpamControlTextContainer.getLayoutParams().height = maxHeight; broadcastSpamControlTextContainer.requestLayout(); int broadcastSpamControlWidth = broadcastSpamControl.getWidth(); android.view.ViewGroup.LayoutParams lp = broadcastSpamControlSettingsContainer .getLayoutParams(); lp.width = broadcastSpamControlWidth / 4; broadcastSpamControlSettingsContainer.setLayoutParams(lp); } }); } if (!isUpdate) collapseDetails(DETAIL_SECTIONS); }
From source file:com.zoffcc.applications.zanavi.Navit.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (last_orientation != newConfig.orientation) { // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { // setContentView(R.layout.main_layout); // -- bottom bar -- int h = NavitGraphics.mCanvasHeight; try { int h001; android.view.ViewGroup.LayoutParams lp001; View v003 = (View) findViewById(R.id.osd_nextturn_new); h001 = getResources().getDimensionPixelSize(R.dimen.osd_nextturn_new_height); lp001 = v003.getLayoutParams(); lp001.height = h001;/* w w w . jav a 2 s . com*/ v003.requestLayout(); v003 = (View) findViewById(R.id.bottom_bar); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_bar_height); lp001 = v003.getLayoutParams(); lp001.height = h001; v003.requestLayout(); LinearLayout v002 = (LinearLayout) findViewById(R.id.bottom_slide_view); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_slide_view_height); lp001 = v002.getLayoutParams(); lp001.height = h001; v002.requestLayout(); v003 = (View) findViewById(R.id.osd_timetodest_new); h001 = getResources().getDimensionPixelSize(R.dimen.osd_timetodest_new_height); lp001 = v003.getLayoutParams(); lp001.height = h001; v003.requestLayout(); v002 = (LinearLayout) findViewById(R.id.bottom_line_container); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_line_container_height); lp001 = v002.getLayoutParams(); lp001.height = h001; v002.requestLayout(); RelativeLayout v001 = (RelativeLayout) findViewById(R.id.gui_top_container); h001 = getResources().getDimensionPixelSize(R.dimen.gui_top_container_height); lp001 = v001.getLayoutParams(); lp001.height = h001; v001.requestLayout(); int ml = getResources().getDimensionPixelSize(R.dimen.margin_left_speeding); int mb = getResources().getDimensionPixelSize(R.dimen.margin_bottom_speeding); v003 = (View) findViewById(R.id.view_speeding); RelativeLayout.LayoutParams relativeParams_001 = (RelativeLayout.LayoutParams) v003 .getLayoutParams(); relativeParams_001.setMargins(ml, 0, 0, mb); // left, top, right, bottom v003.setLayoutParams(relativeParams_001); v003.requestLayout(); smaller_top_bar(true); // Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); bottom_bar_px = (int) getResources().getDimension(R.dimen.gui_top_container_height); bottom_bar_slider_shadow_px = (int) getResources() .getDimension(R.dimen.bottom_slide_view_shadow_compat_height); Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom } catch (Exception e) { Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom } Navit.bottom_y_margin_bottom_bar_touch = Navit.cur_y_margin_bottom_bar_touch; // -- bottom bar -- } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { // setContentView(R.layout.main_layout); // -- bottom bar -- int h = NavitGraphics.mCanvasHeight; try { int h001; android.view.ViewGroup.LayoutParams lp001; View v003 = (View) findViewById(R.id.osd_nextturn_new); h001 = getResources().getDimensionPixelSize(R.dimen.osd_nextturn_new_height); lp001 = v003.getLayoutParams(); lp001.height = h001; v003.requestLayout(); v003 = (View) findViewById(R.id.bottom_bar); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_bar_height); lp001 = v003.getLayoutParams(); lp001.height = h001; v003.requestLayout(); LinearLayout v002 = (LinearLayout) findViewById(R.id.bottom_slide_view); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_slide_view_height); lp001 = v002.getLayoutParams(); lp001.height = h001; v002.requestLayout(); v003 = (View) findViewById(R.id.osd_timetodest_new); h001 = getResources().getDimensionPixelSize(R.dimen.osd_timetodest_new_height); lp001 = v003.getLayoutParams(); lp001.height = h001; v003.requestLayout(); v002 = (LinearLayout) findViewById(R.id.bottom_line_container); h001 = getResources().getDimensionPixelSize(R.dimen.bottom_line_container_height); lp001 = v002.getLayoutParams(); lp001.height = h001; v002.requestLayout(); RelativeLayout v001 = (RelativeLayout) findViewById(R.id.gui_top_container); h001 = getResources().getDimensionPixelSize(R.dimen.gui_top_container_height); lp001 = v001.getLayoutParams(); lp001.height = h001; v001.requestLayout(); int ml = getResources().getDimensionPixelSize(R.dimen.margin_left_speeding); int mb = getResources().getDimensionPixelSize(R.dimen.margin_bottom_speeding); v003 = (View) findViewById(R.id.view_speeding); RelativeLayout.LayoutParams relativeParams_001 = (RelativeLayout.LayoutParams) v003 .getLayoutParams(); relativeParams_001.setMargins(ml, 0, 0, mb); // left, top, right, bottom v003.setLayoutParams(relativeParams_001); v003.requestLayout(); smaller_top_bar(false); // Toast.makeText(this, "protrait", Toast.LENGTH_SHORT).show(); bottom_bar_px = (int) getResources().getDimension(R.dimen.gui_top_container_height); bottom_bar_slider_shadow_px = (int) getResources() .getDimension(R.dimen.bottom_slide_view_shadow_compat_height); Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom } catch (Exception e) { Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom } Navit.bottom_y_margin_bottom_bar_touch = Navit.cur_y_margin_bottom_bar_touch; // -- bottom bar -- } last_orientation = newConfig.orientation; } }