Example usage for android.widget ImageView setPadding

List of usage examples for android.widget ImageView setPadding

Introduction

In this page you can find the example usage for android.widget ImageView setPadding.

Prototype

public void setPadding(int left, int top, int right, int bottom) 

Source Link

Document

Sets the padding.

Usage

From source file:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java

public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) {
    // map our custom item data to fields
    //        title.setText(item.getTitle());
    resultItems = item.getResultItems();

    resultListView.removeAllViews();/* w  w  w  . j av a  2  s  . com*/

    final float scale = getResources().getDisplayMetrics().density;

    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    final int topBottomItem = Helperfunctions.dpToPx(3, scale);

    final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);

    final int topBottomImg = Helperfunctions.dpToPx(1, scale);

    if (resultItems != null && resultItems.length() > 0) {

        for (int i = 0; i < 1; i++)
            // JSONObject resultListItem;
            try {
                final JSONObject result = resultItems.getJSONObject(i);

                final LayoutInflater resultInflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent);

                final LinearLayout measurementLayout = (LinearLayout) resultView
                        .findViewById(R.id.resultMeasurementList);
                measurementLayout.setVisibility(View.GONE);

                final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList);
                netLayout.setVisibility(View.GONE);

                final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement);
                measurementHeader.setVisibility(View.GONE);

                final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet);
                netHeader.setVisibility(View.GONE);

                final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate);
                dateHeader.setVisibility(View.GONE);

                dateHeader.setText(result.optString("time_string"));

                final JSONArray measurementArray = result.getJSONArray("measurement");

                final JSONArray netArray = result.getJSONArray("net");

                for (int j = 0; j < measurementArray.length(); j++) {

                    final JSONObject singleItem = measurementArray.getJSONObject(j);

                    final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    measurememtItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

                    measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL);
                    measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem,
                            topBottomItem);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    measurememtItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
                    // itemClassification.set setGravity(Gravity.LEFT);

                    itemClassification.setImageDrawable(getResources().getDrawable(
                            Helperfunctions.getClassificationImage(singleItem.getInt("classification"))));

                    measurememtItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.getString("value"));

                    measurememtItemLayout.addView(itemValue);

                    measurementLayout.addView(measurememtItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    measurementLayout.addView(divider);

                    measurementLayout.invalidate();
                }

                for (int j = 0; j < netArray.length(); j++) {

                    final JSONObject singleItem = netArray.getJSONObject(j);

                    final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

                    netItemLayout.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
                    netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);

                    netItemLayout.setGravity(Gravity.CENTER_VERTICAL);

                    final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle);
                    itemTitle.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f));
                    itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle);
                    itemTitle.setWidth(0);
                    itemTitle.setGravity(Gravity.LEFT);
                    itemTitle.setText(singleItem.getString("title"));

                    netItemLayout.addView(itemTitle);

                    final ImageView itemClassification = new ImageView(context);
                    itemClassification.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f));
                    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);

                    itemClassification.setImageDrawable(
                            context.getResources().getDrawable(R.drawable.traffic_lights_none));
                    netItemLayout.addView(itemClassification);

                    final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue);
                    itemValue.setLayoutParams(
                            new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f));
                    itemValue.setTextAppearance(context, R.style.balloonResultItemValue);
                    itemValue.setWidth(0);
                    itemValue.setGravity(Gravity.LEFT);
                    itemValue.setText(singleItem.optString("value", null));

                    netItemLayout.addView(itemValue);

                    netLayout.addView(netItemLayout);

                    final View divider = new View(context);
                    divider.setLayoutParams(new LinearLayout.LayoutParams(
                            android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1));
                    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                    divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                    netLayout.addView(divider);

                    netLayout.invalidate();
                }

                measurementHeader.setVisibility(View.VISIBLE);
                netHeader.setVisibility(View.VISIBLE);

                measurementLayout.setVisibility(View.VISIBLE);
                netLayout.setVisibility(View.VISIBLE);

                dateHeader.setVisibility(View.VISIBLE);

                resultListView.addView(resultView);

                Log.d(DEBUG_TAG, "View Added");
                // codeText.setText(resultListItem.getString("sync_code"));

            } catch (final JSONException e) {
                e.printStackTrace();
            }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultListView.setVisibility(View.VISIBLE);

        resultListView.invalidate();
    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(context.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}

From source file:com.filemanager.free.adapters.DrawerAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (values.get(position).isSection()) {
        ImageView view = new ImageView(context);
        if (m.theme1 == 0)
            view.setImageResource(R.color.divider);
        else//  w w  w .  j a  va 2s .c om
            view.setImageResource(R.color.divider_dark);
        view.setClickable(false);
        view.setFocusable(false);
        if (m.theme1 == 0)
            view.setBackgroundColor(Color.WHITE);
        else
            view.setBackgroundResource(R.color.background_material_dark);
        view.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, m.dpToPx(17)));
        view.setPadding(0, m.dpToPx(8), 0, m.dpToPx(8));
        return view;
    } else {
        View view = inflater.inflate(R.layout.drawerrow, parent, false);
        final TextView txtTitle = (TextView) view.findViewById(R.id.firstline);
        final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
        if (m.theme1 == 0) {
            view.setBackgroundResource(R.drawable.safr_ripple_white);
        } else {
            view.setBackgroundResource(R.drawable.safr_ripple_black);
        }
        view.setOnClickListener(new View.OnClickListener() {

            public void onClick(View p1) {
                m.selectItem(position);
            }
            // TODO: Implement this method

        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (!getItem(position).isSection())
                    // not to remove the first bookmark (storage) and permanent bookmarks
                    if (position > m.storage_count && position < values.size() - 7) {
                        EntryItem item = (EntryItem) getItem(position);
                        String path = (item).getPath();
                        if (DataUtils.containsBooks(new String[] { item.getTitle(), path }) != -1) {
                            m.renameBookmark((item).getTitle(), path);
                        } else if (path.startsWith("smb:/")) {
                            m.showSMBDialog(item.getTitle(), path, true);
                        }
                    } else if (position < m.storage_count) {
                        String path = ((EntryItem) getItem(position)).getPath();
                        if (!path.equals("/"))
                            new Futils().showProps(RootHelper.generateBaseFile(new File(path), true), m,
                                    m.theme1);
                    }

                // return true to denote no further processing
                return true;
            }
        });

        txtTitle.setText(((EntryItem) (values.get(position))).getTitle());
        imageView.setImageDrawable(getDrawable(position));
        imageView.clearColorFilter();
        if (myChecked.get(position)) {
            if (m.theme1 == 0)
                view.setBackgroundColor(Color.parseColor("#ffeeeeee"));
            else
                view.setBackgroundColor(Color.parseColor("#ff424242"));
            imageView.setColorFilter(fabskin);
            txtTitle.setTextColor(Color.parseColor(m.fabskin));
        } else {
            if (m.theme1 == 0) {
                imageView.setColorFilter(Color.parseColor("#666666"));
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.black));
            } else {
                imageView.setColorFilter(Color.WHITE);
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
            }
        }

        return view;
    }
}

From source file:com.almeida.matheus.androidslidingtabmaterialdesigner.Components.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link (int, int)}./*from w ww. j a  v  a 2 s.c  o m*/
 */
protected ImageView createDefaultTabView(Context context) {
    ImageView iconTab = new ImageView(context);
    iconTab.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    iconTab.setBackgroundResource(outValue.resourceId);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    iconTab.setPadding(padding, padding, padding, padding);

    return iconTab;
}

From source file:com.TakeTaxi.jy.OnrouteScreen.java

public void pingpicked(JSONObject json) {

    try {//from   www . j a v  a 2 s.  c o  m

        int driverpicked = json.getInt("picked");
        int drivercancelled = json.getInt("dcancel");
        int starttime = json.getInt("datetime");

        // /////////////////////////////// DRIVER CANCEL ////////
        if (drivercancelled == 1) {

            // //// DRIVER CANCEL LATE /////

            if (starttime + 300 <= Query.getServerTime()) {
                handlerboolean = false;
                handler.removeCallbacks(r);

                AlertDialog dcancelbuilder = new AlertDialog.Builder(OnrouteScreen.this).create();
                dcancelbuilder
                        .setMessage("Job has been cancelled.\nWould you like to report a late cancellation?.");

                // //// DRIVER CANCEL LATE - NO REPORT LATE/////
                button_cancelJob_noquery(dcancelbuilder);
                // //// DRIVER CANCEL LATE - REPORT LATE /////
                button_drivercancel_reportlate(dcancelbuilder);

                dcancelbuilder.show();

            } else {
                // /////////////////////////////// DRIVER CANCEL NO ALERTS -
                // WITHIN TIME LIMIT///////////////
                handlerboolean = false;
                handler.removeCallbacks(r);

                alertdialog_drivercancelintime();

            }
        }
        if (driverpicked == 1) {
            // /////////////////////////////// CONFIRM PICK UP
            // ///////////////////////////////////////////

            handlerboolean = false;
            handler.removeCallbacks(r);
            AlertDialog.Builder alert = new AlertDialog.Builder(OnrouteScreen.this);
            final Drawable thumbsup = getResources().getDrawable(R.drawable.thumbsup);
            final Drawable thumbsupwhite = getResources().getDrawable(R.drawable.thumbsupwhite);
            final Drawable thumbsdown = getResources().getDrawable(R.drawable.thumbsdown);
            final Drawable thumbsdownwhite = getResources().getDrawable(R.drawable.thumbsdownwhite);
            LinearLayout layout = new LinearLayout(OnrouteScreen.this);
            layout.setOrientation(1);
            layout.setGravity(17);

            TextView tx1 = new TextView(OnrouteScreen.this);
            tx1.setText("Driver says you have been picked up");
            tx1.setGravity(17);
            tx1.setTextSize(20);
            tx1.setTextColor(Color.WHITE);
            tx1.setPadding(10, 10, 10, 10);

            TextView tx2 = new TextView(OnrouteScreen.this);
            tx2.setText("Please rate your driver");
            tx2.setGravity(17);
            tx2.setTextSize(16);

            LinearLayout imglayout = new LinearLayout(OnrouteScreen.this);
            imglayout.setOrientation(0);
            imglayout.setGravity(17);

            final ImageView ivup = new ImageView(OnrouteScreen.this);
            ivup.setImageDrawable(thumbsupwhite);
            ivup.setClickable(true);
            ivup.setPadding(0, 5, 30, 5);
            final ImageView ivdown = new ImageView(OnrouteScreen.this);
            ivdown.setImageDrawable(thumbsdownwhite);
            ivdown.setClickable(true);
            ivup.setPadding(30, 5, 0, 5);
            imglayout.addView(ivup);
            imglayout.addView(ivdown);

            layout.addView(tx1);
            layout.addView(tx2);

            layout.addView(imglayout);
            // /////////////////////////////// CONFIRM PICK UP - RATINGS
            // ///////////////////////////////////////////

            ivup.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsupboolean == false) {
                        thumbsupboolean = true;
                        thumbsdownboolean = false;
                        ivup.setImageDrawable(thumbsup);
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 1;
                    } else {
                        thumbsupboolean = false;
                        ivup.setImageDrawable(thumbsupwhite);
                        rating = 0;
                    }

                }
            });

            ivdown.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsdownboolean == false) {
                        thumbsdownboolean = true;
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdown);
                        ivup.setImageDrawable(thumbsupwhite);

                        AlertDialog alert = new AlertDialog.Builder(OnrouteScreen.this).create();

                        alert.setMessage("Please pick one");
                        alert.setButton("No show", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -1;
                            }
                        });
                        alert.setButton2("Driver late", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -2;
                            }
                        });
                        alert.setButton3("Poor service", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -3;
                            }
                        });
                        alert.show();

                    } else {
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 0;
                    }

                }
            });

            button_completed_finish(alert);

            alert.setView(layout);
            alert.create();
            alert.show();
        } else {
        }

    } catch (JSONException e) {
    }
}

From source file:br.edu.ifpb.breath.slidingtabs.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int, int)}.
 *//*from   w w  w . j  av a 2s.c om*/
protected View createDefaultTabView(Context context, int type) {
    if (type == 0) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));

        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
        textView.setAllCaps(true);

        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding, padding, padding, padding);

        return textView;
    } else {
        ImageView iconView = new ImageView(context);
        int iconSize = (int) (TAB_VIEW_ICON_SIZE_DIPS * getResources().getDisplayMetrics().density);
        int padding = (int) (TAB_VIEW_ICON_PADDING_DIPS * getResources().getDisplayMetrics().density);

        iconView.setLayoutParams(new LinearLayout.LayoutParams(iconSize + padding, iconSize + padding));
        iconView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        iconView.setPadding(padding, padding, padding, padding);

        return iconView;
    }
}

From source file:com.markupartist.sthlmtraveling.ui.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//w  ww.j ava2s  .  c om
 */
protected ImageView createImageTabView(Context context) {
    ImageView v = new ImageView(context);
    v.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    v.setBackgroundResource(outValue.resourceId);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    v.setPadding(padding, padding, padding, padding);

    return v;
}

From source file:com.yadadeya.yadadeya.widget.SlidingTabLayout.java

protected ImageView createDefaultImageView(Context context) {
    ImageView imageView = new ImageView(context);

    //imageView.setGravity(Gravity.CENTER);
    //imageView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    //imageView.setTypeface(Typeface.DEFAULT_BOLD);
    //imageView.setLayoutParams(new LinearLayout.LayoutParams(
    //ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    imageView.setPadding(padding / 2, padding, padding / 2, padding);

    int width = (int) (getResources().getDisplayMetrics().widthPixels / 5);
    imageView.setMinimumWidth(width);//  w ww.  j a va  2 s . com

    return imageView;
}

From source file:the.joevlc.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (!Util.hasCompatibleCPU()) {
        Log.e(TAG, Util.getErrorMsg());
        Intent i = new Intent(this, CompatErrorActivity.class);
        startActivity(i);//from   w  ww . j a  va2  s. com
        finish();
        super.onCreate(savedInstanceState);
        return;
    }

    /* Get the current version from package */
    PackageInfo pinfo = null;
    try {
        pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package info not found.");
    }
    if (pinfo != null)
        mVersionNumber = pinfo.versionCode;

    /* Get settings */
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);

    /* Check if it's the first run */
    mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber;
    if (mFirstRun) {
        Editor editor = mSettings.edit();
        editor.putInt(PREF_FIRST_RUN, mVersionNumber);
        editor.commit();
    }

    try {
        // Start LibVLC
        LibVLC.getInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
        Intent i = new Intent(this, CompatErrorActivity.class);
        i.putExtra("runtimeError", true);
        i.putExtra("message", "LibVLC failed to initialize (LibVlcException)");
        startActivity(i);
        finish();
        super.onCreate(savedInstanceState);
        return;
    }

    super.onCreate(savedInstanceState);

    /*** Start initializing the UI ***/

    /* Enable the indeterminate progress feature */
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Set up the sliding menu
    setContentView(R.layout.sliding_menu);
    mMenu = (SlidingMenu) findViewById(R.id.sliding_menu);
    changeMenuOffset();

    View v_main = LayoutInflater.from(this).inflate(R.layout.main, null);
    mMenu.setContent(v_main);

    View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null);
    final ListView listView = (ListView) sidebar.findViewById(android.R.id.list);
    listView.setFooterDividersEnabled(true);
    mSidebarAdapter = new SidebarAdapter();
    listView.setAdapter(mSidebarAdapter);
    mMenu.setMenu(sidebar);

    /* Initialize UI variables */
    mInfoLayout = v_main.findViewById(R.id.info_layout);
    mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress);
    mInfoText = (TextView) v_main.findViewById(R.id.info_text);

    /* Set up the action bar */
    mActionBar = getSupportActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    mActionBar.setDisplayHomeAsUpEnabled(true);

    /* Add padding between the home button and the arrow */
    ImageView home = (ImageView) findViewById(Util.isHoneycombOrLater() ? android.R.id.home : R.id.abs__home);
    if (home != null)
        home.setPadding(20, 0, 0, 0);

    /* Set up the sidebar click listener */
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SidebarEntry entry = (SidebarEntry) listView.getItemAtPosition(position);
            Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);

            if (current == null || current.getTag() == entry.id) { /* Already selected */
                mMenu.showAbove();
                return;
            }

            /*
             * Clear any backstack before switching tabs. This avoids
             * activating an old backstack, when a user hits the back button
             * to quit
             */
            for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) {
                getSupportFragmentManager().popBackStack();
            }

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.detach(current);
            ft.attach(getFragment(entry.id));
            ft.commit();
            mCurrentFragment = entry.id;
            mMenu.showAbove();
        }
    });

    /* Set up the mini audio player */
    mAudioPlayer = new AudioMiniPlayer();
    mAudioController = AudioServiceController.getInstance();
    mAudioPlayer.setAudioPlayerControl(mAudioController);
    mAudioPlayer.update();

    getSupportFragmentManager().beginTransaction().replace(R.id.audio_mini_player, mAudioPlayer).commit();

    /* Show info/alpha/beta Warning */
    if (mSettings.getInt(PREF_SHOW_INFO, -1) != mVersionNumber)
        showInfoDialog();
    else if (mFirstRun) {
        /*
         * The sliding menu is automatically opened when the user closes
         * the info dialog. If (for any reason) the dialog is not shown,
         * open the menu after a short delay.
         */
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMenu.showBehind();
            }
        }, 500);
    }

    /* Prepare the progressBar */
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHOW_PROGRESSBAR);
    filter.addAction(ACTION_HIDE_PROGRESSBAR);
    filter.addAction(ACTION_SHOW_TEXTINFO);
    registerReceiver(messageReceiver, filter);

    /* Reload the latest preferences */
    reloadPreferences();

    /* Load the thumbnailer */
    mThumbnailerManager = new ThumbnailerManager(this, getWindowManager().getDefaultDisplay());
}

From source file:self.philbrown.droidQuery.Example.ExampleActivity.java

/**
 * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually
 * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be
 * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>.
 * <br>/* w  ww . ja v  a  2  s.  c  om*/
 * For this example, the public stream is retrieved using <em>ajax</em>, and for each message
 * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to
 * retrieve the thumbnail image for the user. As all these events occur on a background thread, the
 * main ScrollView is populated with cells and displayed to the user.
 * <br>
 * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will
 * trigger the global start and stop events (which show a progress indicator, using a droidQuery
 * extension). The image get requests are not global, so they will not trigger global events.
 */
public void refresh() {
    $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json")
            .type("GET").error(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object error, int status, String reason
                    Object error = params[0];
                    int status = (Integer) params[1];
                    String reason = (String) params[2];
                    Log.w("app.net Client", "Could not complete request: " + reason);
                }
            }).success(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object, reason
                    JSONObject json = (JSONObject) params[0];
                    String reason = (String) params[1];
                    try {
                        Map<String, ?> map = $.map(json);
                        JSONArray datas = (JSONArray) map.get("data");

                        if (datas.length() != 0) {
                            //clear old subviews in layout
                            $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove();

                            //get each message infos and create a cell
                            for (int i = 0; i < datas.length(); i++) {
                                JSONObject jdata = (JSONObject) datas.get(i);
                                Map<String, ?> data = $.map(jdata);

                                String text = data.get("text").toString();

                                Map<String, ?> user = $.map((JSONObject) data.get("user"));

                                String username = user.get("username").toString();
                                String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url");

                                //get Avatar image in a new task (but go ahead and create the cell for now)
                                LinearLayout cell = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                cell_params.bottomMargin = 5;
                                cell.setLayoutParams(cell_params);
                                cell.setOrientation(LinearLayout.HORIZONTAL);
                                cell.setWeightSum(8);
                                cell.setPadding(5, 5, 5, 5);
                                cell.setBackgroundColor(Color.parseColor("#333333"));
                                final LinearLayout fcell = cell;

                                //contains the image location
                                ImageView image = new ImageView(ExampleActivity.this);
                                image.setId(99);
                                LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                ip_params.weight = 2;
                                image.setLayoutParams(ip_params);
                                image.setPadding(0, 0, 5, 0);
                                $.with(image).attr("alpha", 0.0f);
                                cell.addView(image);
                                final ImageView fimage = image;

                                //the text location in the cell
                                LinearLayout body = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                body_params.weight = 5;
                                body.setLayoutParams(body_params);
                                body.setOrientation(LinearLayout.VERTICAL);
                                body.setGravity(Gravity.CENTER_VERTICAL);
                                cell.addView(body);

                                //the username
                                TextView name = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                name.setLayoutParams(name_params);
                                name.setTextColor(Color.GRAY);
                                name.setText(username);
                                body.addView(name);

                                //the message
                                TextView message = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                message.setLayoutParams(msg_params);
                                message.setTextColor(Color.WHITE);
                                message.setTextSize(18);
                                message.setText(text);
                                body.addView(message);

                                CheckBox checkbox = new CheckBox(ExampleActivity.this);
                                LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                box_params.weight = 1;
                                checkbox.setLayoutParams(box_params);

                                cell.addView(checkbox);

                                $.with(ExampleActivity.this, R.id.example_layout).add(cell);
                                //$.with(fimage).image(avatarURL, 200, 200, $.noop());
                                $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200)
                                        .imageWidth(200).global(false).success(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object, reason
                                                Bitmap src = (Bitmap) params[0];
                                                String reason = (String) params[1];
                                                $.with(fimage).val(src);
                                                try {
                                                    $.with(fimage)
                                                            .fadeIn(new AnimationOptions("{ duration: 400 }"));
                                                } catch (Throwable e) {
                                                    e.printStackTrace();
                                                }
                                                LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell
                                                        .getLayoutParams();
                                                try {
                                                    lparams.height = Math.min(src.getWidth(),
                                                            fimage.getWidth());
                                                } catch (Throwable t) {
                                                    //ignore NPE
                                                }

                                                fcell.setLayoutParams(lparams);
                                            }
                                        }).error(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object error, int status, String reason
                                                Object error = params[0];
                                                int status = (Integer) params[1];
                                                String reason = (String) params[2];
                                                Log.w("app.net Client",
                                                        "Could not complete image request: " + reason);
                                            }
                                        }));

                            }
                        } else {
                            Log.w("app.net client", "could not update data");
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }));
}

From source file:org.videolan.vlc.gui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (!LibVlcUtil.hasCompatibleCPU(this)) {
        Log.e(TAG, LibVlcUtil.getErrorMsg());
        Intent i = new Intent(this, CompatErrorActivity.class);
        startActivity(i);//w w w .  j  a  v  a  2 s .  c o m
        finish();
        super.onCreate(savedInstanceState);
        return;
    }

    /* Get the current version from package */
    PackageInfo pinfo = null;
    try {
        pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package info not found.");
    }
    if (pinfo != null)
        mVersionNumber = pinfo.versionCode;

    /* Get settings */
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);

    /* Check if it's the first run */
    mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber;
    if (mFirstRun) {
        Editor editor = mSettings.edit();
        editor.putInt(PREF_FIRST_RUN, mVersionNumber);
        editor.commit();
    }

    try {
        // Start LibVLC
        Util.getLibVlcInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
        Intent i = new Intent(this, CompatErrorActivity.class);
        i.putExtra("runtimeError", true);
        i.putExtra("message", "LibVLC failed to initialize (LibVlcException)");
        startActivity(i);
        finish();
        super.onCreate(savedInstanceState);
        return;
    }

    super.onCreate(savedInstanceState);

    /*** Start initializing the UI ***/

    /* Enable the indeterminate progress feature */
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Set up the sliding menu
    setContentView(R.layout.sliding_menu);
    mMenu = (SlidingMenu) findViewById(R.id.sliding_menu);
    changeMenuOffset();

    View v_main = LayoutInflater.from(this).inflate(R.layout.main, null);
    mMenu.setContent(v_main);

    View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null);
    final ListView listView = (ListView) sidebar.findViewById(android.R.id.list);
    listView.setFooterDividersEnabled(true);
    mSidebarAdapter = new SidebarAdapter();
    listView.setAdapter(mSidebarAdapter);
    mMenu.setMenu(sidebar);

    /* Initialize UI variables */
    mInfoLayout = v_main.findViewById(R.id.info_layout);
    mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress);
    mInfoText = (TextView) v_main.findViewById(R.id.info_text);

    /* Set up the action bar */
    mActionBar = getSupportActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    mActionBar.setDisplayHomeAsUpEnabled(true);

    /* Add padding between the home button and the arrow */
    ImageView home = (ImageView) findViewById(Util.isHoneycombOrLater() ? android.R.id.home : R.id.abs__home);
    if (home != null)
        home.setPadding(20, 0, 0, 0);

    /* Set up the sidebar click listener */
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SidebarAdapter.SidebarEntry entry = (SidebarEntry) listView.getItemAtPosition(position);
            Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);

            if (current == null || current.getTag().equals(entry.id)) { /* Already selected */
                mMenu.showContent();
                return;
            }

            /*
             * Clear any backstack before switching tabs. This avoids
             * activating an old backstack, when a user hits the back button
             * to quit
             */
            for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) {
                getSupportFragmentManager().popBackStack();
            }

            /**
             * Do not move this getFragment("audio")!
             * This is to ensure that if audio is not already loaded, it
             * will be loaded ahead of the detach/attach below.
             * Otherwise if you add() a fragment after an attach/detach,
             * it will take over the placeholder and you will end up with
             * the audio fragment when some other fragment should be there.
             */
            Fragment audioFragment = getFragment("audio");

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.detach(current);
            ft.attach(getFragment(entry.id));
            ft.commit();
            mCurrentFragment = entry.id;

            /*
             * Set user visibility hints to work around weird Android
             * behaviour of duplicate context menu events.
             */
            current.setUserVisibleHint(false);
            getFragment(mCurrentFragment).setUserVisibleHint(true);
            // HACK ALERT: Set underlying audio browser to be invisible too.
            if (current.getTag().equals("tracks"))
                audioFragment.setUserVisibleHint(false);

            mMenu.showContent();
        }
    });

    /* Set up the mini audio player */
    // TODO use mini player
    //        mAudioPlayer = new AudioMiniPlayer(); 
    mAudioController = MediaServiceController.getInstance();
    //        mAudioPlayer.setAudioPlayerControl(mAudioController);
    //        mAudioPlayer.update();
    //
    //        getSupportFragmentManager().beginTransaction()
    //            .replace(R.id.audio_mini_player, mAudioPlayer)
    //            .commit();

    /* Show info/alpha/beta Warning */
    if (mSettings.getInt(PREF_SHOW_INFO, -1) != mVersionNumber)
        showInfoDialog();
    else if (mFirstRun) {
        /*
         * The sliding menu is automatically opened when the user closes
         * the info dialog. If (for any reason) the dialog is not shown,
         * open the menu after a short delay.
         */
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMenu.showMenu();
            }
        }, 500);
    }

    /* Prepare the progressBar */
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHOW_PROGRESSBAR);
    filter.addAction(ACTION_HIDE_PROGRESSBAR);
    filter.addAction(ACTION_SHOW_TEXTINFO);
    registerReceiver(messageReceiver, filter);

    /* Reload the latest preferences */
    reloadPreferences();
}