Example usage for android.widget RelativeLayout getHeight

List of usage examples for android.widget RelativeLayout getHeight

Introduction

In this page you can find the example usage for android.widget RelativeLayout getHeight.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *//*from www  . ja  v a 2  s  .  co m*/
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

private void startEditFragment(final View view, final int position) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);/*  w  w w . j  a  va 2s .co m*/
    listAdapter.saveData();

    Source dataItem = listAdapter.getItem(position);
    final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment();
    sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable());
    Bundle arguments = new Bundle();
    arguments.putInt("position", position);
    arguments.putString("type", dataItem.getType());
    arguments.putString("title", dataItem.getTitle());
    arguments.putString("data", dataItem.getData());
    arguments.putInt("num", dataItem.getNum());
    arguments.putBoolean("use", dataItem.isUse());
    arguments.putBoolean("preview", dataItem.isPreview());
    String imageFileName = dataItem.getImageFile().getAbsolutePath();
    if (imageFileName != null && imageFileName.length() > 0) {
        arguments.putString("image", imageFileName);
    } else {
        arguments.putString("image", "");
    }

    arguments.putBoolean("use_time", dataItem.isUseTime());
    arguments.putString("time", dataItem.getTime());

    sourceInfoFragment.setArguments(arguments);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final CardView sourceCard = (CardView) view.findViewById(R.id.source_card);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float cardStartShadow = sourceCard.getPaddingLeft();
    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final int viewStartPadding = view.getPaddingLeft();
    final float textStartX = sourceTitle.getX();
    final float textStartY = sourceTitle.getY();
    final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension(
                                                            TypedValue.COMPLEX_UNIT_DIP,
                                                            8,
                                                            getResources().getDisplayMetrics());*/

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment")
                        .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime));
            int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime));
            sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0);
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding;
            view.setPadding(newPadding, 0, newPadding, 0);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            sourceTitle.setY(textStartY + interpolatedTime * textTranslationY);
            sourceTitle.setX(textStartX + viewStartPadding - newPadding);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE));
    titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setTextColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent));
    titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue());
        }
    });

    ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f);
    imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            imageOverlay.setAlpha((Float) animation.getAnimatedValue());
        }
    });

    int transitionTime = INFO_ANIMATION_TIME;

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(transitionTime);
    cardColorAnimation.setDuration(transitionTime);
    titleColorAnimation.setDuration(transitionTime);
    titleShadowAlphaAnimation.setDuration(transitionTime);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);
    titleColorAnimation.setInterpolator(decelerateInterpolator);
    titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator);

    if (imageOverlay.getAlpha() > 0) {
        imageOverlayAlphaAnimation.start();
    }

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }
    }, (long) (transitionTime * 1.1f));

    needsListReset = true;
    view.startAnimation(animation);
    cardColorAnimation.start();
    titleColorAnimation.start();
    titleShadowAlphaAnimation.start();
}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override/* w  w  w  .  ja  v a 2  s. co m*/
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("ACE startup.", // Event category (required)
                    "User started ACE.", // Event action (required)
                    "User started ACE.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.jams.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override//from w w  w  .  ja va  2 s.  c  om
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Genesis Music startup.", // Event category (required)
                    "User started Genesis Music.", // Event action (required)
                    "User started Genesis Music.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.Duo.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override/* ww w .ja  va2  s. c o m*/
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Jams startup.", // Event category (required)
                    "User started Jams.", // Event action (required)
                    "User started Jams.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.jelly.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override/*w  w  w.j  a  va2 s  .  c  om*/
public void onCreate(Bundle savedInstanceState) {

    Parse.initialize(this, "aZiGV1G02m1Mj3SaaD9riuyrucDclK7abpc2Ibz3",
            "eCPoMrWrFnnHPVmBbDDIAFAMTA5EJLgtHLS2U9St");
    Map<String, String> dimensions = new HashMap<String, String>();
    // What type of news is this?
    dimensions.put("category", "politics");
    // Is it a weekday or the weekend?
    dimensions.put("dayType", "weekday");
    // Send the dimensions to Parse along with the 'read' event

    ParseAnalytics.trackEvent("read", dimensions);

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Jelly startup.", // Event category (required)
                    "User started Jelly.", // Event action (required)
                    "User started Jelly.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.openatk.planting.MainActivity.java

private void SliderGrow() {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);// www . j a v a 2s  .c o  m
    int oneThirdHeight = size.y / 3;
    int actionBarHeight = 10;
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }
    if (fragmentEditField != null) {
        RelativeLayout relAdd = (RelativeLayout) fragmentEditField.getView().findViewById(R.id.slider_layMenu);
        RelativeLayout relBottomBar = (RelativeLayout) fragmentEditField.getView()
                .findViewById(R.id.edit_field_layInfo3);
        Log.d("layMenu:", Integer.toString(relAdd.getHeight()));
        ScrollView sv = (ScrollView) fragmentEditField.getView().findViewById(R.id.slider_scrollView);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) sv.getLayoutParams();
        if (sliderPosition == 0) {
            //Small -> Middle
            DropDownAnim an = new DropDownAnim(sv, params.height, oneThirdHeight);
            an.setDuration(300);
            sv.startAnimation(an);
            sliderPosition = 1;
        } else if (sliderPosition == 1) {
            //Middle -> Fullscreen
            DropDownAnim an = new DropDownAnim(sv, params.height,
                    (fragMap.getView().getHeight() - relAdd.getHeight() - relBottomBar.getHeight()));
            Log.d("fullslider", "Full slider" + Integer.toString(relBottomBar.getHeight()));

            an.setDuration(300);
            sv.startAnimation(an);
            sliderPosition = 2;
        }
        sv.setLayoutParams(params);
    }
}

From source file:org.thoughtcrime.securesms.ProfileFragment.java

private void refreshLayout() {
    gDataPreferences = new GDataPreferences(getActivity());
    boolean isMyProfile = (GUtil.numberToLong(gDataPreferences.getE164Number() + "") + "")
            .contains(GUtil.numberToLong(profileId) + "");

    layout_status = (RelativeLayout) getView().findViewById(R.id.layout_status);
    layout_phone = (RelativeLayout) getView().findViewById(R.id.layout_phone);
    layout_group = (RelativeLayout) getView().findViewById(R.id.layout_member);

    statusDate = (TextView) getView().findViewById(R.id.profile__date);
    leaveGroup = (Button) getView().findViewById(R.id.buttonLeaveGroup);
    profileHeader = (TextView) getView().findViewById(R.id.profile_header);
    profileStatus = (AutoCompleteTextView) getView().findViewById(R.id.profile_status);
    xCloseButton = (ImageView) getView().findViewById(R.id.profile_close);
    imageText = (TextView) getView().findViewById(R.id.image_text);
    profilePhone = (TextView) getView().findViewById(R.id.profile_phone);
    groupMember = (ListView) getView().findViewById(R.id.selected_contacts_list);
    historyLayout = (LinearLayout) getView().findViewById(R.id.historylayout);
    historyContentTextView = (TextView) getView().findViewById(R.id.history_content);
    historyScrollView = (HorizontalScrollView) getView().findViewById(R.id.horizontal_scroll);
    recipientsPanel = (PushRecipientsPanel) getView().findViewById(R.id.recipients);
    profilePhone.setText(phonenumber);/*from   w w w  .ja  v  a  2 s  .c om*/
    profilePicture = (ThumbnailView) getView().findViewById(R.id.profile_picture);
    phoneCall = (ImageView) getView().findViewById(R.id.phone_call);
    (getView().findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());
    historyLine = (RelativeLayout) getView().findViewById(R.id.layout_history);
    recipient = recipients.getPrimaryRecipient();
    attachmentAdapter = new ProfileImageTypeSelectorAdapter(getActivity());
    scrollView = (ScrollView) getView().findViewById(R.id.scrollView);
    seekBarFont = (SeekBar) getView().findViewById(R.id.seekbar_font);
    chatPartnersColor = (CheckBox) getView().findViewById(R.id.enabled_chat_partners_color);
    colorDefault = (CheckBox) getView().findViewById(R.id.color_default);
    layoutColor = (RelativeLayout) getView().findViewById(R.id.layout_color);
    floatingActionColorButton = (FloatingActionButton) getView().findViewById(R.id.fab_new_color);
    final ImageView profileStatusEdit = (ImageView) getView().findViewById(R.id.profile_status_edit);

    if (!isGroup) {
        ImageSlide slide = ProfileAccessor.getProfileAsImageSlide(getActivity(), masterSecret, profileId);
        if (slide != null && !isMyProfile) {
            if (masterSecret != null) {
                try {
                    profilePicture.setImageResource(slide, masterSecret);
                } catch (IllegalStateException e) {
                    Log.w("GDATA", "Unable to load profile image");
                }
                profileStatus.setText(ProfileAccessor.getProfileStatusForRecepient(getActivity(), profileId),
                        TextView.BufferType.EDITABLE);
                profileStatus.setEnabled(false);
                layout_status.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        profileStatusEdit.performClick();
                        return false;
                    }
                });
                statusDate.setText(GUtil.getLocalDate(
                        ProfileAccessor.getProfileUpdateTimeForRecepient(getActivity(), profileId),
                        getActivity().getApplicationContext()));
                imageText.setText(recipient.getName());
            }
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
        } else if (ProfileAccessor.getMyProfilePicture(getActivity()).hasImage() && isMyProfile) {
            profileStatus.setText(ProfileAccessor.getProfileStatus(getActivity()),
                    TextView.BufferType.EDITABLE);
            imageText.setText(getString(R.string.MediaPreviewActivity_you));
            initColorSeekbar();
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
            if ((ProfileAccessor.getMyProfilePicture(getActivity()).getUri() + "").equals("")) {
                profilePicture.setImageBitmap(ContactPhotoFactory.getDefaultContactPhoto(getActivity()));
            } else {
                profilePicture.setImageResource(ProfileAccessor.getMyProfilePicture(getActivity()));
            }
            historyLine.setVisibility(View.GONE);
        } else {
            imageText.setText(recipient.getName());
            profilePicture.setImageBitmap(recipient.getContactPhoto());
        }
        layout_group.setVisibility(View.GONE);
    } else {
        String groupName = recipient.getName();
        Bitmap avatar = recipient.getContactPhoto();
        String encodedGroupId = recipient.getNumber();
        if (encodedGroupId != null) {
            try {
                groupId = GroupUtil.getDecodedId(encodedGroupId);
            } catch (IOException ioe) {
                groupId = null;
            }
        }
        GroupDatabase db = DatabaseFactory.getGroupDatabase(getActivity());
        Recipients recipients = db.getGroupMembers(groupId, false);

        recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
            @Override
            public void onRecipientsPanelUpdate(Recipients recipients) {
                Log.w("GDATA", "onRecipientsPanelUpdate received.");
                if (recipients != null) {
                    addAllSelectedContacts(recipients.getRecipientsList());
                    syncAdapterWithSelectedContacts();
                }
            }
        });

        if (recipients != null) {
            final List<Recipient> recipientList = recipients.getRecipientsList();
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }

            SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(getActivity(), android.R.id.text1,
                    new ArrayList<SelectedRecipientsAdapter.RecipientWrapper>());
            adapter.clear();

            if (existingContacts != null) {
                for (Recipient contact : existingContacts) {
                    adapter.add(new SelectedRecipientsAdapter.RecipientWrapper(contact, false));
                }
            }
            adapter.setMasterSecret(masterSecret);
            adapter.setThreadId(threadId);
            adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
                @Override
                public void onRecipientDeleted(Recipient recipient) {
                    removeSelectedContact(recipient);
                }
            });
            groupMember.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }
        if (avatar != null) {
            profilePicture.setVisibility(View.GONE);
            getView().findViewById(R.id.profile_picture_group).setVisibility(View.VISIBLE);
            scaleImage((ImageView) getView().findViewById(R.id.profile_picture_group), avatar);
        }
        imageText.setText(groupName);
        if (profileStatusString.equals("")) {
            profileStatus.setText(groupName);
        }
        layout_phone.setVisibility(View.GONE);

        leaveGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isActiveGroup()) {
                    handleLeavePushGroup();
                } else {
                    handleDeleteThread();
                }
            }
        });
        if (!isActiveGroup()) {
            leaveGroup.setText(getString(R.string.conversation__menu_delete_thread));
        }

        heightMemberList = GUtil.setListViewHeightBasedOnChildren(groupMember);
    }
    ImageView profileImageEdit = (ImageView) getView().findViewById(R.id.profile_picture_edit);
    ImageView profileImageDelete = (ImageView) getView().findViewById(R.id.profile_picture_delete);
    if (!isMyProfile && !isGroup) {
        profileStatusEdit.setVisibility(View.GONE);
        profileImageDelete.setVisibility(View.GONE);
        profileImageEdit.setVisibility(View.GONE);
    } else {
        if (isGroup) {
            profileImageDelete.setVisibility(View.GONE);
            profileHeader.setText(getString(R.string.group_title));
        } else {
            profileImageDelete.setVisibility(View.VISIBLE);
        }
        profileStatusEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                } else {
                    profileStatusEdit
                            .setImageDrawable(getResources().getDrawable(R.drawable.ic_send_sms_gdata));
                    profileStatus.showDropDown();
                    profileStatus.requestFocus();
                }
            }
        });
        profileImageDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hasChanged = true;
                hasLeft = false;
                ProfileAccessor.deleteMyProfilePicture(getActivity());
                refreshLayout();
                profileStatus.dismissDropDown();
                gDataPreferences.hasProfileImageChanged(true);
            }
        });
        profileImageEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gDataPreferences.hasProfileImageChanged(true);
                hasChanged = true;
                hasLeft = false;
                handleAddAttachment();
            }
        });
    }
    if (isMyProfile) {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_dropdown_item_1line,
                getResources().getStringArray(R.array.status_suggestions));
        profileStatus.setAdapter(adapter);
        profileStatus.setCompletionHint(getString(R.string.status_hint));
        profileStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.dismissDropDown();
            }
        });
        profileStatus.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                }
            }
        });
    } else {
        //        if(!isMyProfile) {
        setMediaHistoryImages();
    }
    xCloseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finishAndSave();
        }
    });
    phoneCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            handleDial(recipient);
        }
    });
    final RelativeLayout scrollContainer = (RelativeLayout) getView().findViewById(R.id.scrollContainer);
    final LinearLayout mainLayout = (LinearLayout) getView().findViewById(R.id.mainlayout);
    scrollView.setSmoothScrollingEnabled(true);
    ViewTreeObserver vto = scrollView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            scrollView.scrollTo(0, mainLayout.getTop() - PADDING_TOP);
        }
    });
    scrollContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // getActivity().finish();
        }
    });
    onScrollChangeListener = new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            if (BuildConfig.VERSION_CODE >= 11) {
                scrollContainer.setBackgroundColor(Color.WHITE);
                scrollContainer
                        .setAlpha((float) ((1000.0 / scrollContainer.getHeight()) * scrollView.getHeight()));
            }
            int keyboardHeight = 150;
            int paddingBottom = 250;
            int scrollViewHeight = scrollView.getHeight();
            if (getActivity().getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                scrollViewHeight = 2 * scrollViewHeight;
            }
            int heightDiff = scrollView.getRootView().getHeight() - scrollView.getHeight();
            if (pxToDp(heightDiff) > keyboardHeight) {
                keyboardIsVisible = true;
            } else {
                keyboardIsVisible = false;
            }
            if (!keyboardIsVisible) {
                if ((mainLayout.getTop() - scrollViewHeight) > scrollView.getScrollY()
                        - pxToDp(paddingBottom)) {
                    finishAndSave();
                }
                if ((scrollViewHeight + (heightMemberList)) < (scrollView.getScrollY() - mainLayout.getTop())) {
                    finishAndSave();
                }
            }
        }
    };
    scrollView.getViewTreeObserver().addOnScrollChangedListener(onScrollChangeListener);
    scrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            ViewTreeObserver observer = scrollView.getViewTreeObserver();
            observer.addOnScrollChangedListener(onScrollChangeListener);
            return false;
        }

    });
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

protected void updateMessageDetail(final boolean isUpdate) {
    T.UI();//from w ww  .ja  v  a 2  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);
}