Search in sources :

Example 96 with ImageButton

use of android.widget.ImageButton in project MaterialTabs by neokree.

the class MaterialTabHost method notifyDataSetChanged.

public void notifyDataSetChanged() {
    super.removeAllViews();
    layout.removeAllViews();
    if (!scrollable) {
        // not scrollable tabs
        int tabWidth = this.getWidth() / tabs.size();
        // set params for resizing tabs width
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT);
        for (MaterialTab t : tabs) {
            layout.addView(t.getView(), params);
        }
    } else {
        if (!isTablet) {
            for (int i = 0; i < tabs.size(); i++) {
                LinearLayout.LayoutParams params;
                MaterialTab tab = tabs.get(i);
                // 12dp + text/icon width + 12dp
                int tabWidth = (int) (tab.getTabMinWidth() + (24 * density));
                if (i == 0) {
                    // first tab
                    View view = new View(layout.getContext());
                    view.setMinimumWidth((int) (60 * density));
                    layout.addView(view);
                }
                params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT);
                layout.addView(tab.getView(), params);
                if (i == tabs.size() - 1) {
                    // last tab
                    View view = new View(layout.getContext());
                    view.setMinimumWidth((int) (60 * density));
                    layout.addView(view);
                }
            }
        } else {
            // is a tablet
            for (int i = 0; i < tabs.size(); i++) {
                LinearLayout.LayoutParams params;
                MaterialTab tab = tabs.get(i);
                // 24dp + text/icon width + 24dp
                int tabWidth = (int) (tab.getTabMinWidth() + (48 * density));
                params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT);
                layout.addView(tab.getView(), params);
            }
        }
    }
    if (isTablet && scrollable) {
        // if device is a tablet and have scrollable tabs add right and left arrows
        Resources res = getResources();
        left = new ImageButton(this.getContext());
        left.setId(R.id.left);
        left.setImageDrawable(res.getDrawable(R.drawable.left_arrow));
        left.setBackgroundColor(Color.TRANSPARENT);
        left.setOnClickListener(this);
        // set 56 dp width and 48 dp height
        RelativeLayout.LayoutParams paramsLeft = new LayoutParams((int) (56 * density), (int) (48 * density));
        paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        this.addView(left, paramsLeft);
        right = new ImageButton(this.getContext());
        right.setId(R.id.right);
        right.setImageDrawable(res.getDrawable(R.drawable.right_arrow));
        right.setBackgroundColor(Color.TRANSPARENT);
        right.setOnClickListener(this);
        RelativeLayout.LayoutParams paramsRight = new LayoutParams((int) (56 * density), (int) (48 * density));
        paramsRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        paramsRight.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        paramsRight.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        this.addView(right, paramsRight);
        RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        paramsScroll.addRule(RelativeLayout.LEFT_OF, R.id.right);
        paramsScroll.addRule(RelativeLayout.RIGHT_OF, R.id.left);
        this.addView(scrollView, paramsScroll);
    } else {
        // if is not a tablet add only scrollable content
        RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        this.addView(scrollView, paramsScroll);
    }
    this.setSelectedNavigationItem(tabSelected);
}
Also used : ImageButton(android.widget.ImageButton) RelativeLayout(android.widget.RelativeLayout) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout)

Example 97 with ImageButton

use of android.widget.ImageButton in project KeepScore by nolanlawson.

the class EditablePlayerAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.editable_player, parent, false);
    }
    final PlayerScore playerScore = getItem(position);
    TextView nameTextView = (TextView) view.findViewById(R.id.text_player_name);
    TextView numberTextView = (TextView) view.findViewById(R.id.text_player_number);
    TextView scoreTextView = (TextView) view.findViewById(R.id.text_player_score);
    PlayerColorView playerColorView = (PlayerColorView) view.findViewById(R.id.player_color_image);
    playerColorView.setVisibility(PreferenceHelper.getShowColors(getContext()) ? View.VISIBLE : View.GONE);
    nameTextView.setText(playerScore.toDisplayName(getContext()));
    numberTextView.setText('#' + Integer.toString(playerScore.getPlayerNumber() + 1));
    scoreTextView.setText(Long.toString(playerScore.getScore()));
    playerColorView.setPlayerColor(playerScore.getPlayerColor());
    // listen for player color clicks
    playerColorView.setOnClickListener(new OnClickListener() {

        private PlayerColor chosenColor;

        @Override
        public void onClick(View v) {
            DialogHelper.showColorChooserDialog(getContext(), playerScore.getPlayerColor(), new Callback<PlayerColor>() {

                @Override
                public void onCallback(PlayerColor playerColor) {
                    // color changed
                    chosenColor = playerColor;
                }
            }, new Runnable() {

                @Override
                public void run() {
                    // color selected
                    if (chosenColor == null) {
                        return;
                    }
                    playerScore.setPlayerColor(chosenColor);
                    notifyDataSetChanged();
                }
            });
        }
    });
    // add listener to the delete button
    ImageButton deleteButton = (ImageButton) view.findViewById(R.id.button_delete_player);
    deleteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // delete
            remove(playerScore);
            resetPlayerNumbers();
            notifyDataSetChanged();
            if (onDeleteListener != null) {
                onDeleteListener.onCallback(playerScore);
            }
        }
    });
    // user is not allowed to delete the final 2 users
    deleteButton.setEnabled(getCount() > OrganizePlayersActivity.MIN_NUM_PLAYERS);
    ImageButton editButton = (ImageButton) view.findViewById(R.id.button_edit_player);
    editButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // edit
            DialogHelper.showPlayerNameDialog(getContext(), R.string.title_change_name, playerScore.getName(), playerScore.getPlayerNumber(), new Callback<String>() {

                @Override
                public void onCallback(String input) {
                    playerScore.setName(input);
                    notifyDataSetChanged();
                }
            });
        }
    });
    view.setVisibility(currentlyDragging == view ? View.INVISIBLE : View.VISIBLE);
    return view;
}
Also used : ImageButton(android.widget.ImageButton) PlayerColor(com.nolanlawson.keepscore.helper.PlayerColor) Callback(com.nolanlawson.keepscore.util.Callback) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 98 with ImageButton

use of android.widget.ImageButton in project KeepScore by nolanlawson.

the class TextWithDeleteAdapter method getView.

@Override
public View getView(final int position, View view, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.text_with_delete, parent, false);
    final String textItem = getItem(position);
    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.root_relative_layout);
    textView.setText(textItem);
    // add listener to the delete button
    ImageButton button = (ImageButton) view.findViewById(android.R.id.button1);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //delete button clicked
            onDeleteListener.onDelete(textItem);
        }
    });
    relativeLayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickListener.onCallback(position);
        }
    });
    return view;
}
Also used : ImageButton(android.widget.ImageButton) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 99 with ImageButton

use of android.widget.ImageButton in project android by owncloud.

the class ExpandableUploadListAdapter method getView.

private View getView(OCUpload[] uploadsItems, int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mParentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.upload_list_item, parent, false);
    }
    if (uploadsItems != null && uploadsItems.length > position) {
        final OCUpload upload = uploadsItems[position];
        // local file name
        TextView fileTextView = (TextView) view.findViewById(R.id.upload_name);
        File remoteFile = new File(upload.getRemotePath());
        String fileName = remoteFile.getName();
        if (fileName.length() == 0) {
            fileName = File.separator;
        }
        fileTextView.setText(fileName);
        // remote path to parent folder
        TextView pathTextView = (TextView) view.findViewById(R.id.upload_remote_path);
        String remoteParentPath = upload.getRemotePath();
        remoteParentPath = new File(remoteParentPath).getParent();
        pathTextView.setText(mParentActivity.getString(R.string.app_name) + remoteParentPath);
        // file size
        TextView fileSizeTextView = (TextView) view.findViewById(R.id.upload_file_size);
        fileSizeTextView.setText(DisplayUtils.bytesToHumanReadable(upload.getFileSize(), mParentActivity) + ", ");
        //* upload date
        TextView uploadDateTextView = (TextView) view.findViewById(R.id.upload_date);
        long updateTime = upload.getUploadEndTimestamp();
        CharSequence dateString = DisplayUtils.getRelativeDateTimeString(mParentActivity, updateTime, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
        uploadDateTextView.setText(dateString);
        TextView accountNameTextView = (TextView) view.findViewById(R.id.upload_account);
        try {
            Account account = AccountUtils.getOwnCloudAccountByName(mParentActivity, upload.getAccountName());
            OwnCloudAccount oca = new OwnCloudAccount(account, mParentActivity);
            accountNameTextView.setText(oca.getDisplayName() + " @ " + DisplayUtils.convertIdn(account.name.substring(account.name.lastIndexOf("@") + 1), false));
        } catch (Exception e) {
            Log_OC.w(TAG, "Couldn't get display name for account, using old style");
            accountNameTextView.setText(upload.getAccountName());
        }
        TextView statusTextView = (TextView) view.findViewById(R.id.upload_status);
        ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
        /// Reset fields visibility
        uploadDateTextView.setVisibility(View.VISIBLE);
        pathTextView.setVisibility(View.VISIBLE);
        fileSizeTextView.setVisibility(View.VISIBLE);
        accountNameTextView.setVisibility(View.VISIBLE);
        statusTextView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        /// Update information depending of upload details
        String status = getStatusText(upload);
        switch(upload.getUploadStatus()) {
            case UPLOAD_IN_PROGRESS:
                progressBar.setProgress(0);
                progressBar.setVisibility(View.VISIBLE);
                FileUploader.FileUploaderBinder binder = mParentActivity.getFileUploaderBinder();
                if (binder != null) {
                    if (binder.isUploadingNow(upload)) {
                        /// ... unbind the old progress bar, if any; ...
                        if (mProgressListener != null) {
                            binder.removeDatatransferProgressListener(mProgressListener, // the one that was added
                            mProgressListener.getUpload());
                        }
                        /// ... then, bind the current progress bar to listen for updates
                        mProgressListener = new ProgressListener(upload, progressBar);
                        binder.addDatatransferProgressListener(mProgressListener, upload);
                    } else {
                        /// not really uploading; stop listening progress if view is reused!
                        if (convertView != null && mProgressListener != null && mProgressListener.isWrapping(progressBar)) {
                            binder.removeDatatransferProgressListener(mProgressListener, // the one that was added
                            mProgressListener.getUpload());
                            mProgressListener = null;
                        }
                    }
                } else {
                    Log_OC.w(TAG, "FileUploaderBinder not ready yet for upload " + upload.getRemotePath());
                }
                uploadDateTextView.setVisibility(View.GONE);
                pathTextView.setVisibility(View.GONE);
                fileSizeTextView.setVisibility(View.GONE);
                progressBar.invalidate();
                break;
            case UPLOAD_FAILED:
                uploadDateTextView.setVisibility(View.GONE);
                break;
            case UPLOAD_SUCCEEDED:
                statusTextView.setVisibility(View.GONE);
                break;
        }
        statusTextView.setText(status);
        /// bind listeners to perform actions
        ImageButton rightButton = (ImageButton) view.findViewById(R.id.upload_right_button);
        if (upload.getUploadStatus() == UploadStatus.UPLOAD_IN_PROGRESS) {
            //Cancel
            rightButton.setImageResource(R.drawable.ic_action_cancel_grey);
            rightButton.setVisibility(View.VISIBLE);
            rightButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    FileUploader.FileUploaderBinder uploaderBinder = mParentActivity.getFileUploaderBinder();
                    if (uploaderBinder != null) {
                        uploaderBinder.cancel(upload);
                        refreshView();
                    }
                }
            });
        } else if (upload.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
            //Delete
            rightButton.setImageResource(R.drawable.ic_action_delete_grey);
            rightButton.setVisibility(View.VISIBLE);
            rightButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    mUploadsStorageManager.removeUpload(upload);
                    refreshView();
                }
            });
        } else {
            // UploadStatus.UPLOAD_SUCCESS
            rightButton.setVisibility(View.INVISIBLE);
        }
        // retry
        if (upload.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
            if (UploadResult.CREDENTIAL_ERROR.equals(upload.getLastResult())) {
                view.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        mParentActivity.getFileOperationsHelper().checkCurrentCredentials(upload.getAccount(mParentActivity));
                    }
                });
            } else {
                // not a credentials error
                view.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        File file = new File(upload.getLocalPath());
                        if (file.exists()) {
                            FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
                            requester.retry(mParentActivity, upload);
                            refreshView();
                        } else {
                            final String message = String.format(mParentActivity.getString(R.string.local_file_not_found_toast));
                            Snackbar snackbar = Snackbar.make(v.getRootView().findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG);
                            snackbar.show();
                        }
                    }
                });
            }
        } else {
            view.setOnClickListener(null);
        }
        /// Set icon or thumbnail
        ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
        fileIcon.setImageResource(R.drawable.file);
        /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
             * {@link ThumbnailsCacheManager#cancelPotentialWork} will NEVER cancel any task.
             **/
        OCFile fakeFileToCheatThumbnailsCacheManagerInterface = new OCFile(upload.getRemotePath());
        fakeFileToCheatThumbnailsCacheManagerInterface.setStoragePath(upload.getLocalPath());
        fakeFileToCheatThumbnailsCacheManagerInterface.setMimetype(upload.getMimeType());
        boolean allowedToCreateNewThumbnail = (ThumbnailsCacheManager.cancelPotentialThumbnailWork(fakeFileToCheatThumbnailsCacheManagerInterface, fileIcon));
        // TODO this code is duplicated; refactor to a common place
        if ((fakeFileToCheatThumbnailsCacheManagerInterface.isImage() && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null && upload.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED)) {
            // Thumbnail in Cache?
            Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId()));
            if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.needsUpdateThumbnail()) {
                fileIcon.setImageBitmap(thumbnail);
            } else {
                // generate new Thumbnail
                if (allowedToCreateNewThumbnail) {
                    final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon, mParentActivity.getStorageManager(), mParentActivity.getAccount());
                    if (thumbnail == null) {
                        thumbnail = ThumbnailsCacheManager.mDefaultImg;
                    }
                    final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncThumbnailDrawable(mParentActivity.getResources(), thumbnail, task);
                    fileIcon.setImageDrawable(asyncDrawable);
                    task.execute(fakeFileToCheatThumbnailsCacheManagerInterface);
                }
            }
            if ("image/png".equals(upload.getMimeType())) {
                fileIcon.setBackgroundColor(mParentActivity.getResources().getColor(R.color.background_color));
            }
        } else if (fakeFileToCheatThumbnailsCacheManagerInterface.isImage()) {
            File file = new File(upload.getLocalPath());
            // Thumbnail in Cache?
            Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(file.hashCode()));
            if (thumbnail != null) {
                fileIcon.setImageBitmap(thumbnail);
            } else {
                // generate new Thumbnail
                if (allowedToCreateNewThumbnail) {
                    final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
                    if (thumbnail == null) {
                        thumbnail = ThumbnailsCacheManager.mDefaultImg;
                    }
                    final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncThumbnailDrawable(mParentActivity.getResources(), thumbnail, task);
                    fileIcon.setImageDrawable(asyncDrawable);
                    task.execute(file);
                    Log_OC.v(TAG, "Executing task to generate a new thumbnail");
                }
            }
            if ("image/png".equalsIgnoreCase(upload.getMimeType())) {
                fileIcon.setBackgroundColor(mParentActivity.getResources().getColor(R.color.background_color));
            }
        } else {
            fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(upload.getMimeType(), fileName));
        }
    }
    return view;
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileUploader(com.owncloud.android.files.services.FileUploader) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) ImageButton(android.widget.ImageButton) Bitmap(android.graphics.Bitmap) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ExpandableListView(android.widget.ExpandableListView) OnDatatransferProgressListener(com.owncloud.android.lib.common.network.OnDatatransferProgressListener) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Snackbar(android.support.design.widget.Snackbar)

Example 100 with ImageButton

use of android.widget.ImageButton in project android_frameworks_base by ParanoidAndroid.

the class ListRecyclerProfiling method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.list_recycler_profiling);
    String[] values = new String[1000];
    for (int i = 0; i < 1000; i++) {
        values[i] = ((Integer) i).toString();
    }
    ListView listView = (ListView) findViewById(R.id.list);
    ViewDebug.startRecyclerTracing("SimpleList", listView);
    listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values));
    ImageButton stopProfiling = (ImageButton) findViewById(R.id.pause);
    stopProfiling.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            ViewDebug.stopRecyclerTracing();
        }
    });
}
Also used : ImageButton(android.widget.ImageButton) ListView(android.widget.ListView) View(android.view.View) ListView(android.widget.ListView)

Aggregations

ImageButton (android.widget.ImageButton)149 View (android.view.View)105 TextView (android.widget.TextView)83 ImageView (android.widget.ImageView)51 Button (android.widget.Button)26 ListView (android.widget.ListView)24 AdapterView (android.widget.AdapterView)23 OnClickListener (android.view.View.OnClickListener)21 LinearLayout (android.widget.LinearLayout)19 Intent (android.content.Intent)18 RelativeLayout (android.widget.RelativeLayout)13 DialogInterface (android.content.DialogInterface)11 Bundle (android.os.Bundle)11 LayoutInflater (android.view.LayoutInflater)11 EditText (android.widget.EditText)11 ViewGroup (android.view.ViewGroup)10 ArrayList (java.util.ArrayList)10 Builder (android.app.AlertDialog.Builder)7 MenuItem (android.view.MenuItem)7 Drawable (android.graphics.drawable.Drawable)6