Example usage for android.view Display getHeight

List of usage examples for android.view Display getHeight

Introduction

In this page you can find the example usage for android.view Display getHeight.

Prototype

@Deprecated
public int getHeight() 

Source Link

Usage

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

/**
 * Called when the activity is first created.
 *//*from w ww  . j  a v a  2 s  .c o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.download);

    WindowManager w = getWindowManager();
    Display d = w.getDefaultDisplay();
    swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    gestureScanner = new GestureDetector(this);

    playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
    emptyTextView = (TextView) findViewById(R.id.download_empty);
    songTitleTextView = (TextView) findViewById(R.id.download_song_title);
    artistTextView = (TextView) findViewById(R.id.download_artist);
    albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
    positionTextView = (TextView) findViewById(R.id.download_position);
    durationTextView = (TextView) findViewById(R.id.download_duration);
    statusTextView = (TextView) findViewById(R.id.download_status);
    progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
    playlistView = (ListView) findViewById(R.id.download_list);
    previousButton = findViewById(R.id.download_previous);
    nextButton = findViewById(R.id.download_next);
    pauseButton = findViewById(R.id.download_pause);
    stopButton = findViewById(R.id.download_stop);
    startButton = findViewById(R.id.download_start);
    shuffleButton = findViewById(R.id.download_shuffle);
    repeatButton = (ImageButton) findViewById(R.id.download_repeat);
    equalizerButton = (Button) findViewById(R.id.download_equalizer);
    visualizerButton = (Button) findViewById(R.id.download_visualizer);
    // jukeboxButton = (Button) findViewById(R.id.download_jukebox);
    // shareButton = (ImageView) findViewById(R.id.download_share);
    // starButton = (ImageView) findViewById(R.id.download_star);
    LinearLayout visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
    toggleListButton = (ImageButton) findViewById(R.id.download_toggle_list);

    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent me) {
            return gestureScanner.onTouchEvent(me);
        }
    };
    previousButton.setOnTouchListener(touchListener);
    nextButton.setOnTouchListener(touchListener);
    pauseButton.setOnTouchListener(touchListener);
    stopButton.setOnTouchListener(touchListener);
    // startButton.setOnTouchListener(touchListener);
    equalizerButton.setOnTouchListener(touchListener);
    visualizerButton.setOnTouchListener(touchListener);
    //jukeboxButton.setOnTouchListener(touchListener);
    //shareButton.setOnTouchListener(touchListener);
    //starButton.setOnTouchListener(touchListener);
    emptyTextView.setOnTouchListener(touchListener);
    albumArtImageView.setOnTouchListener(touchListener);

    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            getDownloadService().previous();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
                getDownloadService().next();
                onCurrentChanged();
                onProgressChanged();
            }
        }
    });

    pauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().pause();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    stopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().reset();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    startButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            start();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    shuffleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().shuffle();
            Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
            setControlsVisible(true);
        }
    });

    repeatButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
            getDownloadService().setRepeatMode(repeatMode);
            onDownloadListChanged();
            switch (repeatMode) {
            case OFF:
                Util.toast(DownloadActivity.this, R.string.download_repeat_off);
                break;
            case ALL:
                Util.toast(DownloadActivity.this, R.string.download_repeat_all);
                break;
            case SINGLE:
                Util.toast(DownloadActivity.this, R.string.download_repeat_single);
                break;
            default:
                break;
            }
            setControlsVisible(true);
        }
    });

    equalizerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
            setControlsVisible(true);
        }
    });

    visualizerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean active = !visualizerView.isActive();
            visualizerView.setActive(active);
            getDownloadService().setShowVisualization(visualizerView.isActive());
            updateButtons();
            Util.toast(DownloadActivity.this,
                    active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
            setControlsVisible(true);
        }
    });

    /* jukeboxButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
        getDownloadService().setJukeboxEnabled(jukeboxEnabled);
        updateButtons();
        Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
        setControlsVisible(true);
    }
     });*/

    /*shareButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (currentPlaying != null) {
            ShareUtil.shareInBackground(DownloadActivity.this, currentPlaying.getSong());
        }
        setControlsVisible(true);
    }
    });*/

    /*starButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (currentPlaying != null) {
            MusicDirectory.Entry song = currentPlaying.getSong();
            StarUtil.starInBackground(DownloadActivity.this, song, !song.isStarred());
            starButton.setImageResource(song.isStarred() ? R.drawable.starred : R.drawable.unstarred);
        }
        setControlsVisible(true);
    }
    });*/

    toggleListButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleFullscreenAlbumArt();
        }
    });

    progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int position, boolean fromUser) {
            if (fromUser) {
                Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true);
                setControlsVisible(true);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // Notification that the user has started a touch gesture. Clients may want to use this to disable advancing the seekbar.
            seekInProgress = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // Notification that the user has finished a touch gesture. Clients may want to use this to re-enable advancing the seekbar.
            seekInProgress = false;
            int position = seekBar.getProgress();
            Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true);
            getDownloadService().seekTo(position);
        }
    });

    playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            warnIfNetworkOrStorageUnavailable();
            getDownloadService().play(position);
            onCurrentChanged();
            onProgressChanged();
        }
    });

    registerForContextMenu(playlistView);

    DownloadService downloadService = getDownloadService();
    if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.setShufflePlayEnabled(true);
    }

    boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null;
    boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null;

    if (!equalizerAvailable) {
        equalizerButton.setVisibility(View.GONE);
    }
    if (!visualizerAvailable) {
        visualizerButton.setVisibility(View.GONE);
    } else {
        visualizerView = new VisualizerView(this);
        visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
    }

    final View overflowButton = findViewById(R.id.download_overflow);
    overflowButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new PopupMenuHelper().showMenu(DownloadActivity.this, overflowButton, R.menu.nowplaying);
        }
    });
}

From source file:org.telegram.ui.GalleryImageViewer.java

@SuppressWarnings("unchecked")
@Override//w w  w .j  a  va 2  s . c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Display display = getWindowManager().getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT < 13) {
        displaySize.set(display.getWidth(), display.getHeight());
    } else {
        display.getSize(displaySize);
    }

    classGuid = ConnectionsManager.Instance.generateClassGuid();
    setContentView(R.layout.gallery_layout);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setTitle(getString(R.string.Gallery));
    actionBar.show();

    mViewPager = (GalleryViewPager) findViewById(R.id.gallery_view_pager);
    ImageView shareButton = (ImageView) findViewById(R.id.gallery_view_share_button);
    ImageView deleteButton = (ImageView) findViewById(R.id.gallery_view_delete_button);
    nameTextView = (TextView) findViewById(R.id.gallery_view_name_text);
    timeTextView = (TextView) findViewById(R.id.gallery_view_time_text);
    bottomView = findViewById(R.id.gallery_view_bottom_view);
    fakeTitleView = (TextView) findViewById(R.id.fake_title_view);
    loadingProgress = (ProgressBar) findViewById(R.id.action_progress);

    title = (TextView) findViewById(R.id.action_bar_title);
    if (title == null) {
        final int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) findViewById(titleId);
    }

    NotificationCenter.Instance.addObserver(this, FileLoader.FileDidFailedLoad);
    NotificationCenter.Instance.addObserver(this, FileLoader.FileDidLoaded);
    NotificationCenter.Instance.addObserver(this, FileLoader.FileLoadProgressChanged);
    NotificationCenter.Instance.addObserver(this, MessagesController.mediaCountDidLoaded);
    NotificationCenter.Instance.addObserver(this, MessagesController.mediaDidLoaded);
    NotificationCenter.Instance.addObserver(this, MessagesController.userPhotosLoaded);
    NotificationCenter.Instance.addObserver(this, 658);

    Integer index = null;
    if (localPagerAdapter == null) {
        final MessageObject file = (MessageObject) NotificationCenter.Instance.getFromMemCache(51);
        final TLRPC.FileLocation fileLocation = (TLRPC.FileLocation) NotificationCenter.Instance
                .getFromMemCache(53);
        final ArrayList<MessageObject> messagesArr = (ArrayList<MessageObject>) NotificationCenter.Instance
                .getFromMemCache(54);
        index = (Integer) NotificationCenter.Instance.getFromMemCache(55);
        Integer uid = (Integer) NotificationCenter.Instance.getFromMemCache(56);
        if (uid != null) {
            user_id = uid;
        }

        if (file != null) {
            ArrayList<MessageObject> imagesArr = new ArrayList<MessageObject>();
            HashMap<Integer, MessageObject> imagesByIds = new HashMap<Integer, MessageObject>();
            imagesArr.add(file);
            if (file.messageOwner.action == null
                    || file.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) {
                needSearchMessage = true;
                imagesByIds.put(file.messageOwner.id, file);
                if (file.messageOwner.dialog_id != 0) {
                    currentDialog = file.messageOwner.dialog_id;
                } else {
                    if (file.messageOwner.to_id.chat_id != 0) {
                        currentDialog = -file.messageOwner.to_id.chat_id;
                    } else {
                        if (file.messageOwner.to_id.user_id == UserConfig.clientUserId) {
                            currentDialog = file.messageOwner.from_id;
                        } else {
                            currentDialog = file.messageOwner.to_id.user_id;
                        }
                    }
                }
            }
            localPagerAdapter = new LocalPagerAdapter(imagesArr, imagesByIds);
        } else if (fileLocation != null) {
            ArrayList<TLRPC.FileLocation> arr = new ArrayList<TLRPC.FileLocation>();
            arr.add(fileLocation);
            withoutBottom = true;
            deleteButton.setVisibility(View.INVISIBLE);
            nameTextView.setVisibility(View.INVISIBLE);
            timeTextView.setVisibility(View.INVISIBLE);
            localPagerAdapter = new LocalPagerAdapter(arr);
        } else if (messagesArr != null) {
            ArrayList<MessageObject> imagesArr = new ArrayList<MessageObject>();
            HashMap<Integer, MessageObject> imagesByIds = new HashMap<Integer, MessageObject>();
            imagesArr.addAll(messagesArr);
            Collections.reverse(imagesArr);
            for (MessageObject message : imagesArr) {
                imagesByIds.put(message.messageOwner.id, message);
            }
            index = imagesArr.size() - index - 1;

            MessageObject object = imagesArr.get(0);
            if (object.messageOwner.dialog_id != 0) {
                currentDialog = object.messageOwner.dialog_id;
            } else {
                if (object.messageOwner.to_id.chat_id != 0) {
                    currentDialog = -object.messageOwner.to_id.chat_id;
                } else {
                    if (object.messageOwner.to_id.user_id == UserConfig.clientUserId) {
                        currentDialog = object.messageOwner.from_id;
                    } else {
                        currentDialog = object.messageOwner.to_id.user_id;
                    }
                }
            }
            localPagerAdapter = new LocalPagerAdapter(imagesArr, imagesByIds);
        }
    }

    mViewPager.setPageMargin(Utilities.dp(20));
    mViewPager.setOffscreenPageLimit(1);
    mViewPager.setAdapter(localPagerAdapter);

    if (index != null) {
        fromAll = true;
        mViewPager.setCurrentItem(index);
    }

    shareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                TLRPC.FileLocation file = getCurrentFile();
                File f = new File(Utilities.getCacheDir(), file.volume_id + "_" + file.local_id + ".jpg");
                if (f.exists()) {
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
                    startActivity(intent);
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });

    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mViewPager == null || localPagerAdapter == null || localPagerAdapter.imagesArr == null) {
                return;
            }
            int item = mViewPager.getCurrentItem();
            MessageObject obj = localPagerAdapter.imagesArr.get(item);
            if (obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
                ArrayList<Integer> arr = new ArrayList<Integer>();
                arr.add(obj.messageOwner.id);
                MessagesController.Instance.deleteMessages(arr);
                finish();
            }
        }
    });

    if (currentDialog != 0 && totalCount == 0) {
        MessagesController.Instance.getMediaCount(currentDialog, classGuid, true);
    }
    if (user_id != 0) {
        MessagesController.Instance.loadUserPhotos(user_id, 0, 30, 0, true, classGuid);
    }
    checkCurrentFile();
}

From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java

private void initLayout() {

    /* get size of screen */
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    screenWidth = display.getWidth();//from w w  w .j  av  a 2  s.  c  o m
    screenHeight = display.getHeight();
    FrameLayout.LayoutParams layoutParam = null;
    LayoutInflater myInflate = null;
    myInflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    FrameLayout topLayout = new FrameLayout(this);
    setContentView(topLayout);

    // openGLview
    mGLView = overlay.getGLView();

    /* add camera view */
    // int display_width_d = (int) (1.0 * bg_screen_width * screenWidth /
    // bg_width);
    // int display_height_d = (int) (1.0 * bg_screen_height * screenHeight /
    // bg_height);
    // int prev_rw, prev_rh;
    // if (1.0 * display_width_d / display_height_d > 1.0 * live_width /
    // live_height) {
    // prev_rh = display_height_d;
    // prev_rw = (int) (1.0 * display_height_d * live_width / live_height);
    // } else {
    // prev_rw = display_width_d;
    // prev_rh = (int) (1.0 * display_width_d * live_height / live_width);
    // }
    // layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh);
    // layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight /
    // bg_height);
    // layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth /
    // bg_width);

    int display_width_d = (int) (1.0 * screenWidth);
    int display_height_d = (int) (1.0 * screenHeight);
    int button_width = 0;
    int button_height = 0;
    int prev_rw, prev_rh;
    if (1.0 * display_width_d / display_height_d > 1.0 * live_width / live_height) {
        prev_rh = display_height_d;
        button_height = display_height_d;
        prev_rw = (int) (1.0 * display_height_d * live_width / live_height);
        button_width = display_width_d - prev_rw;

    } else {
        prev_rw = display_width_d;
        prev_rh = (int) (1.0 * display_width_d * live_height / live_width);
    }

    layoutParam = new FrameLayout.LayoutParams(prev_rw, prev_rh, Gravity.CENTER);
    //layoutParam = new FrameLayout.LayoutParams(prev_rw / 2, prev_rh / 2, Gravity.BOTTOM | Gravity.CENTER_VERTICAL);

    // layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight /
    // bg_height);
    // layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth /
    // bg_width);
    Log.d("LAYOUT",
            "display_width_d:" + display_width_d + ":: display_height_d:" + display_height_d + ":: prev_rw:"
                    + prev_rw + ":: prev_rh:" + prev_rh + ":: live_width:" + live_width + ":: live_height:"
                    + live_height + ":: button_width:" + button_width + ":: button_height:" + button_height);
    cameraDevice = openCamera();
    cameraView = new CameraView(this, cameraDevice);

    topLayout.addView(cameraView, layoutParam);
    topLayout.addView(mGLView, layoutParam);

    FrameLayout preViewLayout = (FrameLayout) myInflate.inflate(R.layout.activity_streaming, null);
    layoutParam = new FrameLayout.LayoutParams(screenWidth, screenHeight);
    topLayout.addView(preViewLayout, layoutParam);
    Log.i(LOG_TAG, "cameara preview start: OK");

    final Button recorderButton = (Button) findViewById(R.id.recorder_control);
    recorderButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!recording) {
                Log.d(TAG, "attemptHandshaking");
                attemptHandshake();
                Log.w(LOG_TAG, "Start Button Pushed");
                recorderButton.setText("Stop");
            } else {
                stopRecording();
                Log.w(LOG_TAG, "Stop Button Pushed");
                recorderButton.setText("Start");
            }
        }
    });

}

From source file:com.scoreflex.Scoreflex.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private static Point getScreenSize() {
    final Point size = new Point();
    WindowManager w = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();

    try {//from   ww  w . j a  va  2  s.c  om
        Method getSizeMethod = d.getClass().getDeclaredMethod("getSize", Point.class);
        getSizeMethod.invoke(d, size);
    } catch (Exception e) {
        size.x = d.getWidth();
        size.y = d.getHeight();
    }
    return size;
}

From source file:org.cryptsecure.Utility.java

/**
 * Get the screen height./*from   w w w.  ja v a  2  s.c o m*/
 * 
 * @param context
 *            the context
 * @return the screen height
 */
@SuppressWarnings("deprecation")
public static int getScreenHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    return display.getHeight();
    // API LEVEL 11
    // API LEVEL 13
    // Point size = new Point();
    // display.getSize(size);
    // int width = size.x;
    // int height = size.y;
    // return height;
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Starts a background thread to fetch a new ad. Method is called from the
 * refresh timer task// w ww.  j  a  va 2 s. co m
 */
private void requestNewAd(final boolean isTimerRequest) {
    if (!mFetchAdsEnabled) {
        MadvertiseUtil.logMessage(null, Log.DEBUG, "Fetching ads is disabled");
        return;
    }

    MadvertiseUtil.logMessage(null, Log.DEBUG, "Trying to fetch a new ad");

    mRequestThread = new Thread(new Runnable() {
        public void run() {
            // read all parameters, that we need for the request
            // get site token from manifest xml file
            String siteToken = MadvertiseUtil.getToken(getContext().getApplicationContext(), mCallbackListener);
            if (siteToken == null) {
                siteToken = "";
                MadvertiseUtil.logMessage(null, Log.DEBUG, "Cannot show ads, since the appID ist null");
            } else {
                MadvertiseUtil.logMessage(null, Log.DEBUG, "appID = " + siteToken);
            }

            // create post request
            HttpPost postRequest = new HttpPost(MadvertiseUtil.MAD_SERVER + "/site/" + siteToken);
            postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
            // new ad response version, that supports rich media
            postRequest.addHeader("Accept", "application/vnd.madad+json; version=3");
            List<NameValuePair> parameterList = new ArrayList<NameValuePair>();
            parameterList.add(new BasicNameValuePair("ua", MadvertiseUtil.getUA()));
            parameterList.add(new BasicNameValuePair("app", "true"));
            parameterList.add(new BasicNameValuePair("debug", Boolean.toString(mTestMode)));
            parameterList
                    .add(new BasicNameValuePair("ip", MadvertiseUtil.getLocalIpAddress(mCallbackListener)));
            parameterList.add(new BasicNameValuePair("format", "json"));
            parameterList.add(new BasicNameValuePair("requester", "android_sdk"));
            parameterList.add(new BasicNameValuePair("version", "3.1.3"));
            parameterList.add(new BasicNameValuePair("banner_type", mBannerType));
            parameterList.add(new BasicNameValuePair("deliver_only_text", Boolean.toString(mDeliverOnlyText)));
            if (sAge != null && !sAge.equals("")) {
                parameterList.add(new BasicNameValuePair("age", sAge));
            }

            parameterList.add(new BasicNameValuePair("mraid", Boolean.toString(mIsMraid)));

            if (sGender != null && !sGender.equals("")) {
                parameterList.add(new BasicNameValuePair("gender", sGender));
            }
            final Display display = ((WindowManager) getContext().getApplicationContext()
                    .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            String orientation;
            if (display.getWidth() > display.getHeight()) {
                orientation = "landscape";
            } else {
                orientation = "portrait";
            }

            parameterList.add(new BasicNameValuePair("device_height", Integer.toString(display.getHeight())));
            parameterList.add(new BasicNameValuePair("device_width", Integer.toString(display.getWidth())));

            // When the View is first created, the parent does not exist
            // when this call is made. Hence, we assume that the parent
            // size is equal the screen size for the first call.
            if (mParentWidth == 0 && mParentHeight == 0) {
                mParentWidth = display.getWidth();
                mParentHeight = display.getHeight();
            }

            parameterList.add(new BasicNameValuePair("parent_height", Integer.toString(mParentHeight)));
            parameterList.add(new BasicNameValuePair("parent_width", Integer.toString(mParentWidth)));

            parameterList.add(new BasicNameValuePair("device_orientation", orientation));
            MadvertiseUtil.refreshCoordinates(getContext().getApplicationContext());
            if (MadvertiseUtil.getLocation() != null) {
                parameterList.add(new BasicNameValuePair("lat",
                        Double.toString(MadvertiseUtil.getLocation().getLatitude())));
                parameterList.add(new BasicNameValuePair("lng",
                        Double.toString(MadvertiseUtil.getLocation().getLongitude())));
            }

            parameterList.add(new BasicNameValuePair("app_name",
                    MadvertiseUtil.getApplicationName(getContext().getApplicationContext())));
            parameterList.add(new BasicNameValuePair("app_version",
                    MadvertiseUtil.getApplicationVersion(getContext().getApplicationContext())));

            parameterList.add(new BasicNameValuePair("udid_md5",
                    MadvertiseUtil.getHashedAndroidID(getContext(), MadvertiseUtil.HashType.MD5)));
            parameterList.add(new BasicNameValuePair("udid_sha1",
                    MadvertiseUtil.getHashedAndroidID(getContext(), MadvertiseUtil.HashType.SHA1)));

            parameterList.add(new BasicNameValuePair("mac_md5",
                    MadvertiseUtil.getHashedMacAddress(getContext(), MadvertiseUtil.HashType.MD5)));
            parameterList.add(new BasicNameValuePair("mac_sha1",
                    MadvertiseUtil.getHashedMacAddress(getContext(), MadvertiseUtil.HashType.SHA1)));

            UrlEncodedFormEntity urlEncodedEntity = null;
            try {
                urlEncodedEntity = new UrlEncodedFormEntity(parameterList);
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }

            postRequest.setEntity(urlEncodedEntity);

            MadvertiseUtil.logMessage(null, Log.DEBUG, "Post request created");
            MadvertiseUtil.logMessage(null, Log.DEBUG, "Uri : " + postRequest.getURI().toASCIIString());
            MadvertiseUtil.logMessage(null, Log.DEBUG,
                    "All headers : " + MadvertiseUtil.getAllHeadersAsString(postRequest.getAllHeaders()));
            MadvertiseUtil.logMessage(null, Log.DEBUG,
                    "All request parameters :" + MadvertiseUtil.printRequestParameters(parameterList));

            synchronized (this) {
                // send blocking request to ad server
                HttpClient httpClient = new DefaultHttpClient();
                HttpResponse httpResponse = null;
                InputStream inputStream = null;
                JSONObject json = null;

                try {
                    HttpParams clientParams = httpClient.getParams();
                    HttpConnectionParams.setConnectionTimeout(clientParams, MadvertiseUtil.CONNECTION_TIMEOUT);
                    HttpConnectionParams.setSoTimeout(clientParams, MadvertiseUtil.CONNECTION_TIMEOUT);

                    MadvertiseUtil.logMessage(null, Log.DEBUG, "Sending request");
                    httpResponse = httpClient.execute(postRequest);

                    MadvertiseUtil.logMessage(null, Log.DEBUG,
                            "Response Code => " + httpResponse.getStatusLine().getStatusCode());

                    String message = "";
                    if (httpResponse.getLastHeader("X-Madvertise-Debug") != null) {
                        message = httpResponse.getLastHeader("X-Madvertise-Debug").toString();
                    }

                    if (mTestMode) {
                        MadvertiseUtil.logMessage(null, Log.DEBUG, "Madvertise Debug Response: " + message);
                    }

                    int responseCode = httpResponse.getStatusLine().getStatusCode();

                    HttpEntity entity = httpResponse.getEntity();

                    if (responseCode == 200 && entity != null) {
                        inputStream = entity.getContent();
                        String resultString = MadvertiseUtil.convertStreamToString(inputStream);
                        MadvertiseUtil.logMessage(null, Log.DEBUG, "Response => " + resultString);
                        json = new JSONObject(resultString);

                        // create ad
                        mCurrentAd = new MadvertiseAd(getContext().getApplicationContext(), json,
                                mCallbackListener);

                        calculateBannerDimensions();

                        mHandler.post(mUpdateResults);
                    } else {
                        if (mCallbackListener != null) {
                            mCallbackListener.onIllegalHttpStatusCode(responseCode, message);
                        }
                    }
                } catch (ClientProtocolException e) {
                    MadvertiseUtil.logMessage(null, Log.DEBUG, "Error in HTTP request / protocol", e);
                    if (mCallbackListener != null) {
                        mCallbackListener.onError(e);
                    }
                } catch (IOException e) {
                    MadvertiseUtil.logMessage(null, Log.DEBUG,
                            "Could not receive a http response on an ad request", e);
                    if (mCallbackListener != null) {
                        mCallbackListener.onError(e);
                    }
                } catch (JSONException e) {
                    MadvertiseUtil.logMessage(null, Log.DEBUG, "Could not parse json object", e);
                    if (mCallbackListener != null) {
                        mCallbackListener.onError(e);
                    }
                } catch (Exception e) {
                    MadvertiseUtil.logMessage(null, Log.DEBUG,
                            "Could not receive a http response on an ad request", e);
                    if (mCallbackListener != null) {
                        mCallbackListener.onError(e);
                    }
                } finally {
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                            if (mCallbackListener != null) {
                                mCallbackListener.onError(e);
                            }
                        }
                    }
                }
            }
        }
    }, "MadvertiseRequestThread");
    mRequestThread.start();
}

From source file:com.pdftron.pdf.controls.UserCropDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_user_crop_dialog, null);
    if (mRemoveCropHelperMode) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
    } else {/*from  w  ww . j a va2 s  .  c o m*/
        int width = 10;
        int height = 10;
        WindowManager wm = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            android.graphics.Point size = new android.graphics.Point();
            display.getSize(size);
            width = size.x - 10;
            height = size.y - 10;
        } else {
            width = display.getWidth() - 10;
            height = display.getHeight() - 10;
        }

        int maxImageSize = width * height * 4;
        if (maxImageSize > 0) {
            int maxImages = (DEFAULT_MEM_CACHE_SIZE * 1000) / maxImageSize;
            if (maxImages > 0) {
                mPagesToPreRenderPerDirection = Math.min(MAX_PAGES_TO_PRERENDER_PER_DIRECTION,
                        (maxImages - 1) / 2);
            }
        }
    }
    initUI(view);
    return view;
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressLint("RtlHardcoded")
@SuppressWarnings("deprecation")
@Override// w  ww  .j  ava 2s  . c o m
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    LocalBroadcastManager.getInstance(this)
            .sendBroadcast(new Intent("com.farmerbb.taskbar.CONTEXT_MENU_APPEARING"));

    boolean isNonAppMenu = !getIntent().hasExtra("package_name") && !getIntent().hasExtra("app_name");
    showStartMenu = getIntent().getBooleanExtra("launched_from_start_menu", false);
    isStartButton = isNonAppMenu && getIntent().getBooleanExtra("is_start_button", false);
    isOverflowMenu = isNonAppMenu && getIntent().getBooleanExtra("is_overflow_menu", false);
    contextMenuFix = getIntent().hasExtra("context_menu_fix");

    // Determine where to position the dialog on screen
    WindowManager.LayoutParams params = getWindow().getAttributes();
    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

    int statusBarHeight = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0)
        statusBarHeight = getResources().getDimensionPixelSize(resourceId);

    if (showStartMenu) {
        int x = getIntent().getIntExtra("x", 0);
        int y = getIntent().getIntExtra("y", 0);
        int offset = getResources().getDimensionPixelSize(
                isOverflowMenu ? R.dimen.context_menu_offset_overflow : R.dimen.context_menu_offset);

        switch (U.getTaskbarPosition(this)) {
        case "bottom_left":
        case "bottom_vertical_left":
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            params.x = x;
            params.y = display.getHeight() - y - offset;
            break;
        case "bottom_right":
        case "bottom_vertical_right":
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            params.x = x - getResources().getDimensionPixelSize(R.dimen.context_menu_width) + offset + offset;
            params.y = display.getHeight() - y - offset;
            break;
        case "top_left":
        case "top_vertical_left":
            params.gravity = Gravity.TOP | Gravity.LEFT;
            params.x = x;
            params.y = y - offset + statusBarHeight;
            break;
        case "top_right":
        case "top_vertical_right":
            params.gravity = Gravity.TOP | Gravity.LEFT;
            params.x = x - getResources().getDimensionPixelSize(R.dimen.context_menu_width) + offset + offset;
            params.y = y - offset + statusBarHeight;
            break;
        }
    } else {
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

        int x = getIntent().getIntExtra("x", display.getWidth());
        int y = getIntent().getIntExtra("y", display.getHeight());
        int offset = getResources().getDimensionPixelSize(R.dimen.icon_size);

        switch (U.getTaskbarPosition(this)) {
        case "bottom_left":
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            params.x = isStartButton ? 0 : x;
            params.y = offset;
            break;
        case "bottom_vertical_left":
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            params.x = offset;
            params.y = display.getHeight() - y - (isStartButton ? 0 : offset);
            break;
        case "bottom_right":
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            params.x = display.getWidth() - x;
            params.y = offset;
            break;
        case "bottom_vertical_right":
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            params.x = offset;
            params.y = display.getHeight() - y - (isStartButton ? 0 : offset);
            break;
        case "top_left":
            params.gravity = Gravity.TOP | Gravity.LEFT;
            params.x = isStartButton ? 0 : x;
            params.y = offset;
            break;
        case "top_vertical_left":
            params.gravity = Gravity.TOP | Gravity.LEFT;
            params.x = offset;
            params.y = isStartButton ? 0 : y - statusBarHeight;
            break;
        case "top_right":
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            params.x = display.getWidth() - x;
            params.y = offset;
            break;
        case "top_vertical_right":
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            params.x = offset;
            params.y = isStartButton ? 0 : y - statusBarHeight;
            break;
        }
    }

    params.width = getResources().getDimensionPixelSize(R.dimen.context_menu_width);
    params.dimAmount = 0;

    getWindow().setAttributes(params);

    View view = findViewById(android.R.id.list);
    if (view != null)
        view.setPadding(0, 0, 0, 0);

    generateMenu();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.farmerbb.taskbar.START_MENU_APPEARING");
    intentFilter.addAction("com.farmerbb.taskbar.DASHBOARD_APPEARING");

    LocalBroadcastManager.getInstance(this).registerReceiver(finishReceiver, intentFilter);
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressWarnings("deprecation")
private void openContextMenu() {
    SharedPreferences pref = U.getSharedPreferences(this);
    Intent intent = null;/*from   w ww .  ja  v a 2  s .c om*/

    switch (pref.getString("theme", "light")) {
    case "light":
        intent = new Intent(this, ContextMenuActivity.class);
        break;
    case "dark":
        intent = new Intent(this, ContextMenuActivityDark.class);
        break;
    }

    if (intent != null) {
        intent.putExtra("dont_show_quit",
                LauncherHelper.getInstance().isOnHomeScreen() && !pref.getBoolean("taskbar_active", false));
        intent.putExtra("is_start_button", true);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
        DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
        Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

        if (intent != null && U.isOPreview())
            intent.putExtra("context_menu_fix", true);

        startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU)
                .setLaunchBounds(new Rect(0, 0, display.getWidth(), display.getHeight())).toBundle());
    } else
        startActivity(intent);
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressWarnings("deprecation")
private void openContextMenu(AppEntry entry, int[] location) {
    SharedPreferences pref = U.getSharedPreferences(this);
    Intent intent = null;/*w  w w  .j a  va  2s .  c  om*/

    switch (pref.getString("theme", "light")) {
    case "light":
        intent = new Intent(this, ContextMenuActivity.class);
        break;
    case "dark":
        intent = new Intent(this, ContextMenuActivityDark.class);
        break;
    }

    if (intent != null) {
        intent.putExtra("package_name", entry.getPackageName());
        intent.putExtra("app_name", entry.getLabel());
        intent.putExtra("component_name", entry.getComponentName());
        intent.putExtra("user_id", entry.getUserId(this));
        intent.putExtra("x", location[0]);
        intent.putExtra("y", location[1]);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
        DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
        Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

        if (intent != null && U.isOPreview())
            intent.putExtra("context_menu_fix", true);

        startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU)
                .setLaunchBounds(new Rect(0, 0, display.getWidth(), display.getHeight())).toBundle());
    } else
        startActivity(intent);
}