Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

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

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

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 {// w w w .  j a  v a  2  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.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java

@SuppressWarnings("deprecation")
private void setTextViewFontSize() {
    TextView tv = (TextView) findViewById(R.id.textview_cur);
    // At this point tv.getWidth(), tv.getLineCount() will return 0

    Paint mTestPaint = new Paint();
    mTestPaint.setTextSize(tv.getTextSize());
    mTestPaint.setTypeface(Typeface.MONOSPACE);

    final String text = "Peak:XXXXX.XHz(AX#+XX) -XXX.XdB";
    Display display = getWindowManager().getDefaultDisplay();

    // pixels left
    float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5;

    float fs = tv.getTextSize(); // size in pixel
    while (mTestPaint.measureText(text) > px && fs > 5) {
        fs -= 0.5;//from  w  ww.jav  a  2s . c  o  m
        mTestPaint.setTextSize(fs);
    }
    ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio);
    ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio);
}

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 w  w . j a  v a2 s  .c  o 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:github.bewantbe.audio_analyzer_for_android.AnalyzeActivity.java

@SuppressWarnings("deprecation")
private void setTextViewFontSize() {
    TextView tv = (TextView) findViewById(R.id.textview_cur);
    // At this point tv.getWidth(), tv.getLineCount() will return 0

    Paint mTestPaint = new Paint();
    mTestPaint.setTextSize(tv.getTextSize());
    mTestPaint.setTypeface(Typeface.MONOSPACE);

    final String text = getString(R.string.textview_peak_text);
    Display display = getWindowManager().getDefaultDisplay();

    // pixels left
    float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5;

    float fs = tv.getTextSize(); // size in pixel
    while (mTestPaint.measureText(text) > px && fs > 5) {
        fs -= 0.5;/*from   w w w.j  a v a2 s .c om*/
        mTestPaint.setTextSize(fs);
    }
    ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio);
    ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio);
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@SuppressWarnings("deprecation")
@Override/*w w  w .  j a v  a  2 s.  c  om*/
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int heightSpecMode = View.MeasureSpec.getMode(heightMeasureSpec);
    final int widthSpecMode = View.MeasureSpec.getMode(widthMeasureSpec);
    final int widthSpecSize = View.MeasureSpec.getSize(widthMeasureSpec);
    final int heightSpecSize = View.MeasureSpec.getSize(heightMeasureSpec);

    int h, w;
    if (heightSpecMode == View.MeasureSpec.EXACTLY)
        h = heightSpecSize;
    else {
        h = (int) ((mCoverHeight + mCoverHeight * mReflectionHeight + mReflectionGap) * mMaxScaleFactor
                + mPaddingTop + mPaddingBottom);
        h = resolveSize(h, heightMeasureSpec);
    }

    if (widthSpecMode == View.MeasureSpec.EXACTLY)
        w = widthSpecSize;
    else {
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        w = display.getWidth();
        w = resolveSize(w, widthMeasureSpec);
    }

    setMeasuredDimension(w, h);
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@SuppressWarnings("deprecation")
private void setTextViewFontSize() {
    TextView tv = (TextView) findViewById(R.id.textview_cur);
    // At this point tv.getWidth(), tv.getLineCount() will return 0

    Paint mTestPaint = new Paint();
    mTestPaint.setTextSize(tv.getTextSize());
    mTestPaint.setTypeface(Typeface.MONOSPACE);

    final String text = getString(R.string.textview_peak_text);
    Display display = getWindowManager().getDefaultDisplay();

    // pixels left
    float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5;

    float fs = tv.getTextSize(); // size in pixel
    while (mTestPaint.measureText(text) > px && fs > 5) {
        fs -= 0.5;//from   w w w .ja va  2s.  com
        mTestPaint.setTextSize(fs);
    }

    ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio);
    ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio);
}

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

@SuppressWarnings("deprecation")
private void openContextMenu() {
    SharedPreferences pref = U.getSharedPreferences(this);
    Intent intent = null;/*from   w w w. j  av  a 2  s  .  c o m*/

    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;//from   w  w  w  .ja v a2 s  . c o  m

    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);
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    try {/*ww  w  .j a va 2 s  . c  o m*/
        DataFramework.getInstance().open(this, Utils.packageName);
    } catch (Exception e) {
        e.printStackTrace();
    }

    super.onCreate(savedInstanceState);

    CacheData.getInstance().fillHide();

    ConnectionManager.getInstance().open(this);
    ConnectionManager.getInstance().loadUsers();

    OnAlarmReceiver.callAlarm(this);

    if (PreferenceUtils.getFinishForceClose(this)) {
        PreferenceUtils.setFinishForceClose(this, false);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.title_crash);
        builder.setMessage(R.string.msg_crash);
        builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Utils.sendLastCrash(TweetTopicsActivity.this);
            }
        });
        builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        builder.create();
        builder.show();
    }

    Thread.UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
    if (currentHandler != null) {
        Thread.setDefaultUncaughtExceptionHandler(new ErrorReporter(currentHandler, getApplication()));
    }

    if (PreferenceManager.getDefaultSharedPreferences(this).getString("prf_orientation", "2").equals("2")) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

    // borrar notificaciones
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prf_notif_delete_notifications_inside",
            true)) {
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
    }

    long goToColumnPosition = -1;
    int goToColumnType = -1;
    long goToColumnUser = -1;
    long goToColumnSearch = -1;
    long selectedTweetId = -1;

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_POSITION)) {
            goToColumnPosition = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_POSITION);
        }
        if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_TYPE)) {
            goToColumnType = extras.getInt(KEY_EXTRAS_GOTO_COLUMN_TYPE);
        }
        if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_USER)) {
            goToColumnUser = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_USER);
        }
        if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_SEARCH)) {
            goToColumnSearch = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_SEARCH);
        }
        if (extras.containsKey(KEY_EXTRAS_GOTO_TWEET_ID)) {
            selectedTweetId = extras.getLong(KEY_EXTRAS_GOTO_TWEET_ID);
        }
    }

    int positionFromSensor = -1;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVE_STATE_COLUMN_POS)) {
        positionFromSensor = savedInstanceState.getInt(KEY_SAVE_STATE_COLUMN_POS);
    }

    Utils.createDirectoriesIfIsNecessary();

    Display display = getWindowManager().getDefaultDisplay();
    widthScreen = display.getWidth();
    heightScreen = display.getHeight();

    themeManager = new ThemeManager(this);
    themeManager.setTheme();

    setContentView(R.layout.tweettopics_activity);

    fragmentAdapter = new TweetTopicsFragmentAdapter(this, getSupportFragmentManager());

    pager = (ViewPager) findViewById(R.id.tweet_pager);
    pager.setAdapter(fragmentAdapter);

    indicator = (TitlePageIndicator) findViewById(R.id.tweettopics_bar_indicator);
    indicator.setFooterIndicatorStyle(TitlePageIndicator.IndicatorStyle.Triangle);
    indicator.setFooterLineHeight(0);
    indicator.setFooterColor(Color.WHITE);
    indicator.setClipPadding(-getWindowManager().getDefaultDisplay().getWidth());
    indicator.setViewPager(pager);
    indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i1) {
        }

        @Override
        public void onPageSelected(int i) {
            reloadBarAvatar();
            if (i == 0) {
                refreshMyActivity();
            }
        }

        @Override
        public void onPageScrollStateChanged(int i) {

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

    findViewById(R.id.tweettopics_bar_my_activity).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showActionBarIndicatorAndMovePager(0);
        }
    });

    findViewById(R.id.tweettopics_bar_options).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showMenuColumnsOptions(view);
        }
    });

    layoutOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_options_columns);
    layoutMainOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_main_options_columns);
    layoutMainOptionsColumns.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            hideOptionsColumns();
        }
    });
    btnOptionsColumnsMain = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_main);
    btnOptionsColumnsMain.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int pos = Integer.valueOf(view.getTag().toString());
            Toast.makeText(TweetTopicsActivity.this,
                    getString(R.string.column_main_message, fragmentAdapter.setColumnActive(pos)),
                    Toast.LENGTH_LONG).show();
            hideOptionsColumns();
        }
    });
    btnOptionsColumnsEdit = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_edit);
    btnOptionsColumnsEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int pos = Integer.valueOf(view.getTag().toString());
            EditColumnDialogFragment frag = new EditColumnDialogFragment(
                    fragmentAdapter.getFragmentList().get(pos), new Callable() {
                        @Override
                        public Object call() throws Exception {
                            refreshActionBarColumns();
                            return null;
                        }
                    });
            frag.show(getSupportFragmentManager(), "dialog");
            hideOptionsColumns();
        }
    });

    // cargar el popup de enlaces

    FrameLayout root = ((FrameLayout) findViewById(R.id.tweettopics_root));
    popupLinks = new PopupLinks(this);
    popupLinks.loadPopup(root);

    splitActionBarMenu = new SplitActionBarMenu(this);
    splitActionBarMenu.loadSplitActionBarMenu(root);

    layoutBackgroundApp = (RelativeLayout) findViewById(R.id.tweettopics_layout_background_app);

    layoutBackgroundBar = (RelativeLayout) findViewById(R.id.tweettopics_bar_background);

    horizontalScrollViewColumns = (HorizontalScrollView) findViewById(R.id.tweettopics_bar_horizontal_scroll);

    layoutBackgroundColumnsBarContainer = (LinearLayout) findViewById(R.id.tweettopics_bar_columns_container);

    layoutBackgroundColumnsBar = (LinearLayout) findViewById(R.id.tweettopics_bar_columns);
    //        layoutBackgroundColumnsBar.setCols(4);
    //
    //        layoutBackgroundColumnsBar.setOnRearrangeListener(new OnRearrangeListener() {
    //            public void onRearrange(int oldIndex, int newIndex) {
    //                reorganizeColumns(oldIndex, newIndex);
    //            }
    //
    //            @Override
    //            public void onStartDrag(int x, int index) {
    //                showOptionsColumns(x, index, true);
    //            }
    //
    //            @Override
    //            public void onMoveDragged(int index) {
    //                hideOptionsColumns();
    //            }
    //
    //        });
    //        layoutBackgroundColumnsBar.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    //            @Override
    //            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    //                showActionBarIndicatorAndMovePager(position);
    //            }
    //        });

    imgBarAvatar = (ImageView) findViewById(R.id.tweettopics_bar_avatar);
    imgBarAvatarBg = (ImageView) findViewById(R.id.tweettopics_bar_avatar_bg);
    imgBarCounter = (TextView) findViewById(R.id.tweettopics_bar_counter);
    imgNewStatus = (ImageView) findViewById(R.id.tweettopics_bar_new_status);
    imgNewStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            newStatus();
        }
    });

    imgBarAvatarGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent e) {
            if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) {
                ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop();
            }
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) {
                ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop();
            }
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            animateDragged();
            return true;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    });

    imgBarAvatarBg.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return imgBarAvatarGestureDetector.onTouchEvent(motionEvent);
        }
    });

    refreshTheme();

    reloadBarAvatar();

    refreshActionBarColumns();

    if (goToColumnType >= 0) {
        if ((goToColumnType == TweetTopicsUtils.COLUMN_TIMELINE
                || goToColumnType == TweetTopicsUtils.COLUMN_MENTIONS
                || goToColumnType == TweetTopicsUtils.COLUMN_DIRECT_MESSAGES) && goToColumnUser >= 0) {
            openUserColumn(goToColumnUser, goToColumnType);
        }
        if (goToColumnType == TweetTopicsUtils.COLUMN_SEARCH && goToColumnSearch > 0) {
            openSearchColumn(new Entity("search", goToColumnSearch));
        }
    } else if (goToColumnType == TweetTopicsUtils.COLUMN_MY_ACTIVITY) {
    } else if (goToColumnPosition > 0) {
        goToColumn((int) goToColumnPosition, false, selectedTweetId);
    } else if (positionFromSensor >= 0) {
        goToColumn(positionFromSensor, false, selectedTweetId);
    } else {
        int col = fragmentAdapter.getPositionColumnActive();
        if (col > 0)
            goToColumn(col, false, selectedTweetId);
    }

    // comprobar si hay que proponer ir al market

    int access_count = PreferenceUtils.getApplicationAccessCount(this);

    if (access_count <= 20) {
        if (access_count == 20) {
            try {
                AlertDialog dialog = DialogUtils.RateAppDialogBuilder.create(this);
                dialog.show();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }

        PreferenceUtils.setApplicationAccessCount(this, access_count + 1);
    }

    PreferenceUtils.showChangeLog(this, true);

}

From source file:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {// w w  w . j a va2 s .  com
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}