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:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java

@Override
public void refresh() {
    FrameLayout tasksView = (FrameLayout) getActivity().findViewById(R.id.scheduler_tasks);
    // the view might have been destroyed, in which case we don't do anything
    if (tasksView != null) {
        float density = getActivity().getResources().getDisplayMetrics().density;
        SimpleArrayMap<String, TaskTracker> tasks = mTasks.getTasks();
        LinearLayout tasksList = new LinearLayout(getActivity());
        tasksList.setOrientation(LinearLayout.VERTICAL);
        for (int i = 0; i < tasks.size(); i++) {
            final TaskTracker task = tasks.valueAt(i);
            CardView taskCard = (CardView) getActivity().getLayoutInflater().inflate(R.layout.widget_task,
                    tasksList, false);//from   w w w.  j  a  va  2s . c  o m
            ImageView taskIcon = (ImageView) taskCard.findViewById(R.id.task_icon);
            taskIcon.setImageResource(R.drawable.check_circle_grey600);
            taskIcon.setPadding(0, 0, (int) (8 * density), 0);
            TextView taskLabel = (TextView) taskCard.findViewById(R.id.task_title);
            TextView taskParams = (TextView) taskCard.findViewById(R.id.task_params);
            if (task.period == 0) {
                taskLabel.setText(getString(R.string.scheduler_oneoff, task.tag));
                taskParams.setText(getString(R.string.scheduler_oneoff_params, task.windowStartElapsedSecs,
                        task.windowStopElapsedSecs));
            } else {
                taskLabel.setText(getString(R.string.scheduler_periodic, task.tag));
                taskParams.setText(getString(R.string.scheduler_periodic_params, task.period, task.flex));
            }
            TextView taskCreatedAt = (TextView) taskCard.findViewById(R.id.task_created_at);
            taskCreatedAt.setText(getString(R.string.scheduler_secs_ago, DateUtils
                    .formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - task.createdAtElapsedSecs)));
            TextView lastExecuted = (TextView) taskCard.findViewById(R.id.task_last_exec);
            if (task.executionTimes.isEmpty()) {
                lastExecuted.setText(getString(R.string.scheduler_na));
            } else {
                long lastExecTime = task.executionTimes.get(task.executionTimes.size() - 1);
                lastExecuted.setText(getString(R.string.scheduler_secs_ago,
                        DateUtils.formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - lastExecTime)));
            }
            TextView state = (TextView) taskCard.findViewById(R.id.task_state);
            if (task.isCancelled()) {
                state.setText(getString(R.string.scheduler_cancelled));
            } else if (task.isExecuted()) {
                state.setText(getString(R.string.scheduler_executed));
            } else {
                state.setText(getString(R.string.scheduler_pending));
            }
            Button cancel = (Button) taskCard.findViewById(R.id.task_cancel);
            cancel.setVisibility(View.VISIBLE);
            cancel.setText(R.string.scheduler_cancel);
            Button delete = (Button) taskCard.findViewById(R.id.task_delete);
            delete.setVisibility(View.VISIBLE);
            delete.setText(R.string.scheduler_delete);
            if (!task.isCancelled() && (!task.isExecuted() || task.period != 0)) {
                cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        cancelTask(task.tag);
                        refresh();
                    }
                });
                cancel.setEnabled(true);
                delete.setEnabled(false);
            } else {
                cancel.setEnabled(false);
                delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mTasks.deleteTask(task.tag);
                        refresh();
                    }
                });
                delete.setEnabled(true);
            }
            tasksList.addView(taskCard);
        }
        tasksView.removeAllViews();
        tasksView.addView(tasksList);
    }
}

From source file:com.umeng.comm.ui.emoji.EmojiBorad.java

/**
 * ?</br>//  w  ww .  ja  v a2  s  .c o  m
 * 
 * @return
 */
private ImageView createIndicator() {
    ImageView imageView = new ImageView(getContext());
    LayoutParams params = new LayoutParams(30, 30);
    params.gravity = Gravity.CENTER;
    imageView.setLayoutParams(params);
    imageView.setImageDrawable(ResFinder.getDrawable(mNormalIcon));
    imageView.setPadding(0, 0, 10, 0);
    return imageView;
}

From source file:com.example.khaalijeb.newlistview_module.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  .ja  va2s  .c o m*/
 */

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

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

    //     int width = (int) (getResources().getDisplayMetrics().widthPixels / mViewPager.getAdapter().getCount());
    //    imageView.setMinimumWidth(width);

    imageView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f));

    /*     WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         Display display = wm.getDefaultDisplay();
         Point size = new Point();
         display.getSize(size);
         imageView.setMaxWidth(size.x /4);
    */

    return imageView;
}

From source file:com.pikachu.emoji.widget.EmojiView.java

/**
 * ?</br>// w  w w . jav  a  2 s .c  o  m
 * 
 * @return
 */
private ImageView createIndicator() {
    ImageView imageView = new ImageView(getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(30, 30);
    params.gravity = Gravity.CENTER;
    imageView.setLayoutParams(params);
    imageView.setImageDrawable(ResFinder.getDrawable(mNormalIcon));
    imageView.setPadding(0, 0, 10, 0);
    return imageView;
}

From source file:com.umeng.common.ui.emoji.EmojiBorad.java

/**
 * ?</br>/* www . ja v a2 s  . c om*/
 *
 * @return
 */
private ImageView createIndicator() {
    ImageView imageView = new ImageView(getContext());
    LayoutParams params = new LayoutParams(30, 30);
    params.gravity = Gravity.CENTER;
    imageView.setLayoutParams(params);
    imageView.setImageDrawable(ColorQueque.getDrawable(mNormalIcon));
    imageView.setPadding(0, 0, 10, 0);
    return imageView;
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }/*from  w w  w  .j  a  v  a  2  s . c o  m*/
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

private void startRefreshAnimation() {
    MenuItem item = mToolbar.getMenu().findItem(MENU_ITEM_REFRESH);
    if (item == null) {
        Log.e(TAG, "null");
        return;/*from   w  ww .ja  v a 2s.  c o m*/
    }
    // define the animation for rotation
    Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);

    animation.setRepeatCount(Animation.INFINITE);

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

        @Override
        public void onAnimationEnd(Animation animation) {
            mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setActionView(null);
            mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton);
    imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh));

    imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom());

    imageView.startAnimation(animation);
    item.setActionView(imageView);

}

From source file:com.google.android.gcm.demo.ui.TopicsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;//w  w  w.ja  va 2 s. co m
            }
        }
        if (subscribedTopics > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                            .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                    Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                    icon.setImageResource(R.drawable.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    button.setOnClickListener(this);
                    row.setPadding((int) (16 * density), 0, 0, 0);
                    sendersList.addView(row);
                }
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

/**
 * (non-Javadoc)/* ww  w . j av a 2 s .co m*/
 *
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) ViewRedditActivity.this.getApplicationContext());
    prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this);
    // set window flags
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    // request loading bar first
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // get actionbar and set home button, pad the icon
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    ImageView view = (ImageView) findViewById(android.R.id.home);
    if (view != null) {
        view.setPadding(5, 0, 5, 0);
    }
    // set content view
    setContentView(R.layout.viewreddit);
    // Setup TabHost
    initialiseTabHost(savedInstanceState);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
    }
    redditItemId = getIntent().getStringExtra(WidgetProvider.ITEM_ID);
    widgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
    feedposition = getIntent().getIntExtra("itemposition", 0);
    // Get selected item from feed and user vote preference
    JSONObject currentFeedItem = global.getFeedObject(prefs, widgetId, feedposition, redditItemId);
    try {
        userLikes = currentFeedItem.getString("likes");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //System.out.println("User likes post: " + userLikes);
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override// w w w .  j a  va2  s  . c  om
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}