Example usage for android.content.res Resources getDimensionPixelSize

List of usage examples for android.content.res Resources getDimensionPixelSize

Introduction

In this page you can find the example usage for android.content.res Resources getDimensionPixelSize.

Prototype

public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID for use as a size in raw pixels.

Usage

From source file:com.google.cloud.android.language.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mIntroduction = findViewById(R.id.introduction);
    mResults = findViewById(R.id.results);
    mProgress = findViewById(R.id.progress);

    // Set up the input EditText so that it accepts multiple lines
    mInput = (EditText) findViewById(R.id.input);
    // sum=(Button)findViewById(R.id.button);
    mInput.setHorizontallyScrolling(false);
    mInput.setMaxLines(Integer.MAX_VALUE);

    // Set up the view pager
    final FragmentManager fm = getSupportFragmentManager();
    mAdapter = new ResultPagerAdapter(fm, this);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    final Resources resources = getResources();
    mViewPager.setPageMargin(resources.getDimensionPixelSize(R.dimen.page_margin));
    mViewPager//www  .j a v a2s . co m
            .setPageMarginDrawable(ResourcesCompat.getDrawable(resources, R.drawable.page_margin, getTheme()));
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mAdapter);
    TabLayout tab = (TabLayout) findViewById(R.id.tab);
    tab.setupWithViewPager(mViewPager);

    if (savedInstanceState == null) {
        // The app has just launched; handle share intent if it is necessary
        handleShareIntent();
    } else {
        // Configuration changes; restore UI states
        boolean results = savedInstanceState.getBoolean(STATE_SHOWING_RESULTS);
        if (results) {
            mIntroduction.setVisibility(View.GONE);
            mResults.setVisibility(View.VISIBLE);
            mProgress.setVisibility(View.INVISIBLE);
        } else {
            mResults.setVisibility(View.INVISIBLE);
        }
    }

    // Bind event listeners
    mInput.setOnEditorActionListener(mOnEditorActionListener);
    findViewById(R.id.analyze).setOnClickListener(mOnClickListener);
    findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(getApplicationContext(), Output.class);
            startActivity(in);
        }
    });

    // Prepare the API
    if (getApiFragment() == null) {
        fm.beginTransaction().add(new ApiFragment(), FRAGMENT_API).commit();
    }
    prepareApi();
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private int getStatusBarHeight() {
    int result = 0;
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId);
    }//from   w  w w. jav  a  2 s  .c  o  m
    return result;
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private int getNavigationBarHeight() {
    int result = 0;
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId);
    }/*from  w  ww.  j a  va 2s.c om*/
    return result;
}

From source file:nz.ac.otago.psyanlab.common.designer.assets.ImportAssetActivity.java

@SuppressLint("NewApi")
@Override//from w  w  w . j  a  v a2 s .  c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_import);

    Resources resources = getResources();
    mFilePickerFragment = (FilePickerFragment) getSupportFragmentManager().findFragmentById(R.id.file_picker);
    if (savedInstanceState == null) {
        mFilePickerFragment.setRootDir(Environment.getExternalStorageDirectory());
        mFilePickerFragment.setColumnWidth(resources.getDimensionPixelSize(R.dimen.grid_column_width));
        mFilePickerFragment.setNumColumns(StickyGridHeadersGridView.AUTO_FIT);
        mFilePickerFragment.setMultiSelectEnabled(true);
    }
    ActionBar abs = getActionBar();
    abs.setDisplayUseLogoEnabled(false);
    abs.setDisplayShowHomeEnabled(false);
    abs.setTitle(R.string.title_import_asset);
}

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getHorairesCount(final Context context, final Bundle bundle) {

    synchronized (sLock) {
        if (sHoraireTextWidth == Integer.MIN_VALUE) {
            final TextView horaireTextView = new TextView(context);
            horaireTextView.setTextAppearance(horaireTextView.getContext(),
                    android.R.style.TextAppearance_Medium);

            final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00);
            final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
            horaireTextView.setText(//  w  ww  .ja v a  2 s.c o m
                    FormatUtils.formatTimeAmPm(context, timeFormat.format(noon.toDate())) + " \u2022  ");
            final int specY = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            final int specX = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            horaireTextView.measure(specX, specY);
            sHoraireTextWidth = horaireTextView.getMeasuredWidth();
        }
    }

    final Resources r = context.getResources();
    final int padding = r.getDimensionPixelSize(R.dimen.padding_small);

    final int minWidth = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
    final int minWidthPixel = Math.round(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidth, r.getDisplayMetrics())) - padding;

    return (minWidthPixel / sHoraireTextWidth);
}

From source file:com.linangran.tgfcapp.activities.MainActivity.java

public int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }//from  w  w  w  . j av  a2s.  co  m
    return 0;
}

From source file:org.chromium.ChromeNotifications.java

private void makeNotification(final CordovaArgs args) throws JSONException {
    String notificationId = args.getString(0);
    JSONObject options = args.getJSONObject(1);
    Resources resources = cordova.getActivity().getResources();
    Bitmap largeIcon = makeBitmap(options.getString("iconUrl"),
            resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
            resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
    int smallIconId = resources.getIdentifier("notification_icon", "drawable",
            cordova.getActivity().getPackageName());
    if (smallIconId == 0) {
        smallIconId = resources.getIdentifier("icon", "drawable", cordova.getActivity().getPackageName());
    }//from   w ww  . j a  v a2  s  . c o m
    NotificationCompat.Builder builder = new NotificationCompat.Builder(cordova.getActivity())
            .setSmallIcon(smallIconId).setContentTitle(options.getString("title"))
            .setContentText(options.getString("message")).setLargeIcon(largeIcon)
            .setPriority(options.optInt("priority"))
            .setContentIntent(makePendingIntent(NOTIFICATION_CLICKED_ACTION, notificationId, -1,
                    PendingIntent.FLAG_CANCEL_CURRENT))
            .setDeleteIntent(makePendingIntent(NOTIFICATION_CLOSED_ACTION, notificationId, -1,
                    PendingIntent.FLAG_CANCEL_CURRENT));
    double eventTime = options.optDouble("eventTime");
    if (eventTime != 0) {
        builder.setWhen(Math.round(eventTime));
    }
    JSONArray buttons = options.optJSONArray("buttons");
    if (buttons != null) {
        for (int i = 0; i < buttons.length(); i++) {
            JSONObject button = buttons.getJSONObject(i);
            builder.addAction(android.R.drawable.ic_dialog_info, button.getString("title"), makePendingIntent(
                    NOTIFICATION_BUTTON_CLICKED_ACTION, notificationId, i, PendingIntent.FLAG_CANCEL_CURRENT));
        }
    }
    String type = options.getString("type");
    Notification notification;
    if ("image".equals(type)) {
        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(builder);
        String bigImageUrl = options.optString("imageUrl");
        if (!bigImageUrl.isEmpty()) {
            bigPictureStyle.bigPicture(makeBitmap(bigImageUrl, 0, 0));
        }
        notification = bigPictureStyle.build();
    } else if ("list".equals(type)) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder);
        JSONArray items = options.optJSONArray("items");
        if (items != null) {
            for (int i = 0; i < items.length(); i++) {
                JSONObject item = items.getJSONObject(i);
                inboxStyle.addLine(Html.fromHtml("<b>" + item.getString("title")
                        + "</b>&nbsp;&nbsp;&nbsp;&nbsp;" + item.getString("message")));
            }
        }
        notification = inboxStyle.build();
    } else {
        if ("progress".equals(type)) {
            int progress = options.optInt("progress");
            builder.setProgress(100, progress, false);
        }
        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(builder);
        bigTextStyle.bigText(options.getString("message"));
        notification = bigTextStyle.build();
    }
    notificationManager.notify(notificationId.hashCode(), notification);
}

From source file:org.mariotaku.twidere.fragment.support.DirectMessagesFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final View view = getView();
    if (view == null)
        throw new AssertionError();
    final Context viewContext = view.getContext();
    mMultiSelectManager = getMultiSelectManager();
    final MessageEntriesAdapter adapter = getAdapter();
    final RecyclerView recyclerView = getRecyclerView();
    final LinearLayoutManager layoutManager = getLayoutManager();
    mNavigationHelper = new RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, this);

    adapter.setListener(this);

    final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext,
            layoutManager.getOrientation());
    final Resources res = viewContext.getResources();
    final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
            + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
    itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
    itemDecoration.setDecorationEndOffset(1);
    recyclerView.addItemDecoration(itemDecoration);
    getLoaderManager().initLoader(0, null, this);
    showProgress();/*from   w  w  w .  jav a 2s  . c o m*/
}

From source file:org.xbmc.kore.ui.AddonDetailsFragment.java

@TargetApi(21)
@Override//from  w  w  w  . j a  v  a  2 s . co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    addonId = bundle.getString(BUNDLE_KEY_ADDONID, null);

    if ((container == null) || (addonId == null)) {
        // We're not being shown or there's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_addon_details, container, false);
    ButterKnife.inject(this, root);

    hostManager = HostManager.getInstance(getActivity());
    hostInfo = hostManager.getHostInfo();

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    FloatingActionButton fab = (FloatingActionButton) fabButton;
    fab.attachToScrollView((ObservableScrollView) mediaPanel);

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(bundle.getString(POSTER_TRANS_NAME));
    }

    mediaTitle.setText(bundle.getString(BUNDLE_KEY_NAME));
    mediaUndertitle.setText(bundle.getString(BUNDLE_KEY_SUMMARY));
    mediaAuthor.setText(bundle.getString(BUNDLE_KEY_AUTHOR));
    mediaVersion.setText(bundle.getString(BUNDLE_KEY_VERSION));
    mediaDescription.setText(bundle.getString(BUNDLE_KEY_DESCRIPTION));

    setImages(bundle.getString(BUNDLE_KEY_POSTER), bundle.getString(BUNDLE_KEY_FANART));

    setupEnableButton(bundle.getBoolean(BUNDLE_KEY_ENABLED, false));
    if (bundle.getBoolean(BUNDLE_KEY_BROWSABLE, true))
        updatePinButton();

    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:nz.ac.otago.psyanlab.common.ImportPaleActivity.java

@SuppressLint("NewApi")
@Override//w  ww .j  a v a2s  .c o m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUserDelegate = getIntent().getParcelableExtra(Args.USER_DELEGATE);
    mUserDelegate.init(this);

    setContentView(R.layout.activity_import);

    Resources resources = getResources();
    mFilePickerFragment = (FilePickerFragment) getSupportFragmentManager().findFragmentById(R.id.file_picker);
    if (savedInstanceState == null) {
        mFilePickerFragment.setRootDir(Environment.getExternalStorageDirectory());
        mFilePickerFragment.setColumnWidth(resources.getDimensionPixelSize(R.dimen.grid_column_width));
        mFilePickerFragment.setNumColumns(StickyGridHeadersGridView.AUTO_FIT);
        mFilePickerFragment.setMultiSelectEnabled(true);
    }
    ActionBar abs = getActionBar();
    abs.setDisplayUseLogoEnabled(false);
    abs.setDisplayShowHomeEnabled(false);
    abs.setTitle(R.string.title_import);
    // startActionMode(this);
}